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

GPIO activity diagnostic for the J35 parallel DVP camera signals. More...

#include "cam_ceu.h"
#include <stdint.h>
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_port_regs.h"
#include "ra8_port_utils.h"
#include "ra8_systick.h"
Include dependency graph for cam_ceu.c:

Go to the source code of this file.

Data Structures

struct  cam_ceu_pin_t
 One CEU DVP pin: MCU port/pin routed to the CEU peripheral. More...
struct  cam_probe_ports_t
 GPIO register banks used while sampling the parallel camera bus. More...
struct  cam_sync_state_t
 Accumulator for the bounded sync/data sampling pass. More...

Enumerations

enum  cam_ceu_poll_t : uint32_t {
  k_cam_sync_samples = 2000000U ,
  k_cam_data_d2_pin_bit = 5U ,
  k_cam_data_d5_out_bit = 5U ,
  k_cam_data_d7_out_bit = 7U ,
  k_cam_long_line_pclk = 1024U
}
 Bounded GPIO signal-activity sampling constants. More...

Functions

static void cam_release_probe_pins (uint32_t count)
 Release a bounded prefix of the temporary camera GPIO claims.
static ra8_err_t cam_claim_probe_pins (void)
 Claim every parallel-camera pin as a temporary GPIO input.
static ra8_err_t cam_get_probe_ports (cam_probe_ports_t *ports)
 Resolve the four register banks that carry the camera signals.
static uint8_t cam_read_probe_data (const cam_probe_ports_t *ports)
 Reconstruct VIO_D[7:0] from the three GPIO input banks.
static uint32_t cam_read_probe_sync (const cam_probe_ports_t *ports, uint32_t sync_mask)
 Read and mask the three camera sync signals from PORT11.
static void cam_sync_state_init (cam_sync_state_t *state, uint32_t prior)
 Initialize sync-sampling state from the first masked sample.
static void cam_record_probe_data (cam_sync_state_t *state, cam_ceu_sync_probe_t *probe, uint8_t data)
 Fold one active-line camera byte into the probe statistics.
static void cam_record_sync_sample (const cam_probe_ports_t *ports, uint32_t current, cam_sync_state_t *state, cam_ceu_sync_probe_t *probe)
 Fold one masked sync sample into edge, timing, and data statistics.
static void cam_measure_sync (const cam_probe_ports_t *ports, uint32_t sync_mask, cam_ceu_sync_probe_t *probe)
 Run the bounded sync/data sampling pass and finalize its statistics.
static void cam_measure_lines (const cam_probe_ports_t *ports, uint32_t sync_mask, cam_ceu_sync_probe_t *probe)
 Measure active-line PCLK counts with three bounded sampling loops.
ra8_err_t cam_probe_sync_activity (cam_ceu_sync_probe_t *out_probe)
 Measure DVP sync, clock, and data activity before CEU routing.

Variables

static const cam_ceu_pin_t s_ceu_pins []
 The 11 EK-RA8D2 J35 parallel-camera pins that feed the CEU: VIO_D[7:0], VIO_VD, VIO_HD, VIO_CLK (EK-RA8D2 UM Table 35 p 48).

Detailed Description

GPIO activity diagnostic for the J35 parallel DVP camera signals.

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

Owns only the 11-entry GPIO pin map and bounded signal-activity sampler used by the HIL diagnostics. The reusable ra8_camera_source_ceu backend owns CEU dispatch while the application supplies its state and DMA buffer.

Since
0.1.0

Definition in file cam_ceu.c.

Enumeration Type Documentation

◆ cam_ceu_poll_t

enum cam_ceu_poll_t : uint32_t

Bounded GPIO signal-activity sampling constants.

Enumerator
k_cam_sync_samples 

GPIO samples for live-sync diagnostic.

k_cam_data_d2_pin_bit 

P405 bit position for camera D2.

k_cam_data_d5_out_bit 

Reconstructed byte bit for camera D5.

k_cam_data_d7_out_bit 

Reconstructed byte bit for camera D7.

k_cam_long_line_pclk 

Diagnostic threshold for long HREF lines.

Definition at line 34 of file cam_ceu.c.

Function Documentation

◆ cam_claim_probe_pins()

ra8_err_t cam_claim_probe_pins ( void )
static

