aboutsummaryrefslogtreecommitdiff
path: root/KSDK_1.2.0/platform/drivers/inc/fsl_cadc_driver.h
blob: 54d30cf3b57b72c3c6e165583016d83845d04c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
 * Copyright (c) 2014, Freescale Semiconductor, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __FSL_CADC_DRIVER_H__
#define __FSL_CADC_DRIVER_H__

#include <stdint.h>
#include <stdbool.h>
#include "fsl_cadc_hal.h"
#if FSL_FEATURE_SOC_CADC_COUNT

/*!
 * @addtogroup cadc_driver
 * @{
 */

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*!
 * @brief Defines the type of enumerating ADC converter ID.
 */
typedef enum _cadc_conv_id
{
    kCAdcConvA = 0U,/*!< ID for ADC converter A. */
    kCAdcConvB = 1U /*!< ID for ADC converter B. */
} cadc_conv_id_t;

/*!
 * @brief Defines types for an enumerating event.
 */
typedef enum _cadc_flag
{
    /* Converter events. */
    kCAdcConvInProgress = 0U,   /*!< Conversion in progress for each converter. */
    kCAdcConvEndOfScanInt = 1U, /*!< End of scan interrupt. */
    kCAdcConvPowerDown = 2U,      /*!< The converter is powered Down. */

    /* Global events. */
    kCAdcZeroCrossingInt = 3U,  /*!< Zero crossing interrupt. */
    kCAdcLowLimitInt = 4U,      /*!< Low limit interrupt. */
    kCAdcHighLimitInt = 5U,     /*!< High limit interrupt. */

    /* Slot events. */
    kCAdcSlotReady = 6U,            /*!< Sample is ready to be read. */
    kCAdcSlotLowLimitEvent = 7U,    /*!< Low limit event for each slot. */
    kCAdcSlotHighLimitEvent = 8U,   /*!< High limit event for each slot. */
    kCAdcSlotCrossingEvent = 9U     /*!< Zero crossing event for each slot. */
} cadc_flag_t;

/*! @brief Table of base addresses for ADC instances. */
extern ADC_Type * g_cadcBaseAddr[];

/*! @brief Table to save ADC IRQ enumeration numbers defined in the CMSIS header file. */
extern IRQn_Type g_cadcErrIrqId[ADC_INSTANCE_COUNT];
extern IRQn_Type g_cadcConvAIrqId[ADC_INSTANCE_COUNT];
extern IRQn_Type g_cadcConvBIrqId[ADC_INSTANCE_COUNT];

/*******************************************************************************
 * API
 ******************************************************************************/

#if defined(__cplusplus)
extern "C" {
#endif

/*!
 * @name CADC Driver
 * @{
 */

/*!
 * @brief Populates the user configuration structure for the CyclicADC common settings.
 *
 * This function populates the cadc_user_config_t structure with
 * default settings, which are used in polling mode for ADC conversion.
 * These settings are:
 *
 * .zeroCrossingIntEnable = false;
 * .lowLimitIntEnable = false;
 * .highLimitIntEnable = false;
 * .scanMode = kCAdcScanOnceSequential;
 * .parallelSimultModeEnable = false;
 * .dmaSrc = kCAdcDmaTriggeredByEndOfScan;
 * .autoStandbyEnable = false;
 * .powerUpDelayCount = 0x2AU;
 * .autoPowerDownEnable = false;
 *
 * @param userConfigPtr Pointer to structure of "cadc_controller_config_t".
 * @return Execution status.
 */
cadc_status_t CADC_DRV_StructInitUserConfigDefault(cadc_controller_config_t *userConfigPtr);

/*!
 * @brief Initializes the CyclicADC module for a global configuration.
 *
 * This function configures the CyclicADC module for the global configuration
 * which is shared by all converters.
 *
 * @param instance Instance ID number.
 * @param userConfigPtr Pointer to structure of "cadc_controller_config_t".
 * @return Execution status.
 */
cadc_status_t CADC_DRV_Init(uint32_t instance, const cadc_controller_config_t *userConfigPtr);

/*!
 * @brief De-initializes the CyclicADC module.
 *
 * This function shuts down the CyclicADC module and disables related IRQs.
 *
 * @param instance Instance ID number.
 * @return Execution status.
 */
cadc_status_t CADC_DRV_Deinit(uint32_t instance);

/*!
 * @brief Populates the user configuration structure for each converter.
 *
 * This function populates the cadc_conv_config_t structure with
 * default settings, which are used in polling mode for ADC conversion.
 * These settings are:
 *
 * .dmaEnable = false;
 * .stopEnable = false;
 * .syncEnable = false;
 * .endOfScanIntEnable = false;
 * .clkDivValue = 0x3FU;
 * .useChnInputAsVrefH = false;
 * .useChnInputAsVrefL = false;
 * .speedMode = kCAdcConvClkLimitBy25MHz;
 * .sampleWindowCount = 0U;
 *
 * @param configPtr Pointer to structure of "cadc_converter_config_t".
 * @return Execution status.
 */
cadc_status_t CADC_DRV_StructInitConvConfigDefault(cadc_converter_config_t *configPtr);

/*!
 * @brief Configures each converter in the CyclicADC module.
 *
 * This function configures each converter in the CyclicADC module. However, when
 * the multiple converters are operating simultaneously, the converter settings
 * are interrelated. For more information, see the appropriate device
 * reference manual.
 *
 * @param instance Instance ID number.
 * @param convId Converter ID. See "cadc_conv_id_t".
 * @param configPtr Pointer to configure structure. See "cadc_converter_config_t".
 * @return Execution status.
 */
cadc_status_t CADC_DRV_ConfigConverter(
    uint32_t instance, cadc_conv_id_t convId, const cadc_converter_config_t *configPtr);

/*!
 * @brief Configures the input channel for ADC conversion.
 *
 * This function configures the input channel for ADC conversion. The CyclicADC
 * module input channels are organized in pairs. The configuration can
 * be set for each channel in the pair.
 *
 * @param instance Instance ID number.
 * @param configPtr Pointer to configure structure. See "cadc_chn_config_t".
 * @return Execution status.
 */
cadc_status_t CADC_DRV_ConfigSampleChn(uint32_t instance, const cadc_chn_config_t *configPtr);

/*!
 * @brief Configures each slot for the ADC conversion sequence.
 *
 * This function configures each slot in the ADC conversion sequence. ADC conversion
 * sequence is the basic execution unit in the CyclicADC module. However, the
 * sequence should be configured slot-by-slot. The end of the sequence is a
 * slot that is configured as disabled.
 *
 * @param instance Instance ID number.
 * @param slotIdx Indicated slot number, available in range of 0 - 15.
 * @param configPtr Pointer to configure structure. See "cadc_slot_config_t".
 * @return Execution status.
 */
cadc_status_t CADC_DRV_ConfigSeqSlot(
    uint32_t instance, uint32_t slotIdx, const cadc_slot_config_t *configPtr);

/*!
 * @brief Triggers the ADC conversion sequence by software.
 *
 * This function triggers the ADC conversion by executing a software command. It
 * starts the conversion if no other SYNC input (hardware trigger) is needed.
 *
 * @param instance Instance ID number.
 * @param convId Indicated converter. See "cadc_conv_id_t".
 */
void CADC_DRV_SoftTriggerConv(uint32_t instance, cadc_conv_id_t convId);

/*!
 * @brief Reads the conversion value and returns an absolute value.
 *
 * This function reads the conversion value from each slot in a conversion sequence.
 * The return value is the absolute value without being signed.
 *
 * @param instance Instance ID number.
 * @param slotIdx Indicated slot number, available in range of 0 - 15.
 */
uint16_t CADC_DRV_GetSeqSlotConvValue(uint32_t instance, uint32_t slotIdx);

/*!
 * @brief Gets the global event flag.
 *
 * This function gets the global flag of the CyclicADC module.
 *
 * @param instance Instance ID number.
 * @param flag Indicated event. See "cadc_flag_t".
 * @return Assertion of indicated event.
 */
bool CADC_DRV_GetFlag(uint32_t instance, cadc_flag_t flag);

/*!
 * @brief Clears the global event flag.
 *
 * This function clears the global event flag of the CyclicADC module.
 *
 * @param instance Instance ID number.
 * @param flag Indicated event. See "cadc_flag_t".
 */
void CADC_DRV_ClearFlag(uint32_t instance, cadc_flag_t flag);

/*!
 * @brief Gets the flag for each converter event.
 *
 * This function gets the flag for each converter event.
 *
 * @param instance Instance ID number.
 * @param convId Indicated converter.
 * @param flag Indicated event. See "cadc_flag_t".
 * @return Assertion of indicated event.
 */
bool CADC_DRV_GetConvFlag(uint32_t instance, cadc_conv_id_t convId, cadc_flag_t flag);

/*!
 * @brief Clears the flag for each converter event.
 *
 * This function clears the flag for each converter event.
 *
 * @param instance Instance ID number.
 * @param convId Indicated converter.
 * @param flag Indicated event. See  "cadc_flag_t".
 */
void CADC_DRV_ClearConvFlag(uint32_t instance, cadc_conv_id_t convId, cadc_flag_t flag);

/*!
 * @brief Gets the flag for each slot event.
 *
 * This function gets the flag for each slot event in the conversion in
 * sequence.
 *
 * @param instance Instance ID number.
 * @param slotIdxMask Indicated slot number's mask.
 * @param flag Indicated event. See "cadc_flag_t".
 * @return Assertion of indicated event.
 */
uint16_t CADC_DRV_GetSlotFlag(uint32_t instance, uint16_t slotIdxMask, cadc_flag_t flag);

/*!
 * @brief Clears the flag for each slot event.
 *
 * This function clears the flag for each slot event in the conversion in
 * sequence.
 *
 * @param instance Instance ID number.
 * @param slotIdxMask Indicated slot number's mask.
 * @param flag Indicated event. See "cadc_flag_t".
 */
void CADC_DRV_ClearSlotFlag(uint32_t instance, uint16_t slotIdxMask, cadc_flag_t flag);

/* @} */

#if defined(__cplusplus)
}
#endif

/*! @} */

#endif
#endif /* __FSL_CADC_DRIVER_H__ */
/******************************************************************************
 * EOF
 *****************************************************************************/