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

Download, validate, publish, and reopen one C6-fetched .rabook. More...

#include <stddef.h>
#include <stdint.h>
#include "book.h"
#include "mdl_rabook_vfs.h"
#include "mdl_storage_vfs.h"
#include "media_download_image_internal.h"
#include "miniz.h"
#include "ra8_attributes.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_c6link.h"
#include "ra8_c6link_mdl_transfer.h"
#include "ra8_c6link_wifi.h"
#include "ra8_err.h"
#include "ra8_esp_hosted_c6link.h"
#include "ra8_esp_hosted_port.h"
#include "ra8_fs.h"
#include "ra8_io_vfs.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_net_provision.h"
#include "ra8_rsip.h"
#include "ra8_sdmmc_spi.h"
#include "ra8_secure.h"
#include "ra8_time.h"
#include "tx_api.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define RA8_MEDIA_DOWNLOAD_SOURCE_IMAGE   (0)
 Default preserves direct validation of prebuilt .rabook bodies.

Enumerations

enum  media_limit_t : uint32_t {
  k_media_uart_baud = 115200U ,
  k_media_c6_sck_hz = 5000000U ,
  k_media_c6_edge_poll_ms = 2U ,
  k_media_c6_boot_wait_ms = 200U ,
  k_media_assoc_tries = 200U ,
  k_media_assoc_gap_ms = 50U ,
  k_media_diagnostic_bytes = 256U ,
  k_media_heartbeat_ms = 5000U ,
  k_media_worker_stack_bytes = 8192U ,
  k_media_worker_priority = 8U ,
  k_media_c6_arena_bytes = 4096U ,
  k_media_transfer_chunk = 1024U ,
  k_media_transfer_chunks = 32768U ,
  k_media_rbkc_chunk_bytes = 65536U ,
  k_media_compressed_bytes = 66560U ,
  k_media_table_entries = 2049U ,
  k_media_scratch_bytes = 65536U
}
 Fixed application bounds and board integration policy. More...

Functions

static void internal_puts (const char *text)
 Write one bounded NUL-terminated diagnostic to the board console.
static bool internal_fail (const char *stage, ra8_err_t err)
 Emit one failed-stage diagnostic.
static void internal_halt (void)
 Park the core permanently after an unrecoverable startup failure.
static void internal_setup_or_halt (void)
 Bring up clocks, MSTP, delay timing, and the board console.
static void internal_on_event (void *context, const ra8_c6link_event_t *event)
 Latch the two station events used by the bounded association wait.
static bool internal_wait_connected (void)
 Pump the C6 link until association succeeds or the fixed budget ends.
static ra8_err_t internal_open_and_join (const ra8_net_credentials_t *credentials)
 Open the C6 link, prove readiness, and associate its Wi-Fi station.
static ra8_err_t internal_mount_sd (void)
 Mount the existing Pmod2 SD FAT volume under the VFS name sd.
static ra8_err_t internal_inflate (const void *source, size_t source_bytes, void *destination, size_t destination_capacity, size_t *output_bytes)
 Inflate one zlib-wrapped RBKC chunk without heap allocation.
static ra8_err_t internal_sha_init (void *context)
 Reset the caller-owned SHA-256 stream.
static ra8_err_t internal_sha_update (void *context, const uint8_t *data, uint16_t length)
 Feed one accepted body chunk to the independent RA8 digest.
static ra8_err_t internal_sha_final (void *context, uint8_t output[k_ra8_mdl_sha256_bytes])
 Finalize the independent digest into the coordinator output.
static ra8_err_t internal_bind_transfer (ra8_mdl_transfer_config_t *output)
 Bind strict reader, transaction, SHA, and coordinator policy.
static ra8_err_t internal_consume (void)
 Reopen the committed RBKC and consume its first exact inflated chunk.
static ra8_err_t internal_transfer_and_consume (const ra8_net_credentials_t *configuration)
 Bind, execute, validate, and consume one configured media transfer.
static bool internal_run (ra8_net_credentials_t *configuration)
 Execute the complete hardware composition once.
static void internal_heartbeat (bool passed)
 Keep the final verdict visible without busy-waiting.
static void internal_worker (ULONG input)
 Worker entry for the one-shot media transaction.
