RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
adc.h
Go to the documentation of this file.
1/* ---------------------------------------------------------------------------- */
2/* Atmel Microcontroller Software Support */
3/* SAM Software Package License */
4/* ---------------------------------------------------------------------------- */
5/* Copyright (c) 2015, Atmel Corporation */
6/* */
7/* All rights reserved. */
8/* */
9/* Redistribution and use in source and binary forms, with or without */
10/* modification, are permitted provided that the following condition is met: */
11/* */
12/* - Redistributions of source code must retain the above copyright notice, */
13/* this list of conditions and the disclaimer below. */
14/* */
15/* Atmel's name may not be used to endorse or promote products derived from */
16/* this software without specific prior written permission. */
17/* */
18/* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */
19/* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
20/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */
21/* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */
22/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
23/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
24/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
25/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
26/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
27/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28/* ---------------------------------------------------------------------------- */
29
49#ifndef _ADC_
50#define _ADC_
51
52/*----------------------------------------------------------------------------
53 * Headers
54 *----------------------------------------------------------------------------*/
55#include <assert.h>
56#include <stdint.h>
57
58/*------------------------------------------------------------------------------
59 * Definitions
60 *------------------------------------------------------------------------------*/
61
62/* Max. ADC Clock Frequency (Hz) */
63#define ADC_CLOCK_MAX 20000000
64
65/* Max. normal ADC startup time (us) */
66#define ADC_STARTUP_NORMAL_MAX 40
67/* Max. fast ADC startup time (us) */
68#define ADC_STARTUP_FAST_MAX 12
69
70/* Definitions for ADC channels */
71#define ADC_CHANNEL_0 0
72#define ADC_CHANNEL_1 1
73#define ADC_CHANNEL_2 2
74#define ADC_CHANNEL_3 3
75#define ADC_CHANNEL_4 4
76#define ADC_CHANNEL_5 5
77#define ADC_CHANNEL_6 6
78#define ADC_CHANNEL_7 7
79#define ADC_CHANNEL_8 8
80#define ADC_CHANNEL_9 9
81#define ADC_CHANNEL_10 10
82#define ADC_CHANNEL_11 11
83#define ADC_CHANNEL_12 12
84#define ADC_CHANNEL_13 13
85#define ADC_CHANNEL_14 14
86#define ADC_CHANNEL_15 15
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
92/*------------------------------------------------------------------------------
93 * Macros function of register access
94 *------------------------------------------------------------------------------*/
95
96#define ADC_GetModeReg(pAdc) ((pAdc)->ADC_MR)
97
98#define ADC_StartConversion(pAdc) ((pAdc)->ADC_CR = ADC_CR_START)
99
100#define ADC_SetCalibMode(pAdc) ((pAdc)->ADC_CR |= ADC_CR_AUTOCAL)
101
102#define ADC_EnableChannel(pAdc, dwChannel) {\
103 (pAdc)->ADC_CHER = (1 << (dwChannel));\
104 }
105
106#define ADC_DisableChannel(pAdc, dwChannel) {\
107 (pAdc)->ADC_CHDR = (1 << (dwChannel));\
108 }
109
110#define ADC_EnableIt(pAdc, dwMode) {\
111 (pAdc)->ADC_IER = (dwMode);\
112 }
113
114#define ADC_DisableIt(pAdc, dwMode) {\
115 (pAdc)->ADC_IDR = (dwMode);\
116 }
117
118#define ADC_SetChannelGain(pAdc,dwMode) {\
119 (pAdc)->ADC_CGR = dwMode;\
120 }
121
122#define ADC_SetChannelOffset(pAdc,dwMode) {\
123 (pAdc)->ADC_COR = dwMode;\
124 }
125
126#define ADC_EnableDataReadyIt(pAdc) ((pAdc)->ADC_IER = ADC_IER_DRDY)
127
128#define ADC_GetStatus(pAdc) ((pAdc)->ADC_ISR)
129
130#define ADC_GetCompareMode(pAdc) (((pAdc)->ADC_EMR)& (ADC_EMR_CMPMODE_Msk))
131
132#define ADC_GetChannelStatus(pAdc) ((pAdc)->ADC_CHSR)
133
134#define ADC_GetInterruptMaskStatus(pAdc) ((pAdc)->ADC_IMR)
135
136#define ADC_GetLastConvertedData(pAdc) ((pAdc)->ADC_LCDR)
137
138/*------------------------------------------------------------------------------
139 * Exported functions
140 *------------------------------------------------------------------------------*/
141extern void ADC_Initialize(Adc *pAdc, uint32_t dwId);
142extern uint32_t ADC_SetClock(Adc *pAdc, uint32_t dwPres, uint32_t dwMck);
143extern void ADC_SetTiming(Adc *pAdc, uint32_t dwStartup, uint32_t dwTracking,
144 uint32_t dwSettling);
145extern void ADC_SetTrigger(Adc *pAdc, uint32_t dwTrgSel);
146extern void ADC_SetTriggerMode(Adc *pAdc, uint32_t dwMode);
147extern void ADC_SetLowResolution(Adc *pAdc, uint32_t bEnDis);
148extern void ADC_SetSleepMode(Adc *pAdc, uint8_t bEnDis);
149extern void ADC_SetFastWakeup(Adc *pAdc, uint8_t bEnDis);
150extern void ADC_SetSequenceMode(Adc *pAdc, uint8_t bEnDis);
151extern void ADC_SetSequence(Adc *pAdc, uint32_t dwSEQ1, uint32_t dwSEQ2);
152extern void ADC_SetSequenceByList(Adc *pAdc, uint8_t ucChList[],
153 uint8_t ucNumCh);
154extern void ADC_SetAnalogChange(Adc *pAdc, uint8_t bEnDis);
155extern void ADC_SetTagEnable(Adc *pAdc, uint8_t bEnDis);
156extern void ADC_SetCompareChannel(Adc *pAdc, uint32_t dwChannel);
157extern void ADC_SetCompareMode(Adc *pAdc, uint32_t dwMode);
158extern void ADC_SetComparisonWindow(Adc *pAdc, uint32_t dwHi_Lo);
159extern uint8_t ADC_CheckConfiguration(Adc *pAdc, uint32_t dwMcK);
160extern uint32_t ADC_GetConvertedData(Adc *pAdc, uint32_t dwChannel);
161extern void ADC_SetTsAverage(Adc *pADC, uint32_t dwAvg2Conv);
162extern uint32_t ADC_GetTsXPosition(Adc *pADC);
163extern uint32_t ADC_GetTsYPosition(Adc *pADC);
164extern uint32_t ADC_GetTsPressure(Adc *pADC);
165extern void ADC_SetTsDebounce(Adc *pADC, uint32_t dwTime);
166extern void ADC_SetTsPenDetect(Adc *pADC, uint8_t bEnDis);
167extern void ADC_SetStartupTime(Adc *pAdc, uint32_t dwUs);
168extern void ADC_SetTrackingTime(Adc *pAdc, uint32_t dwNs);
169extern void ADC_SetTriggerPeriod(Adc *pAdc, uint32_t dwPeriod);
170extern void ADC_SetTsMode(Adc *pADC, uint32_t dwMode);
171extern void ADC_TsCalibration(Adc *pAdc);
172
173
174#ifdef __cplusplus
175}
176#endif
177
178#endif /* #ifndef _ADC_ */
179
Information for the Assert Handler.