From bb806fe4c18e628b546291dab906928ebdb46627 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 2 Jan 2018 11:17:31 +0000 Subject: Added callbacks capability to the CAN driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11213 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/hal_can.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'os/hal/include') diff --git a/os/hal/include/hal_can.h b/os/hal/include/hal_can.h index 78bd12a20..16b487d46 100644 --- a/os/hal/include/hal_can.h +++ b/os/hal/include/hal_can.h @@ -60,7 +60,7 @@ /** * @brief Special mailbox identifier. */ -#define CAN_ANY_MAILBOX 0 +#define CAN_ANY_MAILBOX 0U /*===========================================================================*/ /* Driver pre-compile time settings. */ @@ -132,6 +132,73 @@ typedef enum { canReceiveTimeout(canp, mailbox, crfp, timeout) /** @} */ +/** + * @name Low level driver helper macros + * @{ + */ +#if !defined(CAN_ENFORCE_USE_CALLBACKS) +/** + * @brief TX mailbox empty event. + */ +#define _can_tx_empty_isr(canp, flags) { \ + osalSysLockFromISR(); \ + osalThreadDequeueAllI(&(canp)->txqueue, MSG_OK); \ + osalEventBroadcastFlagsI(&(canp)->txempty_event, flags); \ + osalSysUnlockFromISR(); \ +} + +/** + * @brief RX mailbox empty full event. + */ +#define _can_rx_full_isr(canp, flags) { \ + osalSysLockFromISR(); \ + osalThreadDequeueAllI(&(canp)->rxqueue, MSG_OK); \ + osalEventBroadcastFlagsI(&(canp)->rxfull_event, flags); \ + osalSysUnlockFromISR(); \ +} + +/** + * @brief Error event. + */ +#define _can_wakeup_isr(canp) { \ + osalSysLockFromISR(); \ + osalEventBroadcastFlagsI(&(canp)->wakeup_event, 0U); \ + osalSysUnlockFromISR(); \ +} + +/** + * @brief Error event. + */ +#define _can_error_isr(canp, flags) { \ + osalSysLockFromISR(); \ + osalEventBroadcastFlagsI(&(canp)->error_event, flags); \ + osalSysUnlockFromISR(); \ +} +#else /* defined(CAN_ENFORCE_USE_CALLBACKS) */ +#define _can_tx_empty_isr(canp, flags) { \ + (canp)->txempty_cb(canp, flags); \ + osalSysLockFromISR(); \ + osalThreadDequeueAllI(&(canp)->txqueue, MSG_OK); \ + osalSysUnlockFromISR(); \ +} + +#define _can_rx_full_isr(canp, flags) { \ + (canp)->rxfull_cb(canp, flags); \ + osalSysLockFromISR(); \ + osalThreadDequeueAllI(&(canp)->rxqueue, MSG_OK); \ + osalSysUnlockFromISR(); \ +} + +#define _can_wakeup_isr(canp) { \ + (canp)->wakeup_cb(canp, 0U); \ +} + +#define _can_error_isr(canp, flags) { \ + (canp)->error_cb(canp, flags); \ +} +#endif /* defined(CAN_ENFORCE_USE_CALLBACKS) */ +/** @} */ + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ -- cgit v1.2.3