CMSIS-RTOS实现通常作为库提供。要将RTOS功能添加到现有的基于CMSIS的应用程序,需要添加RTOS库(通常是配置文件)。RTOS库的可用功能在头文件cmsis_os.h中定义,该文件特定于每个CMSIS-RTOS实现。
根据CMSIS-RTOS实现,执行可以从main函数开始作为第一个线程。这样做的好处是应用程序员可以使用其他内部创建线程的中间件库,但用户应用程序的其余部分只使用主线程。因此,RTOS的使用对于应用程序员来说是不可见的,但是库可以使用CMSIS-RTOS功能。
将文件添加到项目后,用户可以开始使用CMSIS-RTOS功能。下面提供了一个代码示例:
#include“ cmsis_os.h ” // CMSIS-RTOS头文件 void job1(void const * argument){ // thread function'job1' 而(1){ : //执行一些代码 osDelay(10); //延迟执行10毫秒 } } osThreadDef(job1,osPriorityAboveNormal,1,0); //将job1定义为线程函数 void job2(void const * argument){ // thread function'work2' osThreadCreate(osThread(job1),NULL); //创建job1线程 而(1){ : //执行一些代码 } } osThreadDef(job2,osPriorityNormal,1,0); //将job2定义为线程函数 void job3(void const * argument){ // thread function'work3' 而(1){ : //执行一些代码 osDelay(20); //延迟执行20毫秒 } } osThreadDef(job3,osPriorityNormal,1,0); //将job3定义为线程函数 int main(void){ //程序执行从这里开始 osKernelInitialize(); //初始化RTOS内核 : //设置并初始化外围设备 osThreadCreate(osThread(job2)); osThreadCreate(osThread(job3)); osKernelStart(); //使用job2执行启动内核 }
头文件模板:cmsis_os.h
文件cmsis_os.h是CMSIS-RTOS兼容的实时操作系统(RTOS)的模板头文件。符合CMSIS-RTOS的每个RTOS都应提供代表其实现的特定cmsis_os.h头文件。
文件cmsis_os.h包含:
- CMSIS-RTOS API函数定义
- 参数和返回类型的结构定义
- CMSIS-RTOS API函数使用的状态和优先级值
- 用于定义线程和其他内核对象的宏
名称约定和头文件修改
所有定义都以os为前缀,为CMSIS-RTOS函数提供唯一的名称空间。带有前缀os_的定义不在应用程序代码中使用,而是在此头文件的本地。属于模块的所有定义和函数都被分组并具有公共前缀,即osThread。
标记为CAN BE CHANGED的定义可以根据实际CMSIS-RTOS实施的需要进行调整。这些定义可以特定于底层RTOS内核。
标记为MUST REMAIN UNCHANGED的定义不能更改。否则,CMSIS-RTOS实施不再符合标准。请注意,某些功能是可选的,不需要由每个CMSIS-RTOS实现提供。
定义和引用对象定义
使用#define osObjectsExternal对象被定义为外部符号。这允许创建在整个项目中使用的一致头文件,如下所示:
#include < cmsis_os.h > // CMSIS RTOS头文件 //线程定义 extern void thread_sample(void const * argument); //函数原型 osThreadDef(thread_sample,osPriorityBelowNormal,1,100); //池定义 osPoolDef(MyPool,10,long);
此头文件定义包含在C / C ++源文件中的所有对象。当#define osObjectsExternal出现在头文件之前时,对象被定义为外部符号。因此,可以在整个项目中使用单个一致的头文件。
#include“osObjects.h” // CMSIS-RTOS对象的定义 #define osObjectsExternal //对象将被定义为外部符号 #include“osObjects.h”//引用CMSIS-RTOS对象
头文件cmsis_os.h
/* ---------------------------------------------------------------------- * $Date: 5. February 2013 * $Revision: V1.02 * * Project: CMSIS-RTOS API * Title: cmsis_os.h template header file * * Version 0.02 * Initial Proposal Phase * Version 0.03 * osKernelStart added, optional feature: main started as thread * osSemaphores have standard behavior * osTimerCreate does not start the timer, added osTimerStart * osThreadPass is renamed to osThreadYield * Version 1.01 * Support for C++ interface * - const attribute removed from the osXxxxDef_t typedef's * - const attribute added to the osXxxxDef macros * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete * Added: osKernelInitialize * Version 1.02 * Control functions for short timeouts in microsecond resolution: * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec * Removed: osSignalGet *---------------------------------------------------------------------------- * * Copyright (c) 2013-2017 ARM LIMITED * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *---------------------------------------------------------------------------*/ #ifndef _CMSIS_OS_H #define _CMSIS_OS_H /// ote MUST REMAIN UNCHANGED: osCMSIS identifies the CMSIS-RTOS API version. #define osCMSIS 0x10002 ///< API version (main [31:16] .sub [15:0]) /// ote CAN BE CHANGED: osCMSIS_KERNEL identifies the underlying RTOS kernel and version number. #define osCMSIS_KERNEL 0x10000 ///< RTOS identification and version (main [31:16] .sub [15:0]) /// ote MUST REMAIN UNCHANGED: osKernelSystemId shall be consistent in every CMSIS-RTOS. #define osKernelSystemId "KERNEL V1.00" ///< RTOS identification string /// ote MUST REMAIN UNCHANGED: osFeature_xxx shall be consistent in every CMSIS-RTOS. #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available #define osFeature_Signals 8 ///< maximum number of Signal Flags available per thread #define osFeature_Semaphore 30 ///< maximum count for ef osSemaphoreCreate function #define osFeature_Wait 1 ///< osWait function: 1=available, 0=not available #define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available #include <stdint.h> #include <stddef.h> #ifdef __cplusplus extern "C" { #endif // ==== Enumeration, structures, defines ==== /// Priority used for thread control. /// ote MUST REMAIN UNCHANGED: osPriority shall be consistent in every CMSIS-RTOS. typedef enum { osPriorityIdle = -3, ///< priority: idle (lowest) osPriorityLow = -2, ///< priority: low osPriorityBelowNormal = -1, ///< priority: below normal osPriorityNormal = 0, ///< priority: normal (default) osPriorityAboveNormal = +1, ///< priority: above normal osPriorityHigh = +2, ///< priority: high osPriorityRealtime = +3, ///< priority: realtime (highest) osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority } osPriority; /// Timeout value. /// ote MUST REMAIN UNCHANGED: osWaitForever shall be consistent in every CMSIS-RTOS. #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value /// Status code values returned by CMSIS-RTOS functions. /// ote MUST REMAIN UNCHANGED: osStatus shall be consistent in every CMSIS-RTOS. typedef enum { osOK = 0, ///< function completed; no error or event occurred. osEventSignal = 0x08, ///< function completed; signal event occurred. osEventMessage = 0x10, ///< function completed; message event occurred. osEventMail = 0x20, ///< function completed; mail event occurred. osEventTimeout = 0x40, ///< function completed; timeout occurred. osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object. osErrorResource = 0x81, ///< resource not available: a specified resource was not available. osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period. osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines. osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object. osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority. osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation. osErrorValue = 0x86, ///< value of a parameter is out of range. osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits. os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization. } osStatus; /// Timer type value for the timer definition. /// ote MUST REMAIN UNCHANGED: os_timer_type shall be consistent in every CMSIS-RTOS. typedef enum { osTimerOnce = 0, ///< one-shot timer osTimerPeriodic = 1 ///< repeating timer } os_timer_type; /// Entry point of a thread. /// ote MUST REMAIN UNCHANGED: os_pthread shall be consistent in every CMSIS-RTOS. typedef void (*os_pthread) (void const *argument); /// Entry point of a timer call back function. /// ote MUST REMAIN UNCHANGED: os_ptimer shall be consistent in every CMSIS-RTOS. typedef void (*os_ptimer) (void const *argument); // >>> the following data type definitions may shall adapted towards a specific RTOS /// Thread ID identifies the thread (pointer to a thread control block). /// ote CAN BE CHANGED: os_thread_cb is implementation specific in every CMSIS-RTOS. typedef struct os_thread_cb *osThreadId; /// Timer ID identifies the timer (pointer to a timer control block). /// ote CAN BE CHANGED: os_timer_cb is implementation specific in every CMSIS-RTOS. typedef struct os_timer_cb *osTimerId; /// Mutex ID identifies the mutex (pointer to a mutex control block). /// ote CAN BE CHANGED: os_mutex_cb is implementation specific in every CMSIS-RTOS. typedef struct os_mutex_cb *osMutexId; /// Semaphore ID identifies the semaphore (pointer to a semaphore control block). /// ote CAN BE CHANGED: os_semaphore_cb is implementation specific in every CMSIS-RTOS. typedef struct os_semaphore_cb *osSemaphoreId; /// Pool ID identifies the memory pool (pointer to a memory pool control block). /// ote CAN BE CHANGED: os_pool_cb is implementation specific in every CMSIS-RTOS. typedef struct os_pool_cb *osPoolId; /// Message ID identifies the message queue (pointer to a message queue control block). /// ote CAN BE CHANGED: os_messageQ_cb is implementation specific in every CMSIS-RTOS. typedef struct os_messageQ_cb *osMessageQId; /// Mail ID identifies the mail queue (pointer to a mail queue control block). /// ote CAN BE CHANGED: os_mailQ_cb is implementation specific in every CMSIS-RTOS. typedef struct os_mailQ_cb *osMailQId; /// Thread Definition structure contains startup information of a thread. /// ote CAN BE CHANGED: os_thread_def is implementation specific in every CMSIS-RTOS. typedef struct os_thread_def { os_pthread pthread; ///< start address of thread function osPriority tpriority; ///< initial thread priority uint32_t instances; ///< maximum number of instances of that thread function uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size } osThreadDef_t; /// Timer Definition structure contains timer parameters. /// ote CAN BE CHANGED: os_timer_def is implementation specific in every CMSIS-RTOS. typedef struct os_timer_def { os_ptimer ptimer; ///< start address of a timer function } osTimerDef_t; /// Mutex Definition structure contains setup information for a mutex. /// ote CAN BE CHANGED: os_mutex_def is implementation specific in every CMSIS-RTOS. typedef struct os_mutex_def { uint32_t dummy; ///< dummy value. } osMutexDef_t; /// Semaphore Definition structure contains setup information for a semaphore. /// ote CAN BE CHANGED: os_semaphore_def is implementation specific in every CMSIS-RTOS. typedef struct os_semaphore_def { uint32_t dummy; ///< dummy value. } osSemaphoreDef_t; /// Definition structure for memory block allocation. /// ote CAN BE CHANGED: os_pool_def is implementation specific in every CMSIS-RTOS. typedef struct os_pool_def { uint32_t pool_sz; ///< number of items (elements) in the pool uint32_t item_sz; ///< size of an item void *pool; ///< pointer to memory for pool } osPoolDef_t; /// Definition structure for message queue. /// ote CAN BE CHANGED: os_messageQ_def is implementation specific in every CMSIS-RTOS. typedef struct os_messageQ_def { uint32_t queue_sz; ///< number of elements in the queue uint32_t item_sz; ///< size of an item void *pool; ///< memory array for messages } osMessageQDef_t; /// Definition structure for mail queue. /// ote CAN BE CHANGED: os_mailQ_def is implementation specific in every CMSIS-RTOS. typedef struct os_mailQ_def { uint32_t queue_sz; ///< number of elements in the queue uint32_t item_sz; ///< size of an item void *pool; ///< memory array for mail } osMailQDef_t; /// Event structure contains detailed information about an event. /// ote MUST REMAIN UNCHANGED: os_event shall be consistent in every CMSIS-RTOS. /// However the struct may be extended at the end. typedef struct { osStatus status; ///< status code: event or error information union { uint32_t v; ///< message as 32-bit value void *p; ///< message or mail as void pointer int32_t signals; ///< signal flags } value; ///< event value union { osMailQId mail_id; ///< mail id obtained by ef osMailCreate osMessageQId message_id; ///< message id obtained by ef osMessageCreate } def; ///< event definition } osEvent; // ==== Kernel Control Functions ==== /// Initialize the RTOS Kernel for creating objects. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osKernelInitialize shall be consistent in every CMSIS-RTOS. osStatus osKernelInitialize (void); /// Start the RTOS Kernel. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osKernelStart shall be consistent in every CMSIS-RTOS. osStatus osKernelStart (void); /// Check if the RTOS kernel is already started. /// ote MUST REMAIN UNCHANGED: osKernelRunning shall be consistent in every CMSIS-RTOS. /// eturn 0 RTOS is not started, 1 RTOS is started. int32_t osKernelRunning(void); #if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available /// Get the RTOS kernel system timer counter /// ote MUST REMAIN UNCHANGED: osKernelSysTick shall be consistent in every CMSIS-RTOS. /// eturn RTOS kernel system timer as 32-bit value uint32_t osKernelSysTick (void); /// The RTOS kernel system timer frequency in Hz /// ote Reflects the system timer setting and is typically defined in a configuration file. #define osKernelSysTickFrequency 100000000 /// Convert a microseconds value to a RTOS kernel system timer value. /// param microsec time value in microseconds. /// eturn time value normalized to the ef osKernelSysTickFrequency #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000) #endif // System Timer available // ==== Thread Management ==== /// Create a Thread Definition with function, priority, and stack requirements. /// param name name of the thread function. /// param priority initial priority of the thread function. /// param instances number of possible thread instances. /// param stacksz stack size (in bytes) requirements for the thread function. /// ote CAN BE CHANGED: The parameters to osThreadDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osThreadDef(name, priority, instances, stacksz) extern const osThreadDef_t os_thread_def_##name #else // define the object #define osThreadDef(name, priority, instances, stacksz) const osThreadDef_t os_thread_def_##name = { (name), (priority), (instances), (stacksz) } #endif /// Access a Thread definition. /// param name name of the thread definition object. /// ote CAN BE CHANGED: The parameter to osThread shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osThread(name) &os_thread_def_##name /// Create a thread and add it to Active Threads and set it to state READY. /// param[in] thread_def thread definition referenced with ef osThread. /// param[in] argument pointer that is passed to the thread function as start argument. /// eturn thread ID for reference by other functions or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osThreadCreate shall be consistent in every CMSIS-RTOS. osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument); /// Return the thread ID of the current running thread. /// eturn thread ID for reference by other functions or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osThreadGetId shall be consistent in every CMSIS-RTOS. osThreadId osThreadGetId (void); /// Terminate execution of a thread and remove it from Active Threads. /// param[in] thread_id thread ID obtained by ef osThreadCreate or ef osThreadGetId. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osThreadTerminate shall be consistent in every CMSIS-RTOS. osStatus osThreadTerminate (osThreadId thread_id); /// Pass control to next thread that is in state READY. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osThreadYield shall be consistent in every CMSIS-RTOS. osStatus osThreadYield (void); /// Change priority of an active thread. /// param[in] thread_id thread ID obtained by ef osThreadCreate or ef osThreadGetId. /// param[in] priority new priority value for the thread function. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osThreadSetPriority shall be consistent in every CMSIS-RTOS. osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority); /// Get current priority of an active thread. /// param[in] thread_id thread ID obtained by ef osThreadCreate or ef osThreadGetId. /// eturn current priority value of the thread function. /// ote MUST REMAIN UNCHANGED: osThreadGetPriority shall be consistent in every CMSIS-RTOS. osPriority osThreadGetPriority (osThreadId thread_id); // ==== Generic Wait Functions ==== /// Wait for Timeout (Time Delay). /// param[in] millisec ef CMSIS_RTOS_TimeOutValue "time delay" value /// eturn status code that indicates the execution status of the function. osStatus osDelay (uint32_t millisec); #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available /// Wait for Signal, Message, Mail, or Timeout. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue or 0 in case of no time-out /// eturn event that contains signal, message, or mail information or error code. /// ote MUST REMAIN UNCHANGED: osWait shall be consistent in every CMSIS-RTOS. osEvent osWait (uint32_t millisec); #endif // Generic Wait available // ==== Timer Management Functions ==== /// Define a Timer object. /// param name name of the timer object. /// param function name of the timer call back function. /// ote CAN BE CHANGED: The parameter to osTimerDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osTimerDef(name, function) extern const osTimerDef_t os_timer_def_##name #else // define the object #define osTimerDef(name, function) const osTimerDef_t os_timer_def_##name = { (function) } #endif /// Access a Timer definition. /// param name name of the timer object. /// ote CAN BE CHANGED: The parameter to osTimer shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osTimer(name) &os_timer_def_##name /// Create a timer. /// param[in] timer_def timer object referenced with ef osTimer. /// param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. /// param[in] argument argument to the timer call back function. /// eturn timer ID for reference by other functions or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osTimerCreate shall be consistent in every CMSIS-RTOS. osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument); /// Start or restart a timer. /// param[in] timer_id timer ID obtained by ef osTimerCreate. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue "time delay" value of the timer. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osTimerStart shall be consistent in every CMSIS-RTOS. osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); /// Stop the timer. /// param[in] timer_id timer ID obtained by ef osTimerCreate. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osTimerStop shall be consistent in every CMSIS-RTOS. osStatus osTimerStop (osTimerId timer_id); /// Delete a timer that was created by ef osTimerCreate. /// param[in] timer_id timer ID obtained by ef osTimerCreate. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osTimerDelete shall be consistent in every CMSIS-RTOS. osStatus osTimerDelete (osTimerId timer_id); // ==== Signal Management ==== /// Set the specified Signal Flags of an active thread. /// param[in] thread_id thread ID obtained by ef osThreadCreate or ef osThreadGetId. /// param[in] signals specifies the signal flags of the thread that should be set. /// eturn previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. /// ote MUST REMAIN UNCHANGED: osSignalSet shall be consistent in every CMSIS-RTOS. int32_t osSignalSet (osThreadId thread_id, int32_t signals); /// Clear the specified Signal Flags of an active thread. /// param[in] thread_id thread ID obtained by ef osThreadCreate or ef osThreadGetId. /// param[in] signals specifies the signal flags of the thread that shall be cleared. /// eturn previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR. /// ote MUST REMAIN UNCHANGED: osSignalClear shall be consistent in every CMSIS-RTOS. int32_t osSignalClear (osThreadId thread_id, int32_t signals); /// Wait for one or more Signal Flags to become signaled for the current RUNNING thread. /// param[in] signals wait until all specified signal flags set or 0 for any single signal flag. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// eturn event flag information or error code. /// ote MUST REMAIN UNCHANGED: osSignalWait shall be consistent in every CMSIS-RTOS. osEvent osSignalWait (int32_t signals, uint32_t millisec); // ==== Mutex Management ==== /// Define a Mutex. /// param name name of the mutex object. /// ote CAN BE CHANGED: The parameter to osMutexDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osMutexDef(name) extern const osMutexDef_t os_mutex_def_##name #else // define the object #define osMutexDef(name) const osMutexDef_t os_mutex_def_##name = { 0 } #endif /// Access a Mutex definition. /// param name name of the mutex object. /// ote CAN BE CHANGED: The parameter to osMutex shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osMutex(name) &os_mutex_def_##name /// Create and Initialize a Mutex object. /// param[in] mutex_def mutex definition referenced with ef osMutex. /// eturn mutex ID for reference by other functions or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osMutexCreate shall be consistent in every CMSIS-RTOS. osMutexId osMutexCreate (const osMutexDef_t *mutex_def); /// Wait until a Mutex becomes available. /// param[in] mutex_id mutex ID obtained by ef osMutexCreate. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osMutexWait shall be consistent in every CMSIS-RTOS. osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec); /// Release a Mutex that was obtained by ef osMutexWait. /// param[in] mutex_id mutex ID obtained by ef osMutexCreate. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osMutexRelease shall be consistent in every CMSIS-RTOS. osStatus osMutexRelease (osMutexId mutex_id); /// Delete a Mutex that was created by ef osMutexCreate. /// param[in] mutex_id mutex ID obtained by ef osMutexCreate. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osMutexDelete shall be consistent in every CMSIS-RTOS. osStatus osMutexDelete (osMutexId mutex_id); // ==== Semaphore Management Functions ==== #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available /// Define a Semaphore object. /// param name name of the semaphore object. /// ote CAN BE CHANGED: The parameter to osSemaphoreDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osSemaphoreDef(name) extern const osSemaphoreDef_t os_semaphore_def_##name #else // define the object #define osSemaphoreDef(name) const osSemaphoreDef_t os_semaphore_def_##name = { 0 } #endif /// Access a Semaphore definition. /// param name name of the semaphore object. /// ote CAN BE CHANGED: The parameter to osSemaphore shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osSemaphore(name) &os_semaphore_def_##name /// Create and Initialize a Semaphore object used for managing resources. /// param[in] semaphore_def semaphore definition referenced with ef osSemaphore. /// param[in] count number of available resources. /// eturn semaphore ID for reference by other functions or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osSemaphoreCreate shall be consistent in every CMSIS-RTOS. osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count); /// Wait until a Semaphore token becomes available. /// param[in] semaphore_id semaphore object referenced with ef osSemaphoreCreate. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// eturn number of available tokens, or -1 in case of incorrect parameters. /// ote MUST REMAIN UNCHANGED: osSemaphoreWait shall be consistent in every CMSIS-RTOS. int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); /// Release a Semaphore token. /// param[in] semaphore_id semaphore object referenced with ef osSemaphoreCreate. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osSemaphoreRelease shall be consistent in every CMSIS-RTOS. osStatus osSemaphoreRelease (osSemaphoreId semaphore_id); /// Delete a Semaphore that was created by ef osSemaphoreCreate. /// param[in] semaphore_id semaphore object referenced with ef osSemaphoreCreate. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osSemaphoreDelete shall be consistent in every CMSIS-RTOS. osStatus osSemaphoreDelete (osSemaphoreId semaphore_id); #endif // Semaphore available // ==== Memory Pool Management Functions ==== #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available /// rief Define a Memory Pool. /// param name name of the memory pool. /// param no maximum number of blocks (objects) in the memory pool. /// param type data type of a single block (object). /// ote CAN BE CHANGED: The parameter to osPoolDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osPoolDef(name, no, type) extern const osPoolDef_t os_pool_def_##name #else // define the object #define osPoolDef(name, no, type) const osPoolDef_t os_pool_def_##name = { (no), sizeof(type), NULL } #endif /// rief Access a Memory Pool definition. /// param name name of the memory pool /// ote CAN BE CHANGED: The parameter to osPool shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osPool(name) &os_pool_def_##name /// Create and Initialize a memory pool. /// param[in] pool_def memory pool definition referenced with ef osPool. /// eturn memory pool ID for reference by other functions or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osPoolCreate shall be consistent in every CMSIS-RTOS. osPoolId osPoolCreate (const osPoolDef_t *pool_def); /// Allocate a memory block from a memory pool. /// param[in] pool_id memory pool ID obtain referenced with ef osPoolCreate. /// eturn address of the allocated memory block or NULL in case of no memory available. /// ote MUST REMAIN UNCHANGED: osPoolAlloc shall be consistent in every CMSIS-RTOS. void *osPoolAlloc (osPoolId pool_id); /// Allocate a memory block from a memory pool and set memory block to zero. /// param[in] pool_id memory pool ID obtain referenced with ef osPoolCreate. /// eturn address of the allocated memory block or NULL in case of no memory available. /// ote MUST REMAIN UNCHANGED: osPoolCAlloc shall be consistent in every CMSIS-RTOS. void *osPoolCAlloc (osPoolId pool_id); /// Return an allocated memory block back to a specific memory pool. /// param[in] pool_id memory pool ID obtain referenced with ef osPoolCreate. /// param[in] block address of the allocated memory block that is returned to the memory pool. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osPoolFree shall be consistent in every CMSIS-RTOS. osStatus osPoolFree (osPoolId pool_id, void *block); #endif // Memory Pool Management available // ==== Message Queue Management Functions ==== #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available /// rief Create a Message Queue Definition. /// param name name of the queue. /// param queue_sz maximum number of messages in the queue. /// param type data type of a single message element (for debugger). /// ote CAN BE CHANGED: The parameter to osMessageQDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osMessageQDef(name, queue_sz, type) extern const osMessageQDef_t os_messageQ_def_##name #else // define the object #define osMessageQDef(name, queue_sz, type) const osMessageQDef_t os_messageQ_def_##name = { (queue_sz), sizeof (type) } #endif /// rief Access a Message Queue Definition. /// param name name of the queue /// ote CAN BE CHANGED: The parameter to osMessageQ shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osMessageQ(name) &os_messageQ_def_##name /// Create and Initialize a Message Queue. /// param[in] queue_def queue definition referenced with ef osMessageQ. /// param[in] thread_id thread ID (obtained by ef osThreadCreate or ef osThreadGetId) or NULL. /// eturn message queue ID for reference by other functions or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osMessageCreate shall be consistent in every CMSIS-RTOS. osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id); /// Put a Message to a Queue. /// param[in] queue_id message queue ID obtained with ef osMessageCreate. /// param[in] info message information. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osMessagePut shall be consistent in every CMSIS-RTOS. osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec); /// Get a Message or Wait for a Message from a Queue. /// param[in] queue_id message queue ID obtained with ef osMessageCreate. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// eturn event information that includes status code. /// ote MUST REMAIN UNCHANGED: osMessageGet shall be consistent in every CMSIS-RTOS. osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec); #endif // Message Queues available // ==== Mail Queue Management Functions ==== #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available /// rief Create a Mail Queue Definition. /// param name name of the queue /// param queue_sz maximum number of messages in queue /// param type data type of a single message element /// ote CAN BE CHANGED: The parameter to osMailQDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osMailQDef(name, queue_sz, type) extern const osMailQDef_t os_mailQ_def_##name #else // define the object #define osMailQDef(name, queue_sz, type) const osMailQDef_t os_mailQ_def_##name = { (queue_sz), sizeof (type) } #endif /// rief Access a Mail Queue Definition. /// param name name of the queue /// ote CAN BE CHANGED: The parameter to osMailQ shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osMailQ(name) &os_mailQ_def_##name /// Create and Initialize mail queue. /// param[in] queue_def reference to the mail queue definition obtain with ef osMailQ /// param[in] thread_id thread ID (obtained by ef osThreadCreate or ef osThreadGetId) or NULL. /// eturn mail queue ID for reference by other functions or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osMailCreate shall be consistent in every CMSIS-RTOS. osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id); /// Allocate a memory block from a mail. /// param[in] queue_id mail queue ID obtained with ef osMailCreate. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue or 0 in case of no time-out /// eturn pointer to memory block that can be filled with mail or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osMailAlloc shall be consistent in every CMSIS-RTOS. void *osMailAlloc (osMailQId queue_id, uint32_t millisec); /// Allocate a memory block from a mail and set memory block to zero. /// param[in] queue_id mail queue ID obtained with ef osMailCreate. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue or 0 in case of no time-out /// eturn pointer to memory block that can be filled with mail or NULL in case of error. /// ote MUST REMAIN UNCHANGED: osMailCAlloc shall be consistent in every CMSIS-RTOS. void *osMailCAlloc (osMailQId queue_id, uint32_t millisec); /// Put a mail to a queue. /// param[in] queue_id mail queue ID obtained with ef osMailCreate. /// param[in] mail memory block previously allocated with ef osMailAlloc or ef osMailCAlloc. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osMailPut shall be consistent in every CMSIS-RTOS. osStatus osMailPut (osMailQId queue_id, void *mail); /// Get a mail from a queue. /// param[in] queue_id mail queue ID obtained with ef osMailCreate. /// param[in] millisec ef CMSIS_RTOS_TimeOutValue or 0 in case of no time-out /// eturn event that contains mail information or error code. /// ote MUST REMAIN UNCHANGED: osMailGet shall be consistent in every CMSIS-RTOS. osEvent osMailGet (osMailQId queue_id, uint32_t millisec); /// Free a memory block from a mail. /// param[in] queue_id mail queue ID obtained with ef osMailCreate. /// param[in] mail pointer to the memory block that was obtained with ef osMailGet. /// eturn status code that indicates the execution status of the function. /// ote MUST REMAIN UNCHANGED: osMailFree shall be consistent in every CMSIS-RTOS. osStatus osMailFree (osMailQId queue_id, void *mail); #endif // Mail Queues available #ifdef __cplusplus } #endif #endif // _CMSIS_OS_H