blob: a552fe438f910427033c47cf92d35582bc49feb2 [file] [log] [blame]
Christina Quast53b21052014-12-09 15:34:35 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2009, 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 conditions are 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
30/**
31 * \file
32 *
33 * Interface for Serial Peripheral Interface (SPI) controller.
34 *
35 */
36
37#ifndef _SPI_
38#define _SPI_
39
40/*----------------------------------------------------------------------------
41 * Headers
42 *----------------------------------------------------------------------------*/
43
44#include "chip.h"
45
46/*----------------------------------------------------------------------------
47 * Macros
48 *----------------------------------------------------------------------------*/
49
50/**
51 *
52 * Here are several macros which should be used when configuring a SPI
53 * peripheral.
54 *
55 * \section spi_configuration_macros SPI Configuration Macros
56 * - \ref SPI_PCS
57 * - \ref SPI_SCBR
58 * - \ref SPI_DLYBS
59 * - \ref SPI_DLYBCT
60 */
61
62/** Calculate the PCS field value given the chip select NPCS value */
63#define SPI_PCS(npcs) ((~(1 << npcs) & 0xF) << 16)
64
65/** Calculates the value of the CSR SCBR field given the baudrate and MCK. */
66#define SPI_SCBR(baudrate, masterClock) ((uint32_t) (masterClock / baudrate) << 8)
67
68/** Calculates the value of the CSR DLYBS field given the desired delay (in ns) */
69#define SPI_DLYBS(delay, masterClock) ((uint32_t) (((masterClock / 1000000) * delay) / 1000) << 16)
70
71/** Calculates the value of the CSR DLYBCT field given the desired delay (in ns) */
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
84extern void SPI_Enable( Spi* spi ) ;
85extern void SPI_Disable( Spi* spi ) ;
86extern void SPI_EnableIt( Spi* spi, uint32_t dwSources ) ;
87extern void SPI_DisableIt( Spi* spi, uint32_t dwSources ) ;
88
89extern void SPI_Configure( Spi* spi, uint32_t dwId, uint32_t dwConfiguration ) ;
90extern void SPI_ConfigureNPCS( Spi* spi, uint32_t dwNpcs, uint32_t dwConfiguration ) ;
91
92extern uint32_t SPI_Read( Spi* spi ) ;
93extern void SPI_Write( Spi* spi, uint32_t dwNpcs, uint16_t wData ) ;
94
95extern uint32_t SPI_GetStatus( Spi* spi ) ;
96extern uint32_t SPI_IsFinished( Spi* pSpi ) ;
97
98extern void SPI_PdcEnableTx( Spi* spi ) ;
99extern void SPI_PdcDisableTx( Spi* spi ) ;
100extern void SPI_PdcEnableRx( Spi* spi ) ;
101extern void SPI_PdcDisableRx( Spi* spi ) ;
102
103extern void SPI_PdcSetTx( Spi* spi, void* pvTxBuf, uint32_t dwTxCount, void* pvTxNextBuf, uint32_t dwTxNextCount ) ;
104extern void SPI_PdcSetRx( Spi* spi, void* pvRxBuf, uint32_t dwRxCount, void* pvRxNextBuf, uint32_t dwRxNextCount ) ;
105
106extern uint32_t SPI_WriteBuffer( Spi* spi, void* pvBuffer, uint32_t dwLength ) ;
107
108extern uint32_t SPI_ReadBuffer( Spi* spi, void* pvBuffer, uint32_t dwLength ) ;
109
110#ifdef __cplusplus
111}
112#endif
113
114#endif /* #ifndef _SPI_ */
115