CMSIS 接口

汇总

文件

文件 Name 描述
cmsis_os2.h CMSIS 2.0 标准接口头文件。

结构体

结构体 Name 描述
osVersion_t 系统版本信息。 更多...
osThreadAttr_t 线程参数类型。 更多...
osTimerAttr_t 定时器参数类型,不支持配置。 更多...
osEventFlagsAttr_t 事件参数类型,不支持配置。 更多...
osMutexAttr_t 互斥锁参数类型,不支持配置。 更多...
osSemaphoreAttr_t 信号量参数类型,不支持配置。 更多...
osMemoryPoolAttr_t 内存池参数类型。 更多...
osMessageQueueAttr_t 消息队列参数类型。 更多...

宏定义

宏定义 Name 描述
osWaitForever   0xFFFFFFFFU 系统永久等待。 更多...
osFlagsWaitAny   0x00000000U 等待任何标志触发。 更多...
osFlagsWaitAll   0x00000001U 等待全部标志触发。 更多...
osFlagsNoClear   0x00000002U 不清除指定等待标志。 更多...
osFlagsError   0x80000000U 标志相关函数最高位错误,不支持。 更多...
osFlagsErrorUnknown   0xFFFFFFFFU 线程标志未知错误。 更多...
osFlagsErrorTimeout   0xFFFFFFFEU 线程标志超时错误。 更多...
osFlagsErrorResource   0xFFFFFFFDU 线程标志资源错误。 更多...
osFlagsErrorParameter   0xFFFFFFFCU 线程标志参数错误。 更多...
osFlagsErrorISR   0xFFFFFFFAU 线程标志中断错误。 更多...
osThreadDetached   0x00000000U 表示线程不可加入状态的宏。 更多...
osThreadJoinable   0x00000001U 表示线程可加入状态的宏。 更多...
osMutexRecursive   0x00000001U 互斥锁递归属性宏,不支持。 更多...
osMutexPrioInherit   0x00000002U 互斥锁优先级继承属性宏,不支持。 更多...
osMutexRobust   0x00000008U 互斥锁不自动释放属性宏,不支持。 更多...

类型定义

类型定义 Name 描述
osThreadFunc_t 线程入口类型。 更多...
osTimerFunc_t 定时器入口类型。 更多...
osThreadId_t 线程ID类型。 更多...
osTimerId_t 定时器ID类型。 更多...
osEventFlagsId_t 事件ID类型。 更多...
osMutexId_t 互斥锁ID类型。 更多...
osSemaphoreId_t 信号量ID类型。 更多...
osMemoryPoolId_t 内存池ID类型。 更多...
osMessageQueueId_t 消息队列ID类型。 更多...
TZ_ModuleId_t 线程安全模块ID类型,不支持。 更多...

枚举

枚举 Name 描述
osKernelState_t 内核状态枚举。 更多...
osThreadState_t 线程状态枚举。 更多...
osPriority_t 优先级枚举。 更多...
osTimerType_t 定时器类型枚举。 更多...
osStatus_t CMSIS 标准返回值枚举。 更多...

函数

