1111#include <errno.h>
1212
1313#include <zephyr/logging/log.h>
14+ #include <zephyr/logging/log_ctrl.h>
1415LOG_MODULE_REGISTER (resetreason , LOG_LEVEL_INF );
1516
1617static 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)));
2223volatile uint32_t supported __attribute__((section (NOINIT_SECTION )));
2324volatile uint32_t wdt_status __attribute__((section (NOINIT_SECTION )));
2425volatile uint32_t reboot_status __attribute__((section (NOINIT_SECTION )));
26+ volatile uint32_t cpu_lockup_status __attribute__((section (NOINIT_SECTION )));
2527
2628/* Value used to indicate that the watchdog has fired. */
2729#define WDT_HAS_FIRED (0x12345678U)
2830#define REBOOT_WAS_DONE (0x87654321U)
31+ #define CPU_LOCKUP_WAS_DONE (0x19283746U)
2932
3033/* Highest value in the switch statement in the main() */
31- #define LAST_STATE (2 )
34+ #define LAST_STATE (3 )
3235
3336static void wdt_int_cb (const struct device * wdt_dev , int channel_id )
3437{
@@ -236,7 +239,7 @@ void test_reset_software(uint32_t cause)
236239 if (reboot_status != REBOOT_WAS_DONE ) {
237240 /* If software reset hasn't happen yet, do it. */
238241 reboot_status = REBOOT_WAS_DONE ;
239- LOG_INF ("Test RESET_SOFTWARE - Rebooting " );
242+ LOG_INF ("Test RESET_SOFTWARE" );
240243
241244 /* Flush cache as reboot may invalidate all lines. */
242245 sys_cache_data_flush_range ((void * ) & machine_state , sizeof (machine_state ));
@@ -316,6 +319,49 @@ void test_reset_watchdog(uint32_t cause)
316319 }
317320}
318321
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+
319365int main (void )
320366{
321367 uint32_t cause ;
@@ -327,6 +373,9 @@ int main(void)
327373 if (reboot_status == REBOOT_WAS_DONE ) {
328374 LOG_INF ("This boot is due to expected software reset" );
329375 }
376+ if (cpu_lockup_status == CPU_LOCKUP_WAS_DONE ) {
377+ LOG_INF ("This boot is due to expected cpu lockup reset" );
378+ }
330379 print_bar ();
331380
332381 /* Test relies on REST_PIN to correctly start. */
@@ -340,12 +389,14 @@ int main(void)
340389 machine_state = 0 ;
341390 reboot_status = 0 ;
342391 wdt_status = 0 ;
392+ cpu_lockup_status = 0 ;
343393 }
344394
345395 while (machine_state <= LAST_STATE ) {
346396 LOG_DBG ("machine_state = %u" , machine_state );
347397 LOG_DBG ("reboot_status = %u" , reboot_status );
348398 LOG_DBG ("wdt_status = %u" , wdt_status );
399+ LOG_DBG ("cpu_lockup_status = %u" , cpu_lockup_status );
349400
350401 switch (machine_state ) {
351402 case 0 : /* Print (an store) which reset causes are supported. */
@@ -358,6 +409,9 @@ int main(void)
358409 case 2 : /* Test RESET_WATCHDOG. */
359410 test_reset_watchdog (cause );
360411 machine_state ++ ;
412+ case 3 : /* Test CPU_LOCKUP. */
413+ test_reset_cpu_lockup (cause );
414+ machine_state ++ ;
361415 }
362416 }
363417
0 commit comments