SAMV71 Xplained Ultra Software Package 1.4

acc.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, 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 (ACC) peripheral.
00036  *
00037  *  \section Usage
00038  *
00039  *  -# Configurate the pins for ACC
00040  *  -# Initialize the ACC with ACC_Initialize().
00041  *  -# Select the active channel using ACC_EnableChannel()
00042  *  -# Start the conversion with ACC_StartConversion()
00043  *  -# Wait the end of the conversion by polling status with ACC_GetStatus()
00044  *  -# Finally, get the converted data using ACC_GetConvertedData()
00045  *
00046  */
00047 #ifndef _ACC_
00048 #define _ACC_
00049 
00050 /*----------------------------------------------------------------------------
00051  *        Headers
00052  *----------------------------------------------------------------------------*/
00053 #include "chip.h"
00054 
00055 #include <stdint.h>
00056 #include <assert.h>
00057 
00058 /*------------------------------------------------------------------------------
00059  *         Definitions
00060  *------------------------------------------------------------------------------*/
00061 #define ACC_SELPLUS_AD12B0 0
00062 #define ACC_SELPLUS_AD12B1 1
00063 #define ACC_SELPLUS_AD12B2 2
00064 #define ACC_SELPLUS_AD12B3 3
00065 #define ACC_SELPLUS_AD12B4 4
00066 #define ACC_SELPLUS_AD12B5 5
00067 #define ACC_SELPLUS_AD12B6 6
00068 #define ACC_SELPLUS_AD12B7 7
00069 #define ACC_SELMINUS_TS 0
00070 #define ACC_SELMINUS_ADVREF 1
00071 #define ACC_SELMINUS_DAC0   2
00072 #define ACC_SELMINUS_DAC1   3
00073 #define ACC_SELMINUS_AD12B0 4
00074 #define ACC_SELMINUS_AD12B1 5
00075 #define ACC_SELMINUS_AD12B2 6
00076 #define ACC_SELMINUS_AD12B3 7
00077 
00078 #ifdef __cplusplus
00079  extern "C" {
00080 #endif
00081 
00082 /*------------------------------------------------------------------------------
00083  *         Macros function of register access
00084  *------------------------------------------------------------------------------*/
00085 #define ACC_CfgModeReg(pAcc, mode)  { \
00086             (pAcc)->ACC_MR = (mode);\
00087         }
00088 
00089 #define ACC_GetModeReg( pAcc )                ((pAcc)->ACC_MR)
00090 
00091 #define ACC_StartConversion( pAcc )           ((pAcc)->ACC_CR = ACC_CR_START)
00092 
00093 #define ACC_SoftReset( pAcc )                 ((pAcc)->ACC_CR = ACC_CR_SWRST)
00094 
00095 #define ACC_EnableChannel( pAcc, dwChannel )    {\
00096             assert( dwChannel < 16 ) ;\
00097             (pAcc)->ACC_CHER = (1 << (dwChannel));\
00098         }
00099 
00100 #define ACC_DisableChannel( pAcc, dwChannel )  {\
00101             assert( dwChannel < 16 ) ;\
00102             (pAcc)->ACC_CHDR = (1 << (dwChannel));\
00103         }
00104 
00105 #define ACC_EnableIt( pAcc, dwMode )            {\
00106             assert( ((dwMode)&0xFFF00000)== 0 ) ;\
00107             (pAcc)->ACC_IER = (dwMode);\
00108         }
00109 
00110 #define ACC_DisableIt( pAcc, dwMode )           {\
00111             assert( ((dwMode)&0xFFF00000)== 0 ) ;\
00112             (pAcc)->ACC_IDR = (dwMode);\
00113         }
00114 
00115 #define ACC_EnableDataReadyIt( pAcc )         ((pAcc)->ACC_IER = AT91C_ACC_DRDY)
00116 
00117 #define ACC_GetStatus( pAcc )                 ((pAcc)->ACC_ISR)
00118 
00119 #define ACC_GetChannelStatus( pAcc )          ((pAcc)->ACC_CHSR)
00120 
00121 #define ACC_GetInterruptMaskStatus( pAcc )    ((pAcc)->ACC_IMR)
00122 
00123 #define ACC_GetLastConvertedData( pAcc )      ((pAcc)->ACC_LCDR)
00124 
00125 #define ACC_CfgAnalogCtrlReg( pAcc, dwMode )     {\
00126             assert( ((dwMode) & 0xFFFCFF3C) == 0 ) ;\
00127             (pAcc)->ACC_ACR = (dwMode);\
00128         }
00129 
00130 #define ACC_CfgExtModeReg( pAcc, extmode )    {\
00131             assert( ((extmode) & 0xFF00FFFE) == 0 ) ;\
00132             (pAcc)->ACC_EMR = (extmode);\
00133         }
00134 
00135 #define ACC_GetAnalogCtrlReg( pAcc )          ((pAcc)->ACC_ACR)
00136 
00137 /*------------------------------------------------------------------------------
00138  *         Exported functions
00139  *------------------------------------------------------------------------------*/
00140 extern void ACC_Configure( Acc *pAcc, uint8_t idAcc, uint8_t ucSelplus,
00141         uint8_t ucSelminus, uint16_t wAc_en, uint16_t wEdge, uint16_t wInvert ) ;
00142 
00143 extern void ACC_SetComparisonPair( Acc *pAcc, uint8_t ucSelplus, uint8_t ucSelminus ) ;
00144 
00145 extern uint32_t ACC_GetComparisonResult( Acc* pAcc, uint32_t dwStatus ) ;
00146 
00147 #ifdef __cplusplus
00148 }
00149 #endif
00150 
00151 #endif /* #ifndef _ACC_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines