SAMV71 Xplained Ultra Software Package 1.5

xdma_hardware_interface.c

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 /** \addtogroup dmad_module
00031  *
00032  * \section DmaHw Dma Hardware Interface Usage
00033  * <ul>
00034  * <li> The DMA controller can handle the transfer between peripherals and memory
00035  * and so receives the triggers from the peripherals. The hardware interface
00036  * number are getting from DMAIF_Get_ChannelNumber().</li>
00037 
00038  * <li> DMAIF_IsValidatedPeripherOnDma() helps to check if the given DMAC has
00039  * associated peripheral identifier coded by the given  peripheral.</li>
00040  *
00041  * </ul>
00042  */
00043 /*@{*/
00044 /*@}*/
00045 
00046 /** \file */
00047 /*----------------------------------------------------------------------------
00048  *        Headers
00049  *----------------------------------------------------------------------------*/
00050 #include "chip.h"
00051 
00052 /*----------------------------------------------------------------------------
00053  *        Local variables
00054  *----------------------------------------------------------------------------*/
00055 /** Array of DMA Channel definition for SAMv7 chip*/
00056 static const XdmaHardwareInterface xdmaHwIf[] = {
00057     /* xdmac, peripheral,  T/R, HW interface number*/
00058     {0,   ID_HSMCI,     0,      0},
00059     {0,   ID_HSMCI,     1,      0},
00060     {0,   ID_SPI0,      0,      1},
00061     {0,   ID_SPI0,      1,      2},
00062     {0,   ID_SPI1,      0,      3},
00063     {0,   ID_SPI1,      1,      4},
00064     {0,   ID_QSPI,      0,      5},
00065     {0,   ID_QSPI,      1,      6},
00066     {0,   ID_USART0,    0,      7},
00067     {0,   ID_USART0,    1,      8},
00068     {0,   ID_USART1,    0,      9},
00069     {0,   ID_USART1,    1,      10},
00070     {0,   ID_USART2,    0,      11},
00071     {0,   ID_USART2,    1,      12},
00072     {0,   ID_PWM0,      0,      13},
00073     {0,   ID_TWIHS0,    0,      14},
00074     {0,   ID_TWIHS0,    1,      15},
00075     {0,   ID_TWIHS1,    0,      16},
00076     {0,   ID_TWIHS1,    1,      17},
00077     {0,   ID_TWIHS2,    0,      18},
00078     {0,   ID_TWIHS2,    1,      19},
00079     {0,   ID_UART0,     0,      20},
00080     {0,   ID_UART0,     1,      21},
00081     {0,   ID_UART1,     0,      22},
00082     {0,   ID_UART1,     1,      23},
00083     {0,   ID_UART2,     0,      24},
00084     {0,   ID_UART2,     1,      25},
00085     {0,   ID_UART3,     0,      26},
00086     {0,   ID_UART3,     1,      27},
00087     {0,   ID_UART4,     0,      28},
00088     {0,   ID_UART4,     1,      29},
00089     {0,   ID_DACC,      0,      30},
00090     {0,   ID_DACC,      0,      31},
00091     {0,   ID_SSC,       0,      32},
00092     {0,   ID_SSC,       1,      33},
00093     {0,   ID_PIOA,      1,      34},
00094     {0,   ID_AFEC0,     1,      35},
00095     {0,   ID_AFEC1,     1,      36},
00096     {0,   ID_AES,       0,      37},
00097     {0,   ID_AES,       1,      38},
00098     {0,   ID_PWM1,      0,      39},
00099     {0,   ID_TC0,       1,      40},
00100     {0,   ID_TC1,       1,      41},
00101     {0,   ID_TC2,       1,      42},
00102     {0,   ID_TC3,       1,      43},
00103 };
00104 
00105 
00106 /*----------------------------------------------------------------------------
00107  *        Exported functions
00108  *----------------------------------------------------------------------------*/
00109 
00110 /**
00111  * \brief Get peripheral identifier coded for hardware handshaking interface
00112  *
00113  * \param bDmac      DMA Controller number.
00114  * \param bPeriphID  Peripheral ID.
00115  * \param bTransfer  Transfer type 0: Tx, 1 :Rx.
00116  * \return 0-15 peripheral identifier coded.
00117  *         0xff : no associated peripheral identifier coded.
00118  */
00119 uint8_t XDMAIF_Get_ChannelNumber (uint8_t bPeriphID,
00120                                   uint8_t bTransfer)
00121 {
00122     uint8_t i;
00123     uint8_t NumOfPeripheral = ((XDMAC_GetType(XDMAC) & 0x00FF0000) >> 16);
00124 
00125     for (i = 0; i <= NumOfPeripheral; i++) {
00126         if ((xdmaHwIf[i].bPeriphID == bPeriphID) &&
00127              (xdmaHwIf[i].bTransfer == bTransfer))
00128             return xdmaHwIf[i].bIfID;
00129     }
00130 
00131     return 0xff;
00132 }
00133 
00134 /**
00135  * \brief Check if the given DMAC has associated peripheral identifier coded by
00136  * the given  peripheral.
00137  *
00138  * \param bDmac      DMA Controller number.
00139  * \param bPeriphID  Peripheral ID (0xff : memory only).
00140  * \return 1:  Is a validated peripheral. 0: no associated peripheral identifier
00141  * coded.
00142  */
00143 uint8_t XDMAIF_IsValidatedPeripherOnDma(uint8_t bPeriphID)
00144 {
00145     uint8_t i;
00146     uint8_t NumOfPeripheral = ((XDMAC_GetType(XDMAC) & 0x00FF0000) >> 16);
00147 
00148     /* It is always validated when transfer to memory */
00149     if (bPeriphID == 0xFF)
00150         return 1;
00151 
00152     for (i = 0; i <= NumOfPeripheral; i++) {
00153         if ((xdmaHwIf[i].bPeriphID == bPeriphID))
00154             return 1;
00155     }
00156 
00157     return 0;
00158 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines