ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_ceu.c
Go to the documentation of this file.
1
26
27#include "ra8_ceu.h"
28
29#include <stdint.h>
30
31#include "ra8_attributes.h"
32#include "ra8_ceu_internal.h"
33#include "ra8_ceu_regs.h"
34#include "ra8_check.h"
35#include "ra8_dmac.h"
36#include "ra8_err.h"
37#include "ra8_hw_err.h"
38#include "ra8_log.h"
39#include "ra8_mstp.h"
40
45static const char* s_tag = "CEU";
46
51typedef enum : uint32_t {
54
63typedef enum : uintptr_t {
65 (uintptr_t)k_ra8_ceu_buffer_align_bytes - 1U,
67
81
88
93static void* s_ceu_ctx;
94
99static uint32_t s_ceu_int_enable;
100
108static uint32_t s_ceu_image_area;
109
115
123static uint8_t* s_ceu_dma_buf;
124
131static uint32_t s_ceu_dma_len;
132
154{
155 for (uint32_t i = 0U; i < (uint32_t)k_ra8_ceu_reset_spin; i++) {
156 /* HUM Ch 60.2.23 "CSTSR : Capture Status Register" p 3673 */
157 const uint32_t cstsr = *ra8_ceu_reg32(k_ra8_ceu_off_cstsr);
158 /* HUM Ch 60.2.1 "CAPSR : Capture Start Register" p 3630 */
159 const uint32_t capsr = *ra8_ceu_reg32(k_ra8_ceu_off_capsr);
160 const bool idle = ((cstsr & (uint32_t)k_ra8_ceu_cstsr_mask_cpton) == 0U) &&
161 ((capsr & (uint32_t)k_ra8_ceu_capsr_mask_cpkil) == 0U);
162#if defined(RA8_OFF_TARGET) && defined(UNIT_TEST)
163 /* Host MMIO fault seam, keyed on CSTSR (the primary status reg). */
164 if (ra8_fake_mmio_wait_eval(ra8_ceu_reg32(k_ra8_ceu_off_cstsr), i, idle)) {
165 return k_ra8_ok;
166 }
167#else
168 if (idle) {
169 return k_ra8_ok;
170 }
171#endif
172 }
174}
175
194static bool internal_is_aligned(const void* ptr)
195{
196 if (ptr == nullptr) {
197 return true; /* nullptr means "leave register alone" -- caller's choice. */
198 }
199 return ((uintptr_t)ptr & k_ra8_ceu_buffer_align_mask) == 0U;
200}
201
221{
222 if (!internal_is_aligned(bufs->y_top)) {
224 }
225 if (!internal_is_aligned(bufs->c_top)) {
227 }
228 if (!internal_is_aligned(bufs->y_bottom)) {
230 }
231 if (!internal_is_aligned(bufs->c_bottom)) {
233 }
234 if (!internal_is_aligned(bufs->y_top_2)) {
236 }
237 if (!internal_is_aligned(bufs->c_top_2)) {
239 }
240 if (!internal_is_aligned(bufs->y_bottom_2)) {
242 }
243 if (!internal_is_aligned(bufs->c_bottom_2)) {
245 }
246 return k_ra8_ok;
247}
248
265{
266 /* HUM Ch 60.2.13 "CDAYR : Capture Data Y Address Register" p 3656 */
267 *ra8_ceu_reg32(k_ra8_ceu_off_cdayr) = (uint32_t)(uintptr_t)bufs->y_top;
268 /* HUM Ch 60.2.14 "CDACR : Capture Data C Address Register" p 3657 */
269 if (bufs->c_top != nullptr) {
270 *ra8_ceu_reg32(k_ra8_ceu_off_cdacr) = (uint32_t)(uintptr_t)bufs->c_top;
271 }
272 /* HUM Ch 60.2.15 "CDBYR : Capture Data Y Bottom-Field Register" p 3658 */
273 if (bufs->y_bottom != nullptr) {
274 *ra8_ceu_reg32(k_ra8_ceu_off_cdbyr) = (uint32_t)(uintptr_t)bufs->y_bottom;
275 }
276 /* HUM Ch 60.2.16 "CDBCR : Capture Data C Bottom-Field Register" p 3659 */
277 if (bufs->c_bottom != nullptr) {
278 *ra8_ceu_reg32(k_ra8_ceu_off_cdbcr) = (uint32_t)(uintptr_t)bufs->c_bottom;
279 }
280 /* HUM Ch 60.2 "Register Descriptions" p 3629 */
281 /* Bundle-2 group sits at offsets 0x90..0x9C per HUM Table 60.4. */
282 if (bufs->y_top_2 != nullptr) {
283 *ra8_ceu_reg32(k_ra8_ceu_off_cdayr2) = (uint32_t)(uintptr_t)bufs->y_top_2;
284 }
285 if (bufs->c_top_2 != nullptr) {
286 *ra8_ceu_reg32(k_ra8_ceu_off_cdacr2) = (uint32_t)(uintptr_t)bufs->c_top_2;
287 }
288 if (bufs->y_bottom_2 != nullptr) {
289 *ra8_ceu_reg32(k_ra8_ceu_off_cdbyr2) = (uint32_t)(uintptr_t)bufs->y_bottom_2;
290 }
291 if (bufs->c_bottom_2 != nullptr) {
292 *ra8_ceu_reg32(k_ra8_ceu_off_cdbcr2) = (uint32_t)(uintptr_t)bufs->c_bottom_2;
293 }
294 if (bufs->bundle_size_bytes != 0U) {
295 /* HUM Ch 60.2.17 "CBDSR : Capture Bundle Destination Size" p 3660 */
297 }
298}
299
301{
302 RA8_CHECK_NULL_PTR(cfg, s_tag, "cfg must not be nullptr");
303
304 /* Continuous capture is only legal in image-capture mode (HUM Ch
305 * 60.2.2 "Note" on CTNCP). */
309 }
310
311 /* HUM Ch 11.2.8 "MSTPCRC : Module Stop Control Register C" p 446 */
313 /* GCOVR_EXCL_BR_START -- MSTP HW readback */
314 RA8_RETURN_ON_ERROR(mst_err, s_tag, "ceu_init: mstp enable");
315 /* GCOVR_EXCL_BR_STOP */
316
317 /* HUM Ch 60.2.23 "CSTSR" p 3673 */ /* + HUM Ch 60.2.1 "CAPSR" p 3630 */
318 const ra8_err_t idle_err = internal_wait_idle();
319 RA8_RETURN_ON_ERROR(idle_err, s_tag, "ceu_init: wait idle");
320
324
325 s_ceu_int_enable = (uint32_t)cfg->interrupts;
328
329 /* HUM Ch 60.2.21 "CEIER : Capture Event Interrupt Enable Register" p 3668 */
331
332 ra8_log_info_val(s_tag, "ceu_init width", (uint32_t)cfg->width_px);
333 return k_ra8_ok;
334}
335
337{
338 /* HUM Ch 60.2.21 "CEIER : Capture Event Interrupt Enable Register" p 3668 */
340 /* HUM Ch 60.2.1 "CAPSR : Capture Start Register" p 3630 */
341 /* Abort any active capture on the way out. */
343
344 s_ceu_fn = nullptr;
345 s_ceu_ctx = nullptr;
346 s_ceu_int_enable = 0U;
347 s_ceu_image_area = 0U;
348 s_ceu_dma_buf = nullptr;
349 s_ceu_dma_len = 0U;
350
351 /* HUM Ch 11.2.8 "MSTPCRC : Module Stop Control Register C" p 446 */
353}
354
356{
357 /* HUM Ch 60.2.1 "CAPSR : Capture Start Register" p 3630 */
359 return internal_wait_idle();
360}
361
362ra8_err_t ra8_ceu_get_status(uint32_t* out_mask)
363{
364 RA8_CHECK_NULL_PTR(out_mask, s_tag, "out_mask must not be nullptr");
365 /* HUM Ch 60.2.22 "CETCR : Capture Event Flag Clear Register" p 3669 */
367 return k_ra8_ok;
368}
369
371{
372 /* HUM Ch 60.2.22 "CETCR : Capture Event Flag Clear Register" p 3669
373 * CETCR bits clear when 0 is written; preserve bits not in `mask`
374 * by writing back a value that is `current & ~mask`. The hardware
375 * never resets a CETCR bit on a 1 write, so 1s leave the existing
376 * flag asserted. */
377 volatile uint32_t* reg = ra8_ceu_reg32(k_ra8_ceu_off_cetcr);
378 const uint32_t current = *reg;
379 *reg = current & ~mask;
380 return k_ra8_ok;
381}
382
384{
385 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
386
387 /* HUM Ch 60.2.22 "CETCR : Capture Event Flag Clear Register" p 3669 */
389 /* HUM Ch 60.2.24 "CDSSR : Capture Data Size Register" p 3674 */
391 /* HUM Ch 60.2.23 "CSTSR : Capture Status Register" p 3673 */
392 const uint32_t cstsr = *ra8_ceu_reg32(k_ra8_ceu_off_cstsr);
393 out->capturing = ((cstsr & k_ra8_ceu_cstsr_mask_cpton) != 0U);
394 out->top_field = ((cstsr & k_ra8_ceu_cstsr_mask_cpfld) != 0U);
395 out->active_plane =
397 /* HUM Ch 60.2.1 "CAPSR : Capture Start Register" p 3630 */
398 const uint32_t capsr = *ra8_ceu_reg32(k_ra8_ceu_off_capsr);
399 out->reset_in_flight = ((capsr & k_ra8_ceu_capsr_mask_cpkil) != 0U);
400 return k_ra8_ok;
401}
402
404{
405 RA8_CHECK_NULL_PTR(out_bytes, s_tag, "out_bytes must not be nullptr");
406 /* HUM Ch 60.2.24 "CDSSR : Capture Data Size Register" p 3674 */
407 *out_bytes = *ra8_ceu_reg32(k_ra8_ceu_off_cdssr);
408 return k_ra8_ok;
409}
410
412{
413 s_ceu_int_enable = mask;
414 /* HUM Ch 60.2.21 "CEIER : Capture Event Interrupt Enable Register" p 3668 */
416 return k_ra8_ok;
417}
418
420{
421 s_ceu_fn = fn;
422 s_ceu_ctx = ctx;
423 return k_ra8_ok;
424}
425
428{
429 /* HUM Ch 60.2.22 "CETCR : Capture Event Flag Clear Register" p 3669
430 * CETCR bits clear when 0 is written; preserve bits not observed by
431 * re-reading and writing back `current & ~pending`. Writing a 1 to a
432 * CETCR bit leaves that flag asserted, so the prior observed bits
433 * become 0 and any newly-asserted-during-dispatch bits stay set. */
434 volatile uint32_t* reg = ra8_ceu_reg32(k_ra8_ceu_off_cetcr);
435 const uint32_t pending = *reg;
436 const uint32_t current = *reg;
437 *reg = current & ~pending;
438
439 const ra8_ceu_event_fn_t fn = s_ceu_fn;
440 void* const ctx = s_ceu_ctx;
441 if (fn != nullptr) {
442 fn(ctx, pending & s_ceu_int_enable);
443 }
444}
445
447{
448 /* HUM Ch 60.2.1 "CAPSR : Capture Start Register" p 3630 */
450 /* HUM Ch 11.2.8 "MSTPCRC : Module Stop Control Register C" p 446 */
452}
453
455{
456 /* HUM Ch 11.2.8 "MSTPCRC : Module Stop Control Register C" p 446 */
458}
459
479{
480 /* HUM Ch 60.2.23 "CSTSR : Capture Status Register" p 3673 -- a
481 * non-zero CPTON means a capture is already running. */
482 const uint32_t cstsr = *ra8_ceu_reg32(k_ra8_ceu_off_cstsr);
483 if ((cstsr & k_ra8_ceu_cstsr_mask_cpton) != 0U) {
484 return k_ra8_err_busy;
485 }
486 /* HUM Ch 60.2.1 "CAPSR : Capture Start Register" p 3630 -- if a
487 * software reset is in flight the engine is not ready. */
488 const uint32_t capsr_now = *ra8_ceu_reg32(k_ra8_ceu_off_capsr);
489 if ((capsr_now & k_ra8_ceu_capsr_mask_cpkil) != 0U) {
490 return k_ra8_err_busy;
491 }
492
493 /* HUM Ch 60.2.18 "CFWCR : Firewall Operation Control Register" p 3661
494 * In data-enable-fetch mode arm the firewall to the cached image
495 * area; in image / data-sync modes leave the firewall disabled. */
497 // mcdc-deactivated: TU-local helper internal_arm_capture; bufs->y_top non-NULL is enforced by upstream public-API ra8_ceu_capture_start contract, and s_ceu_image_area is non-zero whenever data-enable-fetch mode is configured -- the AND's two conditions cannot be flipped independently from any reachable call site.
498 if ((s_ceu_image_area != 0U) && (bufs->y_top != nullptr)) {
499 const uint32_t upper = (uint32_t)(uintptr_t)bufs->y_top + s_ceu_image_area - 1U;
502 }
503 } else {
505 }
506
507 /* HUM Ch 60.2.13 "CDAYR : Capture Data Y Address Register" p 3656.
508 * Program the destination after the data-enable firewall, matching the
509 * hardware sequence used by Renesas FSP R_CEU_CaptureStart. */
511
512 /* HUM Ch 60.2.22 "CETCR : Capture Event Flag Clear Register" p 3669 */
514
515 /* HUM Ch 60.2.1 "CAPSR : Capture Start Register" p 3630 -- arm the
516 * CE bit; capture begins on the next VD edge. */
518 return k_ra8_ok;
519}
520
522{
523 RA8_CHECK_NULL_PTR(buffer, s_tag, "buffer must not be nullptr");
524
525 /* HUM Ch 60.2.13 "CDAYR : Capture Data Y Address Register" p 3656 --
526 * lower 3 bits must be zero (8-byte alignment). */
527 if (((uintptr_t)buffer & k_ra8_ceu_buffer_align_mask) != 0U) {
529 }
530
531 const ra8_ceu_buffers_t bufs = {
532 .y_top = buffer,
533 .c_top = buffer, /* default to same buffer; image-mode caller can override later. */
534 .y_bottom = nullptr,
535 .c_bottom = nullptr,
536 .y_top_2 = nullptr,
537 .c_top_2 = nullptr,
538 .y_bottom_2 = nullptr,
539 .c_bottom_2 = nullptr,
540 .bundle_size_bytes = 0U,
541 };
542
543 const ra8_err_t arm_err = internal_arm_capture(&bufs);
544 if (arm_err != k_ra8_ok) {
545 return arm_err;
546 }
547 ra8_log_info_val(s_tag, "ceu_capture_start buf", (uint32_t)(uintptr_t)buffer);
548 return k_ra8_ok;
549}
550
552{
553 RA8_CHECK_NULL_PTR(bufs, s_tag, "bufs must not be nullptr");
554 RA8_CHECK_NULL_PTR(bufs->y_top, s_tag, "bufs->y_top must not be nullptr");
555
556 const ra8_err_t align_err = internal_validate_buffers(bufs);
557 if (align_err != k_ra8_ok) {
558 return align_err;
559 }
560
561 return internal_arm_capture(bufs);
562}
563
565{
566 /* HUM Ch 60.2.1 "CAPSR : Capture Start Register" p 3630 -- clear
567 * CE so the next VD does not start a new frame; in-flight frame
568 * runs to completion. */
569 volatile uint32_t* reg = ra8_ceu_reg32(k_ra8_ceu_off_capsr);
570 const uint32_t val = *reg;
571 *reg = val & ~k_ra8_ceu_capsr_mask_ce;
572 return k_ra8_ok;
573}
574
595{
596 static const ra8_ceu_off_t local_plane_offsets[] = {
613 };
614 for (uint32_t i = 0U; i < (sizeof(local_plane_offsets) / sizeof(local_plane_offsets[0])); i++) {
615 const uint32_t a = *ra8_ceu_reg32_plane(local_plane_offsets[i], k_ra8_ceu_plane_a_off);
616 *ra8_ceu_reg32_plane(local_plane_offsets[i], k_ra8_ceu_plane_b_off) = a;
617 }
618}
619
642{
643 if (bufs->y_top != nullptr) {
645 (uint32_t)(uintptr_t)bufs->y_top;
646 }
647 if (bufs->c_top != nullptr) {
649 (uint32_t)(uintptr_t)bufs->c_top;
650 }
651 if (bufs->y_bottom != nullptr) {
653 (uint32_t)(uintptr_t)bufs->y_bottom;
654 }
655 if (bufs->c_bottom != nullptr) {
657 (uint32_t)(uintptr_t)bufs->c_bottom;
658 }
659 if (bufs->y_top_2 != nullptr) {
661 (uint32_t)(uintptr_t)bufs->y_top_2;
662 }
663 if (bufs->c_top_2 != nullptr) {
665 (uint32_t)(uintptr_t)bufs->c_top_2;
666 }
667 if (bufs->y_bottom_2 != nullptr) {
669 (uint32_t)(uintptr_t)bufs->y_bottom_2;
670 }
671 if (bufs->c_bottom_2 != nullptr) {
673 (uint32_t)(uintptr_t)bufs->c_bottom_2;
674 }
675 if (bufs->bundle_size_bytes != 0U) {
678 }
679}
680
682{
683 if (bufs != nullptr) {
684 const ra8_err_t align_err = internal_validate_buffers(bufs);
685 if (align_err != k_ra8_ok) {
686 return align_err;
687 }
688 }
689
691 if (bufs != nullptr) {
693 }
694
695 /* HUM Ch 60.2.8 "CRCNTR : CEU Register Control Register" p 3649 --
696 * enable both planes and arm the VD-synchronised swap. */
699 return k_ra8_ok;
700}
701
703{
704 /* HUM Ch 60.2.9 "CRCMPR : CEU Register Forcible Control Register" p 3650 */
706 return k_ra8_ok;
707}
708
709ra8_err_t ra8_ceu_firewall_set(bool enable, uint32_t upper_bound)
710{
711 uint32_t cfwcr = 0U;
712 if (enable) {
714 cfwcr |= (upper_bound & k_ra8_ceu_cfwcr_mask_fwv);
715 }
716 /* HUM Ch 60.2.18 "CFWCR : Firewall Operation Control Register" p 3661 */
718 return k_ra8_ok;
719}
720
722{
723 RA8_CHECK_NULL_PTR(swap, s_tag, "swap must not be nullptr");
724 /* HUM Ch 60.2.20 "CDOCR : Capture Data Output Control Register" p 3662 */
725 volatile uint32_t* reg = ra8_ceu_reg32(k_ra8_ceu_off_cdocr);
726 uint32_t current = *reg;
728 if (swap->swap_8_bit) {
729 current |= k_ra8_ceu_cdocr_mask_cobs;
730 }
731 if (swap->swap_16_bit) {
732 current |= k_ra8_ceu_cdocr_mask_cows;
733 }
734 if (swap->swap_32_bit) {
735 current |= k_ra8_ceu_cdocr_mask_cols;
736 }
737 *reg = current;
738 return k_ra8_ok;
739}
740
742{
743 /* HUM Ch 60.2.17 "CBDSR : Capture Bundle Destination Size" p 3660 */
745 return k_ra8_ok;
746}
747
749{
750 /* HUM Ch 60.2.19 "CLFCR : Capture Low-Pass Filter Control" p 3662 */
751 uint32_t value = 0U;
752 if (enable) {
754 }
756 return k_ra8_ok;
757}
758
760{
761 /* HUM Ch 60.2.2 "CAPCR : Capture Control Register" p 3634 */
762 volatile uint32_t* reg = ra8_ceu_reg32(k_ra8_ceu_off_capcr);
763 uint32_t current = *reg;
765 if (mode == k_ra8_ceu_capture_continuous) {
767 }
768 *reg = current;
769 return k_ra8_ok;
770}
771
773{
774 /* HUM Ch 60.2.2 "CAPCR : Capture Control Register" p 3634 */
775 volatile uint32_t* reg = ra8_ceu_reg32(k_ra8_ceu_off_capcr);
776 uint32_t current = *reg;
778 current |= ((uint32_t)count) << k_ra8_ceu_capcr_shift_fdrp;
779 *reg = current;
780 return k_ra8_ok;
781}
782
783ra8_err_t ra8_ceu_dma_pump(uint8_t channel, const uint8_t* src, uint8_t* dst, uint32_t bytes)
784{
785 RA8_CHECK_NULL_PTR(src, s_tag, "src must not be nullptr");
786 RA8_CHECK_NULL_PTR(dst, s_tag, "dst must not be nullptr");
787 if (bytes == 0U) {
789 }
790 if ((bytes & k_ra8_ceu_dma_byte_align_mask) != 0U) {
792 }
793
794 /* The CEU writes pixels with its own bus initiator; the DMAC is only
795 * used by the application-level pump that ferries finished
796 * frames. Configure for word-wide block transfer with both
797 * pointers incrementing. */
798 const ra8_dmac_config_t cfg = {
799 .src = (uint32_t)(uintptr_t)src,
800 .dst = (uint32_t)(uintptr_t)dst,
801 .count = (uint16_t)(bytes >> k_ra8_ceu_dma_count_shift),
802 .width = k_ra8_dmac_width_word,
803 .src_inc = true,
804 .dst_inc = true,
805 };
806 return ra8_dmac_start(channel, &cfg);
807}
808
809/* =============================================================================
810 * Sweep 17: DMA-driven framebuffer + multi-frame capture
811 * =============================================================================
812 */
813
814ra8_err_t ra8_ceu_set_dma_buffer(uint8_t* buf, uint32_t len)
815{
816 RA8_CHECK_NULL_PTR(buf, s_tag, "buf must not be nullptr");
817 if (len == 0U) {
819 }
820 if (((uintptr_t)buf & k_ra8_ceu_buffer_align_mask) != 0U) {
822 }
823 s_ceu_dma_buf = buf;
824 s_ceu_dma_len = len;
825 ra8_log_info_val(s_tag, "ceu_set_dma_buffer len", len);
826 return k_ra8_ok;
827}
828
830{
831 if (s_ceu_dma_buf == nullptr) {
833 }
834 /* HUM Ch 60.2.2 "CAPCR" p 3634-3635 -- CTNCP[16] = 1 selects
835 * continuous capture, 0 selects single-shot. */
836 volatile uint32_t* capcr_reg = ra8_ceu_reg32(k_ra8_ceu_off_capcr);
837 uint32_t capcr = *capcr_reg;
838 if (num_frames == 0U) {
839 capcr |= ((uint32_t)1U << k_ra8_ceu_capcr_shift_ctncp);
840 } else {
841 capcr &= ~((uint32_t)1U << k_ra8_ceu_capcr_shift_ctncp);
842 }
843 *capcr_reg = capcr;
844
846}
847
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
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.
Definition ra8_ceu.c:454
static void * s_ceu_ctx
Opaque context forwarded as the first argument to s_ceu_fn.
Definition ra8_ceu.c:93
ra8_err_t ra8_ceu_capture_mode_set(ra8_ceu_capture_mode_t mode)
Enable or disable continuous-capture mode (CAPCR.CTNCP).
Definition ra8_ceu.c:759
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_capture_stop(void)
Stop the in-flight capture started via ra8_ceu_capture_start.
Definition ra8_ceu.c:848
ra8_err_t ra8_ceu_capture_arm(uint8_t *buffer)
Arm a capture into the supplied buffer.
Definition ra8_ceu.c:521
static ra8_err_t internal_wait_idle(void)
Bounded spin until CSTSR.CPTON and CAPSR.CPKIL both clear.
Definition ra8_ceu.c:153
ra8_err_t ra8_ceu_get_status(uint32_t *out_mask)
Snapshot the CEU event-status register (CETCR).
Definition ra8_ceu.c:362
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.
Definition ra8_ceu.c:814
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.
Definition ra8_ceu.c:783
static void internal_program_addresses(const ra8_ceu_buffers_t *bufs)
Program the CDAYR / CDACR / CDBYR / CDBCR family on Plane A.
Definition ra8_ceu.c:264
ra8_err_t ra8_ceu_byte_swap_set(const ra8_ceu_byte_swap_t *swap)
Replace CDOCR byte-swap configuration in-place.
Definition ra8_ceu.c:721
ra8_err_t ra8_ceu_data_size_get(uint32_t *out_bytes)
Return the byte count written by the last data-enable capture.
Definition ra8_ceu.c:403
static uint8_t * s_ceu_dma_buf
Cached DMAC-target buffer set via ra8_ceu_set_dma_buffer.
Definition ra8_ceu.c:123
static uint32_t s_ceu_dma_len
Cached buffer length (bytes) for the next capture.
Definition ra8_ceu.c:131
static ra8_err_t internal_arm_capture(const ra8_ceu_buffers_t *bufs)
Common arming sequence for capture_start / capture_start_ex.
Definition ra8_ceu.c:478
ra8_err_t ra8_ceu_low_pass_set(bool enable)
Enable or disable the input low-pass filter (CLFCR.LPF).
Definition ra8_ceu.c:748
ra8_err_t ra8_ceu_firewall_set(bool enable, uint32_t upper_bound)
Configure the CFWCR firewall window.
Definition ra8_ceu.c:709
static ra8_ceu_event_fn_t s_ceu_fn
Module-scope event callback registered by ra8_ceu_attach_handler.
Definition ra8_ceu.c:87
ra8_ceu_align_mask_t
Buffer-alignment helper.
Definition ra8_ceu.c:63
@ k_ra8_ceu_buffer_align_mask
RA8 CEU buffer align mask.
Definition ra8_ceu.c:64
ra8_err_t ra8_ceu_plane_swap_force(void)
Force an immediate plane swap (CRCMPR.RA).
Definition ra8_ceu.c:702
static void internal_plane_b_mirror_from_a(void)
Mirror every 3-plane register from Plane A to Plane B.
Definition ra8_ceu.c:594
static uint32_t s_ceu_image_area
Cached image_area_size from the most recent ra8_ceu_init.
Definition ra8_ceu.c:108
void ra8_ceu_dispatch(void)
Drain CEU interrupt events and fire the registered callback.
Definition ra8_ceu.c:427
ra8_err_t ra8_ceu_bundle_size_set(uint32_t size_bytes)
Configure the bundle-write size (CBDSR).
Definition ra8_ceu.c:741
ra8_err_t ra8_ceu_frame_drop_set(uint8_t count)
Update the frame-drop counter (CAPCR.FDRP).
Definition ra8_ceu.c:772
static ra8_ceu_capture_format_t s_ceu_capture_format
Cached CAMCR.JPG copy so capture_start can choose its path.
Definition ra8_ceu.c:114
ra8_err_t ra8_ceu_capture_start(uint32_t num_frames)
Start a single or continuous capture into the cached DMA buffer.
Definition ra8_ceu.c:829
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_plane_b_program(const ra8_ceu_buffers_t *bufs)
Mirror the active configuration into Plane B and arm a swap.
Definition ra8_ceu.c:681
ra8_err_t ra8_ceu_attach_handler(ra8_ceu_event_fn_t fn, void *ctx)
Register a callback invoked by ra8_ceu_dispatch.
Definition ra8_ceu.c:419
ra8_err_t ra8_ceu_interrupts_set(uint32_t mask)
Update the CEIER interrupt-enable bitmask.
Definition ra8_ceu.c:411
ra8_err_t ra8_ceu_capture_disarm(void)
Stop the running capture by clearing CAPSR.CE.
Definition ra8_ceu.c:564
static void internal_plane_b_apply_overrides(const ra8_ceu_buffers_t *bufs)
Apply caller-supplied buffer overrides to Plane B.
Definition ra8_ceu.c:641
ra8_err_t ra8_ceu_reset(void)
Issue a software reset of the capture state machine.
Definition ra8_ceu.c:355
static uint32_t s_ceu_int_enable
Cached copy of CEIER – used to gate the dispatched event mask.
Definition ra8_ceu.c:99
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
static ra8_err_t internal_validate_buffers(const ra8_ceu_buffers_t *bufs)
Validate every non-NULL pointer in a buffer bundle.
Definition ra8_ceu.c:220
static bool internal_is_aligned(const void *ptr)
True if ptr is non-NULL and 8-byte aligned.
Definition ra8_ceu.c:194
ra8_err_t ra8_ceu_enter_stop(void)
Stop active captures and drop the CEU module-stop bit.
Definition ra8_ceu.c:446
ra8_ceu_timing_t
Bounded spin budgets for host + target builds.
Definition ra8_ceu.c:51
@ k_ra8_ceu_reset_spin
CSTSR.CPTON / CAPSR.CPKIL clear spin.
Definition ra8_ceu.c:52
ra8_err_t ra8_ceu_deinit(void)
Stop the CEU and drop its module-stop bit.
Definition ra8_ceu.c:336
ra8_ceu_dma_align_t
DMAC-pump byte-count alignment.
Definition ra8_ceu.c:77
@ k_ra8_ceu_dma_count_shift
divide-by-4 to convert bytes->words.
Definition ra8_ceu.c:79
@ k_ra8_ceu_dma_byte_align_mask
RA8 CEU DMA byte align mask.
Definition ra8_ceu.c:78
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.
Definition ra8_check.h:184
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
8-channel DMA controller (DMAC0) driver
@ k_ra8_dmac_width_word
32-bit transfers (DMTMD.SZ = 10b).
Definition ra8_dmac.h:53
ra8_err_t ra8_dmac_start(uint8_t channel, const ra8_dmac_config_t *cfg)
Programme and enable a DMAC0 channel.
Definition ra8_dmac.c:398
Error Code Definitions for ra8-firmware.
@ k_ra8_err_busy
Resource busy – blocking operation cannot proceed.
Definition ra8_err.h:195
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
Definition ra8_err.h:161
@ k_ra8_err_hw_timeout
Hardware timed out waiting for a flag or handshake.
Definition ra8_err.h:304
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
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.
Definition ra8_log.h:366
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.
Definition ra8_mstp.c:343
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
Definition ra8_mstp.c:382
@ 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.
Definition ra8_dmac.h:121