1 /* 2 * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/ 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the 14 * distribution. 15 * 16 * Neither the name of Texas Instruments Incorporated nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * 32 */ 33 //***************************************************************************** 34 // 35 // spi.h 36 // 37 // Defines and Macros for the SPI. 38 // 39 //***************************************************************************** 40 41 #ifndef __SPI_H__ 42 #define __SPI_H__ 43 44 //***************************************************************************** 45 // 46 // If building with a C++ compiler, make all of the definitions in this header 47 // have a C binding. 48 // 49 //***************************************************************************** 50 #ifdef __cplusplus 51 extern "C" 52 { 53 #endif 54 55 //***************************************************************************** 56 // Values that can be passed to SPIConfigSetExpClk() as ulMode parameter 57 //***************************************************************************** 58 #define SPI_MODE_MASTER 0x00000000 59 #define SPI_MODE_SLAVE 0x00000004 60 61 //***************************************************************************** 62 // Values that can be passed to SPIConfigSetExpClk() as ulSubMode parameter 63 //***************************************************************************** 64 #define SPI_SUB_MODE_0 0x00000000 65 #define SPI_SUB_MODE_1 0x00000001 66 #define SPI_SUB_MODE_2 0x00000002 67 #define SPI_SUB_MODE_3 0x00000003 68 69 70 //***************************************************************************** 71 // Values that can be passed to SPIConfigSetExpClk() as ulConfigFlags parameter 72 //***************************************************************************** 73 #define SPI_SW_CTRL_CS 0x01000000 74 #define SPI_HW_CTRL_CS 0x00000000 75 #define SPI_3PIN_MODE 0x02000000 76 #define SPI_4PIN_MODE 0x00000000 77 #define SPI_TURBO_ON 0x00080000 78 #define SPI_TURBO_OFF 0x00000000 79 #define SPI_CS_ACTIVEHIGH 0x00000000 80 #define SPI_CS_ACTIVELOW 0x00000040 81 #define SPI_WL_8 0x00000380 82 #define SPI_WL_16 0x00000780 83 #define SPI_WL_32 0x00000F80 84 85 //***************************************************************************** 86 // Values that can be passed to SPIFIFOEnable() and SPIFIFODisable() 87 //***************************************************************************** 88 #define SPI_TX_FIFO 0x08000000 89 #define SPI_RX_FIFO 0x10000000 90 91 //***************************************************************************** 92 // Values that can be passed to SPIDMAEnable() and SPIDMADisable() 93 //***************************************************************************** 94 #define SPI_RX_DMA 0x00008000 95 #define SPI_TX_DMA 0x00004000 96 97 //***************************************************************************** 98 // Values that can be passed to SPIIntEnable(), SPIIntDiasble(), 99 // SPIIntClear() or returned from SPIStatus() 100 //***************************************************************************** 101 #define SPI_INT_DMATX 0x20000000 102 #define SPI_INT_DMARX 0x10000000 103 #define SPI_INT_EOW 0x00020000 104 #define SPI_INT_WKS 0x00010000 105 #define SPI_INT_RX_OVRFLOW 0x00000008 106 #define SPI_INT_RX_FULL 0x00000004 107 #define SPI_INT_TX_UDRFLOW 0x00000002 108 #define SPI_INT_TX_EMPTY 0x00000001 109 110 //***************************************************************************** 111 // Values that can be passed to SPITransfer() 112 //***************************************************************************** 113 #define SPI_CS_ENABLE 0x00000001 114 #define SPI_CS_DISABLE 0x00000002 115 116 //***************************************************************************** 117 // 118 // API Function prototypes 119 // 120 //***************************************************************************** 121 extern void SPIEnable(unsigned long ulBase); 122 extern void SPIDisable(unsigned long ulBase); 123 extern void SPIReset(unsigned long ulBase); 124 extern void SPIConfigSetExpClk(unsigned long ulBase,unsigned long ulSPIClk, 125 unsigned long ulBitRate, unsigned long ulMode, 126 unsigned long ulSubMode, unsigned long ulConfig); 127 extern long SPIDataGetNonBlocking(unsigned long ulBase, 128 unsigned long * pulData); 129 extern void SPIDataGet(unsigned long ulBase, unsigned long *pulData); 130 extern long SPIDataPutNonBlocking(unsigned long ulBase, 131 unsigned long ulData); 132 extern void SPIDataPut(unsigned long ulBase, unsigned long ulData); 133 extern void SPIFIFOEnable(unsigned long ulBase, unsigned long ulFlags); 134 extern void SPIFIFODisable(unsigned long ulBase, unsigned long ulFlags); 135 extern void SPIFIFOLevelSet(unsigned long ulBase, unsigned long ulTxLevel, 136 unsigned long ulRxLevel); 137 extern void SPIFIFOLevelGet(unsigned long ulBase, unsigned long *pulTxLevel, 138 unsigned long *pulRxLevel); 139 extern void SPIWordCountSet(unsigned long ulBase, unsigned long ulWordCount); 140 extern void SPIIntRegister(unsigned long ulBase, void(*pfnHandler)(void)); 141 extern void SPIIntUnregister(unsigned long ulBase); 142 extern void SPIIntEnable(unsigned long ulBase, unsigned long ulIntFlags); 143 extern void SPIIntDisable(unsigned long ulBase, unsigned long ulIntFlags); 144 extern unsigned long SPIIntStatus(unsigned long ulBase, tBoolean bMasked); 145 extern void SPIIntClear(unsigned long ulBase, unsigned long ulIntFlags); 146 extern void SPIDmaEnable(unsigned long ulBase, unsigned long ulFlags); 147 extern void SPIDmaDisable(unsigned long ulBase, unsigned long ulFlags); 148 extern void SPICSEnable(unsigned long ulBase); 149 extern void SPICSDisable(unsigned long ulBase); 150 extern long SPITransfer(unsigned long ulBase, unsigned char *ucDout, 151 unsigned char *ucDin, unsigned long ulSize, 152 unsigned long ulFlags); 153 154 155 //***************************************************************************** 156 // 157 // Mark the end of the C bindings section for C++ compilers. 158 // 159 //***************************************************************************** 160 #ifdef __cplusplus 161 } 162 #endif 163 164 #endif // __SPI_H__ 165