262 lines
8.7 KiB
Plaintext
262 lines
8.7 KiB
Plaintext
1、BaseType_t xTaskAbortDelay( TaskHandle_t xTask ); 主要用来强制将一个阻塞的进程进入运行模式,
|
||
|
||
2、BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,TickType_t * const pxTicksToWait ); 神奇的功能,
|
||
配合 vTaskSetTimeOutState( &xTimeOut );
|
||
|
||
主要用来处理在一个确定延时等待过程中,反复进入和退出等待过程,用来精确校准总的延时时间使用,例子
|
||
|
||
size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
|
||
{
|
||
size_t uxReceived = 0;
|
||
TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
|
||
TimeOut_t xTimeOut;
|
||
|
||
vTaskSetTimeOutState( &xTimeOut );
|
||
|
||
while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
|
||
{
|
||
if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
|
||
{
|
||
|
||
break;
|
||
}
|
||
|
||
ulTaskNotifyTake( pdTRUE, xTicksToWait );
|
||
}
|
||
|
||
uxReceived = UART_read_from_receive_buffer( pxUARTInstance, pucBuffer, uxWantedBytes );
|
||
return uxReceived;
|
||
}
|
||
|
||
此例子实现总的等待时间 MAX_TIME_TO_WAIT, 当接收的字节总数没有达到要求时,uxWantedBytes ,进入等待过程,当有新数据接收成功,退出等待,检测是否满足接收条件,知道满足接收条件,或者接收超时,完成整个过程。
|
||
|
||
3、xTaskCreateStatic() 创建任务时由程序员指定任务的堆栈空间,不由系统自动分配
|
||
|
||
4、void vTaskDelayUntil( TickType_t *pxPreviousWakeTime, TickType_t xTimeIncrement );
|
||
void vTaskDelay( TickType_t xTicksToDelay );
|
||
|
||
vTaskDelayUntil 与 vTaskDelay的主要区别在于计数的起始时间不一样,vTaskDelay是从调用时算开始时间,vTaskDelayUntil是*pxPreviousWakeTime的值人为指定的开始时间。
|
||
|
||
5、 vTaskDelete() 删除任务
|
||
|
||
6、taskDISABLE_INTERRUPTS()
|
||
如果使用了configMAX_SYSCALL_INTERRUPT_PRIORITY/configMAX_API_CALL_INTERRUPT_PRIORITY,那么调用taskDISABLE_INTERRUPTS()将使低于 configMAX_SYSCALL_INTERRUPT_PRIORITY 优先级的中断无效,高于此优先级的中断不受影响。
|
||
如果不使用configMAX_SYSCALL_INTERRUPT_PRIORITY/configMAX_API_CALL_INTERRUPT_PRIORITY,那么调用taskDISABLE_INTERRUPTS()将使所有的中断无效。
|
||
|
||
taskDISABLE_INTERRUPTS() and taskENABLE_INTERRUPTS() 不支持嵌套,例如两次执行taskDISABLE_INTERRUPTS() ,只需要执行一次taskENABLE_INTERRUPTS() 就可使能所有中断。若要支持嵌套需要使用taskENTER_CRITICAL() and taskEXIT_CRITICAL()替代。
|
||
|
||
7、void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxTagValue );给任务分配一个标记号
|
||
TaskHookFunction_t pxTagValue 可以是一个钩子函数指针,可配合xTaskCallApplicationTaskHook()函数使用,调用任务钩子函数
|
||
要使用 vTaskSetApplicationTaskTag() configUSE_APPLICATION_TASK_TAG 必须为1
|
||
|
||
static BaseType_t prvExampleTaskHook( void * pvParameter )
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
void vAnotherTask( void *pvParameters )
|
||
{
|
||
|
||
vTaskSetApplicationTaskTag( NULL, prvExampleTaskHook );
|
||
for( ;; )
|
||
{
|
||
}
|
||
}
|
||
|
||
/* [As an example use of the hook (callback)] Define the traceTASK_SWITCHED_OUT()
|
||
macro to call the hook function. The kernel will then automatically call the task
|
||
hook each time the task is switched out. This technique can be used to generate
|
||
an execution trace. pxCurrentTCB references the currently executing task. */
|
||
#define traceTASK_SWITCHED_OUT() xTaskCallApplicationTaskHook( pxCurrentTCB, 0 )
|
||
|
||
|
||
8、vTaskSetThreadLocalStoragePointer() 为每个任务设置独立的存储空间,存储数据
|
||
configNUM_THREAD_LOCAL_STORAGE_POINTERS 存储空间大小受这个宏控制
|
||
|
||
|
||
|
||
9、void vTaskStepTick( TickType_t xTicksToJump );低功耗相关 use tickless idle functionality
|
||
|
||
configUSE_TICKLESS_IDLE = 1, 只有 systick 中断无效,只有idle task才能运行
|
||
|
||
portSUPPRESS_TICKS_AND_SLEEP() 从例子上来看,实现的功能为,关闭系统时钟,停止内核运行,在宏定义函数内部,使用vTaskStepTick()实现恢复后对时钟变量的补偿,或者说重新设置系统时间。
|
||
|
||
10、vTaskSuspend() 挂起任务,一个任务被挂起后,只有通过 vTaskResume()才能重新进入运行状态
|
||
FreeRTOS version 6.1.0 以后版本,vTaskSuspend()操作可以在 Scheduler 开始之前调用。
|
||
|
||
11、vTaskSuspendAll()禁止调度器工作,但不影响中断,调度器禁止工作的过程中,不允许调用系统API函数,
|
||
xTaskResumeAll() 恢复调度器工作,此功能嵌套工作。
|
||
|
||
12、taskYIELD() 用于时间片轮工作,在任务优先级相同的任务中,放弃自身的运行,让别的任务运行
|
||
|
||
|
||
xQueueCreateSet() 非常复杂的一个过程,
|
||
|
||
#define QUEUE_LENGTH_1 10
|
||
#define QUEUE_LENGTH_2 10
|
||
|
||
#define BINARY_SEMAPHORE_LENGTH 1
|
||
|
||
#define ITEM_SIZE_QUEUE_1 sizeof( uint32_t )
|
||
#define ITEM_SIZE_QUEUE_2 sizeof( something_else_t )
|
||
|
||
#define COMBINED_LENGTH ( QUEUE_LENGTH_1 + QUEUE_LENGTH_2 + BINARY_SEMAPHORE_LENGTH )
|
||
void vAFunction( void )
|
||
{
|
||
static QueueSetHandle_t xQueueSet;
|
||
QueueHandle_t xQueue1, xQueue2, xSemaphore;
|
||
QueueSetMemberHandle_t xActivatedMember;
|
||
uint32_t xReceivedFromQueue1;
|
||
something_else_t xReceivedFromQueue2;
|
||
|
||
xQueueSet = xQueueCreateSet( COMBINED_LENGTH );
|
||
|
||
xQueue1 = xQueueCreate( QUEUE_LENGTH_1, ITEM_SIZE_QUEUE_1 );
|
||
xQueue2 = xQueueCreate( QUEUE_LENGTH_2, ITEM_SIZE_QUEUE_2 );
|
||
|
||
xSemaphore = xSemaphoreCreateBinary();
|
||
|
||
xSemaphoreTake( xSemaphore, 0 );
|
||
|
||
xQueueAddToSet( xQueue1, xQueueSet );
|
||
xQueueAddToSet( xQueue2, xQueueSet );
|
||
xQueueAddToSet( xSemaphore, xQueueSet );
|
||
|
||
|
||
|
||
for( ;; )
|
||
{
|
||
|
||
xActivatedMember = xQueueSelectFromSet( xQueueSet, pdMS_TO_TICKS( 200 ) );
|
||
|
||
if( xActivatedMember == xQueue1 )
|
||
{
|
||
xQueueReceive( xActivatedMember, &xReceivedFromQueue1, 0 );
|
||
vProcessValueFromQueue1( xReceivedFromQueue1 );
|
||
}
|
||
else if( xActivatedQueue == xQueue2 )
|
||
{
|
||
xQueueReceive( xActivatedMember, &xReceivedFromQueue2, 0 );
|
||
vProcessValueFromQueue2( &xReceivedFromQueue2 );
|
||
}
|
||
else if( xActivatedQueue == xSemaphore )
|
||
{
|
||
xSemaphoreTake( xActivatedMember, 0 );
|
||
vProcessEventNotifiedBySemaphore();
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
13、vQueueDelete() 主要用法,创建队列不成功,删除队列
|
||
|
||
int main( void )
|
||
{
|
||
QueueHandle_t xQueue;
|
||
|
||
xQueue = xQueueCreate( QUEUE_LENGTH, QUEUE_ITEM_SIZE );
|
||
if( xQueue == NULL )
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
vQueueDelete( xQueue );
|
||
}
|
||
}
|
||
|
||
14、UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );查询队列中有多少条目,返回值为对列中条目数
|
||
|
||
15、BaseType_t xQueueOverwrite( QueueHandle_t xQueue, const void *pvItemToQueue ); 奇怪的应用,
|
||
xQueue 必须队列深度为1,对列不是满就是空,
|
||
|
||
16、xQueueReset()复位对列,清空对列中内容
|
||
|
||
17、 xQueueSend() = xQueueSendToBack()
|
||
|
||
18、uxQueueSpacesAvailable()获取对列空闲条目数
|
||
|
||
19、vSemaphoreCreateBinary()是老版本的,为了向后兼容性现在存在,应该使用 xSemaphoreCreateBinary()替换
|
||
|
||
20、xSemaphoreCreateCounting()创建多值得信号量
|
||
|
||
21、xSemaphoreCreateMutex()创建互斥信号量
|
||
|
||
22、xSemaphoreCreateRecursiveMutex()创建递归的互斥信号量,
|
||
|
||
23、xSemaphoreGetMutexHolder()获取使用信号量的任务的句柄
|
||
|
||
24、xTimerGetExpiryTime()获取定时器到时的时间
|
||
|
||
25、pcTimerGetName()获取定时器名称
|
||
|
||
26、xTimerGetPeriod()获取定时器周期
|
||
|
||
27、pvTimerGetTimerID()获取定时器ID,主要用于多个定时器使用同一个回调函数,判断输入参数 ID
|
||
|
||
28、xTimerIsTimerActive()判断定时器是否在工作
|
||
|
||
29、xTimerPendFunctionCall()用于回调函数的应用,基本不许人为参与
|
||
|
||
30、xTimerReset()若定时器不运行,调用后,定时器重新运行,定时器不能在调度器之前运行
|
||
|
||
If xTimerReset() is called before the scheduler is started, then the timer will not start running
|
||
until the scheduler has been started, and the timer’s expiry time will be relative to when the
|
||
scheduler started.
|
||
|
||
31、xEventGroupCreate()
|
||
The number of event bits in an event group is dependent on the configUSE_16_BIT_TICKS
|
||
compile time configuration constant within FreeRTOSConfig.h1:
|
||
? If configUSE_16_BIT_TICKS is 1, then each event group contains 8 usable event bits.
|
||
? If configUSE_16_BIT_TICKS is 0, then each event group contains 24 usable event bits.
|
||
|
||
|
||
|
||
EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
|
||
const EventBits_t uxBitsToSet,
|
||
const EventBits_t uxBitsToWaitFor,
|
||
TickType_t xTicksToWait );
|
||
|
||
此函数实现功能为,首先人为设置 event_group中 uxBitsToSet 位置为1,然后,等待 uxBitsToWaitFor位置的事件发生
|
||
|
||
EventBits_t xEventGroupWaitBits( const EventGroupHandle_t xEventGroup,
|
||
const EventBits_t uxBitsToWaitFor,
|
||
const BaseType_t xClearOnExit,
|
||
const BaseType_t xWaitForAllBits,
|
||
TickType_t xTicksToWait );
|
||
|
||
此函数实现功能为 等待uxBitsToWaitFor事件,xWaitForAllBits,决定是否等待全部事件发生,还是等待uxBitsToWaitFor位置事件发生
|
||
|
||
xEventGroupSync(), xEventGroupWaitBits() 两个函数的功能很接近,稍有差别
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
32、 configCHECK_FOR_STACK_OVERFLOW 任务堆栈溢出检测
|
||
|
||
33、configCPU_CLOCK_HZ
|
||
|
||
34、configTICK_RATE_HZ 设置系统时钟中断频率
|
||
|
||
35、configTIMER_QUEUE_LENGTH 定时器命令处理对列的深度,即能保存未处理的命令的数量
|
||
|
||
36、configTOTAL_HEAP_SIZE 设置系统使用的堆栈大小,系统是静态分配时,使用 heap1.c heap2.c heap4.c
|
||
|
||
37、configUSE_16_BIT_TICKS = 0; TickType_t 为16 bits 数据类型 configUSE_16_BIT_TICKS = 1;TickType_t 为32 bits 数据类型
|
||
|
||
37、configUSE_COUNTING_SEMAPHORES 允许创建多值信号量
|
||
|
||
38、configUSE_MUTEXES 允许创建互斥信号量
|
||
|
||
|
||
INCLUDE_uxTaskGetStackHighWaterMark == 1 prvTaskCheckFreeStackSpace() 可以用来读取单个任务使用过程中最少的剩余空间
|
||
xPortGetFreeHeapSize() 可以用来统计总堆栈剩余空间
|