diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-02-23 09:04:38 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-02-23 09:04:38 +0000 |
commit | 4256a9113fd16e1b8d7cef963f83931b7d9182ad (patch) | |
tree | 5d4e1692bfef3431bcb95255afc8c22915234969 /os | |
parent | 61524c2014380d425983c269f641c6f7404fb8d9 (diff) | |
download | ChibiOS-4256a9113fd16e1b8d7cef963f83931b7d9182ad.tar.gz ChibiOS-4256a9113fd16e1b8d7cef963f83931b7d9182ad.tar.bz2 ChibiOS-4256a9113fd16e1b8d7cef963f83931b7d9182ad.zip |
CAN driver enhancements completed.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5303 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/include/can.h | 4 | ||||
-rw-r--r-- | os/hal/platforms/STM32/can_lld.c | 50 | ||||
-rw-r--r-- | os/hal/src/can.c | 10 |
3 files changed, 45 insertions, 19 deletions
diff --git a/os/hal/include/can.h b/os/hal/include/can.h index 1d8492d28..a62aba3da 100644 --- a/os/hal/include/can.h +++ b/os/hal/include/can.h @@ -62,9 +62,9 @@ /** @} */
/**
- * @brief Special TX mailbox identifier.
+ * @brief Special mailbox identifier.
*/
-#define CAN_ANY_TX_MAILBOX 0
+#define CAN_ANY_MAILBOX 0
/*===========================================================================*/
/* Driver pre-compile time settings. */
diff --git a/os/hal/platforms/STM32/can_lld.c b/os/hal/platforms/STM32/can_lld.c index 89d1b25ac..456e3e53a 100644 --- a/os/hal/platforms/STM32/can_lld.c +++ b/os/hal/platforms/STM32/can_lld.c @@ -172,16 +172,31 @@ static void can_lld_rx0_handler(CANDriver *canp) { /**
* @brief Common RX1 ISR handler.
- * @note Not used, must not be invoked, defaulted to an halt.
*
* @param[in] canp pointer to the @p CANDriver object
*
* @notapi
*/
static void can_lld_rx1_handler(CANDriver *canp) {
+ uint32_t rf1r;
- (void)canp;
- chSysHalt();
+ rf1r = canp->can->RF1R;
+ if ((rf1r & CAN_RF1R_FMP1) > 0) {
+ /* No more receive events until the queue 0 has been emptied.*/
+ canp->can->IER &= ~CAN_IER_FMPIE1;
+ chSysLockFromIsr();
+ while (chSemGetCounterI(&canp->rxsem) < 0)
+ chSemSignalI(&canp->rxsem);
+ chEvtBroadcastFlagsI(&canp->rxfull_event, CAN_MAILBOX_TO_MASK(1));
+ chSysUnlockFromIsr();
+ }
+ if ((rf1r & CAN_RF1R_FOVR1) > 0) {
+ /* Overflow events handling.*/
+ canp->can->RF1R = CAN_RF1R_FOVR1;
+ chSysLockFromIsr();
+ chEvtBroadcastFlagsI(&canp->error_event, CAN_OVERFLOW_ERROR);
+ chSysUnlockFromIsr();
+ }
}
/**
@@ -467,7 +482,7 @@ void can_lld_stop(CANDriver *canp) { * @brief Determines whether a frame can be transmitted.
*
* @param[in] canp pointer to the @p CANDriver object
- * @param[in] mailbox mailbox number, @p CAN_ANY_TX_MAILBOX for any mailbox
+ * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
*
* @return The queue space availability.
* @retval FALSE no space in the transmit queue.
@@ -478,7 +493,7 @@ void can_lld_stop(CANDriver *canp) { bool_t can_lld_is_tx_empty(CANDriver *canp, canmbx_t mailbox) {
switch (mailbox) {
- case CAN_ANY_TX_MAILBOX:
+ case CAN_ANY_MAILBOX:
return (canp->can->TSR & CAN_TSR_TME) != 0;
case 1:
return (canp->can->TSR & CAN_TSR_TME0) != 0;
@@ -496,7 +511,7 @@ bool_t can_lld_is_tx_empty(CANDriver *canp, canmbx_t mailbox) { *
* @param[in] canp pointer to the @p CANDriver object
* @param[in] ctfp pointer to the CAN frame to be transmitted
- * @param[in] mailbox mailbox number, @p CAN_ANY_TX_MAILBOX for any mailbox
+ * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
*
* @notapi
*/
@@ -508,7 +523,7 @@ void can_lld_transmit(CANDriver *canp, /* Pointer to a free transmission mailbox.*/
switch (mailbox) {
- case CAN_ANY_TX_MAILBOX:
+ case CAN_ANY_MAILBOX:
tmbp = &canp->can->sTxMailBox[(canp->can->TSR & CAN_TSR_CODE) >> 24];
break;
case 1:
@@ -540,7 +555,7 @@ void can_lld_transmit(CANDriver *canp, * @brief Determines whether a frame has been received.
*
* @param[in] canp pointer to the @p CANDriver object
- * @param[in] mailbox mailbox number
+ * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
*
* @return The queue space availability.
* @retval FALSE no space in the transmit queue.
@@ -551,10 +566,12 @@ void can_lld_transmit(CANDriver *canp, bool_t can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) {
switch (mailbox) {
+ case CAN_ANY_MAILBOX:
+ return (canp->can->RF0R & (CAN_RF0R_FMP0 | CAN_RF1R_FMP1)) != 0;
case 1:
- return (canp->can->RF0R & CAN_RF0R_FMP0) > 0;
+ return (canp->can->RF0R & CAN_RF0R_FMP0) != 0;
case 2:
- return (canp->can->RF1R & CAN_RF1R_FMP1) > 0;
+ return (canp->can->RF1R & CAN_RF1R_FMP1) != 0;
default:
return FALSE;
}
@@ -564,8 +581,8 @@ bool_t can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) { * @brief Receives a frame from the input queue.
*
* @param[in] canp pointer to the @p CANDriver object
+ * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
* @param[out] crfp pointer to the buffer where the CAN frame is copied
- * @param[in] mailbox mailbox number
*
* @notapi
*/
@@ -574,6 +591,16 @@ void can_lld_receive(CANDriver *canp, CANRxFrame *crfp) {
uint32_t rir, rdtr;
+ if (mailbox == CAN_ANY_MAILBOX) {
+ if ((canp->can->RF0R & CAN_RF0R_FMP0) != 0)
+ mailbox = 1;
+ else if ((canp->can->RF1R & CAN_RF1R_FMP1) != 0)
+ mailbox = 2;
+ else {
+ /* Should not happen, do nothing.*/
+ return;
+ }
+ }
switch (mailbox) {
case 1:
/* Fetches the message.*/
@@ -606,6 +633,7 @@ void can_lld_receive(CANDriver *canp, canp->can->IER |= CAN_IER_FMPIE1;
break;
default:
+ /* Should not happen, do nothing.*/
return;
}
diff --git a/os/hal/src/can.c b/os/hal/src/can.c index e0d47d5c5..64aaa45c8 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -145,7 +145,7 @@ void canStop(CANDriver *canp) { * @note Trying to transmit while in sleep mode simply enqueues the thread.
*
* @param[in] canp pointer to the @p CANDriver object
- * @param[in] mailbox mailbox number, @p CAN_ANY_TX_MAILBOX for any mailbox
+ * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
* @param[in] ctfp pointer to the CAN frame to be transmitted
* @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
@@ -164,8 +164,7 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp,
systime_t timeout) {
- chDbgCheck((canp != NULL) && (ctfp != NULL) &&
- (mailbox <= CAN_TX_MAILBOXES),
+ chDbgCheck((canp != NULL) && (ctfp != NULL) && (mailbox <= CAN_TX_MAILBOXES),
"canTransmit");
chSysLock();
@@ -189,7 +188,7 @@ msg_t canTransmit(CANDriver *canp, * @note Trying to receive while in sleep mode simply enqueues the thread.
*
* @param[in] canp pointer to the @p CANDriver object
- * @param[in] mailbox mailbox number
+ * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
* @param[out] crfp pointer to the buffer where the CAN frame is copied
* @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
@@ -210,8 +209,7 @@ msg_t canReceive(CANDriver *canp, CANRxFrame *crfp,
systime_t timeout) {
- chDbgCheck((canp != NULL) && (crfp != NULL) &&
- (mailbox >= 1) && (mailbox < CAN_RX_MAILBOXES),
+ chDbgCheck((canp != NULL) && (crfp != NULL) && (mailbox < CAN_RX_MAILBOXES),
"canReceive");
chSysLock();
|