/****************************************************************************** Copyright @2024 - 2044 Shenzhen dcenzix Technology Ltd. ****************************************************************************** @file cola_os.h @brief @author xiexiongwu @version V1.0 @date 2024年5月25日 ******************************************************************************/ #ifndef __COLA_OS_H__ #define __COLA_OS_H__ /*----------------------------------------------* * 包含头文件 * *----------------------------------------------*/ #include #include /*----------------------------------------------* * 枚举定义 * *----------------------------------------------*/ /** \enum EN_COLA_EVENT_TYPE * \brief 事件类型 */ typedef enum COLA_EVENT_TYPE { EN_COLA_EVENT_ALARM = 1 << 0, EN_COLA_EVENT_DATA = 1 << 1, EN_COLA_EVENT_UART = 1 << 3, EN_COLA_EVENT_USR1 = 1 << 8, EN_COLA_EVENT_USR2 = 1 << 9, EN_COLA_EVENT_MSG = 1 << 15, } EN_COLA_EVENT_TYPE; /** \enum COLA_TIMER_TYPE * \brief 定时类型 */ typedef enum COLA_TIMER_TYPE { EN_COLA_TIMER_ALWAYS = 0x00, ///< 周期任务 EN_COLA_TIMER_ONE_SHOT = 0x01, ///< 单次任务 } EN_COLA_TIMER_TYPE; /** \enum EN_COLA_TASK_TYPE * \brief 任务类型 */ typedef enum COLA_TASK_TYPE { EN_COLA_TASK_TASK = 0x00, ///< 事件任务 EN_COLA_TASK_TIMER = 0x01, ///< 定时任务 } EN_COLA_TASK_TYPE; /*----------------------------------------------* * 宏定义 * *----------------------------------------------*/ typedef void (*cbFunc)(void *arg, uint32_t event); /*----------------------------------------------* * 结构体定义 * *----------------------------------------------*/ typedef struct task_s { uint32_t taskNum; ///< 任务编号 uint32_t period; ///< 定时周期 EN_COLA_TIMER_TYPE timerType; ///< 定时器类型 uint32_t timerTick; ///< 定时计数 bool start; ///< 开始启动 bool run; ///< 任务运行标志 EN_COLA_TASK_TYPE taskType; ///< 任务标志是主任务还是定时任务 uint32_t event; ///< 驱动事件 cbFunc func; ///< 回调函数 void *usr; ///< 用户接口 struct task_s *next; } __attribute__((aligned(4))) task_t; /*----------------------------------------------* * 全局变量 * *----------------------------------------------*/ extern volatile unsigned int jiffies; /*----------------------------------------------* * 函数原型说明 * *----------------------------------------------*/ #ifdef __cplusplus #if __cplusplus extern "C" { #endif #endif /* __cplusplus */ extern bool cola_clear_event(task_t *task, uint32_t event); extern void cola_delay_ms(uint32_t ms); extern bool cola_set_event(task_t *task, uint32_t event); extern bool cola_task_create(task_t *task, cbFunc func, void *arg); extern bool cola_task_delete(task_t *task); static bool cola_task_is_exists(task_t *task); extern void cola_task_loop(void); extern bool cola_timer_create(task_t *timer, cbFunc func, void *arg); extern bool cola_timer_delete(task_t *timer); extern bool cola_timer_start(task_t *timer, EN_COLA_TIMER_TYPE time_type, uint32_t time_ms); extern bool cola_timer_stop(task_t *timer); extern void cola_timer_ticker(void); extern unsigned int cola_get_ticker(void); #ifdef __cplusplus #if __cplusplus } #endif #endif /* __cplusplus */ #endif /* __COLA_OS_H__ */