mirror of
https://github.com/stnolting/neorv32.git
synced 2025-04-18 19:35:02 -04:00
[sw/lib] add restart/reset functions (#1226)
This commit is contained in:
commit
e1283bcb3b
4 changed files with 33 additions and 1 deletions
|
@ -175,16 +175,18 @@ extern "C" {
|
|||
|
||||
|
||||
/**********************************************************************//**
|
||||
* @name Export linker script symbols
|
||||
* @name NEORV32 linker symbols
|
||||
**************************************************************************/
|
||||
/**@{*/
|
||||
extern char __heap_start[]; /**< heap start address */
|
||||
extern char __heap_end[]; /**< heap last address */
|
||||
extern char __crt0_max_heap[]; /**< heap size in bytes */
|
||||
extern char __crt0_entry[]; /**< crt0 entry point */
|
||||
// aliases
|
||||
#define NEORV32_HEAP_BEGIN ((uint32_t)&__heap_start[0])
|
||||
#define NEORV32_HEAP_END ((uint32_t)&__heap_end[0])
|
||||
#define NEORV32_HEAP_SIZE ((uint32_t)&__crt0_max_heap[0])
|
||||
#define NEORV32_CRT0_ENTRY ((uint32_t)&__crt0_entry[0])
|
||||
/**@}*/
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,20 @@ uint32_t neorv32_cpu_hpm_get_size(void);
|
|||
/**@}*/
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* Restart CPU core (jump to boot address).
|
||||
*
|
||||
* @warning This is just a "software reset" that uses the in-code reset/boot/entry address linked at compile time.
|
||||
**************************************************************************/
|
||||
inline void __attribute__ ((always_inline)) neorv32_cpu_soft_restart(void) {
|
||||
|
||||
uint32_t sw_boot_addr = NEORV32_CRT0_ENTRY; // linker symbol
|
||||
asm volatile ("jalr x0, 0(%[dst])" : : [dst] "r" (sw_boot_addr));
|
||||
__builtin_unreachable();
|
||||
while(1); // should never be reached
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* Store unsigned word to address space.
|
||||
*
|
||||
|
|
|
@ -69,6 +69,7 @@ int neorv32_wdt_available(void);
|
|||
void neorv32_wdt_setup(uint32_t timeout, int lock, int strict);
|
||||
int neorv32_wdt_disable(void);
|
||||
void neorv32_wdt_feed(uint32_t password);
|
||||
void neorv32_wdt_force_hwreset(void);
|
||||
int neorv32_wdt_get_cause(void);
|
||||
/**@}*/
|
||||
|
||||
|
|
|
@ -90,6 +90,21 @@ void neorv32_wdt_feed(uint32_t password) {
|
|||
}
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* Force a hardware reset triggered by the watchdog.
|
||||
**************************************************************************/
|
||||
void neorv32_wdt_force_hwreset(void) {
|
||||
|
||||
// enable strict mode; if strict mode is already enabled and the WDT
|
||||
// is locked this will already trigger a hardware reset
|
||||
NEORV32_WDT->CTRL |= (uint32_t)(1 << WDT_CTRL_STRICT);
|
||||
|
||||
// try to reset the WDT using an incorrect password;
|
||||
// this will finally trigger a hardware reset
|
||||
NEORV32_WDT->RESET = 0;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************//**
|
||||
* Get cause of last system reset.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue