diff --git a/include/HTimer.h b/include/HTimer.h index 4084cc4..2f2e475 100644 --- a/include/HTimer.h +++ b/include/HTimer.h @@ -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(); diff --git a/src/HProtocolBind.c b/src/HProtocolBind.c index ed497a9..932dc91 100644 --- a/src/HProtocolBind.c +++ b/src/HProtocolBind.c @@ -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 { diff --git a/src/HTimer.c b/src/HTimer.c index badae65..db8bb94 100644 --- a/src/HTimer.c +++ b/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); } }