]> git.sur5r.net Git - freertos/blob - Demo/Common/drivers/Atmel/at91lib/peripherals/spi/spi.h
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / Common / drivers / Atmel / at91lib / peripherals / spi / spi.h
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support \r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2008, 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 /// \dir\r
32 /// !Purpose\r
33 /// \r
34 /// Definitions for SPI peripheral usage.\r
35 ///\r
36 /// !Usage\r
37 ///\r
38 /// -# Enable the SPI pins required by the application (see pio.h).\r
39 /// -# Configure the SPI using the SPI_Configure function. This enables the\r
40 ///    peripheral clock. The mode register is loaded with the given value.\r
41 /// -# Configure all the necessary chip selects with SPI_ConfigureNPCS.\r
42 /// -# Enable the SPI by calling SPI_Enable.\r
43 /// -# Send/receive data using SPI_Write and SPI_Read. Note that SPI_Read\r
44 ///    must be called after SPI_Write to retrieve the last value read.\r
45 /// -# Send/receive data using the PDC with the SPI_WriteBuffer and\r
46 ///    SPI_ReadBuffer functions.\r
47 /// -# Disable the SPI by calling SPI_Disable.\r
48 //------------------------------------------------------------------------------\r
49 \r
50 #ifndef SPI_H\r
51 #define SPI_H\r
52 \r
53 //------------------------------------------------------------------------------\r
54 //         Headers\r
55 //------------------------------------------------------------------------------\r
56 \r
57 #include <board.h>\r
58 \r
59 //------------------------------------------------------------------------------\r
60 //         Definitions\r
61 //------------------------------------------------------------------------------\r
62 \r
63 //------------------------------------------------------------------------------\r
64 /// \page "SPI configuration macros"\r
65 /// This page lists several macros which should be used when configuring a SPI\r
66 /// peripheral.\r
67 /// \r
68 /// !Macros\r
69 /// - SPI_PCS\r
70 /// - SPI_SCBR\r
71 /// - SPI_DLYBS\r
72 /// - SPI_DLYBCT\r
73 \r
74 /// Calculate the PCS field value given the chip select NPCS value\r
75 #define SPI_PCS(npcs)       ((~(1 << npcs) & 0xF) << 16)\r
76 \r
77 /// Calculates the value of the CSR SCBR field given the baudrate and MCK.\r
78 #define SPI_SCBR(baudrate, masterClock) \\r
79             ((unsigned int) (masterClock / baudrate) << 8)\r
80 \r
81 /// Calculates the value of the CSR DLYBS field given the desired delay (in ns)\r
82 #define SPI_DLYBS(delay, masterClock) \\r
83             ((unsigned int) (((masterClock / 1000000) * delay) / 1000) << 16)\r
84 \r
85 /// Calculates the value of the CSR DLYBCT field given the desired delay (in ns)\r
86 #define SPI_DLYBCT(delay, masterClock) \\r
87             ((unsigned int) (((masterClock / 1000000) * delay) / 32000) << 16)\r
88 //------------------------------------------------------------------------------\r
89 \r
90 //------------------------------------------------------------------------------\r
91 //         Exported functions\r
92 //------------------------------------------------------------------------------\r
93 extern void SPI_Enable(AT91S_SPI *spi);\r
94 extern void SPI_Disable(AT91S_SPI *spi);\r
95 extern void SPI_Configure(AT91S_SPI *spi,\r
96                                  unsigned int id,\r
97                                  unsigned int configuration);\r
98 extern void SPI_ConfigureNPCS(AT91S_SPI *spi,\r
99                                      unsigned int npcs,\r
100                                      unsigned int configuration);\r
101 extern void SPI_Write(AT91S_SPI *spi, unsigned int npcs, unsigned short data);\r
102 extern unsigned char SPI_WriteBuffer(AT91S_SPI *spi,\r
103                                             void *buffer,\r
104                                             unsigned int length);\r
105 \r
106 extern unsigned char SPI_IsFinished(AT91S_SPI *pSpi);\r
107 \r
108 extern unsigned short SPI_Read(AT91S_SPI *spi);\r
109 extern unsigned char SPI_ReadBuffer(AT91S_SPI *spi,\r
110                                            void *buffer,\r
111                                            unsigned int length);\r
112 \r
113 #endif //#ifndef SPI_H\r
114 \r