spi.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /**
  2. * \file spi.h
  3. *
  4. * \brief SPI APIs and macros.
  5. *
  6. * This file contains the driver API prototypes and macro definitions.
  7. */
  8. /*
  9. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  10. */
  11. /*
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. *
  16. * Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * Neither the name of Texas Instruments Incorporated nor the names of
  25. * its contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. */
  41. #ifndef _SPI_H_
  42. #define _SPI_H_
  43. #include "hw_spi.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /****************************************************************************/
  48. /*
  49. ** Values that can be passed to SPIModeConfigure API as flag to select mode
  50. ** of operation of SPI
  51. */
  52. /* To Configure SPI to Master Mode */
  53. #define SPI_MASTER_MODE (SPI_SPIGCR1_MASTER | SPI_SPIGCR1_CLKMOD)
  54. /* To Configure SPI to Slave Mode */
  55. #define SPI_SLAVE_MODE 0
  56. /***************************************************************************/
  57. /*
  58. ** It use to select different data format register avilable in SPI peripheral.
  59. */
  60. #define SPI_DATA_FORMAT0 SPI_SPIDAT1_DFSEL_FORMAT0
  61. #define SPI_DATA_FORMAT1 SPI_SPIDAT1_DFSEL_FORMAT1
  62. #define SPI_DATA_FORMAT2 SPI_SPIDAT1_DFSEL_FORMAT2
  63. #define SPI_DATA_FORMAT3 SPI_SPIDAT1_DFSEL_FORMAT3
  64. /*************************************************************************/
  65. /*
  66. ** Values that can be passed to SPIDat1Config API as flag to
  67. ** assert the CS pin(line) and to disable or Enable counter
  68. */
  69. /* Assert CS pin(line)*/
  70. #define SPI_CSHOLD SPI_SPIDAT1_CSHOLD
  71. /* Enable Counter */
  72. #define SPI_DELCOUNT_ENABLE SPI_SPIDAT1_WDEL
  73. /* Disable Counter */
  74. #define SPI_DELCOUNT_DISABLE 0
  75. /**********************************************************************/
  76. /*
  77. ** Values that can be passed to SPIConfigClkFormat API as flag to select
  78. ** clock polarity
  79. */
  80. /* Active low clock */
  81. #define SPI_CLK_POL_HIGH SPI_SPIFMT_POLARITY
  82. /* Active high clock */
  83. #define SPI_CLK_POL_LOW 0
  84. /* In Phase clock */
  85. #define SPI_CLK_INPHASE 0
  86. /* Out of Phase clock */
  87. #define SPI_CLK_OUTOFPHASE SPI_SPIFMT_PHASE
  88. /*********************************************************************/
  89. /*
  90. ** Values that can be passed to SPIParityEnable API as flag to select
  91. ** type of parity
  92. */
  93. /* Odd Parity */
  94. #define SPI_ODD_PARITY SPI_SPIFMT_PARPOL
  95. /* Even Parity */
  96. #define SPI_EVEN_PARITY 0
  97. /**********************************************************************/
  98. /*
  99. ** Values that can be passed to SPIIntLevelSet API as flag to map
  100. ** interrupts to interrupt line INT1
  101. */
  102. /* Data length error interrupt enable level */
  103. #define SPI_DATALEN_ERR_INTLVL SPI_SPILVL_DLENERRLVL
  104. /* Time out interrupt level */
  105. #define SPI_TIMEOUT_INTLVL SPI_SPILVL_TIMEOUTLVL
  106. /* Parrity interrupt level */
  107. #define SPI_PARITY_ERR_INTLVL SPI_SPILVL_PARERRLVL
  108. /* Desynchronized salve interrupt level */
  109. #define SPI_DESYNC_SLAVE_INTLVL SPI_SPILVL_DESYNCLVL
  110. /* Bit error interrupt level */
  111. #define SPI_BIT_ERR_INTLVL SPI_SPILVL_BITERRLVL
  112. /* Receive overrun interrupt level */
  113. #define SPI_RECV_OVERRUN_INTLVL SPI_SPILVL_OVRNINTLVL
  114. /* Receive interrupt level */
  115. #define SPI_RECV_INTLVL SPI_SPILVL_RXINTLVL
  116. /* Transmit interrupt level */
  117. #define SPI_TRANSMIT_INTLVL SPI_SPILVL_TXINTLVL
  118. /********************************************************************/
  119. /*
  120. ** Values that can be passed to SPIIntEnable API as flag to
  121. ** enable or disable the interrupt
  122. */
  123. /* Data length error interrupt */
  124. #define SPI_DATALEN_ERR_INT SPI_SPIINT0_DLENERRENA
  125. /* Time out interrupt level */
  126. #define SPI_TIMEOUT_INT SPI_SPIINT0_TIMEOUTENA
  127. /* Parrity error interrupt */
  128. #define SPI_PARITY_ERR_INT SPI_SPIINT0_PARERRENA
  129. /* Desyncronized slave interrupt */
  130. #define SPI_DESYNC_SLAVE_INT SPI_SPIINT0_DESYNCENA
  131. /* Bit error interrupt */
  132. #define SPI_BIT_ERR_INT SPI_SPIINT0_BITERRENA
  133. /* Receive overrun interrupt */
  134. #define SPI_RECV_OVERRUN_INT SPI_SPIINT0_OVRNINTENA
  135. /* Receive interrupt */
  136. #define SPI_RECV_INT SPI_SPIINT0_RXINTENA
  137. /* Transmit interrupt */
  138. #define SPI_TRANSMIT_INT SPI_SPIINT0_TXINTENA
  139. /* DMA request interrupt */
  140. #define SPI_DMA_REQUEST_ENA_INT SPI_SPIINT0_DMAREQEN
  141. /*****************************************************************/
  142. /* Transmit buffer is empty interrupt */
  143. #define SPI_TX_BUF_EMPTY 0x14
  144. /* Receive buffer is full interrupt */
  145. #define SPI_RECV_FULL 0x12
  146. /* Error interrupt */
  147. #define SPI_ERR 0x11
  148. /****************************************************************/
  149. /*
  150. ** Prototypes of SPI driver API.
  151. **
  152. */
  153. void SPIClkConfigure(unsigned int baseAdd, unsigned int moduleClk,
  154. unsigned int spiClk, unsigned int dataFormat);
  155. void SPIEnable(unsigned int baseAdd);
  156. void SPIReset(unsigned int baseAdd);
  157. void SPIOutOfReset(unsigned int baseAdd);
  158. void SPIModeConfigure(unsigned int baseAdd, unsigned int flag);
  159. void SPIPinControl(unsigned int baseAdd, unsigned int idx,
  160. unsigned int flag, unsigned int *val);
  161. void SPIDelayConfigure(unsigned int baseAdd, unsigned int c2edelay,
  162. unsigned int t2edelay, unsigned int t2cdelay,
  163. unsigned int c2tdelay);
  164. void SPIDefaultCSSet(unsigned int baseAdd, unsigned char dcsval);
  165. void SPIDat1Config(unsigned int baseAdd, unsigned int flag, unsigned char cs);
  166. void SPIConfigClkFormat(unsigned int baseAdd, unsigned int flag,
  167. unsigned int dataFormat);
  168. void SPITransmitData1(unsigned int baseAdd, unsigned int data);
  169. void SPICSTimerEnable(unsigned int baseAdd, unsigned int dataFormat);
  170. void SPICSTimerDisable(unsigned int baseAdd, unsigned int dataFormat);
  171. void SPICharLengthSet(unsigned int baseAdd, unsigned int flag,
  172. unsigned int dataFormat);
  173. void SPIShiftMsbFirst(unsigned int baseAdd, unsigned int dataFormat);
  174. void SPIShiftLsbFirst(unsigned int baseAdd, unsigned int dataFormat);
  175. void SPIParityEnable(unsigned int baseAdd, unsigned int flag,
  176. unsigned int dataFormat);
  177. void SPIParityDisable(unsigned int baseAdd, unsigned int dataFormat);
  178. void SPIWdelaySet(unsigned int baseAdd, unsigned int flag,
  179. unsigned int dataFormat);
  180. void SPIWaitEnable(unsigned int baseAdd, unsigned int dataFormat);
  181. void SPIWaitDisable(unsigned int baseAdd, unsigned int dataFormat);
  182. void SPIIntLevelSet(unsigned int baseAdd, unsigned int flag);
  183. void SPIIntEnable(unsigned int baseAdd, unsigned int flag);
  184. void SPIIntDisable(unsigned int baseAdd, unsigned int flag);
  185. void SPIIntStatusClear(unsigned int baseAdd, unsigned int flag);
  186. unsigned int SPIIntStatus(unsigned int baseAdd, unsigned int flag);
  187. unsigned int SPIDataReceive(unsigned int baseAdd);
  188. unsigned int SPIInterruptVectorGet(unsigned int baseAdd);
  189. #ifdef __cplusplus
  190. }
  191. #endif
  192. #endif