Add full automotive RTOS project
Add kernel (Cortex-M0/M3/M4, Tricore, S32K, RISC-V ports), drivers, middleware (CAN stack, diagnostics, safety), applications, board support, build/test tooling, and documentation.
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @file can_nm.h
|
||||
* @brief CAN Network Management (AUTOSAR-like) implementation
|
||||
*/
|
||||
|
||||
#ifndef CAN_NM_H
|
||||
#define CAN_NM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "kernel.h"
|
||||
#include "can_driver.h"
|
||||
|
||||
/* CAN NM Configuration */
|
||||
#define CAN_NM_MAX_NODES 16
|
||||
#define CAN_NM_MAX_NETWORKS 4
|
||||
#define CAN_NM_MESSAGE_ID_BASE 0x400 /* Base ID for NM messages */
|
||||
#define CAN_NM_DEFAULT_TIMEOUT_MS 2000
|
||||
|
||||
/* CAN NM States */
|
||||
typedef enum {
|
||||
CAN_NM_BUS_SLEEP = 0,
|
||||
CAN_NM_PREPARE_BUS_SLEEP = 1,
|
||||
CAN_NM_READY_SLEEP = 2,
|
||||
CAN_NM_NORMAL_OPERATION = 3,
|
||||
CAN_NM_REPEAT_MESSAGE = 4,
|
||||
CAN_NM_SYNCHRONIZE = 5,
|
||||
CAN_NM_OFFLINE = 6
|
||||
} CanNmState_t;
|
||||
|
||||
/* CAN NM Message Types */
|
||||
typedef enum {
|
||||
CAN_NM_MSG_ALIVE = 0,
|
||||
CAN_NM_MSG_RING = 1,
|
||||
CAN_NM_MSG_LIMPHOME = 2,
|
||||
CAN_NM_MSG_SLEEP_ACK = 3,
|
||||
CAN_NM_MSG_SLEEP_CONF = 4
|
||||
} CanNmMessageType_t;
|
||||
|
||||
/* CAN NM Configuration */
|
||||
typedef struct {
|
||||
uint8_t node_id;
|
||||
uint8_t network_id;
|
||||
uint32_t message_id;
|
||||
uint32_t timeout_ms;
|
||||
uint32_t repeat_message_time_ms;
|
||||
bool is_coordinator;
|
||||
uint8_t sleep_ack_timeout_ms;
|
||||
} CanNmConfig_t;
|
||||
|
||||
/* CAN NM Node Information */
|
||||
typedef struct {
|
||||
uint8_t node_id;
|
||||
bool is_present;
|
||||
bool is_awake;
|
||||
uint32_t last_message_time;
|
||||
CanNmState_t state;
|
||||
} CanNmNodeInfo_t;
|
||||
|
||||
/* CAN NM Callbacks */
|
||||
typedef void (*CanNmNetworkStateChangedCallback_t)(CanNmState_t new_state);
|
||||
typedef void (*CanNmNodeStateChangedCallback_t)(uint8_t node_id, bool is_awake);
|
||||
typedef void (*CanNmBusSleepRequestCallback_t)(void);
|
||||
typedef void (*CanNmWakeupIndicationCallback_t)(void);
|
||||
|
||||
/* CAN NM Functions */
|
||||
KernelStatus_t can_nm_init(const CanNmConfig_t* config);
|
||||
KernelStatus_t can_nm_deinit(void);
|
||||
KernelStatus_t can_nm_start(void);
|
||||
KernelStatus_t can_nm_stop(void);
|
||||
KernelStatus_t can_nm_request_bus_sleep(void);
|
||||
KernelStatus_t can_nm_network_release(void);
|
||||
KernelStatus_t can_nm_network_request(void);
|
||||
CanNmState_t can_nm_get_state(void);
|
||||
KernelStatus_t can_nm_get_node_info(uint8_t node_id, CanNmNodeInfo_t* info);
|
||||
KernelStatus_t can_nm_register_callbacks(
|
||||
CanNmNetworkStateChangedCallback_t network_callback,
|
||||
CanNmNodeStateChangedCallback_t node_callback,
|
||||
CanNmBusSleepRequestCallback_t sleep_callback,
|
||||
CanNmWakeupIndicationCallback_t wakeup_callback);
|
||||
void can_nm_process_rx_message(const CanMessage_t* message);
|
||||
void can_nm_main_function(void); /* Periodic processing */
|
||||
bool can_nm_is_bus_awake(void);
|
||||
|
||||
#endif /* CAN_NM_H */
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @file can_tp.h
|
||||
* @brief CAN Transport Protocol (ISO 15765-2) implementation
|
||||
*/
|
||||
|
||||
#ifndef CAN_TP_H
|
||||
#define CAN_TP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "kernel.h"
|
||||
#include "can_driver.h"
|
||||
|
||||
/* CAN TP Configuration */
|
||||
#define CAN_TP_MAX_CONNECTIONS 8
|
||||
#define CAN_TP_MAX_PAYLOAD_SIZE 4096
|
||||
#define CAN_TP_DEFAULT_TIMEOUT_MS 1000
|
||||
#define CAN_TP_STMIN_DEFAULT 10 /* Minimum separation time in ms */
|
||||
#define CAN_TP_BS_DEFAULT 8 /* Block size */
|
||||
|
||||
/* CAN TP Addressing Formats */
|
||||
typedef enum {
|
||||
CAN_TP_ADDRESSING_NORMAL = 0, /* Standard 11-bit or 29-bit */
|
||||
CAN_TP_ADDRESSING_NORMAL_FIXED = 1, /* Fixed addressing */
|
||||
CAN_TP_ADDRESSING_EXTENDED = 2, /* Extended addressing */
|
||||
CAN_TP_ADDRESSING_MIXED = 3 /* Mixed addressing */
|
||||
} CanTpAddressingFormat_t;
|
||||
|
||||
/* CAN TP Frame Types */
|
||||
typedef enum {
|
||||
CAN_TP_FRAME_SINGLE = 0, /* Single Frame */
|
||||
CAN_TP_FRAME_FIRST = 1, /* First Frame */
|
||||
CAN_TP_FRAME_CONSECUTIVE = 2, /* Consecutive Frame */
|
||||
CAN_TP_FRAME_FLOW_CONTROL = 3 /* Flow Control */
|
||||
} CanTpFrameType_t;
|
||||
|
||||
/* CAN TP Flow Control Status */
|
||||
typedef enum {
|
||||
CAN_TP_FC_CONTINUE = 0, /* Continue to send */
|
||||
CAN_TP_FC_WAIT = 1, /* Wait */
|
||||
CAN_TP_FC_OVERFLOW = 2 /* Overflow/Abort */
|
||||
} CanTpFlowControlStatus_t;
|
||||
|
||||
/* CAN TP States */
|
||||
typedef enum {
|
||||
CAN_TP_IDLE = 0,
|
||||
CAN_TP_SEND_IN_PROGRESS = 1,
|
||||
CAN_TP_RECEIVE_IN_PROGRESS = 2,
|
||||
CAN_TP_WAIT_FLOW_CONTROL = 3,
|
||||
CAN_TP_WAIT_CONSECUTIVE = 4,
|
||||
CAN_TP_TIMEOUT = 5,
|
||||
CAN_TP_ERROR = 6
|
||||
} CanTpState_t;
|
||||
|
||||
/* CAN TP Message Structure */
|
||||
typedef struct {
|
||||
uint32_t message_id;
|
||||
uint8_t* data;
|
||||
uint16_t length;
|
||||
uint8_t addressing_format;
|
||||
uint32_t source_address;
|
||||
uint32_t target_address;
|
||||
} CanTpMessage_t;
|
||||
|
||||
/* CAN TP Connection */
|
||||
typedef struct {
|
||||
uint8_t connection_id;
|
||||
CanTpState_t state;
|
||||
CanTpMessage_t current_message;
|
||||
uint16_t current_index;
|
||||
uint8_t sequence_number;
|
||||
uint8_t block_counter;
|
||||
uint32_t timeout_timer;
|
||||
uint8_t stmin;
|
||||
uint8_t block_size;
|
||||
bool is_sender;
|
||||
Semaphore_t flow_control_semaphore;
|
||||
Semaphore_t complete_semaphore;
|
||||
Mutex_t connection_mutex;
|
||||
} CanTpConnection_t;
|
||||
|
||||
/* CAN TP Configuration */
|
||||
typedef struct {
|
||||
CanTpAddressingFormat_t addressing_format;
|
||||
uint32_t source_address;
|
||||
uint32_t target_address;
|
||||
uint32_t timeout_ms;
|
||||
uint8_t stmin;
|
||||
uint8_t block_size;
|
||||
bool padding_enabled;
|
||||
uint8_t padding_byte;
|
||||
} CanTpConfig_t;
|
||||
|
||||
/* CAN TP Callbacks */
|
||||
typedef void (*CanTpMessageReceivedCallback_t)(const CanTpMessage_t* message);
|
||||
typedef void (*CanTpMessageSentCallback_t)(uint8_t connection_id, bool success);
|
||||
typedef void (*CanTpErrorCallback_t)(uint8_t connection_id, uint32_t error_code);
|
||||
|
||||
/* CAN TP Functions */
|
||||
KernelStatus_t can_tp_init(const CanTpConfig_t* config);
|
||||
KernelStatus_t can_tp_deinit(void);
|
||||
KernelStatus_t can_tp_send_message(const CanTpMessage_t* message,
|
||||
uint32_t timeout_ms);
|
||||
KernelStatus_t can_tp_receive_message(CanTpMessage_t* message,
|
||||
uint32_t timeout_ms);
|
||||
KernelStatus_t can_tp_register_callbacks(
|
||||
CanTpMessageReceivedCallback_t rx_callback,
|
||||
CanTpMessageSentCallback_t tx_callback,
|
||||
CanTpErrorCallback_t error_callback);
|
||||
void can_tp_process_rx_indication(const CanMessage_t* can_message);
|
||||
void can_tp_process_tx_confirmation(uint8_t mailbox);
|
||||
void can_tp_main_function(void); /* Periodic processing */
|
||||
CanTpState_t can_tp_get_state(uint8_t connection_id);
|
||||
|
||||
#endif /* CAN_TP_H */
|
||||
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* @file uds.h
|
||||
* @brief Unified Diagnostic Services (ISO 14229) implementation
|
||||
*/
|
||||
|
||||
#ifndef UDS_H
|
||||
#define UDS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "kernel.h"
|
||||
#include "can_tp.h"
|
||||
|
||||
/* UDS Configuration */
|
||||
#define UDS_MAX_SESSIONS 8
|
||||
#define UDS_MAX_SECURITY_LEVELS 5
|
||||
#define UDS_MAX_DTCS 50
|
||||
#define UDS_MAX_DATA_SIZE 4096
|
||||
|
||||
/* UDS Service IDs */
|
||||
typedef enum {
|
||||
UDS_SID_DIAGNOSTIC_SESSION_CONTROL = 0x10,
|
||||
UDS_SID_ECU_RESET = 0x11,
|
||||
UDS_SID_SECURITY_ACCESS = 0x27,
|
||||
UDS_SID_COMMUNICATION_CONTROL = 0x28,
|
||||
UDS_SID_READ_DATA_BY_IDENTIFIER = 0x22,
|
||||
UDS_SID_WRITE_DATA_BY_IDENTIFIER = 0x2E,
|
||||
UDS_SID_IO_CONTROL_BY_IDENTIFIER = 0x2F,
|
||||
UDS_SID_ROUTINE_CONTROL = 0x31,
|
||||
UDS_SID_REQUEST_DOWNLOAD = 0x34,
|
||||
UDS_SID_REQUEST_UPLOAD = 0x35,
|
||||
UDS_SID_TRANSFER_DATA = 0x36,
|
||||
UDS_SID_REQUEST_TRANSFER_EXIT = 0x37,
|
||||
UDS_SID_READ_DTC_INFORMATION = 0x19,
|
||||
UDS_SID_CLEAR_DTC_INFORMATION = 0x14,
|
||||
UDS_SID_READ_DATA_BY_PERIODIC_IDENTIFIER = 0x2A,
|
||||
UDS_SID_DYNAMICALLY_DEFINE_DATA_IDENTIFIER = 0x2C,
|
||||
UDS_SID_TESTER_PRESENT = 0x3E,
|
||||
UDS_SID_CONTROL_DTC_SETTING = 0x85
|
||||
} UdsServiceId_t;
|
||||
|
||||
/* UDS Response Codes */
|
||||
typedef enum {
|
||||
UDS_RESPONSE_POSITIVE = 0x00,
|
||||
UDS_RESPONSE_GENERAL_REJECT = 0x10,
|
||||
UDS_RESPONSE_SERVICE_NOT_SUPPORTED = 0x11,
|
||||
UDS_RESPONSE_SUBFUNCTION_NOT_SUPPORTED = 0x12,
|
||||
UDS_RESPONSE_INCORRECT_MESSAGE_LENGTH = 0x13,
|
||||
UDS_RESPONSE_CONDITIONS_NOT_CORRECT = 0x22,
|
||||
UDS_RESPONSE_REQUEST_SEQUENCE_ERROR = 0x24,
|
||||
UDS_RESPONSE_REQUEST_OUT_OF_RANGE = 0x31,
|
||||
UDS_RESPONSE_SECURITY_ACCESS_DENIED = 0x33,
|
||||
UDS_RESPONSE_INVALID_KEY = 0x35,
|
||||
UDS_RESPONSE_EXCEED_NUMBER_OF_ATTEMPTS = 0x36,
|
||||
UDS_RESPONSE_REQUIRED_TIME_DELAY_NOT_EXPIRED = 0x37,
|
||||
UDS_RESPONSE_UPLOAD_DOWNLOAD_NOT_ACCEPTED = 0x70,
|
||||
UDS_RESPONSE_TRANSFER_DATA_SUSPENDED = 0x71,
|
||||
UDS_RESPONSE_GENERAL_PROGRAMMING_FAILURE = 0x72,
|
||||
UDS_RESPONSE_WRONG_BLOCK_SEQUENCE_COUNTER = 0x73,
|
||||
UDS_RESPONSE_RESPONSE_PENDING = 0x78,
|
||||
UDS_RESPONSE_SUBFUNCTION_NOT_SUPPORTED_IN_ACTIVE_SESSION = 0x7E,
|
||||
UDS_RESPONSE_SERVICE_NOT_SUPPORTED_IN_ACTIVE_SESSION = 0x7F
|
||||
} UdsResponseCode_t;
|
||||
|
||||
/* UDS Sessions */
|
||||
typedef enum {
|
||||
UDS_SESSION_DEFAULT = 0x01,
|
||||
UDS_SESSION_PROGRAMMING = 0x02,
|
||||
UDS_SESSION_EXTENDED = 0x03,
|
||||
UDS_SESSION_SAFETY_SYSTEM = 0x04
|
||||
} UdsSessionType_t;
|
||||
|
||||
/* UDS Security Levels */
|
||||
typedef enum {
|
||||
UDS_SECURITY_LOCKED = 0x00,
|
||||
UDS_SECURITY_LEVEL_1 = 0x01,
|
||||
UDS_SECURITY_LEVEL_2 = 0x02,
|
||||
UDS_SECURITY_LEVEL_3 = 0x03,
|
||||
UDS_SECURITY_LEVEL_4 = 0x04,
|
||||
UDS_SECURITY_LEVEL_5 = 0x05
|
||||
} UdsSecurityLevel_t;
|
||||
|
||||
/* UDS Message Structure */
|
||||
typedef struct {
|
||||
uint8_t service_id;
|
||||
uint8_t sub_function;
|
||||
uint8_t* data;
|
||||
uint16_t length;
|
||||
uint32_t data_identifier;
|
||||
UdsSessionType_t session_type;
|
||||
UdsSecurityLevel_t security_level;
|
||||
} UdsMessage_t;
|
||||
|
||||
/* UDS Configuration */
|
||||
typedef struct {
|
||||
uint32_t source_address;
|
||||
uint32_t target_address;
|
||||
uint32_t timeout_ms;
|
||||
UdsSessionType_t current_session;
|
||||
UdsSecurityLevel_t current_security_level;
|
||||
bool security_access_enabled;
|
||||
uint32_t p2_server_max_ms;
|
||||
uint32_t p2_star_server_max_ms;
|
||||
} UdsConfig_t;
|
||||
|
||||
/* UDS Callbacks */
|
||||
typedef void (*UdsServiceCallback_t)(const UdsMessage_t* request,
|
||||
UdsMessage_t* response);
|
||||
typedef void (*UdsSecurityAccessCallback_t)(uint8_t security_level,
|
||||
const uint8_t* seed,
|
||||
uint8_t* key,
|
||||
uint8_t length,
|
||||
bool* access_granted);
|
||||
typedef void (*UdsSessionChangedCallback_t)(UdsSessionType_t old_session,
|
||||
UdsSessionType_t new_session);
|
||||
|
||||
/* UDS Functions */
|
||||
KernelStatus_t uds_init(const UdsConfig_t* config);
|
||||
KernelStatus_t uds_deinit(void);
|
||||
KernelStatus_t uds_process_message(const UdsMessage_t* request,
|
||||
UdsMessage_t* response);
|
||||
KernelStatus_t uds_register_service_callback(UdsServiceId_t service_id,
|
||||
UdsServiceCallback_t callback);
|
||||
KernelStatus_t uds_register_security_callback(
|
||||
UdsSecurityAccessCallback_t callback);
|
||||
KernelStatus_t uds_register_session_callback(
|
||||
UdsSessionChangedCallback_t callback);
|
||||
KernelStatus_t uds_set_session(UdsSessionType_t session);
|
||||
UdsSessionType_t uds_get_session(void);
|
||||
KernelStatus_t uds_set_security_level(UdsSecurityLevel_t level);
|
||||
UdsSecurityLevel_t uds_get_security_level(void);
|
||||
void uds_main_function(void); /* Periodic processing */
|
||||
|
||||
#endif /* UDS_H */
|
||||
Reference in New Issue
Block a user