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

Contracts for file-local SD block-I/O helpers. More...

Include dependency graph for ra8_sdmmc_spi_io_contracts_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static ra8_err_t internal_prepare_init (const ra8_sdmmc_spi_transport_t *transport)
 Validate and stage the transport for initialization.
static ra8_err_t internal_finalize_init (void)
 Switch to data clock and publish initialized state.
static uint32_t internal_lba_to_arg (uint32_t lba)
 Convert an LBA to the card command argument.
static ra8_err_t internal_cmd_require_ready (sd_cmd_t cmd, uint32_t arg)
 Send one command and require a ready R1 response.
static ra8_err_t internal_erase_range (uint32_t lba, uint32_t count)
 Issue the SD erase-start, erase-end, and erase commands.
static ra8_err_t internal_read_block_payload (uint8_t *buf)
 Read one 512-byte payload from the active data stream.
static ra8_err_t internal_read_block_crc_check (const uint8_t *buf)
 Read and verify the CRC trailer for one block.
static ra8_err_t internal_read_data_phase (uint32_t lba, uint8_t *buf)
 Execute one complete CMD17 read data phase.
static ra8_err_t internal_read_multi_stop (void)
 Stop a CMD18 multi-block read stream.
static ra8_err_t internal_write_data_block (const uint8_t *buf, uint8_t start_token)
 Transmit one data block, CRC trailer, and start token.
static ra8_err_t internal_write_multi_stream (const uint8_t *buf, uint32_t count)
 Stream consecutive blocks for an accepted CMD25 operation.
static ra8_err_t internal_fs_read_block (void *ctx, uint64_t lba, uint32_t count, uint8_t *buf)
 Adapt the filesystem read callback to SD multi-block reads.
static ra8_err_t internal_fs_write_block (void *ctx, uint64_t lba, uint32_t count, const uint8_t *buf)
 Adapt the filesystem write callback to SD multi-block writes.
static ra8_err_t internal_fs_erase_block (void *ctx, uint64_t lba, uint64_t count)
 Adapt the filesystem erase callback to the SD erase API.
static ra8_err_t internal_fs_get_capacity (void *ctx, uint64_t *block_count, uint32_t *block_size)
 Publish SD geometry through the filesystem capacity callback.

Detailed Description

Contracts for file-local SD block-I/O helpers.

Declares only helpers defined by ra8_sdmmc_spi_io.c so contracts remain authoritative without expanding the implementation TU.

Definition in file ra8_sdmmc_spi_io_contracts_internal.h.

Function Documentation

◆ internal_cmd_require_ready()

ra8_err_t internal_cmd_require_ready ( sd_cmd_t cmd,
uint32_t arg )
static

Send one command and require a ready R1 response.

Brackets the command with chip select and rejects any nonzero R1.

Parameters
[in]cmdEncoded command byte.
[in]argCommand argument.
Returns
ra8_err_t Command result.
Return values
k_ra8_okThe card returned ready.
otherTransport or protocol error.
Precondition
The card is initialized and transport callbacks are valid.
cmd is legal for the current operation.
Postcondition
Chip select is released before return.
Success confirms an all-clear R1 response.
Note
Used by erase setup and execution commands.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_erase_range()

ra8_err_t internal_erase_range ( uint32_t lba,
uint32_t count )
static

Issue the SD erase-start, erase-end, and erase commands.

Converts the inclusive range endpoints through the active addressing mode.

Parameters
[in]lbaFirst logical block to erase.
[in]countNumber of consecutive blocks.
Returns
ra8_err_t Erase command result.
Return values
k_ra8_okThe card accepted and completed the erase.
otherCommand, transport, or busy-timeout error.
Precondition
count is positive and the range is capacity-checked.
The driver is initialized.
Postcondition
Success completes the requested card erase range.
Failure is returned without publishing a false success.
Note
Card-level erase granularity is implementation-defined.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_finalize_init()

ra8_err_t internal_finalize_init ( void )
static

Switch to data clock and publish initialized state.

Performs the final clock callback only after protocol setup succeeds.

Returns
ra8_err_t Finalization result.
Return values
k_ra8_okData clock is active and initialization is published.
otherPropagated clock callback failure.
Precondition
The full card initialization sequence succeeded.
The bound set-clock callback remains valid.
Postcondition
Success sets initialized true.
Failure leaves initialized false.
Note
Publication occurs after the fallible clock transition.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_fs_erase_block()

