|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
MRAM IRQ enables + dispatcher and FSP r_mram parity surface – DANGEROUS. More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_flash.h"#include "ra8_flash_internal.h"#include "ra8_flash_regs.h"#include "ra8_log.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_flash_blank_const_t : uint8_t { k_ra8_flash_blank_byte = 0xFFU } |
| Erase-pattern constants used by ra8_flash_blank_check. More... | |
Functions | |
| static void | internal_irq_rmw8 (uint16_t off, uint8_t bit, bool enable) |
| Read-modify-write a single bit in an 8-bit register. | |
| static void | internal_apply_ecc_irq (uint16_t off, bool is_ted, bool enable) |
| Apply enable/disable to an MRCRAEINT-style ECC IRQ. | |
| static void | internal_apply_extra_err_irq (bool err_kind, bool enable) |
| Apply enable/disable to an MPAEINT bit. | |
| ra8_err_t | ra8_flash_set_irq_enable (ra8_flash_irq_src_t src, bool enable) |
| Enable or disable MRAM-controller IRQs by source. | |
| ra8_err_t | ra8_flash_callback_set (ra8_flash_callback_t cb, void *user_ctx) |
| Register the unified IRQ callback. | |
| static void | internal_deliver (ra8_flash_irq_src_t src, uint32_t fault_addr, uint32_t status_word) |
| Deliver one IRQ event to the registered callback. | |
| static uint32_t | internal_dispatch_ecc (uint16_t status_off, uint16_t ted_addr_off, uint16_t dec_addr_off, ra8_flash_irq_src_t ted_src, ra8_flash_irq_src_t dec_src) |
| Dispatch ECC TED/DEC events for one of the two MRAM regions. | |
| uint32_t | ra8_flash_dispatch_isr (void) |
| Run the MRAM IRQ dispatcher (call from the BSP vector). | |
| ra8_err_t | ra8_flash_open (const ra8_flash_cfg_t *cfg) |
| FSP-parity bring-up: equivalent to ra8_flash_init. | |
| ra8_err_t | ra8_flash_close (void) |
| FSP-parity tear-down: equivalent to ra8_flash_deinit. | |
| ra8_err_t | ra8_flash_set_window (uintptr_t low, uintptr_t high) |
| Configure the soft access window enforced by write/erase. | |
| static ra8_err_t | internal_validate_range (uintptr_t address, uint64_t total_len) |
| Validate a multi-block erase / multi-page write range. | |
| ra8_err_t | ra8_flash_erase (uintptr_t address, uint32_t num_blocks) |
| Erase num_blocks consecutive 32-byte MRAM blocks. | |
| ra8_err_t | ra8_flash_write (uintptr_t address, const uint8_t *src, uint32_t len) |
| Program len bytes into code-MRAM starting at address. | |
| ra8_err_t | ra8_flash_blank_check (uintptr_t address, uint32_t len, bool *out_blank) |
| Check whether a region holds the erase pattern (all 0xFF). | |
| ra8_err_t | ra8_flash_status (ra8_flash_status_t *out) |
| Decode the controller status into a flat ra8_flash_status_t. | |
MRAM IRQ enables + dispatcher and FSP r_mram parity surface – DANGEROUS.
Interrupt-handling and FSP-parity aspect of the ra8_flash driver, split out of ra8_flash.c so every translation unit stays under the file-size cap. Implements the slice of the HUM Ch 59 surface declared in ra8_flash.h:
Cross-TU shared runtime state and the promoted window_allows helper live in ra8_flash_internal.h. Every register access carries a HUM Ch 59 citation.
Definition in file ra8_flash_irq.c.
| enum ra8_flash_blank_const_t : uint8_t |
Erase-pattern constants used by ra8_flash_blank_check.
| Enumerator | |
|---|---|
| k_ra8_flash_blank_byte | Erased state byte value (HUM Ch 59 p 3548). |
Definition at line 461 of file ra8_flash_irq.c.
|
static |
Apply enable/disable to an MRCRAEINT-style ECC IRQ.
HUM Ch 59 "MRCRAEINT" p 3554 / "MRERAINT" p 3557. The two registers share TED/DEC bit positions, so the helper just picks which register byte and which bit to flip.
| [in] | off | MRCRAEINT or MRERAINT offset. |
| [in] | is_ted | true for the TED bit, false for DEC. |
| [in] | enable | true to set the bit. |
Definition at line 97 of file ra8_flash_irq.c.
References internal_irq_rmw8(), k_ra8_mrcraeint_mask_intenbdc, k_ra8_mrcraeint_mask_intenbtc, and RA8_INTERNAL.
Referenced by ra8_flash_set_irq_enable().
|
static |
Apply enable/disable to an MPAEINT bit.
HUM Ch 59 "MPAEINT" p 3577. Selects between the access-error and command-lock bits.
| [in] | err_kind | true for MREAEIE, false for CMDLKIE. |
| [in] | enable | true to set the bit. |
Definition at line 125 of file ra8_flash_irq.c.
References internal_irq_rmw8(), k_ra8_mpaeint_mask_cmdlkie, k_ra8_mpaeint_mask_mreaeie, k_ra8_mram_off_mpaeint, and RA8_INTERNAL.
Referenced by ra8_flash_set_irq_enable().
|
static |
Deliver one IRQ event to the registered callback.
| [in] | src | Source identifier. |
| [in] | fault_addr | Captured address (0 if N/A). |
| [in] | status_word | Source register snapshot. |
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
Definition at line 207 of file ra8_flash_irq.c.
References g_flash_rt.
Referenced by internal_dispatch_ecc(), and ra8_flash_dispatch_isr().
|
static |
Dispatch ECC TED/DEC events for one of the two MRAM regions.
HUM Ch 59 "MRCRAES" p 3554 (code MRAM) and "MRERAES" p 3557 (extra MRAM). The two registers share the same bit layout; status_off picks which one we observe and W1C-clear, and ted_addr_off / dec_addr_off give the matching error-address registers.
| [in] | status_off | MRCRAES / MRERAES offset. |
| [in] | ted_addr_off | MRCRTEA / MRERTEA offset. |
| [in] | dec_addr_off | MRCRDEA / MRERDEA offset. |
| [in] | ted_src | IRQ source enum for the TED event. |
| [in] | dec_src | IRQ source enum for the DEC event. |
| k_ra8_ok | Success path. |
| k_ra8_err_invalid_arg | Caller violated a precondition. |
Definition at line 249 of file ra8_flash_irq.c.
References internal_deliver(), k_ra8_mrcraes_mask_decerrc, k_ra8_mrcraes_mask_tederrc, RA8_INTERNAL, ra8_mram_reg32(), and ra8_mram_reg8().
Referenced by ra8_flash_dispatch_isr().
|
static |
Read-modify-write a single bit in an 8-bit register.
Helper used by ra8_flash_set_irq_enable to set or clear a single IRQ-enable bit without disturbing the rest of the byte.
| [in] | off | MRAM register offset. |
| [in] | bit | Mask of the bit to drive. |
| [in] | enable | true to set, false to clear. |
Definition at line 65 of file ra8_flash_irq.c.
References RA8_INTERNAL, and ra8_mram_reg8().
Referenced by internal_apply_ecc_irq(), and internal_apply_extra_err_irq().
|
static |
Validate a multi-block erase / multi-page write range.
Folds the alignment + bounds + soft-window checks shared by ra8_flash_erase and ra8_flash_write. Both APIs operate on the 32-byte programming unit (HUM Ch 59.4.2 p 3548).
| [in] | address | Range start address. |
| [in] | total_len | Total number of bytes covered by the operation. |
| k_ra8_ok | Success path. |
| k_ra8_err_invalid_arg | Caller violated a precondition. |
Definition at line 382 of file ra8_flash_irq.c.
References k_ra8_err_invalid_arg, k_ra8_err_out_of_range, k_ra8_flash_code_size, k_ra8_flash_code_start, k_ra8_mram_block_size_bytes, k_ra8_ok, priv_ra8_flash_internal_window_allows(), and RA8_INTERNAL.
Referenced by ra8_flash_erase(), and ra8_flash_write().
|
nodiscard |
Check whether a region holds the erase pattern (all 0xFF).
FSP's R_MRAM_BlankCheck is a stub (returns FSP_ERR_UNSUPPORTED on RA8D2 – see r_mram.c line 395). The HUM Ch 59 layout uses 0xFF as the natural erased state, so this driver implements the check as a direct read of the region in 16-byte chunks. *out_blank is true iff every byte in [address, address + len) equals 0xFF.
| [in] | address | Start address inside code-MRAM, extra-MRAM, or OFS. |
| [in] | len | Length in bytes; must be > 0 and inside one window. |
| [out] | out_blank | Non-NULL destination for the result. |
| k_ra8_ok | Check completed; *out_blank set. |
| k_ra8_err_null_ptr | out_blank was NULL. |
| k_ra8_err_invalid_arg | len is 0 or range outside MRAM windows. |
Definition at line 465 of file ra8_flash_irq.c.
References g_flash_tag, k_ra8_err_invalid_arg, k_ra8_flash_blank_byte, k_ra8_flash_code_size, k_ra8_flash_code_start, k_ra8_flash_extra_size, k_ra8_flash_extra_start, k_ra8_flash_ofs_size, k_ra8_flash_ofs_start, k_ra8_ok, and RA8_CHECK_NULL_PTR.
|
nodiscard |
Register the unified IRQ callback.
The dispatcher (ra8_flash_dispatch_isr) walks every documented status register and calls this callback once per pending source. Pass NULL to deregister.
| [in] | cb | Callback function or NULL. |
| [in] | user_ctx | Opaque pointer passed back via ev->user_ctx. |
| k_ra8_ok | Always. |
Definition at line 181 of file ra8_flash_irq.c.
References g_flash_rt, and k_ra8_ok.
|
nodiscard |
FSP-parity tear-down: equivalent to ra8_flash_deinit.
Mirrors R_MRAM_Close (FSP r_mram.c line 646). Locks all program gates, exits P/E mode, clears sticky errors, re-enables prefetch.
| k_ra8_ok | Always. |
Definition at line 336 of file ra8_flash_irq.c.
References ra8_flash_deinit().
| uint32_t ra8_flash_dispatch_isr | ( | void | ) |
Run the MRAM IRQ dispatcher (call from the BSP vector).
Walks MRCRAES (code-ECC), MRERAES (extra-ECC), MRCPS (program-err), MASTAT (extra-err / cmdlk), MSTATR (extra-ready); for each pending bit, builds a ra8_flash_isr_event_t and calls the registered callback. After the callback returns, the dispatcher clears the matching status flag (W1C bits) so the next call sees only fresh events.
| k_ra8_ok | Success path. |
| k_ra8_err_invalid_arg | Caller violated a precondition. |
Definition at line 273 of file ra8_flash_irq.c.
References internal_deliver(), internal_dispatch_ecc(), k_ra8_flash_irq_code_ecc_dec, k_ra8_flash_irq_code_ecc_ted, k_ra8_flash_irq_extra_cmdlk, k_ra8_flash_irq_extra_ecc_dec, k_ra8_flash_irq_extra_ecc_ted, k_ra8_flash_irq_extra_err, k_ra8_flash_irq_extra_ready, k_ra8_flash_irq_program_err, k_ra8_mastat_mask_cmdlk, k_ra8_mastat_mask_mreae, k_ra8_mram_off_mastat, k_ra8_mram_off_mrcpea, k_ra8_mram_off_mrcps, k_ra8_mram_off_mrcraes, k_ra8_mram_off_mrcrdea, k_ra8_mram_off_mrcrtea, k_ra8_mram_off_mreraes, k_ra8_mram_off_mrerdea, k_ra8_mram_off_mrertea, k_ra8_mram_off_mstatr, k_ra8_mrcps_mask_errors, k_ra8_mstatr_mask_mrdy, ra8_mram_reg32(), and ra8_mram_reg8().
|
nodiscard |
Erase num_blocks consecutive 32-byte MRAM blocks.
Mirrors R_MRAM_Erase (FSP r_mram.c line 365). Loops over ra8_flash_erase_block once per block. The world (NS / S) is inferred from the destination address: addresses inside the secure code-MRAM alias use MRCPC1, all others use MRCPC0.
| [in] | address | 32-byte aligned destination inside code-MRAM. |
| [in] | num_blocks | Number of consecutive 32-byte blocks to erase. Must be > 0 and inside the code-MRAM window. |
| k_ra8_ok | All blocks erased. |
| k_ra8_err_invalid_arg | Address misaligned, num_blocks is 0, or the range exceeds the code-MRAM window. |
| k_ra8_err_out_of_range | Address blocked by the soft access window set via ra8_flash_set_window. |
| k_ra8_err_hw_error | Controller reported a program error. |
| k_ra8_err_hw_timeout | Controller never observed OPDONE. |
Definition at line 400 of file ra8_flash_irq.c.
References g_flash_rt, g_flash_tag, internal_validate_range(), k_ra8_err_invalid_arg, k_ra8_flash_world_ns, k_ra8_mram_block_size_bytes, k_ra8_ok, ra8_flash_erase_block(), RA8_RETURN_ON_ERROR, and RA8_VALIDATE_INIT.
|
nodiscard |
FSP-parity bring-up: equivalent to ra8_flash_init.
Mirrors R_MRAM_Open (FSP r_mram.c line 253). Registers the controller for use, programs MRCFREQ / MREFREQ, and locks both program-control gates. After ra8_flash_open callers may invoke ra8_flash_write / ra8_flash_erase / ra8_flash_blank_check / ra8_flash_status / ra8_flash_set_window.
| [in] | cfg | Non-NULL configuration descriptor. |
| k_ra8_ok | Controller opened. |
| k_ra8_err_null_ptr | cfg was NULL. |
| k_ra8_err_invalid_arg | cfg field out of range. |
Definition at line 329 of file ra8_flash_irq.c.
References ra8_flash_init().
Referenced by ra8_dfu_program_prepare().
|
nodiscard |
Enable or disable MRAM-controller IRQs by source.
Routes per-source enable bits to the matching register:
| [in] | src | Source to gate. |
| [in] | enable | true => enable, false => disable. |
| k_ra8_ok | Enable bit applied. |
| k_ra8_err_invalid_arg | src out of range. |
Definition at line 134 of file ra8_flash_irq.c.
References internal_apply_ecc_irq(), internal_apply_extra_err_irq(), k_ra8_err_invalid_arg, k_ra8_flash_irq_code_ecc_dec, k_ra8_flash_irq_code_ecc_ted, k_ra8_flash_irq_count, k_ra8_flash_irq_extra_cmdlk, k_ra8_flash_irq_extra_ecc_dec, k_ra8_flash_irq_extra_ecc_ted, k_ra8_flash_irq_extra_err, k_ra8_flash_irq_extra_ready, k_ra8_flash_irq_program_err, k_ra8_mram_off_mrcpaeint, k_ra8_mram_off_mrcraeint, k_ra8_mram_off_mrdyie, k_ra8_mram_off_mreraint, k_ra8_mrcpaeint_mask_mrcaeie, k_ra8_mrdyie_mask_mrdyie, k_ra8_ok, and ra8_mram_reg8().
|
nodiscard |
Configure the soft access window enforced by write/erase.
FSP's R_MRAM_AccessWindowSet is a stub on RA8D2 (returns FSP_ERR_UNSUPPORTED – see r_mram.c line 469); the silicon has no FAWMON / FAWMR registers because MRAM uses block-protect bits in the MRCBPROT0 / MRCBPROT1 registers instead. To preserve a useful FSP-style surface, this driver maintains a software window: ra8_flash_write, ra8_flash_erase and ra8_flash_write_block reject any request that touches an address outside [low, high). Pass low == high == 0 to disable the window (allow all addresses, the default after open).
| [in] | low | Inclusive lower bound (or 0 to disable). |
| [in] | high | Exclusive upper bound (or 0 to disable). |
| k_ra8_ok | Window applied. |
| k_ra8_err_invalid_arg | low >= high and not both zero. |
Definition at line 343 of file ra8_flash_irq.c.
References g_flash_rt, k_ra8_err_invalid_arg, and k_ra8_ok.
Referenced by ra8_dfu_program_prepare().
|
nodiscard |
Decode the controller status into a flat ra8_flash_status_t.
Reads MRCPS / MASTAT / MENTRYR / MSTATR / MRCBPROT0 / MRCBPROT1 and collapses the bits down to the FSP-parity ra8_flash_status_t boolean fields. HUM Ch 59 p 3577..3605.
| [out] | out | Non-NULL destination structure. |
| k_ra8_ok | Status decoded. |
| k_ra8_err_null_ptr | out was NULL. |
Definition at line 504 of file ra8_flash_irq.c.
References ra8_flash_status_t::ecc_error, ra8_flash_status_t::erase_busy, g_flash_tag, ra8_flash_status_t::illegal_command, k_ra8_mastat_mask_cmdlk, k_ra8_mentryr_mask_pe_mode, k_ra8_mram_off_mastat, k_ra8_mram_off_mentryr, k_ra8_mram_off_mrcbprot0, k_ra8_mram_off_mrcbprot1, k_ra8_mram_off_mrcps, k_ra8_mram_off_mstatr, k_ra8_mrcps_mask_eccerrc, k_ra8_mrcps_mask_prgbsyc, k_ra8_mrcps_mask_prgerrc, k_ra8_mstatr_mask_ilgcomerr, k_ra8_mstatr_mask_oterr, k_ra8_ok, ra8_flash_status_t::program_error, ra8_flash_status_t::programming_busy, RA8_CHECK_NULL_PTR, ra8_mram_reg16(), ra8_mram_reg32(), ra8_mram_reg8(), ra8_flash_status_t::sector_protected, and ra8_flash_status_t::voltage_error.
|
nodiscard |
Program len bytes into code-MRAM starting at address.
Mirrors R_MRAM_Write (FSP r_mram.c line 323 + mram_write_data line 861). The driver chunks the request into per-page writes of up to 32 bytes (k_ra8_mram_write_size_bytes), each one going through ra8_flash_write_block. len must be a non-zero multiple of the 32-byte page size; arbitrary lengths are rejected to match FSP's BSP_FEATURE_MRAM_PROGRAMMING_SIZE_BYTES boundary requirement.
| [in] | address | Destination start address (32-byte aligned, inside code-MRAM). |
| [in] | src | Non-NULL source buffer of at least len bytes. |
| [in] | len | Length in bytes; must be non-zero and a multiple of 32. |
| k_ra8_ok | All bytes written. |
| k_ra8_err_null_ptr | src was NULL. |
| k_ra8_err_invalid_arg | address misaligned, len not a multiple of 32, or range outside the code-MRAM window. |
| k_ra8_err_out_of_range | Range blocked by the soft access window. |
| k_ra8_err_hw_error | Controller reported a program error. |
| k_ra8_err_hw_timeout | Controller never observed OPDONE. |
Definition at line 430 of file ra8_flash_irq.c.
References g_flash_rt, g_flash_tag, internal_validate_range(), k_ra8_err_invalid_arg, k_ra8_flash_world_ns, k_ra8_mram_write_size_bytes, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_flash_write_block(), RA8_RETURN_ON_ERROR, and RA8_VALIDATE_INIT.