/** * @file fm_coredump_test.c * * @brief * Test Code to test the Fault Management library coredump APIs * on K2 devices * * \par * NOTE: * (C) Copyright 2012-2014 Texas Instruments, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include #include #include /* BIOS/XDC Include Files. */ #include #include #include #include #include #include /* CSL Include Files */ #include #include #include /* Fault Management Include File */ #include /* Exclude Linux CPDMA resources from being disabled during IO halt */ #define EXCLUDE_LINUX_RESOURCES_FROM_HALT 1 /********************************************************************** ************************** External Variables ************************ **********************************************************************/ extern Fm_GlobalConfigParams fmGblCfgParams; extern Fm_ExcludedResource linuxResources[]; /********************************************************************** ************************* Unit Test Functions ************************ **********************************************************************/ Void myExceptionHook(Void) { uint32_t i; Fm_HaltCfg haltCfg; uint32_t efr_val; /* Copy register status into fault management data region for Host */ Fault_Mgmt_getLastRegStatus(); memset(&haltCfg, 0, sizeof(haltCfg)); efr_val = CSL_chipReadEFR(); /* If triggered exception originates from another core through * NMI exception don't need to halt processing and notify other cores * since the parent core where the exception originally triggered via * event would notify them. This eliminates recursive exceptions */ if (!(efr_val & 0x80000000)) { /* Halt all processing - Only need to be done on one core */ haltCfg.haltAif2 = 1; haltCfg.haltCpdma = 1; haltCfg.haltEdma3 = 1; #if EXCLUDE_LINUX_RESOURCES_FROM_HALT haltCfg.haltSGMII = 0; haltCfg.excludedResources = &linuxResources[0]; #else haltCfg.haltSGMII = 1; haltCfg.excludedResources = NULL; #endif Fault_Mgmt_haltIoProcessing(&fmGblCfgParams, &haltCfg); for (i = 0; i < fmGblCfgParams.maxNumCores; i++) { /* Notify remote DSP cores of exception - WARNING: This will generate NMI * pulse to the remote DSP cores */ if (i != CSL_chipReadDNUM()) { Fault_Mgmt_notify_remote_core(i); } } } /* Notify Host of crash */ Fault_Mgmt_notify(); } /* Exception inducing function */ void exceptionFunc (void) { System_printf ("Causing exception\n"); /* Attempt to use B0 twice in the same execution stage. This will * cause a resource sharing exception to occur */ asm(" \n \ mvk 1, a1; \n \ mvk 1, a0; \n \ [a1] mvk 0, b0; \n \ ||[a0] mv a0, b0; \n \ "); /* The crash dump should show NRP as corresponding to this printf. * NRP is used as the PC in the crash dump since that is the return * address from the non-maskable interrupt generated by the * exception */ System_printf ("Print after causing the exception\n"); } /* Second function in test call stack. */ void testFunc1 (void) { System_printf ("In testFunc1\n"); /* Call the function which will cause the exception */ exceptionFunc(); } /* Task which causes DSP exception. Need to create a call stack first for * crash dump analysis testing purposes. */ void testTask () { uint32_t coreId; System_printf ("In testTask\n"); coreId = CSL_chipReadDNUM(); if (coreId == 0) { /* Call first function in call stack */ testFunc1(); } else { /* No operations for other cores */ while(1); } } int32_t main(int32_t argc, char* argv[]) { Task_Params taskParams; System_printf ("**********************************************\n"); System_printf ("******* Fault Management Coredump Test *******\n"); System_printf ("**********************************************\n"); /* Enable the caches. */ CACHE_setL1DSize (CACHE_L1_32KCACHE); CACHE_setL1PSize (CACHE_L1_32KCACHE); /* Check that proper size has been allocated for coredump note header */ if (FAULT_MGMT_DATA_SIZE < Fault_Mgmt_getSizes()) { System_printf ("Error: Section allocated for coredump is too small\n"); System_printf (" Allocated: %d\n", FAULT_MGMT_DATA_SIZE); System_printf (" Required : %d\n", Fault_Mgmt_getSizes()); } else { /* Initialize the Task Parameters. */ Task_Params_init(&taskParams); /* Create a task that causes an exception */ Task_create((Task_FuncPtr)testTask, &taskParams, NULL); BIOS_start(); } return 0; }