diff --git a/drivers/common/opentimers.c b/drivers/common/opentimers.c index 0c7c6683ce..0a6f1dfeb8 100644 --- a/drivers/common/opentimers.c +++ b/drivers/common/opentimers.c @@ -65,8 +65,19 @@ opentimers_id_t opentimers_create(uint8_t timer_id, uint8_t task_prio){ } } + if (timer_id==TIMER_ISR){ + for (id = TIMER_TSCH + 1; id < TIMER_NUMBER_NON_GENERAL; id++){ + if (opentimers_vars.timersBuf[id].isUsed == FALSE){ + opentimers_vars.timersBuf[id].isUsed = TRUE; + opentimers_vars.timersBuf[id].timer_task_prio = task_prio; + ENABLE_INTERRUPTS(); + return id; + } + } + } + if (timer_id==TIMER_GENERAL_PURPOSE){ - for (id=TIMER_NUMBER_NON_GENERAL;id= TIMER_NUMBER_NON_GENERAL && opentimers_vars.timersBuf[i].currentCompareValue - opentimers_vars.currentCompareValue < PRE_CALL_TIMER_WINDOW){ opentimers_vars.timersBuf[i].currentCompareValue = opentimers_vars.currentCompareValue; } } @@ -385,7 +396,7 @@ void opentimers_timer_callback(void){ if (opentimers_vars.currentCompareValue == opentimers_vars.timersBuf[i].currentCompareValue){ // this timer expired, mark as expired opentimers_vars.timersBuf[i].lastCompareValue = opentimers_vars.timersBuf[i].currentCompareValue; - if (i==TIMER_TSCH){ + if (i < TIMER_NUMBER_NON_GENERAL && i != 0 ){ opentimers_vars.insideISR = TRUE; opentimers_vars.timersBuf[i].isrunning = FALSE; opentimers_vars.timersBuf[i].callback(i); @@ -460,4 +471,4 @@ void opentimers_timer_callback(void){ } else { opentimers_vars.running = FALSE; } -} \ No newline at end of file +} diff --git a/drivers/common/opentimers.h b/drivers/common/opentimers.h index 763035e420..fc067adcb0 100644 --- a/drivers/common/opentimers.h +++ b/drivers/common/opentimers.h @@ -7,6 +7,7 @@ #ifndef __OPENTIMERS_H #define __OPENTIMERS_H +#include "config.h" #include "opendefs.h" /** @@ -19,7 +20,7 @@ //=========================== define ========================================== /// Maximum number of timers that can run concurrently -#define MAX_NUM_TIMERS 15 +#define MAX_NUM_TIMERS (15 + TIMER_ISR_NUMBER) #define MAX_TICKS_IN_SINGLE_CLOCK (uint32_t)(((PORT_TIMER_WIDTH)0xFFFFFFFF)>>1) #define ERROR_NO_AVAILABLE_ENTRIES 255 #define MAX_DURATION_ISR 33 // 33@32768Hz = 1ms @@ -27,9 +28,9 @@ #define TIMER_INHIBIT 0 #define TIMER_TSCH 1 +#define TIMER_ISR 254 #define TIMER_GENERAL_PURPOSE 255 - -#define TIMER_NUMBER_NON_GENERAL 2 +#define TIMER_NUMBER_NON_GENERAL (2 + TIMER_ISR_NUMBER) #define SPLITE_TIMER_DURATION 15 // in ticks #define PRE_CALL_TIMER_WINDOW PORT_TsSlotDuration @@ -98,4 +99,4 @@ bool opentimers_isRunning(opentimers_id_t id); \} */ -#endif \ No newline at end of file +#endif diff --git a/inc/config.h b/inc/config.h index 3d483431df..612fdb6b1e 100644 --- a/inc/config.h +++ b/inc/config.h @@ -433,6 +433,20 @@ #define BOARD_FASTSIM_ENABLED (0) #endif +// ======================== Driver configuration ======================== + + +/** + * \def TIMER_ISR_NUMBER + * + * Number of TIMER_ISR, this does not include TIMER_TSCH or TIMER_INHIBIT + * + */ +#ifndef TIMER_ISR_NUMBER +#define TIMER_ISR_NUMBER (0) +#endif + + // ======================== Kernel configuration ======================== /**