void tx_application_define (void *first_unused_memory)
 Initialize ESP-hosted and create the single application worker.
void main (void)
 Initialize the board and hand control to ThreadX.

Variables

static const char s_destination [] = "sd:/BOOKS/C6BOOK.RBK"
 No-replace destination on the mounted SD card.
static const char s_stage_leaf [] = "C6STAGE.TMP"
 Reserved sibling transaction name.
static const bool s_source_is_image = (0) != 0
 Build-time input policy: encoded image or prebuilt RBKC body.
static uint32_t s_cpuclk_hz
 Cached CPU clock for the delay service.
static uint32_t s_pclka_hz
 Cached PCLKA clock for both SPI transports.
static ra8_err_t s_port_err = k_ra8_err_not_initialized
 ESP-hosted port initialization verdict.
static TX_THREAD s_worker
 Worker thread object.
static CHAR s_worker_name [] = "media_download"
 Writable ThreadX worker name.
static UCHAR s_worker_stack [k_media_worker_stack_bytes]
 Caller-owned ThreadX worker stack.
static ra8_c6link_t s_link
 One exclusively owned C6 link.
static uint8_t s_c6_arena [k_media_c6_arena_bytes]
 Fixed C6 decode arena.
static volatile uint8_t s_connected
 Station-associated event latch.
static volatile uint8_t s_disconnected
 Station-disconnected event latch.
static const ra8_net_provision_uart_t s_provision_uart
 Board-console binding for the shared runtime provisioner.
static ra8_fs_backend_t s_fs_backend
 SD filesystem backend retained for the mount lifetime.
static ra8_fs_mount_ts_mount
 Mounted existing SD volume.
static mdl_storage_vfs_t s_storage
 Transactional VFS storage adapter.
static mdl_rabook_vfs_t s_rabook
 Strict RBKC validator and final reader.
static ra8_rsip_sha256_ctx_t s_sha
 Streaming RA8-side SHA-256 context.
static uint64_t s_table [k_media_table_entries]
 RBKC offset table: up to 128 MiB inflated at 64 KiB per chunk.
static uint8_t s_compressed [k_media_compressed_bytes]
 One compressed zlib stream.
static uint8_t s_chunk [k_media_rbkc_chunk_bytes]
 One inflated RBKC chunk and final-consumption destination.
static uint8_t s_scratch [k_media_scratch_bytes]
 Independent strict semantic and CRC scratch.

Detailed Description

Download, validate, publish, and reopen one C6-fetched .rabook.

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

This hardware-pending composition root joins Wi-Fi through the ESP32-C6, mounts an existing FAT volume on Pmod2 micro-SD, and downloads either one prebuilt RBKC .rabook body or one encoded image through the C6 media RPC. Image mode converts the source into a reader-native RABOOK1 book and RBKC container on the RA8. Both modes hash, strictly validate, transactionally publish, reopen, and consume the result. Every large workspace is caller-owned SDRAM; neither first-party heap nor stdio is used.

The image is credential-free. A bounded versioned record supplies Wi-Fi and URL configuration over the board console after boot. The app stays in hw_pending until the exact mixed RA8/C6 image and removable-media path pass physical fault-injection HIL.

Since
0.1.0

Definition in file main.c.

Macro Definition Documentation

◆ RA8_MEDIA_DOWNLOAD_SOURCE_IMAGE

#define RA8_MEDIA_DOWNLOAD_SOURCE_IMAGE   (0)

Default preserves direct validation of prebuilt .rabook bodies.

Definition at line 56 of file main.c.

Enumeration Type Documentation

◆ media_limit_t

enum media_limit_t : uint32_t

Fixed application bounds and board integration policy.

Enumerator
k_media_uart_baud 

J-Link OB console rate.

k_media_c6_sck_hz 

Bench-proven C6 SPI rate.

k_media_c6_edge_poll_ms 

C6 side-band poll period.

k_media_c6_boot_wait_ms 

Coprocessor settle time.

k_media_assoc_tries 

Bounded station-event polls.

k_media_assoc_gap_ms 

Delay between association polls.

k_media_diagnostic_bytes 

Maximum emitted diagnostic length.

k_media_heartbeat_ms 

Persistent verdict interval.

