1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2011, Atmel Corporation
\r
6 * All rights reserved.
\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
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\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
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
33 * Interface for Serial Peripheral Interface (SPI) controller.
\r
40 /*----------------------------------------------------------------------------
\r
42 *----------------------------------------------------------------------------*/
\r
46 /*----------------------------------------------------------------------------
\r
48 *----------------------------------------------------------------------------*/
\r
52 * Here are several macros which should be used when configuring a SPI
\r
55 * \section spi_configuration_macros SPI Configuration Macros
\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
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
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
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
74 /*------------------------------------------------------------------------------ */
\r
80 /*----------------------------------------------------------------------------
\r
81 * Exported functions
\r
82 *----------------------------------------------------------------------------*/
\r
84 extern void SPI_Enable( Spi* spi ) ;
\r
85 extern void SPI_Disable( Spi* spi ) ;
\r
87 extern void SPI_EnableIt( Spi* spi, uint32_t dwSources ) ;
\r
88 extern void SPI_DisableIt( Spi* spi, uint32_t dwSources ) ;
\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
93 extern void SPI_ChipSelect( Spi* spi, uint8_t cS);
\r
94 extern void SPI_ReleaseCS( Spi* spi );
\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
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
103 extern uint32_t SPI_GetStatus( Spi* spi ) ;
\r
104 extern uint32_t SPI_IsFinished( Spi* pSpi ) ;
\r
110 #endif /* #ifndef _SPI_ */
\r