ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

ra8_io fabric over the external SDRAM backend (epic #155) on EK-RA8D2. More...

#include <stdint.h>
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_io.h"
#include "ra8_io_roundtrip.h"
#include "ra8_log.h"
#include "ra8_port_constants.h"
#include "ra8_port_utils.h"
#include "ra8_sci.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  demo_const_t : uint32_t {
  k_demo_uart_chan = 8U ,
  k_demo_uart_baud = 115200U ,
  k_demo_disk_blocks = 512U ,
  k_demo_payload = 128U ,
  k_demo_pin_shift = 8U ,
  k_demo_note_len = 64U
}
 Console + volume knobs (no magic numbers). More...

Functions

static void demo_print (const char *msg)
 Print a NUL-terminated string on the demo's UART stream.
static void demo_setup_or_halt (void)
 Bring up CGC + SysTick + the SCI8 console; halt forever on any failure.
static ra8_err_t demo_run (ra8_fs_mount_t **out_mount)
 Bind the SDRAM block device, then run the shared FAT round-trip.
void main (void)
 Firmware entry point.

Variables

static const ra8_port_pin_t k_demo_txd
 SCI8 console TXD = PD02.
static const ra8_port_pin_t k_demo_rxd
 SCI8 console RXD = PD03.
static ra8_io_blockdev_t s_bd
 Block-device handle + its SDRAM backend state (storage is the SDRAM).
static ra8_io_blockdev_ram_state_t s_bstate
static ra8_fs_backend_t s_be
 ra8_fs backend bridged onto the block device.
static ra8_io_stream_t s_uart
 UART output stream + its sink state.
static ra8_io_stream_uart_state_t s_ust
static const char *const s_tag = "ra8_io_sdram_demo"
 Module log tag.
static const ra8_io_roundtrip_params_t s_params
 Shared round-trip parameters for this SDRAM-backed FAT12 volume.

Detailed Description