ra8_err_t internal_fs_erase_block ( void * ctx,
uint64_t lba,
uint64_t count )
static

Adapt the filesystem erase callback to the SD erase API.

Validates and narrows the filesystem range before delegation.

Parameters
[in]ctxUnused backend context.
[in]lbaFirst logical block.
[in]countNumber of blocks.
Returns
ra8_err_t Adapter result.
Return values
k_ra8_okRequested range was erased.
otherValidation or driver error.
Precondition
The range fits the driver 32-bit geometry.
The driver is initialized.
Postcondition
ctx remains untouched.
Success confirms the erase operation completed.
Note
Zero-length ranges are rejected by the public layer.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_fs_get_capacity()

ra8_err_t internal_fs_get_capacity ( void * ctx,
uint64_t * block_count,
uint32_t * block_size )
static

Publish SD geometry through the filesystem capacity callback.

Returns the initialized block count and fixed 512-byte block size.

Parameters
[in]ctxUnused backend context.
[out]block_countDestination for logical block count.
[out]block_sizeDestination for bytes per block.
Returns
ra8_err_t Capacity query result.
Return values
k_ra8_okBoth geometry values were published.
otherNull-pointer or invalid-state error.
Precondition
Both output pointers are non-null and writable.
The driver is initialized with validated capacity.
Postcondition
Success publishes both geometry values.
ctx remains untouched.
Note
The block size is always k_ra8_sdmmc_spi_block_size.
Since
0.1.0

◆ internal_fs_read_block()

ra8_err_t internal_fs_read_block ( void * ctx,
uint64_t lba,
uint32_t count,
uint8_t * buf )
static

Adapt the filesystem read callback to SD multi-block reads.

Narrows checked 64-bit arguments and delegates to the public driver API.

Parameters
[in]ctxUnused backend context.
[in]lbaFirst logical block.
[in]countNumber of blocks.
[out]bufWritable destination blocks.
Returns
ra8_err_t Adapter result.
Return values
k_ra8_okRequested blocks were read.
otherValidation or driver error.
Precondition
buf is non-null for a nonzero request.
Inputs fit the driver 32-bit geometry.
Postcondition
Success initializes all requested destination blocks.
ctx remains untouched.
Note
The bound backend intentionally uses no context object.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_fs_write_block()

ra8_err_t internal_fs_write_block ( void * ctx,
uint64_t lba,
uint32_t count,
const uint8_t * buf )
static

Adapt the filesystem write callback to SD multi-block writes.

Narrows checked 64-bit arguments and delegates to the public driver API.

Parameters
[in]ctxUnused backend context.
[in]lbaFirst logical block.
[in]countNumber of blocks.
[in]bufImmutable source blocks.
Returns
ra8_err_t Adapter result.
Return values
k_ra8_okRequested blocks were written.
otherValidation or driver error.
Precondition
buf is non-null for a nonzero request.
Inputs fit the driver 32-bit geometry.
Postcondition
Source blocks remain unchanged.
ctx remains untouched.
Note
The bound backend intentionally uses no context object.
Since
0.1.0

◆ internal_lba_to_arg()

uint32_t internal_lba_to_arg ( uint32_t lba)
static

Convert an LBA to the card command argument.

Uses block addressing for SDHC and checked byte addressing otherwise.

Parameters
[in]lbaLogical 512-byte block address.
Returns
Command argument for the active card type.
Return values
otherLBA or byte-addressed LBA value.
Precondition
Card type was classified during initialization.
lba is within the published capacity.
Postcondition
No state or storage is modified.
The result follows the active card addressing mode.
Note
Caller range checks prevent byte-address overflow.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_prepare_init()

ra8_err_t internal_prepare_init ( const ra8_sdmmc_spi_transport_t * transport)
static

Validate and stage the transport for initialization.

Rejects reinitialization, copies callbacks, and selects the init clock.

