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

Capture Engine Unit (CEU) peripheral-block model for ra8_emulator. More...

#include <stdint.h>
#include <stdio.h>
#include "board_console.h"
#include "board_periph_block.h"
#include "emu_host_io_internal.h"
Include dependency graph for board_periph_ceu.c:

Go to the source code of this file.

Data Structures

struct  ceu_state_t
 CEU model state: register backing store + capture observability. More...

Enumerations

enum  ceu_map_t : uint64_t {
  k_ceu_base = 0x40348000UL ,
  k_ceu_span = 0x100UL ,
  k_ceu_words = 0x100UL / 4UL ,
  k_ceu_off_capsr = 0x00UL ,
  k_ceu_off_cmcyr = 0x0CUL ,
  k_ceu_off_capwr = 0x14UL ,
  k_ceu_off_cdwdr = 0x38UL ,
  k_ceu_off_cdayr = 0x3CUL ,
  k_ceu_off_cetcr = 0x74UL ,
  k_ceu_off_cstsr = 0x7CUL ,
  k_ceu_off_cdssr = 0x84UL
}
 CEU register-window geometry (ra8_ceu_regs.h, Plane A view). More...
enum  ceu_field_t : uint32_t {
  k_ceu_capsr_ce = 0x00000001U ,
  k_ceu_capsr_cpkil = 0x00010000U ,
  k_ceu_cetcr_cpe = 0x00000001U ,
  k_ceu_cmcyr_hcyl = 0x00003FFFU ,
  k_ceu_field_14bit = 0x00003FFFU ,
  k_ceu_capwr_hwdth = 0x00001FFFU ,
  k_ceu_field_12bit = 0x00000FFFU ,
  k_ceu_pattern_mask = 0x000000FFU
}
 CEU register bit fields (ra8_ceu_regs.h). More...
enum  ceu_bound_t : uint32_t {
  k_ceu_shift_vert = 16U ,
  k_ceu_max_line = 8192U ,
  k_ceu_max_lines = 4096U
}
 Field shift + fill bounds. More...
enum  ceu_console_t : uint32_t { k_ceu_console_line_cap = 56U }
 Console anti-flood cadence for the CEU (DMA/transfer) tab. More...

Functions

static RA8_INTERNAL uint32_t internal_ceu_word (uint64_t off)
 Word index into the backing store for an in-window byte offset.
static RA8_INTERNAL uint32_t internal_ceu_line_bytes (void)
 Destination line width (bytes): CDWDR stride, else CMCYR.HCYL.
static RA8_INTERNAL uint32_t internal_ceu_line_count (void)
 Destination line count: CAPWR.VWDTH, else CMCYR.VCYL.
static RA8_INTERNAL bool internal_ceu_do_capture (uc_engine *uc)
 Synthesise one frame into the CDAYR buffer and latch CETCR.CPE.
static RA8_INTERNAL uint64_t internal_ceu_read (uc_engine *uc, uint64_t addr, unsigned size)
 MMIO read inside the CEU window.