函数 Name 描述
osKernelInitialize (void) 内核初始化函数。 更多...
osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) 获取内核信息函数。 更多...
osKernelGetState (void) 获取内核状态。 更多...
osKernelStart (void) 内核启动函数。 更多...
osKernelLock (void) 内核调度锁定函数。 更多...
osKernelUnlock (void) 内核调度解锁函数。 更多...
osKernelRestoreLock (int32_t lock) 内核调度锁恢复函数。 更多...
osKernelSuspend (void) 内核挂起函数,不支持。 更多...
osKernelResume (uint32_t sleep_ticks) 内核挂起恢复函数,不支持。 更多...
osKernelGetTickCount (void) 获取内核tick函数。 更多...
osKernelGetTickFreq (void) 获取内核tick频率函数。 更多...
osKernelGetSysTimerCount (void) 获取系统启动后时间。 更多...
osKernelGetSysTimerFreq (void) 获取内核cpu cycle频率函数。 更多...
osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) 创建线程函数。 更多...
osThreadGetName (osThreadId_t thread_id) 获取线程名称函数。 更多...
osThreadGetId (void) 获取线程ID函数。 更多...
osThreadGetState (osThreadId_t thread_id) 获取线程状态函数。 更多...
osThreadGetStackSize (osThreadId_t thread_id) 获取线程栈大小函数。 更多...
osThreadGetStackSpace (osThreadId_t thread_id) 获取线程栈使用水线函数。 更多...
osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority) 设置线程优先级函数。 更多...
osThreadGetPriority (osThreadId_t thread_id) 获取线程优先级函数。 更多...
osThreadYield (void) 线程调度函数。 更多...
osThreadSuspend (osThreadId_t thread_id) 线程挂起函数。 更多...
osThreadResume (osThreadId_t thread_id) 线程挂起恢复函数。 更多...
osThreadDetach (osThreadId_t thread_id) 线程分离函数。 更多...
osThreadJoin (osThreadId_t thread_id) 等待指定线程终止函数。 更多...
osThreadExit (void) 当前线程退出函数。 更多...
osThreadTerminate (osThreadId_t thread_id) 指定线程终止函数。 更多...
osThreadGetCount (void) 获取使用中的线程数量。 更多...
osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items) 获取活动线程枚举,不支持。 更多...
osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) 设置线程的指定线程标志。 更多...
osThreadFlagsClear (uint32_t flags) 清除线程的指定线程标志。 更多...
osThreadFlagsGet (void) 获取线程的线程标志。 更多...
osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout) 等待指定线程标志。 更多...
osDelay (uint32_t ticks) 延时等待函数。 更多...
osDelayUntil (uint32_t ticks) 指定到期时间的延时等待函数。 更多...
osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) 定时器创建函数。 更多...
osTimerGetName (osTimerId_t timer_id) 获取定时器名称函数。 更多...
osTimerStart (osTimerId_t timer_id, uint32_t ticks) 定时器开始运行函数。 更多...
osTimerStop (osTimerId_t timer_id) 定时器停止运行函数。 更多...
osTimerIsRunning (osTimerId_t timer_id) 定时器状态查询函数。 更多...
osTimerDelete (osTimerId_t timer_id) 定时器删除函数。 更多...
osEventFlagsNew (const osEventFlagsAttr_t *attr) 事件初始化函数。 更多...
osEventFlagsGetName (osEventFlagsId_t ef_id) 获取事件名称函数。 更多...
osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) 设置事件标志函数。 更多...
osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) 清除事件标志函数。 更多...
osEventFlagsGet (osEventFlagsId_t ef_id) 获取事件标志函数。 更多...
osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) 事件标志等待函数。 更多...
osEventFlagsDelete (osEventFlagsId_t ef_id) 事件删除函数。 更多...
osMutexNew (const osMutexAttr_t *attr) 互斥锁初始化函数。 更多...
osMutexGetName (osMutexId_t mutex_id) 获取互斥锁名称函数,不支持。 更多...
osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) 获取互斥锁函数。 更多...
osMutexRelease (osMutexId_t mutex_id) 释放互斥锁函数。 更多...
osMutexGetOwner (osMutexId_t mutex_id) 获取互斥锁所有者函数。 更多...
osMutexDelete (osMutexId_t mutex_id) 互斥锁删除函数。 更多...
osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) 信号量初始化函数。 更多...
osSemaphoreGetName (osSemaphoreId_t semaphore_id) 获取信号量名称函数。 更多...
osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) 获取信号量函数。 更多...
osSemaphoreRelease (osSemaphoreId_t semaphore_id) 释放信号量函数。 更多...
osSemaphoreGetCount (osSemaphoreId_t semaphore_id) 获取信号量状态量函数。 更多...
osSemaphoreDelete (osSemaphoreId_t semaphore_id) 信号量删除函数。 更多...
osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) 内存池初始化函数。 更多...
osMemoryPoolGetName (osMemoryPoolId_t mp_id) 获取内存池名称函数。 更多...
osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) 申请内存函数。 更多...
osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) 释放内存函数。 更多...
osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id) 获取内存池拥有块数量函数。 更多...
osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id) 获取内存池块大小函数。 更多...
osMemoryPoolGetCount (osMemoryPoolId_t mp_id) 获取内存池块使用块函数。 更多...
osMemoryPoolGetSpace (osMemoryPoolId_t mp_id) 获取内存池剩余块函数。 更多...
osMemoryPoolDelete (osMemoryPoolId_t mp_id) 删除内存池函数。 更多...
osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) 消息队列初始化函数。 更多...
osMessageQueueGetName (osMessageQueueId_t mq_id) 获取消息队列名称函数。 更多...
osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) 消息队列发送消息函数。 更多...
osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) 消息队列接收消息函数。 更多...
osMessageQueueGetCapacity (osMessageQueueId_t mq_id) 获取消息队列最大节点数函数。 更多...
osMessageQueueGetMsgSize (osMessageQueueId_t mq_id) 获取消息队列节点大小函数。 更多...
osMessageQueueGetCount (osMessageQueueId_t mq_id) 获取消息队列待读节点数量函数。 更多...
osMessageQueueGetSpace (osMessageQueueId_t mq_id) 获取消息队列剩余可用节点数量函数。 更多...
osMessageQueueReset (osMessageQueueId_t mq_id) 消息队列重置函数,不支持。 更多...
osMessageQueueDelete (osMessageQueueId_t mq_id) 删除消息队列函数。 更多...

详细描述

宏定义说明

osFlagsError

#define osFlagsError   0x80000000U

描述:

标志相关函数最高位错误,不支持。

osFlagsErrorISR

#define osFlagsErrorISR   0xFFFFFFFAU

描述:

线程标志中断错误。

osFlagsErrorParameter

#define osFlagsErrorParameter   0xFFFFFFFCU

描述:

线程标志参数错误。

osFlagsErrorResource

#define osFlagsErrorResource   0xFFFFFFFDU

描述:

线程标志资源错误。

osFlagsErrorTimeout

#define osFlagsErrorTimeout   0xFFFFFFFEU

描述:

线程标志超时错误。

osFlagsErrorUnknown

#define osFlagsErrorUnknown   0xFFFFFFFFU

描述:

线程标志未知错误。

osFlagsNoClear

#define osFlagsNoClear   0x00000002U

描述:

不清除指定等待标志。

该宏用于标志相关函数中设置触发的方式。

osFlagsWaitAll

#define osFlagsWaitAll   0x00000001U

描述:

等待全部标志触发。

该宏用于标志相关函数中设置触发的方式。

osFlagsWaitAny

#define osFlagsWaitAny   0x00000000U

描述:

等待任何标志触发

该宏用于标志相关函数中设置触发的方式。

osMutexPrioInherit

#define osMutexPrioInherit   0x00000002U

描述:

互斥锁优先级继承属性宏,不支持。

osMutexRecursive

#define osMutexRecursive   0x00000001U

描述:

互斥锁递归属性宏,不支持。

osMutexRobust

#define osMutexRobust   0x00000008U

描述:

互斥锁不自动释放属性宏,不支持。

osThreadDetached

#define osThreadDetached   0x00000000U

描述:

表示线程不可加入状态的宏。

该宏表示无法使用osThreadJoin加入处于此状态的线程。

osThreadJoinable

#define osThreadJoinable   0x00000001U

描述:

表示线程可加入状态的宏。

该宏表示可以使用osThreadJoin加入处于这种状态的线程。

osWaitForever

#define osWaitForever   0xFFFFFFFFU

描述:

该宏表示系统永久等待,直到资源变得可用。

类型定义说明

osEventFlagsId_t

typedef void* osEventFlagsId_t

描述:

事件ID类型。

该类型用于识别不同事件。

osMemoryPoolId_t

typedef void* osMemoryPoolId_t

描述:

内存池ID类型。

该类型用于识别不同内存池。

osMessageQueueId_t

typedef void* osMessageQueueId_t

描述:

消息队列ID类型。

该类型用于识别不同消息队列。

osMutexId_t

typedef void* osMutexId_t

描述:

互斥锁ID类型。

该类型用于识别不同互斥锁。

osSemaphoreId_t

typedef void* osSemaphoreId_t

描述:

信号量ID类型。

该类型用于识别不同信号量。

osThreadFunc_t

typedef void(* osThreadFunc_t) (void *argument)

描述:

线程入口类型。

该类型用于线程调度时回调。

osThreadId_t

typedef void* osThreadId_t

描述:

线程ID类型。

该类型用于识别不同线程。

osTimerFunc_t

typedef void(* osTimerFunc_t) (void *argument)

描述:

定时器入口类型。

该类型用于定时器触发时回调。

osTimerId_t

typedef void* osTimerId_t

描述:

定时器ID类型。

该类型用于识别不同定时器。

TZ_ModuleId_t

typedef uint32_t TZ_ModuleId_t

描述:

线程安全模块ID类型,不支持。

枚举类型说明

osKernelState_t

enum osKernelState_t

描述:

内核状态枚举。

该枚举用于描述内核的运行状态。

枚举值 描述
osKernelInactive 内核未启动
osKernelReady 内核就绪
osKernelRunning 内核运行中
osKernelLocked 内核锁定
osKernelSuspended 内核挂起
osKernelError 内核异常
osKernelReserved 保留的状态,用于阻止编译器对枚举进行优化

osPriority_t

enum osPriority_t

描述:

优先级枚举。

该枚举用于描述各级别优先级。

枚举值 描述
osPriorityNone 未初始化的优先级
osPriorityIdle 为空闲线程保留的最低优先级,非空闲线程不能使用该优先级
osPriorityLow 低优先级,这是非空闲线程当前版本可使用的最低优先级
osPriorityLow1 低优先级 + 1
osPriorityLow2 低优先级 + 2
osPriorityLow3 低优先级 + 3
osPriorityLow4 低优先级 + 4
osPriorityLow5 低优先级 + 5
osPriorityLow6 低优先级 + 6
osPriorityLow7 低优先级 + 7
osPriorityBelowNormal 比普通等级稍低的优先级
osPriorityBelowNormal1 比普通等级稍低的优先级 + 1
osPriorityBelowNormal2 比普通等级稍低的优先级 + 2
osPriorityBelowNormal3 比普通等级稍低的优先级 + 3
osPriorityBelowNormal4 比普通等级稍低的优先级 + 4
osPriorityBelowNormal5 比普通等级稍低的优先级 + 5
osPriorityBelowNormal6 比普通等级稍低的优先级 + 6
osPriorityBelowNormal7 比普通等级稍低的优先级 + 7
osPriorityNormal 普通优先级
osPriorityNormal1 普通优先级 + 1
osPriorityNormal2 普通优先级 + 2
osPriorityNormal3 普通优先级 + 3
osPriorityNormal4 普通优先级 + 4
osPriorityNormal5 普通优先级 + 5
osPriorityNormal6 普通优先级 + 6
osPriorityNormal7 普通优先级 + 7
osPriorityAboveNormal 比普通等级稍高的优先级
osPriorityAboveNormal1 比普通等级稍高的优先级 + 1,这是当前版本可用的最高优先级
osPriorityAboveNormal2 比普通等级稍高的优先级 + 2
osPriorityAboveNormal3 比普通等级稍高的优先级 + 3
osPriorityAboveNormal4 比普通等级稍高的优先级 + 4
osPriorityAboveNormal5 比普通等级稍高的优先级 + 5
osPriorityAboveNormal6 比普通等级稍高的优先级 + 6
osPriorityAboveNormal7 比普通等级稍高的优先级 + 7
osPriorityHigh 高优先级
osPriorityHigh1 高优先级 + 1
osPriorityHigh2 高优先级 + 2
osPriorityHigh3 高优先级 + 3
osPriorityHigh4 高优先级 + 4
osPriorityHigh5 高优先级 + 5
osPriorityHigh6 高优先级 + 6
osPriorityHigh7 高优先级 + 7
osPriorityRealtime 实时优先级
osPriorityRealtime1 实时优先级 + 1
osPriorityRealtime2 实时优先级 + 2
osPriorityRealtime3 实时优先级 + 3
osPriorityRealtime4 实时优先级 + 4
osPriorityRealtime5 实时优先级 + 5
osPriorityRealtime6 实时优先级 + 6
osPriorityRealtime7 实时优先级 + 7
osPriorityISR 为ISR(interrupt service routine,中断服务程序)保留的优先级
osPriorityError 非法的优先级
osPriorityReserved 保留的优先级,用于阻止编译器对枚举进行优化

