]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained_IAR_Keil/libchip_samv7/include/spi.h
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained_IAR_Keil / libchip_samv7 / include / spi.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License \r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2011, 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  * Interface for Serial Peripheral Interface (SPI) controller.\r
34  *\r
35  */\r
36 \r
37 #ifndef _SPI_\r
38 #define _SPI_\r
39 \r
40 /*----------------------------------------------------------------------------\r
41  *        Headers\r
42  *----------------------------------------------------------------------------*/\r
43 \r
44 #include "chip.h"\r
45 \r
46 /*----------------------------------------------------------------------------\r
47  *        Macros\r
48  *----------------------------------------------------------------------------*/\r
49 \r
50 /**\r
51  *\r
52  * Here are several macros which should be used when configuring a SPI\r
53  * peripheral.\r
54  *\r
55  * \section spi_configuration_macros SPI Configuration Macros\r
56  * - \ref SPI_PCS\r
57  * - \ref SPI_SCBR\r
58  * - \ref SPI_DLYBS\r
59  * - \ref SPI_DLYBCT\r
60  */\r
61 \r
62 /** Calculate the PCS field value given the chip select NPCS value */\r
63 #define SPI_PCS(npcs)       SPI_MR_PCS((~(1 << npcs) & 0xF))\r
64 \r
65 /** Calculates the value of the CSR SCBR field given the baudrate and MCK. */\r
66 #define SPI_SCBR(baudrate, masterClock) SPI_CSR_SCBR((uint32_t)(masterClock / baudrate))\r
67 \r
68 /** Calculates the value of the CSR DLYBS field given the desired delay (in ns) */\r
69 #define SPI_DLYBS(delay, masterClock)  SPI_CSR_DLYBS((uint32_t) (((masterClock / 1000000) * delay) / 1000)+1)\r
70 \r
71 /** Calculates the value of the CSR DLYBCT field given the desired delay (in ns) */\r
72 #define SPI_DLYBCT(delay, masterClock) SPI_CSR_DLYBCT ((uint32_t) (((masterClock / 1000000) * delay) / 32000)+1)\r
73 \r
74 /*------------------------------------------------------------------------------ */\r
75 \r
76 #ifdef __cplusplus\r
77  extern "C" {\r
78 #endif\r
79 \r
80 /*----------------------------------------------------------------------------\r
81  *        Exported functions\r
82  *----------------------------------------------------------------------------*/\r
83 \r
84 extern void SPI_Enable( Spi* spi ) ;\r
85 extern void SPI_Disable( Spi* spi ) ;\r
86 \r
87 extern void SPI_EnableIt( Spi* spi, uint32_t dwSources ) ;\r
88 extern void SPI_DisableIt( Spi* spi, uint32_t dwSources ) ;\r
89 \r
90 extern void SPI_Configure( Spi* spi, uint32_t dwId, uint32_t dwConfiguration ) ;\r
91 extern void SPI_SetMode( Spi* spi, uint32_t dwConfiguration );\r
92 \r
93 extern void SPI_ChipSelect( Spi* spi, uint8_t cS);\r
94 extern void SPI_ReleaseCS( Spi* spi );\r
95 \r
96 extern void SPI_ConfigureNPCS( Spi* spi, uint32_t dwNpcs, uint32_t dwConfiguration ) ;\r
97 extern void SPI_ConfigureCSMode( Spi* spi, uint32_t dwNpcs, uint32_t bReleaseOnLast );\r
98 \r
99 extern uint32_t SPI_Read( Spi* spi ) ;\r
100 extern void SPI_Write( Spi* spi, uint32_t dwNpcs, uint16_t wData ) ;\r
101 extern void SPI_WriteLast( Spi* spi, uint32_t dwNpcs, uint16_t wData );\r
102 \r
103 extern uint32_t SPI_GetStatus( Spi* spi ) ;\r
104 extern uint32_t SPI_IsFinished( Spi* pSpi ) ;\r
105 \r
106 #ifdef __cplusplus\r
107 }\r
108 #endif\r
109 \r
110 #endif /* #ifndef _SPI_ */\r
111 \r