void gfxSemSignal(gfxSem *psem) { chSysLock(); if (gfxSemCounterI(psem) < psem->limit) chSemSignalI(&psem->sem); chSchRescheduleS(); chSysUnlock(); }
/** * @brief Performs a signal operation on a semaphore. * @post This function does not reschedule so a call to a rescheduling * function must be performed before unlocking the kernel. Note that * interrupt handlers always reschedule on exit so an explicit * reschedule must not be performed in ISRs. * * @param[in] sp pointer to a @p semaphore_t structure * * @api */ void chSemSignal(semaphore_t *sp) { chSysLock(); chSemSignalI(sp); chSchRescheduleS(); chSysUnlock(); }
THD_FUNCTION(test_support, arg) { #if CH_CFG_USE_EVENTS == TRUE thread_t *tp = (thread_t *)arg; #else (void)arg; #endif /* Initializing global resources.*/ chSemObjectInit(&gsem1, 0); chSemObjectInit(&gsem2, 0); while (true) { chSysLock(); if (chSemGetCounterI(&gsem1) < 0) chSemSignalI(&gsem1); chSemResetI(&gsem2, 0); chThdResumeI(>r1, MSG_OK); #if CH_CFG_USE_EVENTS == TRUE chEvtSignalI(tp, 0x55); #endif chSchRescheduleS(); chSysUnlock(); chThdSleepMilliseconds(250); } }
/** * @brief Release a semaphore. */ osStatus osSemaphoreRelease(osSemaphoreId semaphore_id) { syssts_t sts = chSysGetStatusAndLockX(); chSemSignalI((semaphore_t *)semaphore_id); chSysRestoreStatusX(sts); return osOK; }
/* * This callback is invoked when a transmission buffer has been completely * read by the driver. */ static void txend1(UARTDriver *uartp) { (void)uartp; chSysLockFromIsr(); chSemSignalI(&uart_sem); chSysUnlockFromIsr(); }
static THD_FUNCTION(thread2, p) { (void)p; chThdSleepMilliseconds(50); chSysLock(); chSemSignalI(&sem1); /* For coverage reasons */ chSchRescheduleS(); chSysUnlock(); }
datatype * DataListener< datatype >::peekI(uint32_t timeout_ms){ datatype * dst; if(RDY_OK == chSemWaitTimeoutS(&sem, timeout_ms)){ chSemSignalI(&sem); dst = rd_head; return dst; } return nullptr; }
/* (*i2scallback_t) */ static void mp45dt02Cb(I2SDriver *i2sp, size_t offset, size_t number) { (void)i2sp; chSysLockFromISR(); mp45dt02I2sData.offset = offset; mp45dt02I2sData.number = number; chSemSignalI(&mp45dt02ProcessingSem); chSysUnlockFromISR(); }
static msg_t thread2(void *p) { (void)p; chThdSleepMilliseconds(50); chSysLock(); chSemSignalI(&sem1); /* For coverage reasons */ chSchRescheduleS(); chSysUnlock(); return 0; }
/** * @brief Input queue write. * @details A byte value is written into the low end of an input queue. * * @param[in] iqp pointer to an @p InputQueue structure * @param[in] b the byte value to be written in the queue * @return The operation status. * @retval Q_OK if the operation has been completed with success. * @retval Q_FULL if the queue is full and the operation cannot be * completed. * * @iclass */ msg_t chIQPutI(InputQueue *iqp, uint8_t b) { if (chIQIsFullI(iqp)) return Q_FULL; *iqp->q_wrptr++ = b; if (iqp->q_wrptr >= iqp->q_top) iqp->q_wrptr = iqp->q_buffer; chSemSignalI(&iqp->q_sem); return Q_OK; }
/** * @brief Common TX ISR handler. * * @param[in] canp pointer to the @p CANDriver object * * @notapi */ static void can_lld_tx_handler(CANDriver *canp) { /* All transmit buffers are available.*/ if (canp->can->GSR & CANGSR_TBS) { chSysLockFromIsr(); while (chSemGetCounterI(&canp->txsem) < 0) chSemSignalI(&canp->txsem); chEvtBroadcastFlagsI(&canp->txempty_event, CAN_MAILBOX_TO_MASK(1)); chSysUnlockFromIsr(); } }
/** * @brief Retrieves a message from a mailbox. * @details This variant is non-blocking, the function returns a timeout * condition if the queue is full. * * @param[in] mbp the pointer to an initialized Mailbox object * @param[out] msgp pointer to a message variable for the received message * @return The operation status. * @retval RDY_OK if a message has been correctly fetched. * @retval RDY_TIMEOUT if the mailbox is empty and a message cannot be * fetched. * * @iclass */ msg_t chMBFetchI(Mailbox *mbp, msg_t *msgp) { chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchI"); if (chSemGetCounterI(&mbp->mb_fullsem) <= 0) return RDY_TIMEOUT; *msgp = *mbp->mb_rdptr++; if (mbp->mb_rdptr >= mbp->mb_top) mbp->mb_rdptr = mbp->mb_buffer; chSemSignalI(&mbp->mb_emptysem); return RDY_OK; }
/** * @brief Releases exclusive access to the ILI9341 module. * @pre In order to use this function the option * @p ILI9341_USE_MUTUAL_EXCLUSION must be enabled. * @pre ILI9341 is ready. * * @param[in] driverp pointer to the @p ILI9341Driver object * * @sclass */ void ili9341ReleaseBusS(ILI9341Driver *driverp) { osalDbgCheckClassS(); osalDbgCheck(driverp == &ILI9341D1); osalDbgAssert(driverp->state == ILI9341_READY, "not ready"); #if (TRUE == CH_CFG_USE_MUTEXES) chMtxUnlockS(&driverp->lock); #else chSemSignalI(&driverp->lock); #endif }
/** * @brief Output queue read. * @details A byte value is read from the low end of an output queue. * * @param[in] oqp pointer to an @p OutputQueue structure * @return The byte value from the queue. * @retval Q_EMPTY if the queue is empty. * * @iclass */ msg_t chOQGetI(OutputQueue *oqp) { uint8_t b; if (chOQIsEmptyI(oqp)) return Q_EMPTY; b = *oqp->q_rdptr++; if (oqp->q_rdptr >= oqp->q_top) oqp->q_rdptr = oqp->q_buffer; chSemSignalI(&oqp->q_sem); return b; }
bool DataListener< datatype >::pushI(datatype & src){ if(chSemGetCounterI(&sem) + 1 < len + 1){ chSemSignalI(&sem); *wr_head = src; if(wr_head == buf_head + len - 1){ wr_head = buf_head; } else { wr_head += 1; } return true; } return false; }
/** * @brief Posts a message into a mailbox. * @details This variant is non-blocking, the function returns a timeout * condition if the queue is full. * * @param[in] mbp the pointer to an initialized Mailbox object * @param[in] msg the message to be posted on the mailbox * @return The operation status. * @retval RDY_OK if a message has been correctly posted. * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be * posted. * * @iclass */ msg_t chMBPostI(Mailbox *mbp, msg_t msg) { chDbgCheck(mbp != NULL, "chMBPostI"); if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) return RDY_TIMEOUT; chSemFastWaitI(&mbp->mb_emptysem); *mbp->mb_wrptr++ = msg; if (mbp->mb_wrptr >= mbp->mb_top) mbp->mb_wrptr = mbp->mb_buffer; chSemSignalI(&mbp->mb_fullsem); return RDY_OK; }
/** * @brief Posts an high priority message into a mailbox. * @details This variant is non-blocking, the function returns a timeout * condition if the queue is full. * * @param[in] mbp the pointer to an initialized Mailbox object * @param[in] msg the message to be posted on the mailbox * @return The operation status. * @retval RDY_OK if a message has been correctly posted. * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be * posted. * * @iclass */ msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) { chDbgCheck(mbp != NULL, "chMBPostAheadI"); if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) return RDY_TIMEOUT; chSemFastWaitI(&mbp->mb_emptysem); if (--mbp->mb_rdptr < mbp->mb_buffer) mbp->mb_rdptr = mbp->mb_top - 1; *mbp->mb_rdptr = msg; chSemSignalI(&mbp->mb_fullsem); return RDY_OK; }
/** * @brief Retrieves a message from a mailbox. * @details This variant is non-blocking, the function returns a timeout * condition if the queue is empty. * * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[out] msgp pointer to a message variable for the received message * @return The operation status. * @retval MSG_OK if a message has been correctly fetched. * @retval MSG_TIMEOUT if the mailbox is empty and a message cannot be * fetched. * * @iclass */ msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { chDbgCheckClassI(); chDbgCheck((mbp != NULL) && (msgp != NULL)); if (chSemGetCounterI(&mbp->mb_fullsem) <= 0) return MSG_TIMEOUT; chSemFastWaitI(&mbp->mb_fullsem); *msgp = *mbp->mb_rdptr++; if (mbp->mb_rdptr >= mbp->mb_top) mbp->mb_rdptr = mbp->mb_buffer; chSemSignalI(&mbp->mb_emptysem); return MSG_OK; }
/** * @brief Posts an high priority message into a mailbox. * @details This variant is non-blocking, the function returns a timeout * condition if the queue is full. * * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @return The operation status. * @retval MSG_OK if a message has been correctly posted. * @retval MSG_TIMEOUT if the mailbox is full and the message cannot be * posted. * * @iclass */ msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL); if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) return MSG_TIMEOUT; chSemFastWaitI(&mbp->mb_emptysem); if (--mbp->mb_rdptr < mbp->mb_buffer) mbp->mb_rdptr = mbp->mb_top - 1; *mbp->mb_rdptr = msg; chSemSignalI(&mbp->mb_fullsem); return MSG_OK; }
/** * @brief Posts a message into a mailbox. * @details This variant is non-blocking, the function returns a timeout * condition if the queue is full. * * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @return The operation status. * @retval MSG_OK if a message has been correctly posted. * @retval MSG_TIMEOUT if the mailbox is full and the message cannot be * posted. * * @iclass */ msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL); if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) return MSG_TIMEOUT; chSemFastWaitI(&mbp->mb_emptysem); *mbp->mb_wrptr++ = msg; if (mbp->mb_wrptr >= mbp->mb_top) mbp->mb_wrptr = mbp->mb_buffer; chSemSignalI(&mbp->mb_fullsem); return MSG_OK; }
/** * @brief Retrieves a message from a mailbox. * @details The invoking thread waits until a message is posted in the mailbox * or the specified time runs out. * * @param[in] mbp the pointer to an initialized Mailbox object * @param[out] msgp pointer to a message variable for the received message * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_INFINITE no timeout. * . * @return The operation status. * @retval RDY_OK if a message has been correctly fetched. * @retval RDY_RESET if the mailbox has been reset while waiting. * @retval RDY_TIMEOUT if the operation has timed out. * * @sclass */ msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) { msg_t rdymsg; chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchS"); rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, time); if (rdymsg == RDY_OK) { *msgp = *mbp->mb_rdptr++; if (mbp->mb_rdptr >= mbp->mb_top) mbp->mb_rdptr = mbp->mb_buffer; chSemSignalI(&mbp->mb_emptysem); chSchRescheduleS(); } return rdymsg; }
/** * @brief Posts an high priority message into a mailbox. * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * * @param[in] mbp the pointer to an initialized Mailbox object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_INFINITE no timeout. * . * @return The operation status. * @retval RDY_OK if a message has been correctly posted. * @retval RDY_RESET if the mailbox has been reset while waiting. * @retval RDY_TIMEOUT if the operation has timed out. * * @sclass */ msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheck(mbp != NULL, "chMBPostAheadS"); rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); if (rdymsg == RDY_OK) { if (--mbp->mb_rdptr < mbp->mb_buffer) mbp->mb_rdptr = mbp->mb_top - 1; *mbp->mb_rdptr = msg; chSemSignalI(&mbp->mb_fullsem); chSchRescheduleS(); } return rdymsg; }
/** * @brief Posts a message into a mailbox. * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * * @param[in] mbp the pointer to an initialized Mailbox object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_INFINITE no timeout. * . * @return The operation status. * @retval RDY_OK if a message has been correctly posted. * @retval RDY_RESET if the mailbox has been reset while waiting. * @retval RDY_TIMEOUT if the operation has timed out. * * @sclass */ msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheck(mbp != NULL, "chMBPostS"); rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); if (rdymsg == RDY_OK) { *mbp->mb_wrptr++ = msg; if (mbp->mb_wrptr >= mbp->mb_top) mbp->mb_wrptr = mbp->mb_buffer; chSemSignalI(&mbp->mb_fullsem); chSchRescheduleS(); } return rdymsg; }
/** * @brief Common RX ISR handler. * * @param[in] canp pointer to the @p CANDriver object * @param[in] status * @notapi */ static void can_lld_rx_handler(CANDriver *canp, uint32_t status) { /* No more receive events until the queue 0 has been emptied.*/ canp->can->IER &= ~CANIER_RIE; chSysLockFromIsr(); while (chSemGetCounterI(&canp->rxsem) < 0) chSemSignalI(&canp->rxsem); chEvtBroadcastFlagsI(&canp->rxfull_event, CAN_MAILBOX_TO_MASK(1)); chSysUnlockFromIsr(); if (( status & CANICR_DOI) > 0) { /* Overflow events handling.*/ canp->can->CMR = CANCMR_CDO; chSysLockFromIsr(); chEvtBroadcastFlagsI(&canp->error_event, CAN_OVERFLOW_ERROR); chSysUnlockFromIsr(); } }
/** * @brief Releases an object into a guarded memory pool. * @pre The guarded memory pool must be already been initialized. * @pre The freed object must be of the right size for the specified * guarded memory pool. * @pre The added object must be properly aligned. * * @param[in] gmp pointer to a @p guarded_memory_pool_t structure * @param[in] objp the pointer to the object to be released * * @iclass */ void chGuardedPoolFreeI(guarded_memory_pool_t *gmp, void *objp) { chPoolFreeI(&gmp->pool, objp); chSemSignalI(&gmp->sem); }
void gfxSemSignalI(gfxSem *psem) { if (gfxSemCounterI(psem) < psem->limit) chSemSignalI(&psem->sem); }
void CounterSemaphore::signalI(void) { chSemSignalI(&sem); }
/* CHIBIOS FIX: specific variant of this call to be called from within a lock.*/ void sys_sem_signal_S(sys_sem_t *sem) { chSemSignalI(*sem); chSchRescheduleS(); }
inline void Semaphore_::signal_unsafe() { chSemSignalI(&impl); }