FreeRTOS内核API速览
 
 - 信号量
 -  
  
 - 消息队列
 -  
  
 - 软件定时器
 - 创建定时器
 - 启动定时器
 - 停止定时器
 - 复位定时器
 - 删除定时器
 - 改变定时器周期
 - 其他操作函数
 
 
  - 任务通知
 -  
  
 - 错误排查
 - 其他
 - 汇总图
 
 
  
 
 
 
 信号量
 
 
创建信号量
 
计数信号量
 
【动态】SemaphoreHandle_t xSemaphoreCreateCounting(uxMaxCount,uxInitialCount);
【静态】SemaphoreHandle_t xSemaphoreCreateCountingStatic(uxMaxCount,uxInitialCount,*pxSemaphoreBuffer);
uxMaxCount        : 最大计数值
uxInitialCount    : 初始计数值
pxSemaphoreBuffer : 计数信号量控制块缓存
xSemaphoreHandle  : 信号量句柄
 
互斥信号量
 
【动态】xSemaphoreHandle xSemaphoreCreateMutex(void);
【静态】SemaphoreHandle_t xSemaphoreCreateMutexStatic(*pxMutexBuffer);
pxMutexBuffer    : 互斥信号量控制块缓存
xSemaphoreHandle : 信号量句柄
 
二值信号量
 
【动态】void vSemaphoreCreateBinary(xSemaphore);
	    SemaphoreHandle_t xSemaphoreCreateBinary(void);
【静态】SemaphoreHandle_t xSemaphoreCreateBinaryStatic(*pxSemaphoreBuffer);
SemaphoreHandle_t xSemaphore : 信号量句柄
pxSemaphoreBuffer            : 二值信号量控制块缓存
 
释放信号量
 
任务模式
 
BaseType_t xSemaphoreGive(xSemaphore);
xSemaphore : 信号量句柄
 
中断模式
 
【互斥信号量不能使用该函数】
BaseType_t xSemaphoreGiveFromISR(xSemaphore,*pxHigherPriorityTaskWoken);
xSemaphore                : 信号量句柄
pxHigherPriorityTaskWoken : 高优先级任务,为TRUE退出中断前进行上下文切换portSWITCH_CONTEXT()
 
获取信号量
 
任务模式
 
BaseType_t xSemaphoreTake(xSemaphore,xBlockTime);
xSemaphore : 信号量句柄
xBlockTime : 阻塞时间
 
中断模式
 
【互斥信号量不能使用该函数】
BaseType_t xSemaphoreTakeFromISR(xSemaphore, pxHigherPriorityTaskWoken);
xSemaphore                : 信号量句柄
pxHigherPriorityTaskWoken : 高优先级任务,为TRUE退出中断前进行上下文切换portSWITCH_CONTEXT()
 
 
 
 
 
 消息队列
 
 
创建队列
 
【动态】QueueHandle_t xQueueCreate(uxQueueLength,uxItemSize);
【静态】QueueHandle_t xQueueCreateStatic(uxQueueLength,uxItemSize,*pucQueueStorageBuffer,*pxQueueBuffer);
 uxQueueLength         : 队列最大存储量,即队列深度
 uxItemSize            : 队列数据大小,即队列项大小,单位字节
 pucQueueStorageBuffer : 队列元素存储缓存
 pxQueueBuffer         : 消息队列控制块缓存
 QueueHandle_t         : 队列句柄
 
发送消息
 
任务模式
 
BaseType_t xQueueSendToBack(xQueue,*pvItemToQueue,xTicksToWait);  
BaseType_t xQueueSendToFront(xQueue,*pvItemToQueue,xTicksToWait); 
BaseType_t xQueueSend(xQueue,*pvItemToQueue,xTicksToWait);        
xQueue        : 队列句柄
pvItemToQueue : 发送数据(消息)指针
xTicksToWait  : 队列已满阻塞时间,为0不阻塞,为portMAX_DELAY一直阻塞直到队列不满
 
中断模式
 
xQueueSendToBackFromISR(xQueue,*pvItemToQueue,*pxHigherPriorityTaskWoken);  
xQueueSendToFrontFromISR(xQueue,*pvItemToQueue,*pxHigherPriorityTaskWoken); 
xQueue                    : 队列句柄
pvItemToQueue             : 发送数据指针
pxHigherPriorityTaskWoken : 高优先级任务,为TRUE退出中断前进行上下文切换
 
获取消息
 
任务模式
 
xQueueReceive(xQueue,*pvBuffer,xTicksToWait); 
xQueuePeek(xQueue,*pvBuffer,xTicksToWait);    
xQueue       : 队列句柄
pvBuffer     : 接收消息缓存
xTicksToWait : 阻塞时间
 
中断模式
 
xQueueReceiveFromISR(xQueue,*pvBuffer,*pxHigherPriorityTaskWoken);
xQueue                    : 队列句柄
pvBuffer                  : 接收消息缓存
pxHigherPriorityTaskWoken : 高优先级任务,为TRUE退出中断前进行上下文切换
 
 
 
 
 
 软件定时器
 
 
创建定时器
 
【动态】TimerHandle_t xTimerCreate(*pcTimerName,xTimerPeriodInTicks,uxAutoReload,*pvTimerID,pxCallbackFunction);
【静态】TimerHandle_t xTimerCreateStatic(*pcTimerName,xTimerPeriodInTicks,uxAutoReload,*pvTimerID,pxCallbackFunction,*pxTimerBuffer);
pcTimerName         : 名称                                                         
xTimerPeriodInTicks : 周期
uxAutoReload        : 模式,pdTRUE周期,pdFALSE单次            
pvTimerID           : ID,在多个定时器使用同一个回调函数中使用
pxCallbackFunction  : 回调函数                                          
pxTimerBuffer       : 定时器控制块指针
TimerHandle_t       : 定时器句柄
 