k_media_worker_stack_bytes 

ThreadX worker stack.

k_media_worker_priority 

Worker priority and threshold.

k_media_c6_arena_bytes 

Protobuf decode arena.

k_media_transfer_chunk 

Bytes requested per C6 body pull.

k_media_transfer_chunks 

32 MiB compressed-body ceiling.

k_media_rbkc_chunk_bytes 

Accepted inflated RBKC chunk geometry.

k_media_compressed_bytes 

One worst-case zlib-wrapped 64 KiB chunk.

k_media_table_entries 

2048 chunks + terminal offset.

k_media_scratch_bytes 

Strict CRC/ownership validation scratch.

Definition at line 63 of file main.c.

Function Documentation

◆ internal_bind_transfer()

ra8_err_t internal_bind_transfer ( ra8_mdl_transfer_config_t * output)
static

Bind strict reader, transaction, SHA, and coordinator policy.

Connects only caller-owned workspaces and the mounted VFS to a create-new transaction whose validator reopens every RBKC stream.

Parameters
[out]outputComplete transfer configuration.
Returns
Adapter binding status.
Return values
k_ra8_okEvery caller-owned seam is ready.
Precondition
The SD VFS mount is registered.
All static workspaces are exclusively available.
Postcondition
Success binds strict validation before transaction commit.
Failure starts no storage transaction.
Note
The 32 MiB transfer ceiling is independent of inflated RBKC size.
Since
0.1.0

Definition at line 506 of file main.c.

References internal_inflate(), internal_sha_final(), internal_sha_init(), internal_sha_update(), k_mdl_format_rabook, k_media_table_entries, k_media_transfer_chunk, k_media_transfer_chunks, k_ra8_ok, mdl_rabook_vfs_init(), mdl_rabook_vfs_validate(), mdl_storage_vfs_init(), RA8_INTERNAL, s_chunk, s_compressed, s_rabook, s_scratch, s_sha, s_stage_leaf, s_storage, and s_table.

Referenced by internal_transfer_and_consume().

◆ internal_consume()

ra8_err_t internal_consume ( void )
static

Reopen the committed RBKC and consume its first exact inflated chunk.

Revalidates final-file geometry through the reusable reader and performs one demand-paged chunk read to prove post-publication consumption.

Returns
Strict reader and consumption status.
Return values
k_ra8_okMetadata and the first chunk were read successfully.
k_ra8_err_invalid_sizeGeometry exceeds the bound workspace.
Precondition
The transaction committed s_destination.
s_rabook remains initialized and closed.
Postcondition
The final reader is closed on every path after a successful open.
Success proves at least one demand-paged read from the published file.
Note
Full semantic validation already consumed every chunk before commit.
Since
0.1.0

Definition at line 558 of file main.c.

References k_ra8_err_invalid_size, k_ra8_ok, mdl_rabook_vfs_close(), mdl_rabook_vfs_info(), mdl_rabook_vfs_open(), mdl_rabook_vfs_read_chunk(), RA8_INTERNAL, s_chunk, s_destination, s_rabook, and book_header_t::total_size.

Referenced by internal_transfer_and_consume().

◆ internal_fail()

bool internal_fail ( const char * stage,
ra8_err_t err )
static

Emit one failed-stage diagnostic.

Composes the stage label and canonical error spelling as bounded fragments so a failure path never needs a formatting stream or scratch.

Parameters
[in]stageStable stage label.
[in]errCanonical RA8 error for that stage.
Returns
Always false for direct propagation through a phase chain.
Return values
falseThe stage failed.
Precondition
The console is initialized.
stage is a bounded NUL-terminated string.
Postcondition
One FAIL line was queued.
No transfer or storage state was changed.
Note
Formatting uses bounded writes, never stdio.
Since
0.1.0

Definition at line 174 of file main.c.

References internal_puts(), ra8_err_to_str(), and RA8_INTERNAL.

Referenced by internal_run(), and internal_worker().

◆ internal_halt()

void internal_halt ( void )
static

Park the core permanently after an unrecoverable startup failure.

Precondition
Reset handling configured the CPU for WFI.
No recovery path remains.
Postcondition
The function never returns.
The core repeatedly executes WFI.
Note
Used only before or after ThreadX owns scheduling.
Since
0.1.0

