]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained_IAR_Keil/libchip_samv7/include/afec.h
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained_IAR_Keil / libchip_samv7 / include / afec.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2014, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\r
31  *  \file\r
32  *\r
33  *  \section Purpose\r
34  *\r
35  *  Interface for configuration the Analog-to-Digital Converter (AFEC) peripheral.\r
36  *\r
37  *  \section Usage\r
38  *\r
39  *  -# Configurate the pins for AFEC.\r
40  *  -# Initialize the AFEC with AFEC_Initialize().\r
41  *  -# Set AFEC clock and timing with AFEC_SetClock() and AFEC_SetTiming().\r
42  *  -# Select the active channel using AFEC_EnableChannel().\r
43  *  -# Start the conversion with AFEC_StartConversion().\r
44  *  -# Wait the end of the conversion by polling status with AFEC_GetStatus().\r
45  *  -# Finally, get the converted data using AFEC_GetConvertedData() or AFEC_GetLastConvertedData().\r
46  *\r
47 */\r
48 #ifndef _AFEC_\r
49 #define _AFEC_\r
50 \r
51 /*----------------------------------------------------------------------------\r
52  *        Headers\r
53  *----------------------------------------------------------------------------*/\r
54 #include <assert.h>\r
55 #include <stdint.h>\r
56 \r
57 /*------------------------------------------------------------------------------\r
58  *         Definitions\r
59  *------------------------------------------------------------------------------*/\r
60 \r
61 /* -------- AFEC_MR : (AFEC Offset: 0x04) AFEC Mode Register -------- */\r
62 #define AFEC_MR_SETTLING_Pos 20\r
63 #define AFEC_MR_SETTLING_Msk (0x3u << AFEC_MR_SETTLING_Pos) /**< \brief (AFEC_MR) Trigger Selection */\r
64 #define   AFEC_MR_SETTLING_AST3 (0x0u << 20) /**< \brief (AFEC_MR) ADC_SETTLING_AST3 3 periods of AFEClock */\r
65 #define   AFEC_MR_SETTLING_AST5 (0x1u << 20) /**< \brief (AFEC_MR) ADC_SETTLING_AST5 5 periods of AFEClock */\r
66 #define   AFEC_MR_SETTLING_AST9 (0x2u << 20) /**< \brief (AFEC_MR) ADC_SETTLING_AST9 9 periods of AFEClock*/\r
67 #define   AFEC_MR_SETTLING_AST17 (0x3u << 20) /**< \brief (AFEC_MR) ADC_SETTLING_AST17  17 periods of AFEClock*/\r
68 \r
69 /***************************** Single Trigger Mode ****************************/\r
70 #define AFEC_EMR_STM_Pos 25\r
71 #define AFEC_EMR_STM_Msk (0x1u << AFEC_EMR_STM_Pos) /**< \brief (AFEC_EMR) Single Trigger Mode */\r
72 #define   AFEC_EMR_STM_MULTI_TRIG (0x0u << 25) /**< \brief (AFEC_EMR) Single Trigger Mode: Multiple triggers are required to get an averaged result. */\r
73 #define   AFEC_EMR_STM_SINGLE_TRIG (0x1u << 25) /**< \brief (AFEC_EMR) Single Trigger Mode: Only a Single Trigger is required to get an averaged value. */\r
74 \r
75 /***************************** TAG of the AFEC_LDCR Register ******************/\r
76 #define AFEC_EMR_TAG_Pos 24\r
77 #define AFEC_EMR_TAG_Msk (0x1u << AFEC_EMR_TAG_Pos) /**< \brief (AFEC_EMR) TAG of the AFEC_LDCR Register */\r
78 #define   AFEC_EMR_TAG_CHNB_ZERO (0x0u << 24) /**< \brief (AFEC_EMR) TAG of the AFEC_LDCR Register: Sets CHNB to zero in AFEC_LDCR. */\r
79 #define   AFEC_EMR_TAG_APPENDS (0x1u << 24) /**< \brief (AFEC_EMR) TAG of the AFEC_LDCR Register: Appends the channel number to the conversion result in AFEC_LDCR register. */\r
80 \r
81 /***************************** Compare All Channels ******************/\r
82 #define AFEC_EMR_CMPALL_Pos 9\r
83 #define AFEC_EMR_CMPALL_Msk (0x1u << AFEC_EMR_TAG_Pos) /**< \brief (AFEC_EMR) Compare All Channels */\r
84 #define   AFEC_EMR_CMPALL_ONE_CHANNEL_COMP (0x0u << 9) /**< \brief (AFEC_EMR) Compare All Channels: Only channel indicated in CMPSEL field is compared. */\r
85 #define   AFEC_EMR_CMPALL_ALL_CHANNELS_COMP  (0x1u << 9) /**< \brief (AFEC_EMR) Compare All Channels: All channels are compared. */\r
86 \r
87 #define AFEC_ACR_PGA0_ON     (0x1u << 2)\r
88 #define AFEC_ACR_PGA1_ON     (0x1u << 3)\r
89 \r
90 #ifdef __cplusplus\r
91  extern "C" {\r
92 #endif\r
93 \r
94 /*------------------------------------------------------------------------------\r
95  *         Macros function of register access\r
96  *------------------------------------------------------------------------------*/\r
97 \r
98 #define AFEC_GetModeReg( pAFEC )                ((pAFEC)->AFEC_MR)\r
99 #define AFEC_SetModeReg( pAFEC, mode )          ((pAFEC)->AFEC_MR = mode)\r
100 \r
101 #define AFEC_GetExtModeReg( pAFEC )             ((pAFEC)->AFEC_EMR)\r
102 #define AFEC_SetExtModeReg( pAFEC, mode )       ((pAFEC)->AFEC_EMR = mode)\r
103 \r
104 #define AFEC_StartConversion( pAFEC )           ((pAFEC)->AFEC_CR = AFEC_CR_START)\r
105 \r
106 #define AFEC_EnableChannel( pAFEC, dwChannel )    {\\r
107             (pAFEC)->AFEC_CHER = (1 << (dwChannel));\\r
108         }\r
109 \r
110 #define AFEC_DisableChannel(pAFEC, dwChannel)  {\\r
111             (pAFEC)->AFEC_CHDR = (1 << (dwChannel));\\r
112         }\r
113 \r
114 #define AFEC_EnableIt(pAFEC, dwMode)            {\\r
115             (pAFEC)->AFEC_IER = (dwMode);\\r
116         }\r
117 \r
118 #define AFEC_DisableIt(pAFEC, dwMode)           {\\r
119             (pAFEC)->AFEC_IDR = (dwMode);\\r
120         }\r
121 \r
122 #define AFEC_SetChannelGain(pAFEC,dwMode)       {\\r
123             (pAFEC)->AFEC_CG1R = dwMode;\\r
124         }\r
125 \r
126 #define AFEC_EnableDataReadyIt(pAFEC)         ((pAFEC)->AFEC_IER = AFEC_IER_DRDY)\r
127 \r
128 #define AFEC_GetStatus(pAFEC)                 ((pAFEC)->AFEC_ISR)\r
129 \r
130 #define AFEC_GetCompareMode(pAFEC)            (((pAFEC)->AFEC_EMR)& (AFEC_EMR_CMPMODE_Msk))\r
131 \r
132 #define AFEC_GetChannelStatus(pAFEC)          ((pAFEC)->AFEC_CHSR)\r
133 \r
134 #define AFEC_GetInterruptMaskStatus(pAFEC)    ((pAFEC)->AFEC_IMR)\r
135 \r
136 #define AFEC_GetLastConvertedData(pAFEC)      ((pAFEC)->AFEC_LCDR)\r
137 \r
138 /*------------------------------------------------------------------------------\r
139  *         Exported functions\r
140  *------------------------------------------------------------------------------*/\r
141 extern void AFEC_Initialize( Afec* pAFEC, uint32_t dwId );\r
142 extern uint32_t AFEC_SetClock( Afec* pAFEC, uint32_t dwPres, uint32_t dwMck );\r
143 extern void AFEC_SetTiming( Afec* pAFEC, uint32_t dwStartup, uint32_t dwTracking, uint32_t dwSettling );\r
144 extern void AFEC_SetTrigger( Afec* pAFEC, uint32_t dwTrgSel );\r
145 extern void AFEC_SetAnalogChange( Afec* pAFE, uint8_t bEnDis );\r
146 extern void AFEC_SetSleepMode( Afec* pAFEC, uint8_t bEnDis );\r
147 extern void AFEC_SetFastWakeup( Afec* pAFEC, uint8_t bEnDis );\r
148 extern void AFEC_SetSequenceMode( Afec* pAFEC, uint8_t bEnDis );\r
149 extern void AFEC_SetSequence( Afec* pAFEC, uint32_t dwSEQ1, uint32_t dwSEQ2 );\r
150 extern void AFEC_SetSequenceByList( Afec* pAFEC, uint8_t ucChList[], uint8_t ucNumCh );\r
151 extern void AFEC_SetTagEnable( Afec* pAFEC, uint8_t bEnDis );\r
152 extern void AFEC_SetCompareChannel( Afec* pAFEC, uint32_t dwChannel ) ;\r
153 extern void AFEC_SetCompareMode( Afec* pAFEC, uint32_t dwMode ) ;\r
154 extern void AFEC_SetComparisonWindow( Afec* pAFEC, uint32_t dwHi_Lo ) ;\r
155 extern uint8_t AFEC_CheckConfiguration( Afec* pAFEC, uint32_t dwMcK ) ;\r
156 extern uint32_t AFEC_GetConvertedData( Afec* pAFEC, uint32_t dwChannel ) ;\r
157 extern void AFEC_SetStartupTime( Afec* pAFEC, uint32_t dwUs );\r
158 extern void AFEC_SetTrackingTime( Afec* pAFEC, uint32_t dwNs );\r
159 extern void AFEC_SetAnalogOffset( Afec *pAFE, uint32_t dwChannel,uint32_t aoffset );\r
160 extern void AFEC_SetAnalogControl( Afec *pAFE, uint32_t control);\r
161 #ifdef __cplusplus\r
162 }\r
163 #endif\r
164 \r
165 #endif /* #ifndef _AFEC_ */\r
166 \r