赞
踩
图示,官方说明,The argument instances defines the number of times that osThreadCreate can be called for the same osThreadDef。
翻译为:instances这个参数为该osThreadDef能够被实例化的最大数量。
由于cmsis os对freertos进行了封装,原来的xTaskCreate变为两个函数
osThreadDef (Thread, osPriorityNormal, 3, 0); // define Thread and specify to allow three instances
osThreadId id1, id2, id3;
id1 = osThreadCreate (osThread (Thread), NULL); // create the thread with id1
id2 = osThreadCreate (osThread (Thread), NULL); // create the thread with id2
id3 = osThreadCreate (osThread (Thread), NULL); // create the thread with id3`
osThreadDef就相当于把那几个参数用宏定义拼接起来,再传入osThreadCreate进行真正的创建,参数instances限定了一个osThreadDef被osThreadCreate的次数,图示创建了三次。
在实际的使用中,这个instances是不起任何作用的,验证时我将instances定为2,而实际可以创建不止两次(只要堆空间还有富裕就可以不断创建),点进osThreadCreate的定义后,可以看到,其中instances并没有参与。因此判断这个参数可能是CMSISRTOS中使用的,在堆FreeRTOS封装时舍弃了。自己处理一下也可以实现同样的效果。
下面是 osThreadCreate本体:
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument) { TaskHandle_t handle; #if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) if((thread_def->buffer != NULL) && (thread_def->controlblock != NULL)) { handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), thread_def->buffer, thread_def->controlblock); } else { if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), &handle) != pdPASS) { return NULL; } } #elif( configSUPPORT_STATIC_ALLOCATION == 1 ) handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), thread_def->buffer, thread_def->controlblock); #else if (xTaskCreate((TaskFunction_t)thread_def->pthread,(const portCHAR *)thread_def->name, thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority), &handle) != pdPASS) { return NULL; } #endif return handle; }
另外,刚接触CUBEMX生成FreeRTOS,可以参考官方文档。
在本地下图路径:
C:\Keil_v5\ARM\PACK\ARM\CMSIS\5.4.0\CMSIS\Documentation\RTOS\html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。