if (tid >= TIMER_NUM) {
// no such timer
DBGMSG("[DemoLib - Timer] No timer id %d", tid);
return -1;
}
if (hdlr == NULL) {
// NULL hdlr
DBGMSG("[DemoLib - Timer] Timer handler is NULL");
return -1;
}
cur = &(timers[tid]);
found = 0;
for (i=0; i<MAX_TIMER_HANDLER; i++) {
if (hdlr == cur->hdlr[i]) {
// hdlr already exists
DBGMSG("[DemoLib - Timer] This timer handler has already been registered");
found = 1;
break;
}
}
if (!found) {
for (i=0; i<MAX_TIMER_HANDLER; i++) {
if (cur->hdlr[i] == NULL) {
// Empty slot found. Insert hdlr
cur->hdlr[i] = hdlr;
cur->hdlr_num++;
if (!cur->valid) {
DBGMSG("[DemoLib - Timer] Timer id %d is invalid. Create timer id %d", tid, tid);
timer_set_timer(tid);
}
break;
}
}
}