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,47 @@ 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 ("k_sys_fatal_error_handler(%d)" , 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 , sizeof (cpu_lockup_status ));
343+ __ASSERT (0 , "Intentionally failed assertion" );
344+ } else {
345+ /* Reset due to CPU Lockup was done */
346+ LOG_INF ("TEST that RESET_CPU_LOCKUP was detected" );
347+ if (cause & RESET_CPU_LOCKUP ) {
348+ LOG_INF ("PASS: RESET_CPU_LOCKUP detected" );
349+ print_bar ();
350+ /* Check RESET_SOFTWARE can be cleared */
351+ test_clear_reset_cause ();
352+ } else {
353+ LOG_ERR ("FAIL: RESET_CPU_LOCKUP not set" );
354+ print_bar ();
355+ }
356+ /* Cleanup */
357+ cpu_lockup_status = 0 ;
358+ sys_cache_data_flush_range ((void * ) & cpu_lockup_status , sizeof (cpu_lockup_status ));
359+ }
360+ }
361+ }
362+
319363int main (void )
320364{
321365 uint32_t cause ;
@@ -327,6 +371,9 @@ int main(void)
327371 if (reboot_status == REBOOT_WAS_DONE ) {
328372 LOG_INF ("This boot is due to expected software reset" );
329373 }
374+ if (cpu_lockup_status == CPU_LOCKUP_WAS_DONE ) {
375+ LOG_INF ("This boot is due to expected cpu lockup reset" );
376+ }
330377 print_bar ();
331378
332379 /* Test relies on REST_PIN to correctly start. */
@@ -340,12 +387,14 @@ int main(void)
340387 machine_state = 0 ;
341388 reboot_status = 0 ;
342389 wdt_status = 0 ;
390+ cpu_lockup_status = 0 ;
343391 }
344392
345393 while (machine_state <= LAST_STATE ) {
346394 LOG_DBG ("machine_state = %u" , machine_state );
347395 LOG_DBG ("reboot_status = %u" , reboot_status );
348396 LOG_DBG ("wdt_status = %u" , wdt_status );
397+ LOG_DBG ("cpu_lockup_status = %u" , cpu_lockup_status );
349398
350399 switch (machine_state ) {
351400 case 0 : /* Print (an store) which reset causes are supported. */
@@ -358,6 +407,9 @@ int main(void)
358407 case 2 : /* Test RESET_WATCHDOG. */
359408 test_reset_watchdog (cause );
360409 machine_state ++ ;
410+ case 3 : /* Test CPU_LOCKUP. */
411+ test_reset_cpu_lockup (cause );
412+ machine_state ++ ;
361413 }
362414 }
363415
0 commit comments