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#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG == DISABLED
117# define VSF_DAC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG DISABLED
118#endif
119
131#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
132# define VSF_DAC_CFG_REIMPLEMENT_TYPE_CFG DISABLED
133#endif
134
144#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
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, _dac_t) *dac_ptr, vsf_dac_cfg_t *cfg_ptr) \
171 __VSF_HAL_TEMPLATE_API(__prefix_name, void, dac, fini, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr) \
172 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, dac, enable, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr) \
173 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, dac, disable, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr) \
174 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_dac_status_t, dac, status, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr) \
175 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_dac_capability_t, dac, capability, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr) \
176 __VSF_HAL_TEMPLATE_API(__prefix_name, void, dac, irq_enable, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr, vsf_dac_irq_mask_t irq_mask) \
177 __VSF_HAL_TEMPLATE_API(__prefix_name, void, dac, irq_disable, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr, vsf_dac_irq_mask_t irq_mask) \
178 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, channel_request_once, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr, vsf_dac_channel_cfg_t *cfg, uint_fast16_t value) \
179 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, channel_config, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr, vsf_dac_channel_cfg_t *cfgs_ptr, uint_fast8_t cnt) \
180 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, channel_request, VSF_MCONNECT(__prefix_name, _dac_t) *dac_ptr, void *values_ptr, uint_fast32_t cnt)
181
182/*============================ TYPES =========================================*/
183
184#if VSF_DAC_CFG_REIMPLEMENT_TYPE_IRQ_MASK == DISABLED
198typedef enum vsf_dac_irq_mask_t {
199 VSF_DAC_IRQ_MASK_IDLE = (0x01ul << 0),
200 VSF_DAC_IRQ_MASK_CPL = (0x1ul << 0),
202#endif
203
204enum {
207};
208
210#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG == DISABLED
218typedef struct vsf_dac_channel_cfg_t {
222#endif
223
224#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
225typedef struct vsf_dac_t vsf_dac_t;
226
240typedef void vsf_dac_isr_handler_t(void *target_ptr, vsf_dac_t *dac_ptr, vsf_dac_irq_mask_t irq_mask);
241
249typedef struct vsf_dac_isr_t {
254
262typedef struct vsf_dac_cfg_t {
265#endif
266
267#if VSF_DAC_CFG_REIMPLEMENT_TYPE_STATUS == DISABLED
275typedef struct vsf_dac_status_t {
276 union {
278 struct {
279 uint32_t is_busy : 1;
280 };
281 };
283#endif
284
285#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
293typedef struct vsf_dac_capability_t {
294#if VSF_DAC_CFG_INHERIT_HAL_CAPABILITY == ENABLED
296#endif
302#endif
303
304typedef struct vsf_dac_op_t {
306#undef __VSF_HAL_TEMPLATE_API
307#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
309
310 VSF_DAC_APIS(vsf)
312
313#if VSF_DAC_CFG_MULTI_CLASS == ENABLED
314struct vsf_dac_t {
316};
317#endif
318
319/*============================ PROTOTYPES ====================================*/
320
340extern vsf_err_t vsf_dac_init(vsf_dac_t *dac_ptr, vsf_dac_cfg_t *cfg_ptr);
341
353extern void vsf_dac_fini(vsf_dac_t *dac_ptr);
354
366extern fsm_rt_t vsf_dac_enable(vsf_dac_t *dac_ptr);
367
379extern fsm_rt_t vsf_dac_disable(vsf_dac_t *dac_ptr);
380
397
412
425
438
439
456 vsf_dac_channel_cfg_t *channel_cfg,
458
475 vsf_dac_channel_cfg_t *cfgs_ptr,
476 uint_fast8_t cnt);
477
494 void *buffer_ptr,
495 uint_fast32_t count);
496
497/*============================ MACROFIED FUNCTIONS ===========================*/
498
500#if VSF_DAC_CFG_FUNCTION_RENAME == ENABLED
501# define __vsf_dac_t VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_t)
502# define vsf_dac_init(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_init) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
503# define vsf_dac_fini(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_fini) ((__vsf_dac_t *)(__DAC))
504# define vsf_dac_enable(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_enable) ((__vsf_dac_t *)(__DAC))
505# define vsf_dac_disable(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_disable) ((__vsf_dac_t *)(__DAC))
506# define vsf_dac_status(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_status) ((__vsf_dac_t *)(__DAC))
507# define vsf_dac_capability(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_capability) ((__vsf_dac_t *)(__DAC))
508# define vsf_dac_irq_enable(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_irq_enable) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
509# define vsf_dac_irq_disable(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_irq_disable) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
510# define vsf_dac_channel_request_once(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_channel_request_once) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
511# define vsf_dac_channel_config(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_channel_config) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
512# define vsf_dac_channel_request(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_channel_request) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
513#endif
515
516#ifdef __cplusplus
517}
518#endif
519
520#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:132
vsf_dac_irq_mask_t
Definition dac.h:113
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:293
uint8_t min_resolution_bits
Minimum resolution bits.
Definition vsf_template_dac.h:299
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:300
uint8_t max_resolution_bits
Maximum resolution bits.
Definition vsf_template_dac.h:298
DAC configuration structure.
Definition vsf_template_dac.h:262
vsf_dac_isr_t isr
Interrupt configuration.
Definition vsf_template_dac.h:263
dac channel configuration
Definition vsf_template_dac.h:218
uint8_t channel
Channel index.
Definition vsf_template_dac.h:219
uint8_t resolution
Channel resolution.
Definition vsf_template_dac.h:220
DAC interrupt configuration structure.
Definition vsf_template_dac.h:249
vsf_dac_isr_handler_t * handler_fn
Interrupt handler.
Definition vsf_template_dac.h:250
void * target_ptr
User target pointer.
Definition vsf_template_dac.h:251
vsf_arch_prio_t prio
Interrupt priority.
Definition vsf_template_dac.h:252
Definition vsf_template_dac.h:304
DAC status structure that can be reimplemented in specific HAL drivers.
Definition vsf_template_dac.h:275
Definition vsf_template_dac.h:314
const vsf_dac_op_t * op
Definition vsf_template_dac.h:315
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:240
struct vsf_dac_cfg_t vsf_dac_cfg_t
DAC configuration structure.
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:198
@ VSF_DAC_IRQ_MASK_IDLE
DAC is idle.
Definition vsf_template_dac.h:199
@ VSF_DAC_IRQ_MASK_CPL
DAC transfer complete.
Definition vsf_template_dac.h:200
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:128
vsf_dac_status_t vsf_dac_status(vsf_dac_t *dac_ptr)
Get the status of DAC instance.
Definition dac_common.c:92
#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_DAC_IRQ_ALL_BITS_MASK
Definition vsf_template_dac.h:206
@ VSF_DAC_IRQ_COUNT
Definition vsf_template_dac.h:205
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:119
fsm_rt_t vsf_dac_disable(vsf_dac_t *dac_ptr)
Disable a DAC instance.
Definition dac_common.c:65
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:83
fsm_rt_t vsf_dac_enable(vsf_dac_t *dac_ptr)
Enable a DAC instance.
Definition dac_common.c:56
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_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:110
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:74
vsf_dac_capability_t vsf_dac_capability(vsf_dac_t *dac_ptr)
Get the capability of DAC instance.
Definition dac_common.c:101
Generated from commit: vsfteam/vsf@2b286be