PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
adc.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
61 #ifndef __ADC_H__
62 #define __ADC_H__
63 
64 /******************************************************************************/
65 /* Include files */
66 /******************************************************************************/
67 #include "pdl.h"
68 
69 #if (defined(PDL_PERIPHERAL_ADC_ACTIVE))
70 
71 /* C binding of definitions if building with C++ compiler */
72 #ifdef __cplusplus
73 extern "C"
74 {
75 #endif
76 
154 
155 /******************************************************************************
156  * Global definitions
157  ******************************************************************************/
158 #define stc_adcn_t FM4_ADC_TypeDef
159 #define ADC0 (*((volatile stc_adcn_t *) FM4_ADC0_BASE))
160 #define ADC1 (*((volatile stc_adcn_t *) FM4_ADC1_BASE))
161 #define ADC2 (*((volatile stc_adcn_t *) FM4_ADC2_BASE))
162 
163 #define PDL_ADC_READY_WAIT_COUNT 1000000u
164 
165 #define ADC_INSTANCE_COUNT \
166  (uint8_t)(PDL_PERIPHERAL_ENABLE_ADC0 == PDL_ON) + \
167  (uint8_t)(PDL_PERIPHERAL_ENABLE_ADC1 == PDL_ON) + \
168  (uint8_t)(PDL_PERIPHERAL_ENABLE_ADC2 == PDL_ON)
169 
170 /******************************************************************************
171  * Global type definitions
172  ******************************************************************************/
173 typedef void (*func_ptr_adc_parg32_t)(uint32_t* pu32Argument);
174 
179 typedef enum en_adc_scan_mode
180 {
184 
190 {
191  Value1 = 0,
192  Value4 = 1,
193  Value8 = 2,
194  Value16 = 3,
195  Value32 = 4,
196  Value64 = 5,
197  Value128 = 6,
198  Value256 = 7,
200 
205 typedef enum en_adc_fifo_status
206 {
213 
219 {
223 
229 {
235 
241 {
246 
253 {
255  AdcMft = 1,
256  AdcBt0 = 2,
257  AdcBt1 = 3,
258  AdcBt2 = 4,
259  AdcBt3 = 5,
260  AdcBt4 = 6,
261  AdcBt5 = 7,
262  AdcBt6 = 8,
263  AdcBt7 = 9,
264  AdcBt8 = 10,
265  AdcBt9 = 11,
266  AdcBt10 = 12,
267  AdcBt11 = 13,
268  AdcBt12 = 14,
269  AdcBt13 = 15,
271 
276 typedef struct stc_ad_channel_list
277 {
279  {
280  uint32_t u32AD_CHn;
282  {
283  uint32_t AD_CH_0 : 1 ;
284  uint32_t AD_CH_1 : 1 ;
285  uint32_t AD_CH_2 : 1 ;
286  uint32_t AD_CH_3 : 1 ;
287  uint32_t AD_CH_4 : 1 ;
288  uint32_t AD_CH_5 : 1 ;
289  uint32_t AD_CH_6 : 1 ;
290  uint32_t AD_CH_7 : 1 ;
291  uint32_t AD_CH_8 : 1 ;
292  uint32_t AD_CH_9 : 1 ;
293  uint32_t AD_CH_10 : 1 ;
294  uint32_t AD_CH_11 : 1 ;
295  uint32_t AD_CH_12 : 1 ;
296  uint32_t AD_CH_13 : 1 ;
297  uint32_t AD_CH_14 : 1 ;
298  uint32_t AD_CH_15 : 1 ;
299  uint32_t AD_CH_16 : 1 ;
300  uint32_t AD_CH_17 : 1 ;
301  uint32_t AD_CH_18 : 1 ;
302  uint32_t AD_CH_19 : 1 ;
303  uint32_t AD_CH_20 : 1 ;
304  uint32_t AD_CH_21 : 1 ;
305  uint32_t AD_CH_22 : 1 ;
306  uint32_t AD_CH_23 : 1 ;
307  uint32_t AD_CH_24 : 1 ;
308  uint32_t AD_CH_25 : 1 ;
309  uint32_t AD_CH_26 : 1 ;
310  uint32_t AD_CH_27 : 1 ;
311  uint32_t AD_CH_28 : 1 ;
312  uint32_t AD_CH_29 : 1 ;
313  uint32_t AD_CH_30 : 1 ;
314  uint32_t AD_CH_31 : 1 ;
315  };
316  };
318 
323 typedef struct stc_adc_config
324 {
330  uint8_t u8SamplingTime0;
332  uint8_t u8SamplingTime1;
334  uint8_t u8EnableTime;
337  uint8_t u8ScanFifoDepth;
339 
343  uint8_t u8PrioFifoDepth;
348 
358 #if (PDL_INTERRUPT_ENABLE_ADC0 == PDL_ON) || \
359  (PDL_INTERRUPT_ENABLE_ADC1 == PDL_ON) || \
360  (PDL_INTERRUPT_ENABLE_ADC2 == PDL_ON)
362 
374 #endif // #if (PDL_INTERRUPT_ENABLE_ADC0 == PDL_ON) || (PDL_INTERRUPT_ENABLE_ADC1 == PDL_ON) || (PDL_INTERRUPT_ENABLE_ADC2 == PDL_ON)
376 
377 
380 {
381  #if (PDL_PERIPHERAL_ENABLE_ADC0 == PDL_ON)
383  #endif
384  #if (PDL_PERIPHERAL_ENABLE_ADC1 == PDL_ON)
386  #endif
387  #if (PDL_PERIPHERAL_ENABLE_ADC2 == PDL_ON)
389  #endif
392 
394 typedef struct stc_adc_intern_data
395 {
403 
405 typedef struct stc_adc_instance_data
406 {
410 
411 /******************************************************************************/
412 /* Global variable declarations ('extern', definition in C source) */
413 /******************************************************************************/
414 
417 
418 /******************************************************************************/
419 /* Global function prototypes ('extern', definition in C source) */
420 /******************************************************************************/
421 extern void AdcIrqHandler( volatile stc_adcn_t* pstcAdc,
422  stc_adc_intern_data_t* pstcAdcInternData );
423 extern en_result_t Adc_Init( volatile stc_adcn_t* pstcAdc,
424  stc_adc_config_t* pstcConfig );
425 extern en_result_t Adc_DeInit( volatile stc_adcn_t* pstcAdc );
426 extern en_result_t Adc_EnableWaitReady( volatile stc_adcn_t* pstcAdc );
427 extern en_result_t Adc_Enable( volatile stc_adcn_t* pstcAdc );
428 extern en_result_t Adc_Ready( volatile stc_adcn_t* pstcAdc );
429 extern en_result_t Adc_ScanSwTrigger( volatile stc_adcn_t* pstcAdc );
430 extern en_result_t Adc_PrioSwTrigger( volatile stc_adcn_t* pstcAdc );
431 extern en_result_t Adc_ForceStop( volatile stc_adcn_t* pstcAdc );
432 extern en_result_t Adc_ScanStatus( volatile stc_adcn_t* pstcAdc );
433 extern en_result_t Adc_PrioStatus( volatile stc_adcn_t* pstcAdc );
434 extern en_result_t Adc_Prio2Status( volatile stc_adcn_t* pstcAdc );
435 extern en_adc_fifo_status_t Adc_ScanFifoStatus( volatile stc_adcn_t* pstcAdc );
436 extern en_result_t Adc_ScanFifoClear( volatile stc_adcn_t* pstcAdc );
437 extern en_adc_fifo_status_t Adc_PrioFifoStatus( volatile stc_adcn_t* pstcAdc );
438 extern en_result_t Adc_PrioFifoClear( volatile stc_adcn_t* pstcAdc );
439 extern uint32_t Adc_ReadScanFifo( volatile stc_adcn_t* pstcAdc );
440 extern uint8_t Adc_GetScanChannel( uint32_t u32FifoData );
441 extern en_adc_fifo_data_valid_t Adc_GetScanDataValid( uint32_t u32FifoData );
442 extern en_adc_fifo_start_cause_t Adc_GetScanDataCause( uint32_t u32FifoData );
443 extern uint32_t Adc_ReadPrioFifo( volatile stc_adcn_t* pstcAdc );
444 extern uint8_t Adc_GetPrioChannel( uint32_t u32FifoData );
445 extern en_adc_fifo_data_valid_t Adc_GetPrioDataValid( uint32_t u32FifoData );
446 extern en_adc_fifo_start_cause_t Adc_GetPrioDataCause( uint32_t u32FifoData );
447 extern en_adc_range_result_t Adc_GetRangeResultValid( volatile stc_adcn_t* pstcAdc );
448 
450 #ifdef __cplusplus
451 }
452 #endif
453 
454 #endif // #if (defined(PDL_PERIPHERAL_ADC_ACTIVE))
455 
456 #endif /* __ADC_H__ */
457 /******************************************************************************/
458 /* EOF (not truncated) */
459 /******************************************************************************/