根据正点原子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,还是会出现这个问题。并且我也没有用串口的中断服务函数。 打印结果:
1. 初始化列表和列表项
/**************列表和列表项地址**************/
项目                            地址         
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 ********************/
2. 插入ListItem1
/**************列表和列表项地址**************/
项目                            地址         
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 ********************/
3. 插入ListItem2
/**************列表和列表项地址**************/
项目                            地址         
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 ********************/
4. 插入ListItem3
/**************列表和列表项地址**************/
项目                            地址         
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 ********************/
5. 删除ListItem2
/**************列表和列表项地址**************/
项目                            地址         
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 ********************/
6. 末尾插入ListItem2
/**************列表和列表项地址**************/
项目                            地址         
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 ********************/
7. 删除ListItem1
/**************列表和列表项地址**************/
项目                            地址         
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列表和列表项的更多相关文章

  1. FreeRTOS列表和列表项

    FreeRTOS中的列表和列表项类似于数据结构中的链表和节点: 相关的文件是list.c和list.h两个文件: List_t列表结构体 具体定义如下: /* * Definition of the ...

  2. React 点击删除列表中对应项(React 获取DOM中自定义属性)

    点击删除按钮,删除列表中对应项本来是React比较基础的应用,可是应用情况变得复杂了以后,我还真想了一会儿才搞定. 简化一下应用场景:点击新增按钮,增加一条输入框,点击输入框旁边的按钮,删除该输入框( ...

  3. SharePoint REST API - 列表和列表项

    博客地址:http://blog.csdn.net/FoxDave 本篇主要讲述如何用SharePoint REST操作列表和列表项.阅读本篇时请先了解前面讲述的REST介绍和基本操作. 废话不多 ...

  4. 跟我学SharePoint 2013视频培训课程——怎样创建列表和列表项(7)

    课程简介 第7天,怎样在SharePoint 2013中创建列表和列表项 视频 SharePoint 2013 交流群 41032413

  5. MFC CListCtrl 将一个列表的选中项添加到另一个列表

    MFC CListCtrl 将一个列表的选中项添加到另一个列表, 用VC6.0实现: 简单记录一下自己的学习历程, 和大家分享,如果对你有用,我很高兴. 1.新建一个基于对话框的工程(Dialog-B ...

  6. 使用jQuery 中的显示与隐藏动画效果实现折叠下拉菜单的收缩和展开,在页面的列表中有若干项,列表的每项中有一个二级列表,二级列表默认为隐藏状态。点击列表的项,切换二级列表的显示或隐藏状态

    查看本章节 查看作业目录 需求说明: 使用jQuery 中的显示与隐藏动画效果实现折叠下拉菜单的收缩和展开,在页面的列表中有若干项,列表的每项中有一个二级列表,二级列表默认为隐藏状态.点击列表的项,切 ...

  7. HTML&CSS基础学习笔记1.14—有序列表及列表嵌套

    我们上篇讲到了无序列表,那么今天就来看看有序列表和他们的组合嵌套使用吧. 有序列表 现在我们要做那堆杂事了,但是发现这么多杂事,先做哪个好呢?于是我们给这堆杂事弄个优先级排序,让我们能够按照顺序做下去 ...

  8. 《Python CookBook2》 第四章 Python技巧 - 若列表中某元素存在则返回之 && 在无须共享引用的条件下创建列表的列表

    若列表中某元素存在则返回之 任务: 你有一个列表L,还有一个索引号i,若i是有效索引时,返回L[i],若不是,则返回默认值v 解决方案: 列表支持双向索引,所以i可以为负数 >>> ...

  9. Excel列表部分列表隐藏与取消隐藏

    Excel列表部分列表隐藏与取消隐藏 2014-2-19 隐藏:选中需要隐藏的列(选中A.B.C....),右键单击所选部分,选择"隐藏"即可. 取消隐藏:从A选中至所见表格最后的 ...

随机推荐

  1. xml与java代码相互装换的工具类

    这是一个java操作xml文件的工具类,最大的亮点在于能够通过工具类直接生成xml同样层次结构的java代码,也就是说,只要你定义好了xml的模板,就能一键生成java代码.省下了自己再使用工具类写代 ...

  2. python str, list,tuple, dir

    Python3 字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'Hello ...

  3. Sql优化,面试经验总结

    (1)列优先 如图有表A和表B 对其查询时,会有如下语句: select a.*,b.* from a,b where a.id = b.a_id; 注意from 后边的表名, a.如果多表查询是完全 ...

  4. (转)构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(5)-EF增删改查by糟糕的代码

    原文地址:http://www.cnblogs.com/ymnets/archive/2013/11/16/3426454.html 上一讲我们创建了一系列的解决方案,我们通过一个例子来看看层与层之间 ...

  5. Digital image processing(数字图像处理)

    In computer science, digital image processing is the use of computer algorithms to perform image pro ...

  6. mysql 查询条件

    1简单查询   select* from 表名 select name as“姓名”fromstu     (把name改为名字) 2条件查询 where 后面跟条件  条件要写清楚 3模糊查询  l ...

  7. jsp乱码的问题

    大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着大家,现把JSP开发中遇到的中文乱码的问题及解决办法写出来供大家参考.首先了解一下Java中文问题的由来: Java的内核和class文 ...

  8. Delphi xe5如何使用Bluestacks模拟器(用真机或者用猩猩,夜神模拟器,自带的不好用)

    首先,关于这个模拟器问题比较纠结,这是一个关于adb的问题. Delphi XE5会自动识别模拟器和真机,但是你必须先打开模拟器在打开Delphi IDE(Delphi开发环境),否则还得麻烦一会儿. ...

  9. [leetcode] 3. Pascal's Triangle

    第三道还是帕斯卡三角,这个是要求正常输出,题目如下: Given numRows, generate the first numRows of Pascal's triangle. For examp ...

  10. UniCode编码表及部分不可见字符过滤方案

    Unicode编码表/0000-0FFF 图例: Unicode 3.1 Unicode 1.0 Unicode 3.2 Unicode 1.1 Unicode 4.0 Unicode 2.0 Uni ...