11
11
#include <errno.h>
12
12
13
13
#include <zephyr/logging/log.h>
14
+ #include <zephyr/logging/log_ctrl.h>
14
15
LOG_MODULE_REGISTER (resetreason , LOG_LEVEL_INF );
15
16
16
17
static const struct device * const my_wdt_device = DEVICE_DT_GET (DT_ALIAS (watchdog0 ));
@@ -22,13 +23,15 @@ volatile uint32_t machine_state __attribute__((section(NOINIT_SECTION)));
22
23
volatile uint32_t supported __attribute__((section (NOINIT_SECTION )));
23
24
volatile uint32_t wdt_status __attribute__((section (NOINIT_SECTION )));
24
25
volatile uint32_t reboot_status __attribute__((section (NOINIT_SECTION )));
26
+ volatile uint32_t cpu_lockup_status __attribute__((section (NOINIT_SECTION )));
25
27
26
28
/* Value used to indicate that the watchdog has fired. */
27
29
#define WDT_HAS_FIRED (0x12345678U)
28
30
#define REBOOT_WAS_DONE (0x87654321U)
31
+ #define CPU_LOCKUP_WAS_DONE (0x19283746U)
29
32
30
33
/* Highest value in the switch statement in the main() */
31
- #define LAST_STATE (2 )
34
+ #define LAST_STATE (3 )
32
35
33
36
static void wdt_int_cb (const struct device * wdt_dev , int channel_id )
34
37
{
@@ -236,7 +239,7 @@ void test_reset_software(uint32_t cause)
236
239
if (reboot_status != REBOOT_WAS_DONE ) {
237
240
/* If software reset hasn't happen yet, do it. */
238
241
reboot_status = REBOOT_WAS_DONE ;
239
- LOG_INF ("Test RESET_SOFTWARE - Rebooting " );
242
+ LOG_INF ("Test RESET_SOFTWARE" );
240
243
241
244
/* Flush cache as reboot may invalidate all lines. */
242
245
sys_cache_data_flush_range ((void * ) & machine_state , sizeof (machine_state ));
@@ -316,6 +319,49 @@ void test_reset_watchdog(uint32_t cause)
316
319
}
317
320
}
318
321
322
+ void k_sys_fatal_error_handler (unsigned int reason , const struct arch_esf * pEsf )
323
+ {
324
+ LOG_INF ("%s(%d)" , __func__ , reason );
325
+ LOG_PANIC ();
326
+
327
+ /* Assert inside Assert handler - shall result in reset due to cpu lockup. */
328
+ __ASSERT (0 , "Intentionally failed assert inside kernel panic" );
329
+ }
330
+
331
+ void test_reset_cpu_lockup (uint32_t cause )
332
+ {
333
+ /* Check that reset cause from cpu lockup is detected. */
334
+ if (supported & RESET_CPU_LOCKUP ) {
335
+ if (cpu_lockup_status != CPU_LOCKUP_WAS_DONE ) {
336
+ /* If reset due to cpu lockup hasn't happen yet, do it. */
337
+ cpu_lockup_status = CPU_LOCKUP_WAS_DONE ;
338
+ LOG_INF ("Test RESET_CPU_LOCKUP" );
339
+
340
+ /* Flush cache as reboot may invalidate all lines. */
341
+ sys_cache_data_flush_range ((void * ) & machine_state , sizeof (machine_state ));
342
+ sys_cache_data_flush_range ((void * ) & cpu_lockup_status ,
343
+ sizeof (cpu_lockup_status ));
344
+ __ASSERT (0 , "Intentionally failed assertion" );
345
+ } else {
346
+ /* Reset due to CPU Lockup was done */
347
+ LOG_INF ("TEST that RESET_CPU_LOCKUP was detected" );
348
+ if (cause & RESET_CPU_LOCKUP ) {
349
+ LOG_INF ("PASS: RESET_CPU_LOCKUP detected" );
350
+ print_bar ();
351
+ /* Check RESET_SOFTWARE can be cleared */
352
+ test_clear_reset_cause ();
353
+ } else {
354
+ LOG_ERR ("FAIL: RESET_CPU_LOCKUP not set" );
355
+ print_bar ();
356
+ }
357
+ /* Cleanup */
358
+ cpu_lockup_status = 0 ;
359
+ sys_cache_data_flush_range ((void * ) & cpu_lockup_status ,
360
+ sizeof (cpu_lockup_status ));
361
+ }
362
+ }
363
+ }
364
+
319
365
int main (void )
320
366
{
321
367
uint32_t cause ;
@@ -327,6 +373,9 @@ int main(void)
327
373
if (reboot_status == REBOOT_WAS_DONE ) {
328
374
LOG_INF ("This boot is due to expected software reset" );
329
375
}
376
+ if (cpu_lockup_status == CPU_LOCKUP_WAS_DONE ) {
377
+ LOG_INF ("This boot is due to expected cpu lockup reset" );
378
+ }
330
379
print_bar ();
331
380
332
381
/* Test relies on REST_PIN to correctly start. */
@@ -340,12 +389,14 @@ int main(void)
340
389
machine_state = 0 ;
341
390
reboot_status = 0 ;
342
391
wdt_status = 0 ;
392
+ cpu_lockup_status = 0 ;
343
393
}
344
394
345
395
while (machine_state <= LAST_STATE ) {
346
396
LOG_DBG ("machine_state = %u" , machine_state );
347
397
LOG_DBG ("reboot_status = %u" , reboot_status );
348
398
LOG_DBG ("wdt_status = %u" , wdt_status );
399
+ LOG_DBG ("cpu_lockup_status = %u" , cpu_lockup_status );
349
400
350
401
switch (machine_state ) {
351
402
case 0 : /* Print (an store) which reset causes are supported. */
@@ -358,6 +409,9 @@ int main(void)
358
409
case 2 : /* Test RESET_WATCHDOG. */
359
410
test_reset_watchdog (cause );
360
411
machine_state ++ ;
412
+ case 3 : /* Test CPU_LOCKUP. */
413
+ test_reset_cpu_lockup (cause );
414
+ machine_state ++ ;
361
415
}
362
416
}
363
417
0 commit comments