mcspi.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /**
  2. * \file mcspi.h
  3. *
  4. * \brief This file contains the function prototypes for the device
  5. * abstraction layer for McSPI. It also contains some
  6. * related 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 _MCSPI_H_
  42. #define _MCSPI_H_
  43. #include "hw_mcspi.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /****************************************************************************
  48. ** MACRO DEFINITIONS
  49. ****************************************************************************/
  50. /*
  51. ** Values used to determine the channel number used for McSPI communication.
  52. */
  53. #define MCSPI_CHANNEL_0 (0)
  54. #define MCSPI_CHANNEL_1 (1)
  55. #define MCSPI_CHANNEL_2 (2)
  56. #define MCSPI_CHANNEL_3 (3)
  57. /*
  58. ** Maximum number of McSPI channels used.
  59. */
  60. #define MCSPI_MAX_CH (4)
  61. /*
  62. ** Values used for determining the granularity for McSPI clock.
  63. */
  64. #define MCSPI_CLK_GRAN_2_PWR_N (0)
  65. #define MCSPI_CLK_GRAN_1 (1)
  66. /*
  67. ** Values of polarity and phase of SPICLK that are used to configure the clock
  68. ** value in various modes of operation.
  69. */
  70. #define MCSPI_CLK_MODE_0 ((MCSPI_CH0CONF_POL_ACTIVEHIGH << \
  71. MCSPI_CH0CONF_POL_SHIFT) | \
  72. MCSPI_CH0CONF_PHA_ODD)
  73. #define MCSPI_CLK_MODE_1 ((MCSPI_CH0CONF_POL_ACTIVEHIGH << \
  74. MCSPI_CH0CONF_POL_SHIFT) | \
  75. MCSPI_CH0CONF_PHA_EVEN)
  76. #define MCSPI_CLK_MODE_2 ((MCSPI_CH0CONF_POL_ACTIVELOW << \
  77. MCSPI_CH0CONF_POL_SHIFT) | \
  78. MCSPI_CH0CONF_PHA_ODD)
  79. #define MCSPI_CLK_MODE_3 ((MCSPI_CH0CONF_POL_ACTIVELOW << \
  80. MCSPI_CH0CONF_POL_SHIFT) | \
  81. MCSPI_CH0CONF_PHA_EVEN)
  82. /*
  83. ** Values of Single/Multi channel that can be used in master mode.
  84. */
  85. #define MCSPI_SINGLE_CH (MCSPI_MODULCTRL_SINGLE_SINGLE)
  86. #define MCSPI_MULTI_CH (MCSPI_MODULCTRL_SINGLE_MULTI)
  87. /*
  88. ** Values used to configure the chip select time control(TCS).
  89. */
  90. #define MCSPI_CS_TCS_0PNT5_CLK (MCSPI_CH0CONF_TCS0_0P5 << \
  91. MCSPI_CH0CONF_TCS0_SHIFT)
  92. #define MCSPI_CS_TCS_1PNT5_CLK (MCSPI_CH0CONF_TCS0_1P5 << \
  93. MCSPI_CH0CONF_TCS0_SHIFT)
  94. #define MCSPI_CS_TCS_2PNT5_CLK (MCSPI_CH0CONF_TCS0_2P5 << \
  95. MCSPI_CH0CONF_TCS0_SHIFT)
  96. #define MCSPI_CS_TCS_3PNT5_CLK (MCSPI_CH0CONF_TCS0_3P5 << \
  97. MCSPI_CH0CONF_TCS0_SHIFT)
  98. /*
  99. ** Value used to set the polarity for start bit for McSPI communication.
  100. */
  101. #define MCSPI_START_BIT_POL_LOW (MCSPI_CH0CONF_SBPOL_LOWLEVEL)
  102. #define MCSPI_START_BIT_POL_HIGH (MCSPI_CH0CONF_SBPOL)
  103. /*
  104. ** Values used to configure communication on data line pins.
  105. */
  106. #define MCSPI_DATA_LINE_COMM_MODE_0 ((MCSPI_CH0CONF_IS_LINE0) | \
  107. (MCSPI_CH0CONF_DPE1_ENABLED) | \
  108. (MCSPI_CH0CONF_DPE0_ENABLED))
  109. #define MCSPI_DATA_LINE_COMM_MODE_1 ((MCSPI_CH0CONF_IS_LINE0)| \
  110. (MCSPI_CH0CONF_DPE1_ENABLED)| \
  111. (MCSPI_CH0CONF_DPE0_DISABLED << \
  112. MCSPI_CH0CONF_DPE0_SHIFT))
  113. #define MCSPI_DATA_LINE_COMM_MODE_2 ((MCSPI_CH0CONF_IS_LINE0) | \
  114. (MCSPI_CH0CONF_DPE1_DISABLED << \
  115. MCSPI_CH0CONF_DPE1_SHIFT) | \
  116. (MCSPI_CH0CONF_DPE0_ENABLED))
  117. #define MCSPI_DATA_LINE_COMM_MODE_3 ((MCSPI_CH0CONF_IS_LINE0) | \
  118. (MCSPI_CH0CONF_DPE1_DISABLED << \
  119. MCSPI_CH0CONF_DPE1_SHIFT) | \
  120. (MCSPI_CH0CONF_DPE0_DISABLED << \
  121. MCSPI_CH0CONF_DPE0_SHIFT))
  122. #define MCSPI_DATA_LINE_COMM_MODE_4 ((MCSPI_CH0CONF_IS_LINE1 << \
  123. MCSPI_CH0CONF_IS_SHIFT) | \
  124. (MCSPI_CH0CONF_DPE1_ENABLED) | \
  125. (MCSPI_CH0CONF_DPE0_ENABLED))
  126. #define MCSPI_DATA_LINE_COMM_MODE_5 ((MCSPI_CH0CONF_IS_LINE1 << \
  127. MCSPI_CH0CONF_IS_SHIFT) | \
  128. (MCSPI_CH0CONF_DPE1_ENABLED) | \
  129. (MCSPI_CH0CONF_DPE0_DISABLED << \
  130. MCSPI_CH0CONF_DPE0_SHIFT))
  131. #define MCSPI_DATA_LINE_COMM_MODE_6 ((MCSPI_CH0CONF_IS_LINE1 << \
  132. MCSPI_CH0CONF_IS_SHIFT) | \
  133. (MCSPI_CH0CONF_DPE1_DISABLED << \
  134. MCSPI_CH0CONF_DPE1_SHIFT) | \
  135. (MCSPI_CH0CONF_DPE0_ENABLED))
  136. #define MCSPI_DATA_LINE_COMM_MODE_7 ((MCSPI_CH0CONF_IS_LINE1 << \
  137. MCSPI_CH0CONF_IS_SHIFT) | \
  138. (MCSPI_CH0CONF_DPE1_DISABLED << \
  139. MCSPI_CH0CONF_DPE1_SHIFT) | \
  140. (MCSPI_CH0CONF_DPE0_DISABLED << \
  141. MCSPI_CH0CONF_DPE0_SHIFT))
  142. /*
  143. ** Values used to enable initial delay for first transfer from McSPI peripheral.
  144. */
  145. #define MCSPI_INITDLY_0 (MCSPI_MODULCTRL_INITDLY_NODELAY)
  146. #define MCSPI_INITDLY_4 (MCSPI_MODULCTRL_INITDLY_4CLKDLY \
  147. << MCSPI_MODULCTRL_INITDLY_SHIFT)
  148. #define MCSPI_INITDLY_8 (MCSPI_MODULCTRL_INITDLY_8CLKDLY \
  149. << MCSPI_MODULCTRL_INITDLY_SHIFT)
  150. #define MCSPI_INITDLY_16 (MCSPI_MODULCTRL_INITDLY_16CLKDLY \
  151. << MCSPI_MODULCTRL_INITDLY_SHIFT)
  152. #define MCSPI_INITDLY_32 (MCSPI_MODULCTRL_INITDLY_32CLKDLY \
  153. << MCSPI_MODULCTRL_INITDLY_SHIFT)
  154. /*
  155. ** Values used to determine transmit/receive modes of McSPI peripheral in
  156. ** master mode.
  157. */
  158. #define MCSPI_TX_RX_MODE (MCSPI_CH0CONF_TRM_TXRX)
  159. #define MCSPI_RX_ONLY_MODE (MCSPI_CH0CONF_TRM_RXONLY << \
  160. MCSPI_CH0CONF_TRM_SHIFT)
  161. #define MCSPI_TX_ONLY_MODE (MCSPI_CH0CONF_TRM_TXONLY << \
  162. MCSPI_CH0CONF_TRM_SHIFT)
  163. /*
  164. ** Values that can be passed to enable/disable/clear status of the various
  165. ** interrupts of McSPI peripheral.
  166. ** These macros can also be used to check the status obtained from
  167. ** 'McSPIIntStatusGet' API.
  168. ** 0 <= chan <= 3 \n
  169. */
  170. #define MCSPI_INT_TX_EMPTY(chan) (1 << ((chan) * 4))
  171. #define MCSPI_INT_TX_UNDERFLOW(chan) (2 << ((chan) * 4))
  172. #define MCSPI_INT_RX_FULL(chan) (4 << ((chan) * 4))
  173. #define MCSPI_INT_RX0_OVERFLOW (8u)
  174. #define MCSPI_INT_EOWKE (MCSPI_IRQENABLE_EOW_ENABLE)
  175. /*
  176. ** Values used to check the status of McSPI channel status registers and FIFO.
  177. */
  178. #define MCSPI_CH_STAT_RXS_FULL (MCSPI_CH0STAT_RXS)
  179. #define MCSPI_CH_STAT_TXS_EMPTY (MCSPI_CH0STAT_TXS)
  180. #define MCSPI_CH_STAT_EOT (MCSPI_CH0STAT_EOT)
  181. #define MCSPI_CH_TXFFE (MCSPI_CH0STAT_TXFFE)
  182. #define MCSPI_CH_TXFFF (MCSPI_CH0STAT_TXFFF)
  183. #define MCSPI_CH_RXFFE (MCSPI_CH0STAT_RXFFE)
  184. #define MCSPI_CH_RXFFF (MCSPI_CH0STAT_RXFFF)
  185. /*
  186. ** Values used to set the word length for McSPI communication.
  187. ** 'n' can take values only between 4 <= n <= 32.
  188. */
  189. #define MCSPI_WORD_LENGTH(n) ((n - 1) << MCSPI_CH0CONF_WL_SHIFT)
  190. /*
  191. ** Values used to set CS polarity for the McSPI peripheral.
  192. */
  193. #define MCSPI_CS_POL_HIGH (MCSPI_CH0CONF_EPOL_ACTIVEHIGH)
  194. #define MCSPI_CS_POL_LOW (MCSPI_CH0CONF_EPOL)
  195. /*
  196. ** Values used to enable/disable the read/write DMA events of McSPI peripheral.
  197. */
  198. #define MCSPI_DMA_RX_EVENT (MCSPI_CH0CONF_DMAR)
  199. #define MCSPI_DMA_TX_EVENT (MCSPI_CH0CONF_DMAW)
  200. /*
  201. ** Value used to enable the turbo mode of operation for McSPI peripheral.
  202. */
  203. #define MCSPI_SET_STATUS_BIT (MCSPI_SYST_SSB)
  204. /*
  205. ** Value used to set the value of SPICLK in master mode of McSPI peripheral.
  206. */
  207. #define MCSPI_CLK_HIGH (MCSPI_SYST_SPICLK)
  208. #define MCSPI_CLK_LOW (0x00000000)
  209. /*
  210. ** Value used to enable/disable multiple word ocp access.
  211. */
  212. #define MCSPI_MOA_ENABLE (MCSPI_MODULCTRL_MOA)
  213. #define MCSPI_MOA_DISABLE (MCSPI_MODULCTRL_MOA_DISABLED)
  214. /*
  215. ** Value used to enable/disable FDAA operation of McSPI peripheral.
  216. */
  217. #define MCSPI_FDAA_DISABLE (MCSPI_MODULCTRL_FDAA_NOSHADOWREG)
  218. #define MCSPI_FDAA_ENABLE (MCSPI_MODULCTRL_FDAA)
  219. /*
  220. ** Values used to enable/disable the Tx/Rx FIFOs of McSPI peripheral.
  221. */
  222. #define MCSPI_RX_FIFO_ENABLE (MCSPI_CH0CONF_FFER)
  223. #define MCSPI_RX_FIFO_DISABLE (MCSPI_CH0CONF_FFER_FFDISABLED)
  224. #define MCSPI_TX_FIFO_ENABLE (MCSPI_CH0CONF_FFEW)
  225. #define MCSPI_TX_FIFO_DISABLE (MCSPI_CH0CONF_FFEW_FFDISABLED)
  226. extern void McSPIClkConfig(unsigned int baseAdd, unsigned int spiInClk,
  227. unsigned int spiOutClk,
  228. unsigned int chNum, unsigned int clkMode);
  229. extern void McSPIWordLengthSet(unsigned int baseAdd, unsigned int wordLength,
  230. unsigned int chNum);
  231. extern void McSPICSEnable(unsigned int baseAdd);
  232. extern void McSPICSDisable(unsigned int baseAdd);
  233. extern void McSPICSTimeControlSet(unsigned int baseAdd, unsigned int csTimeControl,
  234. unsigned int chNum);
  235. extern void McSPICSAssert(unsigned int baseAdd, unsigned int chNum);
  236. extern void McSPICSDeAssert(unsigned int baseAdd, unsigned int chNum);
  237. extern void McSPIStartBitEnable(unsigned int baseAdd, unsigned int chNum);
  238. extern void McSPIStartBitPolarityConfig(unsigned int baseAdd,
  239. unsigned int startBitPol, unsigned int chNum);
  240. extern void McSPICSPolarityConfig(unsigned int baseAdd, unsigned int spiEnPol,
  241. unsigned int chNum);
  242. extern void McSPIStartBitDisable(unsigned int baseAdd,unsigned int chNum);
  243. extern void McSPIMasterModeEnable(unsigned int baseAdd);
  244. extern unsigned int McSPIMasterModeConfig(unsigned int baseAdd,
  245. unsigned int channelMode,
  246. unsigned int trMode,
  247. unsigned int pinMode,
  248. unsigned int chNum);
  249. extern void McSPIChannelEnable(unsigned int baseAdd, unsigned int chNum);
  250. extern void McSPIChannelDisable(unsigned int baseAdd, unsigned int chNum);
  251. extern void McSPIReset(unsigned int baseAdd);
  252. extern void McSPITurboModeEnable(unsigned int baseAdd, unsigned int chNum);
  253. extern void McSPITurboModeDisable(unsigned int baseAdd, unsigned int chNum);
  254. extern void McSPITxFIFOConfig(unsigned int baseAdd, unsigned int txFifo,
  255. unsigned int chNum);
  256. extern void McSPIRxFIFOConfig(unsigned int baseAdd, unsigned int rxFifo,
  257. unsigned int chNum);
  258. extern void McSPIFIFOTrigLvlSet(unsigned int baseAdd, unsigned char afl,
  259. unsigned char ael, unsigned int trMode);
  260. extern void McSPIWordCountSet(unsigned int baseAdd, unsigned short wCnt);
  261. extern void McSPIDMAEnable(unsigned int baseAdd, unsigned int dmaFlags,
  262. unsigned int chNum);
  263. extern void McSPIDMADisable(unsigned int baseAdd, unsigned int dmaFlags,
  264. unsigned int chNum);
  265. extern void McSPIIntEnable(unsigned int baseAdd, unsigned int intFlags);
  266. extern void McSPIIntDisable(unsigned int baseAdd, unsigned int intFlags);
  267. extern void McSPIInitDelayConfig(unsigned int baseAdd, unsigned int initDelay);
  268. extern void McSPITransmitData(unsigned int baseAdd, unsigned int txData,
  269. unsigned int chNum);
  270. extern unsigned int McSPIReceiveData(unsigned int baseAdd,unsigned int chNum);
  271. extern unsigned int McSPIIntStatusGet(unsigned int baseAdd);
  272. extern void McSPIIntStatusClear(unsigned int baseAdd, unsigned int intFlags);
  273. extern unsigned int McSPIChannelStatusGet(unsigned int baseAdd, unsigned int chNum);
  274. extern void McSPIMultipleWordAccessConfig(unsigned int baseAdd, unsigned int moa);
  275. extern void McSPIFIFODatManagementConfig(unsigned int baseAdd, unsigned int fdaa);
  276. #ifdef __cplusplus
  277. }
  278. #endif
  279. #endif
  280. /*************************** END OF FILE **************************************/