Claim every parallel-camera pin as a temporary GPIO input.

Returns
Error status from the claim sequence.
Return values
k_ra8_okEvery camera pin is configured as an input.
k_ra8_err_gpio_conflictA pin could not be claimed.
Precondition
The CEU has not claimed the parallel-camera pins.
GPIO ownership tracking is initialized.
Postcondition
Success leaves every camera pin claimed as an input.
Failure releases every pin claimed by this call.
Note
Thread safety: init context only.
Since
0.1.0

Definition at line 128 of file cam_ceu.c.

References cam_release_probe_pins(), k_ra8_err_gpio_conflict, k_ra8_ok, k_ra8_pull_none, pin, ra8_gpio_input_init(), RA8_PIN, and s_ceu_pins.

Referenced by cam_probe_sync_activity().

◆ cam_get_probe_ports()

ra8_err_t cam_get_probe_ports ( cam_probe_ports_t * ports)
static

Resolve the four register banks that carry the camera signals.

Parameters
[out]portsReceives non-NULL register-bank pointers.
Returns
Error status from register-bank resolution.
Return values
k_ra8_okEvery required bank is addressable.
k_ra8_err_hw_errorA required bank is unavailable.
k_ra8_err_null_ptrports was NULL.
Precondition
ports is non-NULL.
The GPIO register layer is initialized.
Postcondition
Success fills all four bank pointers.
Failure does not dereference an unavailable bank.
Note
Thread safety: pure register-address resolution.
Since
0.1.0

Definition at line 157 of file cam_ceu.c.

References k_ra8_err_hw_error, k_ra8_ok, k_ra8_port_11, k_ra8_port_4, k_ra8_port_7, k_ra8_port_9, cam_probe_ports_t::port11, cam_probe_ports_t::port4, cam_probe_ports_t::port7, cam_probe_ports_t::port9, RA8_CHECK_NULL_PTR, and ra8_port().

Referenced by cam_probe_sync_activity().

◆ cam_measure_lines()

void cam_measure_lines ( const cam_probe_ports_t * ports,
uint32_t sync_mask,
cam_ceu_sync_probe_t * probe )
static

Measure active-line PCLK counts with three bounded sampling loops.

Parameters
[in]portsResolved camera GPIO banks.
[in]sync_maskMask covering VSYNC, HSYNC, and PCLK.
[in,out]probeProbe result to populate.
Precondition
All pointers are valid and camera GPIOs are claimed.
The sensor is configured for continuous DVP streaming.
Postcondition
Line-count fields describe only complete observed HSYNC pulses.
A missing line produces zero-valued minimum and mean fields.
Note
Thread safety: not thread-safe; reads live GPIO state.
Since
0.1.0

Definition at line 381 of file cam_ceu.c.

References cam_read_probe_sync(), k_cam_long_line_pclk, k_cam_sync_samples, k_ra8_pin_3, k_ra8_pin_4, 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_probe_sync_activity().

◆ cam_measure_sync()

void cam_measure_sync ( const cam_probe_ports_t * ports,
uint32_t sync_mask,
cam_ceu_sync_probe_t * probe )
static

Run the bounded sync/data sampling pass and finalize its statistics.

Parameters
[in]portsResolved camera GPIO banks.
[in]sync_maskMask covering VSYNC, HSYNC, and PCLK.
[in,out]probeProbe result to populate.
Precondition
All pointers are valid and camera GPIOs are claimed.
sync_mask selects the three camera sync signals.
Postcondition
probe contains bounded edge, run, timing, and data statistics.
Sentinel minima are converted to zero when no sample was observed.
Note
Thread safety: not thread-safe; reads live GPIO state.
Since
0.1.0

Definition at line 345 of file cam_ceu.c.

References cam_read_probe_sync(), cam_record_sync_sample(), cam_sync_state_init(), cam_ceu_sync_probe_t::data_and, cam_sync_state_t::data_and, cam_ceu_sync_probe_t::data_max, cam_sync_state_t::data_max, cam_ceu_sync_probe_t::data_min, cam_sync_state_t::data_min, cam_ceu_sync_probe_t::data_or, cam_sync_state_t::data_or, cam_ceu_sync_probe_t::data_samples, cam_sync_state_t::high_cycles_max, cam_sync_state_t::high_cycles_min, cam_sync_state_t::high_max, cam_sync_state_t::high_min, 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, cam_ceu_sync_probe_t::hsync_low_min, k_cam_sync_samples, cam_sync_state_t::low_max, cam_sync_state_t::low_min, and cam_ceu_sync_probe_t::pclk_half_cycles_min.

