ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_devcfg_store_extra_mram.c
Go to the documentation of this file.
1
31
32#include <stddef.h>
33#include <stdint.h>
34#include <string.h>
35
36#include "ra8_attributes.h"
37#include "ra8_check.h"
38#include "ra8_devcfg.h"
39#include "ra8_err.h"
40
41#ifndef RA8_OFF_TARGET
42#include "ra8_flash_core.h"
43#include "ra8_flash_regs.h"
44#endif
45
52static const char* const s_tag = "DEVCFG_XM";
53
61typedef enum : uint32_t {
65
66#ifdef RA8_OFF_TARGET
67
72typedef enum : uint8_t {
73 k_ra8_devcfg_xm_blank = 0xFFU,
74} ra8_devcfg_xm_shadow_t;
75
86static uint8_t s_shadow[k_ra8_devcfg_xm_span] = {};
87
94static bool s_shadow_ready = false;
95
115static uint8_t* internal_devcfg_xm_shadow(void)
116{
117 if (!s_shadow_ready) {
118 (void)memset(s_shadow, (int)k_ra8_devcfg_xm_blank, sizeof s_shadow);
119 s_shadow_ready = true;
120 }
121 return s_shadow;
122}
123
124#endif /* RA8_OFF_TARGET */
125
150[[nodiscard]] static ra8_err_t internal_devcfg_xm_read(uint32_t offset, uint8_t* dst, uint32_t len)
151{
152 RA8_CHECK_NULL_PTR(dst, s_tag, "xm read: dst null");
153 if ((offset + len) > (uint32_t)k_ra8_devcfg_xm_span) {
155 }
156#ifdef RA8_OFF_TARGET
157 (void)memcpy(dst, &internal_devcfg_xm_shadow()[offset], (size_t)len);
158#else
159 /* HUM Ch 59.1 "Address Map" p 3543 -- the extra-MRAM window is directly
160 * memory-mapped for CPU reads; a virgin word returns 0xFFFFFFFF with valid
161 * ECC and no BusFault (#315). */
162 const volatile uint8_t* src =
163 (const volatile uint8_t*)(uintptr_t)((uint32_t)k_ra8_flash_extra_start + offset);
164 for (uint32_t i = 0U; i < len; i++) {
165 dst[i] = src[i];
166 }
167#endif
168 return k_ra8_ok;
169}
170
197[[nodiscard]] static ra8_err_t
198internal_devcfg_xm_write(uint32_t offset, const uint8_t* src, uint32_t len)
199{
200 RA8_CHECK_NULL_PTR(src, s_tag, "xm write: src null");
201 if ((offset + len) > (uint32_t)k_ra8_devcfg_xm_span) {
203 }
204#ifdef RA8_OFF_TARGET
205 (void)memcpy(&internal_devcfg_xm_shadow()[offset], src, (size_t)len);
206 return k_ra8_ok;
207#else
208 /* Bounded by len/page_bytes (<= record_len/page_bytes = 4) chunks; each
209 * chunk stays inside one 32-byte program page. */
210 uint32_t done = 0U;
211 while (done < len) {
212 uint32_t chunk = len - done;
213 if (chunk > (uint32_t)k_ra8_devcfg_page_bytes) {
214 chunk = (uint32_t)k_ra8_devcfg_page_bytes;
215 }
216 const uint32_t addr = (uint32_t)k_ra8_flash_extra_start + offset + done;
217 const ra8_err_t err = ra8_flash_extra_mram_write(addr, &src[done], chunk);
218 RA8_RETURN_ON_ERROR(err, s_tag, "xm write: page program failed");
219 done += chunk;
220 }
221 return k_ra8_ok;
222#endif
223}
224
237
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
Definition ra8_check.h:184
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Per-device (per-unit) configuration record – schema, storage seam, two-copy resolution.
@ k_ra8_devcfg_page_bytes
Extra-MRAM program page.
Definition ra8_devcfg.h:100
@ k_ra8_devcfg_slot_bytes
Reserved slot pitch per copy.
Definition ra8_devcfg.h:98
@ k_ra8_devcfg_copy1_off
Copy 1 offset in extra-MRAM.
Definition ra8_devcfg.h:102
ra8_devcfg_xm_span_t
End of the devcfg region: copy 1 offset plus one reserved slot.
@ k_ra8_devcfg_xm_span
One past the last devcfg region byte.
static const ra8_devcfg_store_t s_default_store
The process-lifetime extra-MRAM-backed store.
static ra8_err_t internal_devcfg_xm_read(uint32_t offset, uint8_t *dst, uint32_t len)
Extra-MRAM read backend (ra8_devcfg_read_fn_t).
const ra8_devcfg_store_t * ra8_devcfg_default_store(void)
Return the production extra-MRAM-backed store binding.
static ra8_err_t internal_devcfg_xm_write(uint32_t offset, const uint8_t *src, uint32_t len)
Extra-MRAM write backend (ra8_devcfg_write_fn_t).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
Definition ra8_err.h:337
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Code MRAM + Extra MRAM + Option-Setting driver – core API.
ra8_err_t ra8_flash_extra_mram_write(uint32_t mram_addr, const uint8_t *src, uint32_t len)
Program 1..32 contiguous bytes into the general-purpose extra-MRAM window.
Flash / MRAM controller register layout for the Renesas RA8D2.
@ k_ra8_flash_extra_start
First legal Program target (FSBL setting).
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
Dependency-injection vtable for the record backing store.
Definition ra8_devcfg.h:320