*** stock_iot-lab_M3/openwsn/opentimers.c Thu Apr 24 11:01:37 2014 --- riot-openwsn-wip/openwsn/opentimers.c Thu Apr 24 16:55:54 2014 *************** *** 9,33 **** #include "openwsn.h" #include "opentimers.h" ! #include "bsp_timer.h" ! #include "leds.h" //=========================== define ========================================== //=========================== variables ======================================= - typedef struct { - opentimers_t timersBuf[MAX_NUM_TIMERS]; - bool running; - PORT_TIMER_WIDTH currentTimeout; // current timeout, in ticks - } opentimers_vars_t; - opentimers_vars_t opentimers_vars; //uint32_t counter; //counts the elapsed time. //=========================== prototypes ====================================== ! void opentimers_timer_callback(); //=========================== public ========================================== --- 9,34 ---- #include "openwsn.h" #include "opentimers.h" ! // #include "bsp_timer.h" ! #include "board_ow.h" ! #include "leds_ow.h" ! ! #include "hwtimer_cpu.h" ! #include "arch/hwtimer_arch.h" ! // #include "hwtimer.h" //=========================== define ========================================== //=========================== variables ======================================= opentimers_vars_t opentimers_vars; //uint32_t counter; //counts the elapsed time. + uint32_t timer_id; //=========================== prototypes ====================================== ! void opentimers_int_handler(int); ! void opentimers_timer_callback(void); //=========================== public ========================================== *************** *** 36,42 **** Initializes data structures and hardware timer. */ ! void opentimers_init(){ uint8_t i; // initialize local variables --- 37,43 ---- Initializes data structures and hardware timer. */ ! void opentimers_init(void){ uint8_t i; // initialize local variables *************** *** 51,57 **** } // set callback for bsp_timers module ! bsp_timer_set_callback(opentimers_timer_callback); } /** --- 52,71 ---- } // set callback for bsp_timers module ! // bsp_timer_set_callback(opentimers_timer_callback); ! hwtimer_arch_enable_interrupt(); ! hwtimer_arch_init(opentimers_int_handler, F_CPU); ! // hwtimer_init(); ! } ! ! /** ! \brief opentimers interrupt handler ! ! This is a wrapper to fit the hwtimer_arch API ! */ ! void opentimers_int_handler(int t) { ! (void)t; ! opentimers_timer_callback(); } /** *************** *** 64,70 **** - if not, insert it in the list \param duration Number milli-seconds after which the timer will fire. ! \param type The type of timer, indicating whether it's a one-shot or a period timer. \param callback The function to call when the timer fires. \returns The id of the timer (which serves as a handler to stop it) if the --- 78,89 ---- - if not, insert it in the list \param duration Number milli-seconds after which the timer will fire. ! \param type Type of timer: ! - #TIMER_PERIODIC for a periodic timer. ! - #TIMER_ONESHOT for a on-shot timer. ! \param timetype Units of the duration: ! - #TIME_MS when duration is in ms. ! - #TIME_TICS when duration is in clock ticks. \param callback The function to call when the timer fires. \returns The id of the timer (which serves as a handler to stop it) if the *************** *** 74,79 **** --- 93,99 ---- opentimer_id_t opentimers_start(uint32_t duration, timer_type_t type, time_type_t timetype, opentimers_cbt callback) { uint8_t id; + // puts("timer set"); // find an unused timer for (id=0; id sleepTime) + { + opentimers_vars.timersBuf[id].ticks_remaining -= sleepTime; + } + else + { + if(opentimers_vars.timersBuf[id].wraps_remaining > 0) + { + opentimers_vars.timersBuf[id].wraps_remaining--; + opentimers_vars.timersBuf[id].ticks_remaining += (MAX_TICKS_IN_SINGLE_CLOCK - sleepTime); + } + else + { + opentimers_vars.timersBuf[id].hasExpired = TRUE; + } + } + } + } + + // step 2. call callbacks of expired timers + for(id=0; id