189 lines
5.6 KiB
C
189 lines
5.6 KiB
C
/*
|
|
* ivec_rte.c
|
|
*
|
|
* Created on: 28-Oct-2024
|
|
* Author: altam
|
|
*/
|
|
#include "ivec_rte.h"
|
|
|
|
#include "ivec_cmplx_queue.h"
|
|
#include "../ivec_ECU/ivec_ecu_uart/inc/ivec_ecu_uart.h"
|
|
#include "../ivec_ECU/ivec_ecu_can/inc/ivec_ecu_can.h"
|
|
#include "../../Core/Include/ivec_mcal_gpio.h"
|
|
#include "socTouchDisplay.h"
|
|
#include "../../TM1650_SDK/inc/ivec_TM1650.h"
|
|
|
|
|
|
McalUartHandle_s g_xUartHandle;
|
|
uint32_t g_u32UartSpeed = 0;
|
|
uint16_t g_u16CanSpeed = 0;
|
|
|
|
static uint8_t __gprv_u8Idx = 0;
|
|
|
|
extern ExtU_socTouchDisplay_T socTouchDisplay_U;
|
|
extern ExtY_socTouchDisplay_T socTouchDisplay_Y;
|
|
|
|
/**
|
|
* @brief Function to use SDA pin of TM1650
|
|
*
|
|
* @param state the value to write on SDA pin (0 or 1)
|
|
* @returns none
|
|
*/
|
|
void mcu_tempDataPin(uint8_t state)
|
|
{
|
|
if(state == 0){
|
|
vMCAL_gpioWrite(TM1650_PORT, TM1650_SDA_PIN_PIN, 0);
|
|
}
|
|
else if(state == 1){
|
|
vMCAL_gpioWrite(TM1650_PORT, TM1650_SDA_PIN_PIN, 1);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Function to use SCL pin of TM1650
|
|
*
|
|
* @param state the value to write on SDA pin (0 or 1)
|
|
* @returns none
|
|
*/
|
|
void mcu_tempClkPin(uint8_t state){
|
|
if(state == 0){
|
|
vMCAL_gpioWrite(TM1650_PORT, TM1650_SCL_PIN_PIN, 0);
|
|
}
|
|
else if(state == 1){
|
|
vMCAL_gpioWrite(TM1650_PORT, TM1650_SCL_PIN_PIN, 1);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Function to read SDA pin of TM1650
|
|
*
|
|
* @param none
|
|
* @returns Value of GPIO (0 or 1)
|
|
*/
|
|
uint8_t mcu_tempDataReadPin(void){
|
|
uint8_t readBuff = 0;
|
|
vMCAL_set_gpioDirection(TM1650_SDA_PIN_IOMUX,false);
|
|
readBuff = u32MCAL_gpioRead(TM1650_PORT, TM1650_SDA_PIN_PIN);
|
|
vMCAL_set_gpioDirection(TM1650_SDA_PIN_IOMUX,true);
|
|
return readBuff;
|
|
}
|
|
|
|
|
|
/**
|
|
* #define TOUCH_BUTTON_PORT (GPIOB)
|
|
#define TOUCH_BUTTON_PIN_17_PIN (DL_GPIO_PIN_17)
|
|
#define TOUCH_BUTTON_PIN_17_IOMUX (IOMUX_PINCM43)
|
|
*/
|
|
void vRTE_MatlabInit(void)
|
|
{
|
|
u8MCAL_gpioInit();
|
|
tm1650_Init(TM_1650_BRIGHT_8, TM_1650_Segment_8, TM_1650_Normal_Mode, TM_1650_Screen_ON, TM_1650_DIG_3, (void*)&mcu_tempDataPin , (void*)&mcu_tempClkPin , &mcu_tempDataReadPin);
|
|
tm1650_displaySwitch(TM_1650_Screen_OFF);
|
|
vMCAL_DelayTicks(500);
|
|
tm1650_showDot(TM_1650_DIG_1,false);
|
|
tm1650_showDot(TM_1650_DIG_2,false);
|
|
tm1650_showDot(TM_1650_DIG_3,false);
|
|
socTouchDisplay_initialize();
|
|
}
|
|
|
|
void vRTE_MatlabRun(void)
|
|
{
|
|
socTouchDisplay_U.in_bTouchDetected = (u32MCAL_gpioRead(GPIOB, DL_GPIO_PIN_17) == DL_GPIO_PIN_17) ? 1 : 0;
|
|
socTouchDisplay_U.ip_u32DisplayDuration_msec = 2000;
|
|
socTouchDisplay_U.ip_u32TouchDuration_msec = 100;
|
|
|
|
socTouchDisplay_step();
|
|
|
|
memset(&socTouchDisplay_U.Input[0], 0, sizeof(CAN_MESSAGE_BUS)*MAX_CAN_MESSAGE_INSTANCE);
|
|
__gprv_u8Idx = 0;
|
|
|
|
if( socTouchDisplay_Y.op_bDisplayStatus )
|
|
{
|
|
tm1650_displaySwitch(TM_1650_Screen_ON);
|
|
tm1650_showDot(TM_1650_DIG_1,false);
|
|
tm1650_showDot(TM_1650_DIG_2,false);
|
|
// tm1650_showDot(TM_1650_DIG_3,false);
|
|
|
|
tm1650_showNum(TM_1650_DIG_3, socTouchDisplay_Y.op_u8OnesPlace);
|
|
tm1650_showNum(TM_1650_DIG_2, socTouchDisplay_Y.op_u8TensPlace);
|
|
// tm1650_showNum(TM_1650_DIG_1, socTouchDisplay_Y.op_u8HundredsPlace);
|
|
}
|
|
if( socTouchDisplay_Y.op_bErrorStatus )
|
|
{
|
|
tm1650_displaySwitch(TM_1650_Screen_ON);
|
|
tm1650_showDot(TM_1650_DIG_1,false);
|
|
tm1650_showDot(TM_1650_DIG_2,false);
|
|
// tm1650_showDot(TM_1650_DIG_3,false);
|
|
|
|
char l_cData = 'R';
|
|
l_cData = 'C';
|
|
tm1650_showAlphabet(TM_1650_DIG_2, (char*)&l_cData);
|
|
l_cData = 'E';
|
|
tm1650_showAlphabet(TM_1650_DIG_3, (char*)&l_cData);
|
|
}
|
|
if( !socTouchDisplay_Y.op_bDisplayStatus && !socTouchDisplay_Y.op_bErrorStatus )
|
|
{
|
|
tm1650_displaySwitch(TM_1650_Screen_OFF);
|
|
}
|
|
|
|
}
|
|
|
|
void vRTE_InitUARTCANEcho(void)
|
|
{
|
|
g_u32UartSpeed = mcalUART_BAUD_115200;
|
|
g_u16CanSpeed = BAUD_500;
|
|
xECU_UARTInit(&g_xUartHandle, g_u32UartSpeed);
|
|
xECU_CANInit(CANFD0,g_u16CanSpeed);
|
|
}
|
|
|
|
void vRTE_UARTDataProcess(void)
|
|
{
|
|
PacketRetCode_t retCode = PACKET_FAIL;
|
|
uint8_t pucBuf[MAX_PACKET_LENGTH] = {0};
|
|
uint32_t ulId = 0xffffffff;
|
|
|
|
retCode= xECU_ReadCANDataOverUART(&g_xUartHandle,pucBuf,&ulId);
|
|
if(retCode > -1)
|
|
{
|
|
if(ulId == 0x00)
|
|
{
|
|
//vECU_InitiateUartToCanTransmit(&g_xUartHandle, ulId, pucBuf, 0);
|
|
|
|
uint32_t baudrate = 0;
|
|
uint8_t mode = pucBuf[PKT_HEADER];
|
|
memcpy(&baudrate, &pucBuf[PKT_HEADER+1], (uint32_t)retCode);
|
|
vECU_InitiateUartToCanTransmit(&g_xUartHandle, ulId, pucBuf, 0);
|
|
if( mode == 0 )
|
|
{
|
|
g_u32UartSpeed = baudrate;
|
|
xECU_UARTReInit(&g_xUartHandle, g_u32UartSpeed);
|
|
}
|
|
else if( mode == 1 )
|
|
{
|
|
g_u16CanSpeed = (uint16_t)baudrate;
|
|
xECU_CanReInit(CANFD0, g_u16CanSpeed);
|
|
}
|
|
}
|
|
else{
|
|
xECU_WriteDataOverCAN(pucBuf, ulId, retCode, 0);
|
|
}
|
|
}
|
|
|
|
}
|
|
void vRTE_CANDataProcess(void)
|
|
{
|
|
IVEC_EcuCommonErr_e retCode = commonECU_FAIL;
|
|
can_buff_t xBuff = { 0x00 };
|
|
|
|
|
|
retCode = xECU_CANGetData(&xBuff);
|
|
if(retCode == commonECU_SUCCESS)
|
|
{
|
|
vECU_InitiateUartToCanTransmit(&g_xUartHandle, (uint32_t)xBuff.id, (uint8_t*)&xBuff.data[0], (uint8_t)xBuff.length);
|
|
socTouchDisplay_U.Input[__gprv_u8Idx].ID = xBuff.id;
|
|
socTouchDisplay_U.Input[__gprv_u8Idx].Length = xBuff.length;
|
|
memcpy(&socTouchDisplay_U.Input[__gprv_u8Idx].Data[0], &xBuff.data[0], 8);
|
|
__gprv_u8Idx = (__gprv_u8Idx + 1) % MAX_CAN_MESSAGE_INSTANCE;
|
|
}
|
|
}
|