|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Init-time bump-arena implementation (Layer 0, #147). More...
#include "ra8_arena.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"Go to the source code of this file.
Functions | |
| static bool | internal_is_pow2 (uint32_t v) |
Test whether v is a power of two. | |
| ra8_err_t | ra8_arena_init (ra8_arena_t *arena, void *base, uint32_t size) |
| Bind a bump arena over a caller-owned tier region. | |
| ra8_err_t | ra8_arena_carve (ra8_arena_t *arena, uint32_t bytes, uint32_t align, void **out_ptr) |
| Carve an aligned sub-block from the arena (bump; no free). | |
| ra8_err_t | ra8_arena_remaining (const ra8_arena_t *arena, uint32_t *out_remaining) |
| Report the bytes still available in the arena. | |
Variables | |
| static const char *const | s_tag = "ra8_arena" |
| Module log tag. | |
Init-time bump-arena implementation (Layer 0, #147).
Bump-only allocation with power-of-two alignment. Fit checks use uintptr_t subtraction against the region end so they never overflow.
Definition in file ra8_arena.c.
|
static |
Test whether v is a power of two.
A power of two has exactly one set bit, so v & (v - 1) is zero; zero is rejected by the leading v != 0 term.
| [in] | v | Value to test. |
v is a non-zero power of two, else false. | true | v is a non-zero power of two. |
| false | v is zero or has more than one set bit. |
v fits in a uint32_t. v.Definition at line 48 of file ra8_arena.c.
References RA8_INTERNAL.
Referenced by ra8_arena_carve().
|
nodiscard |
Carve an aligned sub-block from the arena (bump; no free).
| [in] | arena | Initialised arena. |
| [in] | bytes | Block size to carve (> 0). |
| [in] | align | Required alignment in bytes (a power of two, >= 1). |
| [out] | out_ptr | Receives the aligned block pointer on success. |
| k_ra8_ok | Block carved; *out_ptr set. |
| k_ra8_err_null_ptr | arena or out_ptr was NULL. |
| k_ra8_err_invalid_size | bytes was zero. |
| k_ra8_err_invalid_arg | align was zero or not a power of two. |
| k_ra8_err_no_mem | The aligned block does not fit the remainder. |
Definition at line 69 of file ra8_arena.c.
References ra8_arena_t::base, internal_is_pow2(), k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_err_no_mem, k_ra8_ok, RA8_CHECK_NULL_PTR, s_tag, ra8_arena_t::size, and ra8_arena_t::used.
Referenced by mem_run_arena().
|
nodiscard |
Bind a bump arena over a caller-owned tier region.
| [out] | arena | Arena state to populate (zero-initialised by caller). |
| [in] | base | First byte of the region (out-lives the arena). |
| [in] | size | Region length in bytes. |
| k_ra8_ok | Arena ready (empty). |
| k_ra8_err_null_ptr | arena or base was NULL. |
| k_ra8_err_invalid_size | size was zero. |
Definition at line 56 of file ra8_arena.c.
References ra8_arena_t::base, k_ra8_err_invalid_size, k_ra8_ok, RA8_CHECK_NULL_PTR, s_tag, ra8_arena_t::size, and ra8_arena_t::used.
Referenced by mem_run_arena().
|
nodiscard |
Report the bytes still available in the arena.
| [in] | arena | Initialised arena. |
| [out] | out_remaining | Receives size - used. |
| k_ra8_ok | Remaining bytes reported. |
| k_ra8_err_null_ptr | arena or out_remaining was NULL. |
Definition at line 94 of file ra8_arena.c.
References k_ra8_ok, RA8_CHECK_NULL_PTR, s_tag, ra8_arena_t::size, and ra8_arena_t::used.
Referenced by mem_run_arena().
|
static |
Module log tag.
Definition at line 25 of file ra8_arena.c.