osStatus_t

enum osStatus_t

描述:

CMSIS接口标准返回值枚举。

枚举值 描述
osOK 操作成功
osError 未特别说明的错误
osErrorTimeout 超时错误
osErrorResource 资源错误
osErrorParameter 参数错误
osErrorNoMemory 内存不足
osErrorISR 中断服务错误
osStatusReserved 保留的定义,用于阻止编译器对枚举进行优化

osThreadState_t

enum osThreadState_t

描述:

线程状态枚举。

该枚举用于描述线程的运行状态。

枚举值 描述
osThreadInactive 线程未运行
osThreadReady 线程就绪
osThreadRunning 线程运行中
osThreadBlocked 线程阻塞
osThreadTerminated 线程结束
osThreadError 线程异常
osThreadReserved 保留的状态,用于阻止编译器对枚举进行优化

osTimerType_t

enum osTimerType_t

描述:

定时器类型枚举。

该枚举用于定义定时器的类型。

枚举值 描述
osTimerOnce 单次触发定时器
osTimerPeriodic 重复触发定时器

函数说明

osDelay

osStatus_t osDelay (uint32_t ticks)

描述:

延时等待函数。

用于把本线程置于挂起状态并立即发生上下文切换。开发者可自行提供硬件延时函数VOID HalDelay(UINT32 ticks),即可在系统未运行时执行本函数。

参数:

Name 描述
ticks 任务延时的tick数。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorISR,表示在中断中调用本函数。

osError,表示其他错误。

osDelayUntil

osStatus_t osDelayUntil (uint32_t ticks)

描述:

指定到期时间的延时等待函数。

参数:

Name 描述
ticks 绝对时间,不能小于当前时间。

返回:

osOK,表示执行成功。

osErrorISR,表示在中断中调用本函数。

osError,表示其他错误。

osEventFlagsClear

uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags)

描述:

清除事件标志函数。

用于清除指定的事件标志,并返回清除前的事件标志。

参数:

Name 描述
ef_id 定时器ID(由osEventFlagsNew创建)。
flags 待清除标志。

返回:

成功,返回清除前的事件标志。

osFlagsErrorParameter,表示参数错误。

osFlagsErrorResource,表示其他错误。

osEventFlagsDelete

osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id)

描述:

事件删除函数。

参数:

Name 描述
ef_id 定时器ID(由osEventFlagsNew创建)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorISR,表示在中断中调用本函数。

osEventFlagsGet

uint32_t osEventFlagsGet (osEventFlagsId_t ef_id)

描述:

获取事件标志函数。

参数:

Name 描述
ef_id 定时器ID(由osEventFlagsNew创建)。

返回:

成功,返回当前事件标志数值。

0,表示执行失败。

osEventFlagsGetName

const char* osEventFlagsGetName (osEventFlagsId_t ef_id)

描述:

获取事件名称函数。

参数:

Name 描述
ef_id 定时器ID(由osEventFlagsNew创建)。

返回:

当前只能返回NULL。

osEventFlagsNew

osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t * attr)

描述:

事件初始化函数。

参数:

Name 描述
attr 事件参数,当前不支持该参数,参数可为NULL。

返回:

成功,返回创建的事件ID。

NULL,表示执行失败或在中断中调用该函数。

osEventFlagsSet

uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags)

描述:

设置事件标志函数。

参数:

Name 描述
ef_id 定时器ID(由osEventFlagsNew创建)。
flags 待设置标志,第25位不能设置为1。

返回:

成功,返回设置后的标志。

osFlagsErrorParameter,表示参数错误。

osFlagsErrorResource,表示其他问题。

osEventFlagsWait

uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout)

描述:

事件标志等待函数。

参数:

Name 描述
ef_id 定时器ID(由osEventFlagsNew创建)。
flags 等待的标志,第25位不能设置为1。
options 等待设置,仅限于osFlagsWaitAny | osFlagsWaitAll | osFlagsNoClear。
timeout 超时时间,单位:tick。

返回:

成功,返回等到的标志,内容与参数options设置有关。

osFlagsErrorParameter,表示参数错误或中断中调用该函数。

osFlagsErrorTimeout,表示超时错误。

osFlagsErrorResource,表示其他问题。

osKernelGetInfo

osStatus_t osKernelGetInfo (osVersion_t * version, char * id_buf, uint32_t id_size)

描述:

获取系统版本号和系统名称。

参数:

Name 描述
version 指向获取版本信息缓冲区的指针。
id_buf 指向获取内核版本缓冲区的指针。
id_size 用于获取内核版本缓冲区的大小,单位字节。

返回:

osOK,表示执行成功。

osError,表示其他错误。

osKernelGetState

osKernelState_t osKernelGetState (void)

描述:

获取内核状态。

返回:

返回系统状态的枚举值。

osKernelGetSysTimerCount

uint32_t osKernelGetSysTimerCount (void)

描述:

获取系统启动后时间。

返回:

返回启动后的时间(单位: cycle)。

osKernelGetSysTimerFreq

uint32_t osKernelGetSysTimerFreq (void)

描述:

获取内核cpu cycle频率函数。

返回:

返回每秒cycle数(单位: cycle)。

osKernelGetTickCount

uint32_t osKernelGetTickCount (void)

描述:

获取内核tick函数。

返回:

返回当前的tick。

osKernelGetTickFreq

uint32_t osKernelGetTickFreq (void)

描述:

获取内核tick频率函数。

返回:

返回每秒的tick数。

osKernelInitialize

osStatus_t osKernelInitialize (void)

描述:

内核初始化函数。

初始化实时操作系统内核,大部分接口无法在初始化之前使用。

返回:

osOK,表示执行成功。

osErrorISR,表示在中断中调用本函数。

osError,表示其他错误。

osKernelLock

int32_t osKernelLock (void)

描述:

内核调度锁定函数。

返回:

成功,返回前一次的锁定状态(1为锁定,0为未锁定)。

osErrorISR,表示在中断中调用本函数。

osError,表示其他错误。

osKernelRestoreLock

int32_t osKernelRestoreLock (int32_t lock)

描述:

内核调度锁恢复函数。

参数:

Name 描述
lock 待恢复的锁定状态。

返回:

成功,返回恢复后的锁定状态(1为锁定,0为未锁定)。

osErrorISR,表示在中断中调用本函数。

osError,表示其他错误。

osKernelResume

void osKernelResume (uint32_t sleep_ticks)

描述:

内核挂起恢复函数,不支持。

osKernelStart

osStatus_t osKernelStart (void)

描述:

内核启动函数。

用于开启内核调度,调度之前需要osKernelInitialize

返回:

osOK,表示执行成功。

osErrorISR,表示在中断中调用本函数。

osError,表示其他错误。

osKernelSuspend

uint32_t osKernelSuspend (void)

描述:

内核挂起函数,不支持。

osKernelUnlock

int32_t osKernelUnlock (void)

描述:

内核调度解锁函数。

返回:

成功,返回前一次的锁定状态(1为锁定,0为未锁定)。

osErrorISR,表示在中断中调用本函数。

osError,表示其他错误。

osMemoryPoolAlloc

void* osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout)

描述:

申请内存函数。

用于从内存池中获取到一块内存,该函数不会阻塞。

参数:

Name 描述
mp_id 内存池ID(由osMemoryPoolNew创建)。
timeout 超时时间,当前不支持阻塞,参数不生效。

返回:

成功,返回分配内存块的地址。

NULL,表示参数错误或中断中调用本函数。

osMemoryPoolDelete

osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id)

描述:

删除内存池函数。

参数:

Name 描述
mp_id 内存池ID(由osMemoryPoolNew创建)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorISR,表示在中断中调用本函数。

osErrorResource,表示其他错误。

osMemoryPoolFree

osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void * block)

描述:

释放内存函数。

用于从内存池中释放一块内存。

参数:

Name 描述
mp_id 内存池ID(由osMemoryPoolNew创建)。
block 要释放的块地址。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osMemoryPoolGetBlockSize

uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id)

描述:

获取内存池块大小函数。

参数:

Name 描述
mp_id 内存池ID(由osMemoryPoolNew创建)。

返回:

成功,返回块大小,单位字节。

0,表示参数错误。

osMemoryPoolGetCapacity

uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id)

描述:

获取内存池拥有块数量函数。

参数:

Name 描述
mp_id 内存池ID(由osMemoryPoolNew创建)。

返回:

成功,返回块数量。

0,表示参数错误。

osMemoryPoolGetCount

uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id)

描述:

获取内存池块使用块函数。

参数:

Name 描述
mp_id 内存池ID(由osMemoryPoolNew创建)。

返回:

成功,返回已使用块数量。

0,表示参数错误。

osMemoryPoolGetName

const char* osMemoryPoolGetName (osMemoryPoolId_t mp_id)

描述:

获取内存池名称函数。

参数:

Name 描述
mp_id 内存池ID(由osMemoryPoolNew创建)。

返回:

成功,返回内存池名。

NULL,表示参数错误或中断中调用本函数。

osMemoryPoolGetSpace

uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id)

描述:

获取内存池剩余块函数。

参数:

Name 描述
mp_id 内存池ID(由osMemoryPoolNew创建)。

返回:

成功,返回剩余数量。

0,表示参数错误。

osMemoryPoolNew

osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t * attr)

描述:

内存池初始化函数。

参数:

Name 描述
block_count 内存池块数。
block_size 内存池块大小,单位:字节。
attr 内存池参数,若参数为NULL则使用默认配置。
- attr->name 不支持配置。
- attr->attr_bits 不支持配置。
- attr->cb_mem不为NULL且attr->cb_size大于控制块所需大小即可使用外部传入的内存池控制块。 内存池控制块必需大小当前为36字节(sizeof(MemPoolCB),MemPoolCB定义在cmsis_liteos2.c中)。
- attr->mp_mem,用户指定的内存池指针,指向的地址符合4字节对齐时使用用户指定的内存作为内存池。
- attr->mp_size,用户指定的内存大小,使用用户指定内存作为内存池时,需配置为不小于内存池所有节点所需的空间。

