|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
1 KB DTC SRAM-to-SRAM block-copy + verify demo for the EK-RA8D2 More...
#include <stdint.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_check.h"#include "ra8_dtc.h"#include "ra8_dtc_regs.h"#include "ra8_elc.h"#include "ra8_err.h"#include "ra8_icu_regs.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | dtc_demo_config_t : uint32_t { k_dtc_demo_baud = 115200U , k_dtc_demo_period_ms = 1000U , k_dtc_demo_buf_bytes = 1024U , k_dtc_demo_buf_words = 256U , k_dtc_demo_poll_limit = 200000U } |
| Compile-time settings. More... | |
| enum | dtc_demo_byte_t : uint8_t { k_dtc_demo_byte_sh = 8U , k_dtc_demo_isr_prio = 12U } |
| Single-byte constants. More... | |
| enum | dtc_demo_event_t : uint16_t { k_dtc_demo_event_swevt0 = 0x0CCU } |
| ELC software event 0 -> ICU event number. More... | |
| enum | dtc_demo_swevt_t : uint8_t { k_dtc_demo_swevt_index = 0U } |
| ELSEGRn index fired by ra8_elc_software_trigger. More... | |
| enum | dtc_mr_field_t : uint8_t { k_dtc_md_block = 0x2U , k_dtc_sz_word = 0x2U , k_dtc_sm_inc = 0x2U , k_dtc_dm_inc = 0x2U } |
| DTC Transfer-Information mode-bit field values. More... | |
| enum | dtc_mr_pos_t : uint8_t { k_dtc_mra_md_pos = 6U , k_dtc_mra_sz_pos = 4U , k_dtc_mra_sm_pos = 2U , k_dtc_mrb_dm_pos = 2U , k_dtc_mra_byte_pos = 24U , k_dtc_mrb_byte_pos = 16U } |
| Bit positions inside the DTC TI MR word. More... | |
| enum | dtc_count_t : uint16_t { k_dtc_cra_block_256 = 0x0000U , k_dtc_crb_one_block = 0x0001U } |
| DTC count-register values for one 256-word block. More... | |
| enum | dtc_vt_geom_t : uint32_t { k_dtc_vt_entries = 96U , k_dtc_vt_align = 1024U , k_dtc_ti_align = 16U } |
| DTC vector-table geometry. More... | |
| enum | dtc_cra_t : uint32_t { k_dtc_cra_block_units = 256U } |
| CRA=0x0000 encodes a full 256-unit block. More... | |
Functions | |
| static void | dtc_demo_panic_halt (void) |
| Park forever after a fatal init failure. | |
| static void | dtc_demo_complete_cb (void *ctx, uint16_t status) |
| DTC completion callback (fanned out by ra8_dtc_dispatch). | |
| static void | dtc_demo_swevt_isr (void *ctx) |
| IELSR-slot ISR for the DTC-complete interrupt. | |
| static void | dtc_demo_setup_or_halt (void) |
| Bring CGC + SysTick + ISR + ELC + SCI8 + LEDs + MSTP up. | |
| static void | dtc_demo_fill_buffers (void) |
| Fill s_src with a deterministic pattern and clear s_dst. | |
| static void | dtc_demo_program_ti (void) |
| Write the 16-byte TI block describing the block copy. | |
| static ra8_err_t | dtc_demo_arm_slot (void) |
| Re-arm DTC activation on the slot and clear any latched IR. | |
| static void | dtc_demo_bringup_or_halt (void) |
| Initialise the DTC, allocate its activation slot, and enable it. | |
| static uint8_t | dtc_demo_verify (void) |
| Verify that s_dst matches s_src element-by-element. | |
| static ra8_err_t | dtc_demo_run_once (uint8_t *out_ok) |
| Program + activate one DTC block copy and wait for completion. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| static const char * | s_tag = "dtc_demo" |
| Diagnostic / log tag. | |
| static const uint8_t | k_dtc_demo_ok_msg [] = "dtc: copied 1024B match=Y\r\n" |
| Output line tags. | |
| static const uint8_t | k_dtc_demo_bad_msg [] = "dtc: copied 1024B match=N\r\n" |
| static uint32_t | s_src [k_dtc_demo_buf_words] |
| Source / destination buffers (32-bit aligned by element type). | |
| static uint32_t | s_dst [k_dtc_demo_buf_words] |
| static uint32_t | s_dtc_vt [k_dtc_vt_entries] |
| DTC vector table – one 4-byte TI start address per IELSR slot. | |
| static r_dtc_xfer_info_t | s_dtc_ti |
| The 16-byte Transfer Information block the DTC reads each pass. | |
| static uint16_t | s_dtc_slot |
| IELSR slot allocated for the DTC activation = DTC vector number. | |
| volatile uint32_t | g_dtc_match = 0U |
| 1 when the destination matched the source after the last pass. | |
| volatile uint32_t | g_dtc_bytes = 0U |
| Bytes the DTC moved on the last successful pass (0 on failure). | |
| volatile uint32_t | g_dtc_activations = 0U |
| volatile uint32_t | g_dtc_isr_count = 0U |
| volatile uint32_t | g_dtc_heartbeat = 0U |
1 KB DTC SRAM-to-SRAM block-copy + verify demo for the EK-RA8D2
The Data Transfer Controller (DTC) is the CPU-transparent, descriptor-table transfer engine that sits next to the DMAC. Unlike the DMAC it has no software-start register (HUM Ch 18.3 p 796: "The DTC is activated by an interrupt request"); every transfer is kicked by a peripheral interrupt whose ICU.IELSRn slot has the DTCE bit set. This demo drives that activation deterministically with an ELC software event so no external stimulus is needed.
Bring-up: CGC + SysTick + SCI8 + LEDs + the ISR/ELC/DTC blocks. Once a second the loop:
LED1 toggles on every successful copy; LED2 latches if the destination ever differs from the source. The g_dtc_* globals mirror the result for headless probing (HIL / board emulator).
Bare EK-RA8D2 only – no shields or external transceivers.
Definition in file main.c.
| enum dtc_count_t : uint16_t |
DTC count-register values for one 256-word block.
HUM Ch 18.2.7 "CRA" (p 790): in block mode CRAH/CRAL hold the block size and "the transfer count is ... 256 when the set value is 0x00". HUM Ch 18.2.8 "CRB" (p 791): CRB is the block count.
| Enumerator | |
|---|---|
| k_dtc_cra_block_256 | CRAH = CRAL = 0 => 256-unit block. |
| k_dtc_crb_one_block | CRB = 1 => one block per pass. |
| enum dtc_cra_t : uint32_t |
| enum dtc_demo_byte_t : uint8_t |
| enum dtc_demo_config_t : uint32_t |
| enum dtc_demo_event_t : uint16_t |
ELC software event 0 -> ICU event number.
HUM Table 19.3 (p 824) row "0x0CC | ELC | ELC_SWEVT0 | Software event 0": ra8_elc_software_trigger(0) writes ELSEGR0.SEG which raises this event; routed to an IELSR slot with DTCE = 1 it activates the DTC. App-local (the shared ra8_elc_event_t table only carries events the HAL itself wires), mirroring uart_irq_echo.
| Enumerator | |
|---|---|
| k_dtc_demo_event_swevt0 | ELC software event 0 (HUM Table 19.3). |
| enum dtc_demo_swevt_t : uint8_t |
ELSEGRn index fired by ra8_elc_software_trigger.
| Enumerator | |
|---|---|
| k_dtc_demo_swevt_index | ELSEGR0 -> ELC_SWEVT0 (0x0CC). |
| enum dtc_mr_field_t : uint8_t |
DTC Transfer-Information mode-bit field values.
HUM Ch 18.2.2 "MRA" (p 786) and 18.2.3 "MRB" (p 787): a block-mode, 32-bit-word, increment-both copy. 2 selects "increment" for SM/DM, "32-bit word" for SZ, and "block transfer" for MD.
| enum dtc_mr_pos_t : uint8_t |
Bit positions inside the DTC TI MR word.
HUM Figure 18.4 (p 799) lays the first TI long-word out as MR[31:24] = MRA, MR[23:16] = MRB, MR[15:8] = MRC, MR[7:0] = reserved.
| enum dtc_vt_geom_t : uint32_t |
DTC vector-table geometry.
HUM Ch 18.3.1 (p 796) + Figure 18.3 (p 798): DTCVBR points at a table of 4-byte entries, one per interrupt vector number; entry n (at DTCVBR + n*4) holds the 16-byte-aligned start address of that source's TI. DTCVBR itself must be 1 KB-aligned (HUM Ch 18.2.11 p 792 "the lower 10 bits should be 0").
| Enumerator | |
|---|---|
| k_dtc_vt_entries | One pointer per IELSR slot 0..95. |
| k_dtc_vt_align | DTCVBR 1 KB alignment (HUM 18.2.11). |
| k_dtc_ti_align | TI start address multiple of 16. |
|
staticnodiscard |
Re-arm DTC activation on the slot and clear any latched IR.
The DTC clears ICU.IELSRn.DTCE to 0 and sets the RW1C IR flag when the block completes (HUM Figure 18.5 p 801), so both are refreshed before each activation. The read-modify-write preserves the IELS field and write-1-clears a pending IR.
Definition at line 383 of file main.c.
References k_ra8_err_hw_error, k_ra8_ielsr_dtce_mask, k_ra8_ok, ra8_icu_ielsr(), and s_dtc_slot.
Referenced by dtc_demo_run_once().
|
static |
Initialise the DTC, allocate its activation slot, and enable it.
Programs DTCVBR to s_dtc_vt, attaches the completion callback, allocates an IELSR slot for ELC software event 0 (whose index is the DTC vector number), points that slot's vector-table entry at the TI block, and starts the engine (DTCST = 1). Halts on any failure.
Definition at line 409 of file main.c.
References dtc_demo_complete_cb(), dtc_demo_panic_halt(), dtc_demo_swevt_isr(), k_dtc_demo_event_swevt0, k_dtc_demo_isr_prio, k_dtc_vt_entries, k_ra8_ok, ra8_dtc_attach_handler(), ra8_dtc_enable(), ra8_dtc_init(), ra8_isr_register(), s_dtc_slot, s_dtc_ti, and s_dtc_vt.
Referenced by main().
|
static |
DTC completion callback (fanned out by ra8_dtc_dispatch).
| [in] | ctx | Unused registration context. |
| [in] | status | DTCSTS snapshot at completion. |
Definition at line 257 of file main.c.
References g_dtc_isr_count.
Referenced by dtc_demo_bringup_or_halt().
|
static |
Fill s_src with a deterministic pattern and clear s_dst.
Definition at line 329 of file main.c.
References k_dtc_demo_buf_words, k_dtc_demo_byte_sh, s_dst, and s_src.
Referenced by main().
|
static |
Park forever after a fatal init failure.
Definition at line 240 of file main.c.
Referenced by dtc_demo_bringup_or_halt(), dtc_demo_setup_or_halt(), and main().
|
static |
Write the 16-byte TI block describing the block copy.
Rebuilt every pass because the DTC writes the post-transfer TI back to SRAM (MRA.WBDIS = 0, HUM Ch 18.2.2 p 786), consuming SAR/DAR/CRA/CRB. Field encoding per HUM Figure 18.4 (p 799): MR holds MRA/MRB/MRC, then SAR, DAR, CRB, CRA.
Definition at line 353 of file main.c.
References k_dtc_cra_block_256, k_dtc_crb_one_block, k_dtc_dm_inc, k_dtc_md_block, k_dtc_mra_byte_pos, k_dtc_mra_md_pos, k_dtc_mra_sm_pos, k_dtc_mra_sz_pos, k_dtc_mrb_byte_pos, k_dtc_mrb_dm_pos, k_dtc_sm_inc, k_dtc_sz_word, s_dst, s_dtc_ti, and s_src.
Referenced by dtc_demo_run_once().
|
staticnodiscard |
Program + activate one DTC block copy and wait for completion.
Rebuilds the TI, re-arms the slot, fires ELC software event 0, then polls the last destination word until it lands (bounded). The DTC writes s_dst in ascending order, so the final word settling is the completion gate. If the engine never runs (e.g. the headless emulator shadows the DTC window without transferring), the poll times out and the verify reports a mismatch.
| [out] | out_ok | 1 if the destination matched the source, else 0. |
| k_ra8_err_null_ptr | out_ok was NULL. |
Definition at line 479 of file main.c.
References dtc_demo_arm_slot(), dtc_demo_program_ti(), dtc_demo_verify(), g_dtc_activations, k_dtc_demo_buf_words, k_dtc_demo_poll_limit, k_dtc_demo_swevt_index, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_elc_software_trigger(), s_dst, s_src, and s_tag.
Referenced by main().
|
static |
Bring CGC + SysTick + ISR + ELC + SCI8 + LEDs + MSTP up.
Definition at line 285 of file main.c.
References dtc_demo_panic_halt(), k_dtc_demo_baud, k_ra8_board_led1, k_ra8_board_led2, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_led_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_elc_init(), ra8_isr_init(), ra8_mstp_init(), and ra8_time_init().
Referenced by main().
|
static |
IELSR-slot ISR for the DTC-complete interrupt.
When the single block finishes, the DTC clears ICU.IELSRn.DTCE and raises the slot's CPU interrupt (HUM Figure 18.5 p 801). This routes the event through the HAL dispatch into dtc_demo_complete_cb.
| [in] | ctx | Unused registration context. |
Definition at line 278 of file main.c.
References ra8_dtc_dispatch().
Referenced by dtc_demo_bringup_or_halt().
|
static |
Verify that s_dst matches s_src element-by-element.
Definition at line 449 of file main.c.
References k_dtc_demo_buf_words, s_dst, and s_src.
Referenced by dtc_demo_run_once().
| void main | ( | void | ) |
The application entry point Reset_Handler hands control to.
Returns void, not int. This is a freestanding image: there is no hosted C environment, no process and nothing to report an exit status to. ISO C fixes main at int only for a hosted implementation; for a freestanding one (C23 5.1.2.1) the startup function's name and type are implementation-defined, and this is that definition. Reset_Handler discards no value because there is none to discard, and if main ever does return, startup halts the CPU rather than resuming anything.
The firmware lane is compiled -ffreestanding (see cmake/ra8_add_app.cmake) and the flag and this signature travel together: without it both GCC and clang reject a non-int main (-Wmain / -Wmain-return-type). Do not remove one without the other.
That coupling is why the declaration sits behind __STDC_HOSTED__ == 0, which -ffreestanding sets and a hosted build does not. The guard is not defensive dressing: this header is reachable from host builds (the unit tests compile ra8_core natively), and an unguarded void main(void); makes every hosted translation unit that includes it fail with conflicting types for 'main' against its own ISO int main. The declaration therefore exists exactly where its contract does.
Hosted first-party code – everything under tests/ and tools/ – uses the ISO int main(...) contract instead, because it genuinely does run under an OS that reads the exit status. scripts/checks/check_entry_points.py holds each domain to its own contract (#707).
Declared here, once, for the same reason SystemInit is: every vector_table.c used to restate it as a local extern int32_t main(void);, sixteen copies that no compiler ever compared against the definition – and roughly thirty of them had silently drifted out of agreement with the main they called.
The application entry point Reset_Handler hands control to.
Brings up CGC + BSP audio then plays blocks.
The application entry point Reset_Handler hands control to.
Brings up CGC + GPT triple, runs sweep.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART, then enters ThreadX.
The application entry point Reset_Handler hands control to.
Brings up LED, console, SDHI pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up CGC + USB-FS + UAC1, then enters the iso-IN feed loop forever.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
See file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Profiles power modes once a second.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, SPI, and SD card, then runs the shared ra8_io VFS round-trip over the SD-over-SPI block device. On success it prints the exact PASS banner the HIL runner and ra8_emulator smoke gate scrape for; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
Initialises logging and the console, brings up the OSPI NOR volume, runs the erase-before-write round-trip, and prints a single PASS/FAIL verdict line over SCI8 before parking in an infinite loop.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Both USB controllers' clocks and pins come up before the kernel so the workers only deal with stack bring-up.
The application entry point Reset_Handler hands control to.
Brings up logging and the clock tree, releases the Cortex-M33 (which then blinks LED1 via ra8_pcntr_set_output()), and idles. See the file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the cacheable-SRAM round-trip with the D-cache that SystemInit() enabled through ra8_cache_dcache_enable(), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI. Every byte the self-test touches runs with the L1 caches + MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU + RA8_BOOT_CACHE_VIA_HAL).
The application entry point Reset_Handler hands control to.
Publishes the mailbox, releases the Cortex-M33 into the emitter, yields until it signals done, validates the blob the M33 built, then logs the PASS/FAIL verdict and the chapter count read back from the blob. See the file header for the offload narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Publishes the mailbox, arms the IPC0 wake and configures the LPM block, releases the Cortex-M33 into the reader, waits for the first held page, logs the page-0 verdict, then runs the #150 mode-switch cycle – parking in low-power WFI and waking on the M33's page-turn pokes – before logging the handoff verdict and parking for good. See the file header for the narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the timebase then measures forever.
The application entry point Reset_Handler hands control to.
Arms the RIIC1 target and polls the dispatcher.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the LIN commander then drives frames.
The application entry point Reset_Handler hands control to.
Brings up logging, "renders" page 0 into the shared mailbox, releases the Cortex-M33 into its hold loop, and parks the M85 in low-power WFI sleep. See the file header for the power-saving narrative.
The application entry point Reset_Handler hands control to.
The USB clock, pins, console, and the SD card all come up before the kernel so the worker only deals with USB stack bring-up.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the three-step self-test (MPU enabled, canonical boot map, Device MMIO), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Initialises logging + console, brings up the MRAM volume, runs the wear-levelling + power-cycle-survival flow, and prints a single PASS/FAIL verdict.
The application entry point Reset_Handler hands control to.
Initialises logging + console, brings up the MRAM volume, runs the program/erase round-trip, and prints a single PASS/FAIL verdict.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, and SDHI bus pins, runs the native SD card identification, fills the payload, then runs the full ra8_io VFS round-trip over the native-SDHI block device. On success it prints the exact PASS banner the HIL runner and ra8_emulator smoke gate scrape for; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
Brings up the console and both stdio sinks, retargets the engine's stdio to the in-RAM capture sink, runs the two-backend swap, replays the RAM capture out of the UART, and prints a single PASS/FAIL verdict per abstraction before parking in an infinite loop.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, and SDHI bus pins, runs the native SD card identification, fills the payload, then writes + reads + compares one raw 512-byte block straight against ra8_sdcard. On success it prints the exact PASS banner; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII + RSIP, then ThreadX.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Initializes and arms ADC_B, formats each successful channel sample without variadic I/O, emits the verdict, toggles LED1, and delays.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, releases the Cortex-M33 (which then blinks LED1), and idles. See the file header for the teaching narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
See the file header for the full behaviour summary.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the three-step self-test (cacheable SRAM, RO MRAM const, Device MMIO), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI. Every byte the self-test touches runs with the L1 caches and MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU).
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Lights HOCO + PLL, then runs a 1 Hz blink.
The application entry point Reset_Handler hands control to.
See file header for behaviour summary.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Initializes the demo, executes one comparison per period, increments the exported match or mismatch counter, and toggles the matching LED.
The application entry point Reset_Handler hands control to.
Brings up the clock tree, MSTP, ISR/ELC, and the VCOM console, programs a software-triggered DTC block copy, runs it with the L1 caches + MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI.
Definition at line 504 of file main.c.
References dtc_demo_bringup_or_halt(), dtc_demo_fill_buffers(), dtc_demo_panic_halt(), dtc_demo_run_once(), dtc_demo_setup_or_halt(), g_dtc_bytes, g_dtc_heartbeat, g_dtc_match, k_dtc_demo_bad_msg, k_dtc_demo_buf_bytes, k_dtc_demo_ok_msg, k_dtc_demo_period_ms, k_ra8_board_led1, k_ra8_board_led2, k_ra8_ok, ra8_board_led_toggle(), ra8_board_uart_console_write(), and ra8_delay_ms().
| volatile uint32_t g_dtc_bytes = 0U |
| volatile uint32_t g_dtc_match = 0U |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |