1 /**
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 * Description: Provides adc port \n
16 *
17 * History: \n
18 * 2022-09-16, Create file. \n
19 */
20
21 #ifndef ADC_PORTING_H
22 #define ADC_PORTING_H
23
24 #include <stdint.h>
25 #include <stdbool.h>
26 #include "adc.h"
27 #include "osal_interrupt.h"
28
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33 #endif /* __cplusplus */
34
35 /**
36 * @defgroup drivers_port_adc ADC
37 * @ingroup drivers_port
38 * @{
39 */
40
41 #define ADC_LOCK_GET_ATTE 0xFFFFFFFF
42
43 /* auto scan fifo start addr */
44 #define HAL_ADC_SCAN_CH0_1_ADDR 0x4400D01C
45 #define HAL_ADC_SCAN_CH2_3_ADDR 0x4400D024
46 #define HAL_ADC_SCAN_CH0_ADDR 0x4400D01C
47 #define HAL_ADC_SCAN_CH1_ADDR 0x4400D020
48 #define HAL_ADC_SCAN_CH2_ADDR 0x4400D024
49 #define HAL_ADC_SCAN_CH3_ADDR 0x4400D028
50 #define HAL_ADC_SCAN_CH4_ADDR 0x4400D02C
51 #define HAL_ADC_SCAN_CH5_ADDR 0x4400D030
52
53 // FPGA手册中只有CH1 CH6 CH7,platfor_core.h中无对应的GPIO,此处先统一写0
54 #define HAL_ADC_CH0_PIN 0
55 #define HAL_ADC_CH1_PIN 0
56 #define HAL_ADC_CH2_PIN 0
57 #define HAL_ADC_CH3_PIN 0
58 #define HAL_ADC_CH4_PIN 0
59 #define HAL_ADC_CH5_PIN 0
60 #define HAL_ADC_CH6_PIN 0
61 #define HAL_ADC_CH7_PIN 0
62 #define HAL_ADC_CH8_PIN 0
63
64 /**
65 * @brief ADC channels definition.
66 */
67 typedef enum {
68 ADC_CHANNEL_0,
69 ADC_CHANNEL_1,
70 ADC_CHANNEL_2,
71 ADC_CHANNEL_3,
72 ADC_CHANNEL_4,
73 ADC_CHANNEL_5,
74 ADC_CHANNEL_MAX_NUM,
75 ADC_CHANNEL_NONE = ADC_CHANNEL_MAX_NUM
76 } adc_channel_t;
77
78 /**
79 * @if Eng
80 * @brief ADC auto scan frequency which is public used for all channel.
81 * @else
82 * @brief adc自动扫描频率,用于所有通道。
83 * @endif
84 */
85 typedef enum {
86 HAL_ADC_SCAN_FREQ_2HZ,
87 HAL_ADC_SCAN_FREQ_4HZ,
88 HAL_ADC_SCAN_FREQ_8HZ,
89 HAL_ADC_SCAN_FREQ_16HZ,
90 HAL_ADC_SCAN_FREQ_32HZ,
91 HAL_ADC_SCAN_FREQ_64HZ,
92 HAL_ADC_SCAN_FREQ_128HZ,
93 HAL_ADC_SCAN_FREQ_256HZ,
94 HAL_ADC_SCAN_FREQ_MAX,
95 HAL_ADC_SCAN_FREQ_NONE = HAL_ADC_SCAN_FREQ_MAX
96 } port_adc_scan_freq_t;
97
98 /**
99 * @if Eng
100 * @brief Get the base address of a specified adc.
101 * @return The base address of specified adc.
102 * @else
103 * @brief 获取指定ADC的基地址。
104 * @return 指定ADC的基地址。
105 * @endif
106 */
107 uintptr_t adc_porting_base_addr_get(void);
108
109 /**
110 * @if Eng
111 * @brief Get the base address of a adc reset register.
112 * @return The base address of a adc reset register.
113 * @else
114 * @brief 获取指定ADC复位寄存器的基地址。
115 * @return 指定ADC复位寄存器的基地址。
116 * @endif
117 */
118 uintptr_t cldo_addr_get(void);
119
120 /**
121 * @brief Register hal funcs objects into hal_adc module.
122 */
123 void adc_port_register_hal_funcs(void);
124
125 /**
126 * @brief Unregister hal funcs objects from hal_adc module.
127 */
128 void adc_port_unregister_hal_funcs(void);
129
130 /**
131 * @brief Set the divider number of the peripheral device clock.
132 * @param [in] clock The clock which is used for adc sample, adc source clock is 2MHz.
133 */
134 void adc_port_init_clock(adc_clock_t clock);
135
136 /**
137 * @brief Set the divider number of the peripheral device clock.
138 * @param [in] on Enable or disable.
139 */
140 void adc_port_clock_enable(bool on);
141
142 /**
143 * @brief Register the interrupt of adc.
144 */
145 void adc_port_register_irq(void);
146
147 /**
148 * @brief Unregister the interrupt of adc.
149 */
150 void adc_port_unregister_irq(void);
151
152 /**
153 * @brief Power on or power off the peripheral device.
154 * @param [in] on Power on or Power off.
155 */
156 void adc_port_power_on(bool on);
157
158 /**
159 * @brief ADC calibratio.
160 */
161 void adc_port_calibration(void);
162
163 /**
164 * @brief ADC disadle channel pull.
165 * @param [in] channel The adc channel.
166 */
167 void adc_port_pull_disable(adc_channel_t channel);
168
169 /**
170 * @brief ADC set scan discard number and average number.
171 * @param [in] channel The adc channel.
172 */
173 void adc_port_set_scan_discard_and_average_num(adc_channel_t channel);
174
175 /**
176 * @brief Lock of the interrupt.
177 * @return The irq status.
178 */
adc_irq_lock(void)179 inline uint32_t adc_irq_lock(void)
180 {
181 return osal_irq_lock();
182 }
183
184 /**
185 * @brief Unlock of the interrupt.
186 * @param [in] irq_sts The irq status to restore.
187 */
adc_irq_unlock(uint32_t irq_sts)188 inline void adc_irq_unlock(uint32_t irq_sts)
189 {
190 osal_irq_restore(irq_sts);
191 }
192
193 errcode_t adc_port_get_cali_param(uint8_t *data_s, uint8_t *data_b, uint8_t *data_k);
194 /**
195 * @}
196 */
197
198 #ifdef __cplusplus
199 #if __cplusplus
200 }
201 #endif /* __cplusplus */
202 #endif /* __cplusplus */
203
204 #endif