spi.h 7.4 KB

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