|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
OV5640 parallel (CEU) camera capture + plausibility self-test. More...
#include <stdint.h>#include "cam_ceu.h"#include "cam_image.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_camera.h"#include "ra8_camera_source_ceu.h"#include "ra8_ceu.h"#include "ra8_cgc.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_gpt.h"#include "ra8_i2c.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_ov5640.h"#include "ra8_port_utils.h"#include "ra8_sdramc.h"#include "ra8_time.h"Go to the source code of this file.
Enumerations | |
| enum | cam_u32_t : uint32_t { k_cam_baud = 115200U , k_cam_xclk_hz = 24000000U , k_cam_mode_settle_ms = 100U , k_cam_capture_poll_ms = 5U , k_cam_capture_tries = 800U , k_cam_cache_line = 32U , k_cam_string_cap = 1024U , k_cam_dec_cap = 99999999U , k_cam_gpt_probe_iters = 64U } |
| Scalar app tunables (baud, clocks, GPT limits, decimal cap). More... | |
| enum | cam_u8_t : uint8_t { k_cam_nibble_mask = 0x0FU , k_cam_dec_base = 10U , k_cam_byte_max = 0xFFU , k_cam_scan_lo = 0x08U , k_cam_scan_hi = 0x77U } |
| 8-bit app constants: hex/decimal printing, bus scan, U15 expander. More... | |
| enum | cam_capture_geom_t : uint16_t { k_cam_line_bytes = 1280U } |
| Packed VGA UYVY CEU geometry. More... | |
| enum | cam_capture_layout_t : uint8_t { k_cam_bytes_per_pixel = 2U } |
| Packed VGA UYVY storage layout. More... | |
| enum | cam_gpt_t : uint8_t { k_cam_xclk_gpt_ch = 12U } |
| GPT channel that generates XCLK on GTIOC12A (P501). More... | |
Functions | |
| static ra8_err_t | cam_sensor_bind (void) |
| Bind the reusable sensor driver to the EK-RA8D2 SCCB adapter. | |
| static ra8_err_t | cam_capture_source_bind (void) |
| Bind the generic CEU source to app-owned state and VGA metadata. | |
| static uint32_t | cam_strlen (const char *s) |
| Bounded length of a NUL-terminated C string. | |
| static ra8_err_t | cam_puts (const char *s) |
| Write a NUL-terminated string to the SCI8 console. | |
| static ra8_err_t | cam_put_hex (uint32_t value, uint8_t width) |
| Write width hex nibbles of value (big-endian) to the console. | |
| static ra8_err_t | cam_put_u32 (uint32_t value) |
| Write an unsigned decimal integer to the console. | |
| static bool | cam_frame_is_plausible (const ra8_camera_frame_t *frame) |
| Compute min / max / mean over the CEU frame and store to globals. | |
| static void | cam_bus_scan (void) |
| Probe every 7-bit I2C address on ch1 and print those that ACK. | |
| static void | cam_park (void) |
| Park forever after the self-test has reported its verdict. | |
| static ra8_err_t | cam_bringup (void) |
| Bring up clocks, console, SDRAM, XCLK, SCCB and parallel camera. | |
| static void | cam_print_hsync_probe (const cam_ceu_sync_probe_t *probe) |
| Print horizontal-sync pulse diagnostics. | |
| static void | cam_print_data_probe (const cam_ceu_sync_probe_t *probe) |
| Print pixel-clock and sampled data diagnostics. | |
| static void | cam_print_line_probe (const cam_ceu_sync_probe_t *probe) |
| Print per-line pixel-clock diagnostics. | |
| static void | cam_print_sync_probe (const cam_ceu_sync_probe_t *probe) |
| Print the complete GPIO-observed DVP diagnostic snapshot. | |
| static ra8_err_t | cam_prepare_capture (void) |
| Configure the sensor, sample DVP, and prepare the CEU. | |
| static bool | cam_capture_frame_and_report (bool ready) |
| Attempt one frame capture and print CEU completion diagnostics. | |
| static void | cam_finish_verdict (bool frame_ok) |
| Validate, convert, and report the completed camera frame. | |
| static void | cam_capture_and_verdict (void) |
| Configure the sensor, capture one frame, and print the verdict. | |
| static void | cam_run (void) |
| Run the capture pipeline and emit the plausibility banner. | |
| void | main (void) |
| Application entry: OV5640 CEU capture plausibility self-test. | |
Variables | |
| volatile uint32_t | g_cam_chipid = 0U |
| Chip ID read over SCCB (0x300A<<8 | 0x300B). | |
| volatile uint32_t | g_cam_frame_ok = 0U |
| 1 when the CEU signalled a completed capture, else 0. | |
| volatile uint32_t | g_cam_min = 0U |
| Minimum byte value across the captured frame. | |
| volatile uint32_t | g_cam_max = 0U |
| Maximum byte value across the captured frame. | |
| volatile uint32_t | g_cam_mean = 0U |
| Mean byte value across the captured frame. | |
| volatile uint32_t | g_cam_verdict = 0U |
| 1 = plausible camera frame (PASS), 0 = FAIL. | |
| static const uint8_t | k_cam_tag [] = "cam: " |
| Console tag prefix for every banner line. | |
| static ra8_ov5640_t | s_camera_sensor |
| Transport-independent sensor instance bound to the board SCCB adapter. | |
| static ra8_camera_source_t | s_camera_source |
| Generic CEU source handle and caller-owned backend state. | |
| static ra8_camera_source_ceu_state_t | s_camera_source_state |
| static ra8_camera_frame_t | s_camera_frame |
| Last immutable frame view returned by the generic source. | |
| static uint8_t | s_camera_capture [k_cam_uyvy_frame_bytes] |
| App-owned, cache-line-aligned target for one packed VGA capture. | |
OV5640 parallel (CEU) camera capture + plausibility self-test.
End-to-end bring-up of the EK-RA8D2 on-board OV5640 5 MP CMOS sensor over the chip's Capture Engine Unit (CEU) parallel (DVP) path – the interface the board wires the camera to (connector J35, HUM Ch 60). The app drives the real HAL drivers with no fakes and reports a plausibility verdict over the SCI8 console plus a set of J-Link-probable globals:
The reusable ra8_ov5640 sensor driver owns sensor protocol and tables; the board adapter owns J35 routing/reset/SCCB; ra8_camera_source_ceu owns generic capture dispatch. This file owns app policy, caller-supplied source state/storage, console output, and the verdict. cam_ceu is limited to the HIL-only pre-routing GPIO activity probe.
Banner (scraped by the HIL gate once promoted): cam: gpt=RUN scan=3C:56.43:00. chipid=5640 xclk=OK rst=OK sccb=OK ceu=OK bytes=614400 frame=OK cetcr=........ min=.. max=.. mean=.. verdict=PASS
Hardware: EK-RA8D2 with the OV5640 Camera Expansion Board on the underside FFC port (J35). SW4-6 is driven ON in firmware; no manual jumpers required.
Definition in file main.c.
| enum cam_capture_geom_t : uint16_t |
| enum cam_capture_layout_t : uint8_t |
| enum cam_gpt_t : uint8_t |
| enum cam_u32_t : uint32_t |
Scalar app tunables (baud, clocks, GPT limits, decimal cap).
| enum cam_u8_t : uint8_t |
8-bit app constants: hex/decimal printing, bus scan, U15 expander.
|
static |
Bring up clocks, console, SDRAM, XCLK, SCCB and parallel camera.
Initializes dependencies in order, starts the sensor clock, and selects the U15 parallel-camera route without overwriting unrelated bits.
| k_ra8_ok | Console, SDRAM, XCLK, and the U15 DVP route are live. |
Definition at line 511 of file main.c.
References k_cam_baud, k_cam_mode_settle_ms, k_cam_xclk_hz, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_camera_select_parallel(), ra8_board_camera_xclk_start(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_delay_ms(), ra8_mstp_init(), ra8_sdramc_init(), and ra8_time_init().
Referenced by main().
|
static |
Probe every 7-bit I2C address on ch1 and print those that ACK.
A discovery aid: emits scan=3C.43. so the bench log shows exactly which devices answer on the SCCB bus (the OV5640 at 0x3C/0x3D, the U15 expander at 0x43, ...). Address-only probes, no register access.
Definition at line 453 of file main.c.
References cam_put_hex(), cam_puts(), k_cam_scan_hi, k_cam_scan_lo, k_ra8_board_camera_i2c_channel, k_ra8_ok, ra8_i2c_scan(), and ra8_i2c_transfer().
Referenced by cam_run().
|
static |
Configure the sensor, capture one frame, and print the verdict.
Called only after the OV5640 chip ID is confirmed. Emits the the DVP probe, CEU status, byte count, frame statistics, and verdict banner fields. PASS also requires all four RGB SDRAM views.
Definition at line 770 of file main.c.
References cam_capture_frame_and_report(), cam_finish_verdict(), cam_prepare_capture(), and k_ra8_ok.
Referenced by cam_run().
|
static |
Attempt one frame capture and print CEU completion diagnostics.
| [in] | ready | Whether CEU preparation completed successfully. |
| true | CEU capture completed. |
| false | Preparation failed or capture timed out. |
Definition at line 697 of file main.c.
References cam_put_hex(), cam_put_u32(), cam_puts(), g_cam_frame_ok, k_ra8_ok, ra8_camera_source_capture(), ra8_camera_source_ceu_get_last_events(), s_camera_capture, s_camera_frame, s_camera_source, and s_camera_source_state.
Referenced by cam_capture_and_verdict().
|
static |
Bind the generic CEU source to app-owned state and VGA metadata.
Configures a single-shot 8-bit synchronous UYVY capture with fixed VGA geometry and bounded polling.
| k_ra8_ok | The generic source is ready. |
| k_ra8_err_null_ptr | Internal source bindings were invalid. |
Definition at line 210 of file main.c.
References k_cam_bytes_per_pixel, k_cam_capture_poll_ms, k_cam_capture_tries, k_cam_image_height_px, k_cam_image_width_px, k_cam_line_bytes, k_cam_uyvy_frame_bytes, k_ra8_camera_format_uyvy422, k_ra8_ceu_burst_32, k_ra8_ceu_bus_8_bit, k_ra8_ceu_capture_single, k_ra8_ceu_edge_rising, k_ra8_ceu_field_immediate, k_ra8_ceu_fmt_data_synchronous, k_ra8_ceu_input_cb0_y0_cr0_y1, k_ra8_ceu_output_ycbcr_422, k_ra8_ceu_pol_high_active, ra8_camera_source_ceu_init(), s_camera_source, and s_camera_source_state.
Referenced by cam_prepare_capture().
|
static |
Validate, convert, and report the completed camera frame.
| [in] | frame_ok | Whether CEU capture completed. |
Definition at line 732 of file main.c.
References cam_frame_is_plausible(), cam_image_generate(), cam_put_u32(), cam_puts(), g_cam_max, g_cam_mean, g_cam_min, g_cam_rgb_frame_bytes, g_cam_verdict, k_ra8_ok, and s_camera_frame.
Referenced by cam_capture_and_verdict().
|
static |
Compute min / max / mean over the CEU frame and store to globals.
Validates the expected VGA UYVY geometry before reducing all bytes into simple non-degeneracy statistics for the HIL verdict.
| true | Frame varies, consistent with a live non-degenerate capture. |
| false | Frame is all-identical, empty, or the buffer was unavailable. |
| [in] | frame | Completed generic-camera frame view. |
frame was returned by ra8_camera_source_capture. Definition at line 397 of file main.c.
References ra8_camera_frame_t::bytes, ra8_camera_frame_t::data, ra8_camera_frame_t::format, g_cam_max, g_cam_mean, g_cam_min, ra8_camera_frame_t::height, k_cam_byte_max, k_cam_image_height_px, k_cam_image_width_px, k_cam_line_bytes, k_cam_uyvy_frame_bytes, k_ra8_camera_format_uyvy422, ra8_camera_frame_t::stride_bytes, and ra8_camera_frame_t::width.
Referenced by cam_finish_verdict().
|
static |
Park forever after the self-test has reported its verdict.
Repeatedly enters wait-for-interrupt without returning to startup code.
Definition at line 490 of file main.c.
Referenced by main().
|
static |
Configure the sensor, sample DVP, and prepare the CEU.
| k_ra8_ok | Sensor, pin routing, and CEU are ready. |
Definition at line 663 of file main.c.
References cam_capture_source_bind(), cam_print_sync_probe(), cam_probe_sync_activity(), cam_puts(), k_ra8_ok, k_ra8_ov5640_mode_vga_uyvy, ra8_board_camera_route_parallel_pins(), ra8_ov5640_configure(), s_camera_frame, and s_camera_sensor.
Referenced by cam_capture_and_verdict().
|
static |
Print pixel-clock and sampled data diagnostics.
| [in] | probe | Completed DVP sync/data probe. |
Definition at line 586 of file main.c.
References cam_put_hex(), cam_put_u32(), cam_puts(), cam_ceu_sync_probe_t::data_and, cam_ceu_sync_probe_t::data_changes, cam_ceu_sync_probe_t::data_max, cam_ceu_sync_probe_t::data_min, cam_ceu_sync_probe_t::data_or, cam_ceu_sync_probe_t::data_samples, cam_ceu_sync_probe_t::pclk_edges, and cam_ceu_sync_probe_t::pclk_half_cycles_min.
Referenced by cam_print_sync_probe().
|
static |
Print horizontal-sync pulse diagnostics.
| [in] | probe | Completed DVP sync/data probe. |
Definition at line 561 of file main.c.
References cam_put_u32(), cam_puts(), cam_ceu_sync_probe_t::hsync_high_cycles_max, cam_ceu_sync_probe_t::hsync_high_cycles_min, cam_ceu_sync_probe_t::hsync_high_max, cam_ceu_sync_probe_t::hsync_high_min, cam_ceu_sync_probe_t::hsync_low_max, and cam_ceu_sync_probe_t::hsync_low_min.
Referenced by cam_print_sync_probe().
|
static |
Print per-line pixel-clock diagnostics.
| [in] | probe | Completed DVP sync/data probe. |
Definition at line 615 of file main.c.
References cam_put_u32(), cam_puts(), cam_ceu_sync_probe_t::line_pclk_long, cam_ceu_sync_probe_t::line_pclk_max, cam_ceu_sync_probe_t::line_pclk_mean, cam_ceu_sync_probe_t::line_pclk_min, and cam_ceu_sync_probe_t::measured_lines.
Referenced by cam_print_sync_probe().
|
static |
Print the complete GPIO-observed DVP diagnostic snapshot.
| [in] | probe | Completed DVP sync/data probe. |
Definition at line 640 of file main.c.
References cam_print_data_probe(), cam_print_hsync_probe(), cam_print_line_probe(), cam_put_u32(), cam_puts(), cam_ceu_sync_probe_t::hsync_edges, and cam_ceu_sync_probe_t::vsync_edges.
Referenced by cam_prepare_capture().
|
static |
Write width hex nibbles of value (big-endian) to the console.
Formats uppercase hexadecimal into fixed stack storage before one write.
| [in] | value | Value to print. |
| [in] | width | Number of nibbles (1..8). |
| k_ra8_ok | Digits queued. |
| k_ra8_err_invalid_arg | width out of 1..8. |
Definition at line 328 of file main.c.
References k_cam_nibble_mask, k_ra8_err_invalid_arg, ra8_board_uart_console_write(), and RA8_CHECK_RANGE.
Referenced by cam_bus_scan(), cam_capture_frame_and_report(), cam_print_data_probe(), and cam_run().
|
static |
Write an unsigned decimal integer to the console.
Formats the value backward into fixed stack storage before one write.
| [in] | value | Value to print (0..99999999). |
| k_ra8_ok | Digits queued. |
| k_ra8_err_invalid_arg | value exceeds 8 decimal digits. |
Definition at line 358 of file main.c.
References k_cam_dec_base, k_cam_dec_cap, k_ra8_err_invalid_arg, and ra8_board_uart_console_write().
Referenced by cam_capture_frame_and_report(), cam_finish_verdict(), cam_print_data_probe(), cam_print_hsync_probe(), cam_print_line_probe(), and cam_print_sync_probe().
|
static |
Write a NUL-terminated string to the SCI8 console.
Measures the bounded string and forwards its bytes to the board console.
| [in] | s | Non-NULL C string. |
| k_ra8_ok | String queued. |
| k_ra8_err_null_ptr | s was NULL. |
Definition at line 305 of file main.c.
References cam_strlen(), ra8_board_uart_console_write(), and RA8_CHECK_NULL_PTR.
Referenced by cam_bus_scan(), cam_capture_frame_and_report(), cam_finish_verdict(), cam_prepare_capture(), cam_print_data_probe(), cam_print_hsync_probe(), cam_print_line_probe(), cam_print_sync_probe(), cam_run(), and main().
|
static |
Run the capture pipeline and emit the plausibility banner.
Reports progressively so a single flash reveals exactly which stage the hardware reached. The verdict is PASS only when the sensor ID is 0x5640, a frame was captured, it is non-degenerate, and the four RGB SDRAM views are complete.
Definition at line 792 of file main.c.
References cam_bus_scan(), cam_capture_and_verdict(), cam_put_hex(), cam_puts(), cam_sensor_bind(), g_cam_chipid, k_cam_gpt_probe_iters, k_cam_tag, k_cam_xclk_gpt_ch, k_ra8_ok, ra8_board_camera_reset(), ra8_gpt_read(), ra8_ov5640_probe(), and s_camera_sensor.
Referenced by main().
|
static |
Bind the reusable sensor driver to the EK-RA8D2 SCCB adapter.
Constructs a transport over board-owned SCCB and delay callbacks.
| k_ra8_ok | The sensor instance was initialized. |
| k_ra8_err_null_ptr | A required transport callback was unavailable. |
Definition at line 185 of file main.c.
References ra8_board_camera_delay_ms(), ra8_board_camera_sccb_read_reg(), ra8_board_camera_sccb_write_reg(), ra8_ov5640_init(), and s_camera_sensor.
Referenced by cam_run().
|
static |
Bounded length of a NUL-terminated C string.
Scans at most k_cam_string_cap bytes to keep console helpers bounded.
| [in] | s | Non-NULL C string. |
| uint32_t | Number of bytes preceding NUL or the configured cap. |
Definition at line 280 of file main.c.
References k_cam_string_cap, and RA8_CHECK_NULL_PTR.
Referenced by cam_puts().
| void main | ( | void | ) |
Application entry: OV5640 CEU capture plausibility self-test.
The application entry point Reset_Handler hands control to.
Definition at line 853 of file main.c.
References cam_bringup(), cam_park(), cam_puts(), cam_run(), k_ra8_ok, and ra8_isr_globals_enable().
| volatile uint32_t g_cam_chipid = 0U |
| volatile uint32_t g_cam_frame_ok = 0U |
1 when the CEU signalled a completed capture, else 0.
Definition at line 138 of file main.c.
Referenced by cam_capture_frame_and_report().
| volatile uint32_t g_cam_max = 0U |
Maximum byte value across the captured frame.
Definition at line 146 of file main.c.
Referenced by cam_finish_verdict(), and cam_frame_is_plausible().
| volatile uint32_t g_cam_mean = 0U |
Mean byte value across the captured frame.
Definition at line 150 of file main.c.
Referenced by cam_finish_verdict(), and cam_frame_is_plausible().
| volatile uint32_t g_cam_min = 0U |
Minimum byte value across the captured frame.
Definition at line 142 of file main.c.
Referenced by cam_finish_verdict(), and cam_frame_is_plausible().
| volatile uint32_t g_cam_verdict = 0U |
1 = plausible camera frame (PASS), 0 = FAIL.
Definition at line 154 of file main.c.
Referenced by cam_finish_verdict().
|
static |
|
static |
App-owned, cache-line-aligned target for one packed VGA capture.
Definition at line 170 of file main.c.
Referenced by cam_capture_frame_and_report().
|
static |
Last immutable frame view returned by the generic source.
Definition at line 167 of file main.c.
Referenced by cam_capture_frame_and_report(), cam_finish_verdict(), and cam_prepare_capture().
|
static |
|
static |
Generic CEU source handle and caller-owned backend state.
Definition at line 163 of file main.c.
Referenced by cam_capture_frame_and_report(), and cam_capture_source_bind().
|
static |
Definition at line 164 of file main.c.
Referenced by cam_capture_frame_and_report(), and cam_capture_source_bind().