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 _AFE_DMA_ 00050 #define _AFE_DMA_ 00051 00052 /*---------------------------------------------------------------------------- 00053 * Headers 00054 *----------------------------------------------------------------------------*/ 00055 00056 #include "chip.h" 00057 00058 00059 /*---------------------------------------------------------------------------- 00060 * Types 00061 *----------------------------------------------------------------------------*/ 00062 00063 /** AFE transfer complete callback. */ 00064 typedef void (*AfeCallback)( uint8_t, void* ) ; 00065 00066 /** \brief Spi Transfer Request prepared by the application upper layer. 00067 * 00068 * This structure is sent to the AFE_SendCommand function to start the transfer. 00069 * At the end of the transfer, the callback is invoked by the interrupt handler. 00070 */ 00071 typedef struct 00072 { 00073 /** Pointer to the Rx data. */ 00074 uint32_t *pRxBuff; 00075 /** Rx size in bytes. */ 00076 uint16_t RxSize; 00077 /** Callback function invoked at the end of transfer. */ 00078 AfeCallback callback; 00079 /** Callback arguments. */ 00080 void *pArgument; 00081 } AfeCmd ; 00082 00083 00084 /** Constant structure associated with AFE port. This structure prevents 00085 client applications to have access in the same time. */ 00086 typedef struct 00087 { 00088 /** Pointer to AFE Hardware registers */ 00089 Afec* pAfeHw ; 00090 /** Current SpiCommand being processed */ 00091 AfeCmd *pCurrentCommand ; 00092 /** Pointer to DMA driver */ 00093 sXdmad* pXdmad; 00094 /** AFEC Id as defined in the product datasheet */ 00095 uint8_t afeId ; 00096 /** Mutual exclusion semaphore. */ 00097 volatile int8_t semaphore ; 00098 } AfeDma; 00099 00100 00101 /*------------------------------------------------------------------------------ 00102 * Definitions 00103 *----------------------------------------------------------------------------*/ 00104 #define AFE_OK 0 00105 #define AFE_ERROR 1 00106 #define AFE_ERROR_LOCK 2 00107 /*------------------------------------------------------------------------------ 00108 * Exported functions 00109 *----------------------------------------------------------------------------*/ 00110 extern uint32_t Afe_ConfigureDma( AfeDma *pAfed , 00111 Afec *pAfeHw , 00112 uint8_t AfeId, 00113 sXdmad *pXdmad ); 00114 extern uint32_t Afe_SendData( AfeDma *pAfed, AfeCmd *pCommand); 00115 00116 00117 #endif /* #ifndef _AFE_DMA_ */ 00118