Definition at line 193 of file main.c.

References RA8_INTERNAL.

Referenced by internal_setup_or_halt(), and main().

◆ internal_heartbeat()

void internal_heartbeat ( bool passed)
static

Keep the final verdict visible without busy-waiting.

Parameters
[in]passedStable end-to-end verdict.
Precondition
The ThreadX worker is running.
The console remains initialized.
Postcondition
The function never returns.
One bounded heartbeat is emitted every configured interval.
Note
Storage and C6 transports are not touched after the verdict.
Since
0.1.0

Definition at line 676 of file main.c.

References internal_puts(), k_media_heartbeat_ms, RA8_INTERNAL, and tx_thread_sleep.

Referenced by internal_worker().

◆ internal_inflate()

ra8_err_t internal_inflate ( const void * source,
size_t source_bytes,
void * destination,
size_t destination_capacity,
size_t * output_bytes )
static

Inflate one zlib-wrapped RBKC chunk without heap allocation.

Adapts miniz's bounded memory-to-memory decoder to the strict RBKC reader callback and maps an incomplete or malformed stream to validation.

Parameters
[in]sourceCompressed bytes.
[in]source_bytesCompressed byte count.
[out]destinationInflated destination.
[in]destination_capacityWritable destination capacity.
[out]output_bytesExact inflated count.
Returns
Inflation or validation status.
Return values
k_ra8_okOne complete stream inflated.
k_ra8_err_validation_failedMiniz rejected the stream.
Precondition
All pointers are non-null and their extents match the sizes.
The build defines MINIZ_NO_MALLOC and MINIZ_NO_STDIO.
Postcondition
Success initializes exactly *output_bytes destination bytes.
Failure publishes no reader metadata.
Note
The callback satisfies book_inflate_fn.
Since
0.1.0

Definition at line 405 of file main.c.

References k_ra8_err_null_ptr, k_ra8_err_validation_failed, k_ra8_ok, and RA8_INTERNAL.

Referenced by internal_bind_transfer(), and ra8_fmt_rabook_inspect_stream().

◆ internal_mount_sd()

ra8_err_t internal_mount_sd ( void )
static

Mount the existing Pmod2 SD FAT volume under the VFS name sd.

Composes the board SCI transport through SDMMC, FAT, and VFS layers, then prepares only the bounded BOOKS namespace without formatting media.

Returns
Mount and directory-preparation status.
Return values
k_ra8_okThe mount and sd:/BOOKS directory are ready.
k_ra8_err_invalid_argBOOKS exists but is not a directory.
Precondition
PCLKA is cached and the Pmod2 pins are free.
The card already contains a supported FAT volume; it is never formatted.
Postcondition
Success leaves s_mount live and registered as sd.
Failure never creates or replaces the destination book.
Note
The storage transaction later refuses an existing destination.
Since
0.1.0

Definition at line 346 of file main.c.

References ra8_io_vfs_stat_t::exists, ra8_io_vfs_stat_t::is_directory, k_ra8_board_pmod2_sci_channel, k_ra8_board_pmod2_spi_cipo, k_ra8_board_pmod2_spi_copi, k_ra8_board_pmod2_spi_cs, k_ra8_board_pmod2_spi_sck, k_ra8_err_invalid_arg, k_ra8_ok, ra8_fs_mount(), RA8_INTERNAL, ra8_io_vfs_init(), ra8_io_vfs_mkdir(), ra8_io_vfs_mount(), ra8_io_vfs_stat(), ra8_sdmmc_spi_bind_fs_backend(), ra8_sdmmc_spi_init(), ra8_sdmmc_spi_transport_sci(), s_fs_backend, s_mount, and s_pclka_hz.

Referenced by internal_run().

◆ internal_on_event()

void internal_on_event ( void * context,
const ra8_c6link_event_t * event )
static

Latch the two station events used by the bounded association wait.

Reduces the asynchronous event stream to the two terminal states needed by the worker's bounded association loop.

Parameters
[in]contextUnused callback context.
[in]eventC6 event record, or null for a defensive no-op.
Precondition
The C6 link invokes this synchronously while polling.
File-scope event latches are writable.
Postcondition
Connected/disconnected station events set their matching latch.
Other events and null input leave both latches unchanged.
Note
The worker is the only reader, so byte latches are sufficient.
Since
0.1.0

