/** * \file Fusa_Cpu.c * \author Yang Zuqiao * \brief Source file for fusa CAN Loop Back * \copyright (c) 2024 Preh GmbH, all rights reserved. */ /*----------------------------------------------------------------------------*/ /* Includes */ /*----------------------------------------------------------------------------*/ #include "Fusa_Cpu.h" #include "hw_memmap.h" #include "hw_pie.h" #include "stdlib.h" #include "sta_util.h" /*----------------------------------------------------------------------------*/ /* Micro Define */ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* Definition of RAM-Variables */ /*----------------------------------------------------------------------------*/ const STA_Tests_Types STA_Tests_testArray[STA_TESTS_NUMBERS] = { STA_CLA_TEST_START, STA_CLA_TEST_REGISTERS_1, STA_CLA_TEST_REGISTERS_2, STA_CLA_TEST_REGISTERS_3, STA_CLA_POST, STA_CLA_PEST, STA_CLA_ALL, STA_CLA_TEST_END }; uint16 numPOST = 0; uint16 numPEST = 0; uint16 enableErrorInject = 0; uint16 test_1 = 0; /*----------------------------------------------------------------------------*/ /* Local data at RAM */ /*----------------------------------------------------------------------------*/ static boolean STA_Tests_injectError = 0U; static uint16 STA_Tests_passCount = 0U; static boolean STA_Tests_report[10] = {0}; /*----------------------------------------------------------------------------*/ /* Declaration of local functions */ /*----------------------------------------------------------------------------*/ static uint16 STA_Tests_testDevice(STA_Tests_Types testItem); /*----------------------------------------------------------------------------*/ /* Implementation of global functions */ /*----------------------------------------------------------------------------*/ uint8 FusaStl_StartupCheck(void) { uint16 returnVal = E_NOT_OK; STA_Tests_Types i = STA_CLA_TEST_START; for(i = STA_CLA_TEST_START; i <= STA_CLA_TEST_END; i++) { returnVal |= STA_Tests_testDevice(i); } test_1 = returnVal; return returnVal; } /*----------------------------------------------------------------------------*/ /* Implementation of local functions */ /*---------------------------------------static-------------------------------------*/ static uint16 STA_Tests_testDevice(STA_Tests_Types testItem) { uint16 returnVal = E_NOT_OK; switch(testItem) { case STA_CLA_TEST_START: { // // Configure the CLA memory one time. // STL_CLA_configMemory(); STA_Tests_report[0] = 1; STA_Tests_passCount = 0U; break; } case STA_CLA_TEST_REGISTERS_1: { uint32 claBase = CLA1_BASE; if(STA_Tests_injectError) { claBase = ADCARESULT_BASE; } returnVal = STL_CLA_testRegisters1(claBase); if(STL_CLA_PASS == returnVal) { STA_Tests_passCount++; STA_Tests_report[1] = 0; } else { STA_Tests_report[1] = 1; } break; } case STA_CLA_TEST_REGISTERS_2: { uint32 claBase = CLA1_BASE; if(STA_Tests_injectError) { claBase = ADCARESULT_BASE; } returnVal = STL_CLA_testRegisters2(claBase); if(STL_CLA_PASS == returnVal) { STA_Tests_passCount++; STA_Tests_report[2] = 0; } else { STA_Tests_report[2] = 1; } break; } case STA_CLA_TEST_REGISTERS_3: { uint16 delay = 50U; uint32 claBase = CLA1_BASE; if(STA_Tests_injectError) { claBase = ADCARESULT_BASE; } // // Clear task complete flag in PIE. // (*((volatile uint16 *)(PIECTRL_BASE + PIE_O_IFR11))) = 0x0000U; returnVal = STL_CLA_testRegisters3(claBase, delay); if(STL_CLA_PASS == returnVal) { STA_Tests_passCount++; STA_Tests_report[3] = 0; } else { STA_Tests_report[3] = 1; } break; } case STA_CLA_POST: { uint16 delay = 50U; if(STA_Tests_injectError) { delay = 2U; } // // Clear task complete flag in PIE. // (*((volatile uint16 *)(PIECTRL_BASE + PIE_O_IFR11))) = 0x0000U; // // Copy test segment to RAMLS0 for CLA execution. // STL_CLA_bootVector((uint32 *)STL_CLA_postHandleArray[numPOST]->vectorAddress, \ (size_t)STL_CLA_postHandleArray[numPOST]->vectorLength); // // Run a micro-run of CLASWBIST. // for(numPOST = 0; numPOST < STL_CLA_POST_NUM_VECTS; numPOST++) { returnVal |= STL_CLA_runPOSTMicro((STL_CLA_POSTVector)numPOST, delay); } if(STL_CLA_PASS == returnVal) { STA_Tests_passCount++; STA_Tests_report[4] = 0; } else { STA_Tests_report[4] = 1; } break; } case STA_CLA_PEST: { uint16 delay = 50U; if(STA_Tests_injectError) { delay = 2U; } // // Clear task complete flag in PIE. // (*((volatile uint16 *)(PIECTRL_BASE + PIE_O_IFR11))) = 0x0000U; // // Copy test segment to RAMLS0 for CLA execution. // STL_CLA_bootVector((uint32 *)STL_CLA_pestHandleArray[numPEST]->vectorAddress, \ (size_t)STL_CLA_pestHandleArray[numPEST]->vectorLength); // // TID_02_73_01 // // // Run a micro-run of CLASWBIST. // for(numPEST = 0; numPEST < STL_CLA_PEST_NUM_VECTS; numPEST++) { returnVal |= STL_CLA_runPESTMicro((STL_CLA_PESTVector)numPEST, delay); } returnVal = STL_CLA_runPESTMicro(STL_CLA_PEST_VECTOR_02, delay); if(STL_CLA_PASS == returnVal) { STA_Tests_passCount++; STA_Tests_report[5] = 0; } else { STA_Tests_report[5] = 1; } break; } case STA_CLA_ALL: { uint16 delay = 50U; uint32 claBase = CLA1_BASE; uint16 returnVal = STL_CLA_PASS; sint16 numPOSTAll; sint16 numPESTAll; if(STA_Tests_injectError) { claBase = 0x80000UL; delay = 2U; } // // TID_02_74_01 // // // Copy test segment to RAMLS0 for CLA execution. // // // POST tests // returnVal |= STL_CLA_testRegisters1(claBase); returnVal |= STL_CLA_testRegisters2(claBase); returnVal |= STL_CLA_testRegisters3(claBase, delay); STA_Tests_report[6] = returnVal; for(numPOSTAll = 0; numPOSTAll < STL_CLA_POST_NUM_VECTS; numPOSTAll++) { STL_CLA_bootVector((uint32 *)STL_CLA_postHandleArray[numPOSTAll]->vectorAddress, \ (size_t)STL_CLA_postHandleArray[numPOSTAll]->vectorLength); if ((STL_CLA_POST_VECTOR_11 == numPOSTAll) && (FALSE == STA_Tests_injectError)) { delay = STL_CLA_FPU_TEST_DELAY; // POST vector 11 - FPU tests - POST only cannot qualify for PEST } returnVal |= STL_CLA_runPOSTMicro((STL_CLA_POSTVector)numPOSTAll, delay); STA_Tests_report[7] = STL_CLA_runPOSTMicro((STL_CLA_POSTVector)numPOSTAll, delay); } // // PEST tests // if(STL_CLA_PASS == returnVal) { for(numPESTAll = 0; numPESTAll < STL_CLA_PEST_NUM_VECTS; numPESTAll++) { STL_CLA_bootVector((uint32 *)STL_CLA_pestHandleArray[numPESTAll]->vectorAddress, \ (size_t)STL_CLA_pestHandleArray[numPESTAll]->vectorLength); returnVal |= STL_CLA_runPESTMicro((STL_CLA_PESTVector)numPESTAll, delay); STA_Tests_report[8] = STL_CLA_runPESTMicro((STL_CLA_PESTVector)numPESTAll, delay); } } if(STL_CLA_PASS == returnVal) { STA_Tests_passCount++; STA_Tests_report[9] = 0; } else { STA_Tests_report[9] = 1; } break; } case STA_CLA_TEST_END: { STA_Tests_report[7] = 1; break; } default: { break; } } return returnVal; }