Referenced by cam_probe_sync_activity().

◆ cam_probe_sync_activity()

ra8_err_t cam_probe_sync_activity ( cam_ceu_sync_probe_t * out_probe)

Measure DVP sync, clock, and data activity before CEU routing.

Temporarily samples the camera connector as GPIO to characterize live sensor timing before the CEU peripheral claims the pins.

Parameters
[out]out_probeReceives observed sync transition counts.
Returns
ra8_err_t; ok when the GPIO sampling pass completed.
Return values
k_ra8_okSampling completed and populated out_probe.
k_ra8_err_null_ptrout_probe was null.
Precondition
The sensor is configured and streaming.
The DVP pins have not been claimed by ra8_board_camera_route_parallel_pins.
Postcondition
All temporary DVP GPIO claims are released.
out_probe contains bounded transition and data statistics on success.
Note
This diagnostic must run before parallel-pin routing.
Since
0.1.0

Definition at line 420 of file cam_ceu.c.

References cam_claim_probe_pins(), cam_get_probe_ports(), cam_measure_lines(), cam_measure_sync(), cam_release_probe_pins(), k_ra8_ok, k_ra8_pin_2, k_ra8_pin_3, k_ra8_pin_4, RA8_CHECK_NULL_PTR, and s_ceu_pins.

Referenced by cam_prepare_capture().

◆ cam_read_probe_data()

uint8_t cam_read_probe_data ( const cam_probe_ports_t * ports)
inlinestatic

Reconstruct VIO_D[7:0] from the three GPIO input banks.

Parameters
[in]portsResolved camera GPIO banks.
Returns
Current parallel-camera data byte.
Precondition
Every pointer in ports is valid.
Camera pins are configured as GPIO inputs.
Postcondition
The return value represents one coherent best-effort bus sample.
No GPIO register is modified.
Note
Thread safety: pure MMIO reads.
Since
0.1.0

Definition at line 186 of file cam_ceu.c.

References k_cam_data_d2_pin_bit, k_cam_data_d5_out_bit, k_cam_data_d7_out_bit, r_port_regs_t::PCNTR2, cam_probe_ports_t::port4, cam_probe_ports_t::port7, and cam_probe_ports_t::port9.

Referenced by cam_record_sync_sample().

◆ cam_read_probe_sync()

uint32_t cam_read_probe_sync ( const cam_probe_ports_t * ports,
uint32_t sync_mask )
inlinestatic

Read and mask the three camera sync signals from PORT11.

Parameters
[in]portsResolved camera GPIO banks.
[in]sync_maskMask covering VSYNC, HSYNC, and PCLK.
Returns
Current masked camera sync sample.
Precondition
ports->port11 is valid.
Camera sync pins are configured as GPIO inputs.
Postcondition
The returned value contains no bits outside sync_mask.
No GPIO register is modified.
Note
Thread safety: pure MMIO read.
Since
0.1.0

Definition at line 212 of file cam_ceu.c.

References r_port_regs_t::PCNTR2, and cam_probe_ports_t::port11.

Referenced by cam_measure_lines(), and cam_measure_sync().

◆ cam_record_probe_data()

void cam_record_probe_data ( cam_sync_state_t * state,
cam_ceu_sync_probe_t * probe,
uint8_t data )
inlinestatic

Fold one active-line camera byte into the probe statistics.

Parameters
[in,out]stateSync/data accumulator.
[in,out]probePublic probe result being accumulated.
[in]dataNewly sampled camera byte.
Precondition
state and probe are non-NULL.
data was sampled on an active-line PCLK rising edge.
Postcondition
Byte extrema and reductions include data.
Change count compares data with the preceding sample.
Note
Thread safety: caller-owned state only.
Since
0.1.0

Definition at line 262 of file cam_ceu.c.

References cam_sync_state_t::data_and, cam_ceu_sync_probe_t::data_changes, cam_sync_state_t::data_max, cam_sync_state_t::data_min, cam_sync_state_t::data_or, cam_ceu_sync_probe_t::data_samples, and cam_sync_state_t::prior_data.

