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

Shared C6 camera-stream application workflow. More...

#include <stdint.h>
#include "c6_camera_server.h"
#include "nx_ether_driver_c6.h"
#include "ra8_attributes.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_c6link.h"
#include "ra8_c6link_wifi.h"
#include "ra8_err.h"
#include "ra8_esp_hosted_c6link.h"
#include "ra8_esp_hosted_port.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_net_provision.h"
#include "ra8_sdramc.h"
#include "ra8_secure.h"
#include "ra8_time.h"
#include "tx_api.h"
Include dependency graph for c6_cam_app.c:

Go to the source code of this file.

Functions

static void internal_c6_cam_halt (void)
 Park the application after a terminal failure.
static void internal_c6_cam_setup_or_halt (void)
 Initialize shared clocks, services, and the diagnostic console.
static void internal_c6_cam_on_event (void *ctx, const ra8_c6link_event_t *event)
 Latch station connection events from the C6 link.
static void internal_c6_cam_report_fault (const char *stage, ra8_err_t err)
 Emit one standardized application failure line.
static ra8_err_t internal_c6_cam_open_link (void)
 Bind and open the raw ESP-hosted C6 link.
static bool internal_c6_cam_wait_connected (void)
 Poll for a station association result.
static bool internal_c6_cam_prepare_link (void)
 Open the C6 link and await firmware readiness.
static bool internal_c6_cam_associate (ra8_c6link_mac_t *mac, const ra8_net_credentials_t *credentials)
 Start station mode and associate with the configured AP.
static bool internal_c6_cam_join (c6_cam_lease_t *lease, const ra8_net_credentials_t *credentials)
 Join configured Wi-Fi and acquire a DHCP lease.
static bool internal_c6_cam_prepare_camera (void)
 Initialize the camera backend and prove one startup JPEG capture.
static bool internal_c6_cam_prepare_media (void)
 Initialize and self-test the audio and camera backends.
static void internal_c6_cam_worker_entry (ULONG input)
 Run the network, audio, camera, and HTTP worker workflow.
void tx_application_define (void *first_unused_memory)
int32_t c6_cam_app_run (void)
 Run the shared runtime-provisioned C6, DHCP, and HTTP application flow.

Variables

static uint32_t s_cpuclk_hz
static uint32_t s_pclka_hz
static ra8_err_t s_port_err = k_ra8_err_not_initialized
static TX_THREAD s_worker
static CHAR s_worker_name [] = "c6_cam_stream"
static UCHAR s_worker_stack [k_c6_cam_worker_stack]
static uint8_t s_arena [k_c6_cam_arena_bytes]
static ra8_c6link_t s_link
static volatile uint32_t s_events
static volatile uint8_t s_connected
static volatile uint8_t s_disconnected
static volatile uint16_t s_disconnect_reason
static const ra8_net_provision_uart_t s_provision_uart
 Board-console binding for the shared runtime provisioner.

Detailed Description

Shared C6 camera-stream application workflow.

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

Initializes external SDRAM for camera storage, joins Wi-Fi through the bench-validated raw ra8_c6link sequence, obtains a NetX DHCP lease, then serves the selected camera backend on TCP port 80. Each camera example supplies its own local main.c and camera backend while reusing this flow.

Since
0.1.0

Definition in file c6_cam_app.c.

Function Documentation

◆ c6_cam_app_run()

int32_t c6_cam_app_run ( void )
nodiscard

Run the shared runtime-provisioned C6, DHCP, and HTTP application flow.

Definition at line 498 of file c6_cam_app.c.

References c6_cam_puts(), internal_c6_cam_halt(), internal_c6_cam_setup_or_halt(), and ra8_isr_globals_enable().

Referenced by main().

◆ internal_c6_cam_associate()

bool internal_c6_cam_associate ( ra8_c6link_mac_t * mac,
const ra8_net_credentials_t * credentials )
static

Start station mode and associate with the configured AP.

Starts Wi-Fi, reads the station MAC, applies the supplied runtime credentials, joins, and waits for the association result.

Parameters
[out]macDestination for the bound station MAC address.
[in]credentialsValidated runtime credential record.
Returns
Association outcome.
Return values
trueWi-Fi control and association completed.
falseCredentials, control, or association failed.
Precondition
s_link is open and ready for Wi-Fi commands.
mac points to writable storage.
Postcondition
On success, *mac holds the station MAC address.
Failure diagnostics identify the stage or association reason.
Note
The caller erases credentials immediately after this synchronous use.
Since
0.1.0

Definition at line 266 of file c6_cam_app.c.

References c6_cam_put_u32(), c6_cam_puts(), internal_c6_cam_report_fault(), internal_c6_cam_wait_connected(), k_ra8_ok, ra8_net_credentials::psk, ra8_c6link_sta_cfg_set(), ra8_c6link_wifi_join(), ra8_c6link_wifi_mac(), ra8_c6link_wifi_start(), RA8_INTERNAL, ra8_secure_memzero(), s_connected, s_disconnect_reason, s_disconnected, s_events, s_link, and ra8_net_credentials::ssid.

Referenced by internal_c6_cam_join().

◆ internal_c6_cam_halt()

void internal_c6_cam_halt ( void )
static

Park the application after a terminal failure.

Repeatedly waits for interrupt and never returns to the failed workflow.

Precondition
A terminal condition has been diagnosed or the server has returned unexpectedly.
Interrupt state is suitable for the application terminal state.
Postcondition
No further workflow stage executes.
Static application state remains available to a debugger.
Note
Only reset or debugger intervention terminates the loop.
Since
0.1.0

Definition at line 66 of file c6_cam_app.c.

References RA8_INTERNAL.

Referenced by c6_cam_app_run(), internal_c6_cam_setup_or_halt(), and internal_c6_cam_worker_entry().

◆ internal_c6_cam_join()

bool internal_c6_cam_join ( c6_cam_lease_t * lease,
const ra8_net_credentials_t * credentials )
static

Join configured Wi-Fi and acquire a DHCP lease.

Associates with the configured AP, then binds NetX to the link.

Parameters
[out]leaseDestination for the bound network lease.
[in]credentialsValidated runtime credential record.
Returns
Join outcome.
Return values
trueAssociation and DHCP completed with a bound lease.
falseCredentials, control, association, or DHCP failed.
Precondition
s_link is open and ready for Wi-Fi commands.
lease points to writable storage.
Postcondition
On success, lease->bound is true and address fields are valid.
Failure diagnostics identify the stage or association reason.
Note
The caller retains and erases the record after this function returns.
Since
0.1.0

Definition at line 324 of file c6_cam_app.c.

References c6_cam_lease_t::bound, c6_cam_net_up(), c6_cam_puts(), internal_c6_cam_associate(), k_ra8_ok, ra8_err_to_str(), RA8_INTERNAL, and s_link.

Referenced by internal_c6_cam_worker_entry().

◆ internal_c6_cam_on_event()

void internal_c6_cam_on_event ( void * ctx,
const ra8_c6link_event_t * event )
static

Latch station connection events from the C6 link.

Counts every delivered event and records connected or disconnected state.

Parameters
[in,out]ctxUnused callback context.
[in]eventBorrowed event descriptor from the C6 link.
Precondition
Static event latches are writable.
The callback executes serially with C6 link polling.
Postcondition
Nonnull events increment the event count once.
Connection transitions update their corresponding latches.
Note
Boot and unrelated Wi-Fi events are counted without extra state.
Since
0.1.0

Definition at line 118 of file c6_cam_app.c.

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

Referenced by internal_c6_cam_open_link().

◆ internal_c6_cam_open_link()

ra8_err_t internal_c6_cam_open_link ( void )
static

Bind and open the raw ESP-hosted C6 link.

Supplies static arena storage plus event and NetX receive callbacks.

Returns
Repository error code.
Return values
k_ra8_okThe link opened successfully.
k_ra8_err_not_initializedThe ESP-hosted transport was unavailable.
Precondition
The ESP-hosted port configuration is available to its transport binder.
Static link and arena storage are not in use by another link.
Postcondition
On success, s_link owns the active transport session.
The arena remains statically allocated for the session lifetime.
Note
Transport or link-open errors are propagated unchanged.
Since
0.1.0

Definition at line 169 of file c6_cam_app.c.

References ra8_c6link_cfg::arena, ra8_c6link_cfg::arena_bytes, ra8_c6link_cfg::cb_ctx, ra8_c6link_cfg::event_cb, internal_c6_cam_on_event(), k_ra8_ok, nx_ether_driver_c6_rx(), ra8_c6link_open(), ra8_esp_hosted_c6link_bind(), RA8_INTERNAL, ra8_c6link_cfg::rx_cb, s_arena, s_link, and ra8_c6link_cfg::transport.

Referenced by internal_c6_cam_prepare_link().

