45static const char*
s_tag =
"CEU";
51typedef enum : uint32_t {
63typedef enum : uintptr_t {
77typedef enum : uint32_t {
162#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
196 if (ptr ==
nullptr) {
269 if (bufs->
c_top !=
nullptr) {
282 if (bufs->
y_top_2 !=
nullptr) {
285 if (bufs->
c_top_2 !=
nullptr) {
378 const uint32_t current = *reg;
379 *reg = current & ~mask;
435 const uint32_t pending = *reg;
436 const uint32_t current = *reg;
437 *reg = current & ~pending;
538 .y_bottom_2 =
nullptr,
539 .c_bottom_2 =
nullptr,
540 .bundle_size_bytes = 0U,
570 const uint32_t val = *reg;
614 for (uint32_t i = 0U; i < (
sizeof(local_plane_offsets) /
sizeof(local_plane_offsets[0])); i++) {
643 if (bufs->
y_top !=
nullptr) {
645 (uint32_t)(uintptr_t)bufs->
y_top;
647 if (bufs->
c_top !=
nullptr) {
649 (uint32_t)(uintptr_t)bufs->
c_top;
653 (uint32_t)(uintptr_t)bufs->
y_bottom;
657 (uint32_t)(uintptr_t)bufs->
c_bottom;
659 if (bufs->
y_top_2 !=
nullptr) {
661 (uint32_t)(uintptr_t)bufs->
y_top_2;
663 if (bufs->
c_top_2 !=
nullptr) {
665 (uint32_t)(uintptr_t)bufs->
c_top_2;
683 if (bufs !=
nullptr) {
691 if (bufs !=
nullptr) {
726 uint32_t current = *reg;
763 uint32_t current = *reg;
776 uint32_t current = *reg;
799 .src = (uint32_t)(uintptr_t)src,
800 .dst = (uint32_t)(uintptr_t)dst,
837 uint32_t capcr = *capcr_reg;
838 if (num_frames == 0U) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
ra8_err_t ra8_ceu_exit_stop(void)
Exit the MSTP-gated stop entered by ra8_ceu_enter_stop.
static void * s_ceu_ctx
Opaque context forwarded as the first argument to s_ceu_fn.
ra8_err_t ra8_ceu_capture_mode_set(ra8_ceu_capture_mode_t mode)
Enable or disable continuous-capture mode (CAPCR.CTNCP).
ra8_err_t ra8_ceu_status_snapshot(ra8_ceu_status_t *out)
Snapshot CSTSR + CDSSR + the active plane into one struct.
ra8_err_t ra8_ceu_clear_status(uint32_t mask)
Clear the CETCR event flags identified by mask.
ra8_err_t ra8_ceu_capture_stop(void)
Stop the in-flight capture started via ra8_ceu_capture_start.
ra8_err_t ra8_ceu_capture_arm(uint8_t *buffer)
Arm a capture into the supplied buffer.
static ra8_err_t internal_wait_idle(void)
Bounded spin until CSTSR.CPTON and CAPSR.CPKIL both clear.
ra8_err_t ra8_ceu_get_status(uint32_t *out_mask)
Snapshot the CEU event-status register (CETCR).
ra8_err_t ra8_ceu_set_dma_buffer(uint8_t *buf, uint32_t len)
Cache a DMAC-target framebuffer for the next ra8_ceu_capture_start call.
ra8_err_t ra8_ceu_dma_pump(uint8_t channel, const uint8_t *src, uint8_t *dst, uint32_t bytes)
Pump a finished CEU bundle into a downstream DMAC channel.
static void internal_program_addresses(const ra8_ceu_buffers_t *bufs)
Program the CDAYR / CDACR / CDBYR / CDBCR family on Plane A.
ra8_err_t ra8_ceu_byte_swap_set(const ra8_ceu_byte_swap_t *swap)
Replace CDOCR byte-swap configuration in-place.
ra8_err_t ra8_ceu_data_size_get(uint32_t *out_bytes)
Return the byte count written by the last data-enable capture.
static uint8_t * s_ceu_dma_buf
Cached DMAC-target buffer set via ra8_ceu_set_dma_buffer.
static uint32_t s_ceu_dma_len
Cached buffer length (bytes) for the next capture.
static ra8_err_t internal_arm_capture(const ra8_ceu_buffers_t *bufs)
Common arming sequence for capture_start / capture_start_ex.
ra8_err_t ra8_ceu_low_pass_set(bool enable)
Enable or disable the input low-pass filter (CLFCR.LPF).
ra8_err_t ra8_ceu_firewall_set(bool enable, uint32_t upper_bound)
Configure the CFWCR firewall window.
static ra8_ceu_event_fn_t s_ceu_fn
Module-scope event callback registered by ra8_ceu_attach_handler.
ra8_ceu_align_mask_t
Buffer-alignment helper.
@ k_ra8_ceu_buffer_align_mask
RA8 CEU buffer align mask.
ra8_err_t ra8_ceu_plane_swap_force(void)
Force an immediate plane swap (CRCMPR.RA).
static void internal_plane_b_mirror_from_a(void)
Mirror every 3-plane register from Plane A to Plane B.
static uint32_t s_ceu_image_area
Cached image_area_size from the most recent ra8_ceu_init.
void ra8_ceu_dispatch(void)
Drain CEU interrupt events and fire the registered callback.
ra8_err_t ra8_ceu_bundle_size_set(uint32_t size_bytes)
Configure the bundle-write size (CBDSR).
ra8_err_t ra8_ceu_frame_drop_set(uint8_t count)
Update the frame-drop counter (CAPCR.FDRP).
static ra8_ceu_capture_format_t s_ceu_capture_format
Cached CAMCR.JPG copy so capture_start can choose its path.
ra8_err_t ra8_ceu_capture_start(uint32_t num_frames)
Start a single or continuous capture into the cached DMA buffer.
ra8_err_t ra8_ceu_init(const ra8_ceu_config_t *cfg)
Power on the CEU and write the full configuration.
ra8_err_t ra8_ceu_plane_b_program(const ra8_ceu_buffers_t *bufs)
Mirror the active configuration into Plane B and arm a swap.
ra8_err_t ra8_ceu_attach_handler(ra8_ceu_event_fn_t fn, void *ctx)
Register a callback invoked by ra8_ceu_dispatch.
ra8_err_t ra8_ceu_interrupts_set(uint32_t mask)
Update the CEIER interrupt-enable bitmask.
ra8_err_t ra8_ceu_capture_disarm(void)
Stop the running capture by clearing CAPSR.CE.
static void internal_plane_b_apply_overrides(const ra8_ceu_buffers_t *bufs)
Apply caller-supplied buffer overrides to Plane B.
ra8_err_t ra8_ceu_reset(void)
Issue a software reset of the capture state machine.
static uint32_t s_ceu_int_enable
Cached copy of CEIER – used to gate the dispatched event mask.
ra8_err_t ra8_ceu_capture_start_ex(const ra8_ceu_buffers_t *bufs)
Arm a capture using a full address bundle.
static ra8_err_t internal_validate_buffers(const ra8_ceu_buffers_t *bufs)
Validate every non-NULL pointer in a buffer bundle.
static bool internal_is_aligned(const void *ptr)
True if ptr is non-NULL and 8-byte aligned.
ra8_err_t ra8_ceu_enter_stop(void)
Stop active captures and drop the CEU module-stop bit.
ra8_ceu_timing_t
Bounded spin budgets for host + target builds.
@ k_ra8_ceu_reset_spin
CSTSR.CPTON / CAPSR.CPKIL clear spin.
ra8_err_t ra8_ceu_deinit(void)
Stop the CEU and drop its module-stop bit.
ra8_ceu_dma_align_t
DMAC-pump byte-count alignment.
@ k_ra8_ceu_dma_count_shift
divide-by-4 to convert bytes->words.
@ k_ra8_ceu_dma_byte_align_mask
RA8 CEU DMA byte align mask.
Capture Engine Unit (CEU) camera-capture driver.
void priv_ra8_ceu_program_format(const ra8_ceu_config_t *cfg)
Program filter / format / camera-interface registers.
void priv_ra8_ceu_program_geometry(const ra8_ceu_config_t *cfg)
Program the CMCYR/CAMOR/CAPWR geometry registers.
void priv_ra8_ceu_program_destination(const ra8_ceu_config_t *cfg)
Program destination / firewall / output / event registers.
Cross-TU surface for the ra8_ceu driver split.
Capture Engine Unit (CEU) register layout for the RA8D2.
@ k_ra8_ceu_capcr_shift_fdrp
FDRP[7:0] @ [31:24].
@ k_ra8_ceu_capcr_shift_ctncp
CTNCP @ bit 16.
@ k_ra8_ceu_cfwcr_mask_fwv
FWV[26:0] @ [31:5].
@ k_ra8_ceu_cfwcr_mask_fwe
FWE: enable.
@ k_ra8_ceu_capsr_mask_cpkil
CPKIL: software reset bit.
@ k_ra8_ceu_capsr_mask_ce
CE: capture-enable bit.
@ k_ra8_ceu_clfcr_mask_lpf
LPF: enable LPF.
@ k_ra8_ceu_cstsr_mask_crst
CRST: reset in flight.
@ k_ra8_ceu_cstsr_mask_cpfld
CPFLD: current field.
@ k_ra8_ceu_cstsr_mask_cpton
CPTON: capture running.
@ k_ra8_ceu_cdocr_mask_cows
RA8 CEU cdocr mask cows.
@ k_ra8_ceu_cdocr_mask_cobs
RA8 CEU cdocr mask cobs.
@ k_ra8_ceu_cdocr_mask_cols
RA8 CEU cdocr mask cols.
@ k_ra8_ceu_crcntr_mask_rvs
RVS: VD-sync update.
@ k_ra8_ceu_crcntr_mask_rc
RC: enable Plane A.
@ k_ra8_ceu_crcntr_mask_rs
RS: enable Plane B.
@ k_ra8_ceu_plane_a_off
Plane A (active).
@ k_ra8_ceu_plane_b_off
Plane B (shadow).
static volatile uint32_t * ra8_ceu_reg32(ra8_ceu_off_t offset)
Pointer to a 32-bit register inside the CEU window.
@ k_ra8_ceu_buffer_align_bytes
RA8 CEU buffer align bytes.
@ k_ra8_ceu_capcr_mask_fdrp
FDRP[7:0] frame-drop cnt.
@ k_ra8_ceu_capcr_mask_ctncp
CTNCP: continuous mode.
static volatile uint32_t * ra8_ceu_reg32_plane(ra8_ceu_off_t offset, ra8_ceu_plane_off_t plane)
Pointer to a 32-bit register on a specific CEU plane.
ra8_ceu_off_t
Plane A register offsets inside the CEU window.
@ k_ra8_ceu_off_capwr
Camera Interface Width Register.
@ k_ra8_ceu_off_cdbcr
Capture Data C Bottom-Field Register.
@ k_ra8_ceu_off_cfszr
Capture Filter Size Clip Register.
@ k_ra8_ceu_off_crcmpr
Register Forcible Control Register.
@ k_ra8_ceu_off_cdocr
Capture Data Output Control Register.
@ k_ra8_ceu_off_camor
Camera Interface Offset Register.
@ k_ra8_ceu_off_crcntr
Register Control Register.
@ k_ra8_ceu_off_cetcr
Capture Event Flag Clear Register.
@ k_ra8_ceu_off_cdacr
Capture Data C Address Register.
@ k_ra8_ceu_off_cfwcr
Firewall Operation Control Register.
@ k_ra8_ceu_off_cdssr
Capture Data Size Status Register.
@ k_ra8_ceu_off_capcr
Capture Control Register.
@ k_ra8_ceu_off_cdbcr2
Capture Data C2 Bottom-Field Register.
@ k_ra8_ceu_off_cdwdr
Capture Destination Width Register.
@ k_ra8_ceu_off_cflcr
Capture Filter Control Register.
@ k_ra8_ceu_off_cstsr
Capture Status Register (R).
@ k_ra8_ceu_off_cdbyr2
Capture Data Y2 Bottom-Field Register.
@ k_ra8_ceu_off_cdayr
Capture Data Y Address Register.
@ k_ra8_ceu_off_cdayr2
Capture Data Y Address Register 2.
@ k_ra8_ceu_off_ceier
Capture Event Interrupt Enable Register.
@ k_ra8_ceu_off_cdacr2
Capture Data C Address Register 2.
@ k_ra8_ceu_off_cbdsr
Capture Bundle Destination Size.
@ k_ra8_ceu_off_cdbyr
Capture Data Y Bottom-Field Register.
@ k_ra8_ceu_off_capsr
Capture Start Register.
@ k_ra8_ceu_off_clfcr
Capture Low-Pass Filter Control.
@ k_ra8_ceu_crcmpr_mask_ra
RA: force plane swap.
@ k_ra8_ceu_bundle_align_mask
RA8 CEU bundle align mask.
ra8_ceu_capture_mode_t
CAPCR.CTNCP single-shot vs continuous capture.
@ k_ra8_ceu_capture_continuous
CE stays asserted across frames.
ra8_ceu_capture_format_t
CAMCR.JPG capture-format select.
@ k_ra8_ceu_fmt_image_capture
YCbCr image capture mode.
@ k_ra8_ceu_fmt_data_enable
JPEG / data-enable fetch.
void(* ra8_ceu_event_fn_t)(void *ctx, uint32_t event_mask)
Callback fired by ra8_ceu_dispatch for every CETCR event.
@ k_ra8_ceu_plane_a
Use Plane A registers (default).
@ k_ra8_ceu_plane_b
Use Plane B (shadow) registers.
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
8-channel DMA controller (DMAC0) driver
@ k_ra8_dmac_width_word
32-bit transfers (DMTMD.SZ = 10b).
ra8_err_t ra8_dmac_start(uint8_t channel, const ra8_dmac_config_t *cfg)
Programme and enable a DMAC0 channel.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_busy
Resource busy – blocking operation cannot proceed.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Bounded wait-flag primitives for RA8D2 HAL drivers.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
@ k_ra8_mstp_ceu
MSTPC16 CEU.
Address bundle programmed into the CDAYR / CDACR family.
uint8_t * c_bottom
CDBCR – C bottom-field C address.
uint32_t bundle_size_bytes
CBDSR bundle write size (bytes/lines).
uint8_t * c_bottom_2
CDBCR2 – bundle-2 C bottom.
uint8_t * y_bottom_2
CDBYR2 – bundle-2 Y bottom.
uint8_t * y_top_2
CDAYR2 – bundle-2 Y top.
uint8_t * y_top
CDAYR – Y / top-field address.
uint8_t * c_top
CDACR – C / top-field C address.
uint8_t * y_bottom
CDBYR – Y bottom-field address.
uint8_t * c_top_2
CDACR2 – bundle-2 C top.
CDOCR.COBS / COWS / COLS byte-swap control bundle.
bool swap_16_bit
COWS: word-swap inside 32-bit dwords.
bool swap_8_bit
COBS: byte-swap inside 16-bit words.
bool swap_32_bit
COLS: dword-swap inside 64-bit qwords.
Full configuration descriptor for ra8_ceu_init.
ra8_ceu_capture_format_t capture_format
CAMCR.JPG.
uint16_t width_px
Captured image width (CMCYR.HCYL).
ra8_ceu_capture_mode_t capture_mode
CAPCR.CTNCP single/continuous.
uint32_t image_area_size
For data-enable firewall window.
uint32_t interrupts
CEIER bitmask (k_ra8_ceu_evt_*).
Snapshot of the CEU live-status registers.
uint32_t events
CETCR raw value (event flags).
bool top_field
CSTSR.CPFLD == 1.
bool capturing
CSTSR.CPTON.
uint32_t data_size
CDSSR last-write byte count.
bool reset_in_flight
CAPSR.CPKIL.
ra8_ceu_plane_t active_plane
CSTSR.CRST register plane.
DMAC channel configuration.