caffeine-hal 0.6.6
A Header-Defined Interface c library, it provides the hal layer for the Caffeine framework
Loading...
Searching...
No Matches
cfn_hal_dma.h
Go to the documentation of this file.
1
26#ifndef CAFFEINE_HAL_HAL_DMA_H
27#define CAFFEINE_HAL_HAL_DMA_H
28
29#ifdef __cplusplus
30extern "C"
31{
32#endif
33
34/* Includes ---------------------------------------------------------*/
35#include "cfn_hal.h"
36#include "cfn_hal_base.h"
37#include "cfn_hal_types.h"
38
39/* Defines ----------------------------------------------------------*/
40
41/* Types Enums ------------------------------------------------------*/
42
52
62
63/* Types Structs ----------------------------------------------------*/
64
68typedef struct
69{
70 uint32_t src_addr;
71 uint32_t dst_addr;
72 uint32_t length;
74
78typedef struct
79{
80 uint32_t direction;
81 uint32_t priority;
82 void *custom;
84
88typedef struct
89{
90 void *instance;
91 void *user_arg;
93
94typedef struct cfn_hal_dma_s cfn_hal_dma_t;
96
104typedef void (*cfn_hal_dma_callback_t)(cfn_hal_dma_t *driver, uint32_t event_mask, uint32_t error_mask, void *user_arg);
105
110{
112
113 /* DMA Specific Extensions */
116};
118
120/* Functions inline ------------------------------------------------- */
122 uint32_t peripheral_id,
123 struct cfn_hal_clock_s *clock,
124 void *dependency,
125 const cfn_hal_dma_api_t *api,
126 const cfn_hal_dma_phy_t *phy,
127 const cfn_hal_dma_config_t *config,
128 cfn_hal_dma_callback_t callback,
129 void *user_arg)
130{
132 driver, CFN_HAL_PERIPHERAL_TYPE_DMA, peripheral_id, clock, dependency, api, phy, config, callback, user_arg);
133}
134
142 const cfn_hal_dma_config_t *config)
143{
144 if (driver == NULL || config == NULL)
145 {
147 }
148
149 return cfn_hal_base_config_validate(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA, config);
150}
151
158{
159 if (!driver)
160 {
162 }
163 driver->base.vmt = (const struct cfn_hal_api_base_s *) driver->api;
164 cfn_hal_error_code_t error = cfn_hal_dma_config_validate(driver, driver->config);
165 if (error != CFN_HAL_ERROR_OK)
166 {
167 return error;
168 }
169 return cfn_hal_base_init(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA);
170}
171
178{
179 if (!driver)
180 {
182 }
184}
185
193{
194 if (!driver)
195 {
197 }
199 if (error != CFN_HAL_ERROR_OK)
200 {
201 return error;
202 }
203 {
204 driver->config = config;
205 }
206 return cfn_hal_base_config_set(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA, (const void *) config);
207}
208
216{
217 if (!driver || !config || !driver->config)
218 {
220 }
221 *config = *(driver->config);
222 return CFN_HAL_ERROR_OK;
223}
224
233 const cfn_hal_dma_callback_t callback,
234 void *user_arg)
235{
236 if (!driver)
237 {
239 }
240 {
241 driver->cb = callback;
242 driver->cb_user_arg = user_arg;
243 }
245 &driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA, (cfn_hal_callback_t) callback, user_arg);
246}
247
262
270{
271 if (!driver)
272 {
274 }
275 return cfn_hal_base_event_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA, event_mask);
276}
277
285{
286 if (!driver)
287 {
289 }
290 return cfn_hal_base_event_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA, event_mask);
291}
292
300{
301 if (!driver)
302 {
304 }
305 return cfn_hal_base_event_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA, event_mask);
306}
307
315{
316 if (!driver)
317 {
319 }
320 return cfn_hal_base_error_enable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA, error_mask);
321}
322
330{
331 if (!driver)
332 {
334 }
335 return cfn_hal_base_error_disable(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA, error_mask);
336}
337
345{
346 if (!driver)
347 {
349 }
350 return cfn_hal_base_error_get(&driver->base, CFN_HAL_PERIPHERAL_TYPE_DMA, error_mask);
351}
352
353/* DMA Specific Functions ------------------------------------------- */
354
367
380 const cfn_hal_dma_config_t *config,
381 const cfn_hal_dma_phy_t *phy,
382 struct cfn_hal_clock_s *clock,
383 void *dependency,
384 cfn_hal_dma_callback_t callback,
385 void *user_arg);
387#ifdef __cplusplus
388}
389#endif
390
391#endif // CAFFEINE_HAL_HAL_DMA_H
Core Hardware Abstraction Layer definitions and macros.
#define CFN_HAL_CHECK_AND_CALL_FUNC_VARG(expected_peripheral_type, func, driver, result,...)
Definition cfn_hal.h:134
#define CFN_HAL_CHECK_AND_CALL_FUNC(expected_peripheral_type, func, driver, result)
Definition cfn_hal.h:114
#define CFN_HAL_INLINE
Macro for inlining HAL wrapper functions. Can be overridden with attribute((always_inline)) for perfo...
Definition cfn_hal.h:61
#define CFN_HAL_BIT(x)
Definition cfn_hal.h:79
#define CFN_HAL_CREATE_DRIVER_TYPE(prefix, config_type, api_type, phy_type, cb_type)
Definition cfn_hal.h:102
Base driver Hardware Abstraction Layer declarations.
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_disable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t error_mask)
Generic error disable for any driver. Deactivates exception-flow hardware triggers based on the provi...
Definition cfn_hal_base_impl.h:436
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_callback_register(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, cfn_hal_callback_t callback, void *user_arg)
Generic callback registration for any driver.
Definition cfn_hal_base_impl.h:254
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_enable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t error_mask)
Generic error enable for any driver. Activates exception-flow hardware triggers based on the provided...
Definition cfn_hal_base_impl.h:411
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_enable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t event_mask)
Generic event enable for any driver. Activates nominal hardware triggers based on the provided mask.
Definition cfn_hal_base_impl.h:331
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_get(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t *event_mask)
Generic event status getter for any driver. Retrieves the current nominal hardware triggers/flags.
Definition cfn_hal_base_impl.h:386
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_get(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t *error_mask)
Generic error status getter for any driver. Retrieves current exception-flow hardware flags/errors.
Definition cfn_hal_base_impl.h:461
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_config_set(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, const void *config)
Generic configuration setter for any driver.
Definition cfn_hal_base_impl.h:196
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_power_state_set(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, cfn_hal_power_state_t state)
Generic power state transition for any driver.
Definition cfn_hal_base_impl.h:279
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_deinit(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type)
Generic deinitialization for any driver. Returns the driver to the CONSTRUCTED state and releases boa...
Definition cfn_hal_base_impl.h:144
#define CFN_HAL_VMT_CHECK(api_struct_type)
Compile-time check to ensure a peripheral API struct is compatible with the base layer....
Definition cfn_hal_base.h:91
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_init(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type)
Generic initialization for any driver. Handles board-level hooks, type validation,...
Definition cfn_hal_base_impl.h:85
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_config_validate(const cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, const void *config)
Generic validation for a configuration.
Definition cfn_hal_base_impl.h:234
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_disable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t event_mask)
Generic event disable for any driver. Deactivates nominal hardware triggers based on the provided mas...
Definition cfn_hal_base_impl.h:361
#define CFN_HAL_POPULATE_DRIVER( driver_ptr, periph_type, periph_id, clock_ptr, dep_ptr, api_ptr, phy_ptr, cfg_ptr, cb_func, cb_arg)
Standardizes the population of a peripheral driver structure. This macro ensures that the base driver...
Definition cfn_hal_base_impl.h:45
struct cfn_hal_dma_s cfn_hal_dma_t
Definition cfn_hal_dma.h:94
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_config_validate(const cfn_hal_dma_t *driver, const cfn_hal_dma_config_t *config)
Validates the DMA configuration.
Definition cfn_hal_dma.h:141
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_error_get(cfn_hal_dma_t *driver, uint32_t *error_mask)
Retrieves the current DMA exception error status.
Definition cfn_hal_dma.h:344
cfn_hal_error_code_t cfn_hal_dma_destruct(cfn_hal_dma_t *driver)
Definition cfn_hal_dma_port.c:83
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_config_set(cfn_hal_dma_t *driver, const cfn_hal_dma_config_t *config)
Sets the DMA configuration.
Definition cfn_hal_dma.h:192
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_config_get(cfn_hal_dma_t *driver, cfn_hal_dma_config_t *config)
Gets the current DMA configuration.
Definition cfn_hal_dma.h:215
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_power_state_set(cfn_hal_dma_t *driver, cfn_hal_power_state_t state)
Sets the DMA power state.
Definition cfn_hal_dma.h:254
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_start(cfn_hal_dma_t *driver, const cfn_hal_dma_transfer_t *transfer)
Starts a DMA transfer.
Definition cfn_hal_dma.h:361
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_init(cfn_hal_dma_t *driver)
Initializes the DMA driver.
Definition cfn_hal_dma.h:157
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_callback_register(cfn_hal_dma_t *driver, const cfn_hal_dma_callback_t callback, void *user_arg)
Registers a callback for DMA events and errors.
Definition cfn_hal_dma.h:232
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_deinit(cfn_hal_dma_t *driver)
Deinitializes the DMA driver.
Definition cfn_hal_dma.h:177
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_error_enable(cfn_hal_dma_t *driver, uint32_t error_mask)
Enables one or more DMA exception errors.
Definition cfn_hal_dma.h:314
CFN_HAL_INLINE void cfn_hal_dma_populate(cfn_hal_dma_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_dma_api_t *api, const cfn_hal_dma_phy_t *phy, const cfn_hal_dma_config_t *config, cfn_hal_dma_callback_t callback, void *user_arg)
Definition cfn_hal_dma.h:121
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_event_enable(cfn_hal_dma_t *driver, uint32_t event_mask)
Enables one or more DMA nominal events.
Definition cfn_hal_dma.h:269
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_stop(cfn_hal_dma_t *driver)
Stops an ongoing DMA transfer.
Definition cfn_hal_dma.h:373
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_event_get(cfn_hal_dma_t *driver, uint32_t *event_mask)
Retrieves the current DMA nominal event status.
Definition cfn_hal_dma.h:299
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_error_disable(cfn_hal_dma_t *driver, uint32_t error_mask)
Disables one or more DMA exception errors.
Definition cfn_hal_dma.h:329
cfn_hal_error_code_t cfn_hal_dma_construct(cfn_hal_dma_t *driver, const cfn_hal_dma_config_t *config, const cfn_hal_dma_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_dma_callback_t callback, void *user_arg)
Definition cfn_hal_dma_port.c:67
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_dma_event_disable(cfn_hal_dma_t *driver, uint32_t event_mask)
Disables one or more DMA nominal events.
Definition cfn_hal_dma.h:284
void(* cfn_hal_dma_callback_t)(cfn_hal_dma_t *driver, uint32_t event_mask, uint32_t error_mask, void *user_arg)
DMA callback signature.
Definition cfn_hal_dma.h:104
cfn_hal_dma_event_t
DMA nominal event flags.
Definition cfn_hal_dma.h:47
@ CFN_HAL_DMA_EVENT_TRANSFER_HALF
Definition cfn_hal_dma.h:49
@ CFN_HAL_DMA_EVENT_NONE
Definition cfn_hal_dma.h:48
@ CFN_HAL_DMA_EVENT_TRANSFER_COMPLETE
Definition cfn_hal_dma.h:50
cfn_hal_dma_error_t
DMA exception error flags.
Definition cfn_hal_dma.h:57
@ CFN_HAL_DMA_ERROR_TRANSFER
Definition cfn_hal_dma.h:59
@ CFN_HAL_DMA_ERROR_NONE
Definition cfn_hal_dma.h:58
@ CFN_HAL_DMA_ERROR_GENERAL
Definition cfn_hal_dma.h:60
Common type definitions and enums for the HAL.
void(* cfn_hal_callback_t)(void)
Generic function pointer for HAL callbacks. Used as a standard-compliant carrier in the base layer.
Definition cfn_hal_types.h:98
#define CFN_HAL_PERIPHERAL_TYPE_DMA
Definition cfn_hal_types.h:124
enum cfn_hal_error_codes cfn_hal_error_code_t
cfn_hal_power_state_t
Definition cfn_hal_types.h:156
@ CFN_HAL_ERROR_OK
Definition cfn_hal_types.h:50
@ CFN_HAL_ERROR_BAD_PARAM
Definition cfn_hal_types.h:53
Base API structure for all peripheral drivers. Every peripheral-specific API struct MUST have this as...
Definition cfn_hal_base.h:63
DMA Virtual Method Table (VMT).
Definition cfn_hal_dma.h:110
cfn_hal_api_base_t base
Definition cfn_hal_dma.h:111
cfn_hal_error_code_t(* stop)(cfn_hal_dma_t *driver)
Definition cfn_hal_dma.h:115
cfn_hal_error_code_t(* start)(cfn_hal_dma_t *driver, const cfn_hal_dma_transfer_t *transfer)
Definition cfn_hal_dma.h:114
DMA configuration structure.
Definition cfn_hal_dma.h:79
uint32_t direction
Definition cfn_hal_dma.h:80
uint32_t priority
Definition cfn_hal_dma.h:81
void * custom
Definition cfn_hal_dma.h:82
DMA hardware physical mapping.
Definition cfn_hal_dma.h:89
void * instance
Definition cfn_hal_dma.h:90
void * user_arg
Definition cfn_hal_dma.h:91
DMA transfer configuration.
Definition cfn_hal_dma.h:69
uint32_t length
Definition cfn_hal_dma.h:72
uint32_t dst_addr
Definition cfn_hal_dma.h:71
uint32_t src_addr
Definition cfn_hal_dma.h:70