Robobo
spi.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * SAM Software Package License
3  * ----------------------------------------------------------------------------
4  * Copyright (c) 2011-2012, Atmel Corporation
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following condition is met:
10  *
11  * - Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the disclaimer below.
13  *
14  * Atmel's name may not be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * ----------------------------------------------------------------------------
28  */
29 
37 #ifndef _SPI_
38 #define _SPI_
39 
40 /*----------------------------------------------------------------------------
41  * Headers
42  *----------------------------------------------------------------------------*/
43 
44 #include "../chip.h"
45 
46 /*----------------------------------------------------------------------------
47  * Macros
48  *----------------------------------------------------------------------------*/
49 
63 #define SPI_PCS(npcs) ((~(1 << (npcs)) & 0xF) << 16)
64 
66 #define SPI_SCBR(baudrate, masterClock) ((uint32_t) ((masterClock) / (baudrate)) << 8)
67 
69 #define SPI_DLYBS(delay, masterClock) ((uint32_t) ((((masterClock) / 1000000) * (delay)) / 1000) << 16)
70 
72 #define SPI_DLYBCT(delay, masterClock) ((uint32_t) ((((masterClock) / 1000000) * (delay)) / 32000) << 24)
73 
74 /*------------------------------------------------------------------------------ */
75 
76 #ifdef __cplusplus
77  extern "C" {
78 #endif
79 
80 /*----------------------------------------------------------------------------
81  * Exported functions
82  *----------------------------------------------------------------------------*/
83 
84 extern void SPI_Enable( Spi* spi ) ;
85 extern void SPI_Disable( Spi* spi ) ;
86 extern void SPI_EnableIt( Spi* spi, uint32_t dwSources ) ;
87 extern void SPI_DisableIt( Spi* spi, uint32_t dwSources ) ;
88 
89 extern void SPI_Configure( Spi* spi, uint32_t dwId, uint32_t dwConfiguration ) ;
90 extern void SPI_ConfigureNPCS( Spi* spi, uint32_t dwNpcs, uint32_t dwConfiguration ) ;
91 
92 extern uint32_t SPI_Read( Spi* spi ) ;
93 extern void SPI_Write( Spi* spi, uint32_t dwNpcs, uint16_t wData ) ;
94 
95 extern uint32_t SPI_GetStatus( Spi* spi ) ;
96 extern uint32_t SPI_IsFinished( Spi* pSpi ) ;
97 
98 #if (defined _SAM3S_) || (defined _SAM3S8_) || (defined _SAM3N_)
99 extern void SPI_PdcEnableTx( Spi* spi ) ;
100 extern void SPI_PdcDisableTx( Spi* spi ) ;
101 extern void SPI_PdcEnableRx( Spi* spi ) ;
102 extern void SPI_PdcDisableRx( Spi* spi ) ;
103 
104 extern void SPI_PdcSetTx( Spi* spi, void* pvTxBuf, uint32_t dwTxCount, void* pvTxNextBuf, uint32_t dwTxNextCount ) ;
105 extern void SPI_PdcSetRx( Spi* spi, void* pvRxBuf, uint32_t dwRxCount, void* pvRxNextBuf, uint32_t dwRxNextCount ) ;
106 
107 extern uint32_t SPI_WriteBuffer( Spi* spi, void* pvBuffer, uint32_t dwLength ) ;
108 
109 extern uint32_t SPI_ReadBuffer( Spi* spi, void* pvBuffer, uint32_t dwLength ) ;
110 #endif /* (defined _SAM3S_) || (defined _SAM3S8_) || (defined _SAM3N_) */
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif /* #ifndef _SPI_ */
117 
void SPI_DisableIt(Spi *spi, uint32_t dwSources)
Disables one or more interrupt sources of a SPI peripheral.
Definition: spi.c:116
void SPI_EnableIt(Spi *spi, uint32_t dwSources)
Enables one or more interrupt sources of a SPI peripheral.
Definition: spi.c:105
void SPI_ConfigureNPCS(Spi *spi, uint32_t dwNpcs, uint32_t dwConfiguration)
Configures a chip select of a SPI peripheral. The chip select configuration is computed using several...
Definition: spi.c:149
uint32_t SPI_IsFinished(Spi *pSpi)
Check if SPI transfer finish.
Definition: spi.c:206
uint32_t SPI_GetStatus(Spi *spi)
Get the current status register of the given SPI peripheral.
Definition: spi.c:161
Spi hardware registers.
Definition: component_spi.h:41
uint32_t SPI_Read(Spi *spi)
Reads and returns the last word of data received by a SPI peripheral. This method must be called afte...
Definition: spi.c:174
void SPI_Configure(Spi *spi, uint32_t dwId, uint32_t dwConfiguration)
Configures a SPI peripheral as specified. The configuration can be computed using several macros (see...
Definition: spi.c:129
void SPI_Disable(Spi *spi)
Disables a SPI peripheral.
Definition: spi.c:94
void SPI_Enable(Spi *spi)
Enables a SPI peripheral.
Definition: spi.c:84
void SPI_Write(Spi *spi, uint32_t dwNpcs, uint16_t wData)
Sends data through a SPI peripheral. If the SPI is configured to use a fixed peripheral select...
Definition: spi.c:190