◆ internal_c6_cam_prepare_camera()

bool internal_c6_cam_prepare_camera ( void )
static

Initialize the camera backend and prove one startup JPEG capture.

Runs after SDRAM and audio are already confirmed working, so a camera failure is never masked by an earlier media stage.

Returns
Whether camera initialization and the startup capture passed.
Return values
trueCamera initialization and one JPEG capture passed.
falseA diagnostic was emitted for the failing stage.
Precondition
SDRAM and audio initialization already passed.
No network server is using the camera backend.
Postcondition
On success, the camera is capture-ready.
On failure, the caller may halt without exposing an HTTP endpoint.
Note
The startup JPEG remains owned by the selected camera backend.
Since
0.1.0

Definition at line 356 of file c6_cam_app.c.

References c6_cam_camera_capture_jpeg(), c6_cam_camera_description(), c6_cam_camera_init(), c6_cam_camera_report_last_error(), c6_cam_put_u32(), c6_cam_puts(), c6_cam_frame_timing_t::capture_ms, k_ra8_ok, ra8_err_to_str(), and RA8_INTERNAL.

Referenced by internal_c6_cam_prepare_media().

◆ internal_c6_cam_prepare_link()

bool internal_c6_cam_prepare_link ( void )
static

Open the C6 link and await firmware readiness.

Reports link status and the coprocessor firmware version to SCI8.

Returns
Link readiness outcome.
Return values
trueThe link opened and the ready announcement arrived.
falseTransport open or ready negotiation failed.
Precondition
The ESP-hosted port initialization result is successful.
The diagnostic console is initialized.
Postcondition
On success, s_link is ready for Wi-Fi control commands.
Failures are reported before returning false.
Note
The caller decides whether failure is terminal.
Since
0.1.0

Definition at line 225 of file c6_cam_app.c.

References c6_cam_put_u32(), c6_cam_puts(), internal_c6_cam_open_link(), internal_c6_cam_report_fault(), k_ra8_c6link_announce_transfers, k_ra8_ok, ra8_c6link_fw_version::major, ra8_c6link_fw_version::minor, ra8_c6link_fw_version::patch, ra8_c6link_await_ready(), ra8_err_to_str(), RA8_INTERNAL, and s_link.

Referenced by internal_c6_cam_worker_entry().

◆ internal_c6_cam_prepare_media()

bool internal_c6_cam_prepare_media ( void )
static

Initialize and self-test the audio and camera backends.

Proves local media hardware before any Wi-Fi or DHCP dependency can mask a camera failure, while giving the C6 additional boot time.

Returns
Whether every media backend passed its startup contract.
Return values
trueSDRAM, audio, camera initialization, and one JPEG capture passed.
falseA diagnostic was emitted for the failing stage.
Precondition
ThreadX and the shared clock services are initialized.
No network server is using the media backends.
Postcondition
On success, audio streaming is active and the camera is capture-ready.
On failure, the caller may halt without exposing an HTTP endpoint.
Note
The startup JPEG remains owned by the selected camera backend.
Since
0.1.0

Definition at line 403 of file c6_cam_app.c.

References c6_cam_audio_start(), c6_cam_puts(), internal_c6_cam_prepare_camera(), k_ra8_ok, ra8_err_to_str(), RA8_INTERNAL, and ra8_sdramc_init().

Referenced by internal_c6_cam_worker_entry().

◆ internal_c6_cam_report_fault()

void internal_c6_cam_report_fault ( const char * stage,
ra8_err_t err )
static

Emit one standardized application failure line.

Combines a stage label with the repository error string on SCI8.

Parameters
[in]stageNUL-terminated failing-stage name.
[in]errRepository error code to describe.
Precondition
stage is nonnull and bounded for c6_cam_puts.
The diagnostic console is initialized.
Postcondition
One complete failure line is queued.
Application workflow state remains unchanged.
Note
This helper does not halt the caller.
Since
0.1.0

Definition at line 147 of file c6_cam_app.c.

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

Referenced by internal_c6_cam_associate(), internal_c6_cam_prepare_link(), and internal_c6_cam_worker_entry().

◆ internal_c6_cam_setup_or_halt()

void internal_c6_cam_setup_or_halt ( void )
static

Initialize shared clocks, services, and the diagnostic console.

Performs ordered CGC, MSTP, ISR, timebase, and UART initialization.

Precondition
Startup initialized data, BSS, vector state, and the CPU clock source.
Called from the single-threaded application entry path.
Postcondition
On success, clock globals and the diagnostic console are ready.
Any initialization failure transfers permanently to internal_c6_cam_halt.
Note
ThreadX has not started when this function runs.
Since
0.1.0

Definition at line 83 of file c6_cam_app.c.

References c6_cam_puts(), ra8_board_clock_rates_t::cpuclk0_hz, internal_c6_cam_halt(), k_c6_cam_uart_baud, k_ra8_ok, ra8_board_clock_rates_t::pclka_hz, ra8_board_clocks_init(), ra8_board_uart_console_init(), RA8_INTERNAL, ra8_isr_init(), ra8_mstp_init(), ra8_time_init(), s_cpuclk_hz, and s_pclka_hz.

Referenced by c6_cam_app_run().

◆ internal_c6_cam_wait_connected()

bool internal_c6_cam_wait_connected ( void )
static

Poll for a station association result.

Services C6 transfers between bounded sleeps until connected, disconnected, or timed out.

Returns
Association outcome.
Return values
trueA station-connected event was observed.
falseDisconnection or the poll budget ended first.
Precondition
s_link is open and Wi-Fi join was requested.
ThreadX timing services are running.
Postcondition
All observed C6 events have been dispatched through the event callback.
The function returns within the configured poll budget.
Note
Poll transport errors are ignored while event latches determine the result.
Since
0.1.0

Definition at line 197 of file c6_cam_app.c.

References k_c6_cam_assoc_gap_ms, k_c6_cam_assoc_polls, k_ra8_c6link_announce_transfers, ra8_c6link_poll(), RA8_INTERNAL, s_connected, s_disconnected, s_link, and tx_thread_sleep.

Referenced by internal_c6_cam_associate().

◆ internal_c6_cam_worker_entry()

void internal_c6_cam_worker_entry ( ULONG input)
static

Run the network, audio, camera, and HTTP worker workflow.

Validates local media, joins Wi-Fi, then serves HTTP.

Parameters
[in]inputThreadX entry parameter, unused by this worker.
Precondition
ThreadX created the worker with its static stack.
tx_application_define stored the ESP-hosted port result.
Postcondition
On success, control transfers permanently to the HTTP server.
Any failure emits a diagnostic and parks the worker.
Note
All persistent buffers are static or caller-owned.
Since
0.1.0

Definition at line 432 of file c6_cam_app.c.

References c6_cam_http_serve(), c6_cam_put_ip(), c6_cam_puts(), internal_c6_cam_halt(), internal_c6_cam_join(), internal_c6_cam_prepare_link(), internal_c6_cam_prepare_media(), internal_c6_cam_report_fault(), c6_cam_lease_t::ip, k_c6_cam_boot_wait_ms, k_ra8_net_provision_timeout_ms, k_ra8_ok, ra8_delay_ms(), ra8_err_to_str(), RA8_INTERNAL, ra8_net_provision_clear(), ra8_net_provision_receive(), s_port_err, and s_provision_uart.

Referenced by tx_application_define().

◆ tx_application_define()

Variable Documentation

◆ s_arena

◆ s_connected

◆ s_cpuclk_hz

uint32_t s_cpuclk_hz
static

◆ s_disconnect_reason

volatile uint16_t s_disconnect_reason
static

Definition at line 48 of file c6_cam_app.c.

Referenced by internal_c6_cam_associate(), and internal_c6_cam_on_event().

◆ s_disconnected

◆ s_events

volatile uint32_t s_events
static

◆ s_link

◆ s_pclka_hz

◆ s_port_err

ra8_err_t s_port_err = k_ra8_err_not_initialized
static

Definition at line 39 of file c6_cam_app.c.

Referenced by internal_c6_cam_worker_entry(), internal_run(), and tx_application_define().

◆ 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.

Since
0.1.0

Definition at line 50 of file c6_cam_app.c.

Referenced by c6_join_worker_entry(), internal_c6_cam_worker_entry(), internal_worker(), and wifi_hal_worker_entry().

◆ s_worker

TX_THREAD s_worker
static

Definition at line 40 of file c6_cam_app.c.

Referenced by tx_application_define().

◆ s_worker_name

CHAR s_worker_name[] = "c6_cam_stream"
static

Definition at line 41 of file c6_cam_app.c.

Referenced by tx_application_define().

◆ s_worker_stack

UCHAR s_worker_stack[k_c6_cam_worker_stack]
static

Definition at line 42 of file c6_cam_app.c.

Referenced by tx_application_define().