要使用 API 版本 2 功能,请遵循以下步骤中描述的步骤:
RTX5 提供两个 API 层:CMSIS-RTOS v1 和 CMSIS-RTOS v2 。这允许从 v1 到 v2 的梯度转换。修改的 v1 头文件和特殊的 v1 兼容性模块使现有代码可以在几乎不做任何修改的情况下在 v2 实现上运行。
只有少数不兼容和局限性存在:
迁移等级取决于项目在其生命周期中的阶段:
使用 API v1 兼容层从任何 4.x 版本升级到 RTX 版本 5 。按如下所示配置现有项目:
示例 - 应用程序主线程
为了在迁移后验证 RTOS 的正确操作,您可以暂时将 RTOS 验证组件集成到您的项目中。
在您的项目中实现新功能最好使用新的 API 来完成。这两个 API 版本都在 RTX5 中提供,并且可以一起存在。
组件选择与迁移级别 1 相同。
在需要访问 API v2 函数的所有模块中包含 “cmsis_os2.h” 。
以下片段显示了如何使用两个 API 版本创建的线程同时存在:
完整的示例 “RTX5 迁移” 是 CMSIS5 包的一部分,可从包安装程序中获取。
完全迁移到 API v2 可以减少翻译层的开销并简化项目。有一些努力来替换和重新测试所有 API v1 调用。建议采用以下步骤作为粗略指导:
通常不再有 os * Def 宏来声明 OS 对象。
本节列出 CMSIS-RTOS API v1 和 API v2 函数以及功能差异。该列表按照 API v2 函数名称的字母顺序进行排序,结构如下:
背景颜色表示:
osStatus_t osKernelGetInfo (osVersion_t* version, char* id_buf, uint32_t id_size)
osKernelState_t osKernelGetState (void)
int32_t osKernelRunning (void)
uint32_t osKernelGetTickCount (void)
uint32_t osKernelGetTickFreq (void)
uint32_t osKernelGetSysTimerCount (void)
uint32_t osKernelSysTick (void)
uint64_t osKernelGetSysTimerFreq (void)
osStatus_t osKernelInitialize (void)
osStatus osKernelInitialize (void)
uint32_t osKernelLock (void)
int32_t osKernelUnlock (void)
void osKernelRestoreLock (void)
osStatus_t osKernelStart (void)
osStatus osKernelStart (void)
uint32_t osKernelSuspend (void)
void osKernelResume (uint32_t sleep_time)
osStatus_t osThreadDetach (osThreadId_t thread_id)
uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items)
__NO_RETURN void osThreadExit (void)
uint32_t osThreadGetCount (osThreadId_t thread_id)
const char *osThreadGetName (osThreadId_t thread_id)
osThreadId_t osThreadGetId (void)
osThreadId osThreadGetId (void)
osPriority_t osThreadGetPriority (osThreadId_t thread_id)
osPriority osThreadGetPriority (osThreadId thread_id)
uint32_t osThreadGetStackSize (osThreadId_t thread_id)
uint32_t osThreadGetStackSpace (osThreadId_t thread_id)
osThreadState_t osThreadGetState (osThreadId_t thread_id)
osStatus_t osThreadJoin (osThreadId_t thread_id)
osThreadId_t osThreadNew (osThreadFunc_t function, void *argument, const osThreadAttr_t *attr)
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument)
void func (void *arg)
, 之前是: void func (const void *arg)
。osStatus_t osThreadResume (osThreadId_t thread_id)
osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority)
osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority)
osStatus_t osThreadSuspend (osThreadId_t thread_id)
osStatus_t osThreadTerminate (osThreadId_t thread_id)
osStatus osThreadTerminate (osThreadId thread_id)
osStatus_t osThreadYield (void)
osStatus osThreadYield (void)
新部分使用标志同步线程。线程标志和更灵活的事件标志取代了 RTOS v1 信号事件。请参阅信号事件以获取不推荐使用的功能列表。有关详细信息,请参阅线程标记。
uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags)
uint32_t osThreadFlagsClear (uint32_t flags)
uint32_t osThreadFlagsGet (void)
uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout)
新部分使用标志同步事件。事件标志和线程标志取代了 RTOS v1 信号事件。RTOS v1 信号事件中列出的所有功能已被弃用。请参阅信号事件以获取不推荐使用的功能列表。 有关新功能的详细信息,请参阅事件标志。
uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags)
const char *osEventFlagsGetName ((osEventFlagsId_t ef_id)
osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id)
uint32_t osEventFlagsGet (osEventFlagsId_t ef_id)
osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr)
uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags)
uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout)
详情请参阅通用等待功能。
osStatus_t osDelay (uint32_t ticks)
osStatus osDelay (uint32_t timeout)
osStatus_t osDelayUntil (uint32_t ticks)
osEvent osWait (uint32_t millisec)
详情请参阅定时器管理。
osStatus_t osTimerDelete (osTimerId_t timer_id)
osStatus osTimerDelete (osTimerId timer_id)
const char *osTimerGetName (osTimerId_t timer_id)
uint32_t osTimerIsRunning (osTimerId_t timer_id)
osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument)
osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks)
osStatus osTimerStart (osTimerId timer_id, uint32_t timeout)
osStatus_t osTimerStop (osTimerId_t timer_id)
osStatus osTimerStop (osTimerId timer_id)
有关详细信息,请参阅互斥管理。
osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout)
osStatus osMutexWait (osMutexId mutex_id, uint32_t timeout)
osStatus_t osMutexDelete (osMutexId_t mutex_id)
osStatus osMutexDelete (osMutexId mutex_id)
const char *osMutexGetName ((osMutexId_t mutex_id)
osThreadId_t osMutexGetOwner (osMutexId_t mutex_id)
osMutexId_t osMutexNew (const osMutexAttr_t *attr)
osMutexId osMutexCreate (const osMutexDef_t *mutex_def)
osStatus_t osMutexRelease (osMutexId_t mutex_id)
osStatus osMutexRelease (osMutexId mutex_id)
有关详细信息,请参阅信号量。
osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout)
osSemaphoreWait
。
osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id)
osStatus osSemaphoreDelete (osSemaphoreId semaphore_id)
uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id)
const char *osSemaphoreGetName ((osSemaphoreId_t semaphore_id)
osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)
osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count)
osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id)
osStatus osSemaphoreRelease (osSemaphoreId semaphore_id)
int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t timeout)
void * osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout)
void * osPoolAlloc (osPoolId pool_id)
osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id)
osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void * block)
osStatus osPoolFree (osPoolId pool_id, void * block)
uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id)
uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id)
uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id)
const char *osMemoryPoolGetName ((osMemoryPoolId_t mp_id)
uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id)
osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr)
osPoolId osPoolCreate (const osPoolDef_t * pool_def)
通常,消息现在使用固定大小的内存,而不是32位值。有关详细信息,请参阅消息队列。
osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id)
osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout)
osEvent osMessageGet (osMessageQId queue_id, uint32_t timeout)
uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id)
uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id)
uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id)
const char *osMessageQueueGetName ((osMessageQueueId_t mq_id)
uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id)
osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr)
osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id)
osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout)
osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t timeout)
osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id)
邮件队列 RTOS v1 功能已被弃用。改为使用 Message Queue 的功能。差异在 Message Queue 下列出。
void * osMailAlloc (osMailQId queue_id, uint32_t timeout)
void * osMailCAlloc (osMailQId queue_id, uint32_t timeout)
osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id)
osStatus osMailFree (osMailQId queue_id, void *mail)
osEvent osMailGet (osMailQId queue_id, uint32_t timeout)
osStatus osMailPut (osMailQId queue_id, void *mail)
RTOS v1 信号事件部分已被弃用。改用线程标志下面列出的功能。
int32_t osSignalClear (osThreadId thread_id, int32_t signals)
int32_t osSignalSet (osThreadId thread_id, int32_t signals)
osEvent osSignalWait (int32_t signals, uint32_t timeout)