PebbleOS v4.44.0-105-g1dd754433
Loading...
Searching...
No Matches
Reboot and power-off

Restart or power off the system, with handlers to shut down in order. More...

Data Structures

struct  pbl_sys_off_handler
 Restart or power-off handler. More...
 

Macros

#define PBL_SYS_OFF_PRIO_LOW   -128
 Priority of handlers that must run after the others of their mode.
 
#define PBL_SYS_OFF_PRIO_DEFAULT   0
 Default handler priority.
 
#define PBL_SYS_OFF_PRIO_HIGH   128
 Priority of handlers that must run before the others of their mode.
 
#define PBL_SYS_OFF_HANDLER_DEFINE(_name, _mode, _priority, _handler, _user_data)
 Define a restart or power-off handler.
 

Enumerations

enum  pbl_sys_off_mode { PBL_SYS_OFF_RESTART_PREPARE , PBL_SYS_OFF_POWER_OFF_PREPARE , PBL_SYS_OFF_RESTART , PBL_SYS_OFF_POWER_OFF }
 Stage of a restart or power-off a handler runs in. More...
 

Functions

void pbl_reboot (void)
 Restart the system in order.
 
void pbl_power_off (void)
 Power off the system in order.
 
void pbl_reboot_emergency (void)
 Reset the SoC at once, without running any handler.
 
void pbl_soc_reset (void)
 Reset the SoC.
 

Detailed Description

Restart or power off the system, with handlers to shut down in order.

pbl_reboot() and pbl_power_off() run the handlers of the matching prepare mode, then the handlers that restart or power off the system, highest priority first. Prepare handlers shut down what must not be cut off midway, e.g. a radio link or a flash erase. Restart and power-off handlers end the system; one that returns has declined or failed, and the next one runs. If none ends the system, the kernel resets the SoC with pbl_soc_reset() when the SoC selects CONFIG_SOC_HAS_RESET, else with the architecture's reset.

Prepare handlers only run on the first request made from a thread with interrupts and the scheduler unlocked; otherwise, or when a handler requests a reboot itself, they are skipped. Restart and power-off handlers run in the context of the request, so they must check it before doing anything that blocks.

static void prv_radio_off(enum pbl_sys_off_mode mode, void *user_data) {
radio_disable();
}
prv_radio_off, nullptr);
PBL_SYS_OFF_PRIO_DEFAULT, prv_radio_off, nullptr);
#define PBL_SYS_OFF_HANDLER_DEFINE(_name, _mode, _priority, _handler, _user_data)
Define a restart or power-off handler.
Definition reboot.h:89
pbl_sys_off_mode
Stage of a restart or power-off a handler runs in.
Definition reboot.h:40
#define PBL_SYS_OFF_PRIO_DEFAULT
Default handler priority.
Definition reboot.h:54
@ PBL_SYS_OFF_POWER_OFF_PREPARE
Before a power-off, from a thread; may block.
Definition reboot.h:44
@ PBL_SYS_OFF_RESTART_PREPARE
Before a restart, from a thread; may block.
Definition reboot.h:42

Macro Definition Documentation

◆ PBL_SYS_OFF_HANDLER_DEFINE

#define PBL_SYS_OFF_HANDLER_DEFINE (   _name,
  _mode,
  _priority,
  _handler,
  _user_data 
)
Value:
static const struct pbl_sys_off_handler pbl_sys_off_handler_##_name PBL_USED PBL_ALIGNED(4) \
PBL_SECTION(".pbl_sys_off_handlers." #_name) = { \
.handler = (_handler), \
.user_data = (_user_data), \
.mode = (_mode), \
.priority = (_priority), \
}
#define PBL_USED
Keep the symbol even if it appears unreferenced.
Definition compiler.h:90
#define PBL_ALIGNED(bytes)
Align the symbol or type.
Definition compiler.h:87
#define PBL_SECTION(name)
Place the symbol in a linker section.
Definition compiler.h:126
Restart or power-off handler.
Definition reboot.h:59
int priority
Order among the handlers of mode, highest first.
Definition reboot.h:67
void(* handler)(enum pbl_sys_off_mode mode, void *user_data)
Called in mode.
Definition reboot.h:61
void * user_data
Data passed to handler.
Definition reboot.h:63

Define a restart or power-off handler.

Parameters
_nameName of the handler, unique across the firmware.
_modeMode the handler runs in, an pbl_sys_off_mode.
_priorityOrder among the handlers of _mode, highest first.
_handlerFunction called in _mode.
_user_dataData passed to _handler.

◆ PBL_SYS_OFF_PRIO_DEFAULT

#define PBL_SYS_OFF_PRIO_DEFAULT   0

Default handler priority.

◆ PBL_SYS_OFF_PRIO_HIGH

#define PBL_SYS_OFF_PRIO_HIGH   128

Priority of handlers that must run before the others of their mode.

◆ PBL_SYS_OFF_PRIO_LOW

#define PBL_SYS_OFF_PRIO_LOW   -128

Priority of handlers that must run after the others of their mode.

Enumeration Type Documentation

◆ pbl_sys_off_mode

Stage of a restart or power-off a handler runs in.

Enumerator
PBL_SYS_OFF_RESTART_PREPARE 

Before a restart, from a thread; may block.

PBL_SYS_OFF_POWER_OFF_PREPARE 

Before a power-off, from a thread; may block.

PBL_SYS_OFF_RESTART 

Restart the system.

PBL_SYS_OFF_POWER_OFF 

Power off the system.

Function Documentation

◆ pbl_power_off()

void pbl_power_off ( void  )

Power off the system in order.

Runs the PBL_SYS_OFF_POWER_OFF_PREPARE handlers, then the PBL_SYS_OFF_POWER_OFF ones. Resets the SoC if none of them powers off. Callable from any context.

◆ pbl_reboot()

void pbl_reboot ( void  )

Restart the system in order.

Runs the PBL_SYS_OFF_RESTART_PREPARE handlers, then the PBL_SYS_OFF_RESTART ones. Callable from any context.

◆ pbl_reboot_emergency()

void pbl_reboot_emergency ( void  )

Reset the SoC at once, without running any handler.

For contexts where nothing else can be trusted to work. Callable from any context.

◆ pbl_soc_reset()

void pbl_soc_reset ( void  )

Reset the SoC.

Implemented by SoCs that select CONFIG_SOC_HAS_RESET, for those the architecture's reset doesn't suit. Called with interrupts locked.