luat_soc_sdk_2024 V1.0
luat_rtos.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2022 OpenLuat & AirM2M
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of
5 * this software and associated documentation files (the "Software"), to deal in
6 * the Software without restriction, including without limitation the rights to
7 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8 * the Software, and to permit persons to whom the Software is furnished to do so,
9 * subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22#ifndef LUAT_RTOS_H
23#define LUAT_RTOS_H
24
25#include "luat_base.h"
26#include "luat_rtos_legacy.h"
27
36typedef enum LUAT_RTOS_WAIT
37{
39 LUAT_WAIT_FOREVER = (uint32_t)0xFFFFFFFF
41
49
50/* ------------------------------------------------ task begin------------------------------------------------ */
59typedef void (*luat_rtos_task_entry) (void*);
63typedef void * luat_rtos_task_handle;
76int luat_rtos_task_create(luat_rtos_task_handle *task_handle, uint32_t stack_size, uint8_t priority, const char *task_name, luat_rtos_task_entry task_fun, void* user_data, uint16_t event_cout);
77
85
93
101
107
113
119void luat_rtos_task_sleep(uint32_t ms);
120
127
135
140
145void luat_rtos_task_run_time_record_print(uint8_t print_ticks);
147/* ------------------------------------------------ task end------------------------------------------------ */
152/* ----------------------------------------------- event begin---------------------------------------------- */
157typedef LUAT_RT_RET_TYPE (*luat_rtos_event_wait_callback_t)(LUAT_RT_CB_PARAM);
158
170int luat_rtos_event_send(luat_rtos_task_handle task_handle, uint32_t id, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t timeout);
171
182int luat_rtos_event_recv(luat_rtos_task_handle task_handle, uint32_t wait_event_id, luat_event_t *out_event, luat_rtos_event_wait_callback_t *callback_fun, uint32_t timeout);
183
184/* ----------------------------------------------- event end---------------------------------------------- */
185
186/* ----------------------------------------------- message begin---------------------------------------------- */
195int luat_rtos_message_send(luat_rtos_task_handle task_handle, uint32_t message_id, void *p_message);
196
206int luat_rtos_message_recv(luat_rtos_task_handle task_handle, uint32_t *message_id, void **p_p_message, uint32_t timeout);
209/* ----------------------------------------------- message end---------------------------------------------- */
210
216/* ---------------------------------------------- semaphore begin--------------------------------------------- */
228int luat_rtos_semaphore_create(luat_rtos_semaphore_t *semaphore_handle, uint32_t init_count);
229
237
245int luat_rtos_semaphore_take(luat_rtos_semaphore_t semaphore_handle, uint32_t timeout);
246
254/* ---------------------------------------------- semaphore end--------------------------------------------- */
261/* ------------------------------------------------ mutex begin----------------------------------------------- */
265typedef void * luat_rtos_mutex_t;
273
281int luat_rtos_mutex_lock(luat_rtos_mutex_t mutex_handle, uint32_t timeout);
282
290
298
299/* ------------------------------------------------ mutex end----------------------------------------------- */
306/* ------------------------------------------------ queue begin----------------------------------------------- */
307
311typedef void * luat_rtos_queue_t;
320int luat_rtos_queue_create(luat_rtos_queue_t *queue_handle, uint32_t item_count, uint32_t item_size);
321
329
339int luat_rtos_queue_send(luat_rtos_queue_t queue_handle, void *item, uint32_t item_size, uint32_t timeout);
340
350int luat_rtos_queue_recv(luat_rtos_queue_t queue_handle, void *item, uint32_t item_size, uint32_t timeout);
351
359int luat_rtos_queue_get_cnt(luat_rtos_queue_t queue_handle, uint32_t *item_cnt);
360/* ------------------------------------------------ queue end----------------------------------------------- */
367/* ------------------------------------------------ flag begin----------------------------------------------- */
368
372typedef void * luat_rtos_flag_t;
388int luat_rtos_flag_wait(luat_rtos_flag_t flag_handle, uint32_t mask, LUAT_FLAG_OP_E operation, uint32_t *flags,uint32_t timeout);
396int luat_rtos_flag_release(luat_rtos_flag_t flag_handle, uint32_t mask, LUAT_FLAG_OP_E operation);
404/* ------------------------------------------------ flag end----------------------------------------------- */
412/* ------------------------------------------------ timer begin----------------------------------------------- */
416typedef void * luat_rtos_timer_t;
420typedef LUAT_RT_RET_TYPE (*luat_rtos_timer_callback_t)(LUAT_RT_CB_PARAM);
428
436
447int luat_rtos_timer_start(luat_rtos_timer_t timer_handle, uint32_t timeout, uint8_t repeat, luat_rtos_timer_callback_t callback_fun, void *user_param);
448
456
464
465/*------------------------------------------------ timer end----------------------------------------------- */
473/* ------------------------------------------------ critical begin----------------------------------------------- */
480
486void luat_rtos_exit_critical(uint32_t critical);
487
494uint32_t luat_rtos_get_ipsr(void);
495/*------------------------------------------------ critical end----------------------------------------------- */
498#endif
int luat_rtos_task_suspend(luat_rtos_task_handle task_handle)
挂起某个task
int luat_rtos_task_create(luat_rtos_task_handle *task_handle, uint32_t stack_size, uint8_t priority, const char *task_name, luat_rtos_task_entry task_fun, void *user_data, uint16_t event_cout)
创建一个可以带mailbox机制的task,mailbox是message和event的基础,但是和queue无关
void luat_rtos_task_resume_all(void)
恢复全部task
int luat_rtos_task_delete(luat_rtos_task_handle task_handle)
删除task
uint32_t luat_rtos_task_get_high_water_mark(luat_rtos_task_handle task_handle)
获取task堆栈剩余的最小值,叫做“高水位线”
int luat_rtos_task_resume(luat_rtos_task_handle task_handle)
恢复挂起的task
void luat_rtos_task_run_time_record_print(uint8_t print_ticks)
打印所有task运行时间和占用百分比
void * luat_rtos_task_handle
定义task任务句柄
void luat_rtos_task_run_time_record_enable(void)
启动task运行时间记录功能,必须在task调度前启用
void luat_rtos_task_suspend_all(void)
挂起全部task
void luat_rtos_task_sleep(uint32_t ms)
task休眠一段时间
luat_rtos_task_handle luat_rtos_get_current_handle(void)
获取当前task的句柄
void(* luat_rtos_task_entry)(void *)
task的入口函数,函数类型
uint32_t luat_rtos_entry_critical(void)
进入临界保护
uint32_t luat_rtos_get_ipsr(void)
获取是否为中断
void luat_rtos_exit_critical(uint32_t critical)
退出临界保护
int luat_rtos_message_send(luat_rtos_task_handle task_handle, uint32_t message_id, void *p_message)
发送一个message给task的mailbox,只有设置了mailbox启用的task能接收,message可以动态创建的,可以任意大小,如果缓存了超过1024个message会断言
int luat_rtos_event_recv(luat_rtos_task_handle task_handle, uint32_t wait_event_id, luat_event_t *out_event, luat_rtos_event_wait_callback_t *callback_fun, uint32_t timeout)
接收一个event,只能在task里接收
int luat_rtos_event_send(luat_rtos_task_handle task_handle, uint32_t id, uint32_t param1, uint32_t param2, uint32_t param3, uint32_t timeout)
发送一个event给task的mailbox,只有设置了mailbox启用的task能接收,如果缓存了超过1024个event会断言
int luat_rtos_message_recv(luat_rtos_task_handle task_handle, uint32_t *message_id, void **p_p_message, uint32_t timeout)
接收一个message,只能在task里接收
LUAT_RT_RET_TYPE(* luat_rtos_event_wait_callback_t)(LUAT_RT_CB_PARAM)
在等待event中,如果设置了目标event id,而到来的不是目标event id,可以通过回调函数交给用户处理
int luat_rtos_flag_create(luat_rtos_flag_t *flag_handle)
创建事件
void * luat_rtos_flag_t
定义事件句柄
int luat_rtos_flag_wait(luat_rtos_flag_t flag_handle, uint32_t mask, LUAT_FLAG_OP_E operation, uint32_t *flags, uint32_t timeout)
等待事件
int luat_rtos_flag_delete(luat_rtos_flag_t flag_handle)
删除事件
int luat_rtos_flag_release(luat_rtos_flag_t flag_handle, uint32_t mask, LUAT_FLAG_OP_E operation)
设置事件
int luat_rtos_mutex_create(luat_rtos_mutex_t *mutex_handle)
互斥锁创建,不能在中断中unlock
int luat_rtos_mutex_lock(luat_rtos_mutex_t mutex_handle, uint32_t timeout)
获得锁
void * luat_rtos_mutex_t
定义mutex句柄
int luat_rtos_mutex_delete(luat_rtos_mutex_t mutex_handle)
删除互斥锁
int luat_rtos_mutex_unlock(luat_rtos_mutex_t mutex_handle)
释放锁
int luat_rtos_queue_send(luat_rtos_queue_t queue_handle, void *item, uint32_t item_size, uint32_t timeout)
往队列里发送一个元素
int luat_rtos_queue_create(luat_rtos_queue_t *queue_handle, uint32_t item_count, uint32_t item_size)
创建队列
int luat_rtos_queue_delete(luat_rtos_queue_t queue_handle)
删除队列
void * luat_rtos_queue_t
定义队列句柄
int luat_rtos_queue_recv(luat_rtos_queue_t queue_handle, void *item, uint32_t item_size, uint32_t timeout)
从队列里取出一个元素
int luat_rtos_queue_get_cnt(luat_rtos_queue_t queue_handle, uint32_t *item_cnt)
查询队列中剩余未处理的元素数量
void * luat_rtos_semaphore_t
定义信号量句柄
int luat_rtos_semaphore_delete(luat_rtos_semaphore_t semaphore_handle)
删除信号量
int luat_rtos_semaphore_take(luat_rtos_semaphore_t semaphore_handle, uint32_t timeout)
信号量等待获取
int luat_rtos_semaphore_create(luat_rtos_semaphore_t *semaphore_handle, uint32_t init_count)
信号量创建,可以在中断中release
int luat_rtos_semaphore_release(luat_rtos_semaphore_t semaphore_handle)
信号量释放发送
int luat_rtos_timer_create(luat_rtos_timer_t *timer_handle)
创建软件定时器
int luat_rtos_timer_stop(luat_rtos_timer_t timer_handle)
停止软件定时器
LUAT_RT_RET_TYPE(* luat_rtos_timer_callback_t)(LUAT_RT_CB_PARAM)
定义定时器处理函数
void * luat_rtos_timer_t
定时器头数据类型
int luat_rtos_timer_is_active(luat_rtos_timer_t timer_handle)
检测软件定时器是否处于激活状态
int luat_rtos_timer_delete(luat_rtos_timer_t timer_handle)
删除软件定时器
int luat_rtos_timer_start(luat_rtos_timer_t timer_handle, uint32_t timeout, uint8_t repeat, luat_rtos_timer_callback_t callback_fun, void *user_param)
启动软件定时器
LUAT_RTOS_WAIT
LUAT_RTOS 超时时间枚举值
LUAT_FLAG_OP_E
enum LUAT_RTOS_WAIT LUAT_RTOS_WAIT_E
LUAT_RTOS 超时时间枚举值
@ LUAT_NO_WAIT
@ LUAT_WAIT_FOREVER
@ LUAT_FLAG_OR
@ LUAT_FLAG_AND_CLEAR
@ LUAT_FLAG_OR_CLEAR
@ LUAT_FLAG_AND