SAMV71 Xplained Ultra Software Package 1.3

spi.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /**
00031  * \file
00032  *
00033  * Interface for Serial Peripheral Interface (SPI) controller.
00034  *
00035  */
00036 
00037 #ifndef _SPI_
00038 #define _SPI_
00039 
00040 /*----------------------------------------------------------------------------
00041  *        Headers
00042  *----------------------------------------------------------------------------*/
00043 
00044 #include "chip.h"
00045 
00046 /*----------------------------------------------------------------------------
00047  *        Macros
00048  *----------------------------------------------------------------------------*/
00049 
00050 /**
00051  *
00052  * Here are several macros which should be used when configuring a SPI
00053  * peripheral.
00054  *
00055  * \section spi_configuration_macros SPI Configuration Macros
00056  * - \ref SPI_PCS
00057  * - \ref SPI_SCBR
00058  * - \ref SPI_DLYBS
00059  * - \ref SPI_DLYBCT
00060  */
00061 
00062 /** Calculate the PCS field value given the chip select NPCS value */
00063 #define SPI_PCS(npcs)       SPI_MR_PCS((~(1 << npcs) & 0xF))
00064 
00065 /** Calculates the value of the CSR SCBR field given the baudrate and MCK. */
00066 #define SPI_SCBR(baudrate, masterClock) \
00067             SPI_CSR_SCBR((uint32_t)(masterClock / baudrate))
00068 
00069 /** Calculates the value of the CSR DLYBS field given the desired delay (in ns) */
00070 #define SPI_DLYBS(delay, masterClock)  \
00071         SPI_CSR_DLYBS((uint32_t) (((masterClock / 1000000) * delay) / 1000)+1)
00072 
00073 /** Calculates the value of the CSR DLYBCT field given the desired delay (in ns) */
00074 #define SPI_DLYBCT(delay, masterClock) \
00075         SPI_CSR_DLYBCT ((uint32_t) (((masterClock / 1000000) * delay) / 32000)+1)
00076 
00077 /*------------------------------------------------------------------------------ */
00078 
00079 #ifdef __cplusplus
00080  extern "C" {
00081 #endif
00082 
00083 /*----------------------------------------------------------------------------
00084  *        Exported functions
00085  *----------------------------------------------------------------------------*/
00086 
00087 extern void SPI_Enable( Spi* spi ) ;
00088 extern void SPI_Disable( Spi* spi ) ;
00089 
00090 extern void SPI_EnableIt( Spi* spi, uint32_t dwSources ) ;
00091 extern void SPI_DisableIt( Spi* spi, uint32_t dwSources ) ;
00092 
00093 extern void SPI_Configure( Spi* spi, uint32_t dwId, uint32_t dwConfiguration ) ;
00094 extern void SPI_SetMode( Spi* spi, uint32_t dwConfiguration );
00095 
00096 extern void SPI_ChipSelect( Spi* spi, uint8_t cS);
00097 extern void SPI_ReleaseCS( Spi* spi );
00098 
00099 extern void SPI_ConfigureNPCS( Spi* spi, uint32_t dwNpcs, uint32_t dwConfiguration ) ;
00100 extern void SPI_ConfigureCSMode( Spi* spi, uint32_t dwNpcs, uint32_t bReleaseOnLast );
00101 
00102 extern uint32_t SPI_Read( Spi* spi ) ;
00103 extern void SPI_Write( Spi* spi, uint32_t dwNpcs, uint16_t wData ) ;
00104 extern void SPI_WriteLast( Spi* spi, uint32_t dwNpcs, uint16_t wData );
00105 
00106 extern uint32_t SPI_GetStatus( Spi* spi ) ;
00107 extern uint32_t SPI_IsFinished( Spi* pSpi ) ;
00108 
00109 #ifdef __cplusplus
00110 }
00111 #endif
00112 
00113 #endif /* #ifndef _SPI_ */
00114 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines