69 lines
2.6 KiB
C
69 lines
2.6 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 IVEC_ECU_UART_MAX_PACKET_LENGTH 32/*!<Maximum length of packet that can be received*/
|
|
|
|
#define IVEC_ECU_UART_PKT_HEADER 7/*!<Protocol headers*/
|
|
#define IVEC_ECU_UART_PKT_HEADER_FOOTER 9/*!<Protocol headers+footers*/
|
|
|
|
#endif
|
|
|
|
#define IVEC_ECU_UART_GET_PACKET_SIZE(x) (x + IVEC_ECU_UART_PKT_HEADER_FOOTER)/*!<Complete packet size*/
|
|
|
|
#define IVEC_ECU_UART_PACKET_SUCCESS 0/*!<Success*/
|
|
#define IVEC_ECU_UART_PACKET_FAIL -1/*!<Error*/
|
|
|
|
/*Private Variables*/
|
|
typedef int IVEC_ECU_UartPacketRetCode_e;/*SERVICE_SUCESS or SERVICE_FAIL*/
|
|
|
|
|
|
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
|
|
{
|
|
xMcalUartHandle __xUartHandle;
|
|
IVEC_ECU_UartPortNumber_e eUartPortNumber;
|
|
volatile uint8_t* u8Qbuffer;
|
|
uint16_t u16QbufSize;
|
|
uint16_t u16len;
|
|
void (*pvUartRecvCallback)(IVEC_ECU_UartPortNumber_e, IVEC_ECU_UartEvent_e , char *, uint32_t);
|
|
} IVEC_ECU_UartHandle_s;
|
|
|
|
/*===========================================================================
|
|
* Functions declaration
|
|
===========================================================================*/
|
|
|
|
|
|
IVEC_EcuCommonErr_e IVEC_ECU_Uart_Init(IVEC_ECU_UartHandle_s* uartHandle, uint32_t speed);
|
|
IVEC_EcuCommonErr_e IVEC_ECU_Uart_Deinit(IVEC_ECU_UartHandle_s *uartHandle);
|
|
IVEC_EcuCommonErr_e IVEC_ECU_Uart_Reinit(IVEC_ECU_UartHandle_s *uartHandle, uint32_t speed);
|
|
IVEC_EcuCommonErr_e IVEC_ECU_Uart_Transmit(IVEC_ECU_UartHandle_s *uartHandle, uint8_t* buffer, uint16_t len);
|
|
IVEC_EcuCommonErr_e IVEC_ECU_Uart_GetData(IVEC_ECU_UartHandle_s *uartHandle, uint8_t* buffer, uint16_t len, uint16_t timeout);
|
|
|
|
IVEC_ECU_UartPacketRetCode_e IVEC_ECU_Uart_FormatPacket(IVEC_ECU_UartHandle_s *uartHandle, uint8_t* data, uint8_t dlc, uint32_t id);
|
|
IVEC_ECU_UartPacketRetCode_e IVEC_ECU_Uart_ReadCANDataLenOverUART(IVEC_ECU_UartHandle_s *uartHandle, uint8_t* buffer, uint32_t *id);
|
|
IVEC_ECU_UartPacketRetCode_e IVEC_ECU_Uart_ReadCANDataOverUART(IVEC_ECU_UartHandle_s* uartHandle, uint8_t* buffer, uint32_t *id);
|
|
int IVEC_ECU_Uart_InitiateTransmit(IVEC_ECU_UartHandle_s* uartHandle, uint32_t id, uint8_t *data, uint8_t len);
|