VSF Documented
adc.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 __HAL_DRIVER_${SERIES/ADC_IP}_ADC_H__
19#define __HAL_DRIVER_${SERIES/ADC_IP}_ADC_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_ADC == ENABLED
26
27// HW/IPCore
32// HW/IPCore end
33
34/*\note Refer to template/README.md for usage cases.
35 * For peripheral drivers, blackbox mode is recommended but not required, reimplementation part MUST be open.
36 * For IPCore drivers, class structure, MULTI_CLASS configuration, reimplementation and class APIs should be open to user.
37 * For emulated drivers, **** No reimplementation ****.
38 */
39
40/*\note Includes CAN ONLY be put here. */
41/*\note If current header is for a peripheral driver(hw driver), and inherit from an IPCore driver, include IPCore header here. */
42
43// IPCore
44#if defined(__VSF_HAL_${ADC_IP}_ADC_CLASS_IMPLEMENT)
45# define __VSF_CLASS_IMPLEMENT__
46#elif defined(__VSF_HAL_${ADC_IP}_ADC_CLASS_INHERIT__)
47# define __VSF_CLASS_INHERIT__
48#endif
49
50#include "utilities/ooc_class.h"
51// IPCore end
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57/*============================ MACROS ========================================*/
58
59/*\note VSF_${ADC_IP}_ADC_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
60 * while VSF_HW_ADC_CFG_MULTI_CLASS should be in adc.c.
61 */
62
63// IPCore
64#ifndef VSF_${ADC_IP}_ADC_CFG_MULTI_CLASS
65# define VSF_${ADC_IP}_ADC_CFG_MULTI_CLASS VSF_ADC_CFG_MULTI_CLASS
66#endif
67// IPCore end
68
69// HW
70/*\note hw ADC driver can reimplement following types:
71 * To enable reimplementation, please enable macro below:
72 * VSF_ADC_CFG_REIMPLEMENT_TYPE_MODE for vsf_adc_mode_t
73 * VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_MODE for vsf_adc_channel_mode_t
74 * VSF_ADC_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_adc_irq_mask_t
75 * VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG for vsf_adc_channel_cfg_t
76 * VSF_ADC_CFG_REIMPLEMENT_TYPE_CFG for vsf_adc_cfg_t
77 * VSF_ADC_CFG_REIMPLEMENT_TYPE_STATUS for vsf_adc_status_t
78 * VSF_ADC_CFG_REIMPLEMENT_TYPE_CTRL for vsf_adc_ctrl_t
79 * VSF_ADC_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_adc_capability_t
80 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
81 * *** DO NOT reimplement these in emulated drivers. ***
82 */
83
84#define VSF_ADC_CFG_REIMPLEMENT_TYPE_MODE ENABLED
85#define VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_MODE ENABLED
86#define VSF_ADC_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
87#define VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG ENABLED
88#define VSF_ADC_CFG_REIMPLEMENT_TYPE_CFG ENABLED
89#define VSF_ADC_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
90#define VSF_ADC_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
91#define VSF_ADC_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
92// HW end
93
94/*============================ MACROFIED FUNCTIONS ===========================*/
95/*============================ TYPES =========================================*/
96
97// IPCore
98vsf_class(vsf_${adc_ip}_adc_t) {
99#if VSF_${ADC_IP}_CFG_MULTI_CLASS == ENABLED
100 public_member(
101 vsf_adc_t vsf_adc;
102 )
103#endif
104
105/*\note You can add more member in vsf_${adc_ip}_adc_t instance.
106 * For members accessible from child, put in protected_member.
107 * Else, put in private_member.
108 */
109
110 protected_member(
111 vsf_${adc_ip}_adc_reg_t *reg;
114};
115// IPCore end
116
117// HW/IPCore, not for emulated drivers
118
119#if VSF_ADC_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
120typedef enum vsf_adc_mode_t {
133#endif
134
135#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_MODE == ENABLED
147 // more vendor specified channel mode can be added here
149#endif
150
151#if VSF_ADC_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
152typedef enum vsf_adc_irq_mask_t {
153 VSF_ADC_IRQ_MASK_CPL = (0x1ul << 0),
155#endif
156
157#if VSF_ADC_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
158typedef struct vsf_adc_status_t {
159 union {
161 struct {
162 uint32_t is_busy : 1;
163 };
165 };
166
167 // more vendor specified status can be added here
169#endif
170
171#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG == ENABLED
172typedef struct vsf_adc_channel_cfg_t {
176 // more vendor specified channel cfg can be added here
178#endif
179
180#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CFG == ENABLED
181typedef struct vsf_adc_t vsf_adc_t;
182typedef void vsf_adc_isr_handler_t(void *target_ptr,
183 vsf_adc_t *adc_ptr,
185typedef struct vsf_adc_isr_t {
187 void *target_ptr;
190typedef struct vsf_adc_cfg_t {
195#endif
196
197#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
198typedef struct vsf_adc_capability_t {
199#if VSF_ADC_CFG_INHERIT_HAL_CAPABILITY == ENABLED
201#endif
206#endif
207
208#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
209typedef enum vsf_adc_ctrl_t {
212#endif
213// HW/IPCore end
214
215/*============================ INCLUDES ======================================*/
216
217// IPCore
218/*\note Extern APIs for ip core diriver.
219 * There is no requirement about how APIs of IPCore drivers should be implemented.
220 * Just consider the simplicity for actual peripheral drivers.
221 */
222// IPCore end
223
224#ifdef __cplusplus
225}
226#endif
227
228// IPCore
229#undef __VSF_HAL_${ADC_IP}_ADC_CLASS_IMPLEMENT
230#undef __VSF_HAL_${ADC_IP}_ADC_CLASS_INHERIT__
231// IPCore end
232
233#endif // VSF_HAL_USE_ADC
234#endif // __HAL_DRIVER_${SERIES/ADC_IP}_ADC_H__
235/* EOF */
Definition adc.h:98
vsf_arch_prio_t
Definition cortex_a_generic.h:88
#define vsf_class(__name)
Definition ooc_class.h:48
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
Predefined VSF ADC capability that can be reimplemented in specific HAL drivers.
Definition vsf_template_adc.h:703
inherit(vsf_peripheral_capability_t) vsf_adc_irq_mask_t irq_mask
uint8_t max_data_bits
Definition vsf_template_adc.h:709
uint8_t channel_count
Definition vsf_template_adc.h:710
Configuration structure for ADC.
Definition vsf_template_adc.h:653
vsf_adc_isr_t isr
Interrupt service routine configuration.
Definition vsf_template_adc.h:655
uint32_t clock_hz
Clock frequency in Hertz.
Definition vsf_template_adc.h:656
vsf_adc_mode_t mode
ADC working mode.
Definition vsf_template_adc.h:654
adc channel configuration
Definition vsf_template_adc.h:627
vsf_adc_channel_mode_t mode
Channel mode.
Definition vsf_template_adc.h:628
uint32_t channel
Definition adc.h:173
uint32_t sample_cycles
Definition adc.h:175
adc isr for api
Definition vsf_template_adc.h:640
vsf_arch_prio_t prio
Definition vsf_template_adc.h:643
void * target_ptr
Definition vsf_template_adc.h:642
vsf_adc_isr_handler_t * handler_fn
Definition vsf_template_adc.h:641
Predefined VSF ADC status that can be reimplemented in specific HAL drivers.
Definition vsf_template_adc.h:675
uint32_t value
Definition vsf_template_adc.h:681
Definition vsf_template_adc.h:755
Definition vsf_template_hal_driver.h:204
Definition vsf_template_hal_driver.h:197
void vsf_adc_isr_handler_t(void *target_ptr, vsf_adc_t *adc_ptr, vsf_adc_irq_mask_t irq_mask)
Definition adc.h:182
vsf_adc_irq_mask_t
Definition adc.h:152
@ VSF_ADC_IRQ_MASK_CPL
Definition adc.h:153
vsf_adc_channel_mode_t
Definition adc.h:136
@ VSF_ADC_CHANNEL_REF_VDD_1_3
Definition adc.h:145
@ VSF_ADC_CHANNEL_REF_VDD_1_2
Definition adc.h:144
@ VSF_ADC_CHANNEL_REF_VDD_1
Definition adc.h:143
@ VSF_ADC_CHANNEL_GAIN_1_4
Definition adc.h:139
@ VSF_ADC_CHANNEL_GAIN_1_5
Definition adc.h:138
@ VSF_ADC_CHANNEL_GAIN_1_2
Definition adc.h:141
@ VSF_ADC_CHANNEL_GAIN_1
Definition adc.h:142
@ VSF_ADC_CHANNEL_REF_VDD_1_4
Definition adc.h:146
@ VSF_ADC_CHANNEL_GAIN_1_3
Definition adc.h:140
@ VSF_ADC_CHANNEL_GAIN_1_6
Definition adc.h:137
vsf_adc_mode_t
Definition adc.h:120
@ VSF_ADC_EXTERN_TRIGGER_2
Definition adc.h:131
@ VSF_ADC_DATA_ALIGN_LEFT
Definition adc.h:126
@ VSF_ADC_REF_VDD_1_2
Definition adc.h:122
@ VSF_ADC_DATA_ALIGN_RIGHT
Definition adc.h:125
@ VSF_ADC_REF_VDD_1_4
Definition adc.h:124
@ VSF_ADC_EXTERN_TRIGGER_1
Definition adc.h:130
@ VSF_ADC_REF_VDD_1_3
Definition adc.h:123
@ VSF_ADC_EXTERN_TRIGGER_0
Definition adc.h:129
@ VSF_ADC_SCAN_CONV_SINGLE_MODE
Definition adc.h:127
@ VSF_ADC_SCAN_CONV_SEQUENCE_MODE
Definition adc.h:128
@ VSF_ADC_REF_VDD_1
Definition adc.h:121
class vsf_$ * reg
vsf_adc_isr_t isr
Definition adc.h:113
vsf_adc_ctrl_t
Definition adc.h:209
@ __VSF_ADC_CTRL_DUMMY
Definition adc.h:210
vsf_adc_irq_mask_t
Predefined VSF ADC interrupt that can be reimplemented in specific HAL drivers.
Definition vsf_template_adc.h:608
vsf_adc_channel_mode_t
Predefined VSF ADC channel modes that can be reimplemented in specific HAL drivers.
Definition vsf_template_adc.h:460
vsf_adc_mode_t
Predefined VSF ADC modes that can be reimplemented in specific HAL drivers.
Definition vsf_template_adc.h:276
vsf_adc_ctrl_t
ADC control commands for hardware-specific operations.
Definition vsf_template_adc.h:723
Generated from commit: vsfteam/vsf@94a8bb1