Definition at line 238 of file main.c.

References k_ra8_c6link_event_sta_connected, k_ra8_c6link_event_sta_disconnected, ra8_c6link_event::kind, RA8_INTERNAL, s_connected, and s_disconnected.

Referenced by internal_open_and_join().

◆ internal_open_and_join()

ra8_err_t internal_open_and_join ( const ra8_net_credentials_t * credentials)
static

Open the C6 link, prove readiness, and associate its Wi-Fi station.

Binds the ESP-hosted transport, completes the C6 readiness handshake, starts Wi-Fi, and applies the supplied runtime station credentials.

Parameters
[in]credentialsValidated runtime credential record.
Returns
Association status.
Return values
k_ra8_okThe C6 is ready and the station connected.
k_ra8_err_invalid_argCredentials are empty.
Precondition
ESP-hosted port initialization succeeded.
The C6 worker owns the transport.
Postcondition
Success leaves s_link open and associated.
Failure publishes no storage object.
Note
No NetX stack is needed; HTTPS executes on the C6 service.
Since
0.1.0

Definition at line 296 of file main.c.

References ra8_c6link_cfg::arena, ra8_c6link_cfg::arena_bytes, ra8_c6link_cfg::event_cb, internal_on_event(), internal_wait_connected(), k_ra8_c6link_announce_transfers, k_ra8_err_invalid_arg, k_ra8_err_timeout, k_ra8_ok, ra8_net_credentials::psk, ra8_c6link_await_ready(), ra8_c6link_open(), ra8_c6link_sta_cfg_set(), ra8_c6link_wifi_join(), ra8_c6link_wifi_start(), ra8_esp_hosted_c6link_bind(), RA8_INTERNAL, ra8_secure_memzero(), s_c6_arena, s_link, ra8_net_credentials::ssid, and ra8_c6link_cfg::transport.

Referenced by internal_run().

◆ internal_puts()

void internal_puts ( const char * text)
static

Write one bounded NUL-terminated diagnostic to the board console.

Measures only within the fixed diagnostic cap, then sends that byte span through the board's allocation-free UART adapter.

Parameters
[in]textNUL-terminated text to emit.
Precondition
The J-Link OB console was initialized.
text is non-null and terminates within the diagnostic cap.
Postcondition
At most k_media_diagnostic_bytes were presented to the UART driver.
No application state was modified.
Note
Single-worker use; no synchronization is provided.
Since
0.1.0

Definition at line 150 of file main.c.

References k_media_diagnostic_bytes, ra8_board_uart_console_write(), and RA8_INTERNAL.

Referenced by internal_fail(), internal_heartbeat(), internal_run(), main(), and tx_application_define().

◆ internal_run()

bool internal_run ( ra8_net_credentials_t * configuration)
static

Execute the complete hardware composition once.

Sequences storage mount, RSIP self-test, C6 association, bounded transfer, optional image-to-RABOOK formatting, strict precommit validation, publication, and final consumption.

Returns
End-to-end verdict.
Return values
trueThe artifact was downloaded, committed, and consumed.
falseOne named stage failed.
Precondition
The worker is running and ESP-hosted port init completed.
Parameters
[in,out]configurationValidated runtime network and URL configuration.
Precondition
Runtime URL and credentials are non-empty and bounded.
Postcondition
Success leaves one validated destination and no stage file.
Failure emits a named diagnostic and publishes no new destination.
Note
An existing destination is intentionally preserved and causes failure.
Since
0.1.0

Definition at line 631 of file main.c.

References internal_fail(), internal_mount_sd(), internal_open_and_join(), internal_puts(), internal_transfer_and_consume(), k_media_c6_boot_wait_ms, k_ra8_err_invalid_arg, k_ra8_ok, ra8_net_credentials::psk, ra8_net_credentials::psk_len, ra8_c6link_close(), ra8_delay_ms(), RA8_INTERNAL, ra8_rsip_init(), ra8_secure_memzero(), s_link, s_port_err, ra8_net_credentials::ssid, ra8_net_credentials::ssid_len, and ra8_net_credentials::url.