Referenced by cam_record_sync_sample().

◆ cam_record_sync_sample()

void cam_record_sync_sample ( const cam_probe_ports_t * ports,
uint32_t current,
cam_sync_state_t * state,
cam_ceu_sync_probe_t * probe )
inlinestatic

Fold one masked sync sample into edge, timing, and data statistics.

Parameters
[in]portsResolved camera GPIO banks.
[in]currentCurrent masked VSYNC/HSYNC/PCLK sample.
[in,out]statePrivate sampling state.
[in,out]probePublic probe result being accumulated.
Precondition
All pointers are non-NULL and refer to caller-owned state.
current contains only the three sync bits.
Postcondition
Edge and run statistics include current.
state->prior equals current.
Note
Thread safety: bounded single-caller sampling loop.
Since
0.1.0

Definition at line 289 of file cam_ceu.c.

References cam_read_probe_data(), cam_record_probe_data(), cam_sync_state_t::high_cycles_max, cam_sync_state_t::high_cycles_min, cam_sync_state_t::high_max, cam_sync_state_t::high_min, cam_ceu_sync_probe_t::hsync_edges, k_ra8_pin_2, k_ra8_pin_3, k_ra8_pin_4, cam_sync_state_t::low_max, cam_sync_state_t::low_min, cam_ceu_sync_probe_t::pclk_edges, cam_ceu_sync_probe_t::pclk_half_cycles_min, cam_sync_state_t::prior, cam_sync_state_t::prior_pclk_cycles, ra8_dwt_cyccnt_read(), cam_sync_state_t::run_samples, cam_sync_state_t::run_start_cycles, and cam_ceu_sync_probe_t::vsync_edges.

Referenced by cam_measure_sync().

◆ cam_release_probe_pins()

void cam_release_probe_pins ( uint32_t count)
static

Release a bounded prefix of the temporary camera GPIO claims.

Parameters
[in]countNumber of entries in s_ceu_pins to release.
Precondition
count does not exceed the pin-table length.
Each selected pin is either claimed or safe to release.
Postcondition
Every selected pin has been offered back to the GPIO owner.
Pins outside the selected prefix are untouched.
Note
Thread safety: init context only.
Since
0.1.0

Definition at line 106 of file cam_ceu.c.

References pin, ra8_gpio_release(), RA8_PIN, and s_ceu_pins.

Referenced by cam_claim_probe_pins(), and cam_probe_sync_activity().

◆ cam_sync_state_init()

void cam_sync_state_init ( cam_sync_state_t * state,
uint32_t prior )
static

Initialize sync-sampling state from the first masked sample.

Parameters
[out]stateState accumulator to initialize.
[in]priorFirst masked sync sample.
Precondition
state is non-NULL.
DWT cycle counting is available.
Postcondition
All minima use their maximum-value sentinels.
Timing origins describe the instant of initialization.
Note
Thread safety: caller-owned state only.
Since
0.1.0

Definition at line 231 of file cam_ceu.c.

References ra8_dwt_cyccnt_read().

Referenced by cam_measure_sync().

Variable Documentation

◆ s_ceu_pins

const cam_ceu_pin_t s_ceu_pins[]
static
Initial value:
= {
}
@ k_ra8_port_9
RA8 port 9.
@ k_ra8_port_7
RA8 port 7.
@ k_ra8_port_11
RA8 port 11.
@ k_ra8_port_4
RA8 port 4.
@ k_ra8_pin_4
RA8 pin 4.
@ k_ra8_pin_6
RA8 pin 6.
@ k_ra8_pin_1
RA8 pin 1.
@ k_ra8_pin_2
RA8 pin 2.
@ k_ra8_pin_5
RA8 pin 5.
@ k_ra8_pin_0
RA8 pin 0.
@ k_ra8_pin_3
RA8 pin 3.

The 11 EK-RA8D2 J35 parallel-camera pins that feed the CEU: VIO_D[7:0], VIO_VD, VIO_HD, VIO_CLK (EK-RA8D2 UM Table 35 p 48).

Since
0.1.0

Definition at line 81 of file cam_ceu.c.

Referenced by cam_claim_probe_pins(), cam_probe_sync_activity(), and cam_release_probe_pins().