]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained_IAR_Keil/libchip_samv7/include/qspi_dma.h
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained_IAR_Keil / libchip_samv7 / include / qspi_dma.h
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support\r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2009, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /**\r
31  * \file\r
32  *\r
33  * Implementation of SPI driver, transfer data through DMA.\r
34  *\r
35  */\r
36 \r
37 #ifndef _QSPI_DMA_\r
38 #define _QSPI_DMA_\r
39 \r
40 /*----------------------------------------------------------------------------\r
41  *        Headers\r
42  *----------------------------------------------------------------------------*/\r
43 \r
44 #include "chip.h"\r
45 \r
46 /*----------------------------------------------------------------------------\r
47  *        Definitions\r
48  *----------------------------------------------------------------------------*/\r
49 \r
50 /** An unspecified error has occured.*/\r
51 #define QSPID_ERROR          1\r
52 \r
53 /** SPI driver is currently in use.*/\r
54 #define QSPID_ERROR_LOCK     2\r
55 \r
56 /*----------------------------------------------------------------------------\r
57  *        Macros\r
58  *----------------------------------------------------------------------------*/\r
59 \r
60 /** Calculates the value of the SCBR field of the Chip Select Register given MCK and SPCK.*/\r
61 #define QSPID_CSR_SCBR(mck, spck)    QSPI_CSR_SCBR((mck) / (spck))\r
62 \r
63 /** Calculates the value of the DLYBS field of the Chip Select Register given delay in ns and MCK.*/\r
64 #define QSPID_CSR_DLYBS(mck, delay)  QSPI_CSR_DLYBS((((delay) * ((mck) / 1000000)) / 1000) + 1)\r
65 \r
66 /** Calculates the value of the DLYBCT field of the Chip Select Register given delay in ns and MCK.*/\r
67 #define QSPID_CSR_DLYBCT(mck, delay) QSPI_CSR_DLYBCT((((delay) / 32 * ((mck) / 1000000)) / 1000) + 1)\r
68 \r
69 #ifdef __cplusplus\r
70  extern "C" {\r
71 #endif\r
72 \r
73 /*----------------------------------------------------------------------------\r
74  *        Types\r
75  *----------------------------------------------------------------------------*/\r
76 \r
77 /** SPI transfer complete callback. */\r
78 typedef void (*QspidCallback)( uint8_t, void* ) ;\r
79 \r
80 /** \brief Qspi Transfer Request prepared by the application upper layer.\r
81  *\r
82  * This structure is sent to the SPI_SendCommand function to start the transfer.\r
83  * At the end of the transfer, the callback is invoked by the interrupt handler.\r
84  */\r
85 typedef struct _QspidCmd\r
86 {\r
87     /** Pointer to the Tx data. */\r
88     uint8_t *pTxBuff;\r
89     /** Tx size in bytes. */\r
90     uint8_t TxSize;\r
91     /** Pointer to the Rx data. */\r
92     uint8_t *pRxBuff;\r
93     /** Rx size in bytes. */\r
94     uint16_t RxSize;\r
95     /** Callback function invoked at the end of transfer. */\r
96     QspidCallback callback;\r
97     /** Callback arguments. */\r
98     void *pArgument;\r
99 } QspidCmd ;\r
100 \r
101 /** Constant structure associated with SPI port. This structure prevents\r
102     client applications to have access in the same time. */\r
103 typedef struct _Qspid\r
104 {\r
105     /** Pointer to SPI Hardware registers */\r
106     Qspi* pQspiHw ;\r
107     /** Current QspiCommand being processed */\r
108     QspidCmd *pCurrentCommand ;\r
109     /** Pointer to DMA driver */\r
110     sXdmad* pXdmad;\r
111     /** SPI Id as defined in the product datasheet */\r
112     uint8_t spiId ;\r
113     /** Mutual exclusion semaphore. */\r
114     volatile int8_t semaphore ;\r
115 } Qspid ;\r
116 \r
117 /*----------------------------------------------------------------------------\r
118  *        Exported functions\r
119  *----------------------------------------------------------------------------*/\r
120 \r
121 extern uint32_t QSPID_Configure( Qspid* pQspid,\r
122                                 Qspi* pQspiHw,\r
123                                 uint8_t spiId,\r
124                                 uint8_t QspiMode,\r
125                                 sXdmad* pXdmad ) ;\r
126 \r
127 extern void QSPID_ConfigureCS( Qspid* pQspid, uint32_t dwCS, uint32_t dwCsr ) ;\r
128 \r
129 extern uint32_t QSPID_SendCommand( Qspid* pQspid, QspidCmd* pCommand ) ;\r
130 \r
131 extern void QSPID_Handler( Qspid* pQspid ) ;\r
132 \r
133 extern void QSPID_DmaHandler( Qspid *pQspid );\r
134 \r
135 extern uint32_t QSPID_IsBusy( const Qspid* pQspid ) ;\r
136 \r
137 #ifdef __cplusplus\r
138 }\r
139 #endif\r
140 \r
141 #endif /* #ifndef _SPI_DMA_ */\r