diff --git a/os/hal/include/can.h b/os/hal/include/can.h index aa205b0ba..c803a92e2 100644 --- a/os/hal/include/can.h +++ b/os/hal/include/can.h @@ -137,7 +137,6 @@ extern "C" { void canStop(CANDriver *canp); msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout); msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout); - canstatus_t canGetAndClearFlags(CANDriver *canp); #if CAN_USE_SLEEP_MODE void canSleep(CANDriver *canp); void canWakeup(CANDriver *canp); diff --git a/os/hal/platforms/STM32/can_lld.c b/os/hal/platforms/STM32/can_lld.c index dd0cacd11..32d273c6f 100644 --- a/os/hal/platforms/STM32/can_lld.c +++ b/os/hal/platforms/STM32/can_lld.c @@ -95,9 +95,8 @@ CH_IRQ_HANDLER(STM32_CAN1_RX0_HANDLER) { if ((rf0r & CAN_RF0R_FOVR0) > 0) { /* Overflow events handling.*/ CAN1->RF0R = CAN_RF0R_FOVR0; - canAddFlagsI(&CAND1, CAN_OVERFLOW_ERROR); chSysLockFromIsr(); - chEvtBroadcastI(&CAND1.error_event); + chEvtBroadcastFlagsI(&CAND1.error_event, CAN_OVERFLOW_ERROR); chSysUnlockFromIsr(); } @@ -138,16 +137,18 @@ CH_IRQ_HANDLER(STM32_CAN1_SCE_HANDLER) { } /* Error event.*/ if (msr & CAN_MSR_ERRI) { - canstatus_t flags; + flagsmask_t flags; uint32_t esr = CAN1->ESR; CAN1->ESR &= ~CAN_ESR_LEC; - flags = (canstatus_t)(esr & 7); + flags = (flagsmask_t)(esr & 7); if ((esr & CAN_ESR_LEC) > 0) flags |= CAN_FRAMING_ERROR; + chSysLockFromIsr(); - canAddFlagsI(&CAND1, flags | (canstatus_t)(flags < 16)); - chEvtBroadcastI(&CAND1.error_event); + /* The content of the ESR register is copied unchanged in the upper + half word of the listener flags mask.*/ + chEvtBroadcastFlagsI(&CAND1.error_event, flags | (flagsmask_t)(esr < 16)); chSysUnlockFromIsr(); } diff --git a/os/hal/platforms/STM32/can_lld.h b/os/hal/platforms/STM32/can_lld.h index 6cb882df2..003a6743f 100644 --- a/os/hal/platforms/STM32/can_lld.h +++ b/os/hal/platforms/STM32/can_lld.h @@ -111,11 +111,6 @@ /* Driver data structures and types. */ /*===========================================================================*/ -/** - * @brief CAN status flags. - */ -typedef uint32_t canstatus_t; - /** * @brief CAN transmission frame. * @note Accessing the frame data as word16 or word32 is not portable because @@ -273,10 +268,6 @@ typedef struct { * @brief A CAN bus error happened. */ EventSource error_event; - /** - * @brief Error flags set when an error event is broadcasted. - */ - canstatus_t status; #if CAN_USE_SLEEP_MODE || defined (__DOXYGEN__) /** * @brief Entering sleep state event. diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 041409c99..422825a83 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -79,7 +79,6 @@ void canObjectInit(CANDriver *canp) { chEvtInit(&canp->rxfull_event); chEvtInit(&canp->txempty_event); chEvtInit(&canp->error_event); - canp->status = 0; #if CAN_USE_SLEEP_MODE chEvtInit(&canp->sleep_event); chEvtInit(&canp->wakeup_event); @@ -136,7 +135,6 @@ void canStop(CANDriver *canp) { chSemResetI(&canp->txsem, 0); chSchRescheduleS(); canp->state = CAN_STOP; - canp->status = 0; chSysUnlock(); } @@ -219,24 +217,6 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { return RDY_OK; } -/** - * @brief Returns the current status mask and clears it. - * - * @param[in] canp pointer to the @p CANDriver object - * @return The status flags mask. - * - * @api - */ -canstatus_t canGetAndClearFlags(CANDriver *canp) { - canstatus_t status; - - chSysLock(); - status = canp->status; - canp->status = 0; - chSysUnlock(); - return status; -} - #if CAN_USE_SLEEP_MODE || defined(__DOXYGEN__) /** * @brief Enters the sleep mode. diff --git a/readme.txt b/readme.txt index dbebc04b6..a1cf53ffc 100644 --- a/readme.txt +++ b/readme.txt @@ -85,6 +85,8 @@ *** 2.5.1 *** - FIX: Fixed Data available event not generated in serial_usb driver (bug 3567992). +- NEW: Modified the CAN drivers to use the new event flags mechanism, the + previous flags handling has been removed. - NEW: Modified serial and serial_usb drivers to use the new event flags mechanism, the previous flags handling in BaseAsynchronousChannel has been removed.