aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/STM32/LLD/CANv1/hal_can_lld.h
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/STM32/LLD/CANv1/hal_can_lld.h')
-rw-r--r--os/hal/ports/STM32/LLD/CANv1/hal_can_lld.h51
1 files changed, 48 insertions, 3 deletions
diff --git a/os/hal/ports/STM32/LLD/CANv1/hal_can_lld.h b/os/hal/ports/STM32/LLD/CANv1/hal_can_lld.h
index c6c10dc12..a26377f24 100644
--- a/os/hal/ports/STM32/LLD/CANv1/hal_can_lld.h
+++ b/os/hal/ports/STM32/LLD/CANv1/hal_can_lld.h
@@ -189,10 +189,26 @@
/*===========================================================================*/
/**
+ * @brief Type of a structure representing an CAN driver.
+ */
+typedef struct CANDriver CANDriver;
+
+/**
* @brief Type of a transmission mailbox index.
*/
typedef uint32_t canmbx_t;
+#if defined(CAN_ENFORCE_USE_CALLBACKS) || defined(__DOXYGEN__)
+/**
+ * @brief Type of a CAN notification callback.
+ *
+ * @param[in] canp pointer to the @p CANDriver object triggering the
+ * callback
+ * @param[in] flags flags associated to the mailbox callback
+ */
+typedef void (*can_callback_t)(CANDriver *canp, uint32_t flags);
+#endif
+
/**
* @brief CAN transmission frame.
* @note Accessing the frame data as word16 or word32 is not portable because
@@ -309,7 +325,7 @@ typedef struct {
/**
* @brief Structure representing an CAN driver.
*/
-typedef struct {
+struct CANDriver {
/**
* @brief Driver state.
*/
@@ -326,6 +342,7 @@ typedef struct {
* @brief Receive threads queue.
*/
threads_queue_t rxqueue;
+#if !defined(CAN_ENFORCE_USE_CALLBACKS)
/**
* @brief One or more frames become available.
* @note After broadcasting this event it will not be broadcasted again
@@ -345,7 +362,6 @@ typedef struct {
* transmit mailboxes become empty.
* @note The upper 16 bits are transmission error flags associated
* to the transmit mailboxes.
- *
*/
event_source_t txempty_event;
/**
@@ -366,12 +382,41 @@ typedef struct {
*/
event_source_t wakeup_event;
#endif /* CAN_USE_SLEEP_MODE */
+#else /* defined(CAN_ENFORCE_USE_CALLBACKS) */
+ /**
+ * @brief One or more frames become available.
+ * @note After calling this function it will not be called again
+ * until the received frames queue has been completely emptied. It
+ * is <b>not</b> called for each received frame. It is
+ * responsibility of the application to empty the queue by
+ * repeatedly invoking @p chTryReceiveI().
+ * This behavior minimizes the interrupt served by the system
+ * because CAN traffic.
+ */
+ can_callback_t rxfull_cb;
+ /**
+ * @brief One or more transmission mailbox become available.
+ * @note The flags associated to the callback will indicate which
+ * transmit mailboxes become empty.
+ */
+ can_callback_t txempty_cb;
+ /**
+ * @brief A CAN bus error happened.
+ */
+ can_callback_t error_cb;
+#if (CAN_USE_SLEEP_MODE == TRUE) || defined (__DOXYGEN__)
+ /**
+ * @brief Exiting sleep state.
+ */
+ can_callback_t wakeup_cb;
+#endif
+#endif
/* End of the mandatory fields.*/
/**
* @brief Pointer to the CAN registers.
*/
CAN_TypeDef *can;
-} CANDriver;
+};
/*===========================================================================*/
/* Driver macros. */