1. 修改定时器接口, 索引值包含id
This commit is contained in:
parent
55e0793377
commit
cc177be0eb
@ -72,7 +72,7 @@ void HTimerRun(uint8_t id);
|
||||
HTimer_t HTimerAdd(uint8_t id, uint32_t ms, HTimerCallType call, eHTimerFlags flags);
|
||||
|
||||
///< 移除一个定时任务
|
||||
void HTimerRemove(uint8_t id, HTimer_t index);
|
||||
void HTimerRemove(HTimer_t index);
|
||||
|
||||
///< 在定时器回调任务中获取当前定时器ID
|
||||
uint8_t HTimerGetCurrentId();
|
||||
|
||||
@ -9,8 +9,8 @@
|
||||
#endif
|
||||
|
||||
#define CREATE_INDEX(id, index) ((id << 8) | index)
|
||||
#define GET_ID(index) ((index >> 8) & 0xFF)
|
||||
#define GET_INDEX(index) (index & 0xFF)
|
||||
#define GET_ID(index) ((index >> 8) & 0xFF)
|
||||
#define GET_INDEX(index) (index & 0xFF)
|
||||
|
||||
enum eEnableStatus
|
||||
{
|
||||
|
||||
13
src/HTimer.c
13
src/HTimer.c
@ -11,7 +11,10 @@
|
||||
|
||||
static uint32_t (*GetCurrentMs)(void);
|
||||
|
||||
#define CHECK_VALUE (0x0FFFFFFF)
|
||||
#define CHECK_VALUE (0x0FFFFFFF)
|
||||
#define CREATE_INDEX(id, index) ((id << 8) | index)
|
||||
#define GET_ID(index) ((index >> 8) & 0xFF)
|
||||
#define GET_INDEX(index) (index & 0xFF)
|
||||
|
||||
|
||||
struct __attribute__((packed)) TimeRegisterInfo {
|
||||
@ -84,7 +87,7 @@ static int16_t AddTimerData(uint8_t id, uint32_t duration, HTimerCallType call,
|
||||
sTimeRegisters[id].timers[i].lastTime = GetCurrentMs();
|
||||
sTimeRegisters[id].timers[i].call = call;
|
||||
sTimeRegisters[id].timers[i].flags = flags;
|
||||
return i;
|
||||
return CREATE_INDEX(id, i);
|
||||
}
|
||||
|
||||
LogD("timers full, id[%d], duration[%d], flags[%d]", id, duration, flags);
|
||||
@ -182,7 +185,9 @@ HTimer_t HTimerAdd(uint8_t id, uint32_t ms, HTimerCallType call, eHTimerFlags fl
|
||||
#endif
|
||||
}
|
||||
|
||||
void HTimerRemove(uint8_t id, HTimer_t index) {
|
||||
void HTimerRemove(HTimer_t index) {
|
||||
const uint8_t id = GET_ID(index);
|
||||
index = GET_INDEX(index);
|
||||
if (id >= HTIMER_REGISTER_MAX) {
|
||||
LogD("error id[%d]", id);
|
||||
return ;
|
||||
@ -217,7 +222,7 @@ HTimer_t HTimerGetCurrentCaller(uint8_t id) {
|
||||
|
||||
for (uint16_t i = 0; i < sTimeRegisters[id].len; ++i) {
|
||||
if (sTimeRegisters[id].timers[i].curr == 1) {
|
||||
return i;
|
||||
return CREATE_INDEX(id, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user