idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches

Reset reason, restart, shutdown handlers, and heap information. More...

Namespaces

namespace  idfxx
 

Enumerations

enum class  idfxx::reset_reason : int {
  idfxx::reset_reason::unknown = 0 ,
  idfxx::reset_reason::power_on = 1 ,
  idfxx::reset_reason::external = 2 ,
  idfxx::reset_reason::software = 3 ,
  idfxx::reset_reason::panic = 4 ,
  idfxx::reset_reason::interrupt_watchdog = 5 ,
  idfxx::reset_reason::task_watchdog = 6 ,
  idfxx::reset_reason::watchdog = 7 ,
  idfxx::reset_reason::deep_sleep = 8 ,
  idfxx::reset_reason::brownout = 9 ,
  idfxx::reset_reason::sdio = 10 ,
  idfxx::reset_reason::usb = 11 ,
  idfxx::reset_reason::jtag = 12 ,
  idfxx::reset_reason::efuse = 13 ,
  idfxx::reset_reason::power_glitch = 14 ,
  idfxx::reset_reason::cpu_lockup = 15
}
 Reason for the most recent chip reset. More...
 

Functions

std::string idfxx::to_string (reset_reason r)
 Returns a string representation of a reset reason.
 
reset_reason idfxx::last_reset_reason () noexcept
 Returns the reason for the most recent chip reset.
 
void idfxx::restart ()
 Restart the chip immediately.
 
void idfxx::register_shutdown_handler (void(*handler)())
 Registers a function to be called during chip shutdown/restart.
 
void idfxx::unregister_shutdown_handler (void(*handler)())
 Unregisters a previously registered shutdown handler.
 
result< voididfxx::try_register_shutdown_handler (void(*handler)())
 Registers a function to be called during chip shutdown/restart.
 
result< voididfxx::try_unregister_shutdown_handler (void(*handler)())
 Unregisters a previously registered shutdown handler.
 
std::size_t idfxx::free_heap_size () noexcept
 Returns the current free heap size in bytes.
 
std::size_t idfxx::free_internal_heap_size () noexcept
 Returns the current free internal heap size in bytes.
 
std::size_t idfxx::minimum_free_heap_size () noexcept
 Returns the minimum free heap size recorded since boot.
 

Detailed Description

Reset reason, restart, shutdown handlers, and heap information.

Enumeration Type Documentation

◆ reset_reason

Reason for the most recent chip reset.

auto reason = idfxx::last_reset_reason();
// Handle crash recovery
}
reset_reason last_reset_reason() noexcept
Returns the reason for the most recent chip reset.
Definition system.hpp:72
@ panic
Software reset due to exception/panic.
Enumerator
unknown 

Reset reason could not be determined.

power_on 

Power-on reset.

external 

Reset by external pin (not applicable for ESP32).

software 

Software reset via esp_restart.

panic 

Software reset due to exception/panic.

interrupt_watchdog 

Reset due to interrupt watchdog.

task_watchdog 

Reset due to task watchdog.

watchdog 

Reset due to other watchdog.

deep_sleep 

Reset after exiting deep sleep mode.

brownout 

Brownout reset (software or hardware).

sdio 

Reset over SDIO.

usb 

Reset by USB peripheral.

jtag 

Reset by JTAG.

efuse 

Reset due to efuse error.

power_glitch 

Reset due to power glitch detected.

cpu_lockup 

Reset due to CPU lock up.

Definition at line 38 of file system.hpp.

Function Documentation

◆ free_heap_size()

std::size_t idfxx::free_heap_size ( )
inlinenoexcept

Returns the current free heap size in bytes.

Returns
The number of bytes available in the heap.

Definition at line 147 of file system.hpp.

◆ free_internal_heap_size()

std::size_t idfxx::free_internal_heap_size ( )
inlinenoexcept

Returns the current free internal heap size in bytes.

Internal memory is directly accessible by the CPU and is typically used for performance-critical allocations.

Returns
The number of bytes available in internal heap.

Definition at line 159 of file system.hpp.

◆ last_reset_reason()

reset_reason idfxx::last_reset_reason ( )
inlinenoexcept

Returns the reason for the most recent chip reset.

Returns
The reset reason.

Definition at line 72 of file system.hpp.

◆ minimum_free_heap_size()

std::size_t idfxx::minimum_free_heap_size ( )
inlinenoexcept

Returns the minimum free heap size recorded since boot.

This is the "high water mark" — the lowest free heap level reached at any point during execution. Useful for diagnosing memory pressure.

Returns
The minimum number of free bytes recorded since boot.

Definition at line 171 of file system.hpp.

◆ register_shutdown_handler()

void idfxx::register_shutdown_handler ( void(*)()  handler)

Registers a function to be called during chip shutdown/restart.

Shutdown handlers are called in reverse order of registration when esp_restart() is invoked.

Parameters
handlerFunction pointer to the shutdown handler.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.

◆ restart()

void idfxx::restart ( )
inline

Restart the chip immediately.

Performs a software reset. This function does not return. Registered shutdown handlers are called before the restart occurs.

Definition at line 82 of file system.hpp.

◆ to_string()

std::string idfxx::to_string ( reset_reason  r)

Returns a string representation of a reset reason.

Parameters
rThe reset reason to convert.
Returns
A descriptive string, or "unknown(N)" for unrecognized values.

◆ try_register_shutdown_handler()

result< void > idfxx::try_register_shutdown_handler ( void(*)()  handler)

Registers a function to be called during chip shutdown/restart.

Shutdown handlers are called in reverse order of registration when esp_restart() is invoked.

Parameters
handlerFunction pointer to the shutdown handler.
Returns
Success, or an error.
Return values
idfxx::errc::invalid_stateif the handler was already registered.

◆ try_unregister_shutdown_handler()

result< void > idfxx::try_unregister_shutdown_handler ( void(*)()  handler)

Unregisters a previously registered shutdown handler.

Parameters
handlerFunction pointer to the shutdown handler to remove.
Returns
Success, or an error.
Return values
idfxx::errc::invalid_stateif the handler was not registered.

◆ unregister_shutdown_handler()

void idfxx::unregister_shutdown_handler ( void(*)()  handler)

Unregisters a previously registered shutdown handler.

Parameters
handlerFunction pointer to the shutdown handler to remove.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron failure.