From 067c61f9cc9ecb41c213ec897cfffb1426c9f947 Mon Sep 17 00:00:00 2001 From: Rakshita Date: Wed, 18 Dec 2024 16:34:53 +0530 Subject: [PATCH] feat: Added relays for Fan 1 and Fan 2 - Introduced two new relays for controlling Fan 1 and Fan 2. - Updated the 9-bit status word to accommodate the new relays, expanding to 11 bits. - Adjusted GPIO pin mapping to include the new relays in the control logic. --- Core/Source/ivec_mcal_uart.c | 4 +- Generated Codes/ti_msp_dl_config.c | 72 +++++++++++++--------- Generated Codes/ti_msp_dl_config.h | 36 ++++++----- ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c | 18 ++++-- ivec_RTE/src/ivec_rte.c | 19 ++++-- utils/utils.h | 2 +- 6 files changed, 94 insertions(+), 57 deletions(-) diff --git a/Core/Source/ivec_mcal_uart.c b/Core/Source/ivec_mcal_uart.c index 6453b9d..8c24551 100644 --- a/Core/Source/ivec_mcal_uart.c +++ b/Core/Source/ivec_mcal_uart.c @@ -317,8 +317,8 @@ static xCoreStatus_t uart_init(McalUartHandle_s* pxUartHandle, McalUartBaudRate_ #elif UART_PIN_SELECTION == 3 DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM19, IOMUX_PINCM19_PF_UART1_TX); DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM20, IOMUX_PINCM20_PF_UART1_RX); - DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM32, IOMUX_PINCM32_PF_UART2_TX); - DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM33, IOMUX_PINCM33_PF_UART2_RX); +// DL_GPIO_initPeripheralOutputFunction(IOMUX_PINCM32, IOMUX_PINCM32_PF_UART2_TX); +// DL_GPIO_initPeripheralInputFunction(IOMUX_PINCM33, IOMUX_PINCM33_PF_UART2_RX); #endif // Get the UART instance based on the port number in the handle diff --git a/Generated Codes/ti_msp_dl_config.c b/Generated Codes/ti_msp_dl_config.c index de863d7..4fd065f 100644 --- a/Generated Codes/ti_msp_dl_config.c +++ b/Generated Codes/ti_msp_dl_config.c @@ -63,7 +63,7 @@ SYSCONFIG_WEAK void SYSCFG_DL_init(void) SYSCFG_DL_CAPTURE_0_init(); SYSCFG_DL_TIMER_0_init(); SYSCFG_DL_TIMER_1_init(); - SYSCFG_DL_UART_0_init(); + //SYSCFG_DL_UART_0_init(); SYSCFG_DL_MCAN0_init(); SYSCFG_DL_SYSCTL_CLK_init(); /* Ensure backup structures have no valid state */ @@ -110,6 +110,9 @@ SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) DL_MCAN_reset(MCAN0_INST); + DL_GPIO_enablePower(GPIOA); + DL_GPIO_enablePower(GPIOB); + #if UART_PIN_SELECTION == 1 DL_UART_Main_reset(UART2); DL_UART_Main_enablePower(UART2); @@ -122,8 +125,8 @@ SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) // UART1 pins DL_UART_Main_reset(UART1); DL_UART_Main_enablePower(UART1); - DL_UART_Main_reset(UART2); - DL_UART_Main_enablePower(UART2); +// DL_UART_Main_reset(UART2); +// DL_UART_Main_enablePower(UART2); DL_GPIO_initDigitalOutput(IOMUX_PINCM48); @@ -143,6 +146,15 @@ SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) DL_GPIO_initDigitalOutput(IOMUX_PINCM25); + DL_GPIO_initDigitalOutput(IOMUX_PINCM54); + + DL_GPIO_initDigitalOutput(IOMUX_PINCM52); + + DL_GPIO_clearPins(GPIOA, GPIO_relay_pin_fan_2_relay_PIN); +// + DL_GPIO_enableOutput(GPIOA, GPIO_relay_pin_fan_2_relay_PIN); + + DL_GPIO_clearPins(GPIOB, GPIO_relay_pin_relay_1_PIN | GPIO_relay_pin_relay_2_PIN | GPIO_relay_pin_relay_3_PIN | @@ -151,7 +163,9 @@ SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) GPIO_relay_pin_relay_6_PIN | GPIO_relay_pin_relay_7_PIN | GPIO_relay_pin_relay_8_PIN | - GPIO_relay_pin_relay_9_PIN); + GPIO_relay_pin_relay_9_PIN | + GPIO_relay_pin_fan_1_relay_PIN); + DL_GPIO_enableOutput(GPIOB, GPIO_relay_pin_relay_1_PIN | GPIO_relay_pin_relay_2_PIN | GPIO_relay_pin_relay_3_PIN | @@ -160,13 +174,13 @@ SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) GPIO_relay_pin_relay_6_PIN | GPIO_relay_pin_relay_7_PIN | GPIO_relay_pin_relay_8_PIN | - GPIO_relay_pin_relay_9_PIN); - + GPIO_relay_pin_relay_9_PIN | + GPIO_relay_pin_fan_1_relay_PIN); #endif - DL_GPIO_enablePower(GPIOA); - DL_GPIO_enablePower(GPIOB); +// DL_GPIO_enablePower(GPIOA); +// DL_GPIO_enablePower(GPIOB); DL_TimerA_enablePower(CAPTURE_0_INST); DL_TimerG_enablePower(TIMER_0_INST); DL_TimerA_enablePower(TIMER_1_INST); @@ -183,10 +197,10 @@ SYSCONFIG_WEAK void SYSCFG_DL_GPIO_init(void) DL_GPIO_initPeripheralInputFunction(GPIO_CAPTURE_0_C0_IOMUX,GPIO_CAPTURE_0_C0_IOMUX_FUNC); - DL_GPIO_initPeripheralOutputFunction( - GPIO_UART_0_IOMUX_TX, GPIO_UART_0_IOMUX_TX_FUNC); - DL_GPIO_initPeripheralInputFunction( - GPIO_UART_0_IOMUX_RX, GPIO_UART_0_IOMUX_RX_FUNC); +// DL_GPIO_initPeripheralOutputFunction( +// GPIO_UART_0_IOMUX_TX, GPIO_UART_0_IOMUX_TX_FUNC); +// DL_GPIO_initPeripheralInputFunction( +// GPIO_UART_0_IOMUX_RX, GPIO_UART_0_IOMUX_RX_FUNC); DL_GPIO_initDigitalInputFeatures(GPIO_GRP_0_PIN_0_IOMUX, DL_GPIO_INVERSION_DISABLE, DL_GPIO_RESISTOR_NONE, @@ -384,23 +398,23 @@ static const DL_UART_Main_Config gUART_0Config = { .stopBits = DL_UART_MAIN_STOP_BITS_ONE }; -SYSCONFIG_WEAK void SYSCFG_DL_UART_0_init(void) -{ - DL_UART_Main_setClockConfig(UART_0_INST, (DL_UART_Main_ClockConfig *) &gUART_0ClockConfig); - - DL_UART_Main_init(UART_0_INST, (DL_UART_Main_Config *) &gUART_0Config); - /* - * Configure baud rate by setting oversampling and baud rate divisors. - * Target baud rate: 115200 - * Actual baud rate: 115246.1 - */ - DL_UART_Main_setOversampling(UART_0_INST, DL_UART_OVERSAMPLING_RATE_16X); - DL_UART_Main_setBaudRateDivisor(UART_0_INST, UART_0_IBRD_24_MHZ_115200_BAUD, UART_0_FBRD_24_MHZ_115200_BAUD); - - - - DL_UART_Main_enable(UART_0_INST); -} +//SYSCONFIG_WEAK void SYSCFG_DL_UART_0_init(void) +//{ +// DL_UART_Main_setClockConfig(UART_0_INST, (DL_UART_Main_ClockConfig *) &gUART_0ClockConfig); +// +// DL_UART_Main_init(UART_0_INST, (DL_UART_Main_Config *) &gUART_0Config); +// /* +// * Configure baud rate by setting oversampling and baud rate divisors. +// * Target baud rate: 115200 +// * Actual baud rate: 115246.1 +// */ +// DL_UART_Main_setOversampling(UART_0_INST, DL_UART_OVERSAMPLING_RATE_16X); +// DL_UART_Main_setBaudRateDivisor(UART_0_INST, UART_0_IBRD_24_MHZ_115200_BAUD, UART_0_FBRD_24_MHZ_115200_BAUD); +// +// +// +// DL_UART_Main_enable(UART_0_INST); +//} static const DL_MCAN_ClockConfig gMCAN0ClockConf = { .clockSel = DL_MCAN_FCLK_HFCLK, diff --git a/Generated Codes/ti_msp_dl_config.h b/Generated Codes/ti_msp_dl_config.h index 7058cf6..6f5cb0b 100644 --- a/Generated Codes/ti_msp_dl_config.h +++ b/Generated Codes/ti_msp_dl_config.h @@ -85,6 +85,10 @@ extern "C" { #define GPIO_relay_pin_relay_8_PIN (DL_GPIO_PIN_9) /* Defines for relay_9: GPIOB.8 with pinCMx 25 on package pin 60 */ #define GPIO_relay_pin_relay_9_PIN (DL_GPIO_PIN_8) +/* Defines for fan_1_relay: GPIOB.24 with pinCMx 52 on package pin 23 */ +#define GPIO_relay_pin_fan_1_relay_PIN (DL_GPIO_PIN_24) +/* Defines for fan_2_relay: GPIOA.24 with pinCMx 54 on package pin 25 */ +#define GPIO_relay_pin_fan_2_relay_PIN (DL_GPIO_PIN_24) /* clang-format off */ @@ -128,22 +132,22 @@ extern "C" { -/* Defines for UART_0 */ -#define UART_0_INST UART2 -#define UART_0_INST_FREQUENCY 24000000 -#define UART_0_INST_IRQHandler UART2_IRQHandler -#define UART_0_INST_INT_IRQN UART2_INT_IRQn -#define GPIO_UART_0_RX_PORT GPIOB -#define GPIO_UART_0_TX_PORT GPIOB -#define GPIO_UART_0_RX_PIN DL_GPIO_PIN_16 -#define GPIO_UART_0_TX_PIN DL_GPIO_PIN_15 -#define GPIO_UART_0_IOMUX_RX (IOMUX_PINCM33) -#define GPIO_UART_0_IOMUX_TX (IOMUX_PINCM32) -#define GPIO_UART_0_IOMUX_RX_FUNC IOMUX_PINCM33_PF_UART2_RX -#define GPIO_UART_0_IOMUX_TX_FUNC IOMUX_PINCM32_PF_UART2_TX -#define UART_0_BAUD_RATE (115200) -#define UART_0_IBRD_24_MHZ_115200_BAUD (13) -#define UART_0_FBRD_24_MHZ_115200_BAUD (1) +///* Defines for UART_0 */ +//#define UART_0_INST UART2 +//#define UART_0_INST_FREQUENCY 24000000 +//#define UART_0_INST_IRQHandler UART2_IRQHandler +//#define UART_0_INST_INT_IRQN UART2_INT_IRQn +//#define GPIO_UART_0_RX_PORT GPIOB +//#define GPIO_UART_0_TX_PORT GPIOB +//#define GPIO_UART_0_RX_PIN DL_GPIO_PIN_16 +//#define GPIO_UART_0_TX_PIN DL_GPIO_PIN_15 +//#define GPIO_UART_0_IOMUX_RX (IOMUX_PINCM33) +//#define GPIO_UART_0_IOMUX_TX (IOMUX_PINCM32) +//#define GPIO_UART_0_IOMUX_RX_FUNC IOMUX_PINCM33_PF_UART2_RX +//#define GPIO_UART_0_IOMUX_TX_FUNC IOMUX_PINCM32_PF_UART2_TX +//#define UART_0_BAUD_RATE (115200) +//#define UART_0_IBRD_24_MHZ_115200_BAUD (13) +//#define UART_0_FBRD_24_MHZ_115200_BAUD (1) 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 dd18754..bd637f2 100644 --- a/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c +++ b/ivec_ECU/ivec_ecu_uart/src/ivec_ecu_uart.c @@ -57,13 +57,23 @@ IVEC_EcuCommonErr_e xECU_UARTInit(McalUartHandle_s* prvUartHandle, uint32_t spee } IVEC_ECU_LOG(LOG_STRING, "Initilising UART"); - #if (UART_PIN_SELECTION == 1 || ((uartCount == 2) && (UART_PIN_SELECTION == 3))) + #if (UART_PIN_SELECTION == 1) prvUartHandle->eUartPortNumber = mcalUART_PORT3; - uartCount = 1; - #elif (UART_PIN_SELECTION == 2 || ((uartCount == 1) && (UART_PIN_SELECTION == 3))) + #elif (UART_PIN_SELECTION == 2 ) prvUartHandle->eUartPortNumber = mcalUART_PORT2; - uartCount = 2; + #elif (UART_PIN_SELECTION == 3) + if(uartCount == 1) + { + prvUartHandle->eUartPortNumber = mcalUART_PORT2; + uartCount = 2; + } + else + { + prvUartHandle->eUartPortNumber = mcalUART_PORT3; + uartCount = 1; + } + #endif diff --git a/ivec_RTE/src/ivec_rte.c b/ivec_RTE/src/ivec_rte.c index 89e5b7e..6307cba 100644 --- a/ivec_RTE/src/ivec_rte.c +++ b/ivec_RTE/src/ivec_rte.c @@ -233,9 +233,9 @@ void vRTE_InitUARTCANEcho(void) g_u16CanSpeed = BAUD_500; xECU_UARTInit(&g_xUartHandle, g_u32UartSpeed); - #if UART_PIN_SELECTION == 3 - xECU_UARTInit(&g_xUart2Handle, g_u32UartSpeed); - #endif +// #if UART_PIN_SELECTION == 3 +// xECU_UARTInit(&g_xUart2Handle, g_u32UartSpeed); +// #endif xECU_CANInit(CANFD0,g_u16CanSpeed); } @@ -443,7 +443,7 @@ void vRTE_CANDataProcess(void) { #if UART_PIN_SELECTION == 3 - if(xBuff.id == 0x6ff69) + if(xBuff.id == 0x6fe69) { uint16_t relay_status = (xBuff.data[0] << 8) |xBuff.data[1]; control_relays(relay_status); // Control relays based on the relay_status @@ -485,7 +485,10 @@ void control_relays(uint16_t relay_status) GPIO_relay_pin_relay_6_PIN | GPIO_relay_pin_relay_7_PIN | GPIO_relay_pin_relay_8_PIN | - GPIO_relay_pin_relay_9_PIN); + GPIO_relay_pin_relay_9_PIN | + GPIO_relay_pin_fan_1_relay_PIN); + + DL_GPIO_clearPins(GPIOA, GPIO_relay_pin_fan_2_relay_PIN); // Check each bit of relay_status and set the corresponding relay pin if ((relay_status & 0x01) != 0) { // Bit 0: Relay 1 @@ -515,6 +518,12 @@ void control_relays(uint16_t relay_status) if ((relay_status & 0x100) != 0) { // Bit 8: Relay 9 DL_GPIO_setPins(GPIOB, GPIO_relay_pin_relay_1_PIN); } + if ((relay_status & 0x200) != 0) { // Bit 9: fan 1 Relay 10 + DL_GPIO_setPins(GPIOB, GPIO_relay_pin_fan_1_relay_PIN); + } + if ((relay_status & 0x400) != 0) { // Bit 10: fan 2 Relay 11 + DL_GPIO_setPins(GPIOA, GPIO_relay_pin_fan_2_relay_PIN); + } } diff --git a/utils/utils.h b/utils/utils.h index 3b77902..1dcf443 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -38,7 +38,7 @@ typedef enum // 1 - Basil Battery Smart // 2 - Basil // 3 - Battery Swapping Station -#define UART_PIN_SELECTION 2 // Set the desired UART configuration here +#define UART_PIN_SELECTION 3 // Set the desired UART configuration here volatile int i32TickCnt;