Callisto4Bootloader: test/watchdog_test.c Source File

Callisto4Bootloader

watchdog_test.c
Go to the documentation of this file.
1
14 /*******************************************************************************
15 * Includes
16 ******************************************************************************/
17
18 #include "c4_watchdog.h"
19 #include "watchdog_test.h"
20 #include "lib/c4_watchdog_types.h"
21 #include "fsl_wdog.h"
22 #include <stdio.h>
23
24 /*******************************************************************************
25 * Defines
26 ******************************************************************************/
27
34 #define TEST_IF(fn, res, rc) \
35 { rc = fn; \
36 C4_displayError(#fn, rc, false); \
37 rc = ((rc == res) ? C4_ERR_OK : C4_ERR_FAILED); \
38 }
39
40 /*******************************************************************************
41 * External Declarations
42 ******************************************************************************/
43
44 extern void BL_SysTick_DelayTicks(uint32_t n);
45
46 /*******************************************************************************
47 * Structures
48 ******************************************************************************/
49
50 /*******************************************************************************
51 * Prototypes
52 ******************************************************************************/
53
54 /*******************************************************************************
55 * Variables
56 ******************************************************************************/
57
58 /*******************************************************************************
59 * Interface Implementation
60 ******************************************************************************/
61
62 exit_code_t watchdog_test()
63 {
64
65 uint16_t resetFlag = 0U;
66 wdog_config_t config;
67
68 NVIC_EnableIRQ(WDOG1_IRQn);
69 /* Cast from our bitfield representation of WDOG registers to shift and mask used in FreeRTOS functions. */
70 WDOG_EnableInterrupts((WDOG_Type *)sWdogRegisters[C4_WDOG1], kWDOG_InterruptEnable);
71 printf("\r\n******** System Start ********\r\n");
72 printf("System reset by:");
73
74 /* Cast from our bitfield representation of WDOG registers to shift and mask used in FreeRTOS functions. */
75 resetFlag = WDOG_GetStatusFlags((WDOG_Type *)sWdogRegisters[C4_WDOG1]);
76
77 switch (resetFlag & (kWDOG_PowerOnResetFlag | kWDOG_TimeoutResetFlag | kWDOG_SoftwareResetFlag))
78 {
79 case kWDOG_PowerOnResetFlag:
80 printf(" Power On Reset!\r\n");
81 break;
82 case kWDOG_TimeoutResetFlag:
83 printf(" Time Out Reset!\r\n");
84 break;
85 case kWDOG_SoftwareResetFlag:
86 printf(" Software Reset!\r\n");
87 break;
88 default:
89 printf(" Error status!\r\n");
90 break;
91 }
92 /* Disable wdog reset function test for some devices can't using this feature. */
93 #if (!(defined(EXAMPLE_DISABLE_WDOG_RESET_FUNCTION) && EXAMPLE_DISABLE_WDOG_RESET_FUNCTION))
94 /* If system reset from power on, trigger a software reset. */
95 if (resetFlag & kWDOG_PowerOnResetFlag)
96 {
97 printf("\r\n- 1.Testing System reset by software trigger... ");
98 /* Cast from our bitfield representation of WDOG registers to shift and mask used in FreeRTOS functions. */
99 WDOG_TriggerSystemSoftwareReset((WDOG_Type *)sWdogRegisters[C4_WDOG1]);
100 }
101
102 /* If system reset from software trigger, testing the timeout reset. */
103 if (resetFlag & kWDOG_SoftwareResetFlag)
104 {
105 printf("\r\n- 2.Testing system reset by WDOG timeout.\r\n");
106 /*
107 * wdogConfig->enableWdog = true;
108 * wdogConfig->workMode.enableWait = true;
109 * wdogConfig->workMode.enableStop = false;
110 * wdogConfig->workMode.enableDebug = false;
111 * wdogConfig->enableInterrupt = false;
112 * wdogConfig->enablePowerdown = false;
113 * wdogConfig->resetExtension = flase;
114 * wdogConfig->timeoutValue = 0xFFU;
115 * wdogConfig->interruptTimeValue = 0x04u;
116 */
117 WDOG_GetDefaultConfig(&config);
118 config.timeoutValue = 0xFU; /* Timeout value is (0xF + 1)/2 = 8 sec. */
119 /* Cast from our bitfield representation of WDOG registers to shift and mask used in FreeRTOS functions. */
120 WDOG_Init((WDOG_Type *)sWdogRegisters[C4_WDOG1], &config);
121 printf("--- wdog Init done---\r\n");
122
123 /* without feed watch dog, wait until timeout. */
124 while (1)
125 {
126 }
127 }
128
129 /* If system reset from WDOG timeout, testing the refresh function using interrupt. */
130 if (resetFlag & kWDOG_TimeoutResetFlag)
131 {
132 #endif
133 printf("\r\n- 3.Test the WDOG refresh function by using interrupt.\r\n");
134 /*
135 * wdogConfig->enableWdog = true;
136 * wdogConfig->workMode.enableWait = true;
137 * wdogConfig->workMode.enableStop = false;
138 * wdogConfig->workMode.enableDebug = false;
139 * wdogConfig->enableInterrupt = false;
140 * wdogConfig->enablePowerdown = false;
141 * wdogConfig->resetExtension = flase;
142 * wdogConfig->timeoutValue = 0xFFU;
143 * wdogConfig->interruptTimeValue = 0x04u;
144 */
145 WDOG_GetDefaultConfig(&config);
146 config.timeoutValue = 0xFU; /* Timeout value is (0xF+1)/2 = 8 sec. */
147 config.enableInterrupt = true;
148 config.interruptTimeValue = 0x8U; /* Interrupt occurred (0x4)/2 = 2 sec before WDOG timeout. */
149 /* Cast from our bitfield representation of WDOG registers to shift and mask used in FreeRTOS functions. */
150 WDOG_Init((WDOG_Type *)sWdogRegisters[C4_WDOG1], &config);
151
152 printf("--- wdog Init done---\r\n");
153
154 #if (!(defined(EXAMPLE_DISABLE_WDOG_RESET_FUNCTION) && EXAMPLE_DISABLE_WDOG_RESET_FUNCTION))
155 }
156 #endif
157
158 while (1)
159 {
160 /* Cast from our bitfield representation of WDOG registers to shift and mask used in FreeRTOS functions. */
161 WDOG_Refresh((WDOG_Type *)sWdogRegisters[C4_WDOG1]);
162 /* User can feed WDG in their main thread. */
163 printf(" \r\nWDOG has been refreshed!");
164
165 /* Delay. */
166 BL_SysTick_DelayTicks(7000);
167 }
168 }
169
170 /*******************************************************************************/
171
172 exit_code_t watchdog_if_test(c4_wdog_t wdog)
173 {
174 exit_code_t rc = C4_ERR_OK;
175 // Check watchdog IDs
176 TEST_IF(c4_setWdogTimeout(-1,100), C4_ERR_RANGE, rc);
177 if (C4_ERR_OK == rc)
178 TEST_IF(c4_setWdogTimeout(2,100), C4_ERR_RANGE, rc);
179 if (C4_ERR_OK == rc)
180 TEST_IF(c4_setWdogInterrupt(-1,100), C4_ERR_RANGE, rc);
181 if (C4_ERR_OK == rc)
182 TEST_IF(c4_setWdogInterrupt(2,100), C4_ERR_RANGE, rc);
183
184 // Test timeout range
185 if (C4_ERR_OK == rc)
186 TEST_IF(c4_setWdogTimeout(wdog, 4), C4_ERR_RANGE, rc);
187 if (C4_ERR_OK == rc)
188 TEST_IF(c4_setWdogTimeout(wdog, 1281), C4_ERR_RANGE, rc);
189 if (C4_ERR_OK == rc)
190 TEST_IF(c4_setWdogInterrupt(wdog,-1), C4_ERR_RANGE, rc);
191 if (C4_ERR_OK == rc)
192 TEST_IF(c4_setWdogInterrupt(wdog,1276), C4_ERR_RANGE, rc);
193
194 // Test re-initialisation of interrupt
195 // This test assumes that the interrupt has been previously enabled.
196 if (C4_ERR_OK == rc)
197 TEST_IF(c4_setWdogInterrupt(wdog,400), C4_ERR_ALREADY_SET, rc);
198
199 return rc;
200 }
c4_wdog_t
c4_wdog_t
Enumeration of watchdogs.
Definition: c4_watchdog.h:34
kWDOG_SoftwareResetFlag
Definition: fsl_wdog.h:71
WDOG_TriggerSystemSoftwareReset
static void WDOG_TriggerSystemSoftwareReset(WDOG_Type *base)
Trigger the system software reset.
Definition: fsl_wdog.h:173
WDOG_GetStatusFlags
uint16_t WDOG_GetStatusFlags(WDOG_Type *base)
Gets the WDOG all reset status flags.
Definition: bl_api.c:298
watchdog_test.h
watchdog_test
exit_code_t watchdog_test()
Test function for watchdog 1.
Definition: watchdog_test.c:56
WDOG_EnableInterrupts
static void WDOG_EnableInterrupts(WDOG_Type *base, uint16_t mask)
Enables the WDOG interrupt.
Definition: fsl_wdog.h:205
fsl_wdog.h
c4_watchdog_types.h
Definition of types to aid manipulation of watchdog registers.
_wdog_config::enableInterrupt
bool enableInterrupt
Definition: fsl_wdog.h:43
WDOG_Type
Definition: MIMXRT1062.h:46321
WDOG_GetDefaultConfig
void WDOG_GetDefaultConfig(wdog_config_t *config)
Initializes the WDOG configuration structure.
Definition: bl_api.c:283
_wdog_config::interruptTimeValue
uint16_t interruptTimeValue
Definition: fsl_wdog.h:45
exit_code_t
exit_code_t
Enumeration of error codes.
Definition: c4_error_codes.h:96
WDOG1_IRQn
Definition: MIMXRT1062.h:182
BL_SysTick_DelayTicks
void BL_SysTick_DelayTicks(uint32_t n)
Sets a delay.
Definition: bootloader.c:317
kWDOG_InterruptEnable
Definition: fsl_wdog.h:58
kWDOG_PowerOnResetFlag
Definition: fsl_wdog.h:69
_wdog_config::timeoutValue
uint16_t timeoutValue
Definition: fsl_wdog.h:44
_wdog_config
Describes WDOG configuration structure.
Definition: fsl_wdog.h:39
C4_WDOG1
Watchdog 1 - resets processor.
Definition: c4_watchdog.h:39
WDOG_Init
void WDOG_Init(WDOG_Type *base, const wdog_config_t *config)
Initializes the WDOG.
Definition: bl_api.c:288
c4_watchdog.h
Interface to enable watchdog functions.
kWDOG_TimeoutResetFlag
Definition: fsl_wdog.h:70
c4_setWdogTimeout
exit_code_t c4_setWdogTimeout(c4_wdog_t wdog, uint16_t to)
Set timeout on watchdog.
Definition: c4_watchdog.c:193
NVIC_EnableIRQ
#define NVIC_EnableIRQ
Definition: core_armv81mml.h:2119
c4_setWdogInterrupt
exit_code_t c4_setWdogInterrupt(c4_wdog_t wdog, uint16_t to)
Enable interrupt on watchdog before expiry.
Definition: c4_watchdog.c:213
watchdog_if_test
exit_code_t watchdog_if_test(c4_wdog_t wdog)
Test Callisto 4 watchdog interfaces.
Definition: watchdog_test.c:166
sWdogRegisters
c4_WDOG_reg_t *const sWdogRegisters[C4_NUM_WDOG]
Watchdog control registers.
Definition: c4_watchdog.c:85
TEST_IF
#define TEST_IF(fn, res, rc)
Macro to perform test and display result.
Definition: watchdog_test.c:33
WDOG_Refresh
void WDOG_Refresh(WDOG_Type *base)
Refreshes the WDOG timer.
Definition: bl_api.c:308