From 3389dd306bb3550c57c00a5c5f3211b72b099b62 Mon Sep 17 00:00:00 2001 From: Mason Tran Date: Fri, 2 Feb 2024 12:49:31 -0500 Subject: [PATCH] [diag] add `diag fault ` and `diag ci` commands `diag fault ` allows users to trigger various fault types `diag ci` prints crash info --- src/src/diag.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/src/diag.c b/src/src/diag.c index cd15f47f..b7340faf 100644 --- a/src/src/diag.c +++ b/src/src/diag.c @@ -65,6 +65,10 @@ #include "sl_rail_util_ant_div.h" #endif +#ifdef SL_CATALOG_OT_CRASH_HANDLER_PRESENT +#include PLATFORM_HEADER +#endif + #define GPIO_PIN_BITMASK 0xFFFFUL #define GPIO_PORT_BITMASK (0xFFFFUL << 16) #define GET_GPIO_PIN(x) (x & GPIO_PIN_BITMASK) @@ -147,12 +151,78 @@ static otError processAutoAck(otInstance *aInstance, return error; } +#if defined(SL_CATALOG_OT_CRASH_HANDLER_PRESENT) +static otError processFault(otInstance *aInstance, + uint8_t aArgsLength, + char *aArgs[], + char *aOutput, + size_t aOutputMaxLen) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aArgs); + + otError error = OT_ERROR_FAILED; + + VerifyOrExit(otPlatDiagModeGet(), error = OT_ERROR_INVALID_STATE); + if (aArgsLength == 0) + { + // Trigger an invalid memory access + int x = 0; + x += *((uint32_t *)0xdeadc0de); + otCliOutputFormat("%d", x); + } + else if (strcmp(aArgs[0], "assert") == 0) + { + assert(0); + } + else if (strcmp(aArgs[0], "udf") == 0) + { + asm("udf"); + } + else if (strcmp(aArgs[0], "bkpt") == 0) + { + asm("bkpt"); + } + +exit: + // Should not be reached + appendErrorResult(error, aOutput, aOutputMaxLen); + return error; +} + +static otError processCrashInfo(otInstance *aInstance, + uint8_t aArgsLength, + char *aArgs[], + char *aOutput, + size_t aOutputMaxLen) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aArgs); + OT_UNUSED_VARIABLE(aOutput); + OT_UNUSED_VARIABLE(aOutputMaxLen); + + otError error = OT_ERROR_NONE; + VerifyOrExit(aArgsLength == 0, error = OT_ERROR_INVALID_ARGS); + +#if CORTEXM3_EFR32 + efr32PrintResetInfo(); +#endif + +exit: + return error; +} +#endif + // ***************************************************************************** // Add more platform specific diagnostic's CLI features here. // ***************************************************************************** const struct PlatformDiagCommand sCommands[] = { {"addr-match", &processAddressMatch}, {"auto-ack", &processAutoAck}, +#if defined(SL_CATALOG_OT_CRASH_HANDLER_PRESENT) + {"fault", &processFault}, + {"ci", &processCrashInfo}, +#endif }; otError otPlatDiagProcess(otInstance *aInstance,