返回:

成功,返回内存池ID。

NULL,表示参数错误或中断中调用本函数。

osMessageQueueDelete

osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id)

描述:

删除消息队列函数。

参数:

Name 描述
mq_id 消息队列ID(由osMessageQueueNew创建)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorISR,表示在中断中调用本函数。

osMessageQueueGet

osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void * msg_ptr, uint8_t * msg_prio, uint32_t timeout)

描述:

消息队列接收消息函数。

用于把消息队列中读取一条消息,当前不支持消息优先级。

参数:

Name 描述
mq_id 消息队列ID(由osMessageQueueNew创建)。
msg_ptr 指向缓冲区的指针,获取到的数据会拷贝到该缓冲区。
msg_prio 消息优先级,当前不支持该参数。
timeout 超时时间,单位:tick。在中断中调用时必须设置为0。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorTimeout,表示超时错误。

osMessageQueueGetCapacity

uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id)

描述:

获取消息队列最大节点数函数。

参数:

Name 描述
mq_id 消息队列ID(由osMessageQueueNew创建)。

返回:

成功,返回队列最大节点数。

0,表示参数错误。

osMessageQueueGetCount

uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id)

描述:

获取消息队列待读节点数量函数。

参数:

Name 描述
mq_id 消息队列ID(由osMessageQueueNew创建)。

返回:

成功,返回待读节点数量。

0,表示参数错误。

osMessageQueueGetMsgSize

uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id)

描述:

获取消息队列节点大小函数。

参数:

Name 描述
mq_id 消息队列ID(由osMessageQueueNew创建)。

返回:

成功,返回队列节点大小,单位: 字节。

0,表示参数错误。

osMessageQueueGetName

const char* osMessageQueueGetName (osMessageQueueId_t mq_id)

描述:

获取消息队列名称函数。

参数:

Name 描述
mq_id 消息队列ID(由osMessageQueueNew创建)。

返回:

成功,返回消息队列名。

NULL,表示参数错误或未设置队列名。

osMessageQueueGetSpace

uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id)

描述:

获取消息队列剩余可用节点数量函数。

参数:

Name 描述
mq_id 消息队列ID(由osMessageQueueNew创建)。

返回:

成功,返回剩余可用节点数量。

0,表示参数错误。

osMessageQueueNew

osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t * attr)

描述:

消息队列初始化函数。

用于初始化消息队列,使用外部内存做队列空间时,需提前打开内核编译选项 LOSCFG_BASE_IPC_QUEUE_STATIC。

参数:

Name 描述
msg_count 队列的节点数量。
msg_size 队列的单个节点空间大小,单位: 字节,使用用户指定内存做队列空间时该参数不生效但不可设置为0。
attr 队列参数,若参数为NULL则使用默认配置。
- attr->name 入参可为NULL,若传递非NULL时需确保传递一个常量。
- attr->attr_bits 不支持配置。
- attr->cb_mem 不支持配置。
- attr->cb_size 不支持配置。
- attr->mq_mem 用户指定内存指针做为队列空间,为NULL则内存由系统自动分配。
- attr->mq_size 用户指定内存大小,由单个节点大小和节点数量相乘获得。

返回:

成功,返回消息队列ID。

NULL,表示参数错误或中断中调用本函数。

osMessageQueuePut

osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void * msg_ptr, uint8_t msg_prio, uint32_t timeout)

描述:

消息队列发送消息函数。

用于把消息插入队列中,当前不支持消息优先级,新消息会在队列尾部。

参数:

Name 描述
mq_id 消息队列ID(由osMessageQueueNew创建)。
msg_ptr 指向缓冲区的指针,数据会拷贝到消息队列中。
msg_prio 消息优先级,当前不支持该参数。
timeout 超时时间,单位:tick。在中断中调用时必须设置为0。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorTimeout,表示超时错误。

osMessageQueueReset

osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id)

描述:

消息队列重置函数,不支持。

osMutexAcquire

osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout)

描述:

获取互斥锁函数。

会阻塞线程运行直到获取互斥锁成功或超时。

参数:

Name 描述
mutex_id 互斥锁ID(由osMutexNew创建)。
timeout 互斥锁获取超时时间,单位:tick。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorISR,表示在中断中调用本函数。

osErrorTimeout,表示超时错误。

osMutexDelete

osStatus_t osMutexDelete (osMutexId_t mutex_id)

描述:

互斥锁删除函数。

参数:

Name 描述
mutex_id 互斥锁ID(由osMutexNew创建)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorISR,表示在中断中调用本函数。

osMutexGetName

const char* osMutexGetName (osMutexId_t mutex_id)

描述:

获取互斥锁名称函数,不支持。

osMutexGetOwner

osThreadId_t osMutexGetOwner (osMutexId_t mutex_id)

描述:

获取互斥锁所有者函数。

参数:

Name 描述
mutex_id 互斥锁ID(由osMutexNew创建)。

返回:

成功,返回线程ID。

NULL,表示参数错误或中断中调用本函数。

osMutexNew

osMutexId_t osMutexNew (const osMutexAttr_t * attr)

