Firmware
Macros | Functions
shutdown.cpp File Reference

Implementation of the API declared in px4_shutdown.h. More...

#include <board_config.h>
#include <px4_workqueue.h>
#include <px4_shutdown.h>
#include <px4_tasks.h>
#include <px4_log.h>
#include <stdint.h>
#include <errno.h>
#include <pthread.h>

Macros

#define MODULE_NAME   "shutdown"
 
#define SHUTDOWN_ARG_IN_PROGRESS   (1<<0)
 
#define SHUTDOWN_ARG_REBOOT   (1<<1)
 
#define SHUTDOWN_ARG_TO_BOOTLOADER   (1<<2)
 

Functions

int px4_shutdown_lock ()
 Grab the shutdown lock. More...
 
int px4_shutdown_unlock ()
 Release the shutdown lock. More...
 
int px4_register_shutdown_hook (shutdown_hook_t hook)
 Register a method that should be called when powering off (and also on reboot). More...
 
int px4_unregister_shutdown_hook (shutdown_hook_t hook)
 Unregister a shutdown hook. More...
 
int px4_shutdown_request (bool reboot, bool to_bootloader)
 Request the system to shut down or reboot. More...
 

Detailed Description

Implementation of the API declared in px4_shutdown.h.

Function Documentation

§ px4_register_shutdown_hook()

int px4_register_shutdown_hook ( shutdown_hook_t  hook)

Register a method that should be called when powering off (and also on reboot).

Parameters
hookcallback method. It must not block, but return immediately. When the system is requested to shutdown, the registered hooks will be called regularily until either all of them return true, or a timeout is reached.
Returns
0 on success, <0 on error

§ px4_shutdown_lock()

int px4_shutdown_lock ( void  )

Grab the shutdown lock.

It will prevent the system from shutting down until the lock is released. It is safe to call this recursively.

Returns
0 on success, <0 on error

§ px4_shutdown_request()

int px4_shutdown_request ( bool  reboot,
bool  to_bootloader 
)

Request the system to shut down or reboot.

Note the following:

  • The system might not support to shutdown (or reboot). In that case -EINVAL will be returned.
  • The system might not shutdown immediately, so expect this method to return even on success.
    Parameters
    rebootperform a reboot instead of a shutdown
    to_bootloaderreboot into bootloader mode (only used if reboot is true)
    Returns
    0 on success, <0 on error

§ px4_shutdown_unlock()

int px4_shutdown_unlock ( void  )

Release the shutdown lock.

Returns
0 on success, <0 on error

§ px4_unregister_shutdown_hook()

int px4_unregister_shutdown_hook ( shutdown_hook_t  hook)

Unregister a shutdown hook.

Parameters
hookcallback method to be removed
Returns
0 on success, <0 on error