VSF Documented
vsf_template_dac.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_TEMPLATE_DAC_H__
19#define __VSF_TEMPLATE_DAC_H__
20
21/*============================ INCLUDES ======================================*/
22
24#include "hal/arch/vsf_arch.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*============================ MACROS ========================================*/
31
39#ifndef VSF_DAC_CFG_MULTI_CLASS
40# define VSF_DAC_CFG_MULTI_CLASS ENABLED
41#endif
42
50#if defined(VSF_HW_DAC_COUNT) && !defined(VSF_HW_DAC_MASK)
51# define VSF_HW_DAC_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_DAC_COUNT)
52#endif
53
61#if defined(VSF_HW_DAC_MASK) && !defined(VSF_HW_DAC_COUNT)
62# define VSF_HW_DAC_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_DAC_MASK)
63#endif
64
73#ifndef VSF_DAC_CFG_PREFIX
74# if VSF_DAC_CFG_MULTI_CLASS == ENABLED
75# define VSF_DAC_CFG_PREFIX vsf
76# elif defined(VSF_HW_DAC_COUNT) && (VSF_HW_DAC_COUNT != 0)
77# define VSF_DAC_CFG_PREFIX vsf_hw
78# else
79# define VSF_DAC_CFG_PREFIX vsf
80# endif
81#endif
82
92#ifndef VSF_DAC_CFG_FUNCTION_RENAME
93# define VSF_DAC_CFG_FUNCTION_RENAME ENABLED
94#endif
95
103#ifndef VSF_DAC_CFG_REIMPLEMENT_TYPE_IRQ_MASK
104# define VSF_DAC_CFG_REIMPLEMENT_TYPE_IRQ_MASK DISABLED
105#endif
106
116#ifndef VSF_DAC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG
117# define VSF_DAC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG DISABLED
118#endif
119
131#ifndef VSF_DAC_CFG_REIMPLEMENT_TYPE_CFG
132# define VSF_DAC_CFG_REIMPLEMENT_TYPE_CFG DISABLED
133#endif
134
144#ifndef VSF_DAC_CFG_REIMPLEMENT_TYPE_CAPABILITY
145# define VSF_DAC_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
146#endif
147
154#ifndef VSF_DAC_CFG_INHERIT_HAL_CAPABILITY
155# define VSF_DAC_CFG_INHERIT_HAL_CAPABILITY ENABLED
156#endif
157
158/*============================ MACROFIED FUNCTIONS ===========================*/
159
169#define VSF_DAC_APIS(__prefix_name) \
170 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, init, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_cfg_t *cfg_ptr) \
171 __VSF_HAL_TEMPLATE_API(__prefix_name, void, dac, fini, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
172 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, get_configuration, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_cfg_t *cfg_ptr) \
173 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, dac, enable, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
174 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, dac, disable, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
175 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_dac_status_t, dac, status, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
176 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_dac_capability_t, dac, capability, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
177 __VSF_HAL_TEMPLATE_API(__prefix_name, void, dac, irq_enable, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_irq_mask_t irq_mask) \
178 __VSF_HAL_TEMPLATE_API(__prefix_name, void, dac, irq_disable, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_irq_mask_t irq_mask) \
179 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, channel_request_once, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_channel_cfg_t *cfg, uint_fast16_t value) \
180 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, channel_config, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_channel_cfg_t *cfgs_ptr, uint_fast8_t cnt) \
181 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, channel_request, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, void *values_ptr, uint_fast32_t cnt)
182
183/*============================ TYPES =========================================*/
184
185#if VSF_DAC_CFG_REIMPLEMENT_TYPE_IRQ_MASK == DISABLED
199typedef enum vsf_dac_irq_mask_t {
200 VSF_DAC_IRQ_MASK_IDLE = (0x01ul << 0),
201 VSF_DAC_IRQ_MASK_CPL = (0x1ul << 0),
203#endif
204
205enum {
208};
209
211#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG == DISABLED
219typedef struct vsf_dac_channel_cfg_t {
223#endif
224
225#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
226typedef struct vsf_dac_t vsf_dac_t;
227
241typedef void vsf_dac_isr_handler_t(void *target_ptr, vsf_dac_t *dac_ptr, vsf_dac_irq_mask_t irq_mask);
242
250typedef struct vsf_dac_isr_t {
255
263typedef struct vsf_dac_cfg_t {
266#endif
267
268#if VSF_DAC_CFG_REIMPLEMENT_TYPE_STATUS == DISABLED
276typedef struct vsf_dac_status_t {
277 union {
279 struct {
280 uint32_t is_busy : 1;
281 };
282 };
284#endif
285
286#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
294typedef struct vsf_dac_capability_t {
295#if VSF_DAC_CFG_INHERIT_HAL_CAPABILITY == ENABLED
297#endif
303#endif
304
305typedef struct vsf_dac_op_t {
307#undef __VSF_HAL_TEMPLATE_API
308#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
310
311 VSF_DAC_APIS(vsf_dac)
313
314#if VSF_DAC_CFG_MULTI_CLASS == ENABLED
315struct vsf_dac_t {
317};
318#endif
319
320/*============================ PROTOTYPES ====================================*/
321
341extern vsf_err_t vsf_dac_init(vsf_dac_t *dac_ptr, vsf_dac_cfg_t *cfg_ptr);
342
354extern void vsf_dac_fini(vsf_dac_t *dac_ptr);
355
374
386extern fsm_rt_t vsf_dac_enable(vsf_dac_t *dac_ptr);
387
399extern fsm_rt_t vsf_dac_disable(vsf_dac_t *dac_ptr);
400
417
432
445
458
459
476 vsf_dac_channel_cfg_t *channel_cfg,
478
495 vsf_dac_channel_cfg_t *cfgs_ptr,
496 uint_fast8_t cnt);
497
514 void *buffer_ptr,
515 uint_fast32_t count);
516
517/*============================ MACROFIED FUNCTIONS ===========================*/
518
520#if VSF_DAC_CFG_FUNCTION_RENAME == ENABLED
521# define __vsf_dac_t VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_t)
522# define vsf_dac_init(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_init) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
523# define vsf_dac_fini(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_fini) ((__vsf_dac_t *)(__DAC))
524# define vsf_dac_get_configuration(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_get_configuration) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
525# define vsf_dac_enable(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_enable) ((__vsf_dac_t *)(__DAC))
526# define vsf_dac_disable(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_disable) ((__vsf_dac_t *)(__DAC))
527# define vsf_dac_status(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_status) ((__vsf_dac_t *)(__DAC))
528# define vsf_dac_capability(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_capability) ((__vsf_dac_t *)(__DAC))
529# define vsf_dac_irq_enable(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_irq_enable) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
530# define vsf_dac_irq_disable(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_irq_disable) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
531# define vsf_dac_channel_request_once(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_channel_request_once) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
532# define vsf_dac_channel_config(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_channel_config) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
533# define vsf_dac_channel_request(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_channel_request) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
534#endif
536
537#ifdef __cplusplus
538}
539#endif
540
541#endif /*__VSF_TEMPLATE_DAC_H__*/
vsf_err_t
Definition __type.h:42
vsf_arch_prio_t
Definition cortex_a_generic.h:88
void vsf_dac_isr_handler_t(void *target_ptr, vsf_dac_t *dac_ptr, vsf_dac_irq_mask_t irq_mask)
Definition dac.h:130
vsf_dac_irq_mask_t
Definition dac.h:111
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned char uint_fast8_t
Definition stdint.h:23
unsigned uint32_t
Definition stdint.h:9
unsigned int uint_fast32_t
Definition stdint.h:27
unsigned short uint_fast16_t
Definition stdint.h:25
unsigned char uint8_t
Definition stdint.h:5
DAC capability structure that can be reimplemented in specific HAL drivers.
Definition vsf_template_dac.h:294
uint8_t min_resolution_bits
Minimum resolution bits.
Definition vsf_template_dac.h:300
inherit(vsf_peripheral_capability_t) vsf_dac_irq_mask_t irq_mask
Supported interrupts.
uint8_t channel_count
Number of channels.
Definition vsf_template_dac.h:301
uint8_t max_resolution_bits
Maximum resolution bits.
Definition vsf_template_dac.h:299
DAC configuration structure.
Definition vsf_template_dac.h:263
vsf_dac_isr_t isr
Interrupt configuration.
Definition vsf_template_dac.h:264
dac channel configuration
Definition vsf_template_dac.h:219
uint8_t channel
Channel index.
Definition vsf_template_dac.h:220
uint8_t resolution
Channel resolution.
Definition vsf_template_dac.h:221
DAC interrupt configuration structure.
Definition vsf_template_dac.h:250
vsf_dac_isr_handler_t * handler_fn
Interrupt handler.
Definition vsf_template_dac.h:251
void * target_ptr
User target pointer.
Definition vsf_template_dac.h:252
vsf_arch_prio_t prio
Interrupt priority.
Definition vsf_template_dac.h:253
Definition vsf_template_dac.h:305
DAC status structure that can be reimplemented in specific HAL drivers.
Definition vsf_template_dac.h:276
Definition vsf_template_dac.h:315
const vsf_dac_op_t * op
Definition vsf_template_dac.h:316
Definition vsf_template_hal_driver.h:203
Definition vsf_template_hal_driver.h:196
vk_av_control_value_t value
Definition vsf_audio.h:171
fsm_rt_t
Definition vsf_fsm.h:315
void vsf_dac_isr_handler_t(void *target_ptr, vsf_dac_t *dac_ptr, vsf_dac_irq_mask_t irq_mask)
DAC interrupt handler function type.
Definition vsf_template_dac.h:241
struct vsf_dac_cfg_t vsf_dac_cfg_t
DAC configuration structure.
@ VSF_DAC_IRQ_ALL_BITS_MASK
Definition vsf_template_dac.h:207
@ VSF_DAC_IRQ_COUNT
Definition vsf_template_dac.h:206
struct vsf_dac_isr_t vsf_dac_isr_t
DAC interrupt configuration structure.
vsf_err_t vsf_dac_init(vsf_dac_t *dac_ptr, vsf_dac_cfg_t *cfg_ptr)
Initialize a DAC instance.
Definition dac_common.c:38
vsf_dac_irq_mask_t
Predefined VSF DAC interrupts that can be reimplemented in specific HAL drivers. Even if the hardware...
Definition vsf_template_dac.h:199
@ VSF_DAC_IRQ_MASK_IDLE
DAC is idle.
Definition vsf_template_dac.h:200
@ VSF_DAC_IRQ_MASK_CPL
DAC transfer complete.
Definition vsf_template_dac.h:201
vsf_err_t vsf_dac_channel_request(vsf_dac_t *dac_ptr, void *buffer_ptr, uint_fast32_t count)
DAC channel request.
Definition dac_common.c:138
vsf_dac_status_t vsf_dac_status(vsf_dac_t *dac_ptr)
Get the status of DAC instance.
Definition dac_common.c:102
#define VSF_DAC_APIS(__prefix_name)
DAC API template, used to generate DAC type, specific prefix function declarations,...
Definition vsf_template_dac.h:169
vsf_err_t vsf_dac_channel_config(vsf_dac_t *dac_ptr, vsf_dac_channel_cfg_t *cfgs_ptr, uint_fast8_t cnt)
DAC channel configuration.
Definition dac_common.c:129
fsm_rt_t vsf_dac_disable(vsf_dac_t *dac_ptr)
Disable a DAC instance.
Definition dac_common.c:75
void vsf_dac_irq_disable(vsf_dac_t *dac_ptr, vsf_dac_irq_mask_t irq_mask)
Disable interrupt masks of DAC instance.
Definition dac_common.c:93
fsm_rt_t vsf_dac_enable(vsf_dac_t *dac_ptr)
Enable a DAC instance.
Definition dac_common.c:66
void vsf_dac_fini(vsf_dac_t *dac_ptr)
Finalize a DAC instance.
Definition dac_common.c:47
struct vsf_dac_status_t vsf_dac_status_t
DAC status structure that can be reimplemented in specific HAL drivers.
vsf_err_t vsf_dac_get_configuration(vsf_dac_t *dac_ptr, vsf_dac_cfg_t *cfg_ptr)
Get current configuration of a DAC instance.
Definition dac_common.c:56
vsf_err_t vsf_dac_channel_request_once(vsf_dac_t *dac_ptr, vsf_dac_channel_cfg_t *channel_cfg, uint_fast16_t value)
DAC request convert once.
Definition dac_common.c:120
struct vsf_dac_capability_t vsf_dac_capability_t
DAC capability structure that can be reimplemented in specific HAL drivers.
void vsf_dac_irq_enable(vsf_dac_t *dac_ptr, vsf_dac_irq_mask_t irq_mask)
Enable interrupt masks of DAC instance.
Definition dac_common.c:84
vsf_dac_capability_t vsf_dac_capability(vsf_dac_t *dac_ptr)
Get the capability of DAC instance.
Definition dac_common.c:111
Generated from commit: vsfteam/vsf@74aa6ce