static void tmrcb(void *p) { event_timer_t *etp = p; chSysLockFromISR(); chEvtBroadcastI(&etp->et_es); chVTDoSetI(&etp->et_vt, etp->et_interval, tmrcb, etp); chSysUnlockFromISR(); }
/* * This callback is invoked when a transmission has physically completed. */ static void txend2(UARTDriver *uartp) { (void)uartp; palClearPad(GPIOB, GPIOB_LED4); chSysLockFromISR(); chVTResetI(&vt1); chVTDoSetI(&vt1, MS2ST(5000), restart, NULL); chSysUnlockFromISR(); }
/** * @brief Virtual timers common callback. */ static void timer_cb(void const *arg) { osTimerId timer_id = (osTimerId)arg; timer_id->ptimer(timer_id->argument); if (timer_id->type == osTimerPeriodic) { chSysLockFromISR(); chVTDoSetI(&timer_id->vt, timer_id->millisec, (vtfunc_t)timer_cb, timer_id); chSysUnlockFromISR(); } }
/* * This callback is invoked when a character is received but the application * was not ready to receive it, the character is passed as parameter. */ static void rxchar(UARTDriver *uartp, uint16_t c) { (void)uartp; (void)c; /* Flashing the LED each time a character is received.*/ palSetPad(GPIOB, GPIOB_LED4); chSysLockFromISR(); chVTResetI(&vt2); chVTDoSetI(&vt2, MS2ST(200), ledoff, NULL); chSysUnlockFromISR(); }
/* Triggered when the button is pressed or released. The LED4 is set to ON.*/ static void extcb1(EXTDriver *extp, expchannel_t channel) { static virtual_timer_t vt4; (void)extp; (void)channel; palSetPad(GPIOB, GPIOB_LED4); chSysLockFromISR(); chVTResetI(&vt4); /* LED4 set to OFF after 200mS.*/ chVTDoSetI(&vt4, MS2ST(200), led4off, NULL); chSysUnlockFromISR(); }
/** * @brief Puts the current thread to sleep into the specified state with * timeout specification. * @details The thread goes into a sleeping state, if it is not awakened * explicitly within the specified timeout then it is forcibly * awakened with a @p MSG_TIMEOUT low level message. The possible * @ref thread_states are defined into @p threads.h. * * @param[in] newstate the new thread state * @param[in] time the number of ticks before the operation timeouts, the * special values are handled as follow: * - @a TIME_INFINITE the thread enters an infinite sleep * state, this is equivalent to invoking * @p chSchGoSleepS() but, of course, less efficient. * - @a TIME_IMMEDIATE this value is not allowed. * . * @return The wakeup message. * @retval MSG_TIMEOUT if a timeout occurs. * * @sclass */ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { chDbgCheckClassS(); if (TIME_INFINITE != time) { virtual_timer_t vt; chVTDoSetI(&vt, time, wakeup, currp); chSchGoSleepS(newstate); if (chVTIsArmedI(&vt)) chVTDoResetI(&vt); } else { chSchGoSleepS(newstate); } return currp->p_u.rdymsg; }