//#include "ti/driverlib/dl_timer.h" //#include "ti/driverlib/dl_wwdt.h" #include "ti/driverlib/dl_wwdt.h" #include "ti/driverlib/m0p/dl_core.h" #include "ti_msp_dl_config.h" #include "src/pi/i2c_pi_target.h" #include "src/controller/controller.h" #include "ti/driverlib/dl_i2c.h" #include "src/battery_data/battery.h" #include "src/cc_cv_charging.h" #include #include "src/battery_data/battery.h" #include "mock_setup.h" //define the varibales: volatile bool mcuSendCommand = false; volatile bool picommandPending = false; volatile bool watchdog_triggered= false; // Interrupt for I2C instance -> MCU to Target void I2C_1_INST_IRQHandler(void) { switch (DL_I2C_getPendingInterrupt(I2C_1_INST)) { case DL_I2C_IIDX_CONTROLLER_START: DL_I2C_flushControllerRXFIFO(I2C_1_INST); DL_I2C_flushControllerTXFIFO(I2C_1_INST); break; case DL_I2C_IIDX_CONTROLLER_RXFIFO_TRIGGER: if (DL_I2C_isTargetRXFIFOEmpty(I2C_1_INST)) { return; } mcuSendCommand= true; break; case DL_I2C_IIDX_CONTROLLER_TXFIFO_TRIGGER: /* Fill TX FIFO with bytes to send */ mcuSendCommand = true; break; case DL_I2C_IIDX_CONTROLLER_STOP: mcuSendCommand = true; case DL_I2C_IIDX_CONTROLLER_ARBITRATION_LOST: case DL_I2C_IIDX_CONTROLLER_NACK: break; default: break; } } void I2C_0_INST_IRQHandler(void) { switch (DL_I2C_getPendingInterrupt(I2C_0_INST)) { case DL_I2C_IIDX_TARGET_START: DL_I2C_flushTargetTXFIFO(I2C_0_INST); break; case DL_I2C_IIDX_TARGET_RXFIFO_TRIGGER: if (DL_I2C_isTargetRXFIFOEmpty(I2C_0_INST)) { return; } picommandPending = true; break; case DL_I2C_IIDX_TARGET_TXFIFO_TRIGGER: /* Fill TX FIFO with bytes to send */ picommandPending = true; break; case DL_I2C_IIDX_TARGET_STOP: picommandPending = true; //DL_I2C_flushTargetTXFIFO(I2C_0_INST); //DL_I2C_flushTargetRXFIFO(I2C_0_INST); break; case DL_I2C_IIDX_TARGET_ARBITRATION_LOST: break; default: break; } } int main(void) { SYSCFG_DL_init(); // initialize watchdog timer configuration SYSCFG_DL_WWDT0_init(); // Enable WWDT after initialization: //DL_WWDT_enablePower(WWDT0); Battery_Init(); //dynamic addressing function call for Pi dynamic_gpio_addressing(); //Interrupt routine for Pi NVIC_EnableIRQ(I2C_0_INST_INT_IRQN); //Interrupt for target mcu NVIC_EnableIRQ(I2C_1_INST_INT_IRQN); /* * Configures timer to be halted if CPU is halted. This ensures * that timer is always aligned with the WWDT so it is never serviced * too late or too early. */ DL_Timer_setCoreHaltBehavior(TIMER_0_INST, DL_TIMER_CORE_HALT_IMMEDIATE); /* Start TimerG counter */ DL_TimerG_startCounter(TIMER_0_INST); while(1) { /* if(picommandPending) { printf("Pi Interrupt Triggered.\n"); pi_i2c_mcu(); picommandPending = false; } if(mcuSendCommand){ printf("MCU Interrupt Triggered.\n"); for(uint8_t i=0; i