启动定时器
 
【任务模式】BaseType_t xTimerStart(xTimer,xTicksToWait);
【中断模式】BaseType_t xTimerStartFromISR(xTimer,*pxHigherPriorityTaskWoken);
xTimer                    : 定时器句柄
xTicksToWait              : 阻塞时间
pxHigherPriorityTaskWoken : 高优先级任务,为TRUE退出中断前进行上下文切换
 
停止定时器
 
【任务模式】BaseType_t xTimerStop(xTimer,xTicksToWait);
【中断模式】BaseType_t xTimerStopFromISR(xTimer,*pxHigherPriorityTaskWoken);
xTimer                    : 定时器句柄
xTicksToWait              : 阻塞时间
pxHigherPriorityTaskWoken : 高优先级任务,为TRUE退出中断前进行上下文切换
 
复位定时器
 
【任务模式】BaseType_t xTimerReset(xTimer,xTicksToWait);
【中断模式】BaseType_t xTimerResetFromISR(xTimer,*pxHigherPriorityTaskWoken);
xTimer                    : 定时器句柄
xTicksToWait              : 阻塞时间
pxHigherPriorityTaskWoken : 高优先级任务,为TRUE退出中断前进行上下文切换
 
删除定时器
 
【任务模式】BaseType_t xTimerDelete(xTimer,xTicksToWait);
xTimer       : 定时器句柄
xTicksToWait : 阻塞时间
 
改变定时器周期
 
【任务模式】BaseType_t xTimerChangePeriod(xTimer,xNewPeriod,xTicksToWait);
【中断模式】BaseType_t xTimerChangePeriodFromISR(xTimer,xNewPeriod,*pxHigherPriorityTaskWoken);
xTimer                    : 定时器句柄
xTicksToWait              : 阻塞时间
pxHigherPriorityTaskWoken : 高优先级任务,为TRUE退出中断前进行上下文切换
 
其他操作函数
 
BaseType_t xTimerIsTimerActive(xTimer);  
void *pvTimerGetTimerID(xTimer);         
void vTimerSetTimerID(xTimer,*pvNewID);  
const char * pcTimerGetName(xTimer);     
TickType_t xTimerGetPeriod(xTimer);      
TickType_t xTimerGetExpiryTime(xTimer);  
BaseType_t  xTimerGetReloadMode(xTimer); 
UBaseType_t uxTimerGetReloadMode(xTimer);
 
 
 
 
 
 任务通知
 
 
发送通知
 
任务模式
 
【任务模式】BaseType_t xTaskNotifyGive(xTaskToNotify);
【任务模式】BaseType_t xTaskNotify(xTaskToNotify,ulValue,eAction);
xTaskToNotify             : 目标任务句柄
ulValue                   : 更新目标任务的通知值
eAction                   : 通知值操作方式。
eNoAction                 :不更新通知值,不使用ulValue(模拟二值信号量)
eSetBits                  : 目标任务的通知值与ulValue按位或运算(模拟事件标志组)
eIncrement                : 目标任务的通知值自增1,不使用ulValue(模拟计数信号量)
eSetValueWithOverwrite    : 将目标任务的通知值设置为ulValue(模拟消息队列)
eSetValueWithoutOrwrite   : 若目标任务没有挂起通知通知值设置为ulValue,若目标任务挂起不会更新通知值。
 
中断模式
 
【中断模式】void vTaskNotifyGiveFromISR(xTaskToNotify, *pxHigherPriorityTaskWoken);
xTaskToNotify             : 目标任务句柄
pxHigherPriorityTaskWoken : 高优先级任务切换,为pdTRUE退出中断前进行上下文切换portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);
 
获取通知
 
uint32_t ulTaskNotifyTake(xClearCountOnExit,xTicksToWait);
xClearCountOnExit : 退出清除通知。若收到任务通知且为pdFALSE,则退出之前递减通知值,等同于递减计数信号量值,若收到任务通知且为pdTRUE,则退出之前清除通知值,等同于二进制信号量。
xTicksToWait      : 在阻塞状态下等待接收通知的最长时间
 
BaseType_t xTaskNotifyWait(ulBitsToClearOnEntry,ulBitsToClearOnExit,*pulNotificationValue,xTicksToWait);
ulBitsToClearOnEntry : 进入函数时需要清除的通知位
ulBitsToClearOnExit  : 退出函数时需要清除的通知位
pulNotificationValue : 指向一个变量的指针,用于获取通知值
xTicksToWait         : 等待通知的超时时间,单位为Tick
 
 
 
 
 
 错误排查
 
 
获取任务栈剩余大小
UBaseType_t uxTaskGetStackHighWaterMark(xTask);
xTask       : 任务句柄
UBaseType_t : 剩余大小,单位4字节,typedef unsigned long UBaseType_t;
 
栈溢出钩子函数
void vApplicationStackOverflowHook(xTask,*pcTaskName);
xTask      : 任务句柄
pcTaskName : 任务名称
 
TickType_t xTaskGetTickCount(void);           
TaskHandle_t xTaskGetCurrentTaskHandle(void); 
void vTaskGetRunTimeStats(*pcWriteBuffer);    
 
 
 
 
 
 其他
 
 
当前任务控制块指针
pxCurrentTCB
 
临界区代码保护
taskENTER_CRITICAL() 
taskEXIT_CRITICAL()  
 
上下文切换 
portSWITCH_CONTEXT();
portYIELD_FROM_ISR();
 
 
 汇总图
 
 
