diff --git a/Generated Codes/ti_msp_dl_config.c b/Generated Codes/ti_msp_dl_config.c index 0370faf..0b0cdbc 100644 --- a/Generated Codes/ti_msp_dl_config.c +++ b/Generated Codes/ti_msp_dl_config.c @@ -162,6 +162,13 @@ SYSCONFIG_WEAK void SYSCFG_DL_GPIO_init(void) DL_GPIO_initPeripheralInputFunction( GPIO_MCAN0_IOMUX_CAN_RX, GPIO_MCAN0_IOMUX_CAN_RX_FUNC); + DL_GPIO_initDigitalInput(GPIO_GRP_0_soc_IOMUX); + + +// DL_GPIO_initDigitalInputFeatures(GPIO_GRP_0_soc_IOMUX, +// DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_PULL_DOWN, +// DL_GPIO_INVERSION_DISABLE, DL_GPIO_WAKEUP_DISABLE); + // DL_GPIO_initDigitalOutput(IOMUX_PINCM31); // // DL_GPIO_clearPins(GPIOB, tick_PIN_0_PIN); diff --git a/Generated Codes/ti_msp_dl_config.h b/Generated Codes/ti_msp_dl_config.h index 1a0e4d4..2caa1dc 100644 --- a/Generated Codes/ti_msp_dl_config.h +++ b/Generated Codes/ti_msp_dl_config.h @@ -92,6 +92,10 @@ extern "C" { #define GPIO_CAPTURE_0_C0_IOMUX (IOMUX_PINCM21) #define GPIO_CAPTURE_0_C0_IOMUX_FUNC IOMUX_PINCM21_PF_TIMA1_CCP0 +/* Defines for soc: GPIOB.17 with pinCMx 43 on package pin 36 */ +#define GPIO_GRP_0_soc_PIN (DL_GPIO_PIN_17) +#define GPIO_GRP_0_soc_IOMUX (IOMUX_PINCM43) + diff --git a/ivec_RTE/src/ivec_rte.c b/ivec_RTE/src/ivec_rte.c index 3b361af..38f5bf0 100644 --- a/ivec_RTE/src/ivec_rte.c +++ b/ivec_RTE/src/ivec_rte.c @@ -61,6 +61,10 @@ uint32_t g_prv_u32CanUartDataAvailable = 0; #define eteCAN_UART_Cc_BUFFER_MAX_SIZE_u32 4096 volatile uint8_t __gprv_u8CcUartDataBuffer[eteCAN_UART_Cc_BUFFER_MAX_SIZE_u32]; +uint8_t g_u8SmdReceived = 0; +IVEC_EcuCommonCanFrame_s g_xSmdCanMsg = {0}; +int32_t g_u32LastSendTick = 0; // Last time we sent over CAN/UART + /** * @brief Sets the state of the MCU temperature data pin (SDA) for TM1650. * @@ -474,6 +478,11 @@ void vRTE_CanFilterSaveVal(uint8_t u8Idx, uint32_t u32Filter, bool bl_bIsExtende g_xCanHandle.u32FilterValues[g_xCanHandle.i32FilterCount] = u32Filter; } + +//IVEC_EcuCommonCanFrame_s g_xSmdCanMsg = {0}; // Global message buffer +//uint8_t g_u8SmdReceived = 0; +uint32_t g_u32LastSmdTick = 0; + void vCcUartRxToCanTx(IVEC_EcuCommonCanFrame_s* pxCanMsg) { if( (pxCanMsg->u32CanId == 0x16) && (pxCanMsg->pucCanData[0] == 'V') && \ @@ -562,14 +571,98 @@ void vCcUartRxToCanTx(IVEC_EcuCommonCanFrame_s* pxCanMsg) { pxCanMsg->u32CanId = g_u32CanId; } - xECU_WriteDataOverCAN(&g_xCanHandle, &pxCanMsg->pucCanData[0], pxCanMsg->u32CanId, pxCanMsg->ucCanDlc, 0); + if (pxCanMsg->u32CanId == 0x696972) + { + g_xSmdCanMsg = *pxCanMsg; // Store the latest data + g_u8SmdReceived = 1; // Flag to indicate data is fresh + + // Add touch info + uint32_t l_u32TouchDetect = DL_GPIO_readPins(GPIOB, GPIO_GRP_0_soc_PIN); + if (g_xSmdCanMsg.pucCanData[0] == 0) + { + g_xSmdCanMsg.pucCanData[0] = 0x2; + } + + g_xSmdCanMsg.pucCanData[1] = (uint8_t)((l_u32TouchDetect >> 17) & 0x1); + } +// if(pxCanMsg->u32CanId == 0x696972) +// { +// g_u8SmdReceived = 1; +// IVEC_EcuCommonCanFrame_s xMyCanMsg; +// +// g_u32LastSmdTick = i32MCAL_getTicks(); // Store time of last valid message +// +//// // Copy entire struct in one line +//// g_xSmdCanMsg = *pxCanMsg; +// +// uint32_t l_u32TouchDetect = DL_GPIO_readPins(GPIOB, GPIO_GRP_0_soc_PIN); +// if(pxCanMsg->pucCanData[0] == 0) +// { +// pxCanMsg->pucCanData[0] = 0x2; +// } +// +// pxCanMsg->pucCanData[1] = (uint8_t)((l_u32TouchDetect >> 17) & 0x1); +// +// // Send immediately +// iECU_UartInitiateTransmit(&g_xUartHandle, (uint32_t)pxCanMsg->u32CanId,(uint8_t*)&pxCanMsg->pucCanData[0],(uint8_t)pxCanMsg->ucCanDlc); +// } + + if(pxCanMsg->u32CanId != 0x696972) + xECU_WriteDataOverCAN(&g_xCanHandle, &pxCanMsg->pucCanData[0], pxCanMsg->u32CanId, pxCanMsg->ucCanDlc, 0); } } } + void vRTE_CcUartRxProcess(void) { static int __prv_i32BfrIdx = 0; g_prv_u32CanUartDataAvailable = xECU_data_length(&__gprv_UartCcHandle); +// +// uint32_t u32CurrentTick = i32MCAL_getTicks(); +// +// // If no message in last 5 sec +// if ((u32CurrentTick - g_u32LastSmdTick) >= 5000) +// { +// uint32_t l_u32TouchDetect = DL_GPIO_readPins(GPIOB, GPIO_GRP_0_soc_PIN); +// +// IVEC_EcuCommonCanFrame_s g_xSmdCanMsg = {0}; +// g_xSmdCanMsg.u32CanId = 0x696972; +// g_xSmdCanMsg.ucCanDlc = 8; +// g_xSmdCanMsg.pucCanData[0] = 0; +// g_xSmdCanMsg.pucCanData[1] = (uint8_t)((l_u32TouchDetect >> 17) & 0x1); +// iECU_UartInitiateTransmit(&g_xUartHandle, (uint32_t)g_xSmdCanMsg.u32CanId,(uint8_t*)&g_xSmdCanMsg.pucCanData[0],(uint8_t)g_xSmdCanMsg.ucCanDlc); +// xECU_WriteDataOverCAN(&g_xCanHandle, &g_xSmdCanMsg.pucCanData[0], g_xSmdCanMsg.u32CanId, g_xSmdCanMsg.ucCanDlc, 0); +// +// g_u32LastSmdTick = u32CurrentTick; +// } + + uint32_t u32CurrentTick = i32MCAL_getTicks(); + + if ((u32CurrentTick - g_u32LastSendTick) >= 5000) + { + IVEC_EcuCommonCanFrame_s xMsgToSend = {0}; + + if (g_u8SmdReceived == 1) + { + xMsgToSend = g_xSmdCanMsg; + g_u8SmdReceived = 0; // Reset flag after sending + } + else + { + xMsgToSend.u32CanId = 0x696972; + xMsgToSend.ucCanDlc = 8; + xMsgToSend.pucCanData[0] = 0; + + uint32_t l_u32TouchDetect = DL_GPIO_readPins(GPIOB, GPIO_GRP_0_soc_PIN); + xMsgToSend.pucCanData[1] = (uint8_t)((l_u32TouchDetect >> 17) & 0x1); + } + + iECU_UartInitiateTransmit(&g_xUartHandle, xMsgToSend.u32CanId, xMsgToSend.pucCanData, xMsgToSend.ucCanDlc); + xECU_WriteDataOverCAN(&g_xCanHandle, xMsgToSend.pucCanData, xMsgToSend.u32CanId, xMsgToSend.ucCanDlc, 0); + + g_u32LastSendTick = u32CurrentTick; // Update last send time + } + int l_u32AvailableData = g_prv_u32CanUartDataAvailable > (CAN_UART_BUFFER_MAX_SIZE - __prv_i32BfrIdx) ? (CAN_UART_BUFFER_MAX_SIZE - __prv_i32BfrIdx) : g_prv_u32CanUartDataAvailable; if ((l_u32AvailableData <= 10 && g_prv_u32CanUartDataAvailable > 10)|| (__prv_i32BfrIdx+l_u32AvailableData)>=CAN_UART_BUFFER_MAX_SIZE) diff --git a/mspm0g3507.lds b/mspm0g3507.lds index ccb3787..97562bf 100644 --- a/mspm0g3507.lds +++ b/mspm0g3507.lds @@ -7,7 +7,7 @@ _Min_Stack_Size = 0x000012E8; /* required amount of stack */ /* Specify the memory areas */ MEMORY { - FLASH (RX) : ORIGIN = 0x00008000, LENGTH = 0x00018000 + FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x00020000 SRAM (RWX) : ORIGIN = 0x20200000, LENGTH = 0x00008000 BCR_CONFIG (R) : ORIGIN = 0x41C00000, LENGTH = 0x00000080 BSL_CONFIG (R) : ORIGIN = 0x41C00100, LENGTH = 0x00000080 @@ -33,7 +33,7 @@ SECTIONS { /* section for the interrupt vector area */ PROVIDE (_intvecs_base_address = - DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x00008000); + DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x00000000); .intvecs (_intvecs_base_address) : AT (_intvecs_base_address) { KEEP (*(.intvecs))