ra8_io fabric over the external SDRAM backend (epic #155) on EK-RA8D2.

Tag
[Ring 6 / APP] {World: S}

The same fabric as ra8_io_demo, but the block device is backed by the 64 MiB external SDRAM (at 0x68000000) instead of an in-SRAM buffer – the swappable backend differs, the ra8_fs + VFS layers above are identical and implemented in this app's ra8_io_roundtrip.{h,c}. This app differs only by the ONE backend bind line (ra8_io_blockdev_sdram_init, which brings the controller up with ra8_sdramc_init and presents the window as 512-byte logical blocks) plus its own PASS banners.

ra8_emulator maps the SDRAM region and models the SDRAM controller bring-up, so the PASS/FAIL line is observable headlessly: a successful run prints ra8_io_sdram_demo: mkdir+nested dr:/SUB/NOTE.TXT PASS.

Definition in file main.c.

Enumeration Type Documentation

◆ demo_const_t

enum demo_const_t : uint32_t

Console + volume knobs (no magic numbers).

Enumerator
k_demo_uart_chan 

SCI8 J-Link OB console.

k_demo_uart_baud 

Console baud.

k_demo_disk_blocks 

256 KiB SDRAM window (FAT12).

k_demo_payload 

Bytes written + read back at root.

k_demo_pin_shift 

Port byte position in ra8_port_pin_t.

k_demo_note_len 

Bytes round-tripped in the subdir.

Definition at line 40 of file main.c.

Function Documentation

◆ demo_print()

void demo_print ( const char * msg)
static

Print a NUL-terminated string on the demo's UART stream.

Thin wrapper over ra8_io_stream_puts bound to s_uart, so call sites do not repeat the sink handle.

Parameters
[in]msgNUL-terminated ASCII string (CR/LF supplied by the caller).
Returns
None.
Precondition
s_uart was initialised by ra8_io_stream_uart_init.
msg is non-NULL and NUL-terminated.
Postcondition
The bytes of msg are queued on the UART stream.
No other state changes.
Note
Blocking polled TX; not interrupt-safe.
Since
0.1.0

Definition at line 100 of file main.c.

References ra8_io_stream_puts(), and s_uart.

Referenced by demo_echo_loop(), demo_file_ops(), demo_fs_format_mount(), demo_fs_format_or_panic(), demo_list_entry(), demo_log_echo(), demo_lx_format_or_panic(), demo_lx_open(), demo_lx_open_or_panic(), demo_print_stat(), demo_print_u32(), demo_print_wear_stats(), demo_read_test_file(), demo_read_verify(), demo_report(), demo_report_map(), demo_report_rw_once(), demo_report_wear(), demo_run(), demo_run_tls(), demo_thread_entry(), demo_write_test_file(), main(), and tx_application_define().

◆ demo_run()

ra8_err_t demo_run ( ra8_fs_mount_t ** out_mount)
static

Bind the SDRAM block device, then run the shared FAT round-trip.

Binds the external-SDRAM backend over a 256 KiB window (the single per-demo bind line), mounts the FAT12 volume through the shared helper, runs the root-file round-trip, and – on success – returns the mount handle through out_mount for the subdir round-trip.

Parameters
[out]out_mountReceives the mount handle on success, nullptr on error.
Returns
ra8_err_t Error code.
Return values
k_ra8_okThe SDRAM volume mounted and the root file round-tripped.
k_ra8_err_*The first failing bind / mount / round-trip step's code.
Precondition
demo_setup_or_halt has run (clocks + console up).
out_mount is non-NULL and the SDRAM pins/clocks allow bring-up.
Postcondition
On success dr:/HELLO.TXT holds the verified payload.
On any non-ok return *out_mount is nullptr.
Note
Not thread-safe; single-caller boot context.
Since
0.1.0

Definition at line 169 of file main.c.

References k_demo_disk_blocks, ra8_io_blockdev_sdram_init(), ra8_io_roundtrip_mount(), ra8_io_roundtrip_root_file(), RA8_RETURN_ON_ERROR, s_bd, s_be, s_bstate, s_params, and s_tag.

◆ demo_setup_or_halt()

void demo_setup_or_halt ( void )
static

Bring up CGC + SysTick + the SCI8 console; halt forever on any failure.

Initialises clocks, reads CPU/PCLKA rates, starts the millisecond time base, routes the SCI8 console pins, and opens the SCI8 UART. Any failure spins forever so a debugger can inspect the halt (there is no console yet to report on).

Returns
None.
Precondition
SystemInit configured VTOR / FPU / priority grouping.
Runs single-threaded during early boot.
Postcondition
On success SCI8 is open at k_demo_uart_baud and the time base runs.
On any failure the function never returns (infinite halt loop).
Note
Not thread-safe; boot-context only.
Since
0.1.0

Definition at line 123 of file main.c.

References k_demo_rxd, k_demo_txd, k_demo_uart_baud, k_demo_uart_chan, k_ra8_clock_id_cpuclk0, k_ra8_clock_id_pclka, k_ra8_ok, k_ra8_psel_sci_async, k_ra8_sci_data_8, k_ra8_sci_parity_none, k_ra8_sci_stop_1, ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_pfs_route_peripheral(), ra8_sci_init(), and ra8_time_init().

Referenced by main().

◆ main()

void main ( void )

Firmware entry point.

The application entry point Reset_Handler hands control to.

Precondition
SystemInit set VTOR / FPU / priority grouping.

Definition at line 183 of file main.c.

References demo_print(), demo_run(), demo_setup_or_halt(), k_demo_uart_chan, k_ra8_ok, ra8_io_log_attach(), ra8_io_roundtrip_subdir_file(), ra8_io_stream_uart_init(), ra8_log_init(), ra8_sci_flush(), s_params, s_uart, and s_ust.

Variable Documentation

◆ k_demo_rxd

const ra8_port_pin_t k_demo_rxd
static
Initial value:
=
(ra8_port_pin_t)(((uint16_t)k_ra8_port_13 << (uint16_t)k_demo_pin_shift) | (uint16_t)k_ra8_pin_3)
@ k_demo_pin_shift
Port byte position in ra8_port_pin_t.
Definition main.c:62
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
@ k_ra8_port_13
RA8 port 13.
@ k_ra8_pin_3
RA8 pin 3.

SCI8 console RXD = PD03.

Definition at line 53 of file main.c.

Referenced by demo_setup_or_halt().

◆ k_demo_txd

const ra8_port_pin_t k_demo_txd
static
Initial value:
=
(ra8_port_pin_t)(((uint16_t)k_ra8_port_13 << (uint16_t)k_demo_pin_shift) | (uint16_t)k_ra8_pin_2)
@ k_ra8_pin_2
RA8 pin 2.

SCI8 console TXD = PD02.

Definition at line 50 of file main.c.

Referenced by demo_setup_or_halt().

◆ s_bd

ra8_io_blockdev_t s_bd
static

Block-device handle + its SDRAM backend state (storage is the SDRAM).

Definition at line 57 of file main.c.

◆ s_be

ra8_fs_backend_t s_be
static

ra8_fs backend bridged onto the block device.

Definition at line 60 of file main.c.

◆ s_bstate

ra8_io_blockdev_ram_state_t s_bstate
static

Definition at line 58 of file main.c.

◆ s_params

const ra8_io_roundtrip_params_t s_params
static
Initial value:
= {
.vfs_prefix = "dr",
.fat_type = k_ra8_fs_type_fat12,
.volume_label = "RAIOSDRAM",
.log_tag = s_tag,
.root_file = "HELLO.TXT",
.root_path = "dr:/HELLO.TXT",
.root_bytes = (uint32_t)k_demo_payload,
.subdir_path = "dr:/SUB",
.subdir_file = "dr:/SUB/NOTE.TXT",
.subdir_bytes = (uint32_t)k_demo_note_len,
}
@ k_demo_payload
Source bytes (compressible).
Definition main.c:60
@ k_demo_note_len
Bytes round-tripped in the subdir.
Definition main.c:46
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
@ k_ra8_fs_type_fat12
count_of_clusters < 4085.

Shared round-trip parameters for this SDRAM-backed FAT12 volume.

Definition at line 69 of file main.c.

◆ s_tag

const char* const s_tag = "ra8_io_sdram_demo"
static

Module log tag.

Definition at line 66 of file main.c.

◆ s_uart

ra8_io_stream_t s_uart
static

UART output stream + its sink state.

Definition at line 62 of file main.c.

◆ s_ust

Definition at line 63 of file main.c.