static RA8_INTERNAL void internal_ceu_write (uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
 MMIO write inside the CEU window: latch, then act on CAPSR.
static RA8_INTERNAL void internal_ceu_reset (void)
 Clear the CEU model to power-on state.
static RA8_INTERNAL void internal_ceu_report (void)
 Print the CEU capture summary if any frame was synthesised.
static RA8_INTERNAL void internal_board_periph_ceu_register (void)
 Self-register the CEU block before main runs (decentralized).

Variables

static ceu_state_t s_ceu
static uint8_t s_ceu_line [k_ceu_max_line]
 One-line fill scratch.
static const board_periph_block_t s_k_ceu_block
 This block's descriptor (static lifetime; the core keeps the pointer).

Detailed Description

Capture Engine Unit (CEU) peripheral-block model for ra8_emulator.

Models the RA8D2 Capture Engine Unit at 0x4034_8000 (ra8_ceu_regs.h / ra8_ceu.c, the real HUM Ch 60 parallel-camera capture path). The firmware (camera_capture via cam_ceu.c) initialises the CEU, arms a single-shot capture with ra8_ceu_capture_arm (which programs the destination address register CDAYR then sets CAPSR.CE), and polls the event register CETCR.CPE for one-frame-end. On silicon that end is raised by the sensor's VD edge; in ra8_emulator the capture is instantaneous.

On the CAPSR.CE arm this block synthesises the frame: it derives the destination byte geometry from the capture registers (CDWDR destination stride x CAPWR.VWDTH lines, falling back to CMCYR), writes a deterministic diagonal-gradient test pattern into the firmware's frame buffer at CDAYR through the Unicorn engine, latches CETCR.CPE (and the data size CDSSR), and clears CAPSR.CE (single-shot end). The status register CSTSR reads idle (capture is instantaneous) and CAPSR.CPKIL self-clears, so ra8_ceu_init's idle wait and the arm path both complete. The result: camera_capture reaches frame=OK with a plausible non-degenerate min/max/mean and runs its capture -> stats -> verdict path headless.

Honest-model boundaries: a capture with no destination address or no valid geometry raises no CPE (no faked frame). And ra8_emulator cannot reproduce the real board's J1/TFT VIO_HD pin conflict (issue #119) – this exercises the register/capture flow, it is not a claim the silicon captures. Self-registers with the board_periph core from a file-scope constructor – see board_periph_block.h.

Since
0.1.0

Definition in file board_periph_ceu.c.

Enumeration Type Documentation

◆ ceu_bound_t

enum ceu_bound_t : uint32_t

Field shift + fill bounds.

Enumerator
k_ceu_shift_vert 

Vertical field shift (VCYL / VWDTH).

k_ceu_max_line 

Max modelled line width (bytes) – QVGA=640.

k_ceu_max_lines 

Max modelled line count – QVGA=240.

Definition at line 73 of file board_periph_ceu.c.

◆ ceu_console_t

enum ceu_console_t : uint32_t

Console anti-flood cadence for the CEU (DMA/transfer) tab.

Enumerator
k_ceu_console_line_cap 

Max chars in a "CEU frame .." line.

Definition at line 80 of file board_periph_ceu.c.

◆ ceu_field_t

enum ceu_field_t : uint32_t

CEU register bit fields (ra8_ceu_regs.h).

Enumerator
k_ceu_capsr_ce 

CAPSR.CE: start capture at next VD.

k_ceu_capsr_cpkil 

CAPSR.CPKIL: software reset.

k_ceu_cetcr_cpe 

CETCR.CPE: one-frame capture end.

k_ceu_cmcyr_hcyl 

CMCYR.HCYL[13:0]: byte-cycles/line.

k_ceu_field_14bit 

14-bit field (CMCYR VCYL after >>16).

k_ceu_capwr_hwdth 

CAPWR.HWDTH[12:0] / CDWDR stride mask.

k_ceu_field_12bit 

12-bit field (CAPWR VWDTH after >>16).

k_ceu_pattern_mask 

Test-pattern byte modulus.

Definition at line 61 of file board_periph_ceu.c.

◆ ceu_map_t

enum ceu_map_t : uint64_t

CEU register-window geometry (ra8_ceu_regs.h, Plane A view).

Enumerator
k_ceu_base 

CEU block base (HUM Ch 60).

k_ceu_span 

Plane-A register set (0x00..0x9C).

k_ceu_words 

Backing-store word count.

k_ceu_off_capsr 

CAPSR capture start (CE / CPKIL).

k_ceu_off_cmcyr 

CMCYR interface cycle (HCYL / VCYL).

k_ceu_off_capwr 

CAPWR capture width (HWDTH / VWDTH).

k_ceu_off_cdwdr 

CDWDR destination stride.

k_ceu_off_cdayr 

CDAYR destination Y address.

k_ceu_off_cetcr 

CETCR event flags (CPE, ...).

k_ceu_off_cstsr 

CSTSR capture status (CPTON).

k_ceu_off_cdssr 

CDSSR captured data byte count.

Definition at line 46 of file board_periph_ceu.c.

Function Documentation

◆ internal_board_periph_ceu_register()

RA8_INTERNAL void internal_board_periph_ceu_register ( void )
static

Self-register the CEU block before main runs (decentralized).

Definition at line 338 of file board_periph_ceu.c.

References board_periph_register_block(), RA8_INTERNAL, and s_k_ceu_block.

◆ internal_ceu_do_capture()

RA8_INTERNAL bool internal_ceu_do_capture ( uc_engine * uc)
static

Synthesise one frame into the CDAYR buffer and latch CETCR.CPE.

Derives the destination geometry from the capture registers, clamps it to the modelled bounds, and writes a diagonal-gradient test pattern ((x + y) & 0xFF – black..white so a real grab always varies) line-by-line into emulated memory at CDAYR. Raises CETCR.CPE + records CDSSR on success. No CDAYR or no geometry -> no frame is written and CPE stays clear (honest).

Parameters
[in,out]ucUnicorn engine (the pattern is written to guest memory).
Returns
true when a frame was synthesised and CPE latched.
Precondition
CAPSR.CE was just written (the arm event).
The CDAYR buffer, when non-zero, is mapped emulated memory.
Postcondition
On true, CETCR.CPE and CDSSR reflect a filled frame; CAPSR.CE is clear.
On false, no guest memory and no CETCR bit changed.
Note
Not thread-safe; the run loop is single-threaded host-side.
Since
0.1.0
Return values
trueThe ceu do capture condition holds or completed successfully; false otherwise.

Definition at line 175 of file board_periph_ceu.c.

References board_console_push(), board_periph_trace(), emu_mem_write(), internal_ceu_line_bytes(), internal_ceu_line_count(), internal_ceu_word(), k_board_console_ch_dma, k_ceu_capsr_ce, k_ceu_cetcr_cpe, k_ceu_console_line_cap, k_ceu_max_line, k_ceu_max_lines, k_ceu_off_capsr, k_ceu_off_cdayr, k_ceu_off_cdssr, k_ceu_off_cetcr, k_ceu_pattern_mask, priv_emu_io_errf(), RA8_INTERNAL, s_ceu, and s_ceu_line.

Referenced by internal_ceu_write().

◆ internal_ceu_line_bytes()

RA8_INTERNAL uint32_t internal_ceu_line_bytes ( void )
static

Destination line width (bytes): CDWDR stride, else CMCYR.HCYL.

Destination line width (bytes): cdwdr stride, else cmcyr.hcyl; this step is contained within the board periph ceu model and uses bounded caller or module-owned storage.

Returns
The ceu line bytes result produced by the board periph ceu model.
Return values
valueThe operation-specific ceu line bytes value.
Precondition
Arguments satisfy the ranges documented for ceu line bytes.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ceu model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 122 of file board_periph_ceu.c.

References internal_ceu_word(), k_ceu_capwr_hwdth, k_ceu_cmcyr_hcyl, k_ceu_off_cdwdr, k_ceu_off_cmcyr, RA8_INTERNAL, and s_ceu.

Referenced by internal_ceu_do_capture().

◆ internal_ceu_line_count()

RA8_INTERNAL uint32_t internal_ceu_line_count ( void )
static

Destination line count: CAPWR.VWDTH, else CMCYR.VCYL.

Destination line count: capwr.vwdth, else cmcyr.vcyl; this step is contained within the board periph ceu model and uses bounded caller or module-owned storage.

Returns
The ceu line count result produced by the board periph ceu model.
Return values
valueThe operation-specific ceu line count value.
Precondition
Arguments satisfy the ranges documented for ceu line count.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ceu model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 142 of file board_periph_ceu.c.

References internal_ceu_word(), k_ceu_field_12bit, k_ceu_field_14bit, k_ceu_off_capwr, k_ceu_off_cmcyr, k_ceu_shift_vert, RA8_INTERNAL, and s_ceu.

Referenced by internal_ceu_do_capture().

◆ internal_ceu_read()

RA8_INTERNAL uint64_t internal_ceu_read ( uc_engine * uc,
uint64_t addr,
unsigned size )
static

MMIO read inside the CEU window.

MMIO read inside the ceu window; this step is contained within the board periph ceu model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
Returns
The ceu read result produced by the board periph ceu model.
Return values
valueThe operation-specific ceu read value.
Precondition
Arguments satisfy the ranges documented for ceu read.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ceu model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 237 of file board_periph_ceu.c.

References internal_ceu_word(), k_ceu_base, k_ceu_capsr_cpkil, k_ceu_off_capsr, k_ceu_off_cstsr, k_ceu_span, RA8_INTERNAL, and s_ceu.

◆ internal_ceu_report()

RA8_INTERNAL void internal_ceu_report ( void )
static

Print the CEU capture summary if any frame was synthesised.

Print the ceu capture summary if any frame was synthesised; this step is contained within the board periph ceu model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for ceu report.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ceu model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 312 of file board_periph_ceu.c.

References priv_emu_io_errf(), RA8_INTERNAL, and s_ceu.

◆ internal_ceu_reset()

RA8_INTERNAL void internal_ceu_reset ( void )
static

Clear the CEU model to power-on state.

Clear the ceu model to power-on state; this step is contained within the board periph ceu model and uses bounded caller or module-owned storage.

Precondition
Arguments satisfy the ranges documented for ceu reset.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ceu model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 299 of file board_periph_ceu.c.

References RA8_INTERNAL, and s_ceu.

◆ internal_ceu_word()

RA8_INTERNAL uint32_t internal_ceu_word ( uint64_t off)
static

Word index into the backing store for an in-window byte offset.

Word index into the backing store for an in-window byte offset; this step is contained within the board periph ceu model and uses bounded caller or module-owned storage.

Parameters
[in]offRegister or byte offset addressed by the operation.
Returns
The ceu word result produced by the board periph ceu model.
Return values
valueThe operation-specific ceu word value.
Precondition
Arguments satisfy the ranges documented for ceu word.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ceu model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 107 of file board_periph_ceu.c.

References RA8_INTERNAL.

Referenced by internal_ceu_do_capture(), internal_ceu_line_bytes(), internal_ceu_line_count(), internal_ceu_read(), and internal_ceu_write().

◆ internal_ceu_write()

RA8_INTERNAL void internal_ceu_write ( uc_engine * uc,
uint64_t addr,
unsigned size,
uint64_t value )
static

MMIO write inside the CEU window: latch, then act on CAPSR.

MMIO write inside the ceu window: latch, then act on capsr; this step is contained within the board periph ceu model and uses bounded caller or module-owned storage.

Parameters
[in,out]ucUnicorn engine whose emulated state is read or updated.
[in]addrGuest address involved in the operation.
[in]sizeSize of the requested region or access in bytes.
[in]valueRegister or payload value involved in the operation.
Precondition
Arguments satisfy the ranges documented for ceu write.
The call executes on the emulator's single owning thread.
Postcondition
State changes remain confined to the board periph ceu model and documented output objects.
Ownership of caller-supplied storage is unchanged.
Note
The operation is synchronous and does not transfer heap ownership.
Since
0.1.0

Definition at line 268 of file board_periph_ceu.c.

References internal_ceu_do_capture(), internal_ceu_word(), k_ceu_base, k_ceu_capsr_ce, k_ceu_capsr_cpkil, k_ceu_off_capsr, k_ceu_off_cetcr, k_ceu_span, and s_ceu.

Variable Documentation

◆ s_ceu

◆ s_ceu_line

uint8_t s_ceu_line[k_ceu_max_line]
static

One-line fill scratch.

Definition at line 94 of file board_periph_ceu.c.

Referenced by internal_ceu_do_capture().

◆ s_k_ceu_block

const board_periph_block_t s_k_ceu_block
static
Initial value:
= {
.base = (uint64_t)k_ceu_base,
.span = (uint64_t)k_ceu_span,
.order = (uint32_t)k_block_order_i2c,
.tick = nullptr,
.name = "CEU",
}
@ k_block_order_i2c
I3C/I2C + GT911 (no tick today).
static RA8_INTERNAL void internal_ceu_reset(void)
Clear the CEU model to power-on state.
static RA8_INTERNAL void internal_ceu_report(void)
Print the CEU capture summary if any frame was synthesised.
static RA8_INTERNAL void internal_ceu_write(uc_engine *uc, uint64_t addr, unsigned size, uint64_t value)
MMIO write inside the CEU window: latch, then act on CAPSR.
static RA8_INTERNAL uint64_t internal_ceu_read(uc_engine *uc, uint64_t addr, unsigned size)
MMIO read inside the CEU window.
@ k_ceu_base
CEU block base (HUM Ch 60).
@ k_ceu_span
Plane-A register set (0x00..0x9C).
-proof

This block's descriptor (static lifetime; the core keeps the pointer).

Definition at line 325 of file board_periph_ceu.c.

Referenced by internal_board_periph_ceu_register().