Referenced by internal_worker().

◆ internal_setup_or_halt()

void internal_setup_or_halt ( void )
static

Bring up clocks, MSTP, delay timing, and the board console.

Establishes the clock values consumed by the C6 and SD transports before ThreadX can schedule their single owning worker.

Precondition
Reset startup initialized .data and .bss.
No peripheral service has been initialized yet.
Postcondition
Success leaves CPUCLK0/PCLKA cached and the console usable.
Any failure parks the core without starting ThreadX.
Note
Called exactly once from main.
Since
0.1.0

Definition at line 211 of file main.c.

References ra8_board_clock_rates_t::cpuclk0_hz, internal_halt(), k_media_uart_baud, k_ra8_ok, ra8_board_clock_rates_t::pclka_hz, ra8_board_clocks_init(), ra8_board_uart_console_init(), RA8_INTERNAL, ra8_mstp_init(), ra8_time_init(), s_cpuclk_hz, and s_pclka_hz.

Referenced by main().

◆ internal_sha_final()

ra8_err_t internal_sha_final ( void * context,
uint8_t output[k_ra8_mdl_sha256_bytes] )
static

Finalize the independent digest into the coordinator output.

Completes the RSIP stream directly into the transfer coordinator's fixed-size digest destination for comparison with the C6-advertised hash.

Parameters
[in,out]contextBound ra8_rsip_sha256_ctx_t.
[out]outputExact SHA-256 digest span.
Returns
SHA finalization status.
Return values
k_ra8_okThe complete digest was written.
k_ra8_err_invalid_argThe state or output span was invalid.
Precondition
context received every accepted body byte.
output covers k_ra8_mdl_sha256_bytes bytes.
Postcondition
Success initializes the complete digest.
The context is no longer an active digest stream.
Note
Finalization retains no artifact body bytes.
Since
0.1.0

Definition at line 486 of file main.c.

References k_ra8_mdl_sha256_bytes, RA8_INTERNAL, and ra8_rsip_sha256_final().

Referenced by internal_bind_transfer().

◆ internal_sha_init()

ra8_err_t internal_sha_init ( void * context)
static

Reset the caller-owned SHA-256 stream.

Adapts the transfer coordinator's opaque context callback to the caller-owned RSIP SHA-256 state without copying or retaining input bytes.

Parameters
[in,out]contextBound ra8_rsip_sha256_ctx_t.
Returns
SHA initialization status.
Return values
k_ra8_okThe digest stream was reset.
k_ra8_err_invalid_argThe bound context was invalid.
Precondition
context points to s_sha.
The context is exclusively owned by one transfer.
Postcondition
Success resets the streaming digest.
No C6 or storage state changes.
Note
The coordinator invokes this once before accepting body bytes.
Since
0.1.0

Definition at line 442 of file main.c.

References RA8_INTERNAL, and ra8_rsip_sha256_init().

Referenced by internal_bind_transfer().

◆ internal_sha_update()

ra8_err_t internal_sha_update ( void * context,
const uint8_t * data,
uint16_t length )
static

Feed one accepted body chunk to the independent RA8 digest.

Preserves transfer order while forwarding each accepted C6 body fragment to the streaming RSIP digest used for final wire verification.

Parameters
[in,out]contextBound ra8_rsip_sha256_ctx_t.
[in]dataOrdered body bytes.
[in]lengthBody byte count.
Returns
SHA update status.
Return values
k_ra8_okThe complete fragment entered the digest.
k_ra8_err_invalid_argThe state or input span was invalid.
Precondition
context was initialized and data covers length bytes.
Calls remain in transfer order.
Postcondition
Success incorporates all length bytes.
The source bytes are unchanged.
Note
The transfer chunk is bounded to fit the callback's uint16 length.
Since
0.1.0

Definition at line 465 of file main.c.

References ra8_rsip_sha256_update().

Referenced by internal_bind_transfer().

◆ internal_transfer_and_consume()

ra8_err_t internal_transfer_and_consume ( const ra8_net_credentials_t * configuration)
static

Bind, execute, validate, and consume one configured media transfer.

Parameters
[in]configurationValidated runtime configuration whose URL is nonempty.
Returns
Transfer or post-publication consumption status.
Return values
k_ra8_okThe artifact was transferred and consumed successfully.
Precondition
configuration is non-NULL and remains live for the synchronous call.
Storage, RSIP, and the C6 station are initialized.
Postcondition
Success leaves a validated artifact at s_destination.
The C6 link remains open for the caller to close.
Note
Uses only bounded, caller-owned static workspaces.
Since
0.1.0

Definition at line 597 of file main.c.

References internal_bind_transfer(), internal_consume(), k_ra8_ok, priv_media_download_image_run(), ra8_c6link_mdl_transfer(), s_destination, s_link, s_source_is_image, and ra8_net_credentials::url.

Referenced by internal_run().

◆ internal_wait_connected()

bool internal_wait_connected ( void )
static

Pump the C6 link until association succeeds or the fixed budget ends.

Alternates bounded RPC polling with ThreadX sleeps and stops on the first connection, disconnection, or exhausted-attempt condition.

Returns
Whether the station-connected event arrived first.
Return values
trueAssociation completed.
falseDisconnection or the poll budget ended first.
Precondition
The link is open and a join request was accepted.
The worker exclusively owns the link.
Postcondition
At most k_media_assoc_tries poll calls were made.
No storage operation was attempted.
Note
ThreadX sleeps between polls to avoid a busy wait.
Since
0.1.0

Definition at line 265 of file main.c.

References k_media_assoc_gap_ms, k_media_assoc_tries, k_ra8_c6link_announce_transfers, ra8_c6link_poll(), RA8_INTERNAL, s_connected, s_disconnected, s_link, and tx_thread_sleep.

Referenced by internal_open_and_join().

◆ internal_worker()

void internal_worker ( ULONG input)
static

Worker entry for the one-shot media transaction.

Runs the complete transaction exactly once and converts its stable result into a low-duty-cycle heartbeat for bench observation.

Parameters
[in]inputUnused ThreadX entry value.
Precondition
ThreadX started this worker after tx_application_define.
The console and clock cache are ready.
Postcondition
The worker transitions permanently into verdict heartbeat.
The transaction runs at most once.
Note
This worker exclusively owns C6, VFS, reader, and SHA contexts.
Since
0.1.0

Definition at line 696 of file main.c.

References internal_fail(), internal_heartbeat(), internal_run(), k_ra8_net_provision_timeout_ms, k_ra8_ok, RA8_INTERNAL, ra8_net_provision_clear(), ra8_net_provision_receive(), and s_provision_uart.

Referenced by tx_application_define().

◆ main()

void main ( void )

Initialize the board and hand control to ThreadX.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler initialized static storage.
SystemInit configured VTOR, FPU, and priority grouping.
Postcondition
The startup banner is printed once.
Control enters ThreadX and never returns normally.
Note
The #707 freestanding contract is declared by ra8_boot_entry.h.
Since
0.1.0

Definition at line 756 of file main.c.

References internal_halt(), internal_puts(), internal_setup_or_halt(), and ra8_isr_globals_enable().

◆ tx_application_define()

void tx_application_define ( void * first_unused_memory)

Initialize ESP-hosted and create the single application worker.

Parameters
[in]first_unused_memoryThreadX free-memory pointer; unused.
Precondition
::tx_kernel_enter was called and PCLKA is cached.
No ESP-hosted API was called earlier.
Postcondition
s_port_err records the exact port-init status.
A successful thread creation starts exactly one worker.
Note
ThreadX object creation belongs in this kernel hook.
Since
0.1.0

Definition at line 723 of file main.c.

References internal_puts(), internal_worker(), k_media_c6_edge_poll_ms, k_media_c6_sck_hz, k_media_worker_priority, k_ra8_board_pmod1_sci_channel, ra8_esp_hosted_port_init(), s_pclka_hz, s_port_err, s_worker, s_worker_name, s_worker_stack, TX_AUTO_START, TX_NO_TIME_SLICE, TX_SUCCESS, and tx_thread_create.

Variable Documentation

◆ s_c6_arena

uint8_t s_c6_arena[k_media_c6_arena_bytes]
static

Fixed C6 decode arena.

Definition at line 105 of file main.c.

Referenced by internal_open_and_join().

