SAMV71 Xplained Ultra Software Package 1.5

dac_dma.h

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- */
00002 /*                  Atmel Microcontroller Software Support                      */
00003 /*                       SAM Software Package License                           */
00004 /* ---------------------------------------------------------------------------- */
00005 /* Copyright (c) 2015, Atmel Corporation                                        */
00006 /*                                                                              */
00007 /* All rights reserved.                                                         */
00008 /*                                                                              */
00009 /* Redistribution and use in source and binary forms, with or without           */
00010 /* modification, are permitted provided that the following condition is met:    */
00011 /*                                                                              */
00012 /* - Redistributions of source code must retain the above copyright notice,     */
00013 /* this list of conditions and the disclaimer below.                            */
00014 /*                                                                              */
00015 /* Atmel's name may not be used to endorse or promote products derived from     */
00016 /* this software without specific prior written permission.                     */
00017 /*                                                                              */
00018 /* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR   */
00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE   */
00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,      */
00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  */
00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING         */
00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                           */
00028 /* ---------------------------------------------------------------------------- */
00029 
00030 /**
00031  *  \file
00032  *
00033  *  \section Purpose
00034  *
00035  *  Interface for configuration the Analog-to-Digital Converter (DACC) peripheral.
00036  *
00037  *  \section Usage
00038  *
00039  *  -# Configurate the pins for DACC
00040  *  -# Initialize the DACC with DACC_Initialize().
00041  *  -# Select the active channel using DACC_EnableChannel()
00042  *  -# Start the conversion with DACC_StartConversion()
00043  *  -# Wait the end of the conversion by polling status with DACC_GetStatus()
00044  *  -# Finally, get the converted data using DACC_GetConvertedData()
00045  *
00046 */
00047 #ifndef _DAC_DMA_
00048 #define _DAC_DMA_
00049 
00050 /*----------------------------------------------------------------------------
00051  *        Headers
00052  *----------------------------------------------------------------------------*/
00053 #include "chip.h"
00054 
00055 #include <stdint.h>
00056 #include <assert.h>
00057 
00058 
00059 #ifdef __cplusplus
00060 extern "C" {
00061 #endif
00062 
00063 
00064 /*----------------------------------------------------------------------------
00065  *        Types
00066  *----------------------------------------------------------------------------*/
00067 
00068 /** DAC transfer complete callback. */
00069 typedef void (*DacCallback)(uint8_t, void *);
00070 
00071 /** \brief Dac Transfer Request prepared by the application upper layer.
00072  *
00073  * This structure is sent to the DAC_SendCommand function to start the transfer.
00074  * At the end of the transfer, the callback is invoked by the interrupt handler.
00075  */
00076 typedef struct {
00077     /** Pointer to the Tx data. */
00078     uint8_t *pTxBuff;
00079     /** Tx size in bytes. */
00080     uint16_t TxSize;
00081     /** Tx loop back. */
00082     uint16_t loopback;
00083     /** DACC channel*/
00084     uint8_t dacChannel;
00085     /** Callback function invoked at the end of transfer. */
00086     DacCallback callback;
00087     /** Callback arguments. */
00088     void *pArgument;
00089 } DacCmd;
00090 
00091 
00092 /** Constant structure associated with DAC port. This structure prevents
00093     client applications to have access in the same time. */
00094 typedef struct {
00095     /** Pointer to DAC Hardware registers */
00096     Dacc *pDacHw;
00097     /** Current SpiCommand being processed */
00098     DacCmd *pCurrentCommand;
00099     /** Pointer to DMA driver */
00100     sXdmad *pXdmad;
00101     /** DACC Id as defined in the product datasheet */
00102     uint8_t dacId;
00103     /** Mutual exclusion semaphore. */
00104     volatile int8_t semaphore;
00105 } DacDma;
00106 
00107 
00108 /*------------------------------------------------------------------------------
00109  *         Definitions
00110  *------------------------------------------------------------------------------*/
00111 #define DAC_OK          0
00112 #define DAC_ERROR       1
00113 #define DAC_ERROR_LOCK  2
00114 
00115 #define DACC_CHANNEL_0 0
00116 #define DACC_CHANNEL_1 1
00117 
00118 /*------------------------------------------------------------------------------
00119  *         Exported functions
00120  *------------------------------------------------------------------------------*/
00121 extern uint32_t Dac_ConfigureDma(DacDma *pDacd ,
00122                                   Dacc *pDacHw ,
00123                                   uint8_t DacId,
00124                                   sXdmad *pXdmad);
00125 extern uint32_t Dac_SendData(DacDma *pDacd, DacCmd *pCommand);
00126 
00127 
00128 /*------------------------------------------------------------------------------
00129  *         Macros function of register access
00130  *------------------------------------------------------------------------------*/
00131 #define DACC_SoftReset(pDACC)                 ((pDACC)->DACC_CR = DACC_CR_SWRST)
00132 #define DACC_CfgModeReg(pDACC, mode)          { (pDACC)->DACC_MR = (mode); }
00133 #define DACC_GetModeReg(pDACC)                ((pDACC)->DACC_MR)
00134 #define DACC_CfgTrigger(pDACC, mode)          { (pDACC)->DACC_TRIGR = (mode); }
00135 
00136 #define DACC_EnableChannel(pDACC, channel)    {(pDACC)->DACC_CHER = (1 << (channel));}
00137 #define DACC_DisableChannel(pDACC, channel)   {(pDACC)->DACC_CHDR = (1 << (channel));}
00138 
00139 #define DACC_EnableIt(pDACC, mode)            {(pDACC)->DACC_IER = (mode);}
00140 #define DACC_DisableIt(pDACC, mode)           {(pDACC)->DACC_IDR = (mode);}
00141 #define DACC_GetStatus(pDACC)                 ((pDACC)->DACC_ISR)
00142 #define DACC_GetChannelStatus(pDACC)          ((pDACC)->DACC_CHSR)
00143 #define DACC_GetInterruptMaskStatus(pDACC)    ((pDACC)->DACC_IMR)
00144 
00145 
00146 #ifdef __cplusplus
00147 }
00148 #endif
00149 
00150 #endif /* #ifndef _DAC_DMA_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines