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

SDRAM block-device backend – the 64 MiB SDRAM window as a ramdisk. More...

#include "ra8_io_blockdev_sdram.h"
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_io_blockdev_ram.h"
#include "ra8_sdramc.h"
#include "ra8_sdramc_regs.h"
Include dependency graph for ra8_io_blockdev_sdram.c:

Go to the source code of this file.

Enumerations

enum  ra8_io_sdram_const_t : uint32_t { k_ra8_io_sdram_min_blocks = 1 }
 SDRAM-backend layout constants. More...

Functions

static uint32_t internal_sdram_max_blocks (void)
 Maximum block count the SDRAM window can hold.
ra8_err_t ra8_io_blockdev_sdram_init (ra8_io_blockdev_t *bd, ra8_io_blockdev_ram_state_t *state, uint32_t block_count)
 Bring up the SDRAM controller and bind it as a volatile ramdisk.

Variables

static const char *const s_tag = "ra8_io_blockdev_sdram"
 Module log tag.

Detailed Description

SDRAM block-device backend – the 64 MiB SDRAM window as a ramdisk.

Tag
[Ring 4 / PAL] {World: NS}

Once ra8_sdramc_init has brought the SDRAM controller up, the external 64 MiB window is plain memory, so this backend reuses the RAM backend's vtable and state. ra8_io_blockdev_sdram_init validates the requested block count against the window, starts the controller, and delegates the binding (and thereby every read/write/erase/caps callback) to ra8_io_blockdev_ram_init. Contents are volatile across a power cycle.

Definition in file ra8_io_blockdev_sdram.c.

Enumeration Type Documentation

◆ ra8_io_sdram_const_t

enum ra8_io_sdram_const_t : uint32_t

SDRAM-backend layout constants.

Since
0.1.0
Enumerator
k_ra8_io_sdram_min_blocks 

Smallest legal device size, in blocks.

Definition at line 40 of file ra8_io_blockdev_sdram.c.

Function Documentation

◆ internal_sdram_max_blocks()

uint32_t internal_sdram_max_blocks ( void )
static

Maximum block count the SDRAM window can hold.

The 64 MiB window divided by the 512-byte logical block size, computed once so ra8_io_blockdev_sdram_init expresses no magic ratio inline.

Returns
uint32_t Number of 512-byte logical blocks the window spans.
Return values
131072The 64 MiB window divided by 512 bytes.
Precondition
k_ra8_sdram_size_bytes is a multiple of k_ra8_io_block_size_bytes.
The result fits in uint32_t (64 MiB / 512 == 131072).
Postcondition
No state is mutated.
The return reflects only the window/block-size ratio.
Note
Thread-safe (pure constant computation).
Since
0.1.0

Definition at line 64 of file ra8_io_blockdev_sdram.c.

References k_ra8_io_block_size_bytes, k_ra8_sdram_size_bytes, and RA8_INTERNAL.

Referenced by ra8_io_blockdev_sdram_init().

◆ ra8_io_blockdev_sdram_init()

ra8_err_t ra8_io_blockdev_sdram_init ( ra8_io_blockdev_t * bd,
ra8_io_blockdev_ram_state_t * state,
uint32_t block_count )
nodiscard

Bring up the SDRAM controller and bind it as a volatile ramdisk.

Validates block_count against the 64 MiB SDRAM window, initialises the SDRAM controller via ra8_sdramc_init, then delegates to ra8_io_blockdev_ram_init using the SDRAM base address as the backing buffer (writable, never read-only). The reused ra8_io_blockdev_ram_state_t is caller-owned and must out-live every call made through the device.

Parameters
[out]bdHandle to bind (zero-initialised by the caller).
[out]stateCaller-owned RAM-backend state to populate.
[in]block_countNumber of 512-byte logical blocks (>= 1, <= window).
Returns
ra8_err_t Error code.
Return values
k_ra8_okController up and backend bound; bd is usable.
k_ra8_err_null_ptrbd or state was NULL.
k_ra8_err_invalid_sizeblock_count was zero or exceeds the window.
Precondition
bd and state out-live every call made through the device.
The SDRAM pins/clocks are configured for ra8_sdramc_init to succeed.
Postcondition
On success bd dispatches to the RAM backend over the SDRAM window.
On any non-ok return bd and state are left unbound/untouched.
Note
Not thread-safe with respect to the same device.
Since
0.1.0

Definition at line 69 of file ra8_io_blockdev_sdram.c.

References internal_sdram_max_blocks(), k_ra8_err_invalid_size, k_ra8_io_sdram_min_blocks, k_ra8_sdram_base_addr, RA8_CHECK_NULL_PTR, ra8_io_blockdev_ram_init(), RA8_RETURN_ON_ERROR, ra8_sdramc_init(), and s_tag.

Referenced by demo_run(), and internal_demo_run().

Variable Documentation

◆ s_tag

const char* const s_tag = "ra8_io_blockdev_sdram"
static

Module log tag.

Definition at line 32 of file ra8_io_blockdev_sdram.c.