]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/include/spi_dma.h
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained / libchip_samv7 / include / spi_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 _SPI_DMA_\r
38 #define _SPI_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 SPID_ERROR          1\r
52 \r
53 /** SPI driver is currently in use.*/\r
54 #define SPID_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 SPID_CSR_SCBR(mck, spck)    SPI_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 SPID_CSR_DLYBS(mck, delay)  SPI_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 SPID_CSR_DLYBCT(mck, delay) SPI_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 (*SpidCallback)( uint8_t, void* ) ;\r
79 \r
80 /** \brief Spi 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 _SpidCmd\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     /** SPI chip select. */\r
96     uint8_t spiCs;\r
97     /** Callback function invoked at the end of transfer. */\r
98     SpidCallback callback;\r
99     /** Callback arguments. */\r
100     void *pArgument;\r
101 } SpidCmd ;\r
102 \r
103 /** Constant structure associated with SPI port. This structure prevents\r
104     client applications to have access in the same time. */\r
105 typedef struct _Spid\r
106 {\r
107     /** Pointer to SPI Hardware registers */\r
108     Spi* pSpiHw ;\r
109     /** Current SpiCommand being processed */\r
110     SpidCmd *pCurrentCommand ;\r
111     /** Pointer to DMA driver */\r
112     sXdmad* pXdmad;\r
113     /** SPI Id as defined in the product datasheet */\r
114     uint8_t spiId ;\r
115     /** Mutual exclusion semaphore. */\r
116     volatile int8_t semaphore ;\r
117 } Spid ;\r
118 \r
119 /*----------------------------------------------------------------------------\r
120  *        Exported functions\r
121  *----------------------------------------------------------------------------*/\r
122 \r
123 extern uint32_t SPID_Configure( Spid* pSpid,\r
124                                 Spi* pSpiHw,\r
125                                 uint8_t spiId,\r
126                                 uint8_t SpiMode,\r
127                                 sXdmad* pXdmad ) ;\r
128 \r
129 extern void SPID_ConfigureCS( Spid* pSpid, uint32_t dwCS, uint32_t dwCsr ) ;\r
130 \r
131 extern uint32_t SPID_SendCommand( Spid* pSpid, SpidCmd* pCommand ) ;\r
132 \r
133 extern void SPID_Handler( Spid* pSpid ) ;\r
134 \r
135 extern void SPID_DmaHandler( Spid *pSpid );\r
136 \r
137 extern uint32_t SPID_IsBusy( const Spid* pSpid ) ;\r
138 \r
139 #ifdef __cplusplus\r
140 }\r
141 #endif\r
142 \r
143 #endif /* #ifndef _SPI_DMA_ */\r