/****************************************************************************************************************/ /* COPYRIGHT */ /* Interface Microsystems (c) 2021 */ /****************************************************************************************************************/ /* File name : Ecu_M.c */ /* Module : MM9Z1_BatterySensor_V1/Sources/BSW/services/Ecumain.c */ /*--------------------------------------------------------------------------------------------------------------*/ /* Description : */ /****************************************************************************************************************/ /* History */ /*--------------------------------------------------------------------------------------------------------------*/ /* Date Revised By Revision Details */ /*--------------------------------------------------------------------------------------------------------------*/ /* July 20, 2021 */ /****************************************************************************************************************/ /******************************************************************************/ /* Includes */ /******************************************************************************/ #include "drv638.h" #include "defn.h" #include "Sys_init.h" #include "Ecumain.h" #include "kt9z1_638_evm.h" #include "lin.h" #include "UDS.h" /* LIN driver is using SCI0, isrD2D and TIM Ch3*/ #include "lin_lld_sci.h" #include "cop.h" #include "cvtMeasurements.h" #include "ECUStateManagement.h" #include "soc.h" #include "MemIf.h" #include "nvm.h" #include "MemConfig.h" #include "Calibration.h" #include "Lin_Process.h" #include "LIN_User_def.h" #include "FTMRZ.h" #include "lin_commontl_proto.h" #include "lin_diagnostic_service.h" #include "lin_commontl_api.h" #ifdef EXTERNAL_CLK #include "TestCase.h" #endif /******************************************************************************/ /* Defines */ /******************************************************************************/ // reset vector for #define BOOTLOADER_TIMEOUT 500 // 5 sec /******************************************************************************/ /* Enumerations */ /******************************************************************************/ /******************************************************************************/ /* Type definitions */ /******************************************************************************/ /******************************************************************************/ /* Global variables */ /******************************************************************************/ word bootloaderTimeout; word bootEntryReq; word bootFlashErased; ECU_BOOT_STATES ECU_Boot_State; u8 WriteSystemCalibrationValues = FALSE; boolean EE_WRITE_CHECK_F; boolean EE_WRITE_ERR_F; boolean FLASH_UNLOCKED_F; boolean CHECKSUM_MATCHED_F; boolean BOOT_POC_F; boolean SCI_TC_F; boolean SCI_TC_OVER_F; l_u8 req_data[300]; WORD ee_data_1, ee_data_2, ee_data_3, ee_data_4; u32 MemreturnCode; u8 LIN_Tx_Data[8]; /* Function pointers to RAM */ pt2Func FTMRZ_Erase_Flash_RAM; pt2Func FTMRZ_Prog_Phrase_RAM; ProgramStruct PS; /* Data structure used by the programming routine */ unsigned char Error; SSD_CONFIG ssdConfigPFlash = { FTM_REG_BASE, /* FTFx control register base */ BUS_CLOCK, /* base address of PFlash block */ PFLASH_BLOCK_BASE, /* size of PFlash block */ PFLASH_BLOCK_SIZE, /* base address of DFlash block */ EE_BLOCK_BASE, /* size of DFlash block */ EE_BLOCK_SIZE, /* base address of EERAM block */ IGNORE_SINGLE_FAULT, /* size of EERAM block */ BDM_ENABLE, /* size of EEE block */ NULL_CALLBACK /* pointer to callback function */ }; /******************************************************************************/ /* Local variables */ /******************************************************************************/ static u8 windowWDValue = 0xAA; static u8 erase_finish = 0; /******************************************************************************/ /* Local function declarations */ /******************************************************************************/ /******************************************************************************/ /* Global function definitions */ /******************************************************************************/ /* -------------------------------------------------------------------------- */ /* Purpose : void */ /* Inputs : void */ /* Return : void */ /* -------------------------------------------------------------------------- */ void ECUM_INIT(void) { bootEntryReq = *(word*)EEPROM_BOOTLOADER_REQ_ADDR; bootFlashErased = *(word*)EEPROM_FLASH_ERASED_ADDR; sys_init_fnc(); //Calibration_Check(); GPIOInit(); /* system calibration values */ CalibDefault(); /* Enable CVT Measurements*/ //MCU_CVTMeasurementsInit(); XirqEnable(); IrqEnable(); init_Variables(); FlashInit(&ssdConfigPFlash); Copy_Shadow(); /* Move shadow functions (Flash related only) to RAM */ /* Get RAM pointer of function after being copied */ FTMRZ_Erase_Flash_RAM = Get_RAM_Ptr(FTMRZ_Erase_Flash); FTMRZ_Prog_Phrase_RAM = Get_RAM_Ptr(FTMRZ_Prog_Phrase); /* Get RAM pointer of function after being copied */ if(bootFlashErased == FLASH_ERASE_SIGNATURE) { // flash is in erased state stay in bootloader bootloaderTimeout = 0; } else { bootloaderTimeout = BOOTLOADER_TIMEOUT; } ECU_Boot_State = START_EXTEND_DIAG_SESSION; for(;;) { if(RTIEvery10ms() == TRUE) { /*reset COP counter */ FEED_COP(); /*reset Analog_die watchDog counter */ windowedWatchdog_Serve(); boot_process_dsl_timeouts(); process_UDS_Frames(); /* eeprom memory routine */ MemIf_NvM_MainFunction(); if(flash_erased != 1) { FTMRZ_Erase_Flash_RAM(); /* Jump to RAM and Erase Flash, return to Flash*/ flash_erased = 1; } } } } /*********************************************************************************************** * * @brief Copy_Shadow - Copy functions on shadow segment to RAM (only Flash related funcions that must run on RAM) * @param none * @return none * ************************************************************************************************/ void Copy_Shadow() { u16 i; for (i = 0; i < SHADOW_SIZE_IN_WORDS; i++) { ((u16 *)SHADOW_RAM_ADD)[i] = ((u16 *)SHADOW_ROM_ADD)[i]; } } /*********************************************************************************************** * * @brief Get_RAM_Ptr - Get the function pointer on the copied Shadow segment on RAM * @param pt2Func ptr - Pointer of the function we want to get the RAM pointer of (must be located on shadow ROM) * @return Pointer of the function on the RAM segment * ************************************************************************************************/ pt2Func Get_RAM_Ptr (pt2Func ptr) { u8 * aux=((u8 *)SHADOW_RAM_ADD)+(((u8 *)ptr)-((u8 *)SHADOW_ROM_ADD)); if (aux < ((u8 *)SHADOW_RAM_ADD) || aux>((u8*)SHADOW_RAM_ADD)+ SHADOW_SIZE_IN_WORDS*2) { aux = 0; } return (pt2Func)aux; } void windowedWD_Serve(void){ if(B_WD_SR_WDWO == TRUE) { B_WD_RR = windowWDValue; windowWDValue = ~windowWDValue; } } /******************************************************************************/ /* End of file Ecum.c */ /******************************************************************************/