1 /* ----------------------------------------------------------------------------
\r
2 * ATMEL Microcontroller Software Support
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2009, 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 * Implementation of SPI driver, transfer data through DMA.
\r
40 /*----------------------------------------------------------------------------
\r
42 *----------------------------------------------------------------------------*/
\r
46 /*----------------------------------------------------------------------------
\r
48 *----------------------------------------------------------------------------*/
\r
50 /** An unspecified error has occured.*/
\r
51 #define QSPID_ERROR 1
\r
53 /** SPI driver is currently in use.*/
\r
54 #define QSPID_ERROR_LOCK 2
\r
56 /*----------------------------------------------------------------------------
\r
58 *----------------------------------------------------------------------------*/
\r
60 /** Calculates the value of the SCBR field of the Chip Select Register given MCK and SPCK.*/
\r
61 #define QSPID_CSR_SCBR(mck, spck) QSPI_CSR_SCBR((mck) / (spck))
\r
63 /** Calculates the value of the DLYBS field of the Chip Select Register given delay in ns and MCK.*/
\r
64 #define QSPID_CSR_DLYBS(mck, delay) QSPI_CSR_DLYBS((((delay) * ((mck) / 1000000)) / 1000) + 1)
\r
66 /** Calculates the value of the DLYBCT field of the Chip Select Register given delay in ns and MCK.*/
\r
67 #define QSPID_CSR_DLYBCT(mck, delay) QSPI_CSR_DLYBCT((((delay) / 32 * ((mck) / 1000000)) / 1000) + 1)
\r
73 /*----------------------------------------------------------------------------
\r
75 *----------------------------------------------------------------------------*/
\r
77 /** SPI transfer complete callback. */
\r
78 typedef void (*QspidCallback)( uint8_t, void* ) ;
\r
80 /** \brief Qspi Transfer Request prepared by the application upper layer.
\r
82 * This structure is sent to the SPI_SendCommand function to start the transfer.
\r
83 * At the end of the transfer, the callback is invoked by the interrupt handler.
\r
85 typedef struct _QspidCmd
\r
87 /** Pointer to the Tx data. */
\r
89 /** Tx size in bytes. */
\r
91 /** Pointer to the Rx data. */
\r
93 /** Rx size in bytes. */
\r
95 /** Callback function invoked at the end of transfer. */
\r
96 QspidCallback callback;
\r
97 /** Callback arguments. */
\r
101 /** Constant structure associated with SPI port. This structure prevents
\r
102 client applications to have access in the same time. */
\r
103 typedef struct _Qspid
\r
105 /** Pointer to SPI Hardware registers */
\r
107 /** Current QspiCommand being processed */
\r
108 QspidCmd *pCurrentCommand ;
\r
109 /** Pointer to DMA driver */
\r
111 /** SPI Id as defined in the product datasheet */
\r
113 /** Mutual exclusion semaphore. */
\r
114 volatile int8_t semaphore ;
\r
117 /*----------------------------------------------------------------------------
\r
118 * Exported functions
\r
119 *----------------------------------------------------------------------------*/
\r
121 extern uint32_t QSPID_Configure( Qspid* pQspid,
\r
127 extern void QSPID_ConfigureCS( Qspid* pQspid, uint32_t dwCS, uint32_t dwCsr ) ;
\r
129 extern uint32_t QSPID_SendCommand( Qspid* pQspid, QspidCmd* pCommand ) ;
\r
131 extern void QSPID_Handler( Qspid* pQspid ) ;
\r
133 extern void QSPID_DmaHandler( Qspid *pQspid );
\r
135 extern uint32_t QSPID_IsBusy( const Qspid* pQspid ) ;
\r
141 #endif /* #ifndef _SPI_DMA_ */
\r