描述:

互斥锁初始化函数。

参数:

Name 描述
attr 互斥锁参数,当前内部未使用该参数,参数可为NULL。

返回:

成功,返回互斥锁ID。

NULL,执行失败或在中断中调用该函数。

osMutexRelease

osStatus_t osMutexRelease (osMutexId_t mutex_id)

描述:

释放互斥锁函数。

等待该互斥锁的线程会从阻塞中恢复。

参数:

Name 描述
mutex_id 互斥锁ID(由osMutexNew创建)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorISR,表示在中断中调用本函数。

osSemaphoreAcquire

osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout)

描述:

获取信号量函数。

会阻塞线程运行直到获取信号量成功或超时。

参数:

Name 描述
semaphore_id 信号量ID(由osSemaphoreNew创建)。
timeout 超时时间,单位:tick。在中断中调用时必须设置为0。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorTimeout,表示超时错误。

osSemaphoreDelete

osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id)

描述:

信号量删除函数。

参数:

Name 描述
semaphore_id 信号量ID(由osSemaphoreNew创建)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误或中断中调用本函数。

osErrorResource,表示其他错误。

osSemaphoreGetCount

uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id)

描述:

获取信号量可用数量。

参数:

Name 描述
semaphore_id 信号量ID(由osSemaphoreNew创建)。

返回:

成功,返回当前可用信号量数量。

0,表示执行失败或当执行成功但无可用信号量。

osSemaphoreGetName

const char* osSemaphoreGetName (osSemaphoreId_t semaphore_id)

描述:

获取信号量名称函数。

参数:

Name 描述
semaphore_id 信号量ID(由osSemaphoreNew创建)。

返回:

当前只能返回NULL。

osSemaphoreNew

osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t * attr)

描述:

信号量初始化函数。

参数:

Name 描述
max_count 信号量可申请最大值,max_count值为1时会创建一个二元信号量。
initial_count 信号量初始值。
attr 信号量参数,当前内部未使用该参数,参数可为NULL。

返回:

成功,返回信号量ID。

NULL,表示参数错误或中断中调用本函数。

osSemaphoreRelease

osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id)

描述:

释放信号量函数。

等待该信号量的线程会从阻塞中恢复。

参数:

Name 描述
semaphore_id 信号量ID(由osSemaphoreNew创建)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osThreadDetach

osStatus_t osThreadDetach (osThreadId_t thread_id)

描述:

线程分离函数。

用于把指定线程属性设置为osThreadDetached

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorISR,表示在中断中调用本函数。

osThreadEnumerate

uint32_t osThreadEnumerate (osThreadId_t * thread_array, uint32_t array_items)

描述:

获取活动线程枚举,不支持。

osThreadExit

__NO_RETURN void osThreadExit (void)

描述:

当前线程退出函数。

用于线程退出,本函数不会返回。

返回:

本函数不会返回。

osThreadFlagsClear

uint32_t osThreadFlagsClear (uint32_t flags)

描述:

清除线程的指定线程标志。

用于清除当前正在运行的线程的指定线程标志。

参数:

Name 描述
flags 待清除的标志,线程标志的第25位为错误标志。

返回:

成功,返回清除前的标志。

osFlagsErrorUnknown,表示在中断中调用本函数。

osFlagsErrorResource,表示其他错误。

osThreadFlagsGet

uint32_t osThreadFlagsGet (void)

描述:

获取线程的线程标志。

返回:

成功,返回当前的标志。

osFlagsErrorUnknown,表示在中断中调用本函数。

osThreadFlagsSet

uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags)

描述:

设置线程的指定线程标志。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。
flags 设置的标志,第25位不能设置为1,函数会返回参数错误。

返回:

成功,返回设置后的标志。

osFlagsErrorParameter,表示参数错误。

osFlagsErrorResource,表示其他错误。

osThreadFlagsWait

uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout)

描述:

等待指定线程标志。

参数:

Name 描述
flags 等待的标志,第 25 位为错误标志。
options 等待的方式,仅限于osFlagsWaitAny | osFlagsWaitAll | osFlagsNoClear
timeout 等待超时时间,单位:tick。

返回:

成功,返回等到的标志,内容与参数options设置有关。

osFlagsErrorUnknown,表示在中断中调用本函数。

osFlagsErrorParameter,表示flag错误或者options错误。

osFlagsErrorTimeout,表示等待超时。

osFlagsErrorResource,表示其他问题。

osThreadGetCount

uint32_t osThreadGetCount (void)

描述:

获取使用中的线程数量。

返回:

返回线程数量。

0,表示中断中调用该函数。

osThreadGetId

osThreadId_t osThreadGetId (void)

描述:

获取当前线程ID函数。

返回:

返回线程ID,该函数不会返回失败。

osThreadGetName

const char* osThreadGetName (osThreadId_t thread_id)

描述:

获取线程名称函数。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

返回线程名称。

NULL,表示失败或在中断中调用该函数。

osThreadGetPriority

osPriority_t osThreadGetPriority (osThreadId_t thread_id)

描述:

获取线程优先级函数。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

成功,返回有效的线程优先级。

osPriorityError,表示参数错误或在中断中调用本函数。

osThreadGetStackSize

uint32_t osThreadGetStackSize (osThreadId_t thread_id)

描述:

获取线程栈大小函数。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

