ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_camera_source_ceu.c
Go to the documentation of this file.
1
15
17
18#include <stdint.h>
19
20#include "ra8_attributes.h"
21#include "ra8_cache.h"
22#include "ra8_camera_internal.h"
23#include "ra8_ceu.h"
24#include "ra8_err.h"
25#include "ra8_time.h"
26
27typedef enum : uintptr_t {
30
36
53{
55 if (state == nullptr) {
57 }
58 if (!state->initialized) {
60 }
61 *out_info = state->info;
62 return k_ra8_ok;
63}
64
81 const ra8_ceu_status_t* status,
82 uint32_t* out_bytes)
83{
84 *out_bytes = state->info.frame_bytes_max;
86 if (status->data_size != 0U) {
87 *out_bytes = status->data_size;
88 }
89 }
90}
91
114 uint32_t* out_bytes)
115{
116 for (uint32_t attempt = 0U; attempt < state->poll_attempts; attempt += 1U) {
117 ra8_ceu_status_t status = {};
118 ra8_err_t err = ra8_ceu_status_snapshot(&status);
119 if (err != k_ra8_ok) {
120 return err;
121 }
122 state->last_events |= status.events;
123 if ((status.events & (uint32_t)k_ceu_fatal_events) != 0U) {
124 (void)ra8_ceu_clear_status(status.events);
125 const ra8_err_t reset_err = ra8_ceu_reset();
127 if (reset_err != k_ra8_ok) {
128 return reset_err;
129 }
130 return k_ra8_err_hw_error;
131 }
132 if ((status.events & (uint32_t)k_ra8_ceu_evt_cpe) != 0U) {
133 internal_ceu_frame_bytes(state, &status, out_bytes);
134 (void)ra8_ceu_clear_status(state->last_events);
135 return k_ra8_ok;
136 }
138 }
139 const ra8_err_t reset_err = ra8_ceu_reset();
141 if (reset_err != k_ra8_ok) {
142 return reset_err;
143 }
145}
146
168{
170 if (state == nullptr) {
172 }
173 if (!state->initialized) {
175 }
176 if (buffer->capacity < state->info.frame_bytes_max) {
178 }
179 if (((uintptr_t)buffer->data & (uintptr_t)k_ceu_buffer_alignment_mask) != 0U) {
181 }
182 state->last_events = 0U;
183 ra8_err_t err =
185 if (err != k_ra8_ok) {
186 return err;
187 }
188 const ra8_ceu_buffers_t buffers = {
189 .y_top = buffer->data,
190 };
191 err = ra8_ceu_capture_start_ex(&buffers);
192 if (err != k_ra8_ok) {
193 return err;
194 }
195 uint32_t captured_bytes = 0U;
196 err = internal_ceu_wait_for_frame(state, &captured_bytes);
197 if (err != k_ra8_ok) {
198 return err;
199 }
200 if (captured_bytes == 0U) {
202 }
203 if (captured_bytes > buffer->capacity) {
205 }
206 err = ra8_cache_dcache_invalidate_by_addr(buffer->data, captured_bytes);
207 if (err != k_ra8_ok) {
208 return err;
209 }
210 *out_frame = (ra8_camera_frame_t){
211 .data = buffer->data,
212 .bytes = captured_bytes,
213 .stride_bytes = state->info.stride_bytes,
214 .width = state->info.width,
215 .height = state->info.height,
216 .format = state->info.format,
217 };
218 return k_ra8_ok;
219}
220
221/* See the public header for the documented contract. */
223 uint32_t* out_events)
224{
225 if (state == nullptr) {
226 return k_ra8_err_null_ptr;
227 }
228 if (out_events == nullptr) {
229 return k_ra8_err_null_ptr;
230 }
231 if (!state->initialized) {
232 *out_events = 0U;
234 }
235 *out_events = state->last_events;
236 return k_ra8_ok;
237}
238
240 .get_info = internal_ceu_get_info,
241 .capture = internal_ceu_capture,
242};
243
262{
263 if (cfg->output.frame_bytes_max == 0U) {
265 }
266 if (cfg->output.width == 0U) {
268 }
269 if (cfg->output.height == 0U) {
271 }
272 if (cfg->poll_interval_ms == 0U) {
274 }
275 if (cfg->poll_attempts == 0U) {
277 }
281 }
283 if (cfg->output.stride_bytes != 0U) {
285 }
286 if (cfg->ceu.image_area_size != cfg->output.frame_bytes_max) {
288 }
289 }
290 return k_ra8_ok;
291}
292
293/* See the public header for the documented contract. */
297{
298 if (source == nullptr) {
299 return k_ra8_err_null_ptr;
300 }
301 if (state == nullptr) {
302 return k_ra8_err_null_ptr;
303 }
304 if (cfg == nullptr) {
305 return k_ra8_err_null_ptr;
306 }
307 *source = (ra8_camera_source_t){};
309 const ra8_err_t cfg_valid = internal_ceu_cfg_valid(cfg);
310 if (cfg_valid != k_ra8_ok) {
311 return cfg_valid;
312 }
313 ra8_err_t err = ra8_ceu_init(&cfg->ceu);
314 if (err != k_ra8_ok) {
315 return err;
316 }
318 .info = cfg->output,
319 .capture_format = cfg->ceu.capture_format,
320 .poll_interval_ms = cfg->poll_interval_ms,
321 .poll_attempts = cfg->poll_attempts,
322 .initialized = true,
323 };
324 *source = (ra8_camera_source_t){
325 .iface = &s_ceu_source_iface,
326 .ctx = state,
327 };
328 return k_ra8_ok;
329}
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Cortex-M85 L1 cache maintenance, enable/disable, and I-cache invalidate.
ra8_err_t ra8_cache_dcache_invalidate_by_addr(const void *addr, uint32_t size)
Invalidate (drop) the D-cache lines covering a byte range.
Definition ra8_cache.c:185
ra8_err_t ra8_cache_dcache_clean_invalidate_by_addr(const void *addr, uint32_t size)
Clean and invalidate the D-cache lines covering a byte range.
Definition ra8_cache.c:190
struct ra8_camera_source_iface ra8_camera_source_iface_t
Opaque source vtable; concrete source backends define its rows.
Definition ra8_camera.h:48
@ k_ra8_camera_format_jpeg
Complete encoded JPEG byte stream.
Definition ra8_camera.h:66
Private source and codec vtables for ra8_camera backends.
ra8_camera_ceu_alignment_t
@ k_ceu_buffer_alignment_mask
Eight-byte CEU buffer alignment mask.
ra8_err_t ra8_camera_source_ceu_get_last_events(const ra8_camera_source_ceu_state_t *state, uint32_t *out_events)
Read the most recent CEU event snapshot retained by the backend.
static ra8_err_t internal_ceu_capture(void *ctx, const ra8_camera_buffer_t *buffer, ra8_camera_frame_t *out_frame)
Capture one CEU frame into caller-owned storage.
ra8_err_t ra8_camera_source_ceu_init(ra8_camera_source_t *source, ra8_camera_source_ceu_state_t *state, const ra8_camera_source_ceu_cfg_t *cfg)
Initialize the CEU and bind it as a generic camera source.
ra8_camera_ceu_event_t
CEU faults that make a pending capture unusable immediately.
@ k_ceu_fatal_events
Events that invalidate captured storage.
static ra8_err_t internal_ceu_get_info(void *ctx, ra8_camera_source_info_t *out_info)
Return validated CEU source metadata.
static void internal_ceu_frame_bytes(const ra8_camera_source_ceu_state_t *state, const ra8_ceu_status_t *status, uint32_t *out_bytes)
Derive the captured byte count for one completed CPE event.
static ra8_err_t internal_ceu_cfg_valid(const ra8_camera_source_ceu_cfg_t *cfg)
Validate CEU capture-source configuration bounds and format pairing.
static ra8_err_t internal_ceu_wait_for_frame(ra8_camera_source_ceu_state_t *state, uint32_t *out_bytes)
Poll bounded CEU status until completion, error, or timeout.
static const ra8_camera_source_iface_t s_ceu_source_iface
RA8 CEU capture backend for the transport-neutral camera facade.
Capture Engine Unit (CEU) camera-capture driver.
ra8_err_t ra8_ceu_status_snapshot(ra8_ceu_status_t *out)
Snapshot CSTSR + CDSSR + the active plane into one struct.
Definition ra8_ceu.c:383
ra8_err_t ra8_ceu_clear_status(uint32_t mask)
Clear the CETCR event flags identified by mask.
Definition ra8_ceu.c:370
ra8_err_t ra8_ceu_init(const ra8_ceu_config_t *cfg)
Power on the CEU and write the full configuration.
Definition ra8_ceu.c:300
ra8_err_t ra8_ceu_reset(void)
Issue a software reset of the capture state machine.
Definition ra8_ceu.c:355
ra8_err_t ra8_ceu_capture_start_ex(const ra8_ceu_buffers_t *bufs)
Arm a capture using a full address bundle.
Definition ra8_ceu.c:551
@ k_ra8_ceu_evt_mask_all
RA8 CEU evt mask all.
@ k_ra8_ceu_evt_firewall
FWF: firewall-address fault.
@ k_ra8_ceu_evt_igrw
IGRW: illegal register write.
@ k_ra8_ceu_evt_cram_overflow
CDTOF: CRAM overflow.
@ k_ra8_ceu_evt_vd_error
VBP: invalid VD condition.
@ k_ra8_ceu_evt_cpe
CPE: one-frame capture end.
@ k_ra8_ceu_fmt_data_enable
JPEG / data-enable fetch.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
Definition ra8_err.h:304
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
Definition ra8_err.h:310
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
Definition ra8_err.h:167
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
SysTick-based tick counter, delay and timestamp helpers.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Definition ra8_time.c:129
Caller-owned writable byte-buffer description.
Definition ra8_camera.h:80
uint32_t capacity
Writable byte capacity.
Definition ra8_camera.h:82
uint8_t * data
First writable byte, or NULL when capacity is zero.
Definition ra8_camera.h:81
Immutable view of one captured or encoded image.
Definition ra8_camera.h:96
Backend configuration, including native CEU register descriptor.
uint32_t poll_attempts
Maximum completion polls.
ra8_ceu_config_t ceu
HAL descriptor programmed at bind.
ra8_camera_source_info_t output
Frame metadata exposed to callers.
uint32_t poll_interval_ms
Delay between completion polls.
Caller-owned CEU source state.
uint32_t poll_attempts
Maximum completion polls.
bool initialized
Backend binding completed.
ra8_camera_source_info_t info
Validated output metadata.
uint32_t last_events
Latest raw CEU event snapshot.
uint32_t poll_interval_ms
Completion polling interval.
ra8_ceu_capture_format_t capture_format
Fixed-frame or data-enable mode.
Native geometry and worst-case storage required by a source.
Definition ra8_camera.h:114
ra8_camera_format_t format
Native output format.
Definition ra8_camera.h:119
uint32_t frame_bytes_max
Required capture-buffer capacity.
Definition ra8_camera.h:115
uint16_t width
Native width in pixels.
Definition ra8_camera.h:117
uint32_t stride_bytes
Native row stride, or zero/JPEG.
Definition ra8_camera.h:116
uint16_t height
Native height in pixels.
Definition ra8_camera.h:118
Caller-owned handle binding one source backend and its context.
Definition ra8_camera.h:131
Address bundle programmed into the CDAYR / CDACR family.
ra8_ceu_capture_format_t capture_format
CAMCR.JPG.
uint32_t image_area_size
For data-enable firewall window.
Snapshot of the CEU live-status registers.
uint32_t events
CETCR raw value (event flags).
uint32_t data_size
CDSSR last-write byte count.