mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-08-05 19:01:54 +00:00
Add moved CAN bus sys task
This commit is contained in:
184
include/sta/rtos/system/can_bus.hpp
Normal file
184
include/sta/rtos/system/can_bus.hpp
Normal file
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Public interface for CAN driver thread.
|
||||
*/
|
||||
#ifndef STA_RTOS_SYSTEM_CAN_BUS_HPP
|
||||
#define STA_RTOS_SYSTEM_CAN_BUS_HPP
|
||||
|
||||
#include <sta/rtos/system/names.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
|
||||
|
||||
/**
|
||||
* @def STA_RTOS_CAN_BUS_TASK_NAME
|
||||
* @brief Set name of CAN driver task.
|
||||
*
|
||||
* @ingroup STA_RTOS_BuildConfig
|
||||
*/
|
||||
#ifndef STA_RTOS_CAN_BUS_TASK_NAME
|
||||
# define STA_RTOS_CAN_BUS_TASK_NAME canBus
|
||||
#endif // !STA_RTOS_CAN_BUS_TASK_NAME
|
||||
|
||||
/**
|
||||
* @def STA_RTOS_CAN_BUS_ENTRY_FUNCTION
|
||||
* @brief Set name of CAN driver task entry function.
|
||||
*
|
||||
* @ingroup STA_RTOS_BuildConfig
|
||||
*/
|
||||
#ifndef STA_RTOS_CAN_BUS_ENTRY_FUNCTION
|
||||
# define STA_RTOS_CAN_BUS_ENTRY_FUNCTION STA_RTOS_MAKE_ENTRY_NAME(STA_RTOS_CAN_BUS_TASK_NAME)
|
||||
#endif // !STA_RTOS_CAN_BUS_ENTRY_FUNCTION
|
||||
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_RTOS_CAN_BUS_ENABLE
|
||||
|
||||
#include <sta/rtos/system/can_msg.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
/**
|
||||
* @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 <sta/config.hpp>"
|
||||
#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 <sta/config.hpp>"
|
||||
#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 Extra initialization run at start of CAN bus task.
|
||||
*
|
||||
* May be overridden by application if required.
|
||||
*/
|
||||
void setupCanBus();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
49
include/sta/rtos/system/can_msg.h
Normal file
49
include/sta/rtos/system/can_msg.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief CAN driver message request types for use in C code.
|
||||
*/
|
||||
#ifndef STA_RTOS_SYSTEM_CAN_MSG_H
|
||||
#define STA_RTOS_SYSTEM_CAN_MSG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/**
|
||||
* @brief CAN message header.
|
||||
*
|
||||
* @ingroup STA_RTOS_CanBus
|
||||
*/
|
||||
struct CanMsgHeader
|
||||
{
|
||||
uint32_t sid; /**< Message SID */
|
||||
uint32_t eid; /**< Message EID */
|
||||
uint8_t format; /**< Message ID format */
|
||||
uint8_t payloadLength; /**< Payload length */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Element type for CAN data message queue.
|
||||
*
|
||||
* @ingroup STA_RTOS_CanBus
|
||||
*/
|
||||
struct CanDataMsg
|
||||
{
|
||||
struct CanMsgHeader header; /**< Message header data */
|
||||
uint8_t payload[64]; /**< Message payload */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Element type for CAN system message queue.
|
||||
*
|
||||
* @ingroup STA_RTOS_CanBus
|
||||
*/
|
||||
struct CanSysMsg
|
||||
{
|
||||
struct CanMsgHeader header; /**< Message header data */
|
||||
uint8_t payload[8]; /**< Message payload */
|
||||
};
|
||||
|
||||
|
||||
#endif // STA_RTOS_SYSTEM_CAN_MSG_H
|
Reference in New Issue
Block a user