/** * @file * @brief Public interface for CAN driver thread. */ #ifndef STA_RTOS_SYSTEM_CAN_BUS_HPP #define STA_RTOS_SYSTEM_CAN_BUS_HPP /** * @defgroup STA_RTOS_CanBus CAN driver * @ingroup STA_RTOS_API * @brief CAN bus system task. * * Check @ref STA_RTOS_BuildConfig for configuration options. */ #ifdef DOXYGEN /** * @brief Enable module. * * @ingroup STA_RTOS_BuildConfig */ # define STA_RTOS_CAN_BUS_ENABLE #endif // DOXYGEN #include #ifdef STA_RTOS_CAN_BUS_ENABLE #include #include #include /** * @def STA_RTOS_CAN_BUS_MAX_FILTER * @brief Set maximum number of usable filters. * * @ingroup STA_RTOS_BuildConfig */ #ifndef STA_RTOS_CAN_BUS_MAX_FILTER # error "Must set STA_RTOS_CAN_BUS_MAX_FILTER in " #endif // STA_RTOS_CAN_BUS_MAX_FILTER /** * @def STA_RTOS_CAN_BUS_MAX_PAYLOAD_SIZE * @brief Set maximum payload size. * * @ingroup STA_RTOS_BuildConfig */ #ifndef STA_RTOS_CAN_BUS_MAX_PAYLOAD_SIZE # error "Must set STA_RTOS_CAN_BUS_MAX_PAYLOAD_SIZE in " #endif // STA_RTOS_CAN_BUS_MAX_PAYLOAD_SIZE /** * @ingroup STA_RTOS_CanBus * @{ */ /** * @brief CAN frame available. */ #define STA_RTOS_CAN_FLAG_MSG_AVAIL 0x000010U /** * @brief Send CAN message. */ #define STA_RTOS_CAN_FLAG_MSG_SEND 0x000020U /** * @brief CAN data message in queue. */ #define STA_RTOS_CAN_FLAG_DATA_QUEUED 0x000040U /** * @brief CAN system message in queue. */ #define STA_RTOS_CAN_FLAG_SYS_QUEUED 0x000080U /** * @brief Show ISOTP statistics. */ #define STA_RTOS_CAN_FLAG_SHOW_STATS 0x000100U /** * @brief CAN SID bits used for system messages. */ #define STA_CAN_SID_SYS_BITS UINT32_C(0x3) /** @} */ namespace sta { namespace rtos { /** * @ingroup STA_RTOS_CanBus * @{ */ /** * @brief Initialize CAN bus. */ void initCanBus(); /** * @brief Return CanController for use in CAN system task. * * Implementation must be provided by application. */ extern CanController * getCanController(); /** * @brief Send notification to CAN driver. * * @param flags Event flags */ void notifyCanBus(uint32_t flags); /** * @brief Place data message in CAN driver TX queue. * * @param msg Message to transmit * @param timeout Timeout for placing message (0 = no wait, osWaitForever = blocking) * @return True if message was queued successfully */ bool queueCanBusMsg(const CanDataMsg & msg, uint32_t timeout); /** * @brief Place system message in CAN driver TX queue. * * @param msg Message to transmit * @param timeout Timeout for placing message (0 = no wait, osWaitForever = blocking) * @return True if message was queued successfully */ bool queueCanBusMsg(const CanSysMsg & msg, uint32_t timeout); /** * @brief Retrieve data message from CAN driver TX queue. * * @param[out] msg Output address for retrieved message * @param timeout Timeout for retrieving message (0 = no wait, osWaitForever = blocking) * @return True if message was retrieved successfully */ bool getCanBusMsg(CanDataMsg * msg, uint32_t timeout); /** * @brief Retrieve system message from CAN driver TX queue. * * @param[out] msg Destination for retrieved message * @param timeout Timeout for retrieving message (0 = no wait, osWaitForever = blocking) * @return True if message was retrieved successfully */ bool getCanBusMsg(CanSysMsg * msg, uint32_t timeout); /** @} */ } // namespace rtos } // namespace sta #endif // STA_RTOS_CAN_BUS_ENABLE #endif // STA_RTOS_SYSTEM_CAN_BUS_HPP