Parameters
[in]transportComplete caller-owned transport descriptor.
Returns
ra8_err_t Preparation result.
Return values
k_ra8_okTransport state and init clock are ready.
otherInvalid state or clock callback failure.
Precondition
transport passed the public callback validation.
The caller owns the singleton initialization sequence.
Postcondition
Success binds the transport without publishing initialization.
Failure leaves initialized false.
Note
The transport descriptor is copied, not retained by address.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_read_block_crc_check()

ra8_err_t internal_read_block_crc_check ( const uint8_t * buf)
static

Read and verify the CRC trailer for one block.

Compares the two wire CRC bytes against CRC16 of caller data.

Parameters
[in]bufComplete block payload to authenticate.
Returns
ra8_err_t CRC validation result.
Return values
k_ra8_okWire and computed CRC values match.
otherTransport failure or CRC mismatch.
Precondition
buf contains one complete block.
The stream is positioned at the CRC trailer.
Postcondition
Input payload remains unchanged.
Success authenticates the just-read block.
Note
CRC uses the SD SPI polynomial and seed.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_read_block_payload()

ra8_err_t internal_read_block_payload ( uint8_t * buf)
static

Read one 512-byte payload from the active data stream.

Clocks exactly one public block into caller storage.

Parameters
[out]bufWritable block-sized destination.
Returns
ra8_err_t Payload transfer result.
Return values
k_ra8_okExactly one block was received.
otherPropagated transport failure.
Precondition
A valid data-start token was consumed.
buf addresses at least one block.
Postcondition
Success initializes every destination byte.
No bytes beyond the destination block are written.
Note
CRC bytes are handled separately.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_read_data_phase()

ra8_err_t internal_read_data_phase ( uint32_t lba,
uint8_t * buf )
static

Execute one complete CMD17 read data phase.

Sends the addressed command, waits for a token, reads data, and checks CRC.

Parameters
[in]lbaCapacity-checked logical block address.
[out]bufWritable block destination.
Returns
ra8_err_t Single-block read result.
Return values
k_ra8_okOne authenticated block was read.
otherCommand, token, transfer, or CRC error.
Precondition
The driver is initialized and lba is in range.
buf addresses at least one block.
Postcondition
Chip select is released before return.
Success publishes a complete authenticated block.
Note
The public wrapper owns null and range validation.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_read_multi_stop()

ra8_err_t internal_read_multi_stop ( void )
static

Stop a CMD18 multi-block read stream.

Sends CMD12, accepts its stuff byte, and waits for card readiness.

Returns
ra8_err_t Stop-sequence result.
Return values
k_ra8_okThe stream stopped and the card became ready.
otherTransport, response, or busy-timeout error.
Precondition
A CMD18 stream is active with chip select asserted.
The bound transport remains valid.
Postcondition
The card stop sequence was attempted exactly once.
Caller can release chip select after return.
Note
Stop is attempted even after an earlier stream error.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_write_data_block()

ra8_err_t internal_write_data_block ( const uint8_t * buf,
uint8_t start_token )
static

Transmit one data block, CRC trailer, and start token.

Validates the card data-response token and waits out programming busy.

Parameters
[in]bufComplete 512-byte source block.
[in]start_tokenSingle- or multi-block data-start token.
Returns
ra8_err_t Data-block write result.
Return values
k_ra8_okThe card accepted and programmed the block.
otherTransport, response, or busy-timeout error.
Precondition
Chip select is asserted for an accepted write command.
buf addresses one immutable source block.
Postcondition
Source bytes remain unchanged.
Success confirms the card left its programming-busy state.
Note
CRC16 is generated from the source payload.
Since
0.1.0

References RA8_INTERNAL.

◆ internal_write_multi_stream()

ra8_err_t internal_write_multi_stream ( const uint8_t * buf,
uint32_t count )
static

Stream consecutive blocks for an accepted CMD25 operation.

Writes each source block, then sends the multi-block stop token.

Parameters
[in]bufContiguous immutable source blocks.
[in]countNumber of blocks to transmit.
Returns
ra8_err_t Stream result.
Return values
k_ra8_okEvery block and the stop token were accepted.
otherFirst transfer, response, or busy error.
Precondition
buf addresses count complete blocks.
count is positive and capacity-checked.
Postcondition
Source storage remains unchanged.
The stop token is attempted before successful return.
Note
The caller releases chip select around the stream.
Since
0.1.0

References RA8_INTERNAL.