◆ s_chunk

uint8_t s_chunk[k_media_rbkc_chunk_bytes]
static

One inflated RBKC chunk and final-consumption destination.

Definition at line 134 of file main.c.

Referenced by internal_bind_transfer(), and internal_consume().

◆ s_compressed

uint8_t s_compressed[k_media_compressed_bytes]
static

One compressed zlib stream.

Definition at line 132 of file main.c.

Referenced by internal_bind_transfer().

◆ s_connected

volatile uint8_t s_connected
static

Station-associated event latch.

Definition at line 107 of file main.c.

◆ s_cpuclk_hz

uint32_t s_cpuclk_hz
static

Cached CPU clock for the delay service.

Definition at line 91 of file main.c.

◆ s_destination

const char s_destination[] = "sd:/BOOKS/C6BOOK.RBK"
static

No-replace destination on the mounted SD card.

Definition at line 84 of file main.c.

Referenced by internal_consume(), and internal_transfer_and_consume().

◆ s_disconnected

volatile uint8_t s_disconnected
static

Station-disconnected event latch.

Definition at line 109 of file main.c.

◆ s_fs_backend

ra8_fs_backend_t s_fs_backend
static

SD filesystem backend retained for the mount lifetime.

Definition at line 118 of file main.c.

Referenced by demo_fs_format_or_panic(), and internal_mount_sd().

◆ s_link

ra8_c6link_t s_link
static

One exclusively owned C6 link.

Definition at line 103 of file main.c.

◆ s_mount

ra8_fs_mount_t* s_mount
static

Mounted existing SD volume.

Definition at line 120 of file main.c.

◆ s_pclka_hz

uint32_t s_pclka_hz
static

Cached PCLKA clock for both SPI transports.

Definition at line 93 of file main.c.

◆ s_port_err

ra8_err_t s_port_err = k_ra8_err_not_initialized
static

ESP-hosted port initialization verdict.

Definition at line 95 of file main.c.

◆ s_provision_uart

const ra8_net_provision_uart_t s_provision_uart
static
Initial value:
= {
.wait_ms = ra8_delay_ms,
}
ra8_err_t ra8_board_uart_console_read(uint8_t *out, size_t cap, size_t *out_len)
Polled non-blocking read from the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Definition ra8_time.c:129

Board-console binding for the shared runtime provisioner.

Definition at line 111 of file main.c.

◆ s_rabook

mdl_rabook_vfs_t s_rabook
static

Strict RBKC validator and final reader.

Definition at line 124 of file main.c.

Referenced by internal_bind_transfer(), and internal_consume().

◆ s_scratch

uint8_t s_scratch[k_media_scratch_bytes]
static

Independent strict semantic and CRC scratch.

Definition at line 136 of file main.c.

◆ s_sha

ra8_rsip_sha256_ctx_t s_sha
static

Streaming RA8-side SHA-256 context.

Definition at line 126 of file main.c.

Referenced by internal_bind_transfer().

◆ s_source_is_image

const bool s_source_is_image = (0) != 0
static

Build-time input policy: encoded image or prebuilt RBKC body.

Definition at line 88 of file main.c.

Referenced by internal_transfer_and_consume().

◆ s_stage_leaf

const char s_stage_leaf[] = "C6STAGE.TMP"
static

Reserved sibling transaction name.

Definition at line 86 of file main.c.

Referenced by internal_bind_transfer().

◆ s_storage

mdl_storage_vfs_t s_storage
static

Transactional VFS storage adapter.

Definition at line 122 of file main.c.

Referenced by internal_bind_transfer().

◆ s_table

uint64_t s_table[k_media_table_entries]
static

RBKC offset table: up to 128 MiB inflated at 64 KiB per chunk.

Definition at line 129 of file main.c.

◆ s_worker

TX_THREAD s_worker
static

Worker thread object.

Definition at line 97 of file main.c.

◆ s_worker_name

CHAR s_worker_name[] = "media_download"
static

Writable ThreadX worker name.

Definition at line 99 of file main.c.

◆ s_worker_stack

UCHAR s_worker_stack[k_media_worker_stack_bytes]
static

Caller-owned ThreadX worker stack.

Definition at line 101 of file main.c.