|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Capture Engine Unit (CEU) driver function prototypes. More...
Go to the source code of this file.
Functions | |
| 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_deinit (void) |
| Stop the CEU and drop its module-stop bit. | |
| ra8_err_t | ra8_ceu_reset (void) |
| Issue a software reset of the capture state machine. | |
| ra8_err_t | ra8_ceu_get_status (uint32_t *out_mask) |
| Snapshot the CEU event-status register (CETCR). | |
| ra8_err_t | ra8_ceu_clear_status (uint32_t mask) |
| Clear the CETCR event flags identified by mask. | |
| 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_data_size_get (uint32_t *out_bytes) |
| Return the byte count written by the last data-enable capture. | |
| ra8_err_t | ra8_ceu_interrupts_set (uint32_t mask) |
| Update the CEIER interrupt-enable bitmask. | |
| ra8_err_t | ra8_ceu_attach_handler (ra8_ceu_event_fn_t fn, void *ctx) |
| Register a callback invoked by ra8_ceu_dispatch. | |
| void | ra8_ceu_dispatch (void) |
| Drain CEU interrupt events and fire the registered callback. | |
| ra8_err_t | ra8_ceu_enter_stop (void) |
| Stop active captures and drop the CEU module-stop bit. | |
| ra8_err_t | ra8_ceu_exit_stop (void) |
| Exit the MSTP-gated stop entered by ra8_ceu_enter_stop. | |
| ra8_err_t | ra8_ceu_capture_arm (uint8_t *buffer) |
| Arm a capture into the supplied buffer. | |
| ra8_err_t | ra8_ceu_capture_start_ex (const ra8_ceu_buffers_t *bufs) |
| Arm a capture using a full address bundle. | |
| ra8_err_t | ra8_ceu_capture_disarm (void) |
| Stop the running capture by clearing CAPSR.CE. | |
| 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_plane_swap_force (void) |
| Force an immediate plane swap (CRCMPR.RA). | |
| ra8_err_t | ra8_ceu_firewall_set (bool enable, uint32_t upper_bound) |
| Configure the CFWCR firewall window. | |
| 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_bundle_size_set (uint32_t size_bytes) |
| Configure the bundle-write size (CBDSR). | |
| 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_capture_mode_set (ra8_ceu_capture_mode_t mode) |
| Enable or disable continuous-capture mode (CAPCR.CTNCP). | |
| ra8_err_t | ra8_ceu_frame_drop_set (uint8_t count) |
| Update the frame-drop counter (CAPCR.FDRP). | |
| 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. | |
| 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_capture_start (uint32_t num_frames) |
| Start a single or continuous capture into the cached DMA buffer. | |
| ra8_err_t | ra8_ceu_capture_stop (void) |
| Stop the in-flight capture started via ra8_ceu_capture_start. | |
Capture Engine Unit (CEU) driver function prototypes.
Public function prototypes for the RA8D2 Capture Engine Unit (CEU) HAL driver: lifecycle (init / deinit / reset), status + IRQ dispatch, power transitions, capture arm/disarm, the live plane / firewall / byte-swap reconfiguration setters, and the DMA-coupling helpers. The configuration descriptors and types these prototypes consume live in ra8_ceu_types.h; both are aggregated by the thin umbrella ra8_ceu.h, which also documents the full driver overview and state machine.
Definition in file ra8_ceu_api.h.
|
nodiscard |
Register a callback invoked by ra8_ceu_dispatch.
| [in] | fn | Callback function, or NULL to clear. |
| [in] | ctx | Opaque context forwarded as the first callback arg. |
| k_ra8_ok | Callback installed (or cleared). |
|
nodiscard |
Configure the bundle-write size (CBDSR).
HUM Ch 60.2.17 p 3660. The size is in bytes for data-enable mode or in lines for image / data-sync mode. The lower 3 bits are masked off by the hardware to enforce the 8-line/32-byte bundle alignment.
| [in] | size_bytes | Bundle size; aligned-down to 8 by the helper. |
| k_ra8_ok | Always. |
Definition at line 741 of file ra8_ceu.c.
References k_ra8_ceu_bundle_align_mask, k_ra8_ceu_off_cbdsr, k_ra8_ok, and ra8_ceu_reg32().
|
nodiscard |
Replace CDOCR byte-swap configuration in-place.
| [in] | swap | Non-NULL byte-swap descriptor. |
| k_ra8_ok | Updated. |
| k_ra8_err_null_ptr | swap was NULL. |
Definition at line 721 of file ra8_ceu.c.
References k_ra8_ceu_cdocr_mask_cobs, k_ra8_ceu_cdocr_mask_cols, k_ra8_ceu_cdocr_mask_cows, k_ra8_ceu_off_cdocr, k_ra8_ok, ra8_ceu_reg32(), RA8_CHECK_NULL_PTR, s_tag, ra8_ceu_byte_swap_t::swap_16_bit, ra8_ceu_byte_swap_t::swap_32_bit, and ra8_ceu_byte_swap_t::swap_8_bit.
|
nodiscard |
Arm a capture into the supplied buffer.
Writes the buffer base into CDAYR (and CDACR for image-capture mode), clears any pending CETCR flags, and finally sets CAPSR.CE=1. Capture begins on the next VD edge. The CETCR.CPE flag fires when the buffer is filled (single-shot) or at every frame boundary (continuous).
In data-enable-fetch mode the firewall (CFWCR) is automatically armed to image_area_size - 1 from the buffer base.
| [in] | buffer | Capture target. Must be non-NULL and 8-byte aligned. |
| k_ra8_ok | Capture armed; CE bit set. |
| k_ra8_err_null_ptr | buffer was NULL. |
| k_ra8_err_invalid_arg | buffer is not 8-byte aligned. |
| k_ra8_err_busy | A capture is already in progress (CSTSR.CPTON == 1) or a software reset is in flight (CAPSR.CPKIL == 1). |
Definition at line 521 of file ra8_ceu.c.
References internal_arm_capture(), k_ra8_ceu_buffer_align_mask, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info_val, and s_tag.
Referenced by ra8_ceu_capture_start().
|
nodiscard |
Stop the running capture by clearing CAPSR.CE.
Distinct from ra8_ceu_reset – this only clears the CE bit so the next VD does not start a new frame. Continuous-mode captures use this to break out cleanly without a CPKIL software reset.
| k_ra8_ok | Always. |
Definition at line 564 of file ra8_ceu.c.
References k_ra8_ceu_capsr_mask_ce, k_ra8_ceu_off_capsr, k_ra8_ok, and ra8_ceu_reg32().
Referenced by ra8_ceu_capture_stop().
|
nodiscard |
Enable or disable continuous-capture mode (CAPCR.CTNCP).
| [in] | mode | Single-shot or continuous. |
| k_ra8_ok | Always. |
Definition at line 759 of file ra8_ceu.c.
References k_ra8_ceu_capcr_mask_ctncp, k_ra8_ceu_capture_continuous, k_ra8_ceu_off_capcr, k_ra8_ok, and ra8_ceu_reg32().
|
nodiscard |
Start a single or continuous capture into the cached DMA buffer.
Wraps ra8_ceu_capture_arm with the buffer that was cached via ra8_ceu_set_dma_buffer. num_frames selects the capture mode:
| [in] | num_frames | 0 = continuous, otherwise number of frames. |
| k_ra8_ok | Capture armed. |
| k_ra8_err_invalid_state | No buffer cached via ra8_ceu_set_dma_buffer. |
| k_ra8_err_busy | CEU is already capturing. |
Definition at line 829 of file ra8_ceu.c.
References k_ra8_ceu_capcr_shift_ctncp, k_ra8_ceu_off_capcr, k_ra8_err_invalid_state, ra8_ceu_capture_arm(), ra8_ceu_reg32(), and s_ceu_dma_buf.
|
nodiscard |
Arm a capture using a full address bundle.
Like ra8_ceu_capture_start but lets the caller specify the C (chrominance) base, the bottom-field addresses (interlace), and the bundle-2 pair (ping-pong). Pointers left NULL leave the matching register at its previous value.
| [in] | bufs | Non-NULL buffer descriptor. |
| k_ra8_ok | Capture armed; CE set. |
| k_ra8_err_null_ptr | bufs was NULL or bufs->y_top NULL. |
| k_ra8_err_invalid_arg | Any non-NULL pointer fails 8-byte alignment. |
| k_ra8_err_busy | CSTSR.CPTON==1 or CAPSR.CPKIL==1. |
Definition at line 551 of file ra8_ceu.c.
References internal_arm_capture(), internal_validate_buffers(), k_ra8_ok, RA8_CHECK_NULL_PTR, s_tag, and ra8_ceu_buffers_t::y_top.
Referenced by internal_ceu_capture().
|
nodiscard |
Stop the in-flight capture started via ra8_ceu_capture_start.
Wraps ra8_ceu_capture_disarm so the high-level start/stop pair share matching names.
Definition at line 848 of file ra8_ceu.c.
References ra8_ceu_capture_disarm().
|
nodiscard |
Clear the CETCR event flags identified by mask.
CETCR is "write-0-to-clear" per HUM Ch 60.2.22 – writing the complement of mask clears exactly those bits. The driver does a read-modify-write so other in-flight flags survive.
| [in] | mask | Bitmask of k_ra8_ceu_evt_* values to clear. |
| k_ra8_ok | Always; mask of zero is a no-op. |
Definition at line 370 of file ra8_ceu.c.
References k_ra8_ceu_off_cetcr, k_ra8_ok, and ra8_ceu_reg32().
Referenced by internal_ceu_wait_for_frame().
|
nodiscard |
Return the byte count written by the last data-enable capture.
Reads CDSSR per HUM Ch 60.2.24 p 3674. Only meaningful after a data-enable-fetch capture completes; in image / data-sync modes this register stays at zero.
| [out] | out_bytes | Non-NULL byte-count receiver. |
| k_ra8_ok | Snapshot taken. |
| k_ra8_err_null_ptr | out_bytes was NULL. |
Definition at line 403 of file ra8_ceu.c.
References k_ra8_ceu_off_cdssr, k_ra8_ok, ra8_ceu_reg32(), RA8_CHECK_NULL_PTR, and s_tag.
|
nodiscard |
Stop the CEU and drop its module-stop bit.
Issues CAPSR.CPKIL=1 to abort any active capture, masks every interrupt source by writing 0 to CEIER, clears the registered callback, and finally calls ra8_mstp_disable(k_ra8_mstp_ceu).
| k_ra8_ok | Driver torn down, MSTP released. |
| k_ra8_err_hw_timeout | MSTP disable read-back failed. |
Definition at line 336 of file ra8_ceu.c.
References k_ra8_ceu_capsr_mask_cpkil, k_ra8_ceu_off_capsr, k_ra8_ceu_off_ceier, k_ra8_mstp_ceu, ra8_ceu_reg32(), ra8_mstp_disable(), s_ceu_ctx, s_ceu_dma_buf, s_ceu_dma_len, s_ceu_fn, s_ceu_image_area, and s_ceu_int_enable.
| void ra8_ceu_dispatch | ( | void | ) |
Drain CEU interrupt events and fire the registered callback.
Intended to be called from the CEU ISR (or from a soft-IRQ context fed by the ISR). Snapshots CETCR, clears the observed bits via write-0, and invokes the registered callback with the masked event set. The mask passed to the callback is gated by the currently-enabled CEIER bits.
Definition at line 427 of file ra8_ceu.c.
References k_ra8_ceu_off_cetcr, ra8_ceu_reg32(), s_ceu_ctx, s_ceu_fn, and s_ceu_int_enable.
|
nodiscard |
Pump a finished CEU bundle into a downstream DMAC channel.
The CEU writes pixels straight to SRAM/SDRAM via its own bus initiator, so it does not need the DMAC for the camera pixel path. This helper exists for the application-level pump that copies a completed CEU frame into a second buffer (e.g. ping-ponging frames into the GLCDC layer-2 framebuffer). It packages the existing ra8_dmac_start call with the CEU's preferred 32-bit / source+dest-incrementing layout.
| [in] | channel | DMAC channel index. |
| [in] | src | Source buffer (typically the CDAYR-pointed window). |
| [in] | dst | Destination buffer. |
| [in] | bytes | Bytes to copy (multiple of 4). |
| k_ra8_ok | DMAC channel armed. |
| k_ra8_err_null_ptr | src or dst was NULL. |
| k_ra8_err_invalid_arg | bytes not a multiple of 4 or 0. |
Definition at line 783 of file ra8_ceu.c.
References k_ra8_ceu_dma_byte_align_mask, k_ra8_ceu_dma_count_shift, k_ra8_dmac_width_word, k_ra8_err_invalid_arg, RA8_CHECK_NULL_PTR, ra8_dmac_start(), and s_tag.
|
nodiscard |
Stop active captures and drop the CEU module-stop bit.
| k_ra8_ok | CEU stopped + MSTP released. |
| k_ra8_err_hw_timeout | MSTP disable read-back failed. |
Definition at line 446 of file ra8_ceu.c.
References k_ra8_ceu_capsr_mask_cpkil, k_ra8_ceu_off_capsr, k_ra8_mstp_ceu, ra8_ceu_reg32(), and ra8_mstp_disable().
|
nodiscard |
Exit the MSTP-gated stop entered by ra8_ceu_enter_stop.
| k_ra8_ok | MSTP re-enabled, CEU window accessible. |
| k_ra8_err_hw_timeout | MSTP enable read-back failed. |
Definition at line 454 of file ra8_ceu.c.
References k_ra8_mstp_ceu, and ra8_mstp_enable().
|
nodiscard |
Configure the CFWCR firewall window.
HUM Ch 60.2.18 "CFWCR" p 3661. The firewall fires CETCR.FWF if the data-enable-fetch engine attempts a write past the supplied upper-bound address. Disabled if enable is false or the upper-bound is zero.
| [in] | enable | True to assert CFWCR.FWE. |
| [in] | upper_bound | Upper-bound address (lower 5 bits forced to 0x1F by the hardware). |
| k_ra8_ok | Always. |
Definition at line 709 of file ra8_ceu.c.
References k_ra8_ceu_cfwcr_mask_fwe, k_ra8_ceu_cfwcr_mask_fwv, k_ra8_ceu_off_cfwcr, k_ra8_ok, and ra8_ceu_reg32().
|
nodiscard |
Update the frame-drop counter (CAPCR.FDRP).
| [in] | count | Number of frames to skip between captures (0..255). |
| k_ra8_ok | Always. |
Definition at line 772 of file ra8_ceu.c.
References k_ra8_ceu_capcr_mask_fdrp, k_ra8_ceu_capcr_shift_fdrp, k_ra8_ceu_off_capcr, k_ra8_ok, and ra8_ceu_reg32().
|
nodiscard |
Snapshot the CEU event-status register (CETCR).
| [out] | out_mask | Receives the raw CETCR value. |
| k_ra8_ok | Snapshot taken. |
| k_ra8_err_null_ptr | out_mask was NULL. |
Definition at line 362 of file ra8_ceu.c.
References k_ra8_ceu_off_cetcr, k_ra8_ok, ra8_ceu_reg32(), RA8_CHECK_NULL_PTR, and s_tag.
|
nodiscard |
Power on the CEU and write the full configuration.
Steps performed:
| [in] | cfg | Non-NULL configuration descriptor. |
| k_ra8_ok | Capture engine powered + configured. |
| k_ra8_err_null_ptr | cfg was NULL. |
| k_ra8_err_invalid_arg | cfg->capture_mode is continuous in a non-image-capture format. |
| k_ra8_err_hw_timeout | MSTP enable failed or the reset-clear spin overran. |
Definition at line 300 of file ra8_ceu.c.
References ra8_ceu_config_t::capture_format, ra8_ceu_config_t::capture_mode, ra8_ceu_config_t::image_area_size, internal_wait_idle(), ra8_ceu_config_t::interrupts, k_ra8_ceu_capture_continuous, k_ra8_ceu_fmt_image_capture, k_ra8_ceu_off_ceier, k_ra8_err_invalid_arg, k_ra8_mstp_ceu, k_ra8_ok, priv_ra8_ceu_program_destination(), priv_ra8_ceu_program_format(), priv_ra8_ceu_program_geometry(), ra8_ceu_reg32(), RA8_CHECK_NULL_PTR, ra8_log_info_val, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, s_ceu_capture_format, s_ceu_image_area, s_ceu_int_enable, s_tag, and ra8_ceu_config_t::width_px.
Referenced by ra8_camera_source_ceu_init().
|
nodiscard |
Update the CEIER interrupt-enable bitmask.
| [in] | mask | Bitwise-OR of k_ra8_ceu_evt_* values. |
| k_ra8_ok | Always. |
Definition at line 411 of file ra8_ceu.c.
References k_ra8_ceu_off_ceier, k_ra8_ok, ra8_ceu_reg32(), and s_ceu_int_enable.
|
nodiscard |
Enable or disable the input low-pass filter (CLFCR.LPF).
| [in] | enable | true => CLFCR.LPF = 1. |
| k_ra8_ok | Always. |
Definition at line 748 of file ra8_ceu.c.
References k_ra8_ceu_clfcr_mask_lpf, k_ra8_ceu_off_clfcr, k_ra8_ok, and ra8_ceu_reg32().
|
nodiscard |
Mirror the active configuration into Plane B and arm a swap.
Writes the current Plane A image of every 3-plane register into Plane B (offset +0x1000) and sets CRCNTR.RVS so the CEU swaps planes on the next VD edge. Used to apply a new geometry / new capture buffer without dropping a frame.
| [in] | bufs | Buffer bundle to install on Plane B; pass NULL to copy the existing Plane A addresses unchanged. |
| k_ra8_ok | Plane B armed. |
| k_ra8_err_invalid_arg | Any non-NULL pointer is misaligned. |
Definition at line 681 of file ra8_ceu.c.
References internal_plane_b_apply_overrides(), internal_plane_b_mirror_from_a(), internal_validate_buffers(), k_ra8_ceu_crcntr_mask_rc, k_ra8_ceu_crcntr_mask_rs, k_ra8_ceu_crcntr_mask_rvs, k_ra8_ceu_off_crcntr, k_ra8_ok, and ra8_ceu_reg32().
|
nodiscard |
Force an immediate plane swap (CRCMPR.RA).
HUM Ch 60.2.9 "CRCMPR" p 3649. Bypasses the VD-edge sync the normal Plane-B path uses; use only when a frame must be dropped.
| k_ra8_ok | Always. |
Definition at line 702 of file ra8_ceu.c.
References k_ra8_ceu_crcmpr_mask_ra, k_ra8_ceu_off_crcmpr, k_ra8_ok, and ra8_ceu_reg32().
|
nodiscard |
Issue a software reset of the capture state machine.
Sets CAPSR.CPKIL and spins on CSTSR.CPTON / CAPSR.CPKIL until both clear or the budget expires. Used to recover from a stuck capture (e.g. after a sensor stopped emitting VD edges).
| k_ra8_ok | Reset completed cleanly. |
| k_ra8_err_hw_timeout | Status bits did not clear in budget. |
Definition at line 355 of file ra8_ceu.c.
References internal_wait_idle(), k_ra8_ceu_capsr_mask_cpkil, k_ra8_ceu_off_capsr, and ra8_ceu_reg32().
Referenced by internal_ceu_wait_for_frame().
|
nodiscard |
Cache a DMAC-target framebuffer for the next ra8_ceu_capture_start call.
The CEU writes pixel data straight to memory via its own bus initiator, so the "DMA buffer" here is just the next CDAYR target the driver will arm when ra8_ceu_capture_start(num_frames) is called. The length is cached so the frame-end callback can hand the whole buffer back to the consumer.
| [in] | buf | Capture target (must be 8-byte aligned per HUM Ch 60.2.13 p 3656). |
| [in] | len | Buffer length in bytes (>0). |
| k_ra8_ok | Buffer cached. |
| k_ra8_err_null_ptr | buf was NULL. |
| k_ra8_err_invalid_arg | len was 0 or buf misaligned. |
Definition at line 814 of file ra8_ceu.c.
References k_ra8_ceu_buffer_align_mask, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info_val, s_ceu_dma_buf, s_ceu_dma_len, and s_tag.
|
nodiscard |
Snapshot CSTSR + CDSSR + the active plane into one struct.
| [out] | out | Non-NULL status struct to populate. |
| k_ra8_ok | Snapshot taken. |
| k_ra8_err_null_ptr | out was NULL. |
Definition at line 383 of file ra8_ceu.c.
References ra8_ceu_status_t::active_plane, ra8_ceu_status_t::capturing, ra8_ceu_status_t::data_size, ra8_ceu_status_t::events, k_ra8_ceu_capsr_mask_cpkil, k_ra8_ceu_cstsr_mask_cpfld, k_ra8_ceu_cstsr_mask_cpton, k_ra8_ceu_cstsr_mask_crst, k_ra8_ceu_off_capsr, k_ra8_ceu_off_cdssr, k_ra8_ceu_off_cetcr, k_ra8_ceu_off_cstsr, k_ra8_ceu_plane_a, k_ra8_ceu_plane_b, k_ra8_ok, ra8_ceu_reg32(), RA8_CHECK_NULL_PTR, ra8_ceu_status_t::reset_in_flight, s_tag, and ra8_ceu_status_t::top_field.
Referenced by internal_ceu_wait_for_frame().