1 /** @file spi.h
2 *   @brief SPI Driver Definition File
3 *   @date 29.May.2013
4 *   @version 03.05.02
5 *
6 *   (c) Texas Instruments 2009-2013, All rights reserved.
7 */
8 
9 
10 #ifndef __SPI_H__
11 #define __SPI_H__
12 
13 #include "reg_spi.h"
14 
15 /** @enum chipSelect
16 *   @brief Transfer Group Chip Select
17 */
18 enum spiChipSelect
19 {
20     SPI_CS_NONE = 0xFFU,
21     SPI_CS_0    = 0xFEU,
22     SPI_CS_1    = 0xFDU,
23     SPI_CS_2    = 0xFBU,
24     SPI_CS_3    = 0xF7U,
25     SPI_CS_4    = 0xEFU,
26     SPI_CS_5    = 0xDFU,
27     SPI_CS_6    = 0xBFU,
28     SPI_CS_7    = 0x7FU
29 };
30 
31 /** @enum spiPinSelect
32 *   @brief spi Pin Select
33 */
34 enum spiPinSelect
35 {
36     SPI_PIN_CS0    = 0U,
37     SPI_PIN_CS1    = 1U,
38     SPI_PIN_CS2    = 2U,
39     SPI_PIN_CS3    = 3U,
40     SPI_PIN_CS4    = 4U,
41     SPI_PIN_CS5    = 5U,
42     SPI_PIN_CS6    = 6U,
43     SPI_PIN_CS7    = 7U,
44     SPI_PIN_ENA    = 8U,
45     SPI_PIN_CLK    = 9U,
46     SPI_PIN_SIMO   = 10U,
47     SPI_PIN_SOMI   = 11U,
48     SPI_PIN_SIMO_1 = 17U,
49     SPI_PIN_SIMO_2 = 18U,
50     SPI_PIN_SIMO_3 = 19U,
51     SPI_PIN_SIMO_4 = 20U,
52     SPI_PIN_SIMO_5 = 21U,
53     SPI_PIN_SIMO_6 = 22U,
54     SPI_PIN_SIMO_7 = 23U,
55     SPI_PIN_SOMI_1 = 25U,
56     SPI_PIN_SOMI_2 = 26U,
57     SPI_PIN_SOMI_3 = 27U,
58     SPI_PIN_SOMI_4 = 28U,
59     SPI_PIN_SOMI_5 = 29U,
60     SPI_PIN_SOMI_6 = 30U,
61     SPI_PIN_SOMI_7 = 31U
62 };
63 
64 /** @enum dataformat
65 *   @brief SPI dataformat register select
66 */
67 typedef enum dataformat
68 {
69     SPI_FMT_0 = 0U,
70     SPI_FMT_1 = 1U,
71     SPI_FMT_2 = 2U,
72     SPI_FMT_3 = 3U
73 }SPIDATAFMT_t;
74 
75 /** @struct spiDAT1RegConfig
76 *   @brief SPI data register configuration
77 */
78 typedef struct spiDAT1RegConfig
79 {
80     boolean CS_HOLD;
81     boolean WDEL;
82     SPIDATAFMT_t DFSEL;
83     uint8 CSNR;
84 }spiDAT1_t;
85 
86 /** @enum SpiTxRxDataStatus
87 *   @brief SPI Data Status
88 */
89 typedef enum SpiTxRxDataStatus
90 {
91     SPI_READY = 0U,
92 	SPI_PENDING = 1U,
93     SPI_COMPLETED = 2U
94 }SpiDataStatus_t;
95 
96 /* USER CODE BEGIN (0) */
97 /* USER CODE END */
98 
99 /**
100  *  @defgroup SPI SPI
101  *  @brief Serial Peripheral Interface Module.
102  *
103  *  SPI is a high-speed synchronous serial input/output port that allows a serial bit stream of
104  *  programmed length (2 to 16 bits) to be shifted in and out of the device at a programmed bit-transfer rate.
105  *
106  *	Related Files
107  *   - reg_spi.h
108  *   - spi.h
109  *   - spi.c
110  *  @addtogroup SPI
111  *  @{
112  */
113 
114 /* SPI Interface Functions */
115 void spiInit(void);
116 void spiSetFunctional(spiBASE_t *spi, uint32 port);
117 void spiEnableNotification(spiBASE_t *spi, uint32 flags);
118 void spiDisableNotification(spiBASE_t *spi, uint32 flags);
119 uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff);
120 void spiSendData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff);
121 uint32 spiReceiveData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * destbuff);
122 void spiGetData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * destbuff);
123 uint32 spiTransmitAndReceiveData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff, uint16 * destbuff);
124 void spiSendAndGetData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff, uint16 * destbuff);
125 void spiEnableLoopback(spiBASE_t *spi, loopBackType_t Loopbacktype);
126 void spiDisableLoopback(spiBASE_t *spi);
127 SpiDataStatus_t SpiTxStatus(spiBASE_t *spi);
128 SpiDataStatus_t SpiRxStatus(spiBASE_t *spi);
129 
130 /** @fn void spiNotification(spiBASE_t *spi, uint32 flags)
131 *   @brief Interrupt callback
132 *   @param[in] spi   - Spi module base address
133 *   @param[in] flags - Copy of error interrupt flags
134 *
135 * This is a callback that is provided by the application and is called upon
136 * an interrupt.  The parameter passed to the callback is a copy of the
137 * interrupt flag register.
138 */
139 void spiNotification(spiBASE_t *spi, uint32 flags);
140 
141 /** @fn void spiEndNotification(spiBASE_t *spi)
142 *   @brief Interrupt callback for End of TX or RX data length.
143 *   @param[in] spi   - Spi module base address
144 *
145 * This is a callback that is provided by the application and is called upon
146 * an interrupt at the End of TX or RX data length.
147 */
148 void spiEndNotification(spiBASE_t *spi);
149 
150 /**@}*/
151 /* USER CODE BEGIN (1) */
152 /* USER CODE END */
153 
154 #endif
155