156 lines
3.4 KiB
C
156 lines
3.4 KiB
C
//
|
|
// Created by cfif on 16.03.2024.
|
|
//
|
|
|
|
#ifndef CAN_MODULE_CAN_FRAME_UDS_H
|
|
#define CAN_MODULE_CAN_FRAME_UDS_H
|
|
|
|
#include "SerialPortFrameIO.h"
|
|
#include "SerialPortFrameTpIO.h"
|
|
#include "CanSerialPortFrame.h"
|
|
#include "LoggerToSerialPort.h"
|
|
#include "CmsisRtosThreadUtils.h"
|
|
#include "SystemMutexCmsis.h"
|
|
|
|
#define TP_FRAME_PADDING 0xaa
|
|
|
|
#define WAIT_FC_FRAME_TIMEOUT 200
|
|
#define WAIT_FF_FRAME_TIMEOUT 300
|
|
|
|
#define WAIT_FRAME_WRITE 300
|
|
|
|
typedef enum {
|
|
TP_TYPE_FRAME_SF = 0,
|
|
TP_TYPE_FRAME_FF = 1,
|
|
TP_TYPE_FRAME_CF = 2,
|
|
TP_TYPE_FRAME_FC = 3
|
|
} eTpTypeFrame;
|
|
|
|
typedef enum {
|
|
TP_RECEIVED_DATA = 0,
|
|
TP_RECEIVED_FC_DATA = 1,
|
|
TP_ERROR_FS_ERROR_SIZE = 2,
|
|
TP_ERROR_FC_TIMEOUT = 3,
|
|
TP_ERROR_FC_ERROR = 4,
|
|
TP_ERROR_FF_ERROR = 5,
|
|
TP_ERROR_FF_ERROR_SIZE = 6,
|
|
TP_ERROR_FF_ERROR_TIMEOUT = 7,
|
|
TP_ERROR_CF_ERROR = 8,
|
|
TP_ERROR_CF_ERROR_SIZE = 9,
|
|
TP_ERROR_CF_ERROR_SN = 10,
|
|
TP_ERROR_WRONG_ADDRESS= 11,
|
|
TP_STANDBY = 12
|
|
|
|
} eTpResult;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
eTpTypeFrame typeFrame: 4;
|
|
} eTpFrameHead;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint8_t dl: 4;
|
|
eTpTypeFrame typeFrame: 4;
|
|
uint8_t data[7];
|
|
} eTpFrameSF;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint8_t dlM: 4;
|
|
eTpTypeFrame typeFrame: 4;
|
|
uint8_t dlL;
|
|
uint8_t data[6];
|
|
} eTpFrameFF;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint8_t sn: 4;
|
|
eTpTypeFrame typeFrame: 4;
|
|
uint8_t data[7];
|
|
} eTpFrameCF;
|
|
|
|
typedef struct __attribute__ ((packed)) {
|
|
uint8_t status: 4;
|
|
eTpTypeFrame typeFrame: 4;
|
|
uint8_t blockSize;
|
|
uint8_t timeST;
|
|
} eTpFrameFC;
|
|
|
|
typedef struct {
|
|
uint32_t adrCan;
|
|
uint16_t len;
|
|
uint8_t data[50];
|
|
} tCanTP_data;
|
|
|
|
typedef struct {
|
|
uint32_t adrCan;
|
|
uint16_t len;
|
|
uint8_t data[1024];
|
|
} tCanTP_Ext_data;
|
|
|
|
typedef void (*tReceivedTP_func)(void *arg, tCanTP_data *data);
|
|
typedef bool (*tReceivedCan_func)(void *arg, can_rx_message_type *data);
|
|
|
|
typedef struct {
|
|
tSerialPortFrameIO *ioCanFrame;
|
|
tLoggerToSerialPort *slog;
|
|
char hexString[2048 * 2];
|
|
volatile bool isFlowControl;
|
|
|
|
SystemMutexCmsis txAccessQueue;
|
|
|
|
uint32_t timeoutFF;
|
|
|
|
tCanTP_data *dataBuf;
|
|
uint16_t dataBufMaxSize;
|
|
uint16_t dataBufWorkLen;
|
|
uint16_t dataBufLen;
|
|
|
|
uint16_t dataReceivedConsecutiveFrameLen;
|
|
uint8_t sn;
|
|
|
|
tReceivedCan_func ReceivedCan_func;
|
|
void *callback_argCan;
|
|
|
|
tReceivedTP_func receivedTP_func;
|
|
void *callback_argTp;
|
|
|
|
uint8_t filterIdCount;
|
|
uint32_t *filterReqId;
|
|
uint32_t *filterRespId;
|
|
uint8_t *filterDirReq;
|
|
|
|
uint8_t numBuf;
|
|
|
|
tStaticThreadBlock(1024) T_can_Listener0;
|
|
tStaticThreadBlock(1024) T_can_Listener1;
|
|
} tCanSerialPortFrameTp;
|
|
|
|
void CanSerialPortFrameTpInit(
|
|
tCanSerialPortFrameTp *env,
|
|
|
|
uint8_t numBuf,
|
|
|
|
SystemMutexCmsis txAccessQueue,
|
|
|
|
tReceivedCan_func receivedCan_func,
|
|
void *callback_argCan,
|
|
|
|
tReceivedTP_func receivedTP_func,
|
|
void *callback_argTp,
|
|
|
|
tSerialPortFrameIO *ioCanFrame,
|
|
tCanTP_data *dataBuf,
|
|
uint16_t dataBufMaxSize,
|
|
tLoggerToSerialPort *slog,
|
|
|
|
uint8_t filterIdCount,
|
|
uint32_t *filterReqId,
|
|
uint32_t *filterRespId,
|
|
uint8_t *filterDirReq
|
|
);
|
|
|
|
void CanSerialPortFrameTp_Start(tCanSerialPortFrameTp *env, uint8_t numBuf);
|
|
|
|
bool
|
|
CanSerialPortFrameTpTransmit(tCanSerialPortFrameTp *env, uint8_t *data, uint16_t size, uint32_t id, uint32_t timeout);
|
|
|
|
#endif //CAN_MODULE_CAN_FRAME_UDS_H
|