aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src/can.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/src/can.c')
-rw-r--r--os/hal/src/can.c28
1 files changed, 20 insertions, 8 deletions
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;
}