148 lines
5.3 KiB
C
148 lines
5.3 KiB
C
#ifndef _API_COTIME_H
|
||
#define _API_COTIME_H
|
||
|
||
#include "include.h"
|
||
|
||
//CO timer
|
||
typedef enum
|
||
{
|
||
/// Only run once
|
||
TIMER_ONE_SHOT,
|
||
/// Repeat until stop it
|
||
TIMER_REPEAT,
|
||
}co_timer_mode_t;
|
||
|
||
typedef struct _co_timer_t {
|
||
struct _co_timer_t *next;
|
||
co_timer_mode_t mode;
|
||
uint32_t time_sorce;
|
||
uint32_t time_out;
|
||
uint32_t en : 1;
|
||
uint32_t is_sleep_run : 1;
|
||
void *func_cb;
|
||
void *param;
|
||
}co_timer_t;
|
||
|
||
typedef void (*co_timer_callback_t)(co_timer_t *timer, void *param);
|
||
|
||
//CO
|
||
/**
|
||
* @brief Setup a software timer with millisecond
|
||
* 设置软定时器
|
||
* @param[in] timer the timer object (must be static or global variable)
|
||
* @param[in] delay it uint is 1ms
|
||
* @param[in] mode one shot or repeat
|
||
* @param[in] callback expire callback
|
||
* @param[in] param params
|
||
*
|
||
* @return false: Set timer fail;
|
||
* true: Set timer success
|
||
**/
|
||
bool co_timer_set(co_timer_t *timer, uint32_t delay, co_timer_mode_t mode,
|
||
co_timer_callback_t callback, void *param);
|
||
|
||
/**
|
||
* @brief 删除对应软定时器
|
||
*
|
||
* @param[in] timer the timer object (must be static or global variable)
|
||
*
|
||
* @return None
|
||
**/
|
||
void co_timer_del(co_timer_t *timer);
|
||
|
||
/**
|
||
* @brief reset a timer
|
||
*
|
||
* @param[in] timer the timer object (must be static or global variable)
|
||
*
|
||
* @return false: Reset timer fail;
|
||
true: Reset timer success
|
||
**/
|
||
bool co_timer_reset(co_timer_t *timer);
|
||
|
||
/**
|
||
* @brief 打开或关闭对应软定时器
|
||
* 注:只是关闭或打开,而不是删除
|
||
* @param[in] timer the timer object (must be static or global variable)
|
||
* @param[in] enable
|
||
*
|
||
* @return false: Reset timer fail;
|
||
true: Reset timer success
|
||
**/
|
||
bool co_timer_enable(co_timer_t *timer, bool en);
|
||
|
||
/**
|
||
* @brief 设置对应的软定时器是否可以在sleep模式下运行
|
||
*
|
||
* @param[in] timer the timer object (must be static or global variable)
|
||
* @param[in] is_acitve : true-> Exe in sleep, when time out.
|
||
*
|
||
* @return false: Set timer fail;
|
||
* true: Set timer success
|
||
**/
|
||
bool co_timer_set_sleep(co_timer_t *timer, bool is_acitve);
|
||
|
||
/**
|
||
* @brief 对应timer是否在队列里
|
||
*
|
||
* @param[in] timer the timer object (must be static or global variable)
|
||
*
|
||
* @return false: timer 没在队列
|
||
* true: timer 在队列里
|
||
**/
|
||
bool co_timer_handle_valid(co_timer_t *timer);
|
||
|
||
/**
|
||
* @brief 设置软定时器最大数量
|
||
* 默认是100个,即不调用这个函数之前,默认是100
|
||
* @param[in] 最大数量
|
||
*
|
||
**/
|
||
void co_timer_max_num_set(u8 num);
|
||
|
||
|
||
void co_timer_init(void);
|
||
bool co_timer_enable(co_timer_t *timer, bool en);
|
||
bool co_timer_reset(co_timer_t *timer);
|
||
|
||
bool co_timer_pro(bool is_sleep_mode);
|
||
bool co_timer_pro_sleep(void);
|
||
bool co_timer_is_plan(void);
|
||
u32 co_timer_get_min_time(bool type);
|
||
bool co_timer_sleep_10ms_enable(void);
|
||
u32 co_timer_tick_get(void);
|
||
bool co_timer_check_expire(u32 tick, u32 co_expire);
|
||
|
||
typedef bool (*co_timer_set_func) (co_timer_t *timer, uint32_t delay, co_timer_mode_t mode, co_timer_callback_t callback, void *param);
|
||
typedef void (*co_timer_del_func) (co_timer_t *timer);
|
||
typedef bool (*co_timer_reset_func) (co_timer_t *timer);
|
||
typedef bool (*co_timer_enable_func) (co_timer_t *timer, bool en);
|
||
typedef bool (*co_timer_set_sleep_func) (co_timer_t *timer, bool is_acitve);
|
||
typedef bool (*co_timer_handle_valid_func) (co_timer_t *timer);
|
||
typedef void (*co_timer_max_num_set_func) (u8 num);
|
||
typedef void (*co_timer_init_func) (void);
|
||
typedef bool (*co_timer_pro_func) (bool is_sleep_mode);
|
||
typedef bool (*co_timer_pro_sleep_func) (void);
|
||
typedef bool (*co_timer_is_plan_func) (void);
|
||
typedef u32 (*co_timer_get_min_time_func) (bool type);
|
||
typedef bool (*co_timer_sleep_10ms_enable_func) (void);
|
||
typedef u32 (*co_timer_tick_get_func) (void);
|
||
typedef bool (*co_timer_check_expire_func) (u32 tick, u32 co_expire);
|
||
|
||
#define sys_co_timer_set ((co_timer_set_func)(co_timer_set))
|
||
#define sys_co_timer_del ((co_timer_del_func)(co_timer_del))
|
||
#define sys_co_timer_reset ((co_timer_reset_func)(co_timer_reset))
|
||
#define sys_co_timer_enable ((co_timer_enable_func)(co_timer_enable))
|
||
#define sys_co_timer_set_sleep ((co_timer_set_sleep_func)(co_timer_set_sleep))
|
||
#define sys_co_timer_handle_valid ((co_timer_handle_valid_func)(co_timer_handle_valid))
|
||
#define sys_co_timer_max_num_set ((co_timer_max_num_set_func)(co_timer_max_num_set))
|
||
#define sys_co_timer_init ((co_timer_init_func)(co_timer_init))
|
||
#define sys_co_timer_pro ((co_timer_pro_func)(co_timer_pro))
|
||
#define sys_co_timer_pro_sleep ((co_timer_pro_sleep_func)(co_timer_pro_sleep))
|
||
#define sys_co_timer_is_plan ((co_timer_is_plan_func)(co_timer_is_plan))
|
||
#define sys_co_timer_get_min_time ((co_timer_get_min_time_func)(co_timer_get_min_time))
|
||
#define sys_co_timer_sleep_10ms_enable ((co_timer_sleep_10ms_enable_func)(co_timer_sleep_10ms_enable))
|
||
#define sys_co_timer_tick_get ((co_timer_tick_get_func)(co_timer_tick_get))
|
||
#define sys_co_timer_check_expire ((co_timer_check_expire_func)(co_timer_check_expire))
|
||
|
||
#endif |