SAMV71 Xplained Ultra Software Package 1.3

afec.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2014, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /**
00031  *  \file
00032  *
00033  *  \section Purpose
00034  *
00035  *  Interface for configuration the Analog-to-Digital Converter (AFEC) peripheral.
00036  *
00037  *  \section Usage
00038  *
00039  *  -# Configurate the pins for AFEC.
00040  *  -# Initialize the AFEC with AFEC_Initialize().
00041  *  -# Set AFEC clock and timing with AFEC_SetClock() and AFEC_SetTiming().
00042  *  -# Select the active channel using AFEC_EnableChannel().
00043  *  -# Start the conversion with AFEC_StartConversion().
00044  *  -# Wait the end of the conversion by polling status with AFEC_GetStatus().
00045  *  -# Finally, get the converted data using AFEC_GetConvertedData() or 
00046  * AFEC_GetLastConvertedData().
00047  *
00048 */
00049 #ifndef _AFEC_
00050 #define _AFEC_
00051 
00052 /*----------------------------------------------------------------------------
00053  *        Headers
00054  *----------------------------------------------------------------------------*/
00055 #include <assert.h>
00056 #include <stdint.h>
00057 
00058 /*------------------------------------------------------------------------------
00059  *         Definitions
00060  *------------------------------------------------------------------------------*/
00061 
00062 /* -------- AFEC_MR : (AFEC Offset: 0x04) AFEC Mode Register -------- */
00063 #define AFEC_MR_SETTLING_Pos 20
00064 #define AFEC_MR_SETTLING_Msk (0x3u << AFEC_MR_SETTLING_Pos) 
00065 /**< \brief (AFEC_MR) Trigger Selection */
00066 #define   AFEC_MR_SETTLING_AST3 (0x0u << 20) 
00067 /**< \brief (AFEC_MR) ADC_SETTLING_AST3 3 periods of AFEClock */
00068 #define   AFEC_MR_SETTLING_AST5 (0x1u << 20) 
00069 /**< \brief (AFEC_MR) ADC_SETTLING_AST5 5 periods of AFEClock */
00070 #define   AFEC_MR_SETTLING_AST9 (0x2u << 20) 
00071 /**< \brief (AFEC_MR) ADC_SETTLING_AST9 9 periods of AFEClock*/
00072 #define   AFEC_MR_SETTLING_AST17 (0x3u << 20) 
00073 /**< \brief (AFEC_MR) ADC_SETTLING_AST17  17 periods of AFEClock*/
00074 
00075 /***************************** Single Trigger Mode ****************************/
00076 #define AFEC_EMR_STM_Pos 25
00077 #define AFEC_EMR_STM_Msk (0x1u << AFEC_EMR_STM_Pos) 
00078 /**< \brief (AFEC_EMR) Single Trigger Mode */
00079 #define   AFEC_EMR_STM_MULTI_TRIG (0x0u << 25) 
00080 /**< \brief (AFEC_EMR) Single Trigger Mode: Multiple triggers are required to 
00081     get an averaged result. */
00082 #define   AFEC_EMR_STM_SINGLE_TRIG (0x1u << 25) 
00083 /**< \brief (AFEC_EMR) Single Trigger Mode: Only a Single Trigger is required
00084     to get an averaged value. */
00085 
00086 /***************************** TAG of the AFEC_LDCR Register ******************/
00087 #define AFEC_EMR_TAG_Pos 24
00088 #define AFEC_EMR_TAG_Msk (0x1u << AFEC_EMR_TAG_Pos) 
00089 /**< \brief (AFEC_EMR) TAG of the AFEC_LDCR Register */
00090 #define   AFEC_EMR_TAG_CHNB_ZERO (0x0u << 24) 
00091 /**< \brief (AFEC_EMR) TAG of the AFEC_LDCR Register: Sets CHNB to zero 
00092 in AFEC_LDCR. */
00093 #define   AFEC_EMR_TAG_APPENDS (0x1u << 24) 
00094 /**< \brief (AFEC_EMR) TAG of the AFEC_LDCR Register: Appends the channel 
00095 number to the conversion result in AFEC_LDCR register. */
00096 
00097 /***************************** Compare All Channels ******************/
00098 #define AFEC_EMR_CMPALL_Pos 9
00099 #define AFEC_EMR_CMPALL_Msk (0x1u << AFEC_EMR_TAG_Pos) 
00100 /**< \brief (AFEC_EMR) Compare All Channels */
00101 #define   AFEC_EMR_CMPALL_ONE_CHANNEL_COMP (0x0u << 9) 
00102 /**< \brief (AFEC_EMR) Compare All Channels: Only channel indicated in 
00103 CMPSEL field is compared. */
00104 #define   AFEC_EMR_CMPALL_ALL_CHANNELS_COMP  (0x1u << 9) 
00105 /**< \brief (AFEC_EMR) Compare All Channels: All channels are compared. */
00106 
00107 #define AFEC_ACR_PGA0_ON     (0x1u << 2)
00108 #define AFEC_ACR_PGA1_ON     (0x1u << 3)
00109 
00110 #ifdef __cplusplus
00111  extern "C" {
00112 #endif
00113 
00114 /*------------------------------------------------------------------------------
00115  *         Macros function of register access
00116  *------------------------------------------------------------------------------*/
00117 
00118 #define AFEC_GetModeReg( pAFEC )                ((pAFEC)->AFEC_MR)
00119 #define AFEC_SetModeReg( pAFEC, mode )          ((pAFEC)->AFEC_MR = mode)
00120 
00121 #define AFEC_GetExtModeReg( pAFEC )             ((pAFEC)->AFEC_EMR)
00122 #define AFEC_SetExtModeReg( pAFEC, mode )       ((pAFEC)->AFEC_EMR = mode)
00123 
00124 #define AFEC_StartConversion( pAFEC )           ((pAFEC)->AFEC_CR = AFEC_CR_START)
00125 
00126 #define AFEC_EnableChannel( pAFEC, dwChannel )    {\
00127             (pAFEC)->AFEC_CHER = (1 << (dwChannel));\
00128         }
00129 
00130 #define AFEC_DisableChannel(pAFEC, dwChannel)  {\
00131             (pAFEC)->AFEC_CHDR = (1 << (dwChannel));\
00132         }
00133 
00134 #define AFEC_EnableIt(pAFEC, dwMode)            {\
00135             (pAFEC)->AFEC_IER = (dwMode);\
00136         }
00137 
00138 #define AFEC_DisableIt(pAFEC, dwMode)           {\
00139             (pAFEC)->AFEC_IDR = (dwMode);\
00140         }
00141 
00142 #define AFEC_SetChannelGain(pAFEC,dwMode)       {\
00143             (pAFEC)->AFEC_CGR = dwMode;\
00144         }
00145 
00146 #define AFEC_EnableDataReadyIt(pAFEC)         ((pAFEC)->AFEC_IER = AFEC_IER_DRDY)
00147 
00148 #define AFEC_GetStatus(pAFEC)                 ((pAFEC)->AFEC_ISR)
00149 
00150 #define AFEC_GetCompareMode(pAFEC)            (((pAFEC)->AFEC_EMR)& (AFEC_EMR_CMPMODE_Msk))
00151 
00152 #define AFEC_GetChannelStatus(pAFEC)          ((pAFEC)->AFEC_CHSR)
00153 
00154 #define AFEC_GetInterruptMaskStatus(pAFEC)    ((pAFEC)->AFEC_IMR)
00155 
00156 #define AFEC_GetLastConvertedData(pAFEC)      ((pAFEC)->AFEC_LCDR)
00157 
00158 /*------------------------------------------------------------------------------
00159  *         Exported functions
00160  *------------------------------------------------------------------------------*/
00161 extern void AFEC_Initialize( Afec* pAFEC, uint32_t dwId );
00162 extern uint32_t AFEC_SetClock( Afec* pAFEC, uint32_t dwPres, uint32_t dwMck );
00163 extern void AFEC_SetTiming( Afec* pAFEC, uint32_t dwStartup, uint32_t dwTracking, 
00164     uint32_t dwSettling );
00165 extern void AFEC_SetTrigger( Afec* pAFEC, uint32_t dwTrgSel );
00166 extern void AFEC_SetAnalogChange( Afec* pAFE, uint8_t bEnDis );
00167 extern void AFEC_SetSleepMode( Afec* pAFEC, uint8_t bEnDis );
00168 extern void AFEC_SetFastWakeup( Afec* pAFEC, uint8_t bEnDis );
00169 extern void AFEC_SetSequenceMode( Afec* pAFEC, uint8_t bEnDis );
00170 extern void AFEC_SetSequence( Afec* pAFEC, uint32_t dwSEQ1, uint32_t dwSEQ2 );
00171 extern void AFEC_SetSequenceByList( Afec* pAFEC, uint8_t ucChList[], uint8_t ucNumCh );
00172 extern void AFEC_SetTagEnable( Afec* pAFEC, uint8_t bEnDis );
00173 extern void AFEC_SetCompareChannel( Afec* pAFEC, uint32_t dwChannel ) ;
00174 extern void AFEC_SetCompareMode( Afec* pAFEC, uint32_t dwMode ) ;
00175 extern void AFEC_SetComparisonWindow( Afec* pAFEC, uint32_t dwHi_Lo ) ;
00176 extern uint8_t AFEC_CheckConfiguration( Afec* pAFEC, uint32_t dwMcK ) ;
00177 extern uint32_t AFEC_GetConvertedData( Afec* pAFEC, uint32_t dwChannel ) ;
00178 extern void AFEC_SetStartupTime( Afec* pAFEC, uint32_t dwUs );
00179 extern void AFEC_SetTrackingTime( Afec* pAFEC, uint32_t dwNs );
00180 extern void AFEC_SetAnalogOffset( Afec *pAFE, uint32_t dwChannel,uint32_t aoffset );
00181 extern void AFEC_SetAnalogControl( Afec *pAFE, uint32_t control);
00182 #ifdef __cplusplus
00183 }
00184 #endif
00185 
00186 #endif /* #ifndef _AFEC_ */
00187 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines