summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f3101fb)
raw | patch | inline | side by side (parent: f3101fb)
author | Danny Jochelson <dsjochel@ti.com> | |
Fri, 12 Jun 2020 23:44:43 +0000 (18:44 -0500) | ||
committer | Sivaraj R <sivaraj@ti.com> | |
Tue, 23 Jun 2020 04:17:48 +0000 (23:17 -0500) |
All 5 use cases for ESM example application functional.
Includes pin control for clearing the MCU_SAFETY_ERRORn
pin.
Confirmed proper functionality of the MCU_SAFETY_ERRORn
with the default minimum interval time of 100usec.
Includes pin control for clearing the MCU_SAFETY_ERRORn
pin.
Confirmed proper functionality of the MCU_SAFETY_ERRORn
with the default minimum interval time of 100usec.
13 files changed:
index a0cccf1077ce9ed296b1b851f3538433f3d416b2..b7053e629f258668dae7db9faea6125d6ffbc314 100644 (file)
export PDK_CSITX_COMP_PATH = $(PDK_CSITX_ROOT_PATH)/ti/drv/csitx
PDK_SDR_ROOT_PATH ?= $(pdk_PATH)
export PDK_SDR_COMP_PATH = $(pdk_PATH)/ti/diag/sdr
+PDK_DIAG_EX_ROOT_PATH ?= $(pdk_PATH)
+export PDK_DIAG_EX_COMP_PATH = $(pdk_PATH)/ti/diag/examples
#Below applicable only for TPR12 devices
PDK_CRC_ROOT_PATH ?= $(pdk_PATH)
index 3431169e2d31534553955a727b697312c8c61626..3cc9ac1ef203028ab63b304b76743a623d8b3a67 100644 (file)
pdk_EXAMPLE_LIST += $(sdr_EXAMPLE_LIST)
endif
+# - used to ignore include if component not present
+-include $(PDK_DIAG_EX_COMP_PATH)/diag_ex_component.mk
+ifneq ($(diag_ex_LIB_LIST),)
+ pdk_LIB_LIST += $(diag_ex_LIB_LIST)
+endif
+ifneq ($(diag_ex_APP_LIB_LIST),)
+ pdk_APP_LIB_LIST += $(diag_ex_APP_LIB_LIST)
+endif
+ifneq ($(diag_ex_EXAMPLE_LIST),)
+ pdk_EXAMPLE_LIST += $(diag_ex_EXAMPLE_LIST)
+endif
+
# - used to ignore include if component not present
-include $(PDK_IPC_COMP_PATH)/ipc_component.mk
ifneq ($(ipc_LIB_LIST),)
diff --git a/packages/ti/diag/examples/common/diag_utils.c b/packages/ti/diag/examples/common/diag_utils.c
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Diagnostic Utils
+ *
+ * Diagnostic Example utility functions
+ *
+ * Copyright (c) 2020 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.
+ */
+
+/* UART driver API header files */
+#include <ti/drv/uart/UART.h>
+#include <ti/drv/uart/UART_stdio.h>
+#include <ti/drv/uart/soc/UART_soc.h>
+
+#include <platform.h>
+#include "diag_utils.h"
+
+/**
+ * \brief This function initializes the UART instance for use for
+ * console operations.
+ *
+ * \return None
+ *
+ */
+void DIAG_uartStdioInit(void)
+{
+ UART_HwAttrs uart_cfg;
+
+ /* Disable the UART interrupt */
+ (void)UART_socGetInitCfg(UART_INSTANCE, &uart_cfg);
+ uart_cfg.enableInterrupt = FALSE;
+ (void)UART_socSetInitCfg(UART_INSTANCE, &uart_cfg);
+
+ UART_stdioInit(UART_INSTANCE);
+ return;
+}
+
diff --git a/packages/ti/diag/examples/common/diag_utils.h b/packages/ti/diag/examples/common/diag_utils.h
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Diagnostic Utils
+ *
+ * Diagnostic Example utility functions
+ *
+ * Copyright (c) 2020 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.
+ */
+#ifndef INCLUDE_DIAG_UTILS_H_
+#define INCLUDE_DIAG_UTILS_H_
+
+/* Platform-specific header file */
+#include <platform.h>
+
+#ifdef UART_PRINTF
+#include <ti/drv/uart/UART_stdio.h>
+#define DIAG_printf UART_printf
+#else
+#include <stdio.h>
+#define DIAG_printf printf
+#endif
+
+void DIAG_uartStdioInit(void);
+
+#endif /* INCLUDE_DIAG_UTILS_H_ */
diff --git a/packages/ti/diag/examples/diag_ex_component.mk b/packages/ti/diag/examples/diag_ex_component.mk
--- /dev/null
@@ -0,0 +1,103 @@
+# File: diag_ex_component.mk
+# This file is component include make file of Software Diagnostic Example
+# Applications.
+# List of variables set in this file and their purpose:
+# <mod>_RELPATH - This is the relative path of the module, typically from
+# top-level directory of the package
+# <mod>_PATH - This is the absolute path of the module. It derives from
+# absolute path of the top-level directory (set in env.mk)
+# and relative path set above
+# <mod>_INCLUDE - This is the path that has interface header files of the
+# module. This can be multiple directories (space separated)
+# <mod>_PKG_LIST - Names of the modules (and sub-modules) that are a part
+# part of this module, including itself.
+# <mod>_BOARD_DEPENDENCY - "yes": means the code for this module depends on
+# platform and the compiled obj/lib has to be kept
+# under <platform> directory
+# "no" or "" or if this variable is not defined: means
+# this module has no platform dependent code and hence
+# the obj/libs are not kept under <platform> dir.
+# <mod>_CORE_DEPENDENCY - "yes": means the code for this module depends on
+# core and the compiled obj/lib has to be kept
+# under <core> directory
+# "no" or "" or if this variable is not defined: means
+# this module has no core dependent code and hence
+# the obj/libs are not kept under <core> dir.
+# <mod>_APP_STAGE_FILES - List of source files that belongs to the module
+# <mod>, but that needs to be compiled at application
+# build stage (in the context of the app). This is
+# primarily for link time configurations or if the
+# source file is dependent on options/defines that are
+# application dependent. This can be left blank or
+# not defined at all, in which case, it means there
+# no source files in the module <mod> that are required
+# to be compiled in the application build stage.
+#
+ifeq ($(diag_ex_component_make_include), )
+
+############################
+# Software Diagnostics Example Applications
+# List of components included under Diagnostic Example applications
+# The components included here are built and will be part of Diagnostic Example apps
+############################
+diag_ex_LIB_LIST =
+
+diag_ex_SOCLIST = j721e
+diag_ex_BOARDLIST = j721e_evm
+diag_ex_j721e_CORELIST = mcu1_0
+diag_ex_j721e_APPCORELIST = mcu1_0
+diag_ex_DISABLE_PARALLEL_MAKE = yes
+
+############################
+# Software diagnostic examples package
+# List of software diagnostics included under diagnostic examples
+# The components included here are built and will be part of software diagnostic examples
+############################
+diag_ex_LIB_LIST =
+
+############################
+# Software Diagnostic examples
+# List of examples under diag_ex (+= is used at each example definition)
+# All the tests mentioned in list are built when test target is called
+# List below all examples for allowed values
+############################
+diag_ex_EXAMPLE_LIST =
+
+# Diagnostic Example Application have no locally built library components
+
+diag_ex_COMP_LIST = diag_ex
+
+#
+# Software Diagnostic Application Examples
+#
+
+# ESM example
+diag_ex_esm_example_app_COMP_LIST = diag_ex_esm_example_app
+diag_ex_esm_example_app_RELPATH = ti/diag/examples/esm_example_app
+diag_ex_esm_example_app_PATH = $(PDK_DIAG_EX_COMP_PATH)/esm_example_app
+diag_ex_esm_example_app_MAKEFILE = -f makefile
+diag_ex_esm_example_app_BOARD_DEPENDENCY = yes
+diag_ex_esm_example_app_CORE_DEPENDENCY = yes
+export diag_ex_esm_example_app_COMP_LIST
+export diag_ex_esm_example_app_BOARD_DEPENDENCY
+export diag_ex_esm_example_app_CORE_DEPENDENCY
+export diag_ex_esm_example_app_MAKEFILE
+diag_ex_esm_example_app_PKG_LIST = diag_ex_esm_example_app
+diag_ex_esm_example_app_INCLUDE = $(diag_ex_esm_example_app_PATH)
+diag_ex_esm_example_app_BOARDLIST = $(diag_ex_BOARDLIST)
+export diag_ex_esm_example_app_BOARDLIST
+diag_ex_esm_example_app_$(SOC)_CORELIST = $(diag_ex_$(SOC)_CORELIST)
+export diag_ex_esm_example_app_$(SOC)_CORELIST
+export diag_ex_esm_example_app_SBL_APPIMAGEGEN = yes
+
+diag_ex_EXAMPLE_LIST += diag_ex_esm_example_app
+
+export diag_ex_LIB_LIST
+export diag_ex_EXAMPLE_LIST
+
+DIAG_EX_CFLAGS =
+
+export DIAG_EX_CFLAGS
+
+diag_ex_component_make_include := 1
+endif
diff --git a/packages/ti/diag/examples/esm_example_app/esm.c b/packages/ti/diag/examples/esm_example_app/esm.c
--- /dev/null
@@ -0,0 +1,602 @@
+/*
+ * ESM Example
+ *
+ * Error Signaling Module (ESM) Example Application
+ *
+ * Copyright (c) 2020 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 esm.c
+ *
+ * \brief ESM utility functions and handler ISR's
+ */
+
+/* ========================================================================== */
+/* Include Files */
+/* ========================================================================== */
+/* For Timer functions */
+#include <ti/osal/osal.h>
+
+/* For interrupt ID numbers */
+#include <ti/csl/soc/cslr_soc_intr.h>
+
+/* Diagnostic example utility functions, e.g. print outputs */
+#include <diag_utils.h>
+#include <sdr_esm.h>
+
+#include "esm.h"
+#include "event_trig.h"
+
+/* ========================================================================== */
+/* Macros & Typedefs */
+/* ========================================================================== */
+
+#define MAX_ESM_EVENTS_LOGGED (20)
+#define MAX_ESM_INSTANCE (SDR_ESM_INSTANCE_MAIN)
+#define MAX_ESM_INT_TYPE (SDR_ESM_INT_TYPE_CFG)
+
+/* ESM event log entry */
+typedef struct
+{
+ SDR_ESM_InstanceType esmInstance;
+ SDR_ESM_IntType intType;
+ uint32_t grpChannel;
+ uint32_t index;
+ uint32_t intSrc;
+ uint8_t useCaseNum;
+} ESM_Example_log_entry_t;
+
+/* ========================================================================== */
+/* Structure Declarations */
+/* ========================================================================== */
+
+/* None */
+
+/* ========================================================================== */
+/* Function Declarations */
+/* ========================================================================== */
+
+static int32_t ESM_Example_EsmInitHandlerInit(SDR_ESM_InstanceType esmInstType);
+
+/* ========================================================================== */
+/* Global Variables */
+/* ========================================================================== */
+
+static ESM_Example_log_entry_t esmEventLog[MAX_ESM_EVENTS_LOGGED];
+static uint32_t totalEventsLogged = 0;
+static uint32_t totalHiEventsLogged = 0;
+static uint32_t totalLoEventsLogged = 0;
+static int32_t thresholdsReset = 0;
+
+/* Initialization structure for MCU ESM instance */
+static SDR_ESM_InitConfig_t ESM_Example_esmInitConfig_MCU =
+{
+ .esmErrorConfig = {0u, 3u}, /* Self test error config */
+ .eventMap = {0xffffffffu, 0x033fffffu, 0x7fffffffu, 0xffffffe7u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ },
+ /**< All events enable: except timer and self test events, */
+ /* and Main ESM output. Disabling vim compare error as well.
+ * Exclude MCU Timer 0, which is left on by SBL in continuous mode,
+ * and MCU Timer 1, which is used for controlling the Output pin clearing.
+ * MCU Timer 2 set to High Priority with output pin routing.
+ * MCU Timer 3 set to Low Priorirty with no Output pin routing. */
+ .eventPriorityMap = {0xffffffffu, 0x013fffffu, 0x7fffffffu, 0xffffffe6u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ },
+ /**< All events high priority: except timer, selftest error events,
+ * and Main ESM output. Exclude MCU Timer 0, which is left on by
+ * SBL in continuous mode, and MCU Timer 1, which is used for controlling
+ * the Output pin clearing.
+ * MCU Timer 2 set to High Priority with output pin routing.
+ * MCU Timer 3 set to Low Priorirty with no Output pin routing. */
+ .errorOutputMap = {0xffffffffu, 0x013fffffu, 0x7fffffffu, 0xffffffe6u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ },
+ /**< All events high priority: except timer, selftest error events,
+ * and Main ESM output. Exclude MCU Timer 0, which is left on by
+ * SBL in continuous mode, and MCU Timer 1, which is used for controlling
+ * the Output pin clearing.
+ * MCU Timer 2 set to High Priority with output pin routing.
+ * MCU Timer 3 set to Low Priorirty with no Output pin routing. */
+};
+
+/* Initialization structure for WKUP ESM instance */
+static SDR_ESM_InitConfig_t ESM_Example_esmInitConfig_WKUP =
+{
+ .esmErrorConfig = {0u, 0u}, /* Self test error config */
+ .eventMap = {0xffffffffu, 0x00180003u, 0xffffffffu, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ },
+ /**< All events enable: except clkstop events for unused clocks */
+ .eventPriorityMap = {0xfffffcffu, 0x00180003u, 0xffffffffu, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ },
+ /**< All events high priority: except clkstop events for unused clocks,
+ * and make VTM WKUP_VTM0_THERM_LVL_GT_TH1_INTR_0 and
+ * WKUP_VTM0_THERM_LVL_LT_TH0_INTR_0 events low priority */
+ .errorOutputMap = {0xfffffcffu, 0x00180003u, 0xffffffffu, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u,
+ },
+ /**< All events high priority: except clkstop for unused clocks
+ * and make VTM WKUP_VTM0_THERM_LVL_GT_TH1_INTR_0 and
+ * WKUP_VTM0_THERM_LVL_LT_TH0_INTR_0 events not output to pin */
+};
+
+static HwiP_Handle ESM_Example_EsmHiHwiPHandle;
+static HwiP_Handle ESM_Example_EsmLoHwiPHandle;
+static HwiP_Handle ESM_Example_EsmCfgHwiPHandle;
+
+/* ========================================================================== */
+/* External Variables */
+/* ========================================================================== */
+
+/* Completion of Use Case from ESM Handler perspective updates these flags */
+extern volatile uint32_t esmOutputResult[5];
+/* Current use case being run */
+extern volatile uint8_t currUseCase;
+
+/* ========================================================================== */
+/* Function Definitions */
+/* ========================================================================== */
+
+/*********************************************************************
+* @fn ESM_Example_init
+*
+* @brief Initializes Board, Timers, and ESM module
+*
+* @param None
+*
+* @return 0 : Success; < 0 for failures
+*/
+int32_t ESM_Example_init (void)
+{
+ int32_t retValue=0;
+ SDR_Result result;
+
+#ifdef UART_PRINTF
+ /* Initialize UART instance */
+ DIAG_uartStdioInit();
+#endif
+
+ DIAG_printf("\nESM_Example_init: UART ready to print, proceeding with ESM Example init \n");
+
+ if (retValue == 0) {
+ /* Initialize MCU ESM module */
+ result = SDR_ESM_init(SDR_ESM_INSTANCE_MCU, &ESM_Example_esmInitConfig_MCU);
+ if (result != SDR_PASS) {
+ /* print error and quit */
+ DIAG_printf("ESM_Example_init: Error initializing MCU ESM: result = %d\n", result);
+
+ retValue = -1;
+ } else {
+ DIAG_printf("\nESM_Example_init: Init MCU ESM complete \n");
+ }
+ }
+
+ if (retValue == 0) {
+ /* Initialize WKUP ESM module */
+ result = SDR_ESM_init(SDR_ESM_INSTANCE_WKUP, &ESM_Example_esmInitConfig_WKUP);
+ if (result != SDR_PASS) {
+ /* print error and quit */
+ DIAG_printf("ESM_Example_init: Error initializing WKUP ESM: result = %d\n", result);
+
+ retValue = -1;
+ } else {
+ DIAG_printf("\nESM_Example_init: Init WKUP ESM complete \n");
+ }
+ }
+
+ if (retValue == 0) {
+ /* Register MCU Esm handlers */
+ retValue = ESM_Example_EsmInitHandlerInit(SDR_ESM_INSTANCE_MCU);
+ if (retValue != 0) {
+ DIAG_printf("\nESM_Example_init: Init MCU ESM handlers failed \n");
+ } else {
+ DIAG_printf("\nESM_Example_init: Init MCU ESM handlers complete \n");
+ }
+
+ /* Register WKUP Esm handlers */
+ retValue = ESM_Example_EsmInitHandlerInit(SDR_ESM_INSTANCE_WKUP);
+ if (retValue != 0) {
+ DIAG_printf("\nESM_Example_init: Init WKUP ESM handlers failed \n");
+ } else {
+ DIAG_printf("\nESM_Example_init: Init WKUP ESM handlers complete \n");
+ }
+ }
+
+ return retValue;
+}
+
+/*********************************************************************
+* @fn ESM_Example_EsmInitHandlerInit
+*
+* @brief Register all callbacks for an ESM instance
+*
+* @param esmInstType: Instance type of ESM
+*
+* @return 0 : Success; < 0 for failures
+*/
+static int32_t ESM_Example_EsmInitHandlerInit(SDR_ESM_InstanceType esmInstType)
+{
+ int32_t result = 0;
+ uint32_t intNumHi, intNumLo, intNumCfg;
+ HwiP_Params hwiParams;
+ void (*pHiInterruptHandler)(uintptr_t);
+ void (*pLoInterruptHandler)(uintptr_t);
+ void (*pConfigInterruptHandler)(uintptr_t);
+
+ switch (esmInstType) {
+ case (SDR_ESM_INSTANCE_WKUP):
+ pHiInterruptHandler = &SDR_ESM_hiInterruptHandler_WKUP;
+ pLoInterruptHandler = &SDR_ESM_loInterruptHandler_WKUP;
+ pConfigInterruptHandler = &SDR_ESM_configInterruptHandler_WKUP;
+ break;
+
+ case (SDR_ESM_INSTANCE_MAIN):
+ pHiInterruptHandler = &SDR_ESM_hiInterruptHandler_MAIN;
+ pLoInterruptHandler = &SDR_ESM_loInterruptHandler_MAIN;
+ pConfigInterruptHandler = &SDR_ESM_configInterruptHandler_MAIN;
+ break;
+
+ case (SDR_ESM_INSTANCE_MCU):
+ default:
+ pHiInterruptHandler = &SDR_ESM_hiInterruptHandler_MCU;
+ pLoInterruptHandler = &SDR_ESM_loInterruptHandler_MCU;
+ pConfigInterruptHandler = &SDR_ESM_configInterruptHandler_MCU;
+ break;
+ }
+
+ /* Get the interrupt number corresponding to ESM HI interrupt */
+ intNumHi = SDR_ESM_getIntNumber(esmInstType,
+ SDR_ESM_INT_TYPE_HI);
+ if ( intNumHi == SDR_ESM_INTNUMBER_INVALID ) {
+ result = -1;
+ } else {
+ /* Get the interrupt number corresponding to ESM LO interrupt */
+ intNumLo = SDR_ESM_getIntNumber(esmInstType,
+ SDR_ESM_INT_TYPE_LO);
+ if ( intNumLo == SDR_ESM_INTNUMBER_INVALID ) {
+ result = -1;
+ } else {
+ /* Get the interrupt number corresponding to ESM Config interrupt */
+ intNumCfg = SDR_ESM_getIntNumber(esmInstType,
+ SDR_ESM_INT_TYPE_CFG);
+ if ( intNumCfg == SDR_ESM_INTNUMBER_INVALID ) {
+ result = -1;
+ } else {
+ DIAG_printf("\n ESM_Example_EsmInitHandlerInit: " \
+ "Obtain interrupt number complete \n");
+ /* Clear all interrupts first */
+ HwiP_disableInterrupt(intNumHi);
+ HwiP_disableInterrupt(intNumLo);
+ HwiP_disableInterrupt(intNumCfg);
+
+ DIAG_printf("\n ESM_Example_EsmInitHandlerInit: " \
+ "Disable interrupts complete \n");
+
+ /* Default parameter initialization */
+ HwiP_Params_init(&hwiParams);
+
+ hwiParams.arg = intNumHi;
+ DIAG_printf("\n ESM_Example_EsmInitHandlerInit: " \
+ "HwiP_Params_init complete \n");
+
+ /* Register call back function for ESM Hi Interrupt */
+ ESM_Example_EsmHiHwiPHandle = HwiP_create(intNumHi,
+ (HwiP_Fxn)(*pHiInterruptHandler),
+ (void *)&hwiParams);
+ DIAG_printf("\n ESM_Example_EsmInitHandlerInit: " \
+ "intNumHi registration complete \n");
+ if (ESM_Example_EsmHiHwiPHandle == (HwiP_Handle) NULL) {
+ result = -1;
+ } else {
+ hwiParams.arg = intNumLo;
+ /* Register call back function for ESM Lo Interrupt */
+ ESM_Example_EsmLoHwiPHandle = HwiP_create(intNumLo,
+ (HwiP_Fxn)(*pLoInterruptHandler),
+ (void *)&hwiParams);
+ DIAG_printf("\n ESM_Example_EsmInitHandlerInit: " \
+ "intNumLo registration complete \n");
+ if (ESM_Example_EsmLoHwiPHandle == (HwiP_Handle) NULL) {
+ result = -1;
+ } else {
+ hwiParams.arg = intNumCfg;
+ /* Register call back function for ESM Config Interrupt */
+ ESM_Example_EsmCfgHwiPHandle = HwiP_create(intNumCfg,
+ (HwiP_Fxn)(*pConfigInterruptHandler),
+ (void *)&hwiParams);
+ DIAG_printf("\n ESM_Example_EsmInitHandlerInit: " \
+ "intNumCfg registration complete \n");
+ if (ESM_Example_EsmCfgHwiPHandle == (HwiP_Handle) NULL) {
+ result = -1;
+ } else {
+ /* Enable all ESM Interrupts */
+ HwiP_enableInterrupt(intNumHi);
+ HwiP_enableInterrupt(intNumLo);
+ HwiP_enableInterrupt(intNumCfg);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+}
+
+static int32_t deactivateTrigger(SDR_ESM_InstanceType esmInstType,
+ SDR_ESM_IntType esmIntType,
+ uint32_t intEsmSrc)
+{
+ int32_t retVal = 0;
+
+ if ((esmInstType == SDR_ESM_INSTANCE_WKUP) && (esmIntType == SDR_ESM_INT_TYPE_LO)) {
+ /* UC-1: Low Priority interrupt on WKUP ESM -
+ * VTM greater than THR1 */
+ if (intEsmSrc ==
+ CSLR_WKUP_ESM0_ESM_LVL_EVENT_WKUP_VTM0_THERM_LVL_GT_TH1_INTR_0)
+ {
+ if (currUseCase == 0)
+ {
+ if (thresholdsReset == 0)
+ {
+ /* Simulate thresholds as if temperature is going to be reduced
+ * below lt_Thr0 */
+ diag_esm_setNormalThresholds();
+#ifdef DEBUG_PRINT
+ diag_esm_printCurrentThresholds();
+#endif
+ thresholdsReset = 1;
+ }
+ diag_esm_vtmGtThr1CrossedUpdateInt();
+ } else if ((currUseCase == 1) || (currUseCase == 2))
+ {
+ if (thresholdsReset == 0)
+ {
+ /* Simulate thresholds as if temperature continues to increase
+ * toward gt_Thr2 */
+ diag_esm_setThresholdsForCriticalTrigger();
+#ifdef DEBUG_PRINT
+ diag_esm_printCurrentThresholds();
+#endif
+ thresholdsReset = 1;
+ }
+ diag_esm_vtmGtThr1CrossedUpdateInt();
+ }
+ } else if (intEsmSrc ==
+ CSLR_WKUP_ESM0_ESM_LVL_EVENT_WKUP_VTM0_THERM_LVL_LT_TH0_INTR_0)
+ {
+ diag_esm_vtmLtThr0CrossedUpdateInt();
+#ifdef DEBUG_PRINT
+ diag_esm_printCurrentThresholds();
+#endif
+ thresholdsReset = 0;
+ esmOutputResult[currUseCase] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+ if (currUseCase == 1) {
+ /* At end of this use case, clear the Pin that was left on
+ * throughout the use case*/
+ Osal_delay(4);
+ diag_esm_startPinClearTimer(true);
+ }
+ }
+ } else if ((esmInstType == SDR_ESM_INSTANCE_WKUP) &&
+ (esmIntType == SDR_ESM_INT_TYPE_HI)) {
+ if ((currUseCase == 1) || (currUseCase == 2)) {
+ /* UC-2: High Priority interrupt on WKUP ESM -
+ * VTM greater than THR2, no clearing of
+ * MCU_SAFETY_ERRORn pin */
+ /* UC-3: High Priority interrupt on WKUP ESM -
+ * VTM greater than THR2 with clearing
+ * of MCU_SAFETY_ERRORn pin */
+ if (thresholdsReset == 1)
+ {
+ /* Simulate thresholds as if temperature is going to be reduced
+ * below lt_Thr0 */
+ diag_esm_setNormalThresholds();
+#ifdef DEBUG_PRINT
+ diag_esm_printCurrentThresholds();
+#endif
+ thresholdsReset = 2;
+ }
+ if (currUseCase == 2) {
+ diag_esm_startPinClearTimer(false);
+ }
+ diag_esm_vtmGtThr2CrossedUpdateInt();
+ } else {
+ retVal = -1;
+ }
+ } else if (((esmInstType == SDR_ESM_INSTANCE_MCU) &&
+ (esmIntType == SDR_ESM_INT_TYPE_LO)) ||
+ ((esmInstType == SDR_ESM_INSTANCE_MCU) &&
+ (esmIntType == SDR_ESM_INT_TYPE_HI))) {
+ /* UC-4: Low Priority interrupt on MCU ESM -
+ * MCU TIMER 2 expiration */
+ /* UC-5: High Priority interrupt on MCU ESM -
+ * MCU TIMER 1 expiration */
+ /* Clear the timer interrupt */
+ retVal = diag_esm_timerUpdateInt(intEsmSrc);
+ if (retVal == 0) {
+ esmOutputResult[currUseCase] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+ }
+ } else {
+ DIAG_printf("ERR: Unexpected ESM Instance %d and ESM Interrupt Type %d \n",
+ esmInstType, esmIntType);
+ retVal = -1;
+ }
+
+ return (retVal);
+}
+
+static const char *printEsmIntType(SDR_ESM_IntType esmIntType)
+{
+ char *pStr;
+
+ switch(esmIntType)
+ {
+ case SDR_ESM_INT_TYPE_HI:
+ pStr = "High Priority ESM event";
+ break;
+ case SDR_ESM_INT_TYPE_LO:
+ pStr = "Low Priority ESM event";
+ break;
+ case SDR_ESM_INT_TYPE_CFG:
+ pStr = "Config ESM event";
+ break;
+ default:
+ pStr = NULL;
+ break;
+ }
+
+ return pStr;
+}
+
+/*********************************************************************
+* @fn ESM_Example_printSummary
+*
+* @brief Print summary of all the example use cases run
+*
+* @param None
+*
+* @return None
+*/
+void ESM_Example_printSummary(void)
+{
+ int32_t i;
+
+ DIAG_printf("\n\n");
+ DIAG_printf("ESM Example Application summary\n");
+ DIAG_printf("-------------------------------\n");
+ DIAG_printf("Completed %d Use Cases\n", currUseCase);
+ DIAG_printf("Received %d High Priority Interrupts\n", totalHiEventsLogged);
+ DIAG_printf("Received %d Low Priority Interrupts\n", totalLoEventsLogged);
+
+ DIAG_printf("\nUse Case Event Log\n");
+ DIAG_printf("------------------\n");
+ for (i = 0; i < totalEventsLogged; i++) {
+ DIAG_printf("\nUse Case %d: ESM Call back function called : grpChannel 0x%x, " \
+ "index 0x%x, intSrc 0x%x \n",
+ esmEventLog[i].useCaseNum,
+ esmEventLog[i].grpChannel,
+ esmEventLog[i].index,
+ esmEventLog[i].intSrc);
+ DIAG_printf(" ESM instance #%d, ESM interrupt type = %s\n",
+ esmEventLog[i].esmInstance,
+ printEsmIntType(esmEventLog[i].intType));
+
+ }
+}
+
+void SDR_ESM_applicationCallbackFunction(SDR_ESM_InstanceType esmInstType,
+ SDR_ESM_IntType esmIntType,
+ uint32_t grpChannel,
+ uint32_t index,
+ uint32_t intSrc)
+{
+ /* Log the event */
+ esmEventLog[totalEventsLogged].useCaseNum = currUseCase;
+ esmEventLog[totalEventsLogged].esmInstance = esmInstType;
+ esmEventLog[totalEventsLogged].intType = esmIntType;
+ esmEventLog[totalEventsLogged].grpChannel = grpChannel;
+ esmEventLog[totalEventsLogged].index = index;
+ esmEventLog[totalEventsLogged].intSrc = intSrc;
+
+ totalEventsLogged++;
+ if (esmIntType == SDR_ESM_INT_TYPE_HI) {
+ totalHiEventsLogged++;
+ } else if (esmIntType == SDR_ESM_INT_TYPE_LO) {
+ totalLoEventsLogged++;
+ }
+
+ /* Any additional customer-specific actions to address ESM event
+ * can be added here */
+
+ deactivateTrigger(esmInstType, esmIntType, intSrc);
+
+#ifdef PRINT_EVENTS
+ /* Print information to screen */
+ DIAG_printf("\n ESM Call back function called : instType 0x%x, intType 0x%x, " \
+ "grpChannel 0x%x, index 0x%x, intSrc 0x%x \n",
+ esmInstType, esmIntType, grpChannel, index, intSrc);
+ DIAG_printf(" Take action \n");
+
+ DIAG_printf(" ESM instance #%d, ESM interrupt type = %s\n",
+ esmInstType, printEsmIntType(esmIntType));
+#endif
+ esmOutputResult[currUseCase]= USE_CASE_STATUS_COMPLETED_SUCCESS;
+
+ return;
+}
+
+void SDR_assertExternalFunction(SDR_assertErrorNumber errorNumber)
+{
+
+ DIAG_printf("\n Assert called with error Number %d \n",
+ errorNumber);
+ /* Asserts are fatal: Currently just wait for ever */
+ while(1);
+}
diff --git a/packages/ti/diag/examples/esm_example_app/esm.h b/packages/ti/diag/examples/esm_example_app/esm.h
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * ESM Example
+ *
+ * Error Signaling Module (ESM) Example Application
+ *
+ * Copyright (c) 2020 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.
+ */
+#ifndef INCLUDE_ESM_H_
+#define INCLUDE_ESM_H_
+
+/*===========================================================================*/
+/* Internal function declarations */
+/*===========================================================================*/
+
+/*********************************************************************
+* @fn ESM_Example_init
+*
+* @brief Initializes Board and ESM module
+*
+* @param None
+*
+* @return 0 : Success; < 0 for failures
+*/
+int32_t ESM_Example_init (void);
+
+/*********************************************************************
+* @fn ESM_Example_printSummary
+*
+* @brief Print summary of all the example use cases run
+*
+* @param None
+*
+* @return None
+*/
+void ESM_Example_printSummary(void);
+
+#endif /* INCLUDE_ESM_H_ */
diff --git a/packages/ti/diag/examples/esm_example_app/event_trig.c b/packages/ti/diag/examples/esm_example_app/event_trig.c
--- /dev/null
@@ -0,0 +1,863 @@
+/*
+ * ESM Example
+ *
+ * Error Signaling Module (ESM) Example Application
+ *
+ * Copyright (c) 2020 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 event_trig.c
+ *
+ * \brief This file contains functions that provide input event triggers
+ * for the Error Signaling Module (ESM) application.
+ */
+
+/* ========================================================================== */
+/* Include Files */
+/* ========================================================================== */
+
+/* For Timer functions */
+#include <ti/osal/osal.h>
+
+#include <ti/drv/sciclient/sciclient.h>
+
+/* Diagnostic example utility functions, e.g. print outputs */
+#include <diag_utils.h>
+
+#include <ti/csl/soc.h>
+#include <ti/csl/csl_vtm.h>
+#include <ti/csl/csl_esm.h>
+
+#include <sdr_esm.h>
+#include "event_trig.h"
+
+/* ========================================================================== */
+/* Macros & Typedefs */
+/* ========================================================================== */
+
+#define PIN_TIMING_TIMER_ID (1)
+#define HIGH_PRIO_TRIG_TIMER_ID (2)
+#define LOW_PRIO_TRIG_TIMER_ID (3)
+
+#define CSL_VTM_TEST_CFG1_BASE (CSL_WKUP_VTM0_MMR_VBUSP_CFG1_BASE)
+#define CSL_VTM_TEST_CFG2_BASE (CSL_WKUP_VTM0_MMR_VBUSP_CFG2_BASE)
+
+#define LT_THR0_DEFAULT (95000)
+#define GT_THR1_DEFAULT (105000)
+#define GT_THR2_DEFAULT (115000)
+
+#define PIN_CLEAR_PERIOD_USEC (10)
+
+/* ========================================================================== */
+/* Structure Declarations */
+/* ========================================================================== */
+
+/* None */
+
+/* ========================================================================== */
+/* Function Declarations */
+/* ========================================================================== */
+
+static void timerExpTrigger(uintptr_t arg);
+static int32_t vtmTriggerTh(int32_t lt_thr0_offset,
+ int32_t gt_thr1_offset,
+ int32_t gt_thr2_offset);
+static int32_t vtmTriggerTh1(void);
+static void setAllVTMTempThr(CSL_vtm_adc_code lt_thr0_adc_code,
+ CSL_vtm_adc_code gt_thr1_adc_code,
+ CSL_vtm_adc_code gt_thr2_adc_code);
+static void timerExpPinDisable(uintptr_t arg);
+
+/* ========================================================================== */
+/* Global Variables */
+/* ========================================================================== */
+
+/* Completion of Use Case from Input trigger perspective updates these flags */
+extern volatile uint32_t esmEventInputTrig[5];
+/* Completion of Use Case from Output Pin clearing perspective updates these flags */
+extern volatile uint32_t esmPinClearResult[5];
+/* Current use case being run */
+extern volatile uint8_t currUseCase;
+
+static uint32_t esmPinMinIntervalCycles;
+static uint32_t esmPinMinIntervalUsec;
+static uint32_t pinClearTimeCycles;
+static bool immediatePinClear;
+
+static TimerP_Handle esmHiEventTrigTimerHandle;
+static TimerP_Handle esmLoEventTrigTimerHandle;
+static TimerP_Handle esmPinTimerHandle;
+static SDR_ESM_InstanceType currEsmInstance;
+
+/* ========================================================================== */
+/* External Variables */
+/* ========================================================================== */
+
+/* None */
+
+/* ========================================================================== */
+/* Function Definitions */
+/* ========================================================================== */
+
+
+/*********************************************************************
+* @fn esmPinTimeInit
+*
+* @brief This checks current timings for the minimum interval time
+* on the MCU_SAFETY_ERRORn pin for eacl Error Signaling Module
+*
+* @param pinClearTime: Amount of time in microseconds that the Pin control
+* timer waits before triggering clearing of the MCU_SAFETY_ERRORn pin
+*
+* @return 0 : Success; < 0 for failures
+*/
+int32_t esmPinTimeInit(uint32_t pinClearTime)
+{
+ int32_t retVal = 0;
+ uint32_t modId;
+ uint32_t clkId;
+ uint64_t esmInputClk;
+
+ ESMGetErrPinLowTimePreload(CSL_MCU_ESM0_CFG_BASE, &esmPinMinIntervalCycles);
+#ifdef PRINT_DEBUG
+ DIAG_printf(" MCU ESM pin minimum interval is %d cycles\n",
+ esmPinMinIntervalCycles);
+#endif
+ ESMGetErrPinLowTimePreload(CSL_WKUP_ESM0_CFG_BASE, &esmPinMinIntervalCycles);
+#ifdef PRINT_DEBUG
+ DIAG_printf(" WKUP ESM pin minimum interval is %d cycles\n",
+ esmPinMinIntervalCycles);
+#endif
+
+ /* WKUP ESM clock */
+ modId = TISCI_DEV_WKUP_ESM0;
+ clkId = TISCI_DEV_WKUP_ESM0_CLK;
+
+ retVal = Sciclient_pmGetModuleClkFreq(modId,
+ clkId,
+ &esmInputClk,
+ SCICLIENT_SERVICE_WAIT_FOREVER);
+#ifdef PRINT_DEBUG
+ DIAG_printf(" WKUP ESM input clock is %d\n", esmInputClk);
+#endif
+ /* MCU ESM clock */
+ modId = TISCI_DEV_MCU_ESM0;
+ clkId = TISCI_DEV_MCU_ESM0_CLK;
+
+ retVal = Sciclient_pmGetModuleClkFreq(modId,
+ clkId,
+ &esmInputClk,
+ SCICLIENT_SERVICE_WAIT_FOREVER);
+#ifdef PRINT_DEBUG
+ DIAG_printf(" MCU ESM input clock is %d\n", esmInputClk);
+#endif
+
+ /* Translate Pin Timer Time (microseconds) into number of ESM cycles */
+ pinClearTimeCycles = (uint32_t)((float)pinClearTime /
+ 1000000 * (float)esmInputClk);
+ DIAG_printf("\n Any clear of MCU_SAFETY_ERRORn pin will first wait " \
+ "%d usecs", pinClearTime);
+ /* Translate Minimum Time Interval (cycles) into time (microseconds)*/
+ esmPinMinIntervalUsec = (uint32_t)((float)esmPinMinIntervalCycles /
+ (float)esmInputClk * 1000000);
+ DIAG_printf("\n Minimum Time Interval is %d usecs", esmPinMinIntervalUsec);
+
+ /* If desired, ESMSetErrPinLowTimePreload can be used to change
+ * minimum interval time here */
+
+ return retVal;
+}
+
+/* TIMER FUNCTIONS */
+
+/*********************************************************************
+* @fn diag_esm_timerInit
+*
+* @brief This initializes all timers for the Error Signaling Module (ESM)
+* example application.
+*
+* @param None
+*
+* @return 0 : Success; < 0 for failures
+*/
+int32_t diag_esm_timerInit(void)
+{
+ TimerP_Params timerParams;
+
+ /* Start Timer and register call back for periodic functions */
+ /* Initialize timer parameters */
+ TimerP_Params_init(&timerParams);
+
+ /* Configure periodic timer for 0.005 sec*/
+ timerParams.period = 5000; /* 0.005s */
+ timerParams.periodType = TimerP_PeriodType_MICROSECS;
+ timerParams.arg = (void *)HIGH_PRIO_TRIG_TIMER_ID;
+ timerParams.startMode = TimerP_StartMode_USER;
+ timerParams.runMode = TimerP_RunMode_ONESHOT;
+
+ /* Create High Priority Event Trigger Timer */
+ esmHiEventTrigTimerHandle = TimerP_create(HIGH_PRIO_TRIG_TIMER_ID,
+ (TimerP_Fxn)&timerExpTrigger,
+ &timerParams);
+ if (esmHiEventTrigTimerHandle == NULL) {
+ DIAG_printf("ERR: High Priority Trigger Timer create failed\n");
+ return -1;
+ }
+
+ /* Low Priority timer has same settings as High Priority timer
+ * but just different timer instance */
+ timerParams.arg = (void *)LOW_PRIO_TRIG_TIMER_ID;
+
+ /* Create Low Priority Event Trigger Timer */
+ esmLoEventTrigTimerHandle = TimerP_create(LOW_PRIO_TRIG_TIMER_ID,
+ (TimerP_Fxn)&timerExpTrigger,
+ &timerParams);
+ if (esmLoEventTrigTimerHandle == NULL) {
+ DIAG_printf("ERR: Low Priority Trigger Timer create failed\n");
+ return -1;
+ }
+
+ /* Configure periodic timer for 10 microseconds */
+ timerParams.period = PIN_CLEAR_PERIOD_USEC; /* 10 usec */
+ timerParams.periodType = TimerP_PeriodType_MICROSECS;
+ timerParams.arg = (void *)&currEsmInstance;
+ timerParams.startMode = TimerP_StartMode_USER;
+ timerParams.runMode = TimerP_RunMode_ONESHOT;
+
+ /* Create Timer for Pin Control */
+ esmPinTimerHandle = TimerP_create(PIN_TIMING_TIMER_ID,
+ (TimerP_Fxn)&timerExpPinDisable,
+ &timerParams);
+ if (esmPinTimerHandle == NULL) {
+ DIAG_printf("ERR: Pin Control and Measurment Timer create failed\n");
+ return -1;
+ }
+
+ esmPinTimeInit(PIN_CLEAR_PERIOD_USEC);
+
+ DIAG_printf("\nESM example timer initialization complete\n");
+
+ return 0;
+}
+
+/*********************************************************************
+* @fn diag_esm_timerDelete
+*
+* @brief This deletes all timers for the Error Signaling Module (ESM)
+* example application.
+*
+* @param None
+*
+* @return 0 : Success; < 0 for failures
+*/
+int32_t diag_esm_timersDelete(void)
+{
+ int32_t retVal = 0;
+
+ if (esmHiEventTrigTimerHandle != NULL_PTR) {
+ if (TimerP_delete(esmHiEventTrigTimerHandle) != TimerP_OK) {
+ retVal = -1;
+ }
+ }
+
+ if (esmLoEventTrigTimerHandle != NULL_PTR) {
+ if (TimerP_delete(esmLoEventTrigTimerHandle) != TimerP_OK) {
+ retVal = -1;
+ }
+ }
+
+ if (esmPinTimerHandle != NULL_PTR) {
+ if (TimerP_delete(esmPinTimerHandle) != TimerP_OK) {
+ retVal = -1;
+ }
+ }
+
+ return (retVal);
+}
+
+/*********************************************************************
+* This callback is triggered by expiration of the input event
+* trigger timers.
+*/
+static void timerExpTrigger(uintptr_t arg)
+{
+ TimerP_Status timerStatus;
+ volatile uint32_t storeArg = arg;
+
+ if (storeArg == HIGH_PRIO_TRIG_TIMER_ID)
+ {
+ esmEventInputTrig[4] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+#ifdef PRINT_DEBUG
+ DIAG_printf("timerExpTrigger: High Priority interrupt timer expired\n");
+#endif
+ /* Start Timer to control when external Pin is reset */
+ timerStatus = TimerP_start(esmPinTimerHandle);
+ if (timerStatus != TimerP_OK) {
+ DIAG_printf("ERR: Could not start the timer %d \n",
+ PIN_TIMING_TIMER_ID);
+ }
+ } else if (storeArg == LOW_PRIO_TRIG_TIMER_ID) {
+ esmEventInputTrig[3] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+#ifdef PRINT_DEBUG
+ DIAG_printf("timerExpTrigger: Low Priority interrupt timer expired\n");
+#endif
+ }
+}
+
+/*
+* This callback is triggered by expiration of the pin disable timer
+*/
+static void timerExpPinDisable(uintptr_t arg)
+{
+ int32_t retVal = 0;
+ bool pinStatus;
+ SDR_Result sdrStatus;
+
+ volatile SDR_ESM_InstanceType *pInstType = (SDR_ESM_InstanceType *)arg;
+
+ pinStatus = SDR_ESM_getNErrorStatus(*pInstType);
+ if (pinStatus != 0) {
+ DIAG_printf("\n timerExpPinDisable: Incorrect pin value before clearing\n");
+ retVal = -1;
+ } else {
+#ifdef DEBUG_PRINT
+ DIAG_printf("\n timerExpPinDisable: before clear, ESM instance %d view of " \
+ "MCU_SAFETY_ERRORn pin is %d\n",
+ *pInstType, pinStatus);
+#endif
+ }
+
+ sdrStatus = SDR_ESM_resetNError(*pInstType);
+
+ if (sdrStatus != SDR_PASS) {
+ /* If resetNError is called within minimum time interval, then the result of
+ * SDR_ESM_resetNError will be failure because pin does not change until
+ * minimum time interval has expired */
+ if ((pinClearTimeCycles >= esmPinMinIntervalCycles) ||
+ (immediatePinClear)) {
+ DIAG_printf("\n timerExpPinDisable: ERROR - Failed to clear the error " \
+ "pin from ESM Instance %d\n",
+ *pInstType);
+ retVal = -1;
+ } else {
+ /* Delay 1msec after minimum time interval is done and check the pin
+ * again */
+ Osal_delay((esmPinMinIntervalUsec / 1000) + 1);
+ }
+ } else {
+#ifdef DEBUG_PRINT
+ DIAG_printf(" timerExpPinDisable: Cleared the error pin successfully from " \
+ "ESM Instance %d\n",
+ *pInstType);
+#endif
+ }
+
+ pinStatus = SDR_ESM_getNErrorStatus(*pInstType);
+ if (pinStatus != 1) {
+ DIAG_printf("\n timerExpPinDisable: Incorrect pin value after clearing\n");
+ retVal = -1;
+ }
+#ifdef DEBUG_PRINT
+ DIAG_printf(" timerExpPinDisable: after clear, ESM instance %d view of " \
+ "MCU_SAFETY_ERRORn pin is %d\n\n",
+ *pInstType, pinStatus);
+#endif
+
+ if (retVal == 0) {
+ esmPinClearResult[currUseCase] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+ } else {
+ esmPinClearResult[currUseCase] = USE_CASE_STATUS_COMPLETED_FAILURE;
+ }
+}
+
+/*
+* This function clears timer interrupts for Timer input events to the ESM.
+*/
+int32_t diag_esm_timerUpdateInt(uint32_t intEsmSrc)
+{
+ int32_t retVal = -1;
+ TimerP_Status status;
+
+ /* Stop/Clear timer interrupt based on which timer triggered it */
+ if (intEsmSrc == CSLR_MCU_ESM0_ESM_LVL_EVENT_MCU_TIMER2_INTR_PEND_0)
+ {
+ status = TimerP_stop(esmHiEventTrigTimerHandle);
+ if (status == TimerP_OK) {
+#ifdef PRINT_DEBUG
+ DIAG_printf("Cleared interrupt for Timer Triggering High " \
+ "Priority Event\n");
+#endif
+ retVal = 0;
+ } else {
+ DIAG_printf("Failed to Clear interrupt for Timer Triggering High " \
+ "Priority Event\n");
+ }
+ } else if (intEsmSrc == CSLR_MCU_ESM0_ESM_LVL_EVENT_MCU_TIMER3_INTR_PEND_0)
+ {
+ status = TimerP_stop(esmLoEventTrigTimerHandle);
+ if (status == TimerP_OK) {
+#ifdef PRINT_DEBUG
+ DIAG_printf("Cleared interrupt for Timer Triggering Low Priority Event\n");
+#endif
+ retVal = 0;
+ } else {
+ DIAG_printf("Failed to Clear interrupt for Timer Triggering " \
+ "Low Priority Event\n");
+ }
+ }
+
+ return retVal;
+}
+
+/* VTM FUNCTIONS */
+
+/*
+* This function modifies all the VTM thresholds in a single function to ensure
+* appropriate number of ESM events are triggered by the change in thresholds.
+*/
+static void setAllVTMTempThr(CSL_vtm_adc_code lt_thr0_adc_code,
+ CSL_vtm_adc_code gt_thr1_adc_code,
+ CSL_vtm_adc_code gt_thr2_adc_code)
+{
+ CSL_vtm_cfg1Regs *p_cfg = (CSL_vtm_cfg1Regs *) CSL_VTM_TEST_CFG1_BASE;
+ CSL_vtm_tsThrVal thr_val;
+ CSL_vtm_vdThr_interrupt_ctrl ctrl;
+ CSL_vtm_vdEvt_sel_set vd_temp_evts;
+ CSL_vtm_tmpSens_id ts_id = 0;
+
+ vd_temp_evts = CSL_VTM_VD_EVT_SELECT_TEMP_SENSOR_0;
+
+ thr_val.thrValidMap = CSL_VTM_GT_TH2_VALID | \
+ CSL_VTM_GT_TH1_VALID | \
+ CSL_VTM_LT_TH0_VALID;
+ ctrl = CSL_VTM_VD_GT_THR2_INTR_EN_SET | \
+ CSL_VTM_VD_GT_THR1_INTR_EN_SET | \
+ CSL_VTM_VD_LT_THR0_INTR_EN_CLR;
+ thr_val.gtTh2En = TRUE;
+ thr_val.gtTh2 = gt_thr2_adc_code;
+ thr_val.gtTh1En = TRUE;
+ thr_val.gtTh1 = gt_thr1_adc_code;
+ thr_val.ltTh0En = TRUE;
+ thr_val.ltTh0 = lt_thr0_adc_code;
+
+ /* Set the temperature thresholds */
+ CSL_vtmTsSetThresholds (p_cfg, ts_id, &thr_val, FALSE);
+ /* enable the threshold interrupts */
+ CSL_vtmVdThrIntrCtrl(p_cfg, CSL_VTM_VD_DOMAIN_1, ctrl, FALSE);
+ /* enable the tracking of temperature events on this VD */
+ CSL_vtmVdEvtSelSet (p_cfg, CSL_VTM_VD_DOMAIN_1, vd_temp_evts, FALSE);
+}
+
+/*
+* This function reads the current temperature in the VTM module
+* and then modifies the VTM thresholds to cause events to trigger.
+* Note that in a typical system, the thresholds would be kept the static, and
+* changes in temperature would cause the events to occur.
+*/
+static int32_t vtmTriggerTh(int32_t lt_thr0_offset,
+ int32_t gt_thr1_offset,
+ int32_t gt_thr2_offset)
+{
+ int32_t retVal = 0;
+ int32_t temp_milli_degrees_read, ts_id = 0;
+ CSL_vtm_adc_code adc_code_read;
+ CSL_vtm_adc_code adc_code_lt_thr0, adc_code_gt_thr1, adc_code_gt_thr2;
+ CSL_vtm_cfg1Regs *p_vtm_cfg1_regs;
+ int32_t gt_thr2_val, gt_thr1_val, lt_thr0_val;
+ CSL_vtm_tsStat_val ts_stat_val;
+ CSL_vtm_tsStat_read_ctrl tsStat_read_ctrl = CSL_VTM_TS_READ_DATA_OUT_VAL;
+ CSL_vtm_vdThr_interrupt_ctrl ctrl;
+
+ p_vtm_cfg1_regs = (CSL_vtm_cfg1Regs *) CSL_VTM_TEST_CFG1_BASE;
+
+ /* Get current temperature value */
+ CSL_vtmTsGetSensorStat (p_vtm_cfg1_regs, &tsStat_read_ctrl, \
+ ts_id, &ts_stat_val);
+ adc_code_read = ts_stat_val.data_out;
+ (void) CSL_vtmTsConvADCToTemp (adc_code_read,
+ (CSL_vtm_tmpSens_id) ts_id,
+ &temp_milli_degrees_read);
+#ifdef DEBUG_PRINT
+ DIAG_printf ("sensor id : %d \n" \
+ "adc_code : %d \n" \
+ "temp in milli degree celcius : %d \n", \
+ ts_id, adc_code_read, temp_milli_degrees_read);
+#endif
+
+ /* Disable interrupts while changing thresholds */
+ ctrl = (CSL_VTM_VD_GT_THR2_INTR_EN_CLR | \
+ CSL_VTM_VD_GT_THR2_INTR_RAW_CLR | \
+ CSL_VTM_VD_GT_THR1_INTR_EN_CLR | \
+ CSL_VTM_VD_GT_THR1_INTR_RAW_CLR | \
+ CSL_VTM_VD_LT_THR0_INTR_EN_CLR | \
+ CSL_VTM_VD_LT_THR0_INTR_RAW_CLR);
+ CSL_vtmVdThrIntrCtrl((CSL_vtm_cfg1Regs *)CSL_VTM_TEST_CFG1_BASE, \
+ CSL_VTM_VD_DOMAIN_1, ctrl, FALSE);
+
+ /* Change all 3 thresholds relative to the current temperature */
+ lt_thr0_val = temp_milli_degrees_read + lt_thr0_offset;
+ gt_thr1_val = temp_milli_degrees_read + gt_thr1_offset;
+ gt_thr2_val = temp_milli_degrees_read + gt_thr2_offset;
+
+ CSL_vtmTsConvTempToAdc(lt_thr0_val, ts_id, &adc_code_lt_thr0);
+ CSL_vtmTsConvTempToAdc(gt_thr1_val, ts_id, &adc_code_gt_thr1);
+ CSL_vtmTsConvTempToAdc(gt_thr2_val, ts_id, &adc_code_gt_thr2);
+
+#ifdef DEBUG_PRINT
+ DIAG_printf ("vtmTriggerTh: Setting lt_thr0_val temp to " \
+ "%d millidegrees Celsius, and adc_code_lt_thr0 = %d\n",
+ lt_thr0_val,
+ adc_code_lt_thr0);
+ DIAG_printf ("vtmTriggerTh: Setting gt_thr1_val temp to " \
+ "%d millidegrees Celsius, and adc_code_gt_thr1 = %d\n",
+ gt_thr1_val,
+ adc_code_gt_thr1);
+ DIAG_printf ("vtmTriggerTh: Setting gt_thr2_val temp to " \
+ "%d millidegrees Celsius, and adc_code_gt_thr2 = %d\n",
+ gt_thr2_val,
+ adc_code_gt_thr2);
+#endif
+
+ setAllVTMTempThr(adc_code_lt_thr0, adc_code_gt_thr1, adc_code_gt_thr2);
+
+#ifdef DEBUG_PRINT
+ DIAG_printf("Finished VTM threshold setting\n");
+#endif
+ return (retVal);
+}
+
+static int32_t vtmTriggerTh1(void)
+{
+ int32_t retVal = 0;
+#ifdef DEBUG_PRINT
+ DIAG_printf("vtmTriggerTh1: starting test with threshold change\n");
+#endif
+ retVal = vtmTriggerTh(-4000, -2000, 5000);
+
+ return (retVal);
+}
+
+/*
+* This function clears VTM THR0 interrupt (Less Than Temp event)
+* for VTM input events to the ESM.
+* It resets the VTM module to look for high temperature events again.
+*/
+void diag_esm_vtmLtThr0CrossedUpdateInt(void)
+{
+ CSL_vtm_vdThr_interrupt_ctrl ctrl;
+
+ /* Ack the interrupt, by clearing the pending bit */
+ ctrl = (CSL_VTM_VD_LT_THR0_INTR_EN_CLR | \
+ CSL_VTM_VD_GT_THR1_INTR_EN_SET | \
+ CSL_VTM_VD_GT_THR2_INTR_EN_SET | \
+ CSL_VTM_VD_LT_THR0_INTR_RAW_CLR | \
+ CSL_VTM_VD_GT_THR1_INTR_RAW_CLR | \
+ CSL_VTM_VD_GT_THR2_INTR_RAW_CLR);
+
+ CSL_vtmVdThrIntrCtrl((CSL_vtm_cfg1Regs *)CSL_VTM_TEST_CFG1_BASE, \
+ CSL_VTM_VD_DOMAIN_1, ctrl, FALSE);
+
+ /* Print output ESM event to the screen */
+#ifdef PRINT_EVENTS
+ DIAG_printf ("\n Got ltThr0 interrupt through ESM module\n");
+ DIAG_printf ("\n System at a temperature below the threshold of lt_thr0 \n"
+ " System running at a safe temperature \n");
+#endif
+}
+
+/*
+* This function clears VTM THR1 interrupts for VTM input event to the ESM.
+*/
+void diag_esm_vtmGtThr1CrossedUpdateInt(void)
+{
+ CSL_vtm_vdThr_interrupt_ctrl ctrl;
+ /*
+ - disable the gt1 interrupt
+ - clear the gt1 interrupt
+ - clear the lt0 interrupt
+ - enable the lt0 intterupt
+ */
+ ctrl = (CSL_VTM_VD_GT_THR1_INTR_EN_CLR | \
+ CSL_VTM_VD_GT_THR1_INTR_RAW_CLR | \
+ CSL_VTM_VD_LT_THR0_INTR_EN_SET | \
+ CSL_VTM_VD_LT_THR0_INTR_RAW_CLR);
+
+ /* Ack and Re-enable the LT_THR0 interrupt to let system know if cooling
+ * took place */
+ CSL_vtmVdThrIntrCtrl((CSL_vtm_cfg1Regs *)CSL_VTM_TEST_CFG1_BASE, \
+ CSL_VTM_VD_DOMAIN_1, ctrl, FALSE);
+
+ /* Print output ESM event to the screen */
+
+#ifdef PRINT_EVENTS
+ DIAG_printf ("\n Got gtThr1 interrupt through ESM module\n");
+ DIAG_printf ("\n Crossed early warning threshold of gt_thr1 \n"
+ " System should take action to implement system cooling \n");
+#endif
+}
+
+/*
+* This function clears VTM THR2 interrupts for VTM input event to the ESM.
+*/
+void diag_esm_vtmGtThr2CrossedUpdateInt(void)
+{
+ CSL_vtm_vdThr_interrupt_ctrl ctrl;
+ /* Ack the interrupt, by clearing the pending bit */
+ ctrl = (CSL_VTM_VD_GT_THR2_INTR_EN_CLR | \
+ CSL_VTM_VD_GT_THR2_INTR_RAW_CLR);
+ CSL_vtmVdThrIntrCtrl((CSL_vtm_cfg1Regs *)CSL_VTM_TEST_CFG1_BASE, \
+ CSL_VTM_VD_DOMAIN_1, ctrl, FALSE);
+
+#ifdef PRINT_EVENTS
+ /* Print output ESM event to the screen */
+ DIAG_printf ("\n Got gtThr2 interrupt through ESM module\n");
+ DIAG_printf ("\n Crossed critical threshold of gt_thr2 \n"
+ " System should take critical action to implement system cooling \n");
+#endif
+}
+
+/*
+* This function starts timer for clearing the MCU_SAFETY_ERRORn pin.
+* When this timer expires, the pin clearing function will be initiated.
+*/
+void diag_esm_startPinClearTimer(bool forcePinClear)
+{
+ /* Start timer to clear the pin at a certain time */
+ TimerP_Status timerStatus;
+
+ immediatePinClear = forcePinClear;
+
+ timerStatus = TimerP_start(esmPinTimerHandle);
+ if (timerStatus != TimerP_OK) {
+ DIAG_printf("ERR: Could not start the timer %d \n",
+ PIN_TIMING_TIMER_ID);
+ } else {
+#ifdef PRINT_DEBUG
+ DIAG_printf("Started timer to simulate MCU addressing error\n");
+#endif
+ }
+
+}
+
+/*
+* This function prints the current VTM thresholds.
+*/
+int32_t diag_esm_printCurrentThresholds(void)
+{
+ int32_t retVal = 0;
+
+ CSL_vtm_cfg1Regs *p_vtm_cfg1_regs = (CSL_vtm_cfg1Regs *) CSL_VTM_TEST_CFG1_BASE;
+ CSL_vtm_tsThrVal tsThrVal;
+
+ tsThrVal.thrValidMap = CSL_VTM_GT_TH1_VALID | \
+ CSL_VTM_GT_TH2_VALID | \
+ CSL_VTM_LT_TH0_VALID;
+
+ retVal = CSL_vtmTsGetThresholds (p_vtm_cfg1_regs,
+ CSL_VTM_TS_ID_0,
+ &tsThrVal);
+
+#ifdef PRINT_EVENTS
+ DIAG_printf("Current VTM Thresholds: lt_thr0 = %d, gt_thr1 = %d, gt_thr2 = %d\n",
+ tsThrVal.ltTh0, tsThrVal.gtTh1, tsThrVal.gtTh2);
+#endif
+ return (retVal);
+}
+
+int32_t diag_esm_setThresholdsForCriticalTrigger(void)
+{
+ int32_t retVal = 0;
+#ifdef DEBUG_PRINT
+ DIAG_printf("diag_esm_setThresholdsForCriticalTrigger: setting thresholds " \
+ "to trigger high priority thermal event.\n");
+#endif
+ retVal = vtmTriggerTh(-12000, -8000, -3000);
+
+ return (retVal);
+}
+
+/*
+* This function resets the VTM thresholds back to some typical default
+* values.
+*/
+int32_t diag_esm_setNormalThresholds(void)
+{
+ int32_t retVal = 0;
+ int32_t ts_id = 0;
+ CSL_vtm_adc_code adc_code_lt_thr0, adc_code_gt_thr1, adc_code_gt_thr2;
+ int32_t gt_thr2_val, gt_thr1_val, lt_thr0_val;
+ CSL_vtm_vdThr_interrupt_ctrl ctrl;
+
+#ifdef DEBUG_PRINT
+ DIAG_printf("Start changing to normal VTM threshold setting\n");
+#endif
+
+ /* Disable interrupts while changing thresholds */
+ ctrl = (CSL_VTM_VD_GT_THR2_INTR_EN_CLR | \
+ CSL_VTM_VD_GT_THR2_INTR_RAW_CLR | \
+ CSL_VTM_VD_GT_THR1_INTR_EN_CLR | \
+ CSL_VTM_VD_GT_THR1_INTR_RAW_CLR | \
+ CSL_VTM_VD_LT_THR0_INTR_EN_CLR | \
+ CSL_VTM_VD_LT_THR0_INTR_RAW_CLR);
+ CSL_vtmVdThrIntrCtrl((CSL_vtm_cfg1Regs *)CSL_VTM_TEST_CFG1_BASE, \
+ CSL_VTM_VD_DOMAIN_1, ctrl, FALSE);
+
+ /* Set to default values */
+ lt_thr0_val = LT_THR0_DEFAULT;
+ gt_thr1_val = GT_THR1_DEFAULT;
+ gt_thr2_val = GT_THR2_DEFAULT;
+
+ CSL_vtmTsConvTempToAdc(lt_thr0_val, ts_id, &adc_code_lt_thr0);
+ CSL_vtmTsConvTempToAdc(gt_thr1_val, ts_id, &adc_code_gt_thr1);
+ CSL_vtmTsConvTempToAdc(gt_thr2_val, ts_id, &adc_code_gt_thr2);
+
+#ifdef DEBUG_PRINT
+ DIAG_printf ("diag_esm_setNormalThresholds: Setting lt_thr0_val temp to %d " \
+ "millidegrees Celsius, and adc_code_lt_thr0 = %d\n",
+ lt_thr0_val,
+ adc_code_lt_thr0);
+ DIAG_printf ("diag_esm_setNormalThresholds: Setting gt_thr1_val temp to %d " \
+ "millidegrees Celsius, and adc_code_gt_thr1 = %d\n",
+ gt_thr1_val,
+ adc_code_gt_thr1);
+ DIAG_printf ("diag_esm_setNormalThresholds: Setting gt_thr2_val temp to %d " \
+ "millidegrees Celsius, and adc_code_gt_thr2 = %d\n",
+ gt_thr2_val,
+ adc_code_gt_thr2);
+#endif
+
+ setAllVTMTempThr(adc_code_lt_thr0, adc_code_gt_thr1, adc_code_gt_thr2);
+
+#ifdef DEBUG_PRINT
+ DIAG_printf("Finished normal VTM threshold setting\n");
+#endif
+
+ return (retVal);
+}
+
+/* USE CASE FUNCTIONS */
+
+/*
+* This function initiates the input trigger event for each use case
+*/
+int32_t diag_esm_runUseCaseTrigger(uint8_t useCaseId)
+{
+ TimerP_Status timerStatus;
+ int32_t retVal = 0;
+
+ DIAG_printf("\nStarting Use Case %d \n", useCaseId);
+ switch(useCaseId)
+ {
+ case 0:
+ /* UC-1: Low Priority interrupt on WKUP ESM -
+ * VTM greater than THR1 */
+ currEsmInstance = SDR_ESM_INSTANCE_WKUP;
+ retVal = vtmTriggerTh1();
+ if (retVal == 0) {
+ esmEventInputTrig[useCaseId] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+ } else {
+ esmEventInputTrig[useCaseId] = USE_CASE_STATUS_COMPLETED_FAILURE;
+ }
+ /* This use case only has low priority interrupts not routed to
+ * the pin, so this flag can be set at beginning of the test */
+ esmPinClearResult[0] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+ break;
+
+ case 1:
+ /* UC-2: High Priority interrupt on WKUP ESM -
+ * VTM greater than THR2, no clearing of
+ * MCU_SAFETY_ERRORn pin */
+ currEsmInstance = SDR_ESM_INSTANCE_WKUP;
+ retVal = vtmTriggerTh1();
+ if (retVal == 0) {
+ esmEventInputTrig[useCaseId] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+ } else {
+ esmEventInputTrig[useCaseId] = USE_CASE_STATUS_COMPLETED_FAILURE;
+ }
+ break;
+
+ case 2:
+ /* UC-3: High Priority interrupt on WKUP ESM -
+ * VTM greater than THR2 with clearing
+ * of MCU_SAFETY_ERRORn pin */
+
+ /* Start the Pin Control and Measurement Timer */
+ currEsmInstance = SDR_ESM_INSTANCE_WKUP;
+ retVal = vtmTriggerTh1();
+ if (retVal == 0) {
+ esmEventInputTrig[useCaseId] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+ } else {
+ esmEventInputTrig[useCaseId] = USE_CASE_STATUS_COMPLETED_FAILURE;
+ }
+ break;
+
+ case 3:
+ /* UC-4: Low Priority interrupt on MCU ESM -
+ * MCU TIMER 2 expiration */
+ currEsmInstance = SDR_ESM_INSTANCE_MCU;
+ /* Start the Low Priority Event Trigger Timer */
+ timerStatus = TimerP_start(esmLoEventTrigTimerHandle);
+ if (timerStatus != TimerP_OK) {
+ DIAG_printf("ERR: Could not start the timer %d \n",
+ LOW_PRIO_TRIG_TIMER_ID);
+ retVal = -1;
+ }
+ /* esmEventInputTrig flag is set in expiration of the timer */
+ /* This use case only has low priority interrupts not routed to
+ * the pin, so this flag can be set at beginning of the test */
+ esmPinClearResult[useCaseId] = USE_CASE_STATUS_COMPLETED_SUCCESS;
+ break;
+
+ case 4:
+ /* UC-5: High Priority interrupt on MCU ESM -
+ * MCU TIMER 1 expiration */
+ /* Start the High Priority Event Trigger Timer */
+ currEsmInstance = SDR_ESM_INSTANCE_MCU;
+ timerStatus = TimerP_start(esmHiEventTrigTimerHandle);
+ if (timerStatus != TimerP_OK) {
+ DIAG_printf("ERR: Could not start the timer %d \n",
+ HIGH_PRIO_TRIG_TIMER_ID);
+ esmEventInputTrig[useCaseId] = USE_CASE_STATUS_COMPLETED_FAILURE;
+ retVal = -1;
+ }
+ /* esmEventInputTrig flag is set in expiration of the Hi Event timer */
+ /* esmPinClearResult flag is set in expiration of the Pin timer */
+ break;
+
+ default:
+ DIAG_printf("ERR: Invalid Use Case ID %d \n", useCaseId);
+ retVal = -1;
+ break;
+ }
+
+ return (retVal);
+}
+
diff --git a/packages/ti/diag/examples/esm_example_app/event_trig.h b/packages/ti/diag/examples/esm_example_app/event_trig.h
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * ESM Example
+ *
+ * Error Signaling Module (ESM) Example Application
+ *
+ * Copyright (c) 2020 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.
+ */
+#ifndef INCLUDE_EVENT_TRIG_H_
+#define INCLUDE_EVENT_TRIG_H_
+
+/*===========================================================================*/
+/* Internal function declarations */
+/*===========================================================================*/
+
+int32_t diag_esm_timerInit(void);
+int32_t diag_esm_timersDelete(void);
+int32_t diag_esm_runUseCaseTrigger(uint8_t useCaseId);
+int32_t diag_esm_setNormalThresholds(void);
+int32_t diag_esm_setThresholdsForCriticalTrigger(void);
+int32_t diag_esm_printCurrentThresholds(void);
+
+void diag_esm_vtmLtThr0CrossedUpdateInt(void);
+void diag_esm_vtmGtThr1CrossedUpdateInt(void);
+void diag_esm_vtmGtThr2CrossedUpdateInt(void);
+int32_t diag_esm_timerUpdateInt(uint32_t intEsmSrc);
+void diag_esm_startPinClearTimer(bool forcePinClear);
+
+#define USE_CASE_STATUS_NOT_RUN (0u)
+#define USE_CASE_STATUS_COMPLETED_SUCCESS (1u)
+#define USE_CASE_STATUS_COMPLETED_FAILURE (2u)
+
+
+#endif /* INCLUDE_EVENT_TRIG_H_ */
diff --git a/packages/ti/diag/examples/esm_example_app/j721e/linker_mcu1_0.lds b/packages/ti/diag/examples/esm_example_app/j721e/linker_mcu1_0.lds
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+ * ESM Example
+ *
+ * Error Signaling Module (ESM) Example Application
+ *
+ * Copyright (c) Texas Instruments Incorporated 2020
+ *
+ * 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: linker_mcu1_0.lds */
+/* Description: */
+/* Link command file for J721E R5F MCU 0 view */
+/*----------------------------------------------------------------------------*/
+/* Linker Settings */
+/* Standard linker options */
+--retain="*(.bootCode)" /* DSJ - ADDED */
+--retain="*(.startupCode)" /* DSJ - ADDED */
+--retain="*(.startupData)" /* DSJ - ADDED */
+--retain="*(.intvecs)"
+--retain="*(.intc_text)"
+--retain="*(.rstvectors)"
+--retain="*(.irqStack)"
+--retain="*(.fiqStack)"
+--retain="*(.abortStack)"
+--retain="*(.undStack)"
+--retain="*(.svcStack)"
+--fill_value=0
+--stack_size=0x2000
+--heap_size=0x1000
+--entry_point=_resetvectors /* Default C RTS boot.asm */
+
+-stack 0x2000 /* SOFTWARE STACK SIZE */
+-heap 0x2000 /* HEAP AREA SIZE */
+
+/* Stack Sizes for various modes */
+__IRQ_STACK_SIZE = 0x1000;
+__FIQ_STACK_SIZE = 0x1000;
+__ABORT_STACK_SIZE = 0x1000;
+__UND_STACK_SIZE = 0x1000;
+__SVC_STACK_SIZE = 0x1000;
+
+/*----------------------------------------------------------------------------*/
+/* Memory Map */
+MEMORY
+{
+ VECTORS_MCU1_0 (X) : origin=0x41C7F000 length=0x1000
+ VECTORS_MCU1_1 (X) : origin=0x41C7E000 length=0x1000
+ /* VECTORS (X) : origin=0x41C7F000 length=0x1000 */
+ /* Reset Vectors base address(RESET_VECTORS) should be 64 bytes aligned */ /* DSJ - changed */
+ MCU1_0_RESET_VECTORS (X) : origin=0x41C00000 length=0x100
+ MCU1_1_RESET_VECTORS (X) : origin=0x41C00100 length=0x200 - 0x100
+ /* RESET_VECTORS (X) : origin=0x41C00000 length=0x100 */ /* DSJ - changed */
+ /* MCU0_R5F_0 local view */
+ MCU0_R5F_TCMA (X) : origin=0x0 length=0x7c00 fill=0xffffffff
+ MCU0_R5F_TCMA_TEST (X) : origin=0x7c00 length=0x400 fill=0xffffffff
+ MCU0_R5F_TCMB0 (RWIX) : origin=0x41010000 length=0x8000
+
+ /* MCU0_R5F_1 SoC view */
+ MCU0_R5F1_ATCM (RWIX) : origin=0x41400000 length=0x8000
+ MCU0_R5F1_BTCM (RWIX) : origin=0x41410000 length=0x8000
+
+ /* MCU0 memory used for SBL and SYSFW. Avaiable after boot for appi starts for dynamic use */
+ SBL_RESERVED (RWIX) : origin=0x41C00100 length=0x60000 - 0x100 /* ~383KB */
+
+ /* MCU0 share locations */
+ OCMRAM (RWIX) : origin=0x41C60000 length=0x20000 - 0x2000 /* ~124KB */
+
+ /* MCU0 Location RESERVED for SDR RAT Self Test */
+ SDR_OCMC_RAT_SELFTEST (R) : origin=0x41C7EFC0 length=32
+
+ /* MCU0 Location RESERVED for SDR MPU Self Test */
+ SDR_OCMC_MPU_SELFTEST (R) : origin=0x41C7EFE0 length=32
+
+ /* J721E R5F locations */
+ /*MSMC3_SDR (RWIX) : origin=0x70000000 length=0x20000 */ /* 128 K */ /* DSJ - REMOVED */
+ MSMC3 (RWIX) : origin=0x70020000 length=0xD0000 /* 840 K */
+ /* Reserved for DMSC */
+ MSMC3_DMSC_FW (RWIX) : origin=0x700F0000 length=0x10000 /* 64K */
+/* MSMC3_H (RWIX) : origin=0x70100000 length=0xF2000 */ /* 1MB -56K */ /* DSJ - REMOVED */
+/* MSMC3_NOCACHE (RWIX) : origin=0x701F2000 length=0xE000 */ /* 56K */ /* DSJ - REMOVED */
+ DDR0 (RWIX) : origin=0x80000000 length=0x80000000 /* 2GB */
+
+/* Additional memory settings */
+
+} /* end of MEMORY */
+
+/*----------------------------------------------------------------------------*/
+/* Section Configuration */
+
+SECTIONS
+{
+/* 'intvecs' and 'intc_text' sections shall be placed within */
+/* a range of +\- 16 MB */
+ .intvecs : {} palign(8) > VECTORS_MCU1_0
+ .intc_text : {} palign(8) > VECTORS_MCU1_0
+ .rstvectors : {} palign(8) > MCU0_R5F_TCMA
+/*
+ .sdr_text_esm align(8) : {
+ sdr.*<sdr_esm.o*> (.text)
+ } > MSMC3_SDR
+ .sdr_text_ecc align(8) : {
+ sdr.*<sdr_ecc.o*> (.text)
+ } > MSMC3_SDR
+ .sdr_text_ccm align(8) : {
+ sdr.*<sdr_ccm.o*> (.text)
+ } > MSMC3_SDR
+ .sdr_text_crc align(8) : {
+ sdr.*<sdr_crc.o*> (.text)
+ } > MSMC3_SDR
+ .sdr_text_mpu align(8) : {
+ sdr.*<sdr_mpu.o*> (.text)
+ } > MSMC3_SDR
+ .sdr_text_wdt align(8) : {
+ sdr.*<sdr_wdt.o*> (.text)
+ } > MSMC3_SDR
+ .sdr__esm align(8) : {
+ } > MSMC3_SDR
+ .sdr_data_ecc align(8) : {
+ sdr.*<sdr_ecc.o*> (.const)
+ } > MSMC3_SDR
+ .sdr_data_mpu align(8) : {
+ sdr.*<sdr_mpu*> (.const)
+ } > MSMC3_SDR
+ .sdr_bss_esm align(8) : {
+ sdr.*<sdr_esm.o*> (.bss)
+ } > MSMC3_SDR
+ .sdr_bss_ecc align(8) : {
+ sdr.*<sdr_ecc.o*> (.bss)
+ } > MSMC3_SDR
+ .sdr_bss_ccm align(8) : {
+ sdr.*<sdr_ccm.o*> (.bss)
+ } > MSMC3_SDR
+ .sdr_bss_crc align(8) : {
+ sdr.*<sdr_crc.o*> (.bss)
+ } > MSMC3_SDR
+ .sdr_bss_mpu align(8) : {
+ sdr.*<sdr_mpu.o*> (.bss)
+ } > MSMC3_SDR
+ .sdr_bss_wdt align(8) : {
+ sdr.*<sdr_wdt.o*> (.bss)
+ } > MSMC3_SDR
+ .sdr_bss_exception align(8) : {
+ sdr.*<sdr_exception*> (.bss)
+ } > MSMC3_SDR
+*/ /* DSJ - removed */
+ .bootCode : {} palign(8) > MSMC3
+ .startupCode: {} palign(8) > MSMC3
+ .text : {} palign(8) > MSMC3
+ .const : {} palign(8) > MSMC3
+ .cinit : {} palign(8) > MSMC3
+ .pinit : {} palign(8) > MSMC3
+ .bss : {} align(4) > MSMC3
+ .data : {} palign(128) > MSMC3
+ .boardcfg_data : {} palign(128) > MSMC3
+ .sysmem : {} > MSMC3
+ .bss:extMemCache:ramdisk : {} align (32) > DDR0
+ .stack : {} align(4) > MSMC3 (HIGH)
+ .irqStack : {. = . + __IRQ_STACK_SIZE;} align(4) > MSMC3 (HIGH)
+ RUN_START(__IRQ_STACK_START)
+ RUN_END(__IRQ_STACK_END)
+ .fiqStack : {. = . + __FIQ_STACK_SIZE;} align(4) > MSMC3 (HIGH)
+ RUN_START(__FIQ_STACK_START)
+ RUN_END(__FIQ_STACK_END)
+ .abortStack : {. = . + __ABORT_STACK_SIZE;} align(4) > MSMC3 (HIGH)
+ RUN_START(__ABORT_STACK_START)
+ RUN_END(__ABORT_STACK_END)
+ .undStack : {. = . + __UND_STACK_SIZE;} align(4) > MSMC3 (HIGH)
+ RUN_START(__UND_STACK_START)
+ RUN_END(__UND_STACK_END)
+ .svcStack : {. = . + __SVC_STACK_SIZE;} align(4) > MSMC3 (HIGH)
+ RUN_START(__SVC_STACK_START)
+ RUN_END(__SVC_STACK_END)
+
+/* Additional sections settings */
+ .sdtf_rat_testsection : {} palign(32) > SDR_OCMC_RAT_SELFTEST
+
+ .sdtf_ecc_testcodesection : {} palign(32) > MCU0_R5F_TCMA_TEST
+
+} /* end of SECTIONS */
+
+/*----------------------------------------------------------------------------*/
+/* Misc linker settings */
+
+
+/*-------------------------------- END ---------------------------------------*/
diff --git a/packages/ti/diag/examples/esm_example_app/j721e/platform.h b/packages/ti/diag/examples/esm_example_app/j721e/platform.h
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * ESM Example app
+ *
+ * Error Signaling Module (ESM) example application
+ *
+ * Copyright (c) Texas Instruments Incorporated 2020
+ *
+ * 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.
+ *
+ */
+
+#ifndef _INCLUDE_PLATFORM_H_
+#define _INCLUDE_PLATFORM_H_
+
+#define UART_INSTANCE 0
+
+#endif /* _INCLUDE_PLATFORM_H_ */
diff --git a/packages/ti/diag/examples/esm_example_app/main.c b/packages/ti/diag/examples/esm_example_app/main.c
--- /dev/null
@@ -0,0 +1,293 @@
+/*
+ * ESM Example
+ *
+ * Error Signaling Module (ESM) Example Application
+ *
+ * Copyright (c) 2020 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 main.c
+ *
+ * \brief This file demonstrates using the Error Signaling Module (ESM),
+ * utilizing the ESM Software Diagnostic Reference (SDR) functions.
+ */
+
+/* ========================================================================== */
+/* Include Files */
+/* ========================================================================== */
+
+/* For Timer functions */
+#include <ti/osal/osal.h>
+
+/* Diagnostic example utility functions, e.g. print outputs */
+#include <diag_utils.h>
+
+#include "event_trig.h"
+#include "esm.h"
+
+#ifdef UNITY_INCLUDE_CONFIG_H
+#include <ti/build/unit-test/Unity/src/unity.h>
+#include <ti/build/unit-test/config/unity_config.h>
+#endif
+
+/* ========================================================================== */
+/* Macros & Typedefs */
+/* ========================================================================== */
+
+#define USE_CASES_RUN (5)
+#define USE_CASES (5)
+#define START_USE_CASE (0)
+
+/* ========================================================================== */
+/* Structure Declarations */
+/* ========================================================================== */
+
+/* None */
+
+/* ========================================================================== */
+/* Function Declarations */
+/* ========================================================================== */
+
+/* Unity functions */
+void diag_ex_esm_example_app_runner(void);
+void esm_example_app(void);
+
+static const char *printUseCaseStepResult(uint32_t result);
+
+/* ========================================================================== */
+/* Global Variables */
+/* ========================================================================== */
+
+/* State variable for each use case indicating input event trigger
+ * has been completed */
+volatile uint32_t esmEventInputTrig[USE_CASES] = {USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN};
+/* State variable for each use case indicating the ISR for the use case
+ * has been completed */
+volatile uint32_t esmOutputResult[USE_CASES] = {USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN};
+/* State variable for each use case indicating the pin clearing has been
+ * completed by pin clearing ISR (applicable only to use cases only
+ * with high priority interrupts routed to the pin directly) */
+volatile uint32_t esmPinClearResult[USE_CASES] = {USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN,
+ USE_CASE_STATUS_NOT_RUN};
+volatile uint8_t currUseCase = START_USE_CASE;
+
+/* ========================================================================== */
+/* External Variables */
+/* ========================================================================== */
+
+/* None */
+
+/* ========================================================================== */
+/* Function Definitions */
+/* ========================================================================== */
+
+
+/*****************************************************************************
+ * This is the main function for the Error Signaling Module (ESM) example
+ * application.
+ * It runs through 5 use cases to demonstrate usage of the ESM modules
+ * for receiving errors and controlling the error pin.
+ */
+void esm_example_app(void)
+{
+ int32_t testErrCount = 0;
+ int32_t retValue;
+ uint8_t i;
+
+ /* Initialize the ESM instances and handlers */
+ retValue = ESM_Example_init();
+#if defined (UNITY_INCLUDE_CONFIG_H)
+ TEST_ASSERT_GREATER_OR_EQUAL_INT32_MESSAGE(0, retValue,
+ "\nERR: ESM_example_init failed");
+#else
+ if (retValue < 0) {
+ /* print and exit */
+ DIAG_printf("\nERR: ESM_example_init failed");
+ testErrCount++;
+ }
+#endif
+ DIAG_printf("\nESM example init complete");
+
+ /* Initialize the Timers for all the Use Cases */
+ retValue = diag_esm_timerInit();
+#if defined (UNITY_INCLUDE_CONFIG_H)
+ TEST_ASSERT_GREATER_OR_EQUAL_INT32_MESSAGE(0, retValue,
+ "\nERR: Timer initialization failed");
+#else
+ if (retValue < 0) {
+ /* print and exit */
+ DIAG_printf("\nERR: Timer initialization failed");
+ testErrCount++;
+ }
+#endif
+
+ /* Trigger each Use Case */
+ for (i = START_USE_CASE; i < USE_CASES_RUN; i++) {
+ retValue = diag_esm_runUseCaseTrigger(i);
+#if defined (UNITY_INCLUDE_CONFIG_H)
+ TEST_ASSERT_EQUAL_MESSAGE(0, retValue,
+ "\nERR: Use Case Trigger for Use Case %d failed \n");
+#else
+ if (retValue != 0) {
+ DIAG_printf("\nERR: Use Case Trigger for Use Case %d failed \n",
+ retValue);
+ break;
+ }
+#endif
+ while((esmEventInputTrig[i] == USE_CASE_STATUS_NOT_RUN) ||
+ (esmOutputResult[i] == USE_CASE_STATUS_NOT_RUN) ||
+ (esmPinClearResult[i] == USE_CASE_STATUS_NOT_RUN))
+ {
+#ifdef DEBUG_PRINT
+ DIAG_printf("InputTrig = %d, OutputResult = %d, ClearResult = %d\n",
+ esmEventInputTrig[i],
+ esmOutputResult[i],
+ esmPinClearResult[i]);
+#endif
+ }
+ DIAG_printf("\nUse Case %d completed: Input Event Trigger = %s, \n" \
+ " Event Handler Complete = %s, \n" \
+ " MCU_SAFETY_ERRORn Pin Clear = %s\n",
+ i,
+ printUseCaseStepResult(esmEventInputTrig[i]),
+ printUseCaseStepResult(esmOutputResult[i]),
+ printUseCaseStepResult(esmPinClearResult[i]));
+ currUseCase++;
+ }
+
+ /* Check results of all the tests */
+ for (i = 0; i < USE_CASES_RUN; i++) {
+ if ((esmEventInputTrig[i] != USE_CASE_STATUS_COMPLETED_SUCCESS) ||
+ (esmOutputResult[i] != USE_CASE_STATUS_COMPLETED_SUCCESS) ||
+ (esmPinClearResult[i] != USE_CASE_STATUS_COMPLETED_SUCCESS)) {
+ testErrCount++;
+ }
+ }
+
+ retValue = diag_esm_timersDelete();
+#if defined (UNITY_INCLUDE_CONFIG_H)
+ TEST_ASSERT_EQUAL_MESSAGE(0, retValue, "\nFailed to delete used timers\n");
+#else
+ if (retValue != 0) {
+ DIAG_printf("\nFailed to delete used timers\n");
+ }
+#endif
+
+ /* Print results and logs of the Use Cases */
+ ESM_Example_printSummary();
+ DIAG_printf("\nESM Example Application: Complete");
+
+ if (testErrCount == 0)
+ {
+ DIAG_printf("\n All tests have passed. \n");
+ }
+ else
+ {
+ DIAG_printf("\n ESM Example app failed. \n");
+ }
+
+#if defined (UNITY_INCLUDE_CONFIG_H)
+ TEST_ASSERT_EQUAL_INT32(0, testErrCount);
+#endif
+ return;
+}
+
+static const char *printUseCaseStepResult(uint32_t result)
+{
+ char *pStr;
+
+ switch(result)
+ {
+ case USE_CASE_STATUS_NOT_RUN:
+ pStr = "Step Not yet run";
+ break;
+ case USE_CASE_STATUS_COMPLETED_SUCCESS:
+ pStr = "Step completed successfully";
+ break;
+ case USE_CASE_STATUS_COMPLETED_FAILURE:
+ pStr = "Step completed with failure";
+ break;
+ default:
+ pStr = NULL;
+ break;
+ }
+
+ return pStr;
+}
+
+int32_t main(void)
+{
+ (void) diag_ex_esm_example_app_runner();
+
+ while (true)
+ {
+ }
+}
+
+#ifdef UNITY_INCLUDE_CONFIG_H
+/*
+ * ======== Unity set up and tear down ========
+ */
+void setUp(void)
+{
+ /* Do nothing */
+}
+
+void tearDown(void)
+{
+ /* Do nothing */
+}
+#endif
+
+void diag_ex_esm_example_app_runner(void)
+{
+#if defined(UNITY_INCLUDE_CONFIG_H)
+ UNITY_BEGIN();
+ RUN_TEST (esm_example_app);
+ UNITY_END();
+ /* Function to print results defined in our unity_config.h file */
+ print_unityOutputBuffer_usingUARTstdio();
+#else
+ esm_example_app();
+#endif
+ return;
+}
diff --git a/packages/ti/diag/examples/esm_example_app/makefile b/packages/ti/diag/examples/esm_example_app/makefile
--- /dev/null
@@ -0,0 +1,79 @@
+#
+# This file is the makefile for building Software Diagnostics ESM Example app.
+#
+# Copyright (c) Texas Instruments Incorporated 2020
+#
+include $(PDK_INSTALL_PATH)/ti/build/Rules.make
+
+APP_NAME = diag_ex_esm_example_app
+
+$(info DSJ - GOT HERE)
+BUILD_OS_TYPE=baremetal
+
+SRCDIR = . ../common
+INCDIR =
+
+INCDIR += $(SOC)/. ../common
+
+# List all the external components/interfaces, whose interface header files
+# need to be included for this component
+INCLUDE_EXTERNAL_INTERFACES = pdk sdr
+
+# List all the components required by the application
+ifeq ($(CSL_BUILD),$(filter $(CSL_BUILD), CSL))
+ COMP_LIST_COMMON = csl
+else
+ COMP_LIST_COMMON = csl2 csl_trim
+endif
+
+COMP_LIST_COMMON += csl_utils_common csl_uart_console
+ifeq ($(SOC),$(filter $(SOC), j721e am64x))
+ COMP_LIST_COMMON += csl_init osal_nonos board uart sciclient i2c
+endif
+COMP_LIST_COMMON += sdr
+# Common source files and CFLAGS across all platforms and cores
+PACKAGE_SRCS_COMMON = .
+
+ifeq ($(SOC),$(filter $(SOC), j721e am64x))
+ SRCS_COMMON = main.c esm.c event_trig.c diag_utils.c
+endif
+LNKFLAGS_LOCAL_mpu1_0 += --entry Entry
+CFLAGS_LOCAL_COMMON = $(PDK_CFLAGS)
+
+CFLAGS_LOCAL_COMMON += -DUART_PRINTF
+
+# To print events to UART during the flow of the Use Case itself,
+# uncomment this line
+# By default, tests are done with pin triggering with 100usec minimum
+# interval time, i.e. this macro is disabled
+#CFLAGS_LOCAL_COMMON += -DPRINT_EVENTS
+# To print more verbose prints, uncomment this build flag
+#CFLAGS_LOCAL_COMMON += -DDEBUG_PRINT
+
+ifeq ($(SOC),$(filter $(SOC), j721e am64x))
+ SRCDIR += $(PDK_INSTALL_PATH)/ti/build/unit-test/Unity/src
+ SRCDIR += $(PDK_INSTALL_PATH)/ti/build/unit-test/config
+ INCDIR += $(PDK_INSTALL_PATH)/ti/build/unit-test/Unity/src
+ INCDIR += $(PDK_INSTALL_PATH)/ti/build/unit-test/config
+ SRCS_COMMON += unity_config.c unity.c
+ CFLAGS_LOCAL_COMMON += -DUNITY_INCLUDE_CONFIG_H
+endif
+
+
+# Core/SoC/platform specific source files and CFLAGS
+# Example:
+# SRCS_<core/SoC/platform-name> =
+# CFLAGS_LOCAL_<core/SoC/platform-name> =
+
+# Include common make files
+ifeq ($(MAKERULEDIR), )
+#Makerule path not defined, define this and assume relative path from ROOTDIR
+ MAKERULEDIR := $(ROOTDIR)/ti/build/makerules
+ export MAKERULEDIR
+endif
+include $(MAKERULEDIR)/common.mk
+
+# OBJs and libraries are built by using rule defined in rules_<target>.mk
+# and need not be explicitly specified here
+
+# Nothing beyond this point