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_CAPABILITY for vsf_adc_capability_t
79 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
80 * *** DO NOT reimplement these in emulated drivers. ***
81 */
82
83#define VSF_ADC_CFG_REIMPLEMENT_TYPE_MODE ENABLED
84#define VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_MODE ENABLED
85#define VSF_ADC_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
86#define VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG ENABLED
87#define VSF_ADC_CFG_REIMPLEMENT_TYPE_CFG ENABLED
88#define VSF_ADC_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
89#define VSF_ADC_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
90// HW end
91
92/*============================ MACROFIED FUNCTIONS ===========================*/
93/*============================ TYPES =========================================*/
94
95// IPCore
96vsf_class(vsf_${adc_ip}_adc_t) {
97#if VSF_${ADC_IP}_CFG_MULTI_CLASS == ENABLED
98 public_member(
99 vsf_adc_t vsf_adc;
100 )
101#endif
102
103/*\note You can add more member in vsf_${adc_ip}_adc_t instance.
104 * For members accessible from child, put in protected_member.
105 * Else, put in private_member.
106 */
107
108 protected_member(
109 vsf_${adc_ip}_adc_reg_t *reg;
112};
113// IPCore end
114
115// HW/IPCore, not for emulated drivers
116
117#if VSF_ADC_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
118typedef enum vsf_adc_mode_t {
131#endif
132
133#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_MODE == ENABLED
145 // more vendor specified channel mode can be added here
147#endif
148
149#if VSF_ADC_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
150typedef enum vsf_adc_irq_mask_t {
151 VSF_ADC_IRQ_MASK_CPL = (0x1ul << 0),
153#endif
154
155#if VSF_ADC_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
156typedef struct vsf_adc_status_t {
157 union {
159 struct {
160 uint32_t is_busy : 1;
161 };
163 };
164
165 // more vendor specified status can be added here
167#endif
168
169#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CHANNEL_CFG == ENABLED
170typedef struct vsf_adc_channel_cfg_t {
174 // more vendor specified channel cfg can be added here
176#endif
177
178#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CFG == ENABLED
179typedef struct vsf_adc_t vsf_adc_t;
180typedef void vsf_adc_isr_handler_t(void *target_ptr,
181 vsf_adc_t *adc_ptr,
183typedef struct vsf_adc_isr_t {
185 void *target_ptr;
188typedef struct vsf_adc_cfg_t {
193#endif
194
195#if VSF_ADC_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
196typedef struct vsf_adc_capability_t {
197#if VSF_ADC_CFG_INHERIT_HAL_CAPABILITY == ENABLED
199#endif
204#endif
205// HW/IPCore end
206
207/*============================ INCLUDES ======================================*/
208
209// IPCore
210/*\note Extern APIs for ip core diriver.
211 * There is no requirement about how APIs of IPCore drivers should be implemented.
212 * Just consider the simplicity for actual peripheral drivers.
213 */
214// IPCore end
215
216#ifdef __cplusplus
217}
218#endif
219
220// IPCore
221#undef __VSF_HAL_${ADC_IP}_ADC_CLASS_IMPLEMENT
222#undef __VSF_HAL_${ADC_IP}_ADC_CLASS_INHERIT__
223// IPCore end
224
225#endif // VSF_HAL_USE_ADC
226#endif // __HAL_DRIVER_${SERIES/ADC_IP}_ADC_H__
227/* EOF */
Definition adc.h:96
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:701
inherit(vsf_peripheral_capability_t) vsf_adc_irq_mask_t irq_mask
uint8_t max_data_bits
Definition vsf_template_adc.h:707
uint8_t channel_count
Definition vsf_template_adc.h:708
Configuration structure for ADC.
Definition vsf_template_adc.h:651
vsf_adc_isr_t isr
Interrupt service routine configuration.
Definition vsf_template_adc.h:653
uint32_t clock_hz
Clock frequency in Hertz.
Definition vsf_template_adc.h:654
vsf_adc_mode_t mode
ADC working mode.
Definition vsf_template_adc.h:652
adc channel configuration
Definition vsf_template_adc.h:625
vsf_adc_channel_mode_t mode
Channel mode.
Definition vsf_template_adc.h:626
uint32_t channel
Definition adc.h:171
uint32_t sample_cycles
Definition adc.h:173
adc isr for api
Definition vsf_template_adc.h:638
vsf_arch_prio_t prio
Definition vsf_template_adc.h:641
void * target_ptr
Definition vsf_template_adc.h:640
vsf_adc_isr_handler_t * handler_fn
Definition vsf_template_adc.h:639
Predefined VSF ADC status that can be reimplemented in specific HAL drivers.
Definition vsf_template_adc.h:673
uint32_t value
Definition vsf_template_adc.h:679
Definition vsf_template_adc.h:722
Definition vsf_template_hal_driver.h:203
Definition vsf_template_hal_driver.h:196
void vsf_adc_isr_handler_t(void *target_ptr, vsf_adc_t *adc_ptr, vsf_adc_irq_mask_t irq_mask)
Definition adc.h:180
vsf_adc_irq_mask_t
Definition adc.h:150
@ VSF_ADC_IRQ_MASK_CPL
Definition adc.h:151
vsf_adc_channel_mode_t
Definition adc.h:134
@ VSF_ADC_CHANNEL_REF_VDD_1_3
Definition adc.h:143
@ VSF_ADC_CHANNEL_REF_VDD_1_2
Definition adc.h:142
@ VSF_ADC_CHANNEL_REF_VDD_1
Definition adc.h:141
@ VSF_ADC_CHANNEL_GAIN_1_4
Definition adc.h:137
@ VSF_ADC_CHANNEL_GAIN_1_5
Definition adc.h:136
@ VSF_ADC_CHANNEL_GAIN_1_2
Definition adc.h:139
@ VSF_ADC_CHANNEL_GAIN_1
Definition adc.h:140
@ VSF_ADC_CHANNEL_REF_VDD_1_4
Definition adc.h:144
@ VSF_ADC_CHANNEL_GAIN_1_3
Definition adc.h:138
@ VSF_ADC_CHANNEL_GAIN_1_6
Definition adc.h:135
vsf_adc_mode_t
Definition adc.h:118
@ VSF_ADC_EXTERN_TRIGGER_2
Definition adc.h:129
@ VSF_ADC_DATA_ALIGN_LEFT
Definition adc.h:124
@ VSF_ADC_REF_VDD_1_2
Definition adc.h:120
@ VSF_ADC_DATA_ALIGN_RIGHT
Definition adc.h:123
@ VSF_ADC_REF_VDD_1_4
Definition adc.h:122
@ VSF_ADC_EXTERN_TRIGGER_1
Definition adc.h:128
@ VSF_ADC_REF_VDD_1_3
Definition adc.h:121
@ VSF_ADC_EXTERN_TRIGGER_0
Definition adc.h:127
@ VSF_ADC_SCAN_CONV_SINGLE_MODE
Definition adc.h:125
@ VSF_ADC_SCAN_CONV_SEQUENCE_MODE
Definition adc.h:126
@ VSF_ADC_REF_VDD_1
Definition adc.h:119
class vsf_$ * reg
vsf_adc_isr_t isr
Definition adc.h:111
vsf_adc_irq_mask_t
Predefined VSF ADC interrupt that can be reimplemented in specific HAL drivers.
Definition vsf_template_adc.h:606
vsf_adc_channel_mode_t
Predefined VSF ADC channel modes that can be reimplemented in specific HAL drivers.
Definition vsf_template_adc.h:458
vsf_adc_mode_t
Predefined VSF ADC modes that can be reimplemented in specific HAL drivers.
Definition vsf_template_adc.h:274
Generated from commit: vsfteam/vsf@f33b89f