What is Reboot?
The Reboot module requests a controlled system restart. It's the mechanism you call when unrecoverable errors require a fresh start. The integrator provides an OSAdapter that actually performs the reset (watchdog, CPU reset, supervisory processor command, etc.).
Key idea: When recovery is impossible, restart cleanly rather than hang.
Quick Start
1. Register OSAdapter at Startup
Integrator supplies platform-specific reboot implementation:
watchdog_enable_without_pet(1ms);
while (1) {}
}
.request = platform_reboot
};
rte_status_t
Common result/status codes.
@ RTE_STATUS_NOT_SUPPORTED
rte_status_t rte_osadapter_reboot_register(const rte_osadapter_reboot_t *adapter)
Registers the OSAdapter reboot implementation.
OSAdapter reboot operations vtable.
2. Request Reboot on Critical Error
if (unrecoverable_error_detected) {
}
}
rte_status_t rte_reboot_request(uint16_t reason_code)
Requests a controlled system restart.
const char * rte_status_to_string(rte_status_t status)
Returns a short, static, human-readable string for a status code. Intended for diagnostics/logging on...
Integration with Safe-State
Typically called from RTE_REBOOT macro or safe-state handler:
log_critical("Initiating controlled restart");
flush_logs();
close_resources();
while (1) {}
}
}
rte_safestate_level_t
Safe-state severity levels (ADR-004 section 2.1).
@ RTE_SAFESTATE_LEVEL_REBOOT
Reason Codes
Pass reason code (16-bit) to identify why reboot was requested:
#define APP_REASON_CRITICAL_ERROR 1
#define APP_REASON_WATCHDOG_TIMEOUT 2
#define APP_REASON_MEMORY_CORRUPTION 3
#define APP_REASON_UNRECOVERABLE_FAULT 4
#define APP_REASON_FIRMWARE_UPDATE 5
OSAdapter can persist reason code to NVM for post-reboot diagnostics.
Practical Examples
Example 1: Watchdog-Triggered Reboot
void watchdog_handler(void *context) {
app_t *app = (app_t *)context;
log_critical("Watchdog timeout - system hung");
log_critical(" Cycle count: %u", app->cycle_count);
log_critical(" Initiating controlled reboot");
}
Example 2: Memory Corruption Detection
void check_memory_integrity(void) {
uint32_t checksum = compute_memory_checksum(&heap_start, heap_size);
if (checksum != expected_checksum) {
log_critical("Memory corruption detected!");
log_critical(" Computed: 0x%x", checksum);
log_critical(" Expected: 0x%x", expected_checksum);
log_critical(" Rebooting...");
}
}
Example 3: Reboot with Fallback
void request_reboot_with_timeout(uint32_t timeout_ms) {
rte_watchdog_t fallback_wd = setup_timeout_watchdog(timeout_ms);
while (1) {}
}
}
rte_status_t rte_watchdog_start(rte_watchdog_t watchdog)
Start watchdog timer.
Best Practices
- Register OSAdapter at startup
- Before any code can request reboot
- Platform-specific implementation
- Must handle lack of hardware support gracefully
- Use specific reason codes
- Not just 0
- Aids post-reboot diagnostics
- OSAdapter can log/persist for analysis
- Prepare for non-return
- rte_reboot_request() typically doesn't return
- Don't rely on execution continuing
- Any final cleanup should happen before calling
- Have fallback mechanism
- Use watchdog timeout as fallback
- Ensures reset happens even if OSAdapter fails
- Better than hanging indefinitely
- Only on unrecoverable errors
- Not for transient failures
- Not for user-initiated shutdown (use graceful exit)
- Only when system state is unsafe to continue
See Also