返回指定线程栈大小,单位: 字节。

0,表示失败或在中断中调用该函数。

osThreadGetStackSpace

uint32_t osThreadGetStackSpace (osThreadId_t thread_id)

描述:

获取线程栈使用水线函数。

用于获取指定线程的栈使用水线,该函数无法通过配置来返回栈剩余空间。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

返回指定线程栈水线,单位: 字节。

0,表示失败或在中断中调用该函数。

osThreadGetState

osThreadState_t osThreadGetState (osThreadId_t thread_id)

描述:

获取线程状态函数。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

返回线程状态枚举。

osThreadError,表示在中断中调用该函数。

osThreadJoin

osStatus_t osThreadJoin (osThreadId_t thread_id)

描述:

等待指定线程终止函数。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorISR,表示在中断中调用本函数。

osThreadNew

osThreadId_t osThreadNew (osThreadFunc_t func, void * argument, const osThreadAttr_t * attr)

描述:

创建线程函数。

用于创建一个活跃的线程,当创建的线程函数的优先级高于当前的运行线程时创建的线程函数立即启动,成为新的运行线程。

参数:

Name 描述
func 线程回调入口函数
argument 传递给线程回调函数的参数
attr 线程属性,传递NULL或者对于非NULL结构体中未配置的成员会使用默认值。
- attr->name 入参为NULL时使用默认名称,若传递非NULL时需确保传递常量。
- attr->attr_bits 未设置为osThreadJoinable时会默认设置为osThreadDetached
- attr->cb_mem 不支持。
- attr->cb_size 不支持。
- attr->stack_mem和attr->stack_size同时设置有效数据才能使用用户指定内存作为任务栈。
- attr->stack_size 设置为0会使用默认栈大小。
- attr->priority 当前可用优先级最高为osPriorityAboveNormal1,最低为osPriorityLow。
- attr->tz_module 不支持。

返回:

返回创建的线程ID。

NULL,表示执行失败或在中断中调用该函数。

osThreadResume

osStatus_t osThreadResume (osThreadId_t thread_id)

描述:

线程挂起恢复函数。

用于把指定线程设置为就绪状态。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示线程未创建或未挂起。

osErrorISR,表示在中断中调用本函数。

osThreadSetPriority

osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority)

描述:

设置线程优先级函数。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。
priority 待设置的优先级,当前可用优先级最高为osPriorityAboveNormal1,最低为osPriorityLow。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示对未创建的线程进行操作。

osErrorISR,表示在中断中调用本函数。

osThreadSuspend

osStatus_t osThreadSuspend (osThreadId_t thread_id)

描述:

线程挂起函数。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示线程未创建或已挂起或已锁定。

osErrorISR,表示在中断中调用本函数。

osThreadTerminate

osStatus_t osThreadTerminate (osThreadId_t thread_id)

描述:

指定线程终止函数。

参数:

Name 描述
thread_id 线程ID(由osThreadNew创建或osThreadGetId获取)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示线程未创建。

osErrorISR,表示在中断中调用本函数。

osThreadYield

osStatus_t osThreadYield (void)

描述:

线程显式放权。

用于将控制权让给其他线程,由于本线程未设置为阻塞态,若无其他同优先级可执行线程,可能继续执行本线程。

返回:

osOK,表示执行成功。

osErrorISR,表示在中断中调用本函数。

osError,表示其他错误。

osTimerDelete

osStatus_t osTimerDelete (osTimerId_t timer_id)

描述:

定时器删除函数。

参数:

Name 描述
timer_id 定时器ID(由osTimerNew创建)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorISR,表示在中断中调用本函数。

osTimerGetName

const char* osTimerGetName (osTimerId_t timer_id)

描述:

获取定时器名称函数。

参数:

Name 描述
timer_id 定时器ID(由osTimerNew创建)。

返回:

当前只能返回NULL。

osTimerIsRunning

uint32_t osTimerIsRunning (osTimerId_t timer_id)

描述:

定时器状态查询函数。

用于判断定时器是否在运行。

参数:

Name 描述
timer_id 定时器ID(由osTimerNew创建)。

返回:

成功,返回状态(0为未运行,1为运行)。

osErrorISR,表示在中断中调用本函数。

0,表示入参为NULL或未运行。

osTimerNew

osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void * argument, const osTimerAttr_t * attr)

描述:

定时器创建函数。

用于创建一个定时器,定时器osTimerStart启动之前处于停止状态。

参数:

Name 描述
func 定时器回调函数。
type 定时器类型,仅限于osTimerOnce或osTimerPeriodic。
argument 定时器回调函数参数。
attr 定时器属性,当前不支持该参数,参数可为NULL。

返回:

返回创建的定时器ID。

NULL,表示执行失败或在中断中调用该函数。

osTimerStart

osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks)

描述:

定时器开始运行函数。

参数:

Name 描述
timer_id 定时器ID(由osTimerNew创建)。
ticks 定时器颗粒度。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorISR,表示在中断中调用本函数。

osTimerStop

osStatus_t osTimerStop (osTimerId_t timer_id)

描述:

定时器停止运行函数。

参数:

Name 描述
timer_id 定时器ID(由osTimerNew创建)。

返回:

osOK,表示执行成功。

osErrorParameter,表示参数错误。

osErrorResource,表示其他错误。

osErrorISR,表示在中断中调用本函数。