diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index e37e7c6..8ea1ea4 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -114,6 +114,60 @@ encoding//Debug/ivec_ESDK/ivec_esdk_nfc_pn532/src/subdir_rules.mk=UTF-8 encoding//Debug/ivec_ESDK/ivec_esdk_nfc_pn532/src/subdir_vars.mk=UTF-8 encoding//Debug/ivec_RTE/src/subdir_rules.mk=UTF-8 encoding//Debug/ivec_RTE/src/subdir_vars.mk=UTF-8 +encoding//Debug/ivec_cmplx_vframe/src/subdir_rules.mk=UTF-8 +encoding//Debug/ivec_cmplx_vframe/src/subdir_vars.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0c110x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0c110x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0g1x0x_g3x0x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0g1x0x_g3x0x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0gx51x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0gx51x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0l111x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0l111x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0l11xx_l13xx/subdir_rules.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0l11xx_l13xx/subdir_vars.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0l122x_l222x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/gcc/m0p/mspm0l122x_l222x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0c110x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0c110x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0g1x0x_g3x0x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0g1x0x_g3x0x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0gx51x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0gx51x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0l111x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0l111x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0l11xx_l13xx/subdir_rules.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0l11xx_l13xx/subdir_vars.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0l122x_l222x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/iar/m0p/mspm0l122x_l222x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0c110x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0c110x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0g1x0x_g3x0x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0g1x0x_g3x0x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0gx51x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0gx51x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0l111x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0l111x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0l11xx_l13xx/subdir_rules.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0l11xx_l13xx/subdir_vars.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0l122x_l222x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/keil/m0p/mspm0l122x_l222x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0c110x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0c110x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0g1x0x_g3x0x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0g1x0x_g3x0x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0gx51x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0gx51x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0l111x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0l111x/subdir_vars.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0l11xx_l13xx/subdir_rules.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0l11xx_l13xx/subdir_vars.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0l122x_l222x/subdir_rules.mk=UTF-8 +encoding//Debug/lib/ticlang/m0p/mspm0l122x_l222x/subdir_vars.mk=UTF-8 +encoding//Debug/m0p/subdir_rules.mk=UTF-8 +encoding//Debug/m0p/subdir_vars.mk=UTF-8 +encoding//Debug/m0p/sysctl/subdir_rules.mk=UTF-8 +encoding//Debug/m0p/sysctl/subdir_vars.mk=UTF-8 encoding//Debug/makefile=UTF-8 encoding//Debug/objects.mk=UTF-8 encoding//Debug/sources.mk=UTF-8 @@ -127,48 +181,64 @@ encoding//Test__GNU/Generated\ Codes/subdir_rules.mk=UTF-8 encoding//Test__GNU/Generated\ Codes/subdir_vars.mk=UTF-8 encoding//Test__GNU/TM1650_SDK/src/subdir_rules.mk=UTF-8 encoding//Test__GNU/TM1650_SDK/src/subdir_vars.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0c1105_c1106/subdir_rules.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0c1105_c1106/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0c110x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0c110x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0g1x0x_g3x0x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0g1x0x_g3x0x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0gx51x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0gx51x/subdir_vars.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0h321x/subdir_rules.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0h321x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0l111x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0l111x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0l11xx_l13xx/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0l11xx_l13xx/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0l122x_l222x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/gcc/m0p/mspm0l122x_l222x/subdir_vars.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0c1105_c1106/subdir_rules.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0c1105_c1106/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0c110x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0c110x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0g1x0x_g3x0x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0g1x0x_g3x0x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0gx51x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0gx51x/subdir_vars.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0h321x/subdir_rules.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0h321x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0l111x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0l111x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0l11xx_l13xx/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0l11xx_l13xx/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0l122x_l222x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/iar/m0p/mspm0l122x_l222x/subdir_vars.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0c1105_c1106/subdir_rules.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0c1105_c1106/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0c110x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0c110x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0g1x0x_g3x0x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0g1x0x_g3x0x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0gx51x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0gx51x/subdir_vars.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0h321x/subdir_rules.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0h321x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0l111x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0l111x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0l11xx_l13xx/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0l11xx_l13xx/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0l122x_l222x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/keil/m0p/mspm0l122x_l222x/subdir_vars.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0c1105_c1106/subdir_rules.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0c1105_c1106/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0c110x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0c110x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0g1x0x_g3x0x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0g1x0x_g3x0x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0gx51x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0gx51x/subdir_vars.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0h321x/subdir_rules.mk=UTF-8 +encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0h321x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0l111x/subdir_rules.mk=UTF-8 encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0l111x/subdir_vars.mk=UTF-8 encoding//Test__GNU/driverlib/lib/ticlang/m0p/mspm0l11xx_l13xx/subdir_rules.mk=UTF-8 @@ -201,6 +271,8 @@ encoding//Test__GNU/ivec_ESDK/ivec_esdk_nfc_pn532/src/subdir_rules.mk=UTF-8 encoding//Test__GNU/ivec_ESDK/ivec_esdk_nfc_pn532/src/subdir_vars.mk=UTF-8 encoding//Test__GNU/ivec_RTE/src/subdir_rules.mk=UTF-8 encoding//Test__GNU/ivec_RTE/src/subdir_vars.mk=UTF-8 +encoding//Test__GNU/ivec_cmplx_vframe/src/subdir_rules.mk=UTF-8 +encoding//Test__GNU/ivec_cmplx_vframe/src/subdir_vars.mk=UTF-8 encoding//Test__GNU/lib/gcc/m0p/mspm0c110x/subdir_rules.mk=UTF-8 encoding//Test__GNU/lib/gcc/m0p/mspm0c110x/subdir_vars.mk=UTF-8 encoding//Test__GNU/lib/gcc/m0p/mspm0g1x0x_g3x0x/subdir_rules.mk=UTF-8 diff --git a/Core/Include/ivec_mcal_uart.h b/Core/Include/ivec_mcal_uart.h index dc9b645..83c2e3b 100644 --- a/Core/Include/ivec_mcal_uart.h +++ b/Core/Include/ivec_mcal_uart.h @@ -55,6 +55,7 @@ typedef enum{ IVEC_MCAL_UART_PORT_1=0, IVEC_MCAL_UART_PORT_2, IVEC_MCAL_UART_PORT_3, + IVEC_MCAL_UART_PORT_4, IVEC_MCAL_UART_PORT_MAX }IVEC_McalUartPort_e; diff --git a/Core/Include/ivec_mcal_wdt.h b/Core/Include/ivec_mcal_wdt.h new file mode 100644 index 0000000..bca3676 --- /dev/null +++ b/Core/Include/ivec_mcal_wdt.h @@ -0,0 +1,12 @@ +#ifndef CORE_INCLUDE_IVEC_MCAL_WDT_H_ +#define CORE_INCLUDE_IVEC_MCAL_WDT_H_ + +#include "../utils/utils.h" + +IVEC_McalStatus_e xMCAL_WatchdogInit(MCAL_WWDT_TIMER timer); + +IVEC_McalStatus_e xMCAL_WatchdogDeInit(void); + +IVEC_McalStatus_e xMCAL_WatchdogReset(void); + +#endif /* CORE_INCLUDE_IVEC_MCAL_WDT_H_ */ diff --git a/Core/Source/ivec_mcal_mcan.c b/Core/Source/ivec_mcal_mcan.c index 0f19a44..8bba39d 100644 --- a/Core/Source/ivec_mcal_mcan.c +++ b/Core/Source/ivec_mcal_mcan.c @@ -676,9 +676,13 @@ IVEC_McalCommonErr_e xMCAL_MCANGetErrorStatus(IVEC_McalCanHandle_s* pxCanHandle, DL_MCAN_getErrCounters(CANFD0, &l_xCounter); /* Return the status based on various error conditions */ - + if((g_xHeaderStat.lastErrCode == DL_MCAN_ERR_CODE_ACK_ERROR) || (g_xHeaderStat.busOffStatus)) + DL_MCAN_setOpMode(CANFD0, DL_MCAN_OPERATION_MODE_NORMAL); + return commonMCAL_SUCCESS; + /* return ( (g_xHeaderStat.lastErrCode == DL_MCAN_ERR_CODE_ACK_ERROR) || \ - (g_xHeaderStat.busOffStatus) ) ? IVEC_MCAL_STATUS_ERROR : IVEC_MCAL_STATUS_SUCCESS; + (g_xHeaderStat.busOffStatus) ) ? commonMCAL_FAIL : commonMCAL_SUCCESS; + */ } diff --git a/Core/Source/ivec_mcal_uart.c b/Core/Source/ivec_mcal_uart.c index 2f5ea79..43f62b2 100644 --- a/Core/Source/ivec_mcal_uart.c +++ b/Core/Source/ivec_mcal_uart.c @@ -139,6 +139,11 @@ void UART2_IRQHandler() prv_vRxCallback(UART2, DL_UART_Main_getPendingInterrupt(UART2)); } +void UART3_IRQHandler() +{ + prv_vRxCallback(UART3, DL_UART_Main_getPendingInterrupt(UART3)); +} + /** * @brief Retrieves the UART instance for the specified port number. * @@ -158,6 +163,8 @@ static UART_Regs* __prv_McalGetUartInstance(IVEC_McalUartPort_e eUartPortNumber) return UART1; case IVEC_MCAL_UART_PORT_3: return UART2; + case IVEC_MCAL_UART_PORT_4: + return UART3; default: return NULL; // Invalid UART port } @@ -183,6 +190,8 @@ static IVEC_McalUartPort_e __prv_McalGetUartPort(UART_Regs* pxUartInstance) return IVEC_MCAL_UART_PORT_2; case (uint32_t)UART2: return IVEC_MCAL_UART_PORT_3; + case (uint32_t)UART3: + return IVEC_MCAL_UART_PORT_4; default: return IVEC_MCAL_UART_PORT_MAX; // Invalid UART port } @@ -242,7 +251,12 @@ static IVEC_McalCommonErr_e _prvMCAL_UartDeInitInstance(IVEC_McalUartHandle_s* p NVIC_ClearPendingIRQ(UART2_INT_IRQn); // Reset the UART2 init flag if needed (b_UART2_init_flag = 0) } - + else if (pxUartInstance == UART3) + { + NVIC_DisableIRQ(UART3_INT_IRQn); + NVIC_ClearPendingIRQ(UART3_INT_IRQn); + // Reset the UART2 init flag if needed (b_UART2_init_flag = 0) + } // Optionally, reset the UART clock configuration if needed DL_UART_Main_setClockConfig(pxUartInstance, NULL); @@ -528,6 +542,15 @@ static IVEC_McalCommonErr_e __prv_McalUartInitInstance(IVEC_McalUartHandle_s* px DL_UART_Main_enablePower(UART2); DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM32, IOMUX_PINCM32_PF_UART2_TX); DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM33, IOMUX_PINCM33_PF_UART2_RX); + + } + else if (pxUartHandle->eUartPortNumber == IVEC_MCAL_UART_PORT_4) + { + DL_UART_Main_reset(UART3); + DL_UART_Main_enablePower(UART3); + DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM36, IOMUX_PINCM36_PF_UART3_TX); + DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM35, IOMUX_PINCM35_PF_UART3_RX); + } UART_Regs* pxUartInstance = __prv_McalGetUartInstance(pxUartHandle->eUartPortNumber); @@ -579,7 +602,14 @@ static IVEC_McalCommonErr_e __prv_McalUartInitInstance(IVEC_McalUartHandle_s* px DL_UART_ClockConfig xUartClockConfig = { 0 }; xUartClockConfig.clockSel = DL_UART_CLOCK_BUSCLK; - xUartClockConfig.divideRatio = DL_UART_MAIN_CLOCK_DIVIDE_RATIO_1; + if(pxUartHandle->eUartPortNumber == IVEC_MCAL_UART_PORT_4) + { + xUartClockConfig.divideRatio = DL_UART_MAIN_CLOCK_DIVIDE_RATIO_2; + } + else + { + xUartClockConfig.divideRatio = DL_UART_MAIN_CLOCK_DIVIDE_RATIO_1; + } DL_UART_Main_setClockConfig(pxUartInstance, (DL_UART_Main_ClockConfig*) &xUartClockConfig); DL_UART_Main_init(pxUartInstance, (DL_UART_Main_Config*) &xUartConfig); @@ -705,6 +735,26 @@ static IVEC_McalCommonErr_e __prv_McalUartInitInstance(IVEC_McalUartHandle_s* px NVIC_ClearPendingIRQ(UART2_INT_IRQn); NVIC_EnableIRQ(UART2_INT_IRQn); } + else if (pxUartInstance == UART3) + { + DL_UART_Main_enableInterrupt(pxUartInstance, + DL_UART_MAIN_INTERRUPT_BREAK_ERROR | + DL_UART_MAIN_INTERRUPT_FRAMING_ERROR | + DL_UART_MAIN_INTERRUPT_NOISE_ERROR | + DL_UART_MAIN_INTERRUPT_OVERRUN_ERROR | + DL_UART_MAIN_INTERRUPT_PARITY_ERROR | + DL_UART_MAIN_INTERRUPT_RX | + DL_UART_MAIN_INTERRUPT_RX_TIMEOUT_ERROR); + + DL_UART_Main_enableFIFOs(UART3); + DL_UART_Main_setRXFIFOThreshold(UART3, DL_UART_RX_FIFO_LEVEL_ONE_ENTRY); + DL_UART_Main_setTXFIFOThreshold(UART3, DL_UART_TX_FIFO_LEVEL_1_2_EMPTY); + + DL_UART_Main_enable(pxUartInstance); + NVIC_ClearPendingIRQ(UART3_INT_IRQn); + NVIC_EnableIRQ(UART3_INT_IRQn); + } + return commonMCAL_SUCCESS; } diff --git a/Core/Source/ivec_mcal_wdt.c b/Core/Source/ivec_mcal_wdt.c new file mode 100644 index 0000000..38bfbc1 --- /dev/null +++ b/Core/Source/ivec_mcal_wdt.c @@ -0,0 +1,133 @@ +#include "ivec_mcal_wdt.h" + +static volatile bool b_WDInitFlag; + + +IVEC_McalStatus_e xMCAL_WatchdogInit(MCAL_WWDT_TIMER timer) +{ + DL_WWDT_CLOCK_DIVIDE Clk_Div; + DL_WWDT_TIMER_PERIOD Tmr_Per; + + assert(WATCHDOG_TIMER != NULL); + + switch(timer) + { + case MCAL_WDT_1_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_1; + Tmr_Per = DL_WWDT_TIMER_PERIOD_15_BITS; + break; + case MCAL_WDT_2_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_2; + Tmr_Per = DL_WWDT_TIMER_PERIOD_15_BITS; + break; + case MCAL_WDT_3_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_3; + Tmr_Per = DL_WWDT_TIMER_PERIOD_15_BITS; + break; + case MCAL_WDT_4_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_4; + Tmr_Per = DL_WWDT_TIMER_PERIOD_15_BITS; + break; + case MCAL_WDT_5_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_5; + Tmr_Per = DL_WWDT_TIMER_PERIOD_15_BITS; + break; + case MCAL_WDT_6_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_6; + Tmr_Per = DL_WWDT_TIMER_PERIOD_15_BITS; + break; + case MCAL_WDT_7_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_7; + Tmr_Per = DL_WWDT_TIMER_PERIOD_15_BITS; + break; + case MCAL_WDT_8_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_8; + Tmr_Per = DL_WWDT_TIMER_PERIOD_15_BITS; + break; + case MCAL_WDT_16_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_2; + Tmr_Per = DL_WWDT_TIMER_PERIOD_18_BITS; + break; + case MCAL_WDT_24_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_3; + Tmr_Per = DL_WWDT_TIMER_PERIOD_18_BITS; + break; + case MCAL_WDT_32_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_4; + Tmr_Per = DL_WWDT_TIMER_PERIOD_18_BITS; + break; + case MCAL_WDT_40_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_5; + Tmr_Per = DL_WWDT_TIMER_PERIOD_18_BITS; + break; + case MCAL_WDT_48_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_6; + Tmr_Per = DL_WWDT_TIMER_PERIOD_18_BITS; + break; + case MCAL_WDT_56_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_7; + Tmr_Per = DL_WWDT_TIMER_PERIOD_18_BITS; + break; + case MCAL_WDT_64_SEC_TIMER: + Clk_Div = DL_WWDT_CLOCK_DIVIDE_8; + Tmr_Per = DL_WWDT_TIMER_PERIOD_18_BITS; + break; + default: return IVEC_MCAL_STATUS_INIT_FAIL; + } + if(b_WDInitFlag == false) + { + /* Set Window0 as active window */ + DL_WWDT_setActiveWindow(WATCHDOG_TIMER, DL_WWDT_WINDOW0); + + DL_WWDT_initWatchdogMode(WATCHDOG_TIMER, Clk_Div,Tmr_Per, DL_WWDT_RUN_IN_SLEEP, DL_WWDT_WINDOW_PERIOD_0, DL_WWDT_WINDOW_PERIOD_0); // DL_WWDT_WINDOW_PERIOD_0 is for selecting the closed percentage of the watchdog + if(DL_WWDT_isPowerEnabled(WATCHDOG_TIMER)) + { + while ((DL_SYSCTL_getClockStatus() & (DL_SYSCTL_CLK_STATUS_LFOSC_GOOD))!= (DL_SYSCTL_CLK_STATUS_LFOSC_GOOD)); + } + else + { + + return IVEC_MCAL_STATUS_TIMEOUT; + } + b_WDInitFlag = true; + + return IVEC_MCAL_STATUS_SUCCESS; + } + else + { + return IVEC_MCAL_STATUS_INIT_FAIL; + } +} + +IVEC_McalStatus_e xMCAL_WatchdogDeInit(void) +{ + assert(WATCHDOG_TIMER != NULL); + + if(b_WDInitFlag == true) + { + DL_WWDT_disablePower(WATCHDOG_TIMER); + + b_WDInitFlag = false; + + return IVEC_MCAL_STATUS_SUCCESS; + } + else + { + return IVEC_MCAL_STATUS_INIT_FAIL; + } +} + + +IVEC_McalStatus_e xMCAL_WatchdogReset(void) +{ + if(DL_WWDT_isRunning(WATCHDOG_TIMER) == true) + { + DL_WWDT_restart(WATCHDOG_TIMER); + + return IVEC_MCAL_STATUS_SUCCESS; + } + else + { + return IVEC_MCAL_STATUS_ERROR; + } +} 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_ECU/ivec_ecu_can/src/ivec_ecu_can.c b/ivec_ECU/ivec_ecu_can/src/ivec_ecu_can.c index 2cab220..b76328f 100644 --- a/ivec_ECU/ivec_ecu_can/src/ivec_ecu_can.c +++ b/ivec_ECU/ivec_ecu_can/src/ivec_ecu_can.c @@ -286,7 +286,7 @@ IVEC_EcuCommonErr_e xECU_CANGetStatus(IVEC_EcuCANHandle_s *xCanHandle) IVEC_EcuCommonErr_e l_eFuncStatus = commonECU_SUCCESS; if (xCanHandle->__xCanHandle.__u8Init == 0) { - l_eFuncStatus = commonMCAL_FAIL; + l_eFuncStatus = commonECU_FAIL; return l_eFuncStatus; } int8_t l_i8ErrorString[32] = {0}; @@ -295,7 +295,8 @@ IVEC_EcuCommonErr_e xECU_CANGetStatus(IVEC_EcuCANHandle_s *xCanHandle) if (xMCAL_MCANGetErrorStatus(&xCanHandle->__xCanHandle, l_i8ErrorString) == commonMCAL_FAIL) { /* Reinitialize CAN if an error is detected */ - l_eFuncStatus = xECU_CANReInit(xCanHandle); + //l_eFuncStatus = xECU_CANReInit(xCanHandle); + l_eFuncStatus = commonECU_FAIL; } return l_eFuncStatus; } diff --git a/ivec_ECU/ivec_ecu_uart/inc/ivec_ecu_uart.h b/ivec_ECU/ivec_ecu_uart/inc/ivec_ecu_uart.h index 17f3a17..0625cd2 100644 --- a/ivec_ECU/ivec_ecu_uart/inc/ivec_ecu_uart.h +++ b/ivec_ECU/ivec_ecu_uart/inc/ivec_ecu_uart.h @@ -55,6 +55,7 @@ typedef enum IVEC_ECU_UART_PORT1 = 0, IVEC_ECU_UART_PORT2, IVEC_ECU_UART_PORT3, + IVEC_ECU_UART_PORT4, IVEC_ECU_UART_PORT_MAX } IVEC_ECU_UartPortNumber_e; diff --git a/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c b/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c index 8c39c38..de89eab 100644 --- a/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c +++ b/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c @@ -34,6 +34,10 @@ static void __prv_EcuCanOverUartMsgCallback(IVEC_McalUartPort_e eUartPort, IVEC_ if (eEventType == IVEC_ECU_UART_EVENT_RX_ARRIVED) { u8CMPLX_FifoEnqueue((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[IVEC_ECU_UART_PORT3], pu8Buffer, u32Size); } + case IVEC_MCAL_UART_PORT_4: + if (eEventType == IVEC_ECU_UART_EVENT_RX_ARRIVED) { + u8CMPLX_FifoEnqueue((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[IVEC_ECU_UART_PORT4], pu8Buffer, u32Size); + } break; default: break; @@ -116,6 +120,10 @@ IVEC_EcuCommonErr_e xECU_UartInit(IVEC_EcuUartHandle_s* pxUartHandle) __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].i32TotalElements = pxUartHandle->u16QbufSize; __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].pu8Buffer = pxUartHandle->u8Qbuffer; break; + case IVEC_ECU_UART_PORT4: + __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].i32TotalElements = pxUartHandle->u16QbufSize; + __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].pu8Buffer = pxUartHandle->u8Qbuffer; + break; default: __gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber].pu8Buffer = NULL; break; @@ -555,3 +563,9 @@ int32_t iECU_UartInitiateTransmit(IVEC_EcuUartHandle_s* pxUartHandle, uint32_t u memcpy(&l_u8Buf[ecuUART_PKT_HEADER_u8], pu8Data, u8Len); return (xECU_UartFormatPacket(pxUartHandle, l_u8Buf, u8Len, u32Id) == ecuUART_PACKET_SUCCESS_u8) ? 0 : -1; } + +uint32_t xECU_data_length(IVEC_EcuUartHandle_s* pxUartHandle) +{ + uint32_t length = i32CMPLX_FifoCounts((CmplxFifoQueueHandle_s*)&__gprv_xUartResponseQueue[pxUartHandle->eUartPortNumber]); + return(length); +} diff --git a/ivec_RTE/src/ivec_rte.c b/ivec_RTE/src/ivec_rte.c index 718046d..7bfc70f 100644 --- a/ivec_RTE/src/ivec_rte.c +++ b/ivec_RTE/src/ivec_rte.c @@ -7,6 +7,7 @@ #include "ivec_rte.h" #include "ivec_cmplx_queue.h" +#include "ivec_cmplx_vFrame.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" @@ -18,6 +19,7 @@ // UART Handles IVEC_EcuUartHandle_s g_xUartHandle = {0}; +IVEC_EcuUartHandle_s __gprv_UartCcHandle = {0}; IVEC_EcuCANHandle_s g_xCanHandle = {0}; // Configuration Macros @@ -26,7 +28,7 @@ IVEC_EcuCANHandle_s g_xCanHandle = {0}; #define rteCONFIG_MOTHER_BOARD_u8 3 // UART Configuration -#define rteUART_PIN_SELECTION_u8 rteCONFIG_BASIL_u8 +#define rteUART_PIN_SELECTION_u8 rteCONFIG_BASIL_BATTERY_SMART_u8 uint8_t g_pu8UartBuffer[ecuUART_MAX_PACKET_LENGTH_u8] = {0}; volatile uint32_t g_u32CanId = 0x1FFFFFFF; @@ -50,6 +52,18 @@ static uint8_t __gprv_U8Index = 0; extern ExtU_socTouchDisplay_T socTouchDisplay_U; extern ExtY_socTouchDisplay_T socTouchDisplay_Y; +#define CAN_UART_BUFFER_MAX_SIZE 300 +uint8_t g_prv_u8CANUartDataBuffer[CAN_UART_BUFFER_MAX_SIZE]; +uint32_t g_prv_u32CanUartDataAvailable = 0; + + +// CAN UART Buffer +#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. @@ -127,7 +141,7 @@ static uint8_t _prv_RteReadMcuTempPin(void) { 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*)&vRTE_SetMcuTempDataPin , (void*)&vRTE_McuSetTempClkPin , &_prv_RteReadMcuTempPin); + tm1650_Init(TM_1650_BRIGHT_6, TM_1650_Segment_8, TM_1650_Normal_Mode, TM_1650_Screen_ON, TM_1650_DIG_3, (void*)&vRTE_SetMcuTempDataPin , (void*)&vRTE_McuSetTempClkPin , &_prv_RteReadMcuTempPin); tm1650_displaySwitch(TM_1650_Screen_OFF); vMCAL_delayTicks(500); tm1650_showDot(TM_1650_DIG_1,false); @@ -135,6 +149,17 @@ void vRTE_MatlabInit(void) tm1650_showDot(TM_1650_DIG_3,false); socTouchDisplay_initialize(); } + + +void vRTE_InitUartCc(void) +{ + __gprv_UartCcHandle.u8Qbuffer = __gprv_u8CcUartDataBuffer; + __gprv_UartCcHandle.u16QbufSize = eteCAN_UART_Cc_BUFFER_MAX_SIZE_u32; + __gprv_UartCcHandle.eUartPortNumber = IVEC_ECU_UART_PORT4; + __gprv_UartCcHandle.u32BaudRate = IVEC_ECU_UART_BAUD_230400; + + xECU_UartInit(&__gprv_UartCcHandle); +} /** * @brief Runs the MATLAB interface for MCU and TM1650 during operation. * @@ -219,6 +244,7 @@ void vRTE_AppInit(void) { #if rteUART_PIN_SELECTION_u8 == 1 vRTE_MatlabInit(); + vRTE_InitUartCc(); #endif vRTE_InitUartCanEcho(); @@ -386,6 +412,11 @@ void vRTE_AppRun(void) { vRTE_ProcessUartData(); vRTE_ProcessCanData(); + +#if rteUART_PIN_SELECTION_u8 == 1 + vRTE_CcUartRxProcess(); +#endif + #if rteUART_PIN_SELECTION_u8 == 3 vRTE_UartNfcProcess(); #endif @@ -446,6 +477,266 @@ void vRTE_CanFilterSaveVal(uint8_t u8Idx, uint32_t u32Filter, bool bl_bIsExtende // Store filter value 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') && \ + (pxCanMsg->pucCanData[1] == 'E') && (pxCanMsg->pucCanData[2] == 'C') && \ + (pxCanMsg->pucCanData[3] == 'I') && (pxCanMsg->pucCanData[4]== 'O') && \ + (pxCanMsg->pucCanData[5] == 'T')) + { + uint32_t l_u32Id = 0x36; // ID to pass + uint8_t pu8Data[1] = {0x79}; // Data array containing 0x79 + uint8_t u8Len = sizeof(pu8Data); // Length of data array + int l_i32RetSize = 0; + uint8_t l_u8UartBuffer[30] = { 0 }; + int l_i32Status = -1; + l_i32RetSize = u16CMPLX_vFrameEncode((uint32_t)l_u32Id, (uint8_t*)&pu8Data[1], u8Len, l_u8UartBuffer, 30); + l_i32Status = IVEC_ECUUartWrite(&__gprv_UartCcHandle, l_u8UartBuffer, l_i32RetSize); + vMCAL_WDG_Refresh(); + vMCAL_WatchdogDisablePower(); + vMCAL_softReset(); + } + + if(pxCanMsg->ucCanDlc > 0 && pxCanMsg->u32CanId == 0x00) + { + uint32_t l_u32Baudrate = 0; + uint8_t l_u8Mode = pxCanMsg->pucCanData[0];//g_pu8UartBuffer[ecuUART_PKT_HEADER_u8]; + memcpy(&l_u32Baudrate, &pxCanMsg->pucCanData[1], (uint32_t)pxCanMsg->ucCanDlc); + iECU_UartInitiateTransmit(&g_xUartHandle, 0x01,(uint8_t*)&pxCanMsg->pucCanData[0],0); + if( l_u8Mode == 0 ) + { + __gprv_UartCcHandle.u32BaudRate = l_u32Baudrate; + xECU_UartReinit(&__gprv_UartCcHandle); + } + else if( l_u8Mode == 1 ) + { + g_xCanHandle.u16Speed = (uint16_t)l_u32Baudrate; + xECU_CANReInit(&g_xCanHandle); + } + else if( l_u8Mode == 2 ) + { + + if( pxCanMsg->pucCanData[1] != 0 ){//22(20+2) rx filter available send each id in a frame + uint32_t l_U32FilterId = 0; + memcpy(&l_U32FilterId, &pxCanMsg->pucCanData[3], sizeof(uint32_t)); + bool l_bIsExtended = 0; + l_bIsExtended = (l_U32FilterId > 0x7FF); // Standard IDs are <= 0x7FF + vRTE_CanFilterSaveVal((pxCanMsg->pucCanData[1] - 1), l_U32FilterId, l_bIsExtended); + if( pxCanMsg->pucCanData[2])//All filter received. Trigger Filter Settings + { + xECU_CANReInit(&g_xCanHandle); + } + else + return; + } + else{ + xECU_CANReInit(&g_xCanHandle); + } + } + + else if ( l_u8Mode == 3 ) + { + if( (pxCanMsg->pucCanData[1] < 1) || (pxCanMsg->pucCanData[1] > 8) )//0-7 maximum received pkts + return; + uint32_t l_u32u32MaskId = 0; + memcpy(&l_u32u32MaskId, &pxCanMsg->pucCanData[3], sizeof(uint32_t)); + bool l_bIsExtended = 0; + l_bIsExtended = (l_u32u32MaskId > 0x7FF); // Standard IDs are <= 0x7FF + vRTE_CanFilterMaskSaveVal((pxCanMsg->pucCanData[1] - 1), l_u32u32MaskId, l_bIsExtended); + } + else if (l_u8Mode == 100) + { + g_u32CanId = l_u32Baudrate; + return; + } + + vMCAL_delayTicks(100); + iECU_UartInitiateTransmit(&g_xUartHandle, 0x01,(uint8_t*)&pxCanMsg->pucCanData[0],0); + } + + if(pxCanMsg->u32CanId != 0x00) + { + + if (pxCanMsg->u32CanId == 0x1cea6969) + { + iECU_UartInitiateTransmit(&g_xUartHandle, (uint32_t)pxCanMsg->u32CanId,(uint8_t*)&pxCanMsg->pucCanData[0],(uint8_t)pxCanMsg->ucCanDlc); + } + else + { + if(pxCanMsg->u32CanId == 0xabcdef) + { + pxCanMsg->u32CanId = g_u32CanId; + } + 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) + { +// printf("Data Overflow detected:%d-%d\n", g_prv_u32CanUartDataAvailable, __prv_i32BfrIdx); + __prv_i32BfrIdx = 0; + l_u32AvailableData = 0; + } + if (1) + { + //record uart recv + uint8_t l_u8Goon=0; + if (l_u32AvailableData && xECU_UartGetData(&__gprv_UartCcHandle, &g_prv_u8CANUartDataBuffer[__prv_i32BfrIdx], l_u32AvailableData, 3000) == commonECU_SUCCESS) + l_u8Goon=1; + if(l_u32AvailableData<=0 && __prv_i32BfrIdx>0) + l_u8Goon=1; + + if(l_u8Goon) + { +// g_prv_u32CanUartDataAvailable -= l_u32AvailableData; + __prv_i32BfrIdx += l_u32AvailableData; + uint8_t* l_ucStart = g_prv_u8CANUartDataBuffer; + uint8_t* l_ucFrameStart = NULL; + uint8_t* l_ucFrameEnd = NULL; + IVEC_ECU_LOG(LOG_STRING, "New Data:%d-%d", l_u32AvailableData, __prv_i32BfrIdx); + while (1) + { + // IVEC_ECU_LOG(LOG_STRING, "Current Idx:%d", __prv_i32BfrIdx); + int l_i32Len = __prv_i32BfrIdx; + if (u16CMPLX_vFrameFind(l_ucStart, l_i32Len, &l_ucFrameStart, &l_ucFrameEnd) == 2)//cksum error + { +// xCANhandle->xMyMetrics.u32CANCommFrameErrors++; + } + + if (l_ucFrameStart == NULL) + { + __prv_i32BfrIdx = 0; + break; + } + if (l_ucFrameEnd == NULL) + { + if (memmove(g_prv_u8CANUartDataBuffer, l_ucFrameStart, __prv_i32BfrIdx) != g_prv_u8CANUartDataBuffer) + { + __prv_i32BfrIdx = 0; + IVEC_ECU_LOG(LOG_STRING, "Never Print"); + } + __prv_i32BfrIdx-=(l_ucFrameStart-g_prv_u8CANUartDataBuffer); + if(__prv_i32BfrIdx<0) + __prv_i32BfrIdx=0; + break; + } + IVEC_EcuCommonCanFrame_s l_xCanFrame = { 0 }; + uint8_t l_u8UartFrameLen = l_ucFrameEnd - l_ucFrameStart + 1; + int l_CanDlc=0; + + + u16CMPLX_vFrameDecode(l_ucFrameStart, l_u8UartFrameLen, &l_xCanFrame.pucCanData,8,&l_CanDlc,&l_xCanFrame.u32CanId); + l_xCanFrame.ucCanDlc = l_CanDlc; + + vCcUartRxToCanTx(&l_xCanFrame); + memset(l_ucFrameStart, 0, l_u8UartFrameLen); + l_ucStart = ++l_ucFrameEnd; + __prv_i32BfrIdx -= l_u8UartFrameLen; + if (__prv_i32BfrIdx < 0) + __prv_i32BfrIdx = 0; + } +// printf( "Out Current Idx:%d\n", __prv_i32BfrIdx); + } + } + + +} /** * @brief Processes UART data to manage CAN and UART communication. * @@ -478,7 +769,10 @@ void vRTE_ProcessUartData(void) uint8_t u8Len = sizeof(pu8Data); // Length of data array iECU_UartInitiateTransmit(&g_xUartHandle, u32Id, pu8Data, u8Len); iECU_UartInitiateTransmit(&g_xUartHandle, 0x8, NULL, 0); + vMCAL_WDG_Refresh(); + vMCAL_WatchdogDisablePower(); vMCAL_softReset(); + } if(l_eRetCode > 0 && l_u32Id == 0x00) @@ -542,10 +836,19 @@ void vRTE_ProcessUartData(void) if ( l_eRetCode >= 0 && (l_u32Id > 0x00 && l_u32Id < 0xffffffff) ) { //_prvU8Buffer = (_prvU8Buffer + 1) % 2; + if(l_u32Id == 0x1cecff69) + { + int l_i32RetSize = 0; + uint8_t l_u8UartBuffer[30] = { 0 }; + int l_i32Status = -1; + l_i32RetSize = u16CMPLX_vFrameEncode((uint32_t)l_u32Id, (uint8_t*)&g_pu8UartBuffer[ecuUART_PKT_HEADER_u8], (int32_t)l_eRetCode, l_u8UartBuffer, 30); + l_i32Status = IVEC_ECUUartWrite(&__gprv_UartCcHandle, l_u8UartBuffer, l_i32RetSize); + } xECU_WriteDataOverCAN(&g_xCanHandle, &g_pu8UartBuffer[ecuUART_PKT_HEADER_u8], l_u32Id, l_eRetCode, 0); - } } + vMCAL_WDG_Refresh(); + } /** * @brief Processes CAN data and handles CAN communication. @@ -571,9 +874,26 @@ void vRTE_ProcessCanData(void) (l_xCanBuff.u8Data[3] == 'I') && (l_xCanBuff.u8Data[4] == 'O') && \ (l_xCanBuff.u8Data[5] == 'T')) { + vMCAL_WatchdogDisablePower(); vMCAL_softReset(); } + +#if rteUART_PIN_SELECTION_u8 == 1 + int l_i32RetSize = 0; + uint8_t l_u8UartBuffer[30] = { 0 }; + int l_i32Status = -1; + l_i32RetSize = u16CMPLX_vFrameEncode((uint32_t)l_xCanBuff.u32UlId, (uint8_t*)&l_xCanBuff.u8Data[0], (int32_t)l_xCanBuff.u8Length, l_u8UartBuffer, 30); + if(l_xCanBuff.u32UlId == g_u32CanId) + { + + l_i32RetSize = u16CMPLX_vFrameEncode((uint32_t)0xabcdef, (uint8_t*)&l_xCanBuff.u8Data[0], (int32_t)l_xCanBuff.u8Length, l_u8UartBuffer, 30); + } + + l_i32Status = IVEC_ECUUartWrite(&__gprv_UartCcHandle, l_u8UartBuffer, l_i32RetSize); +#endif + iECU_UartInitiateTransmit(&g_xUartHandle, (uint32_t)l_xCanBuff.u32UlId, (uint8_t*)&l_xCanBuff.u8Data[0], (uint8_t)l_xCanBuff.u8Length); + socTouchDisplay_U.Input[__gprv_U8Index].ID = l_xCanBuff.u32UlId; socTouchDisplay_U.Input[__gprv_U8Index].Length = l_xCanBuff.u8Length; memcpy(&socTouchDisplay_U.Input[__gprv_U8Index].Data[0], &l_xCanBuff.u8Data[0], 8); @@ -584,5 +904,5 @@ void vRTE_ProcessCanData(void) break; } xECU_CANGetStatus(&g_xCanHandle); - + vMCAL_WDG_Refresh(); } diff --git a/ivec_cmplx_vframe/inc/ivec_cmplx_vFrame.h b/ivec_cmplx_vframe/inc/ivec_cmplx_vFrame.h new file mode 100644 index 0000000..4158700 --- /dev/null +++ b/ivec_cmplx_vframe/inc/ivec_cmplx_vFrame.h @@ -0,0 +1,21 @@ +#ifndef IVEC_RTE_INC_IVEC_RTE_H_ +#define IVEC_RTE_INC_IVEC_RTE_H_ + + +#include "ivec_bsw_common.h" +#include "stdint.h" +#include "stdio.h" + +#define IVEC_VFRAME_MIN_LEN 14 +#define IVEC_VFRAME_DLC 2 +#define IVEC_VFRAME_DLC_LEN 2 +#define IVEC_VFRAME_ID 4 +#define IVEC_VFRAME_ID_LEN 4 +#define IVEC_VFRAME_DATA_START 12 +#define IVEC_VFRAME_SYNC_CHAR_0 0xb5 +#define IVEC_VFRAME_SYNC_CHAR_1 0x63 +int u16CMPLX_vFrameFind(uint8_t* pcBuffer, int i32Len, uint8_t** pcFrameStartPt, uint8_t** pcFrameEndPt); +uint16_t u16CMPLX_vFrameDecode( const uint8_t* pInData, int i32InLen, uint8_t* pu8FrameData, int u8FrameBufLen ,int *pi32FrameDlc,uint32_t *pu32Id); +uint16_t u16CMPLX_vFrameEncode(uint32_t u32Id, const uint8_t* pInData, int i32InLen, uint8_t* pu8FrameBuffer, int pu8FrameBufferLen); + +#endif /* IVEC_RTE_INC_IVEC_RTE_H_ */ diff --git a/ivec_cmplx_vframe/src/ivec_cmplx_vFrame.c b/ivec_cmplx_vframe/src/ivec_cmplx_vFrame.c new file mode 100644 index 0000000..f841d3c --- /dev/null +++ b/ivec_cmplx_vframe/src/ivec_cmplx_vFrame.c @@ -0,0 +1,112 @@ +#include "ivec_cmplx_vFrame.h" + +#define LOG_STRING "ivec-cmplx-vframe" + +static void __prv_CalculateChecksum(uint8_t *pkt, int len, uint8_t *ck) +{ + uint8_t mck_a = 0, mck_b = 0; + /*Incremented to ignore Sync data*/ + for (int i = 2; i < len - 2; i++) + { + mck_a += pkt[i]; + mck_b += mck_a; + } + mck_a &= 0xFF; + mck_b &= 0xFF; + ck[0] = mck_a; + ck[1] = mck_b; +} + +uint16_t u16CMPLX_vFrameEncode(uint32_t u32Id, const uint8_t *pInData, int i32InLen, uint8_t *pu8FrameBuffer, int pu8FrameBufferLen) +{ + if (i32InLen > (pu8FrameBufferLen - IVEC_VFRAME_MIN_LEN) || pu8FrameBuffer == NULL) + return 0; + uint16_t u16Dlc = i32InLen; + pu8FrameBuffer[0] = IVEC_VFRAME_SYNC_CHAR_0; + pu8FrameBuffer[1] = IVEC_VFRAME_SYNC_CHAR_1; + + memcpy(&pu8FrameBuffer[IVEC_VFRAME_ID], &u32Id, IVEC_VFRAME_ID_LEN); + + if (pInData) + { + memcpy(&pu8FrameBuffer[IVEC_VFRAME_DATA_START], pInData, u16Dlc); + } + else + { + u16Dlc = 0; + } + memcpy(&pu8FrameBuffer[IVEC_VFRAME_DLC], &u16Dlc, IVEC_VFRAME_DLC_LEN); + __prv_CalculateChecksum(pu8FrameBuffer, u16Dlc + IVEC_VFRAME_MIN_LEN, &pu8FrameBuffer[IVEC_VFRAME_MIN_LEN + u16Dlc - 2]); + return u16Dlc + IVEC_VFRAME_MIN_LEN; +} +uint16_t u16CMPLX_vFrameDecode(const uint8_t *pInData, int i32InLen, uint8_t *pu8FrameData, int i32FrameBufLen, int *pi32FrameDlc, uint32_t *pu32Id) +{ + if (pInData == NULL || i32InLen < IVEC_VFRAME_MIN_LEN) + return 0; + + if (pu32Id) + memcpy(pu32Id, &pInData[IVEC_VFRAME_ID], IVEC_VFRAME_ID_LEN); + + if (pu8FrameData && pi32FrameDlc && i32FrameBufLen > 0) + { + memcpy(pi32FrameDlc, &pInData[IVEC_VFRAME_DLC], IVEC_VFRAME_DLC_LEN); + if (*pi32FrameDlc <= i32FrameBufLen) + memcpy(pu8FrameData, &pInData[IVEC_VFRAME_DATA_START], *pi32FrameDlc); + } + return 1; +} +int u16CMPLX_vFrameFind(uint8_t *pcBuffer, int i32Len, uint8_t **pcFrameStartPt, uint8_t **pcFrameEndPt) +{ + IVEC_BSW_LOG(LOG_STRING, "Scanning Frame : 0x%x-%d", pcBuffer, i32Len); + uint8_t *l_pcFrameStartPt = NULL; + uint8_t *l_pcFrameEndPt = NULL; + int l_i32Ret = 0; + if (pcBuffer == NULL || i32Len <= 0) + goto exit; + + int i32Ijk = 0; + for (; i32Ijk < i32Len; i32Ijk++) + { + if (pcBuffer[i32Ijk] == IVEC_VFRAME_SYNC_CHAR_0) + { + l_pcFrameStartPt = &pcBuffer[i32Ijk]; + // i32Ijk++; + break; + } + } + if (l_pcFrameStartPt == NULL) + goto exit; + int i32RemainingLen = i32Len - i32Ijk; + IVEC_BSW_LOG(LOG_STRING, "Remaining len: %d", i32RemainingLen); + if ((i32RemainingLen > 1) && (pcBuffer[i32Ijk+1] != IVEC_VFRAME_SYNC_CHAR_1)) + { + l_pcFrameStartPt = NULL; + } + + if (l_pcFrameStartPt == NULL || (i32RemainingLen < IVEC_VFRAME_MIN_LEN)) + goto exit; + uint16_t u16Dlc = 0; + memcpy(&u16Dlc, l_pcFrameStartPt + IVEC_VFRAME_DLC, IVEC_VFRAME_DLC_LEN); + IVEC_BSW_LOG(LOG_STRING, "DLC Found: %d", u16Dlc); + if (i32RemainingLen < (u16Dlc + IVEC_VFRAME_MIN_LEN)) + goto exit; + l_pcFrameEndPt = l_pcFrameStartPt + u16Dlc + IVEC_VFRAME_MIN_LEN - 1; + uint8_t ucCheckSum[2]; + __prv_CalculateChecksum(l_pcFrameStartPt, u16Dlc + IVEC_VFRAME_MIN_LEN, ucCheckSum); + IVEC_BSW_LOG(LOG_STRING, "Checksum: %d-%d-%d-%d", *(l_pcFrameEndPt - 1), *(l_pcFrameEndPt), ucCheckSum[0], ucCheckSum[1]); + if (ucCheckSum[0] == *(l_pcFrameEndPt - 1) && ucCheckSum[1] == *(l_pcFrameEndPt)) + { + goto exit; + } + l_pcFrameStartPt = l_pcFrameEndPt; + l_pcFrameEndPt = NULL; + l_i32Ret = 2; // cksum failure + +exit: + *pcFrameStartPt = l_pcFrameStartPt; + *pcFrameEndPt = l_pcFrameEndPt; + IVEC_BSW_LOG(LOG_STRING, "Frame :[0x%x-0x%x|0x%x-0x%x]", l_pcFrameStartPt, l_pcFrameEndPt, *pcFrameStartPt, *pcFrameEndPt); + if (l_pcFrameStartPt && l_pcFrameEndPt) + return 1; + return l_i32Ret; +} diff --git a/main.c b/main.c index 9181c3f..d87f4b4 100644 --- a/main.c +++ b/main.c @@ -31,6 +31,7 @@ int main(void) { __enable_irq(); volatile DL_SYSCTL_RESET_CAUSE l_xResetCause = DL_SYSCTL_getResetCause(); + vMCAL_WDG_Refresh(); vMCAL_mcuInit(); xMCAL_sysctlInit(IVEC_HFXT,IVEC_STANDBY0); xMCAL_systickInit(IVEC_SYSTICK_PERIOD_1MS); @@ -43,6 +44,7 @@ int main(void) while(1) { vRTE_AppRun(); + vMCAL_WDG_Refresh(); } } diff --git a/mspm0g3507.lds b/mspm0g3507.lds index 97562bf..ccb3787 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 = 0x00000000, LENGTH = 0x00020000 + FLASH (RX) : ORIGIN = 0x00008000, LENGTH = 0x00018000 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 : 0x00000000); + DEFINED(_intvecs_base_address) ? _intvecs_base_address : 0x00008000); .intvecs (_intvecs_base_address) : AT (_intvecs_base_address) { KEEP (*(.intvecs)) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..96c471b --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "cantouart_ti", + "version": "1.1.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "cantouart_ti", + "version": "1.1.1", + "license": "ISC" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..c65664a --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "cantouart_ti", + "version": "1.1.1", + "description": "TI_MCU_firmware", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://gitea.vecmocon.com/Vecmocon_Technologies/cantouart_ti.git" + }, + "keywords": [ + "TI_MCU_FRIMWARE_VIM" + ], + "author": "VIM", + "license": "ISC" +} diff --git a/startup_mspm0g350x_gcc.c b/startup_mspm0g350x_gcc.c index aecd694..23a709e 100644 --- a/startup_mspm0g350x_gcc.c +++ b/startup_mspm0g350x_gcc.c @@ -231,6 +231,7 @@ void Default_Handler(void) // // You can use this to trace the fault location in your code /* Enter an infinite loop. */ + DL_SYSCTL_resetDevice(DL_SYSCTL_RESET_CPU); while(1) { } diff --git a/targetConfigs/MSPM0G3507.ccxml b/targetConfigs/MSPM0G3507.ccxml index 9e48a29..58856c2 100644 --- a/targetConfigs/MSPM0G3507.ccxml +++ b/targetConfigs/MSPM0G3507.ccxml @@ -1,23 +1,173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/utils/utils.c b/utils/utils.c index 2810fde..09c65bb 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -158,11 +158,15 @@ void vMCAL_delayTicks(int32_t i32DelayMs) * * Calls the necessary functions to initialize power and GPIO configurations for the MCU. */ - void vMCAL_mcuInit(void) { SYSCFG_DL_initPower(); + vMCAL_WatchdogEnablePower(); + // if watchDog is not initilized previoulsy in bootloader code then only initilize watchdog with 4sec timer + if(bMCAL_IsWatchdogRunning()==false) + xMCAL_WatchdogInit(MCAL_WDT_4_SEC_TIMER); // Timer Inputs can be : 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 16 , 24 , 32 , 40 , 48 , 56 , 64 in seconds SYSCFG_DL_GPIO_init(); + } /** * @brief Delays execution for a specified number of microseconds. @@ -211,3 +215,23 @@ void vMCAL_softReset(void) { DL_SYSCTL_resetDevice(DL_SYSCTL_RESET_CPU); } + +void vMCAL_WDG_Refresh(void) +{ + xMCAL_WatchdogReset(); +} + +void vMCAL_WatchdogDisablePower(void) +{ + DL_WWDT_disablePower(WATCHDOG_TIMER); +} + +void vMCAL_WatchdogEnablePower(void) +{ + DL_WWDT_enablePower(WATCHDOG_TIMER); +} + +bool bMCAL_IsWatchdogRunning(void) +{ + return DL_WWDT_isRunning(WATCHDOG_TIMER); +} diff --git a/utils/utils.h b/utils/utils.h index 1128195..f048ebc 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -12,6 +12,26 @@ #include #include "ti_msp_dl_config.h" +#define WATCHDOG_TIMER WWDT1 +typedef enum +{ + MCAL_WDT_1_SEC_TIMER = 1, + MCAL_WDT_2_SEC_TIMER, + MCAL_WDT_3_SEC_TIMER, + MCAL_WDT_4_SEC_TIMER, + MCAL_WDT_5_SEC_TIMER, + MCAL_WDT_6_SEC_TIMER, + MCAL_WDT_7_SEC_TIMER, + MCAL_WDT_8_SEC_TIMER, + MCAL_WDT_16_SEC_TIMER = 16, + MCAL_WDT_24_SEC_TIMER = 24, + MCAL_WDT_32_SEC_TIMER = 32, + MCAL_WDT_40_SEC_TIMER = 40, + MCAL_WDT_48_SEC_TIMER = 48, + MCAL_WDT_56_SEC_TIMER = 56, + MCAL_WDT_64_SEC_TIMER = 64 +}MCAL_WWDT_TIMER; + /* Generic Status Codes */ typedef enum { @@ -86,5 +106,9 @@ void vMCAL_delayTicks(int32_t i32DelayMs); void vMCAL_softReset(void); void vMCAL_delayUs(uint32_t u32Us); IVEC_McalStatus_e xMCAL_vrefInit(void); +void vMCAL_WDG_Refresh(void); +void vMCAL_WatchdogDisablePower(void); +void vMCAL_WatchdogEnablePower(void); +bool bMCAL_IsWatchdogRunning(void); #endif /* UTILS_IVEC_UTILS_H_ */