[processor-sdk/pdk.git] / packages / ti / board / diag / current_monitor / src / current_monitor_test.h
1 /******************************************************************************
2 * Copyright (c) 2018-2021 Texas Instruments Incorporated - http://www.ti.com
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *****************************************************************************/
34 /**
35 *
36 * \file current_monitor_test.h
37 *
38 * \brief This is the header file for current monitor diagnostic test.
39 *
40 */
42 #ifndef _CURRENT_MONITOR_TEST_H_
43 #define _CURRENT_MONITOR_TEST_H_
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
49 #include <ti/drv/i2c/I2C.h>
50 #include <ti/drv/i2c/soc/I2C_soc.h>
52 #include <ti/drv/uart/UART.h>
53 #include <ti/drv/uart/UART_stdio.h>
55 #include <ti/csl/soc.h>
57 #include "board.h"
58 #include "board_cfg.h"
60 #include "diag_common_cfg.h"
62 #if defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_J721S2)
63 #include <ti/drv/gpio/GPIO.h>
64 #include "board_internal.h"
65 #include "board_i2c_io_exp.h"
66 #include "board_control.h"
67 #endif
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
73 /* INA Device Register Address Offsets */
74 #define CONFIGURATION_REG_ADDR_OFFSET (0x00U)
75 #define SHUNT_VOLTAGE_REG_ADDR_OFFSET (0x01U)
76 #define BUS_VOLTAGE_REG_ADDR_OFFSET (0x02U)
77 #define POWER_REG_ADDR_OFFSET (0x03U)
78 #define CURRENT_REG_ADDR_OFFSET (0x04U)
79 #define CALIBRATION_REG_ADDR_OFFSET (0x05U)
81 /* Number of INA device Instances used */
82 #if defined(SOC_AM65XX)
83 #define NUM_OF_INA_DEVICES (0x08U)
84 #elif defined(SOC_K2G) || defined(SOC_TPR12)
85 #define NUM_OF_INA_DEVICES (0x04U)
86 #elif defined(SOC_AWR294X)
87 #define NUM_OF_INA_DEVICES (0x05U)
88 #elif defined(SOC_J721E)
89 #define NUM_OF_INA_DEVICES (31U)
90 #define TOT_INA_IN_PM1 (15U)
91 #elif defined(SOC_J721S2)
92 #define NUM_OF_INA_DEVICES (32U)
93 #define TOT_INA_IN_PM1 (16U)
94 #elif defined(SOC_J7200)
95 #define NUM_OF_INA_DEVICES (32U)
96 #define TOT_INA_IN_PM1 (16U)
97 #elif defined(am64x_evm)
98 #define NUM_OF_INA_DEVICES (0x06U)
99 #elif defined(am64x_svb)
100 #define NUM_OF_INA_DEVICES (11U)
101 #endif
103 /* INA Device register masks */
104 #define SHUNT_VOLTAGE_REG_MASK (0x7fffU)
105 #define BUS_VOLTAGE_REG_MASK (0x7fffU)
106 #define POWER_REG_MASK (0xffffU)
107 #define CURRENT_REG_MASK (0x7fffU)
109 #define CALIBRATION_CONSTANT (5120000U)
110 #define DEFAULT_CONFIG_REG_VAL (0x4497U)
112 #if defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_J721S2)
113 #define SIGNAL_LEVEL_LOW (0U)
114 #define SIGNAL_LEVEL_HIGH (1U)
115 #endif
117 /**
118 * \brief Structure defining INA Device calibration parameters.
119 */
120 typedef struct CalibrationParams{
121 float maxRShunt;
122 float shuntVolLsb;
123 float busVolLsb;
124 float powerLsb;
125 float currentLsb;
126 uint16_t calibrartion;
127 }calParams_t;
129 /**
130 * \brief Structure defining INA Device configuration parameters.
131 */
132 typedef struct inaCfgObj{
133 char deviceID[20];
134 uint8_t slaveAddr;
135 calParams_t inaCalParams;
136 }inaCfgObj_t;
138 /**
139 * \brief Generates a random delay.
140 *
141 * \param delayVal [IN] Delay count.
142 *
143 */
144 void BoardDiag_AppDelay(uint32_t delayVal);
146 /**
147 * \brief The function performs the Current Monitor Diagnostic test.
148 *
149 * \return int8_t
150 * 0 - in case of success
151 * -1 - in case of failure.
152 *
153 */
154 int8_t BoardDiag_CurrentMonitorTest(void);
156 #ifdef __cplusplus
157 }
158 #endif /* __cplusplus */
160 #endif /* _CURRENT_MONITOR_TEST_H_ */