From 5f0cb2f928270b28a76d895738529cbfe2c74ba9 Mon Sep 17 00:00:00 2001 From: Josiitaa RL Date: Tue, 2 Apr 2024 12:20:27 +0530 Subject: [PATCH 2/3] POK Integration with PDK BootApp --- packages/ti/boot/sbl/build/boot_app.mk | 7 + .../boot/sbl/example/boot_app/boot_app_main.c | 72 ++- .../ti/boot/sbl/example/boot_app/pok/pok.c | 161 +++++++ .../ti/boot/sbl/example/boot_app/pok/pok.h | 107 +++++ .../sbl/example/boot_app/pok/pok_example.c | 413 ++++++++++++++++++ 5 files changed, 758 insertions(+), 2 deletions(-) create mode 100644 packages/ti/boot/sbl/example/boot_app/pok/pok.c create mode 100644 packages/ti/boot/sbl/example/boot_app/pok/pok.h create mode 100644 packages/ti/boot/sbl/example/boot_app/pok/pok_example.c diff --git a/packages/ti/boot/sbl/build/boot_app.mk b/packages/ti/boot/sbl/build/boot_app.mk index ba30b945..69856ae2 100644 --- a/packages/ti/boot/sbl/build/boot_app.mk +++ b/packages/ti/boot/sbl/build/boot_app.mk @@ -52,11 +52,14 @@ ifeq ($(BOOTMODE), mmcsd) ifeq ($(BOARD),$(filter $(BOARD), j784s4_evm)) CFLAGS_LOCAL_COMMON += -DBIST_TASK_ENABLED CFLAGS_LOCAL_COMMON += -DVTM_TASK_ENABLED + CFLAGS_LOCAL_COMMON += -DPOK_TASK_ENABLED #CFLAGS_LOCAL_COMMON += INCDIR += $(PDK_SBL_COMP_PATH)/example/boot_app/bist INCDIR += $(PDK_SBL_COMP_PATH)/example/boot_app/bist/soc/$(SOC) INCDIR += $(PDK_SBL_COMP_PATH)/example/boot_app/vtm + + INCDIR += $(PDK_SBL_COMP_PATH)/example/boot_app/pok # SDL Include Files SDL_INSTALL_PATH=$(PDK_INSTALL_PATH)/../../sdl INCDIR += $(SDL_INSTALL_PATH)/ @@ -71,6 +74,8 @@ ifeq ($(BOOTMODE), mmcsd) SRCDIR += $(PDK_SBL_COMP_PATH)/example/boot_app/bist/soc/$(SOC) SRCDIR += $(PDK_SBL_COMP_PATH)/example/boot_app/vtm + + SRCDIR += $(PDK_SBL_COMP_PATH)/example/boot_app/pok # SDL Integration EXT_LIB_LIST_COMMON += $(SDL_INSTALL_PATH)/binary/osal/lib/$(SOC)/r5f/$(BUILD_PROFILE)/sdl_osal.$(LIBEXT) EXT_LIB_LIST_COMMON += $(SDL_INSTALL_PATH)/binary/src/ip/lib/$(SOC)/r5f/$(BUILD_PROFILE)/sdl_ip.$(LIBEXT) @@ -84,6 +89,8 @@ ifeq ($(BOOTMODE), mmcsd) SRCS_COMMON += power_seq.c armv8_power_utils.c SRCS_COMMON += vtm.c vtm_example.c + + SRCS_COMMON += pok.c pok_example.c endif endif ifeq ($(BOOTMODE), ospi) diff --git a/packages/ti/boot/sbl/example/boot_app/boot_app_main.c b/packages/ti/boot/sbl/example/boot_app/boot_app_main.c index 1f654ad8..d8311308 100644 --- a/packages/ti/boot/sbl/example/boot_app/boot_app_main.c +++ b/packages/ti/boot/sbl/example/boot_app/boot_app_main.c @@ -88,6 +88,9 @@ #if defined(VTM_TASK_ENABLED) #include "vtm.h" #endif +#if defined(POK_TASK_ENABLED) +#include "pok.h" +#endif /* ========================================================================== */ /* Macros & Typedefs */ /* ========================================================================== */ @@ -98,14 +101,19 @@ #define BOOT_TASK_PRIORITY (2) #if defined(BIST_TASK_ENABLED) -#define BIST_TASK_PRIORITY (4) +#define BIST_TASK_PRIORITY (5) #define BIST_TASK_STACKSIZE (16U * 1024U) #endif #if defined(VTM_TASK_ENABLED) -#define VTM_TASK_PRIORITY (3) +#define VTM_TASK_PRIORITY (4) #define VTM_TASK_STACKSIZE (10U * 1024U) #endif + +#if defined(POK_TASK_ENABLED) +#define POK_TASK_PRIORITY (3) +#define POK_TASK_STACKSIZE (10U * 1024U) +#endif /* uncomment the following for debug logs */ // #define UART_PRINT_DEBUG @@ -125,6 +133,9 @@ static void BistApp_TaskFxn(void* a0, void* a1); #if defined(VTM_TASK_ENABLED) static void VtmApp_TaskFxn(void* a0, void* a1); #endif +#if defined(POK_TASK_ENABLED) +static void PokApp_TaskFxn(void* a0, void* a1); +#endif static uint32_t Boot_App(); static void BootApp_AppSetup(); static int32_t BootApp_RequestStageCores(uint8_t stageNum); @@ -162,6 +173,14 @@ static uint64_t gtimeVtmAppStart, gtimeVtmAppFinish; static SemaphoreP_Handle gVtmTaskCompletedSem = NULL; #endif +#if defined(POK_TASK_ENABLED) +static uint8_t gPok_TaskStack[POK_TASK_STACKSIZE] __attribute__((aligned(32))); +TaskP_Handle gPokTask; +static uint64_t gtimePokAppStart, gtimePokAppFinish; +/* Semaphore to indicate POK Task completion */ +static SemaphoreP_Handle gPokTaskCompletedSem = NULL; +#endif + int32_t main(void) { Board_initCfg boardCfg; @@ -244,6 +263,31 @@ int32_t main(void) OS_stop(); } #endif + +#if defined(POK_TASK_ENABLED) + /* initializing the semaphores*/ + SemaphoreP_Params PoksemParams; + SemaphoreP_Params_init(&PoksemParams); + gPokTaskCompletedSem = SemaphoreP_create(0, &PoksemParams); + if(NULL == gPokTaskCompletedSem) + { + UART_printf("\n Semaphore create failed\r\n"); + } + + /* Initialize the task params */ + TaskP_Params PokTaskParams; + TaskP_Params_init(&PokTaskParams); + PokTaskParams.priority = POK_TASK_PRIORITY; + PokTaskParams.stack = gPok_TaskStack; + PokTaskParams.stacksize = sizeof (gPok_TaskStack); + + gPokTask = TaskP_create(&PokApp_TaskFxn, &PokTaskParams); + if (NULL == gPokTask) + { + UART_printf("\nPOK Task creation failed\r\n"); + OS_stop(); + } +#endif OS_start(); /* does not return */ return(0); @@ -258,6 +302,10 @@ static void BootApp_TaskFxn(void* a0, void* a1) #if defined(VTM_TASK_ENABLED) /* Wait for the VTM task completion */ SemaphoreP_pend(gVtmTaskCompletedSem, SemaphoreP_WAIT_FOREVER); +#endif +#if defined(POK_TASK_ENABLED) + /* Wait for the POK task completion */ + SemaphoreP_pend(gPokTaskCompletedSem, SemaphoreP_WAIT_FOREVER); #endif gtimeBootAppStart = BootApp_GetTimeInMicroSec(CSL_armR5PmuReadCntr(CSL_ARM_R5_PMU_CYCLE_COUNTER_NUM)); @@ -312,6 +360,26 @@ static void VtmApp_TaskFxn(void* a0, void* a1) } #endif +#if defined(POK_TASK_ENABLED) +static void PokApp_TaskFxn(void* a0, void* a1) +{ + /* Initialize the SDL osal */ + SDL_TEST_osalInit(); + + gtimePokAppStart = BootApp_GetTimeInMicroSec(CSL_armR5PmuReadCntr(CSL_ARM_R5_PMU_CYCLE_COUNTER_NUM)); + + test_sdl_pok_baremetal_test_app(); + + gtimePokAppFinish = BootApp_GetTimeInMicroSec(CSL_armR5PmuReadCntr(CSL_ARM_R5_PMU_CYCLE_COUNTER_NUM)); + + UART_printf("\nPOK Task started at %d usecs and finished at %d usecs\r\n", (uint32_t)gtimePokAppStart, (uint32_t)gtimePokAppFinish); + + /* Post semaphore after POK task completion so other tasks could start execution */ + SemaphoreP_post(gPokTaskCompletedSem); + + return; +} +#endif uint32_t Boot_App() { uint32_t retVal; diff --git a/packages/ti/boot/sbl/example/boot_app/pok/pok.c b/packages/ti/boot/sbl/example/boot_app/pok/pok.c new file mode 100644 index 00000000..06b7f6c8 --- /dev/null +++ b/packages/ti/boot/sbl/example/boot_app/pok/pok.c @@ -0,0 +1,161 @@ +/* Copyright (c) 2024 Texas Instruments Incorporated + * + * 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. + * + */ + + /** + * \file pok.c + * + * \brief This file contains POK example code. + * + * \details POK example + **/ + +/*===========================================================================*/ +/* Include files */ +/*===========================================================================*/ + +#include "pok.h" +#ifdef UNITY_INCLUDE_CONFIG_H +#include +#include +#endif + + +/*===========================================================================*/ +/* Declarations */ +/*===========================================================================*/ +/* None */ + +/*===========================================================================*/ +/* Macros */ +/*===========================================================================*/ +/* define the unlock values */ +#define KICK0_UNLOCK_VAL 0x68EF3490 +#define KICK1_UNLOCK_VAL 0xD172BC5A + +/*===========================================================================*/ +/* Internal function declarations */ +/*===========================================================================*/ +void test_sdl_pok_baremetal_test_app (void); +/*===========================================================================*/ +/* Global Variables */ +/*===========================================================================*/ +sdlPokTest_t sdlPokTestList[] = { + {sdlPOK_func, "POK EXAMPLE UC-1" , SDL_APP_TEST_NOT_RUN }, + {sdlPOKInPor_func, "POR EXAMPLE UC-2" , SDL_APP_TEST_NOT_RUN }, + {NULL, "TERMINATING CONDITION", SDL_APP_TEST_NOT_RUN } +}; + +SDL_ESM_config POK_Test_esmInitConfig_WKUP = +{ + .esmErrorConfig = {0u, 8u}, /* Self test error config */ + .enableBitmap = {0xffffffffu, 0x00180003u, 0xffffffffu, + }, + /**< All events enable: except clkstop events for unused clocks */ + .priorityBitmap = {0xffffffffu, 0x00180003u, 0xffffffffu, + }, + /**< All events high priority: except clkstop events for unused clocks */ + .errorpinBitmap = {0xffffffffu, 0x00180003u, 0xffffffffu, + }, + /**< All events high priority: except clkstop for unused clocks + * and selftest error events */ +}; + +extern int32_t SDL_POK_ESM_applicationCallbackFunction(SDL_ESM_Inst esmInstType, + SDL_ESM_IntType esmIntType, + uint32_t grpChannel, + uint32_t index, + uint32_t intSrc, + void *arg); +static uint32_t arg; +/*===========================================================================*/ +/* Local Function definitions */ +/*===========================================================================*/ +/*===========================================================================*/ +/* Function definitions */ +/*===========================================================================*/ +void test_sdl_pok_baremetal_test_app (void) +{ + /* Declarations of variables */ + int32_t testResult = SDL_APP_TEST_PASS; + int32_t i; + int32_t sdlRet; + void *ptr = (void *)&arg; + + UART_printf("\n POK Test Application\r\n"); + /* Unlock the MMR in order to access the POK registers */ + *((uint32_t *)(SDL_WKUP_CTRL_MMR0_CFG0_BASE + SDL_WKUP_CTRL_MMR_CFG0_LOCK6_KICK0)) = KICK0_UNLOCK_VAL; + *((uint32_t *)(SDL_WKUP_CTRL_MMR0_CFG0_BASE + SDL_WKUP_CTRL_MMR_CFG0_LOCK6_KICK1)) = KICK1_UNLOCK_VAL; + + /* ESM Setup for POK tests */ + /* Initialize WKUP ESM module */ + sdlRet = SDL_ESM_init(SDL_ESM_INST_WKUP_ESM0, &POK_Test_esmInitConfig_WKUP, SDL_POK_ESM_applicationCallbackFunction,ptr); + if (sdlRet != SDL_PASS) { + /* print error and quit */ + UART_printf("sdlEsmSetupForPOK init: Error initializing WKUP ESM: sdlRet = SDL_EFAIL \n"); + sdlRet = -1; + } else { + UART_printf("\nsdlEsmSetupForPOK init: Init WKUP ESM complete \n"); + } + + for ( i = 0; sdlPokTestList[i].testFunction != NULL; i++) + { + testResult = sdlPokTestList[i].testFunction(); + sdlPokTestList[i].testStatus = testResult; + } + + testResult = SDL_APP_TEST_PASS; + for ( i = 0; sdlPokTestList[i].testFunction != NULL; i++) + { + if (sdlPokTestList[i].testStatus != SDL_APP_TEST_PASS) + { + UART_printf("Test Name: %s FAILED \n", sdlPokTestList[i].name); + testResult = SDL_APP_TEST_FAILED; + break; + } + else + { + UART_printf("Test Name: %s PASSED \n", sdlPokTestList[i].name); + } + } + + if (testResult == SDL_APP_TEST_PASS) + { + UART_printStatus("\n All tests have passed. \n"); + } + else + { + UART_printStatus("\n Few/all tests Failed \n"); + } +#if defined (UNITY_INCLUDE_CONFIG_H) + TEST_ASSERT_EQUAL_INT32(SDL_APP_TEST_PASS, testResult); +#endif +} \ No newline at end of file diff --git a/packages/ti/boot/sbl/example/boot_app/pok/pok.h b/packages/ti/boot/sbl/example/boot_app/pok/pok.h new file mode 100644 index 00000000..d13c3ba7 --- /dev/null +++ b/packages/ti/boot/sbl/example/boot_app/pok/pok.h @@ -0,0 +1,107 @@ +/* Copyright (c) 2024 Texas Instruments Incorporated + * + * 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. + * + */ + + /** + * \file pok.h + * + * \brief This file contains POK example code defines. + * + **/ + +/*===========================================================================*/ +/* Include files */ +/*===========================================================================*/ +/*===========================================================================*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#if !defined(TEST_POK_H) +#define TEST_POK_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define SDL_INVALID_POK_ID 0xff; + +/*===========================================================================*/ +/* Declarations */ +/*===========================================================================*/ + +/* Define the test interface */ +typedef struct sdlPokTest_s +{ + int32_t (*testFunction)(void); /* The code that runs the test */ + char *name; /* The test name */ + int32_t testStatus; /* Test Status */ +} sdlPokTest_t; + +/*===========================================================================*/ +/* Macros */ +/*===========================================================================*/ +#define SDL_APP_TEST_NOT_RUN (-(int32_t) (2)) +#define SDL_APP_TEST_FAILED (-(int32_t) (1)) +#define SDL_APP_TEST_PASS ( (int32_t) (0)) + +/*===========================================================================*/ +/* Internal function declarations */ +/*===========================================================================*/ +void sdlApp_print(const char * str); +void test_sdl_pok_baremetal_test_app (void); +/*===========================================================================*/ +/* External function declarations */ +/*===========================================================================*/ +extern int32_t sdlPOK_func(void); +extern int32_t sdlPOKInPor_func(void); +extern int32_t SDL_POK_setConfig(SDL_POK_Inst instance, SDL_POK_config *pPokCfg); +/*===========================================================================*/ +/* Local Function definitions */ +/*===========================================================================*/ + +#ifdef __cplusplus +} + +#endif /*extern "C" */ + +#endif /* POK_H */ +/* Nothing past this point */ \ No newline at end of file diff --git a/packages/ti/boot/sbl/example/boot_app/pok/pok_example.c b/packages/ti/boot/sbl/example/boot_app/pok/pok_example.c new file mode 100644 index 00000000..216228ff --- /dev/null +++ b/packages/ti/boot/sbl/example/boot_app/pok/pok_example.c @@ -0,0 +1,413 @@ +/* Copyright (c) 2024 Texas Instruments Incorporated + * + * 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. + * + */ + + /** + * \file sdl_pok_example.c + * + * \brief This file contains POK example code. + * + * \details POK example + **/ + +/*===========================================================================*/ +/* Include files */ +/*===========================================================================*/ +#include "pok.h" + +/*===========================================================================*/ +/* Macros */ +/*===========================================================================*/ +/* None */ + +/* Global variables */ + + +/*===========================================================================*/ +/* Internal function declarations */ +/*===========================================================================*/ +int32_t SDL_POK_setConfig(SDL_POK_Inst instance, SDL_POK_config *pPokCfg); +int32_t sdlPOKInPor_func(void); +int32_t sdlPOK_func(void); +int32_t SDL_POK_ESM_applicationCallbackFunction(SDL_ESM_Inst esmInstType, + SDL_ESM_IntType esmIntType, + uint32_t grpChannel, + uint32_t index, + uint32_t intSrc, + void *arg); +volatile bool ESM_Error = false; +uint32_t deactivate_trigger(uint32_t *esm_err_sig ); +static void sdlGetInstance(SDL_POK_Inst *instance, uint32_t *esm_err_sig); + +/*===========================================================================*/ +/* Function definitions */ +/*===========================================================================*/ +int32_t SDL_POK_ESM_applicationCallbackFunction(SDL_ESM_Inst esmInst, + SDL_ESM_IntType esmIntrType, + uint32_t grpChannel, + uint32_t index, + uint32_t intSrc, + void *arg) +{ + int32_t retVal = SDL_PASS; + UART_printf("\n ESM Call back function called : instType 0x%x, intType 0x%x, " \ + "grpChannel 0x%x, index 0x%x, intSrc 0x%x \n", + esmInst, esmIntrType, grpChannel, index, intSrc); + UART_printf(" Take action \n"); + /* Disable the ESM Interrupt */ + deactivate_trigger(&intSrc); + SDL_ESM_clrNError(esmInst); + ESM_Error = true; + /* Any additional customer specific actions can be added here */ + + return retVal; +} + +uint32_t deactivate_trigger(uint32_t *esm_err_sig ) +{ + SDL_POK_Inst instance; + SDL_POK_config pPokCfg; + SDL_pokVal_t pPokVal; + SDL_wkupCtrlRegsBase_t *pBaseAddr = (SDL_wkupCtrlRegsBase_t *) SDL_POK_MMR_BASE; + int32_t sdlRet = SDL_EFAIL; + + sdlGetInstance(&instance, esm_err_sig); + + pPokCfg.hystCtrl = SDL_PWRSS_HYSTERESIS_NO_ACTION; + pPokCfg.voltDetMode = SDL_PWRSS_GET_VOLTAGE_DET_MODE; + pPokCfg.trim = SDL_PWRSS_TRIM_NO_ACTION; + pPokCfg.detectionCtrl = SDL_POK_DETECTION_NO_ACTION; + pPokCfg.pokEnSelSrcCtrl = SDL_POK_ENSEL_NO_ACTION; +#if defined (SOC_J7200) || defined (SOC_J721S2) || defined (SOC_J784S4) + pPokCfg.hystCtrlOV = SDL_PWRSS_HYSTERESIS_NO_ACTION; + pPokCfg.trimOV = SDL_PWRSS_TRIM_NO_ACTION; + pPokCfg.deglitch = SDL_PWRSS_DEGLITCH_NO_ACTION; +#endif + + SDL_pokGetControl (pBaseAddr,&pPokCfg,&pPokVal,instance); + /* Re-configure to "good" setting */ + if (pPokVal.voltDetMode == SDL_PWRSS_SET_UNDER_VOLTAGE_DET_ENABLE) + { + pPokCfg.trim = 0; +#if defined (SOC_J7200) || defined (SOC_J721S2) || defined (SOC_J784S4) + pPokCfg.trimOV = SDL_PWRSS_TRIM_NO_ACTION; +#endif + } + else + { +#if defined (SOC_J7200) || defined (SOC_J721S2) || defined (SOC_J784S4) + pPokCfg.trimOV = 45; + pPokCfg.trim = SDL_PWRSS_TRIM_NO_ACTION; +#else + pPokCfg.trim = 45; +#endif + } + + pPokCfg.hystCtrl = SDL_PWRSS_HYSTERESIS_NO_ACTION; + pPokCfg.voltDetMode = pPokVal.voltDetMode; + pPokCfg.detectionCtrl = SDL_POK_DETECTION_NO_ACTION; + pPokCfg.pokEnSelSrcCtrl = SDL_POK_ENSEL_NO_ACTION; +#if defined (SOC_J7200) || defined (SOC_J721S2) || defined (SOC_J784S4) + pPokCfg.hystCtrlOV = SDL_PWRSS_HYSTERESIS_NO_ACTION; + pPokCfg.deglitch = SDL_PWRSS_DEGLITCH_NO_ACTION; +#endif + sdlRet = SDL_POK_init(instance,&pPokCfg); + + return sdlRet; +} + +int32_t SDL_POK_setConfig(SDL_POK_Inst instance, SDL_POK_config *pPokCfg) +{ + int32_t sdlRet = SDL_EFAIL; + sdlRet = SDL_POK_init(instance, pPokCfg); + if (sdlRet != SDL_PASS) + { + UART_printf("SDL_POK_init failed! \n"); + } + else + { + volatile int32_t i = 0; + UART_printf("Waiting for ESM to report the error \n"); + /* Wait for the ESM interrupt to report the error */ + do { + i++; + if (i > 0x0FFFFFFF) + { + /* Timeout for the wait */ + break; + } + } while (ESM_Error == false); + + if (ESM_Error == true) + { + UART_printf(" Got the ESM Error Interrupt \n"); + UART_printf("Action taken \n"); + ESM_Error = false; + if (sdlRet != SDL_PASS) + { + UART_printf("SDL_POK_init failed! \n"); + } + } + else + { + sdlRet = SDL_EFAIL; + } + } + return(sdlRet); +} + + +int32_t sdlPOKInPor_func(void) +{ + int32_t testStatus, sdlRet = SDL_PASS, overallStatus = SDL_APP_TEST_PASS; + SDL_POK_config pPokCfg; + SDL_POK_Inst instance; + +#if defined (SOC_J721E) + UART_printf(" \n\n Below are the POK In POR ID values for the example\n"); + UART_printf(" SDL_POR_POKHV_UV_ID is: 14 \n"); + UART_printf(" SDL_POR_POKLV_UV_ID is: 15 \n"); + UART_printf(" SDL_POR_POKHV_OV_ID is: 16 \n"); + + instance = SDL_POR_POKHV_OV_ID; +#else + instance = SDL_POR_POKLVA_OV_ID; +#endif + + UART_printf ("\n\n POK ID = %d , monitoring set to OV \n", instance); + pPokCfg.voltDetMode = SDL_PWRSS_SET_OVER_VOLTAGE_DET_ENABLE; + pPokCfg.trim = 0; + pPokCfg.hystCtrl = SDL_PWRSS_HYSTERESIS_NO_ACTION; + pPokCfg.detectionCtrl = SDL_POK_DETECTION_NO_ACTION; + pPokCfg.pokEnSelSrcCtrl = SDL_POK_ENSEL_NO_ACTION; +#if defined (SOC_J7200) || defined (SOC_J721S2) || defined (SOC_J784S4) + pPokCfg.hystCtrlOV = SDL_PWRSS_HYSTERESIS_NO_ACTION; + pPokCfg.trimOV = 0; + pPokCfg.deglitch = SDL_PWRSS_DEGLITCH_NO_ACTION; +#endif + + sdlRet = SDL_POK_setConfig(instance, &pPokCfg); + if (sdlRet == SDL_PASS) + { + testStatus = SDL_APP_TEST_PASS; + } + else + { + testStatus = SDL_APP_TEST_FAILED; + overallStatus = SDL_APP_TEST_FAILED; + } + UART_printf("Safety software Example UC-2 pok for instance %d %s\n", + instance, (testStatus == SDL_APP_TEST_PASS) ? "PASSED" : "FAILED"); + + return (overallStatus); +} + +int32_t sdlPOK_func(void) +{ + int32_t testStatus, sdlRet = SDL_PASS, overallStatus = SDL_APP_TEST_PASS; + SDL_POK_config pPokCfg; + SDL_POK_Inst instance; + +#if defined (SOC_J721E) + UART_printf(" \n \n Below are the POK ID values \n"); + UART_printf(" SDL_POK_VDDA_PMIC_IN_ID is: 0 \n"); + UART_printf(" SDL_POK_VDD_CORE_UV_ID is: 1 \n"); + UART_printf(" SDL_POK_VDDSHV_WKUP_GEN_UV_ID is: 2 \n"); + UART_printf(" SDL_POK_VDD_CPU_UV_ID is: 3 \n"); + UART_printf(" SDL_POK_VDDR_MCU_UV_ID is: 4 \n"); + UART_printf(" SDL_POK_VMON_EXT_UV_ID is: 5 \n"); + UART_printf(" SDL_POK_VDD_MCU_OV_ID is: 6 \n"); + UART_printf(" SDL_POK_VDDR_CORE_UV_ID is: 7 \n"); + UART_printf(" SDL_POK_VDDSHV_WKUP_GEN_OV_ID is: 8 \n"); + UART_printf(" SDL_POK_VDD_CORE_OV_ID is: 9 \n"); + UART_printf(" SDL_POK_VDDR_MCU_OV_ID is: 10 \n"); + UART_printf(" SDL_POK_VDD_CPU_OV_ID is: 11 \n"); + UART_printf(" SDL_POK_VDDR_CORE_OV_ID is: 12 \n"); + UART_printf(" SDL_POK_VMON_EXT_OV_ID is: 13 \n\n"); + + instance = SDL_POK_VDD_CORE_UV_ID; +#else + instance = SDL_POK_VDD_CORE_ID; +#endif + + UART_printf ("\n\n POK ID = %d , monitoring set to UV \n", instance); + pPokCfg.voltDetMode = SDL_PWRSS_SET_UNDER_VOLTAGE_DET_ENABLE; + pPokCfg.trim = 127; + pPokCfg.hystCtrl = SDL_PWRSS_HYSTERESIS_NO_ACTION; + pPokCfg.detectionCtrl = SDL_POK_DETECTION_NO_ACTION; + pPokCfg.pokEnSelSrcCtrl = SDL_POK_ENSEL_NO_ACTION; +#if defined (SOC_J7200) || defined (SOC_J721S2) || defined (SOC_J784S4) + pPokCfg.hystCtrlOV = SDL_PWRSS_HYSTERESIS_NO_ACTION; + pPokCfg.trimOV = SDL_PWRSS_TRIM_NO_ACTION; + pPokCfg.deglitch = SDL_PWRSS_DEGLITCH_NO_ACTION; +#endif + + sdlRet = SDL_POK_setConfig(instance, &pPokCfg); + if (sdlRet == SDL_PASS) + { + testStatus = SDL_APP_TEST_PASS; + } + else + { + testStatus = SDL_APP_TEST_FAILED; + overallStatus = SDL_APP_TEST_FAILED; + } + UART_printf("Safety software Example UC-1 pok for instance %d %s\n", + instance, (testStatus == SDL_APP_TEST_PASS) ? "PASSED" : "FAILED"); + + return (overallStatus); +} + +#if defined (SOC_J721E) +static void sdlGetInstance(SDL_POK_Inst *instance, uint32_t *esm_err_sig) +{ + switch (*esm_err_sig) + { + case ESM_ERR_SIG_POKHV_UV: + *instance = SDL_POR_POKHV_UV_ID; + break; + case ESM_ERR_SIG_POKHV_OV: + *instance = SDL_POR_POKHV_OV_ID; + break; + case ESM_ERR_SIG_POKLV_UV: + *instance = SDL_POR_POKLV_UV_ID; + break; + case ESM_ERR_SIG_VDDA_IN: + *instance = SDL_POK_VDDA_PMIC_IN_ID; + break; + case ESM_ERR_SIG_VDD_CORE_UV: + *instance = SDL_POK_VDD_CORE_UV_ID; + break; + case ESM_ERR_SIG_VDDSHV_WKUP_GEN_UV: + *instance = SDL_POK_VDDSHV_WKUP_GEN_UV_ID; + break; + case ESM_ERR_SIG_VDD_CPU_UV: + *instance = SDL_POK_VDD_CPU_UV_ID; + break; + case ESM_ERR_SIG_VDDR_MCU_UV: + *instance = SDL_POK_VDDR_MCU_UV_ID; + break; + case ESM_ERR_SIG_VMON_EXT_UV: + *instance = SDL_POK_VMON_EXT_UV_ID; + break; + case ESM_ERR_SIG_VDD_MCU_OV: + *instance = SDL_POK_VDD_MCU_OV_ID; + break; + case ESM_ERR_SIG_VDDR_CORE_UV: + *instance = SDL_POK_VDDR_CORE_UV_ID; + break; + case ESM_ERR_SIG_VDDSHV_WKUP_GEN_OV: + *instance = SDL_POK_VDDSHV_WKUP_GEN_OV_ID; + break; + case ESM_ERR_SIG_VDD_CORE_OV: + *instance = SDL_POK_VDD_CORE_OV_ID; + break; + case ESM_ERR_SIG_VDDR_MCU_OV: + *instance = SDL_POK_VDDR_MCU_OV_ID; + break; + case ESM_ERR_SIG_VDD_CPU_OV: + *instance = SDL_POK_VDD_CPU_OV_ID; + break; + case ESM_ERR_SIG_VDDR_CORE_OV: + *instance = SDL_POK_VDDR_CORE_OV_ID; + break; + case ESM_ERR_SIG_VMON_EXT_OV: + default: + *instance = SDL_POK_VMON_EXT_OV_ID; + break; + } + return; +} +#else +static void sdlGetInstance(SDL_POK_Inst *instance, uint32_t *esm_err_sig) +{ + switch (*esm_err_sig) + { + case WKUP_ESM_ERR_SIG_VDD_CORE_UV: + case WKUP_ESM_ERR_SIG_VDD_CORE_OV: + *instance = SDL_POK_VDD_CORE_ID; + break; + case WKUP_ESM_ERR_SIG_VDDR_CORE_UV: + case WKUP_ESM_ERR_SIG_VDDR_CORE_OV: + *instance = SDL_POK_VDDR_CORE_ID; + break; + case WKUP_ESM_ERR_SIG_VDD_CPU_UV: + case WKUP_ESM_ERR_SIG_VDD_CPU_OV: + *instance = SDL_POK_VDD_CPU_ID; + break; + case WKUP_ESM_ERR_SIG_VMON_EXT_UV: + case WKUP_ESM_ERR_SIG_VMON_EXT_OV: + *instance = SDL_POK_VMON_EXT_ID; + break; + case WKUP_ESM_ERR_SIG_VMON_EXT_MAIN_1P8_OV: + case WKUP_ESM_ERR_SIG_VMON_EXT_MAIN_1P8_UV: + *instance = SDL_POK_VMON_EXT_MAIN_1P8_ID; + break; + case WKUP_ESM_ERR_SIG_VMON_EXT_MAIN_3P3_OV: + case WKUP_ESM_ERR_SIG_VMON_EXT_MAIN_3P3_UV: + *instance = SDL_POK_VMON_EXT_MAIN_3P3_ID; + break; + case WKUP_ESM_ERR_SIG_VDD_MCU_OV: + *instance = SDL_POK_VDD_MCU_OV_ID; + break; + case WKUP_ESM_ERR_SIG_VDD_MCU_UV: + *instance = SDL_POR_POKLVB_UV_ID; + break; + case WKUP_ESM_ERR_SIG_VDDR_MCU_UV: + case WKUP_ESM_ERR_SIG_VDDR_MCU_OV: + *instance = SDL_POK_VDDR_MCU_ID; + break; + case WKUP_ESM_ERR_SIG_VDDSHV_WKUP_GEN_UV: + case WKUP_ESM_ERR_SIG_VDDSHV_WKUP_GEN_OV: + *instance = SDL_POK_VDDSHV_WKUP_GEN_ID; + break; + case WKUP_ESM_ERR_SIG_CAP_VDDS_MCU_GEN_UV: + case WKUP_ESM_ERR_SIG_CAP_VDDS_MCU_GEN_OV: + *instance = SDL_POK_CAP_VDDS_MCU_GEN_ID; + break; + case WKUP_ESM_ERR_SIG_VDDA_PMIC_IN_UV: + *instance = SDL_POK_VDDA_PMIC_IN_ID; + break; + case WKUP_ESM_ERR_SIG_VDDA_MCU_UV: + *instance = SDL_POR_POKHV_UV_ID; + break; + case WKUP_ESM_ERR_SIG_VDDA_MCU_OV: + *instance = SDL_POR_POKLVA_OV_ID; + break; + default: + *instance = (SDL_POK_Inst)(-1); + break; + } + return; +} + +#endif +/* Nothing past this point */ \ No newline at end of file -- 2.34.1