ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
lx_nor_ram.c
Go to the documentation of this file.
1
24
25#include "lx_nor_ram.h"
26
27#include "lx_api.h"
28#include "ra8_attributes.h"
29
45
53
60static ULONG s_ram_sector_buf[LX_NOR_SECTOR_SIZE];
61
79/* Signature is fixed by the LevelX driver-read callback type (non-const). */
80/* cppcheck-suppress constParameterCallback -- bound to the LevelX LX_NOR_FLASH read callback typedef; the ULONG* signature is fixed by the driver seam. */
81/* NOLINTNEXTLINE(readability-non-const-parameter) -- LevelX driver callback signature is fixed by the vendor seam. */
82RA8_INTERNAL static UINT internal_ram_read(ULONG* flash_address, ULONG* destination, ULONG words)
83{
84 if (flash_address == LX_NULL) {
85 return (UINT)LX_ERROR;
86 }
87 if (destination == LX_NULL) {
88 return (UINT)LX_ERROR;
89 }
90 for (ULONG i = 0U; i < words; i++) {
91 destination[i] = flash_address[i];
92 }
93 return (UINT)LX_SUCCESS;
94}
95
113/* Signature is fixed by the LevelX driver-write callback type (non-const). */
114/* cppcheck-suppress constParameterCallback -- bound to the LevelX LX_NOR_FLASH write callback typedef; the ULONG* signature is fixed by the driver seam. */
115/* NOLINTNEXTLINE(readability-non-const-parameter) -- LevelX driver callback signature is fixed by the vendor seam. */
116RA8_INTERNAL static UINT internal_ram_write(ULONG* flash_address, ULONG* source, ULONG words)
117{
118 if (flash_address == LX_NULL) {
119 return (UINT)LX_ERROR;
120 }
121 if (source == LX_NULL) {
122 return (UINT)LX_ERROR;
123 }
124 for (ULONG i = 0U; i < words; i++) {
125 flash_address[i] = source[i];
126 }
127 return (UINT)LX_SUCCESS;
128}
129
147{
148 LX_PARAMETER_NOT_USED(erase_count);
149 if (block >= (ULONG)k_lx_nor_ram_total_blocks) {
150 return (UINT)LX_ERROR;
151 }
153 for (ULONG i = 0U; i < (ULONG)k_lx_nor_ram_words_per_block; i++) {
155 }
156 return (UINT)LX_SUCCESS;
157}
158
175{
176 if (block >= (ULONG)k_lx_nor_ram_total_blocks) {
177 return (UINT)LX_ERROR;
178 }
180 for (ULONG i = 0U; i < (ULONG)k_lx_nor_ram_words_per_block; i++) {
181 if (s_ram_backing[base + i] != (ULONG)k_lx_nor_ram_erased) {
182 return (UINT)LX_ERROR;
183 }
184 }
185 return (UINT)LX_SUCCESS;
186}
187
188unsigned int lx_nor_ram_init(struct LX_NOR_FLASH_STRUCT* nor_flash)
189{
190 if (nor_flash == LX_NULL) {
191 return (UINT)LX_ERROR;
192 }
193 nor_flash->lx_nor_flash_base_address = &s_ram_backing[0];
194 nor_flash->lx_nor_flash_total_blocks = (ULONG)k_lx_nor_ram_total_blocks;
195 nor_flash->lx_nor_flash_words_per_block = (ULONG)k_lx_nor_ram_words_per_block;
196 nor_flash->lx_nor_flash_driver_read = internal_ram_read;
197 nor_flash->lx_nor_flash_driver_write = internal_ram_write;
198 nor_flash->lx_nor_flash_driver_block_erase = internal_ram_block_erase;
199 nor_flash->lx_nor_flash_driver_block_erased_verify = internal_ram_block_erased_verify;
200 nor_flash->lx_nor_flash_sector_buffer = &s_ram_sector_buf[0];
201 return (UINT)LX_SUCCESS;
202}
203
205{
206 for (ULONG i = 0U; i < (ULONG)k_lx_nor_ram_total_words; i++) {
208 }
209}
static ULONG s_ram_sector_buf[LX_NOR_SECTOR_SIZE]
LevelX per-open sector scratch (one logical sector wide).
Definition lx_nor_ram.c:60
static UINT internal_ram_block_erase(ULONG block, ULONG erase_count)
Erase one block to the LevelX erased pattern.
Definition lx_nor_ram.c:146
static UINT internal_ram_write(ULONG *flash_address, ULONG *source, ULONG words)
Write words ULONGs from source to the backing pointer.
Definition lx_nor_ram.c:116
lx_nor_ram_const_t
Geometry + sentinel constants for the RAM NOR driver.
Definition lx_nor_ram.c:39
@ k_lx_nor_ram_words_per_block
ULONG words/block.
Definition lx_nor_ram.c:41
@ k_lx_nor_ram_erased
LevelX erased word.
Definition lx_nor_ram.c:43
@ k_lx_nor_ram_total_words
Backing word count.
Definition lx_nor_ram.c:42
@ k_lx_nor_ram_total_blocks
NOR blocks.
Definition lx_nor_ram.c:40
unsigned int lx_nor_ram_init(struct LX_NOR_FLASH_STRUCT *nor_flash)
LevelX NOR driver-initialise callback over the static SRAM backing.
Definition lx_nor_ram.c:188
static UINT internal_ram_block_erased_verify(ULONG block)
Verify one block is fully erased.
Definition lx_nor_ram.c:174
static ULONG s_ram_backing[k_lx_nor_ram_total_words]
The fake NOR media (persists across open/close within one boot).
Definition lx_nor_ram.c:52
void lx_nor_ram_wipe(void)
Erase the entire SRAM backing to the LevelX "erased" pattern.
Definition lx_nor_ram.c:204
static UINT internal_ram_read(ULONG *flash_address, ULONG *destination, ULONG words)
Read words ULONGs from the backing pointer into destination.
Definition lx_nor_ram.c:82
RAM-backed standalone-LevelX NOR driver (the ra8_cache_store DIP seam).
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
static ra8_err_t internal_ram_read(void *ctx, uint32_t lba, uint32_t count, uint8_t *buf)
RAM backend: read count blocks at lba into buf.
static ra8_err_t internal_ram_write(void *context, const uint8_t *data, uint16_t length, uint16_t *written)
Append one complete transfer fragment to private RAM storage.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).