rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
reset_cause.c File Reference

Why the IOmcu last started: see reset_cause.h. More...

#include "reset_cause.h"
#include <stdio.h>

Functions

int reset_cause_boot_type (const reset_regs_t *r)
 The boot type in the boot word, without the chained flag.
reset_cause_t reset_cause_decode (const reset_regs_t *r)
 Names the cause of the last start.
const char * reset_cause_word (reset_cause_t c)
 The fixed word for a cause: POR, BOR, RUN_PIN, GLITCH, DEBUGGER, POWER_DOWN, FLASH_UPDATE, RAM_IMAGE, BOOTSEL_REBOOT, SW_RESET, WATCHDOG or UNKNOWN.
static size_t as_len (int len)
 snprintf()'s count as a size_t; a format error reads as 0.
size_t reset_cause_full (const reset_regs_t *r, char *out, size_t n)
 The text of the start-up line and the 3s line, every raw value in hex: POR (chip_reset 0x00010000 reason 0x0 boot 0x00000000 params 0x00000000 0x00000000 scratch 0x00000000 0x00000000), with boot none in place of the boot word and the params when rom_get_boot_info() failed.

Variables

static const char *const k_words [RESET_CAUSE_COUNT]
 The words, indexed by reset_cause_t.

Detailed Description

Why the IOmcu last started: see reset_cause.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ as_len()

size_t as_len ( int len)
static

snprintf()'s count as a size_t; a format error reads as 0.

Parameters
lenWhat snprintf() returned.
Returns
len, or 0 when it is negative.

◆ reset_cause_boot_type()

int reset_cause_boot_type ( const reset_regs_t * r)

The boot type in the boot word, without the chained flag.

Parameters
rThe raw values.
Returns
The boot type, or -1 when rom_get_boot_info() failed.

◆ reset_cause_decode()

reset_cause_t reset_cause_decode ( const reset_regs_t * r)

Names the cause of the last start.

First match wins:

  1. The boot type: FLASH_UPDATE (this firmware's update over CAN, a UF2 copied to the BOOTSEL drive, picotool load -x), RAM_IMAGE, BOOTSEL (the boot ROM reports this type only while it stays in BOOTSEL; decoded for completeness).
  2. REASON TIMER or FORCE: a watchdog system reset, and CHIP_RESET is the record of an older reset. SCRATCH2/SCRATCH3 at RESET_PICOTOOL_P0/P1 with a NORMAL boot: BOOTSEL_REBOOT. The 1200 baud request and picotool's -f enter BOOTSEL through reboot() with p0 = interface flags and p1 = the activity LED pin (0xFFFFFFFF for none); the reboot out of BOOTSEL overwrites both. The firmware zeroes both registers after it reads them. Else FORCE: SW_RESET (the SDK's watchdog_reboot() with no delay). Else WATCHDOG: the boot ROM's 16.7s TBYB (try before you buy) timer after an update that was not bought, a reboot() with type NORMAL and other parameters, or the SDK's watchdog_reboot() with a delay.
  3. REASON 0, so CHIP_RESET holds this start's chip-level reset: HAD_POR, HAD_BOR, HAD_RUN_LOW, HAD_GLITCH_DETECT, in that order; then HAD_DP_RESET_REQ, HAD_RESCUE or HAD_HZD_SYS_RESET_REQ as DEBUGGER; HAD_SWCORE_PD as POWER_DOWN; a HAD_WATCHDOG_* bit as WATCHDOG.
  4. Nothing set: UNKNOWN.

A debugger's warm reset of a core clears REASON (datasheet, WATCHDOG REASON) without a chip-level reset; the start after one reads as the chip-level reset before it.

Parameters
rThe raw values; NULL reads as UNKNOWN.
Returns
The cause.

◆ reset_cause_full()

size_t reset_cause_full ( const reset_regs_t * r,
char * out,
size_t n )

The text of the start-up line and the 3s line, every raw value in hex: POR (chip_reset 0x00010000 reason 0x0 boot 0x00000000 params 0x00000000 0x00000000 scratch 0x00000000 0x00000000), with boot none in place of the boot word and the params when rom_get_boot_info() failed.

Parameters
rThe raw values.
outReceives the text, NUL-terminated and cut to fit.
nSize of out in bytes; RESET_CAUSE_FULL_MAX holds it.
Returns
The length the whole text needs, without the NUL, as snprintf().

◆ reset_cause_word()

const char * reset_cause_word ( reset_cause_t c)

The fixed word for a cause: POR, BOR, RUN_PIN, GLITCH, DEBUGGER, POWER_DOWN, FLASH_UPDATE, RAM_IMAGE, BOOTSEL_REBOOT, SW_RESET, WATCHDOG or UNKNOWN.

Parameters
cThe cause; a value out of range reads as UNKNOWN.
Returns
The word, a static string of at most 14 characters.

Variable Documentation

◆ k_words

const char* const k_words[RESET_CAUSE_COUNT]
static
Initial value:
= {
[RESET_CAUSE_UNKNOWN] = "UNKNOWN",
[RESET_CAUSE_POR] = "POR",
[RESET_CAUSE_BOR] = "BOR",
[RESET_CAUSE_RUN_PIN] = "RUN_PIN",
[RESET_CAUSE_GLITCH] = "GLITCH",
[RESET_CAUSE_DEBUGGER] = "DEBUGGER",
[RESET_CAUSE_POWER_DOWN] = "POWER_DOWN",
[RESET_CAUSE_FLASH_UPDATE] = "FLASH_UPDATE",
[RESET_CAUSE_RAM_IMAGE] = "RAM_IMAGE",
[RESET_CAUSE_BOOTSEL_REBOOT] = "BOOTSEL_REBOOT",
[RESET_CAUSE_SW_RESET] = "SW_RESET",
[RESET_CAUSE_WATCHDOG] = "WATCHDOG",
}
@ RESET_CAUSE_SW_RESET
Definition reset_cause.h:124
@ RESET_CAUSE_FLASH_UPDATE
Definition reset_cause.h:121
@ RESET_CAUSE_GLITCH
Definition reset_cause.h:118
@ RESET_CAUSE_WATCHDOG
Definition reset_cause.h:125
@ RESET_CAUSE_RUN_PIN
Definition reset_cause.h:117
@ RESET_CAUSE_UNKNOWN
Definition reset_cause.h:114
@ RESET_CAUSE_BOR
Definition reset_cause.h:116
@ RESET_CAUSE_DEBUGGER
Definition reset_cause.h:119
@ RESET_CAUSE_BOOTSEL_REBOOT
Definition reset_cause.h:123
@ RESET_CAUSE_POR
Definition reset_cause.h:115
@ RESET_CAUSE_RAM_IMAGE
Definition reset_cause.h:122
@ RESET_CAUSE_POWER_DOWN
Definition reset_cause.h:120

The words, indexed by reset_cause_t.