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 * \file 00031 * 00032 * \section Purpose 00033 * 00034 * Interface for configuration the Analog-to-Digital Converter (DACC) peripheral. 00035 * 00036 * \section Usage 00037 * 00038 * -# Configurate the pins for DACC 00039 * -# Initialize the DACC with DACC_Initialize(). 00040 * -# Select the active channel using DACC_EnableChannel() 00041 * -# Start the conversion with DACC_StartConversion() 00042 * -# Wait the end of the conversion by polling status with DACC_GetStatus() 00043 * -# Finally, get the converted data using DACC_GetConvertedData() 00044 * 00045 */ 00046 #ifndef _DAC_DMA_ 00047 #define _DAC_DMA_ 00048 00049 /*---------------------------------------------------------------------------- 00050 * Headers 00051 *----------------------------------------------------------------------------*/ 00052 #include "chip.h" 00053 00054 #include <stdint.h> 00055 #include <assert.h> 00056 00057 00058 #ifdef __cplusplus 00059 extern "C" { 00060 #endif 00061 00062 00063 /*---------------------------------------------------------------------------- 00064 * Types 00065 *----------------------------------------------------------------------------*/ 00066 00067 /** DAC transfer complete callback. */ 00068 typedef void (*DacCallback)( uint8_t, void* ) ; 00069 00070 /** \brief Dac Transfer Request prepared by the application upper layer. 00071 * 00072 * This structure is sent to the DAC_SendCommand function to start the transfer. 00073 * At the end of the transfer, the callback is invoked by the interrupt handler. 00074 */ 00075 typedef struct 00076 { 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 { 00096 /** Pointer to DAC Hardware registers */ 00097 Dacc* pDacHw ; 00098 /** Current SpiCommand being processed */ 00099 DacCmd *pCurrentCommand ; 00100 /** Pointer to DMA driver */ 00101 sXdmad* pXdmad ; 00102 /** DACC Id as defined in the product datasheet */ 00103 uint8_t dacId ; 00104 /** Mutual exclusion semaphore. */ 00105 volatile int8_t semaphore ; 00106 } DacDma; 00107 00108 00109 /*------------------------------------------------------------------------------ 00110 * Definitions 00111 *------------------------------------------------------------------------------*/ 00112 #define DAC_OK 0 00113 #define DAC_ERROR 1 00114 #define DAC_ERROR_LOCK 2 00115 00116 #define DACC_CHANNEL_0 0 00117 #define DACC_CHANNEL_1 1 00118 00119 /*------------------------------------------------------------------------------ 00120 * Exported functions 00121 *------------------------------------------------------------------------------*/ 00122 extern uint32_t Dac_ConfigureDma( DacDma *pDacd , 00123 Dacc *pDacHw , 00124 uint8_t DacId, 00125 sXdmad *pXdmad ); 00126 extern uint32_t Dac_SendData( DacDma *pDacd, DacCmd *pCommand); 00127 00128 00129 /*------------------------------------------------------------------------------ 00130 * Macros function of register access 00131 *------------------------------------------------------------------------------*/ 00132 #define DACC_SoftReset(pDACC) ((pDACC)->DACC_CR = DACC_CR_SWRST) 00133 #define DACC_CfgModeReg(pDACC, mode) { (pDACC)->DACC_MR = (mode); } 00134 #define DACC_GetModeReg(pDACC) ((pDACC)->DACC_MR) 00135 #define DACC_CfgTrigger(pDACC, mode) { (pDACC)->DACC_TRIGR = (mode); } 00136 00137 #define DACC_EnableChannel(pDACC, channel) {(pDACC)->DACC_CHER = (1 << (channel));} 00138 #define DACC_DisableChannel(pDACC, channel) {(pDACC)->DACC_CHDR = (1 << (channel));} 00139 00140 #define DACC_EnableIt(pDACC, mode) {(pDACC)->DACC_IER = (mode);} 00141 #define DACC_DisableIt(pDACC, mode) {(pDACC)->DACC_IDR = (mode);} 00142 #define DACC_GetStatus(pDACC) ((pDACC)->DACC_ISR) 00143 #define DACC_GetChannelStatus(pDACC) ((pDACC)->DACC_CHSR) 00144 #define DACC_GetInterruptMaskStatus(pDACC) ((pDACC)->DACC_IMR) 00145 00146 00147 #ifdef __cplusplus 00148 } 00149 #endif 00150 00151 #endif /* #ifndef _DAC_DMA_ */