From 48506ff3481afe8e2490e78a451852bc4bbb1c0b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 22 Feb 2013 13:42:10 +0000 Subject: CAN driver revision, work in progress. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5299 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/can.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'os/hal/src') diff --git a/os/hal/src/can.c b/os/hal/src/can.c index 18d7b302b..e0d47d5c5 100644 --- a/os/hal/src/can.c +++ b/os/hal/src/can.c @@ -145,6 +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] 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: @@ -158,21 +159,26 @@ void canStop(CANDriver *canp) { * * @api */ -msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { +msg_t canTransmit(CANDriver *canp, + canmbx_t mailbox, + const CANTxFrame *ctfp, + systime_t timeout) { - chDbgCheck((canp != NULL) && (ctfp != NULL), "canTransmit"); + chDbgCheck((canp != NULL) && (ctfp != NULL) && + (mailbox <= CAN_TX_MAILBOXES), + "canTransmit"); chSysLock(); chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP), "canTransmit(), #1", "invalid state"); - while ((canp->state == CAN_SLEEP) || !can_lld_can_transmit(canp)) { + while ((canp->state == CAN_SLEEP) || !can_lld_is_tx_empty(canp, mailbox)) { msg_t msg = chSemWaitTimeoutS(&canp->txsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; } } - can_lld_transmit(canp, ctfp); + can_lld_transmit(canp, mailbox, ctfp); chSysUnlock(); return RDY_OK; } @@ -183,6 +189,7 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { * @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[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: @@ -198,21 +205,26 @@ msg_t canTransmit(CANDriver *canp, const CANTxFrame *ctfp, systime_t timeout) { * * @api */ -msg_t canReceive(CANDriver *canp, CANRxFrame *crfp, systime_t timeout) { +msg_t canReceive(CANDriver *canp, + canmbx_t mailbox, + CANRxFrame *crfp, + systime_t timeout) { - chDbgCheck((canp != NULL) && (crfp != NULL), "canReceive"); + chDbgCheck((canp != NULL) && (crfp != NULL) && + (mailbox >= 1) && (mailbox < CAN_RX_MAILBOXES), + "canReceive"); chSysLock(); chDbgAssert((canp->state == CAN_READY) || (canp->state == CAN_SLEEP), "canReceive(), #1", "invalid state"); - while ((canp->state == CAN_SLEEP) || !can_lld_can_receive(canp)) { + while ((canp->state == CAN_SLEEP) || !can_lld_is_rx_nonempty(canp, mailbox)) { msg_t msg = chSemWaitTimeoutS(&canp->rxsem, timeout); if (msg != RDY_OK) { chSysUnlock(); return msg; } } - can_lld_receive(canp, crfp); + can_lld_receive(canp, mailbox, crfp); chSysUnlock(); return RDY_OK; } -- cgit v1.2.3