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
156#ifndef VSF_DAC_CFG_REIMPLEMENT_TYPE_STATUS
157# define VSF_DAC_CFG_REIMPLEMENT_TYPE_STATUS DISABLED
158#endif
159
166#ifndef VSF_DAC_CFG_INHERIT_HAL_CAPABILITY
167# define VSF_DAC_CFG_INHERIT_HAL_CAPABILITY ENABLED
168#endif
169
180#ifndef VSF_DAC_CFG_REIMPLEMENT_TYPE_CTRL
181# define VSF_DAC_CFG_REIMPLEMENT_TYPE_CTRL DISABLED
182#endif
183
184/*============================ MACROFIED FUNCTIONS ===========================*/
185
195#define VSF_DAC_APIS(__prefix_name) \
196 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, init, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_cfg_t *cfg_ptr) \
197 __VSF_HAL_TEMPLATE_API(__prefix_name, void, dac, fini, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
198 __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) \
199 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, dac, enable, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
200 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, dac, disable, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
201 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_dac_status_t, dac, status, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
202 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_dac_capability_t, dac, capability, VSF_MCONNECT(__prefix_name, _t) *dac_ptr) \
203 __VSF_HAL_TEMPLATE_API(__prefix_name, void, dac, irq_enable, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_irq_mask_t irq_mask) \
204 __VSF_HAL_TEMPLATE_API(__prefix_name, void, dac, irq_disable, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_irq_mask_t irq_mask) \
205 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_dac_irq_mask_t, dac, irq_clear, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_irq_mask_t irq_mask) \
206 __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) \
207 __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) \
208 __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) \
209 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, dac, ctrl, VSF_MCONNECT(__prefix_name, _t) *dac_ptr, vsf_dac_ctrl_t ctrl, void* param)
210
211/*============================ TYPES =========================================*/
212
213#if VSF_DAC_CFG_REIMPLEMENT_TYPE_IRQ_MASK == DISABLED
227typedef enum vsf_dac_irq_mask_t {
228 VSF_DAC_IRQ_MASK_IDLE = (0x01ul << 0),
229 VSF_DAC_IRQ_MASK_CPL = (0x01ul << 1),
231#endif
232
233enum {
236};
237
239#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG == DISABLED
247typedef struct vsf_dac_channel_cfg_t {
251#endif
252
253#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
254typedef struct vsf_dac_t vsf_dac_t;
255
269typedef void vsf_dac_isr_handler_t(void *target_ptr, vsf_dac_t *dac_ptr, vsf_dac_irq_mask_t irq_mask);
270
278typedef struct vsf_dac_isr_t {
283
291typedef struct vsf_dac_cfg_t {
294#endif
295
296#if VSF_DAC_CFG_REIMPLEMENT_TYPE_STATUS == DISABLED
304typedef struct vsf_dac_status_t {
305 union {
307 struct {
308 uint32_t is_busy : 1;
309 };
310 };
312#endif
313
314#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
322typedef struct vsf_dac_capability_t {
323#if VSF_DAC_CFG_INHERIT_HAL_CAPABILITY == ENABLED
325#endif
331#endif
332
333#if VSF_DAC_CFG_REIMPLEMENT_TYPE_CTRL == DISABLED
342typedef enum vsf_dac_ctrl_t {
362#endif
363
364typedef struct vsf_dac_op_t {
366#undef __VSF_HAL_TEMPLATE_API
367#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
369
370 VSF_DAC_APIS(vsf_dac)
372
373#if VSF_DAC_CFG_MULTI_CLASS == ENABLED
374struct vsf_dac_t {
376};
377#endif
378
379/*============================ PROTOTYPES ====================================*/
380
400extern vsf_err_t vsf_dac_init(vsf_dac_t *dac_ptr, vsf_dac_cfg_t *cfg_ptr);
401
413extern void vsf_dac_fini(vsf_dac_t *dac_ptr);
414
433
445extern fsm_rt_t vsf_dac_enable(vsf_dac_t *dac_ptr);
446
458extern fsm_rt_t vsf_dac_disable(vsf_dac_t *dac_ptr);
459
476
491
518
531
544
545
562 vsf_dac_channel_cfg_t *channel_cfg,
564
581 vsf_dac_channel_cfg_t *cfgs_ptr,
582 uint_fast8_t cnt);
583
600 void *buffer_ptr,
601 uint_fast32_t count);
602
618extern vsf_err_t vsf_dac_ctrl(vsf_dac_t *dac_ptr, vsf_dac_ctrl_t ctrl, void * param);
619
620/*============================ MACROFIED FUNCTIONS ===========================*/
621
623#if VSF_DAC_CFG_FUNCTION_RENAME == ENABLED
624# define __vsf_dac_t VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_t)
625# define vsf_dac_init(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_init) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
626# define vsf_dac_fini(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_fini) ((__vsf_dac_t *)(__DAC))
627# define vsf_dac_get_configuration(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_get_configuration) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
628# define vsf_dac_enable(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_enable) ((__vsf_dac_t *)(__DAC))
629# define vsf_dac_disable(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_disable) ((__vsf_dac_t *)(__DAC))
630# define vsf_dac_status(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_status) ((__vsf_dac_t *)(__DAC))
631# define vsf_dac_capability(__DAC) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_capability) ((__vsf_dac_t *)(__DAC))
632# define vsf_dac_irq_enable(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_irq_enable) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
633# define vsf_dac_irq_disable(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_irq_disable) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
634# define vsf_dac_irq_clear(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_irq_clear) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
635# define vsf_dac_channel_request_once(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_channel_request_once) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
636# define vsf_dac_channel_config(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_channel_config) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
637# define vsf_dac_channel_request(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_channel_request) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
638# define vsf_dac_ctrl(__DAC, ...) VSF_MCONNECT(VSF_DAC_CFG_PREFIX, _dac_ctrl) ((__vsf_dac_t *)(__DAC), ##__VA_ARGS__)
639#endif
641
642#ifdef __cplusplus
643}
644#endif
645
646#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:144
vsf_dac_irq_mask_t
Definition dac.h:115
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:322
uint8_t min_resolution_bits
Minimum resolution bits.
Definition vsf_template_dac.h:328
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:329
uint8_t max_resolution_bits
Maximum resolution bits.
Definition vsf_template_dac.h:327
DAC configuration structure.
Definition vsf_template_dac.h:291
vsf_dac_isr_t isr
Interrupt configuration.
Definition vsf_template_dac.h:292
dac channel configuration
Definition vsf_template_dac.h:247
uint8_t channel
Channel index.
Definition vsf_template_dac.h:248
uint8_t resolution
Channel resolution.
Definition vsf_template_dac.h:249
DAC interrupt configuration structure.
Definition vsf_template_dac.h:278
vsf_dac_isr_handler_t * handler_fn
Interrupt handler.
Definition vsf_template_dac.h:279
void * target_ptr
User target pointer.
Definition vsf_template_dac.h:280
vsf_arch_prio_t prio
Interrupt priority.
Definition vsf_template_dac.h:281
Definition vsf_template_dac.h:364
DAC status structure that can be reimplemented in specific HAL drivers.
Definition vsf_template_dac.h:304
Definition vsf_template_dac.h:374
const vsf_dac_op_t * op
Definition vsf_template_dac.h:375
Definition vsf_template_hal_driver.h:204
Definition vsf_template_hal_driver.h:197
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:269
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:227
@ VSF_DAC_IRQ_MASK_IDLE
DAC is idle.
Definition vsf_template_dac.h:228
@ VSF_DAC_IRQ_MASK_CPL
DAC transfer complete.
Definition vsf_template_dac.h:229
@ VSF_DAC_IRQ_ALL_BITS_MASK
Definition vsf_template_dac.h:235
@ VSF_DAC_IRQ_COUNT
Definition vsf_template_dac.h:234
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:147
vsf_dac_ctrl_t
DAC control commands for hardware-specific operations.
Definition vsf_template_dac.h:342
@ __VSF_DAC_CTRL_DUMMY
Dummy value for compilation, required when no actual control commands are defined.
Definition vsf_template_dac.h:360
struct vsf_dac_channel_cfg_t vsf_dac_channel_cfg_t
dac channel configuration
vsf_dac_status_t vsf_dac_status(vsf_dac_t *dac_ptr)
Get the status of DAC instance.
Definition dac_common.c:111
#define VSF_DAC_APIS(__prefix_name)
DAC API template, used to generate DAC type, specific prefix function declarations,...
Definition vsf_template_dac.h:195
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:138
vsf_dac_irq_mask_t vsf_dac_irq_clear(vsf_dac_t *dac_ptr, vsf_dac_irq_mask_t irq_mask)
Clear interrupt flags of DAC instance and return previous state.
Definition dac_common.c:102
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:129
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:120
vsf_err_t vsf_dac_ctrl(vsf_dac_t *dac_ptr, vsf_dac_ctrl_t ctrl, void *param)
Calls the specified DAC command.
Definition dac_common.c:156
Generated from commit: vsfteam/vsf@b2e9e8a