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,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