|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Generic DMA transfer substrate (DMAC engine). More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_dma_request_t |
| Descriptor for a single DMA transfer. More... | |
Typedefs | |
| typedef void(* | ra8_dma_complete_fn_t) (void *ctx) |
| Caller-supplied completion callback. | |
Enumerations | |
| enum | ra8_dma_channel_count_t : uint8_t { k_ra8_dma_channel_count = 8U } |
| Number of channels the DMAC backend exposes. More... | |
| enum | ra8_dma_invalid_channel_t : uint8_t { k_ra8_dma_channel_none = 0xFFU } |
| Sentinel for "no channel allocated". More... | |
Functions | |
| ra8_err_t | ra8_dma_init (void) |
| Initialise the DMA substrate. | |
| ra8_err_t | ra8_dma_deinit (void) |
| Release the DMA substrate. | |
| ra8_err_t | ra8_dma_request (const ra8_dma_request_t *req, uint8_t *out_channel) |
| Allocate a DMAC channel, programme it, and start the trigger wiring. | |
| ra8_err_t | ra8_dma_release (uint8_t channel) |
| Stop a channel and return it to the free pool. | |
| ra8_err_t | ra8_dma_channel_is_busy (uint8_t channel, bool *out_busy) |
| Query the allocation state of a channel. | |
| void | ra8_dma_dispatch_complete (uint8_t channel) |
| Dispatch a transfer-end completion callback for one channel. | |
Generic DMA transfer substrate (DMAC engine).
Ring 3 / HAL substrate. Sits on top of ra8_dmac and exposes a driver-friendly API that hides free-channel allocation and completion-interrupt wiring behind a single ra8_dma_request call.
Drivers call ra8_dma_request with a descriptor that says "I want bytes moved from A to B when ELC event E fires". The substrate:
ra8_dma_release tears a channel down: stops the channel, unregisters the completion interrupt, and returns the channel to the free pool.
The DTC has its own lifecycle + request model (install a vector table, enable, let activation events drive transfers); callers that need DTC semantics use ra8_dtc_* directly rather than going through this substrate.
Single-threaded init context only. Completion callbacks run in ISR context and must not call back into ra8_dma_request.
Definition in file ra8_dma.h.
| typedef void(* ra8_dma_complete_fn_t) (void *ctx) |
| enum ra8_dma_channel_count_t : uint8_t |
| enum ra8_dma_invalid_channel_t : uint8_t |
|
nodiscard |
Query the allocation state of a channel.
Diagnostic accessor used by unit tests to verify the allocator state. Returns true if the channel is currently in use.
| [in] | channel | Channel number 0..k_ra8_dma_channel_count - 1. |
| [out] | out_busy | On success, true if allocated. |
| k_ra8_ok | Query successful. |
| k_ra8_err_null_ptr | out_busy NULL. |
| k_ra8_err_invalid_arg | channel out of range. |
Definition at line 428 of file ra8_dma.c.
References k_ra8_dma_channel_count, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, s_channels, and s_tag.
|
nodiscard |
Release the DMA substrate.
Stops every in-use channel, then drops the MSTP reference. Used by tests; production code rarely tears this down.
| k_ra8_ok | Substrate torn down. |
| k_ra8_err_hw_error | ra8_mstp_disable underflow. |
Release the DMA substrate.
Stops every in-use channel via ra8_dmac_stop(), clears the dispatch table, and releases the MSTPA22 reference (HUM Ch 11.2.6, p 443). After this returns ra8_dma_request() rejects with k_ra8_err_not_initialized.
| k_ra8_ok | All channels stopped and MSTP released. |
| k_ra8_err_hw_error | Underlying ra8_mstp_disable() failed. |
Definition at line 257 of file ra8_dma.c.
References k_ra8_dma_channel_count, k_ra8_err_hw_error, k_ra8_mstp_dmac0_dtc0, k_ra8_ok, ra8_dmac_stop(), ra8_log_error_val, ra8_mstp_disable(), s_channels, s_initialized, and s_tag.
| void ra8_dma_dispatch_complete | ( | uint8_t | channel | ) |
Dispatch a transfer-end completion callback for one channel.
Called from the DMAC IRQ trampoline when a channel finishes. Looks up the caller-supplied on_complete and invokes it with the stored context. Tests can call this function directly to simulate DMA completion without running real hardware.
| [in] | channel | Channel whose completion just fired. |
Dispatch a transfer-end completion callback for one channel.
Looks up the stashed callback / context for channel and invokes the callback if non-NULL. Called from the DMAC IRQ trampoline (or from a unit-test driver in off-target mode). Out-of-range channels are silently ignored.
| [in] | channel | Channel whose completion just fired. |
Definition at line 458 of file ra8_dma.c.
References k_ra8_dma_channel_count, and s_channels.
|
nodiscard |
Initialise the DMA substrate.
Requests MSTPCRA.MSTPA22 via ra8_mstp_enable(k_ra8_mstp_dmac0_dtc0) (so the DMAC is clocked), zeroes the internal channel-allocation table, and returns. Does NOT programme any channel. Callers follow with ra8_dma_request() to kick off actual transfers.
| k_ra8_ok | Substrate ready. |
| k_ra8_err_hw_init_failed | ra8_mstp_enable failed. |
Initialise the DMA substrate.
Enables MSTPA22 (shared with DTC0, HUM Ch 11.2.6 "MSTPCRA : Module Stop Control Register A", p 443) and clears every entry in the channel-allocation / dispatch table. After this returns ra8_dma_request() may allocate channels.
| k_ra8_ok | Channel table reset and MSTP gate opened. |
| k_ra8_err_hw_init_failed | Underlying ra8_mstp_enable() failed. |
Definition at line 215 of file ra8_dma.c.
References k_ra8_dma_channel_count, k_ra8_err_hw_init_failed, k_ra8_mstp_dmac0_dtc0, k_ra8_ok, ra8_log_error_val, ra8_log_info, ra8_mstp_enable(), s_channels, s_initialized, and s_tag.
Referenced by internal_setup_or_halt(), and ra8_nsc_periph_init().
|
nodiscard |
Stop a channel and return it to the free pool.
| [in] | channel | Channel number returned by ra8_dma_request. |
| k_ra8_ok | Channel released. |
| k_ra8_err_invalid_arg | channel out of range. |
| k_ra8_err_invalid_state | Channel was not allocated. |
Stop a channel and return it to the free pool.
Calls ra8_dmac_stop() to disable the channel at the hardware level, then clears the dispatch entry. The MSTP reference held by the substrate root is preserved – only ra8_dma_deinit() releases it.
| [in] | channel | Channel previously returned by ra8_dma_request(). |
| k_ra8_ok | Channel released. |
| k_ra8_err_invalid_arg | channel >= k_ra8_dma_channel_count. |
| k_ra8_err_invalid_state | Channel was not in use. |
| k_ra8_err_hw_error | ra8_dmac_stop() failed. |
Definition at line 370 of file ra8_dma.c.
References k_ra8_dma_channel_count, k_ra8_err_hw_error, k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_ok, ra8_dmac_stop(), ra8_log_error_val, s_channels, and s_tag.
Referenced by internal_run_one().
|
nodiscard |
Allocate a DMAC channel, programme it, and start the trigger wiring.
| [in] | req | Transfer descriptor. engine must be k_ra8_dma_engine_dmac. |
| [out] | out_channel | On success, the allocated DMAC channel number in the range [0, k_ra8_dma_channel_count). |
| k_ra8_ok | Transfer programmed and armed. |
| k_ra8_err_null_ptr | req or out_channel NULL. |
| k_ra8_err_invalid_arg | engine unsupported, count zero, or width out of range. |
| k_ra8_err_no_mem | All DMAC channels in use. |
| k_ra8_err_hw_error | Underlying ra8_dmac_start failed. |
Allocate a DMAC channel, programme it, and start the trigger wiring.
Validates *req, finds a free channel via internal_find_free(), packs a ra8_dmac_config_t and calls ra8_dmac_start(). On success the channel index is written through out_channel and the caller-supplied completion callback is stashed for later dispatch.
| [in] | req | Transfer descriptor (non-NULL). |
| [out] | out_channel | Allocated channel index (non-NULL). |
| k_ra8_ok | Channel allocated and DMAC armed. |
| k_ra8_err_invalid_arg | req malformed. |
| k_ra8_err_not_initialized | ra8_dma_init() was not called. |
| k_ra8_err_no_mem | No free channel. |
| k_ra8_err_hw_error | ra8_dmac_start() failed. |
Definition at line 308 of file ra8_dma.c.
References ra8_dma_request_t::ctx, internal_find_free(), internal_pack_dmac_cfg(), internal_validate_request(), k_ra8_dma_channel_none, k_ra8_err_hw_error, k_ra8_err_no_mem, k_ra8_err_not_initialized, k_ra8_ok, ra8_dma_request_t::on_complete, RA8_CHECK_NULL_PTR, ra8_dmac_start(), ra8_log_error, ra8_log_error_val, s_channels, s_initialized, and s_tag.
Referenced by ra8_gpt_read_dma(), ra8_gpt_write_dma(), ra8_sci_read_dma(), ra8_sci_write_dma(), ra8_spi_read_dma(), and ra8_spi_write_dma().