ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_infrastructure.h File Reference

Bring-up Helpers Called Before Any Driver Init. More...

#include "ra8_err.h"
Include dependency graph for ra8_infrastructure.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ra8_infrastructure_init (void)
 Run every piece of infrastructure init that a driver may assume.
ra8_err_t ra8_stack_canary_check (void)
 Verify the SRAM stack canary sentinel pattern.

Detailed Description

Bring-up Helpers Called Before Any Driver Init.

ra8_infrastructure_init() is the one place every piece of pre-driver state is brought up: the logging backend, the pin validator, and any CPU-core configuration that the rest of the HAL assumes is already in place (I-cache, D-cache, FPU enable, etc.).

Call order for a typical main:

void main(void)
{
// 1. Arch / infra bring-up (no peripheral access).
// 2. Clock tree.
// 3. Application peripherals.
// ...
}
void main(void)
The application entry point Reset_Handler hands control to.
Definition main.c:298
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
#define RA8_ERROR_CHECK(err)
Halt on fatal error.
Definition ra8_check.h:147
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
void ra8_infrastructure_init(void)
Run every piece of infrastructure init that a driver may assume.

Definition in file ra8_infrastructure.h.

Function Documentation

◆ ra8_infrastructure_init()

void ra8_infrastructure_init ( void )

Run every piece of infrastructure init that a driver may assume.

  • Initialises the log backend (ra8_log_init()).
  • Resets the pin validator (ra8_pin_validator_reset()).
  • Enables the FPU (CPACR bits 20..23) if the build is configured for hard-float.
  • Enables the I-cache and D-cache for performance.
  • Enables the branch prediction unit.
Precondition
SystemInit() has already executed.
Function is called from a single-threaded context.
Postcondition
Log backend, pin validator, and stack canary are initialized.
Subsequent ra8_*_init() driver entries may be called.
Note
Must be called before any ra8_* driver init function. Safe to call from main() before ThreadX / FreeRTOS / etc. starts (no scheduling dependency). Not thread-safe.
Since
0.1.0

Run every piece of infrastructure init that a driver may assume.

Initialises the log backend, resets the pin validator, and seeds the stack canary region.

Precondition
SystemInit() has executed.
Function is called from a single-threaded context.
Postcondition
Log backend, pin validator, and stack canary are initialized.
Drivers may now be brought up.
Note
Not thread-safe; intended for one-shot init only.
Since
0.1.0

Definition at line 86 of file ra8_infrastructure.c.

References internal_write_stack_canary(), ra8_log_info, ra8_log_init(), and ra8_pin_validator_reset().

◆ ra8_stack_canary_check()

ra8_err_t ra8_stack_canary_check ( void )
nodiscard

Verify the SRAM stack canary sentinel pattern.

Walks the linker-defined .stack_canary region (32 bytes just below the stack top) and confirms every word still holds the seed value written by ra8_infrastructure_init. A mismatch means the main stack has overflowed into the sentinel; callers typically log a fatal error and reboot.

Returns
ra8_err_t error code.
Return values
k_ra8_okSentinel still intact.
k_ra8_err_validation_failedOne or more words corrupted.
Precondition
ra8_infrastructure_init has been called.
Postcondition
No state is modified.
Note
Thread safety: safe to call concurrently with everything except the linker symbol redefinition path used by tests.
Since
0.1.0

Verify the SRAM stack canary sentinel pattern.

Walks the linker-defined region and compares each word to k_ra8_stack_canary_pattern.

Returns
Error code.
Return values
k_ra8_okSentinel intact.
k_ra8_err_validation_failedAt least one word was corrupted.
Precondition
ra8_infrastructure_init() has run.
Linker-defined sentinel symbols are valid (target build).
Postcondition
No state modified.
Result reflects the canary region at the moment of the call.
Note
Thread-safe (read-only walk). On the off-target host this is a no-op that always returns k_ra8_ok.
Since
0.1.0

Definition at line 120 of file ra8_infrastructure.c.

References g_ra8_ls_stack_canary_end, g_ra8_ls_stack_canary_start, k_ra8_err_validation_failed, k_ra8_ok, and k_ra8_stack_canary_pattern.