Skip to content

Commit

Permalink
[diag] add diag fault <faultType> and diag ci commands
Browse files Browse the repository at this point in the history
`diag fault <faultType>` allows users to trigger various fault types

`diag ci` prints crash info
  • Loading branch information
lmnotran committed Feb 29, 2024
1 parent 19e06d6 commit 3389dd3
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/src/diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3389dd3

Please sign in to comment.