FreeRTOS-04列表和列表项
根据正点原子FreeRTOS视频整理
单片机:STM32F207VC
FreeRTOS源码版本:v10.0.1
实验说明:
1. 验证列表项的插入、末尾插入、删除操作
备注:
末尾插入感觉不是末尾插入,而是插入到列表的后面,所有列表项的前面
1.main.c
/*
* 实验说明:
* 1. 验证列表项的插入、末尾插入、删除操作
*
* 备注:
* 末尾插入感觉不是末尾插入,而是插入到列表的后面,所有列表项的前面
*/
#include "main.h"
#include "delay.h"
#include "sys.h"
#include "usart.h" #include "stm32f2xx_gpio.h" #include "FreeRTOS.h"
#include "task.h" #define START_TASK_PRIO 1 /*任务优先级*/
#define START_STK_SIZE 128 /*任务堆栈大小*/
TaskHandle_t StartTask_Handle; /*任务句柄*/
void StartTask(void *pvParameters); /*任务函数*/ #define LIST_TASK_PRIO 2
#define LIST_STK_SIZE 256
TaskHandle_t ListTask_Handle;
void ListTask(void *pvParameters); /*定义列表和列表项*/
List_t TestList;
ListItem_t ListItem1;
ListItem_t ListItem2;
ListItem_t ListItem3; /***** 声明 *****/
static void SystemInitial(void);
static void GPIO_LED_Configuration(void); static void GPIO_LED_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); GPIO_InitStructure.GPIO_Pin = LED_POWER;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOE, &GPIO_InitStructure); LED_Power_On();
} void StartTask(void *pvParameters)
{
taskENTER_CRITICAL(); /*进入临界区*/ xTaskCreate((TaskFunction_t )ListTask, /*任务函数*/
(const char * )"ListTask", /*任务名称*/
(uint16_t )LIST_STK_SIZE, /*任务堆栈大小*/
(void * )NULL, /*传递给任务函数的参数*/
(UBaseType_t )LIST_TASK_PRIO, /*任务优先级*/
(TaskHandle_t )&ListTask_Handle); /*任务句柄*/ vTaskDelete(StartTask_Handle); /*删除开始任务*/
taskEXIT_CRITICAL(); /*推出临界区*/
} void ListTask(void *pvParameters)
{
/* 1. 初始化列表和列表项 */
vListInitialise(&TestList);
vListInitialiseItem(&ListItem1);
vListInitialiseItem(&ListItem2);
vListInitialiseItem(&ListItem3);
printf("1. 初始化列表和列表项\r\n");
printf("/**************列表和列表项地址**************/\r\n");
printf("项目 地址 \r\n");
printf("TestList %#x \r\n", (int)&TestList);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd %#x \r\n", (int)(&TestList.xListEnd));
printf("TestList->xListEnd->xItemValue %#x \r\n", (int)(&TestList.xListEnd.xItemValue));
printf("TestList->xListEnd->pxNext %#x \r\n", (int)(TestList.xListEnd.pxNext));
printf("TestList->xListEnd->pxPrevious %#x \r\n", (int)(TestList.xListEnd.pxPrevious));
printf("ListItem1 %#x \r\n", (int)&ListItem1);
printf("ListItem2 %#x \r\n", (int)&ListItem2);
printf("ListItem3 %#x \r\n", (int)&ListItem3);
printf("/******************变量和值******************/\r\n");
printf("变量名 变量值 \r\n");
printf("TestList->uxNumberOfItems %ld \r\n", TestList.uxNumberOfItems);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd->xItemValue %#x \r\n", TestList.xListEnd.xItemValue);
printf("ListItem1->xItemValue %d \r\n", ListItem1.xItemValue);
printf("ListItem2->xItemValue %d \r\n", ListItem2.xItemValue);
printf("ListItem3->xItemValue %d \r\n", ListItem3.xItemValue);
printf("/******************* end ********************/\r\n");
printf("\r\n"); /* 2. 插入ListItem1 */
ListItem1.xItemValue = ;
vListInsert(&TestList, &ListItem1);
printf("2. 插入ListItem1\r\n");
printf("/**************列表和列表项地址**************/\r\n");
printf("项目 地址 \r\n");
printf("TestList %#x \r\n", (int)&TestList);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd %#x \r\n", (int)(&TestList.xListEnd));
printf("TestList->xListEnd->xItemValue %#x \r\n", (int)(&TestList.xListEnd.xItemValue));
printf("TestList->xListEnd->pxNext %#x \r\n", (int)(TestList.xListEnd.pxNext));
printf("TestList->xListEnd->pxPrevious %#x \r\n", (int)(TestList.xListEnd.pxPrevious));
printf("ListItem1 %#x \r\n", (int)&ListItem1);
printf("ListItem1->pxNext %#x \r\n", (int)(ListItem1.pxNext));
printf("ListItem1->pxPrevious %#x \r\n", (int)(ListItem1.pxPrevious));
printf("ListItem2 %#x \r\n", (int)&ListItem2);
printf("ListItem3 %#x \r\n", (int)&ListItem3);
printf("/******************变量和值******************/\r\n");
printf("变量名 变量值 \r\n");
printf("TestList->uxNumberOfItems %ld \r\n", TestList.uxNumberOfItems);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd->xItemValue %#x \r\n", TestList.xListEnd.xItemValue);
printf("ListItem1->xItemValue %d \r\n", ListItem1.xItemValue);
printf("ListItem2->xItemValue %d \r\n", ListItem2.xItemValue);
printf("ListItem3->xItemValue %d \r\n", ListItem3.xItemValue);
printf("/******************* end ********************/\r\n");
printf("\r\n"); /* 3. 插入ListItem2 */
ListItem2.xItemValue = ;
vListInsert(&TestList, &ListItem2);
printf("3. 插入ListItem2\r\n");
printf("/**************列表和列表项地址**************/\r\n");
printf("项目 地址 \r\n");
printf("TestList %#x \r\n", (int)&TestList);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd %#x \r\n", (int)(&TestList.xListEnd));
printf("TestList->xListEnd->xItemValue %#x \r\n", (int)(&TestList.xListEnd.xItemValue));
printf("TestList->xListEnd->pxNext %#x \r\n", (int)(TestList.xListEnd.pxNext));
printf("TestList->xListEnd->pxPrevious %#x \r\n", (int)(TestList.xListEnd.pxPrevious));
printf("ListItem1 %#x \r\n", (int)&ListItem1);
printf("ListItem1->pxNext %#x \r\n", (int)(ListItem1.pxNext));
printf("ListItem1->pxPrevious %#x \r\n", (int)(ListItem1.pxPrevious));
printf("ListItem2 %#x \r\n", (int)&ListItem2);
printf("ListItem2->pxNext %#x \r\n", (int)(ListItem2.pxNext));
printf("ListItem2->pxPrevious %#x \r\n", (int)(ListItem2.pxPrevious));
printf("ListItem3 %#x \r\n", (int)&ListItem3);
printf("/******************变量和值******************/\r\n");
printf("变量名 变量值 \r\n");
printf("TestList->uxNumberOfItems %ld \r\n", TestList.uxNumberOfItems);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd->xItemValue %#x \r\n", TestList.xListEnd.xItemValue);
printf("ListItem1->xItemValue %d \r\n", ListItem1.xItemValue);
printf("ListItem2->xItemValue %d \r\n", ListItem2.xItemValue);
printf("ListItem3->xItemValue %d \r\n", ListItem3.xItemValue);
printf("/******************* end ********************/\r\n");
printf("\r\n"); /* 4. 插入ListItem3 */
ListItem3.xItemValue = ;
vListInsert(&TestList, &ListItem3);
printf("4. 插入ListItem3\r\n");
printf("/**************列表和列表项地址**************/\r\n");
printf("项目 地址 \r\n");
printf("TestList %#x \r\n", (int)&TestList);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd %#x \r\n", (int)(&TestList.xListEnd));
printf("TestList->xListEnd->xItemValue %#x \r\n", (int)(&TestList.xListEnd.xItemValue));
printf("TestList->xListEnd->pxNext %#x \r\n", (int)(TestList.xListEnd.pxNext));
printf("TestList->xListEnd->pxPrevious %#x \r\n", (int)(TestList.xListEnd.pxPrevious));
printf("ListItem1 %#x \r\n", (int)&ListItem1);
printf("ListItem1->pxNext %#x \r\n", (int)(ListItem1.pxNext));
printf("ListItem1->pxPrevious %#x \r\n", (int)(ListItem1.pxPrevious));
printf("ListItem2 %#x \r\n", (int)&ListItem2);
printf("ListItem2->pxNext %#x \r\n", (int)(ListItem2.pxNext));
printf("ListItem2->pxPrevious %#x \r\n", (int)(ListItem2.pxPrevious));
printf("ListItem3 %#x \r\n", (int)&ListItem3);
printf("ListItem3->pxNext %#x \r\n", (int)(ListItem3.pxNext));
printf("ListItem3->pxPrevious %#x \r\n", (int)(ListItem3.pxPrevious));
printf("/******************变量和值******************/\r\n");
printf("变量名 变量值 \r\n");
printf("TestList->uxNumberOfItems %ld \r\n", TestList.uxNumberOfItems);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd->xItemValue %#x \r\n", TestList.xListEnd.xItemValue);
printf("ListItem1->xItemValue %d \r\n", ListItem1.xItemValue);
printf("ListItem2->xItemValue %d \r\n", ListItem2.xItemValue);
printf("ListItem3->xItemValue %d \r\n", ListItem3.xItemValue);
printf("/******************* end ********************/\r\n");
printf("\r\n"); /* 5. 删除ListItem2 */
uxListRemove(&ListItem2);
printf("5. 删除ListItem2\r\n");
printf("/**************列表和列表项地址**************/\r\n");
printf("项目 地址 \r\n");
printf("TestList %#x \r\n", (int)&TestList);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd %#x \r\n", (int)(&TestList.xListEnd));
printf("TestList->xListEnd->xItemValue %#x \r\n", (int)(&TestList.xListEnd.xItemValue));
printf("TestList->xListEnd->pxNext %#x \r\n", (int)(TestList.xListEnd.pxNext));
printf("TestList->xListEnd->pxPrevious %#x \r\n", (int)(TestList.xListEnd.pxPrevious));
printf("ListItem1 %#x \r\n", (int)&ListItem1);
printf("ListItem1->pxNext %#x \r\n", (int)(ListItem1.pxNext));
printf("ListItem1->pxPrevious %#x \r\n", (int)(ListItem1.pxPrevious));
printf("ListItem2 %#x \r\n", (int)&ListItem2);
printf("ListItem2->pxNext %#x \r\n", (int)(ListItem2.pxNext));
printf("ListItem2->pxPrevious %#x \r\n", (int)(ListItem2.pxPrevious));
printf("ListItem3 %#x \r\n", (int)&ListItem3);
printf("ListItem3->pxNext %#x \r\n", (int)(ListItem3.pxNext));
printf("ListItem3->pxPrevious %#x \r\n", (int)(ListItem3.pxPrevious));
printf("/******************变量和值******************/\r\n");
printf("变量名 变量值 \r\n");
printf("TestList->uxNumberOfItems %ld \r\n", TestList.uxNumberOfItems);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd->xItemValue %#x \r\n", TestList.xListEnd.xItemValue);
printf("ListItem1->xItemValue %d \r\n", ListItem1.xItemValue);
printf("ListItem2->xItemValue %d \r\n", ListItem2.xItemValue);
printf("ListItem3->xItemValue %d \r\n", ListItem3.xItemValue);
printf("/******************* end ********************/\r\n");
printf("\r\n"); /* 6. 末尾插入ListItem2 */
TestList.pxIndex = TestList.pxIndex->pxNext;
vListInsertEnd(&TestList, &ListItem2);
printf("6. 末尾插入ListItem2\r\n");
printf("/**************列表和列表项地址**************/\r\n");
printf("项目 地址 \r\n");
printf("TestList %#x \r\n", (int)&TestList);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd %#x \r\n", (int)(&TestList.xListEnd));
printf("TestList->xListEnd->xItemValue %#x \r\n", (int)(&TestList.xListEnd.xItemValue));
printf("TestList->xListEnd->pxNext %#x \r\n", (int)(TestList.xListEnd.pxNext));
printf("TestList->xListEnd->pxPrevious %#x \r\n", (int)(TestList.xListEnd.pxPrevious));
printf("ListItem1 %#x \r\n", (int)&ListItem1);
printf("ListItem1->pxNext %#x \r\n", (int)(ListItem1.pxNext));
printf("ListItem1->pxPrevious %#x \r\n", (int)(ListItem1.pxPrevious));
printf("ListItem2 %#x \r\n", (int)&ListItem2);
printf("ListItem2->pxNext %#x \r\n", (int)(ListItem2.pxNext));
printf("ListItem2->pxPrevious %#x \r\n", (int)(ListItem2.pxPrevious));
printf("ListItem3 %#x \r\n", (int)&ListItem3);
printf("ListItem3->pxNext %#x \r\n", (int)(ListItem3.pxNext));
printf("ListItem3->pxPrevious %#x \r\n", (int)(ListItem3.pxPrevious));
printf("/******************变量和值******************/\r\n");
printf("变量名 变量值 \r\n");
printf("TestList->uxNumberOfItems %ld \r\n", TestList.uxNumberOfItems);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd->xItemValue %#x \r\n", TestList.xListEnd.xItemValue);
printf("ListItem1->xItemValue %d \r\n", ListItem1.xItemValue);
printf("ListItem2->xItemValue %d \r\n", ListItem2.xItemValue);
printf("ListItem3->xItemValue %d \r\n", ListItem3.xItemValue);
printf("/******************* end ********************/\r\n");
printf("\r\n"); /* 7. 删除ListItem1 */
uxListRemove(&ListItem1);
printf("7. 删除ListItem1\r\n");
printf("/**************列表和列表项地址**************/\r\n");
printf("项目 地址 \r\n");
printf("TestList %#x \r\n", (int)&TestList);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd %#x \r\n", (int)(&TestList.xListEnd));
printf("TestList->xListEnd->xItemValue %#x \r\n", (int)(&TestList.xListEnd.xItemValue));
printf("TestList->xListEnd->pxNext %#x \r\n", (int)(TestList.xListEnd.pxNext));
printf("TestList->xListEnd->pxPrevious %#x \r\n", (int)(TestList.xListEnd.pxPrevious));
printf("ListItem1 %#x \r\n", (int)&ListItem1);
printf("ListItem1->pxNext %#x \r\n", (int)(ListItem1.pxNext));
printf("ListItem1->pxPrevious %#x \r\n", (int)(ListItem1.pxPrevious));
printf("ListItem2 %#x \r\n", (int)&ListItem2);
printf("ListItem2->pxNext %#x \r\n", (int)(ListItem2.pxNext));
printf("ListItem2->pxPrevious %#x \r\n", (int)(ListItem2.pxPrevious));
printf("ListItem3 %#x \r\n", (int)&ListItem3);
printf("ListItem3->pxNext %#x \r\n", (int)(ListItem3.pxNext));
printf("ListItem3->pxPrevious %#x \r\n", (int)(ListItem3.pxPrevious));
printf("/******************变量和值******************/\r\n");
printf("变量名 变量值 \r\n");
printf("TestList->uxNumberOfItems %ld \r\n", TestList.uxNumberOfItems);
printf("TestList->pxIndex %#x \r\n", (int)(TestList.pxIndex));
printf("TestList->xListEnd->xItemValue %#x \r\n", TestList.xListEnd.xItemValue);
printf("ListItem1->xItemValue %d \r\n", ListItem1.xItemValue);
printf("ListItem2->xItemValue %d \r\n", ListItem2.xItemValue);
printf("ListItem3->xItemValue %d \r\n", ListItem3.xItemValue);
printf("/******************* end ********************/\r\n");
printf("\r\n");
} static void SystemInitial(void)
{
/*组4,16级抢占优先级,无响应优先级*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); DelayInitial();
USART1_Initialization();
GPIO_LED_Configuration();
} int main(void)
{
SystemInitial(); /*创建开始任务*/
xTaskCreate((TaskFunction_t )StartTask, /*任务函数*/
(const char * )"StartTask", /*任务名称*/
(uint16_t )START_STK_SIZE, /*任务堆栈大小*/
(void * )NULL, /*传递给任务函数的参数*/
(UBaseType_t )START_TASK_PRIO, /*任务优先级*/
(TaskHandle_t * )&StartTask_Handle); /*任务句柄*/ /*开启任务调度*/
vTaskStartScheduler();
} /***************************END OF FILE***************************/
2.main.h
/**/
#ifndef __MAIN_H__
#define __MAIN_H__ #define LED_POWER GPIO_Pin_2 /*PE2*/ #define LED_Power_On() GPIO_ResetBits(GPIOE, LED_POWER) #endif /*__MAIN_H__*/ /***************************END OF FILE***************************/
3.sys.c
/**/
#include "sys.h"
#include "stdio.h" #pragma import(__use_no_semihosting)
//标准库需要的支持函数
struct __FILE
{
int handle; }; FILE __stdout;
//定义_sys_exit()以避免使用半主机模式
void _sys_exit(int x)
{
x = x;
}
/* //重定义fputc函数
int fputc(int ch, FILE *f)
{
while((USART1->SR&0X40)==0) //循环发送,直到发送完毕
USART1->DR = (u8) ch;
return ch;
} */ /***************************END OF FILE***************************/
4.sys.h
/**/
#ifndef __SYS_H__
#define __SYS_H__ /*0不支持OS,1支持OS*/
#define SYSTEM_SUPPORT_OS 1 /*定义系统文件夹是否支持OS*/ #endif /*__SYS_H__*/ /***************************END OF FILE***************************/
5.delay.c
/**/
#include "delay.h"
#include "sys.h"
/*如果需要使用OS,则包括下面的头文件即可*/
#if SYSTEM_SUPPORT_OS
#include "FreeRTOS.h"
#include "task.h"
#endif __IO uint32_t TimingDelay; //////////////////////////
static uint8_t fac_us = ;
////////////////////////// /***** 声明 *****/
extern void xPortSysTickHandler(void); /*systick中断服务函数,使用FreeRTOS时用到*/
void SysTick_Handler(void)
{
TimingDelayDecrement(); if(xTaskGetSchedulerState()!=taskSCHEDULER_NOT_STARTED) /*系统已运行*/
{
xPortSysTickHandler();
}
} void DelayInitial(void)
{
/*
* SystemCoreClock / 1000 1ms中断一次
* SystemCoreClock / 100000 10us中断一次
* SystemCoreClock / 1000000 1us中断一次
*/
if (SysTick_Config(SystemCoreClock / ))
{
while ();
}
/*关闭systick timer定时器*/
/* SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;*/ /*使能滴答定时器*/
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
} void DelayNus(uint32_t nus)
{
uint32_t ticks;
uint32_t told, tnow, tcnt = ;
uint32_t reload = SysTick->LOAD; fac_us = SystemCoreClock / ;
ticks = nus * fac_us;
told = SysTick->VAL; while ()
{
tnow = SysTick->VAL;
if (tnow != told)
{
if (tnow < told)
{
tcnt += told - tnow;
}
else
{
tcnt += reload - tnow + told;
}
told = tnow;
if (tcnt >= ticks) break;
}
}
} /*不会引起调度*/
void DelayXms(uint32_t nms)
{
uint32_t i; for (i=;i<nms;++i)
{
DelayNus();
}
} /*
* 本函数在中断函数中调用,滴答定时器中断一次调用一次。
*/
void TimingDelayDecrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
} /*
* TimingDelay值在TimingDelayDecrement函数中递减
*/
void DelayNms(uint32_t nTimes)
{
TimingDelay = nTimes; while (TimingDelay!=); //等待计数停止
} /***************************END OF FILE***************************/
6.delay.h
/**/
#ifndef __DELAY_H__
#define __DELAY_H__ #include "stm32f2xx.h" #include <stdint.h> extern void DelayInitial(void);
extern void TimingDelayDecrement(void);
extern void DelayNms(uint32_t nTimes); /////////////////////////
extern void DelayXms(uint32_t nms);
///////////////////////// #endif /*__DELAY_H__*/
/***************************END OF FILE***************************/
7.usart.c
/*
* USART1: 中断优先级选择第4组, 3级抢占优先级 无响应优先级
*/
#include "usart.h"
#include "stdio.h" /*printf*/
#include "stm32f2xx.h"
#include "stm32f2xx_gpio.h"
#include "stm32f2xx_rcc.h"
#include "stm32f2xx_usart.h" uint8_t USART1_RxBuffer[USART1_RECEIVE_SIZE];
uint8_t Flag_USART1Receive = ;
uint8_t USART1_ReceiveCount = ;
uint8_t USART1_ReceiveIndex = ; void USART1_Initialization(void)
{
USART1_GPIO_Configuration();
USART1_NVIC_Configuration();
/*USART1使能接收中断*/
// USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
/*USART1使能发送中断*/
/* USART_ITConfig(USART1, USART_IT_TXE, ENABLE); */
}
/*
*/
void USART1_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOA, , GPIO_AF_USART1); /*GPIO连接到串口1上,PA9-TXD*/
GPIO_PinAFConfig(GPIOA, , GPIO_AF_USART1); /*GPIO连接到串口1上,PA10-RXD*/ /*tx, PA9*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure); /*rx, PA10*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure); /*配置波特率9600*/
USART_InitStructure.USART_BaudRate = ;
/*配置串口的模式。为了配置双线全双工通讯,需要把Rx和Tx模式都开启. Tx发送使能和Rx接收使能*/
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/*无奇偶校验*/
USART_InitStructure.USART_Parity = USART_Parity_No;
/*1停止位*/
USART_InitStructure.USART_StopBits = USART_StopBits_1;
/*配置串口传输字长8位*/
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
/*不采用硬件流控制*/
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
/*向寄存器写入配置参数*/
USART_Init(USART1, &USART_InitStructure);
/*使能USART1外设。在使用外设时,不仅要使能其时钟,还要调用此函数使能外设才可以正常使用*/
USART_Cmd(USART1, ENABLE);
} //void USART1_SendNChar(uint8_t *str, uint8_t n)
//{
// /*发送区是否为空*/
// while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
//
// while (n--)
// {
// USART_SendData(USART1, (uint8_t)(*str++));
// /*是否发送完成*/
// while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
// }
//} /*
* 如果一次发送多个字节数据,可能会多次进入此函数
* 调用时,应先延时几十毫秒,确保把数据都接收完
*/
//void USART1_ReceiveIRQ(void)
//{
// /*如果寄存器中有数据*/
// while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == SET)
// {
// USART1_RxBuffer[USART1_ReceiveIndex++] = USART_ReceiveData(USART1);
// USART1_ReceiveCount++;
// }
//
// Flag_USART1Receive = 1;
//} void USART1_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure; /*中断优先级选择第1组*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); /*3级抢占优先级 0级响应优先级*/
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = ;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} /*重定义fputc函数 2种方法都可以*/
/*
int fputc(int ch,FILE *f)
{
while(USART_GetFlagStatus(USART1,USART_FLAG_TC) != SET);
USART_SendData(USART1,(uint8_t)ch);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC) != SET); return (ch);
}
*/ int fputc(int ch, FILE *f)
{
while((USART1->SR&0X40)==) /*循环发送,直到发送完毕*/
{} USART1->DR = (uint8_t)ch;
return ch;
}
/***************************END OF FILE***************************/
8.usart.h
/*
*
*/
#ifndef __USART_H__
#define __USART_H__ #include <stdint.h> /* uint8_t */ #define USART1_RECEIVE_SIZE 20 void USART1_Initialization(void);
void USART1_GPIO_Configuration(void);
void USART1_SendNChar(uint8_t *str, uint8_t n);
void USART1_ReceiveIRQ(void);
void USART1_NVIC_Configuration(void); #endif /*__USART_H__*/ /***************************END OF FILE***************************/
说明:
在串口中断助手中,打印完字符后,接着显示:Error:..\FreeRTOS\portable\RVDS\ARM_CM3\port.c,202 网上一般说是串口的中断优先级低于FreeRTOS的优先级,但是我设置FreeRTOS中可管理的最高中断优先级为5,
串口中断优先级为3,还是会出现这个问题。并且我也没有用串口的中断服务函数。 打印结果:
/**************列表和列表项地址**************/
项目 地址
TestList 0x200000ac
TestList->pxIndex 0x200000b4
TestList->xListEnd 0x200000b4
TestList->xListEnd->xItemValue 0x200000b4
TestList->xListEnd->pxNext 0x200000b4
TestList->xListEnd->pxPrevious 0x200000b4
ListItem1 0x200000c0
ListItem2 0x200000d4
ListItem3 0x200000e8
/******************变量和值******************/
变量名 变量值
TestList->uxNumberOfItems 0
TestList->pxIndex 0x200000b4
TestList->xListEnd->xItemValue 0xffffffff
ListItem1->xItemValue 0
ListItem2->xItemValue 0
ListItem3->xItemValue 0
/******************* end ********************/
/**************列表和列表项地址**************/
项目 地址
TestList 0x200000ac
TestList->pxIndex 0x200000b4
TestList->xListEnd 0x200000b4
TestList->xListEnd->xItemValue 0x200000b4
TestList->xListEnd->pxNext 0x200000c0
TestList->xListEnd->pxPrevious 0x200000c0
ListItem1 0x200000c0
ListItem1->pxNext 0x200000b4
ListItem1->pxPrevious 0x200000b4
ListItem2 0x200000d4
ListItem3 0x200000e8
/******************变量和值******************/
变量名 变量值
TestList->uxNumberOfItems 1
TestList->pxIndex 0x200000b4
TestList->xListEnd->xItemValue 0xffffffff
ListItem1->xItemValue 40
ListItem2->xItemValue 0
ListItem3->xItemValue 0
/******************* end ********************/
/**************列表和列表项地址**************/
项目 地址
TestList 0x200000ac
TestList->pxIndex 0x200000b4
TestList->xListEnd 0x200000b4
TestList->xListEnd->xItemValue 0x200000b4
TestList->xListEnd->pxNext 0x200000c0
TestList->xListEnd->pxPrevious 0x200000d4
ListItem1 0x200000c0
ListItem1->pxNext 0x200000d4
ListItem1->pxPrevious 0x200000b4
ListItem2 0x200000d4
ListItem2->pxNext 0x200000b4
ListItem2->pxPrevious 0x200000c0
ListItem3 0x200000e8
/******************变量和值******************/
变量名 变量值
TestList->uxNumberOfItems 2
TestList->pxIndex 0x200000b4
TestList->xListEnd->xItemValue 0xffffffff
ListItem1->xItemValue 40
ListItem2->xItemValue 60
ListItem3->xItemValue 0
/******************* end ********************/
/**************列表和列表项地址**************/
项目 地址
TestList 0x200000ac
TestList->pxIndex 0x200000b4
TestList->xListEnd 0x200000b4
TestList->xListEnd->xItemValue 0x200000b4
TestList->xListEnd->pxNext 0x200000c0
TestList->xListEnd->pxPrevious 0x200000d4
ListItem1 0x200000c0
ListItem1->pxNext 0x200000e8
ListItem1->pxPrevious 0x200000b4
ListItem2 0x200000d4
ListItem2->pxNext 0x200000b4
ListItem2->pxPrevious 0x200000e8
ListItem3 0x200000e8
ListItem3->pxNext 0x200000d4
ListItem3->pxPrevious 0x200000c0
/******************变量和值******************/
变量名 变量值
TestList->uxNumberOfItems 3
TestList->pxIndex 0x200000b4
TestList->xListEnd->xItemValue 0xffffffff
ListItem1->xItemValue 40
ListItem2->xItemValue 60
ListItem3->xItemValue 50
/******************* end ********************/
/**************列表和列表项地址**************/
项目 地址
TestList 0x200000ac
TestList->pxIndex 0x200000b4
TestList->xListEnd 0x200000b4
TestList->xListEnd->xItemValue 0x200000b4
TestList->xListEnd->pxNext 0x200000c0
TestList->xListEnd->pxPrevious 0x200000e8
ListItem1 0x200000c0
ListItem1->pxNext 0x200000e8
ListItem1->pxPrevious 0x200000b4
ListItem2 0x200000d4
ListItem2->pxNext 0x200000b4
ListItem2->pxPrevious 0x200000e8
ListItem3 0x200000e8
ListItem3->pxNext 0x200000b4
ListItem3->pxPrevious 0x200000c0
/******************变量和值******************/
变量名 变量值
TestList->uxNumberOfItems 2
TestList->pxIndex 0x200000b4
TestList->xListEnd->xItemValue 0xffffffff
ListItem1->xItemValue 40
ListItem2->xItemValue 60
ListItem3->xItemValue 50
/******************* end ********************/
/**************列表和列表项地址**************/
项目 地址
TestList 0x200000ac
TestList->pxIndex 0x200000c0
TestList->xListEnd 0x200000b4
TestList->xListEnd->xItemValue 0x200000b4
TestList->xListEnd->pxNext 0x200000d4
TestList->xListEnd->pxPrevious 0x200000e8
ListItem1 0x200000c0
ListItem1->pxNext 0x200000e8
ListItem1->pxPrevious 0x200000d4
ListItem2 0x200000d4
ListItem2->pxNext 0x200000c0
ListItem2->pxPrevious 0x200000b4
ListItem3 0x200000e8
ListItem3->pxNext 0x200000b4
ListItem3->pxPrevious 0x200000c0
/******************变量和值******************/
变量名 变量值
TestList->uxNumberOfItems 3
TestList->pxIndex 0x200000c0
TestList->xListEnd->xItemValue 0xffffffff
ListItem1->xItemValue 40
ListItem2->xItemValue 60
ListItem3->xItemValue 50
/******************* end ********************/
/**************列表和列表项地址**************/
项目 地址
TestList 0x200000ac
TestList->pxIndex 0x200000d4
TestList->xListEnd 0x200000b4
TestList->xListEnd->xItemValue 0x200000b4
TestList->xListEnd->pxNext 0x200000d4
TestList->xListEnd->pxPrevious 0x200000e8
ListItem1 0x200000c0
ListItem1->pxNext 0x200000e8
ListItem1->pxPrevious 0x200000d4
ListItem2 0x200000d4
ListItem2->pxNext 0x200000e8
ListItem2->pxPrevious 0x200000b4
ListItem3 0x200000e8
ListItem3->pxNext 0x200000b4
ListItem3->pxPrevious 0x200000d4
/******************变量和值******************/
变量名 变量值
TestList->uxNumberOfItems 2
TestList->pxIndex 0x200000d4
TestList->xListEnd->xItemValue 0xffffffff
ListItem1->xItemValue 40
ListItem2->xItemValue 60
ListItem3->xItemValue 50
/******************* end ********************/
FreeRTOS-04列表和列表项的更多相关文章
- FreeRTOS列表和列表项
FreeRTOS中的列表和列表项类似于数据结构中的链表和节点: 相关的文件是list.c和list.h两个文件: List_t列表结构体 具体定义如下: /* * Definition of the ...
- React 点击删除列表中对应项(React 获取DOM中自定义属性)
点击删除按钮,删除列表中对应项本来是React比较基础的应用,可是应用情况变得复杂了以后,我还真想了一会儿才搞定. 简化一下应用场景:点击新增按钮,增加一条输入框,点击输入框旁边的按钮,删除该输入框( ...
- SharePoint REST API - 列表和列表项
博客地址:http://blog.csdn.net/FoxDave 本篇主要讲述如何用SharePoint REST操作列表和列表项.阅读本篇时请先了解前面讲述的REST介绍和基本操作. 废话不多 ...
- 跟我学SharePoint 2013视频培训课程——怎样创建列表和列表项(7)
课程简介 第7天,怎样在SharePoint 2013中创建列表和列表项 视频 SharePoint 2013 交流群 41032413
- MFC CListCtrl 将一个列表的选中项添加到另一个列表
MFC CListCtrl 将一个列表的选中项添加到另一个列表, 用VC6.0实现: 简单记录一下自己的学习历程, 和大家分享,如果对你有用,我很高兴. 1.新建一个基于对话框的工程(Dialog-B ...
- 使用jQuery 中的显示与隐藏动画效果实现折叠下拉菜单的收缩和展开,在页面的列表中有若干项,列表的每项中有一个二级列表,二级列表默认为隐藏状态。点击列表的项,切换二级列表的显示或隐藏状态
查看本章节 查看作业目录 需求说明: 使用jQuery 中的显示与隐藏动画效果实现折叠下拉菜单的收缩和展开,在页面的列表中有若干项,列表的每项中有一个二级列表,二级列表默认为隐藏状态.点击列表的项,切 ...
- HTML&CSS基础学习笔记1.14—有序列表及列表嵌套
我们上篇讲到了无序列表,那么今天就来看看有序列表和他们的组合嵌套使用吧. 有序列表 现在我们要做那堆杂事了,但是发现这么多杂事,先做哪个好呢?于是我们给这堆杂事弄个优先级排序,让我们能够按照顺序做下去 ...
- 《Python CookBook2》 第四章 Python技巧 - 若列表中某元素存在则返回之 && 在无须共享引用的条件下创建列表的列表
若列表中某元素存在则返回之 任务: 你有一个列表L,还有一个索引号i,若i是有效索引时,返回L[i],若不是,则返回默认值v 解决方案: 列表支持双向索引,所以i可以为负数 >>> ...
- Excel列表部分列表隐藏与取消隐藏
Excel列表部分列表隐藏与取消隐藏 2014-2-19 隐藏:选中需要隐藏的列(选中A.B.C....),右键单击所选部分,选择"隐藏"即可. 取消隐藏:从A选中至所见表格最后的 ...
随机推荐
- 4619 Warm up 2
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ][]; ...
- centos7设置、查看、删除环境变量的方法
centos查看环境变量与设置环境变量在使用过程中很常见,本文整理了一些常用的与环境变量相关的命令,感兴趣的朋友可以参考下希望对你有所帮助 1. 显示环境变量HOME(红色部分代表要输入的命令,不要把 ...
- Inno Setup创建快捷方式跟快速运行栏快捷方式
[Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescrip ...
- [GO]使用select实现超时
package main import ( "fmt" "time" ) func main() { ch := make(chan int) quit := ...
- nignx ssl 配置
1. 找一个目录,例如: usr/local/nginx/ssl ,进入该目录 2. openssl genrsa -des3 -out server.key 1024 创建自身秘钥 3. op ...
- kcp流模式与消息模式对比
kcp的流模式,和消息模式 流模式: 更高的网络利用率 更大的传输速度 解析数据相对更复杂 消息模式: 更小的网络利用率 更小的传输速度 解析数据相对更简单 消息模式的示意图 http://www.p ...
- js流程图:aworkflow.js
auto-workflow 用于快速构建各种关系图的库 github地址:https://github.com/auto-workflow/AWorkflow 快速开始 npm install awo ...
- css3的那些高级选择器二
在上个星期我介绍了css3的属性选择器,伪类选择器和结构伪类选择器,今天楼主继续把其它的css3选择器说完. 在css3中,共有11中UI状态伪类选择器,分别是E:hover,E:active,E:f ...
- Appium 简介及工作原理
申请:本文介绍主要是针对Android. 1.什么是Appium: Appium是一个开源.跨平台的测试框架,可以用来测试原生及混合的移动端应用.Appium支持IOS.Android及Firefox ...
- CodeForces 408E Curious Array(组合数学+差分)
You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, ...