From 04385d42d46173127ac7c5274cbd15d5d255c460 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 22 Feb 2013 14:45:58 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5300 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/can_lld.c | 26 +++++++++++++++++++++----- os/hal/platforms/STM32/can_lld.h | 2 +- testhal/STM32F4xx/CAN/main.c | 6 +++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/os/hal/platforms/STM32/can_lld.c b/os/hal/platforms/STM32/can_lld.c index 785ca3482..7a6185c1f 100644 --- a/os/hal/platforms/STM32/can_lld.c +++ b/os/hal/platforms/STM32/can_lld.c @@ -510,12 +510,16 @@ void can_lld_transmit(CANDriver *canp, switch (mailbox) { case CAN_ANY_TX_MAILBOX: tmbp = &canp->can->sTxMailBox[(canp->can->TSR & CAN_TSR_CODE) >> 24]; + break; case 1: tmbp = &canp->can->sTxMailBox[0]; + break; case 2: tmbp = &canp->can->sTxMailBox[1]; + break; case 3: tmbp = &canp->can->sTxMailBox[2]; + break; default: return; } @@ -546,8 +550,14 @@ void can_lld_transmit(CANDriver *canp, */ bool_t can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) { - return mailbox == 0 ? (canp->can->RF0R & CAN_RF0R_FMP0) > 0 : - (canp->can->RF1R & CAN_RF1R_FMP1) > 0; + switch (mailbox) { + case 1: + return (canp->can->RF0R & CAN_RF0R_FMP0) > 0; + case 2: + return (canp->can->RF1R & CAN_RF1R_FMP1) > 0; + default: + return FALSE; + } } /** @@ -564,7 +574,8 @@ void can_lld_receive(CANDriver *canp, CANRxFrame *crfp) { uint32_t rir, rdtr; - if (mailbox == 0) { + switch (mailbox) { + case 1: /* Fetches the message.*/ rir = canp->can->sFIFOMailBox[0].RIR; rdtr = canp->can->sFIFOMailBox[0].RDTR; @@ -578,8 +589,8 @@ void can_lld_receive(CANDriver *canp, events again.*/ if ((canp->can->RF0R & CAN_RF0R_FMP0) == 0) canp->can->IER |= CAN_IER_FMPIE0; - } - else { + break; + case 2: /* Fetches the message.*/ rir = canp->can->sFIFOMailBox[1].RIR; rdtr = canp->can->sFIFOMailBox[1].RDTR; @@ -593,7 +604,12 @@ void can_lld_receive(CANDriver *canp, events again.*/ if ((canp->can->RF1R & CAN_RF1R_FMP1) == 0) canp->can->IER |= CAN_IER_FMPIE1; + break; + default: + return; } + + /* Decodes the various fields in the RX frame.*/ crfp->RTR = (rir & CAN_RI0R_RTR) >> 1; crfp->IDE = (rir & CAN_RI0R_IDE) >> 2; if (crfp->IDE) diff --git a/os/hal/platforms/STM32/can_lld.h b/os/hal/platforms/STM32/can_lld.h index a15226f4a..11ef5dcc9 100644 --- a/os/hal/platforms/STM32/can_lld.h +++ b/os/hal/platforms/STM32/can_lld.h @@ -58,7 +58,7 @@ /** * @brief This implementation supports two receive mailboxes. */ -#define CAN_RX_MAILBOXES 3 +#define CAN_RX_MAILBOXES 2 /** * @name CAN registers helper macros diff --git a/testhal/STM32F4xx/CAN/main.c b/testhal/STM32F4xx/CAN/main.c index e7a10247b..e095da4d5 100644 --- a/testhal/STM32F4xx/CAN/main.c +++ b/testhal/STM32F4xx/CAN/main.c @@ -56,7 +56,7 @@ static msg_t can_rx(void *p) { while(!chThdShouldTerminate()) { if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(100)) == 0) continue; - while (canReceive(cip->canp, &rxmsg, TIME_IMMEDIATE) == RDY_OK) { + while (canReceive(cip->canp, 1, &rxmsg, TIME_IMMEDIATE) == RDY_OK) { /* Process message.*/ palTogglePad(GPIOD, cip->led); } @@ -82,8 +82,8 @@ static msg_t can_tx(void * p) { txmsg.data32[1] = 0x00FF00FF; while (!chThdShouldTerminate()) { - canTransmit(&CAND1, &txmsg, MS2ST(100)); - canTransmit(&CAND2, &txmsg, MS2ST(100)); + canTransmit(&CAND1, CAN_ANY_TX_MAILBOX, &txmsg, MS2ST(100)); + canTransmit(&CAND2, CAN_ANY_TX_MAILBOX, &txmsg, MS2ST(100)); chThdSleepMilliseconds(500); } return 0;