93 lines
3.4 KiB
C
93 lines
3.4 KiB
C
#ifndef IVEC_ECU_UART_H
|
|
#define IVEC_ECU_UART_H
|
|
|
|
#include "../Core/Include/ivec_mcal_uart.h"
|
|
#include "../ivec_ECU/ivec_ecu_common/inc/ivec_ecu_common.h"
|
|
|
|
|
|
#include "stdint.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define ecuUART_MAX_PACKET_LENGTH_u8 32/*!<Maximum length of packet that can be received*/
|
|
|
|
#define ecuUART_PKT_HEADER_u8 7/*!<Protocol headers*/
|
|
#define ecuUART_PKT_HEADER_FOOTER_u8 9/*!<Protocol headers+footers*/
|
|
|
|
#endif
|
|
|
|
#define ecuUART_GET_PACKET_SIZE(x) (x + ecuUART_PKT_HEADER_FOOTER_u8)/*!<Complete packet size*/
|
|
|
|
#define ecuUART_PACKET_SUCCESS_u8 0/*!<Success*/
|
|
#define ecuUART_PACKET_FAIL_i8 -1/*!<Error*/
|
|
|
|
/*Private Variables*/
|
|
typedef int IVEC_ECU_UartPacketRetCode_e;/*SERVICE_SUCESS or SERVICE_FAIL*/
|
|
|
|
typedef enum {
|
|
IVEC_ECU_UART_BAUD_AUTO = 0,
|
|
IVEC_ECU_UART_BAUD_2400 = 2400,
|
|
IVEC_ECU_UART_BAUD_4800 = 4800,
|
|
IVEC_ECU_UART_BAUD_9600 = 9600,
|
|
IVEC_ECU_UART_BAUD_14400 = 14400,
|
|
IVEC_ECU_UART_BAUD_19200 = 19200,
|
|
IVEC_ECU_UART_BAUD_28800 = 28800,
|
|
IVEC_ECU_UART_BAUD_33600 = 33600,
|
|
IVEC_ECU_UART_BAUD_38400 = 38400,
|
|
IVEC_ECU_UART_BAUD_57600 = 57600,
|
|
IVEC_ECU_UART_BAUD_115200 = 115200,
|
|
IVEC_ECU_UART_BAUD_230400 = 230400,
|
|
IVEC_ECU_UART_BAUD_460800 = 460800,
|
|
IVEC_ECU_UART_BAUD_921600 = 921600,
|
|
IVEC_ECU_UART_BAUD_1000000 = 1000000,
|
|
IVEC_ECU_UART_BAUD_1843200 = 1843200,
|
|
IVEC_ECU_UART_BAUD_2000000 = 2000000,
|
|
IVEC_ECU_UART_BAUD_2100000 = 2100000,
|
|
IVEC_ECU_UART_BAUD_3686400 = 3686400,
|
|
IVEC_ECU_UART_BAUD_4000000 = 4000000,
|
|
IVEC_ECU_UART_BAUD_4468750 = 4468750
|
|
} IVEC_EcuUartBaudRate_e;
|
|
|
|
|
|
typedef enum
|
|
{
|
|
IVEC_ECU_UART_PORT1 = 0,
|
|
IVEC_ECU_UART_PORT2,
|
|
IVEC_ECU_UART_PORT3,
|
|
IVEC_ECU_UART_PORT_MAX
|
|
} IVEC_ECU_UartPortNumber_e;
|
|
|
|
typedef enum
|
|
{
|
|
IVEC_ECU_UART_EVENT_RX_ARRIVED = 1,
|
|
IVEC_ECU_UART_EVENT_RX_OVERFLOW = 2,
|
|
IVEC_ECU_UART_EVENT_TX_COMPLETE = 3
|
|
} IVEC_ECU_UartEvent_e;
|
|
|
|
typedef struct
|
|
{
|
|
IVEC_McalUartHandle_s __xUartHandle;
|
|
IVEC_ECU_UartPortNumber_e eUartPortNumber;
|
|
volatile uint8_t* u8Qbuffer;
|
|
uint16_t u16QbufSize;
|
|
uint16_t u16len;
|
|
IVEC_EcuUartBaudRate_e u32BaudRate;
|
|
void (*pvUartRecvCallback)(IVEC_ECU_UartPortNumber_e, IVEC_ECU_UartEvent_e , char *, uint32_t);
|
|
} IVEC_EcuUartHandle_s;
|
|
|
|
/*===========================================================================
|
|
* Functions declaration
|
|
===========================================================================*/
|
|
|
|
IVEC_EcuCommonErr_e xECU_UartInit(IVEC_EcuUartHandle_s* pxUartHandle);
|
|
IVEC_EcuCommonErr_e xECU_UartDeinit(IVEC_EcuUartHandle_s *pxUartHandle);
|
|
IVEC_EcuCommonErr_e xECU_UartReinit(IVEC_EcuUartHandle_s *pxUartHandle);
|
|
IVEC_EcuCommonErr_e xECU_UartTransmit(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buffer, uint16_t u16Len);
|
|
IVEC_EcuCommonErr_e xECU_UartGetData(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buffer, uint16_t u16Len, uint16_t u16Timeout);
|
|
|
|
IVEC_ECU_UartPacketRetCode_e xECU_UartFormatPacket(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Data, uint8_t u8Dlc, uint32_t u32Id);
|
|
IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataLenOverUART(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buf, uint32_t* u32Id);
|
|
IVEC_ECU_UartPacketRetCode_e xECU_UartReadCANDataOverUART(IVEC_EcuUartHandle_s* pxUartHandle, uint8_t* pu8Buf, uint32_t* u32Id);
|
|
int32_t iECU_UartInitiateTransmit(IVEC_EcuUartHandle_s* pxUartHandle, uint32_t u32Id, uint8_t* pu8Data, uint8_t u8Len);
|