361 lines
7.9 KiB
C
361 lines
7.9 KiB
C
//
|
|
// Created by cfif on 16.03.2024.
|
|
//
|
|
|
|
#ifndef CAN_MODULE_CAN_FRAME_XCP_H
|
|
#define CAN_MODULE_CAN_FRAME_XCP_H
|
|
|
|
#include "SerialPortFrameIO.h"
|
|
#include "CanSerialPortFrame.h"
|
|
#include "LoggerToSerialPort.h"
|
|
#include "CmsisRtosThreadUtils.h"
|
|
#include "SystemMutexCmsis.h"
|
|
|
|
#define MAX_CTO 8
|
|
#define MAX_DTO 8
|
|
|
|
typedef enum {
|
|
XCP_ERR_CMD_SYNCH = 0x00,
|
|
XCP_ERR_CMD_BUSY = 0x10,
|
|
XCP_ERR_DAQ_ACTIVE = 0x11,
|
|
XCP_ERR_PGM_ACTIVE = 0x12,
|
|
XCP_ERR_CMD_UNKNOWN = 0x20,
|
|
XCP_ERR_CMD_SYNTAX = 0x21,
|
|
XCP_ERR_OUT_OF_RANGE = 0x22,
|
|
XCP_ERR_WRITE_PROTECTED = 0x23,
|
|
XCP_ERR_ACCESS_DENIED = 0x24,
|
|
XCP_ERR_ACCESS_LOCKED = 0x25,
|
|
XCP_ERR_PAGE_NOT_VALID = 0x26,
|
|
XCP_ERR_MODE_NOT_VALID = 0x27,
|
|
XCP_ERR_SEGMENT_NOT_VALID = 0x28,
|
|
XCP_ERR_SEQUENCE = 0x29,
|
|
XCP_ERR_DAQ_CONFIG = 0x2A,
|
|
XCP_ERR_MEMORY_OVERFLOW = 0x30,
|
|
XCP_ERR_GENERIC = 0x31,
|
|
XCP_ERR_VERIFY = 0x32,
|
|
XCP_ERR_RESOURCE_TEMPORARY_NOT_ACCESSIBLE = 0x33,
|
|
XCP_ERR_SUBCMD_UNKNOWN = 0x34
|
|
} eXcpError;
|
|
|
|
typedef enum {
|
|
XCP_COMMAND_CONNECT = 0xFF,
|
|
XCP_COMMAND_DISCONNECT = 0xFE,
|
|
XCP_COMMAND_GET_STATUS = 0xFD,
|
|
XCP_COMMAND_SYNCH = 0xFC,
|
|
XCP_GET_COMM_MODE_INFO = 0xFB,
|
|
|
|
XCP_GET_SEED = 0xF8,
|
|
XCP_UNLOCK = 0xF7,
|
|
|
|
XCP_COMMAND_SET_MTA = 0xF6,
|
|
|
|
XCP_COMMAND_UPLOAD = 0xF5,
|
|
XCP_COMMAND_SHORT_UPLOAD = 0xF4,
|
|
|
|
XCP_COMMAND_DOWNLOAD = 0xF0,
|
|
XCP_COMMAND_DOWNLOAD_NEXT = 0xEF,
|
|
XCP_COMMAND_DOWNLOAD_MAX = 0xEE,
|
|
|
|
XCP_CLEAR_DAQ_LIST = 0xE3,
|
|
XCP_GET_DAQ_LIST_INFO = 0xD8,
|
|
|
|
XCP_FREE_DAQ = 0xD6,
|
|
XCP_ALLOC_DAQ = 0xD5,
|
|
XCP_ALLOC_ODT = 0xD4,
|
|
XCP_ALLOC_ODT_ENTRY = 0xD3,
|
|
|
|
XCP_SET_DAQ_PTR = 0xE2,
|
|
XCP_WRITE_DAQ = 0xE1,
|
|
XCP_SET_DAQ_LIST_MODE = 0xE0,
|
|
XCP_START_STOP_DAQ_LIST = 0xDE,
|
|
XCP_START_STOP_SYNCH = 0xDD,
|
|
|
|
} eXcpTypeCommand;
|
|
|
|
typedef enum {
|
|
XCP_STOP = 0,
|
|
XCP_START = 1,
|
|
XCP_SELECT = 2
|
|
|
|
} eXcpDAQ_Mode;
|
|
|
|
typedef enum {
|
|
XCP_STANDBY = 0
|
|
|
|
} eXcpResult;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
|
|
uint8_t CAL_PAG: 1; // CALibration and PAGing
|
|
uint8_t reserve1: 1;
|
|
uint8_t DAQ: 1; // DAQ lists supported
|
|
uint8_t STIM: 1; // STIMulation
|
|
uint8_t PGM: 1; // Flash programming
|
|
uint8_t reserve2: 1;
|
|
uint8_t reserve3: 1;
|
|
uint8_t reserve4: 1;
|
|
|
|
uint8_t BYTE__ORDER: 1; // 0 - Intel
|
|
uint8_t ADDRESS_GRANULARITY_0: 1;
|
|
uint8_t ADDRESS_GRANULARITY_1: 1;
|
|
uint8_t reserve5: 1;
|
|
uint8_t reserve6: 1;
|
|
uint8_t reserve7: 1;
|
|
uint8_t SLAVE_BLOCK_MODE: 1;
|
|
uint8_t OPTIONAL: 1;
|
|
|
|
uint8_t MAX_CTO_;
|
|
uint16_t MAX_DTO_;
|
|
|
|
uint8_t XCP_PROTOCOL_VER;
|
|
uint8_t XCP_TRANSPORT_VER;
|
|
|
|
} eXcpCommand_CONNECT;
|
|
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
|
|
uint8_t STORE_CAL_REQ: 1;
|
|
uint8_t reserve1: 1;
|
|
uint8_t STORE_DAQ_REQ: 1;
|
|
uint8_t CLEAR_DAQ_REQ: 1;
|
|
uint8_t reserve2: 1;
|
|
uint8_t reserve3: 1;
|
|
uint8_t DAQ_RUNNING: 1;
|
|
uint8_t RESUME: 1;
|
|
|
|
uint8_t CAL_PAG: 1;
|
|
uint8_t reserve5: 1;
|
|
uint8_t DAQ: 1;
|
|
uint8_t STIM: 1;
|
|
uint8_t PGM: 1;
|
|
uint8_t reserve6: 1;
|
|
uint8_t reserve7: 1;
|
|
uint8_t reserve8: 1;
|
|
|
|
uint8_t STATE_NUMBER;
|
|
|
|
uint32_t SESSION_CONFIGURATION_ID;
|
|
|
|
|
|
} eXcpCommand_GET_STATUS;
|
|
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
|
|
uint8_t RESERVED1;
|
|
|
|
uint8_t MASTER_BLOCK_MODE: 1;
|
|
uint8_t INTERLEAVED_MODE: 1;
|
|
uint8_t RESERVED2: 6;
|
|
|
|
uint8_t RESERVED3;
|
|
uint8_t MAX_BS;
|
|
uint8_t MIN_ST;
|
|
uint8_t QUEUE_SIZE;
|
|
uint8_t VERSION;
|
|
} eXcpCommand_GET_COMM_MODE_INFO;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t COUNT;
|
|
} eXcpCommand_Upload;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t COUNT;
|
|
uint8_t RESERVED;
|
|
uint8_t ADR_EX;
|
|
uint32_t ADR;
|
|
} eXcpCommand_SHORT_UPLOAD;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t MODE;
|
|
uint8_t RESOURCE;
|
|
} eXcpCommand_REQ_GET_SEED;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t LEN;
|
|
uint32_t KEY;
|
|
} eXcpCommand_GET_SEED;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t LEN;
|
|
uint32_t KEY;
|
|
} eXcpCommand_REQ_UNLOCK;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint16_t RESERVED;
|
|
uint8_t ADR_EX;
|
|
uint32_t ADR;
|
|
} eXcpCommand_SET_MTA;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t COUNT;
|
|
} eXcpCommand_Download;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint16_t DAQ_LIST_NUMBER;
|
|
} eXcpCommand_Get_DAQ_List_Info_Request;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t RESERVED;
|
|
uint16_t DAQ_LIST_NUMBER;
|
|
uint8_t ODT_NUMBER;
|
|
uint8_t ODT_ENTRY_NUMBER;
|
|
} eXcpCommand_SET_DAQ_PTR;
|
|
|
|
#define MAX_DAO 6
|
|
#define MAX_ODT 10
|
|
#define MAX_ODT_ENTRIES_SIZE 16
|
|
|
|
typedef struct {
|
|
uint8_t ODT_ENTRIES_COUNT;
|
|
uint8_t ODT_ENTRIES_SIZE[MAX_ODT_ENTRIES_SIZE];
|
|
uint32_t ODT_ENTRIES_ADR[MAX_ODT_ENTRIES_SIZE];
|
|
} tXCP_ODT_ENTRIES;
|
|
|
|
|
|
typedef struct {
|
|
uint8_t ALTERNATING;
|
|
uint8_t DIRECTION;
|
|
uint8_t DTO_CTR;
|
|
uint8_t TIMESTAMP;
|
|
uint8_t PID_OFF;
|
|
uint16_t EVENT_CHANNEL_NUMBER;
|
|
uint8_t TRANSMISSION_RATE_PRESCALER;
|
|
uint8_t DAQ_LIST_PRIORITY;
|
|
|
|
eXcpDAQ_Mode MODE;
|
|
uint8_t ODT_COUNT;
|
|
tXCP_ODT_ENTRIES ODT_NUMBER[MAX_ODT];
|
|
} tXCP_DAQ;
|
|
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
|
|
uint8_t PREDEFINED: 1;
|
|
uint8_t EVENT_FIXED: 1;
|
|
uint8_t DAQ: 1;
|
|
uint8_t STIM: 1;
|
|
uint8_t RESERVER: 4;
|
|
|
|
uint8_t MAX_ODT_;
|
|
uint8_t MAX_ODT_ENTRIES_;
|
|
uint16_t FIXED_EVENT;
|
|
|
|
} eXcpCommand_Get_DAQ_List_Info;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t RESERVED;
|
|
uint16_t DAQ_LIST_NUMBER;
|
|
uint8_t ODT_NUMBER;
|
|
uint8_t ODT_ENTRIES_COUNT;
|
|
} eXcpCommand_DAQ_Alloc_ODR_Entry;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t BIT_OFFSET;
|
|
uint16_t ODT_ENTRY_SIZE;
|
|
uint8_t ADR_EXT;
|
|
uint32_t ADR;
|
|
} eXcpCommand_WRITE_DAQ;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
|
|
uint8_t ALTERNATING: 1;
|
|
uint8_t DIRECTION: 1;
|
|
uint8_t RESERVED1: 1;
|
|
uint8_t DTO_CTR: 1;
|
|
uint8_t TIMESTAMP: 1;
|
|
uint8_t PID_OFF: 1;
|
|
uint8_t RESERVED2: 1;
|
|
uint8_t RESERVED3: 1;
|
|
|
|
uint16_t DAQ_LIST_NUMBER;
|
|
uint16_t EVENT_CHANNEL_NUMBER;
|
|
uint8_t TRANSMISSION_RATE_PRESCALER;
|
|
uint8_t DAQ_LIST_PRIORITY;
|
|
} eXcpCommand_SET_DAQ_LIST_MODE;
|
|
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
eXcpDAQ_Mode MODE;
|
|
uint16_t DAQ_LIST_NUMBER;
|
|
} eXcpCommand_START_STOP_DAQ_LIST;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t RESERVED;
|
|
uint16_t DAQ_COUNT;
|
|
} eXcpCommand_ALLOC_DAQ;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t RESERVED;
|
|
uint8_t DAQ_LIST_NUMBER;
|
|
uint8_t ODT_COUNT;
|
|
} eXcpCommand_ALLOC_ODT;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eXcpTypeCommand COM;
|
|
uint8_t RESERVED;
|
|
uint8_t DAQ_LIST_NUMBER;
|
|
uint8_t ODT_NUMBER;
|
|
uint8_t ODT_ENTRIES_COUNT;
|
|
} eXcpCommand_ALLOC_ODT_ENTRY;
|
|
|
|
typedef struct {
|
|
tSerialPortFrameIO *ioCanFrame;
|
|
tLoggerInterface *logger;
|
|
|
|
uint8_t RND;
|
|
uint8_t ADR_EXT;
|
|
uint32_t ADR_MTA;
|
|
|
|
uint16_t DAQ_LIST_NUMBER;
|
|
uint8_t ODT_NUMBER;
|
|
uint8_t ODT_ENTRY_NUMBER;
|
|
|
|
can_rx_message_type canFrame;
|
|
bool isTransmitResponse;
|
|
uint8_t downloadRemaining;
|
|
uint8_t response[8];
|
|
|
|
tXCP_DAQ DAQ[MAX_DAO];
|
|
uint16_t DAQ_COUNT;
|
|
|
|
tRtcIO *rtcIO;
|
|
|
|
tStaticThreadBlock(1024) T_can_Listener_XCP;
|
|
|
|
} tCanSerialPortFrameXCP;
|
|
|
|
typedef uint8_t (*xcp_func_ptr)(tCanSerialPortFrameXCP *env);
|
|
|
|
|
|
void CanSerialPortFrameXcpInit(
|
|
tCanSerialPortFrameXCP *env,
|
|
tSerialPortFrameIO *ioCanFrame,
|
|
tRtcIO *rtcIO,
|
|
tLoggerInterface *logger
|
|
);
|
|
|
|
void CanSerialPortFrameTp_Start(tCanSerialPortFrameXCP *env);
|
|
|
|
#endif //CAN_MODULE_CAN_FRAME_XCP_H
|