nu_spi.h 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /**************************************************************************//**
  2. * @file spi.h
  3. * @brief NUC980 series SPI driver header file
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. * @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  7. *****************************************************************************/
  8. #ifndef __NU_SPI_H__
  9. #define __NU_SPI_H__
  10. #ifdef __cplusplus
  11. extern "C"
  12. {
  13. #endif
  14. /**
  15. @addtogroup REGISTER Control Register
  16. @{
  17. */
  18. /**
  19. @addtogroup SPI Serial Peripheral Interface Controller(SPI)
  20. Memory Mapped Structure for SPI Controller
  21. @{ */
  22. typedef struct
  23. {
  24. /**
  25. * @var SPI_T::CTL
  26. * Offset: 0x00 SPI Control Register
  27. * ---------------------------------------------------------------------------------------------------
  28. * |Bits |Field |Descriptions
  29. * | :----: | :----: | :---- |
  30. * |[0] |SPIEN |SPI Transfer Control Enable Bit
  31. * | | |In Master mode, the transfer will start when there is data in the FIFO buffer after this bit is set to 1
  32. * | | |In Slave mode, this device is ready to receive data when this bit is set to 1.
  33. * | | |0 = Transfer control Disabled.
  34. * | | |1 = Transfer control Enabled.
  35. * | | |Note: Before changing the configurations of SPIx_CTL, SPIx_CLKDIV, SPIx_SSCTL and SPIx_FIFOCTL registers, user shall clear the SPIEN (SPIx_CTL[0]) and confirm the SPIENSTS (SPIx_STATUS[15]) is 0.
  36. * |[1] |RXNEG |Receive on Negative Edge
  37. * | | |0 = Received data input signal is latched on the rising edge of SPI bus clock.
  38. * | | |1 = Received data input signal is latched on the falling edge of SPI bus clock.
  39. * |[2] |TXNEG |Transmit on Negative Edge
  40. * | | |0 = Transmitted data output signal is changed on the rising edge of SPI bus clock.
  41. * | | |1 = Transmitted data output signal is changed on the falling edge of SPI bus clock.
  42. * |[3] |CLKPOL |Clock Polarity
  43. * | | |0 = SPI bus clock is idle low.
  44. * | | |1 = SPI bus clock is idle high.
  45. * |[7:4] |SUSPITV |Suspend Interval (Master Only)
  46. * | | |The four bits provide configurable suspend interval between two successive transmit/receive transaction in a transfer
  47. * | | |The definition of the suspend interval is the interval between the last clock edge of the preceding transaction word and the first clock edge of the following transaction word
  48. * | | |The default value is 0x3
  49. * | | |The period of the suspend interval is obtained according to the following equation.
  50. * | | |(SUSPITV[3:0] + 0.5) * period of SPICLK clock cycle
  51. * | | |Example:
  52. * | | |SUSPITV = 0x0 .... 0.5 SPICLK clock cycle.
  53. * | | |SUSPITV = 0x1 .... 1.5 SPICLK clock cycle.
  54. * | | |.....
  55. * | | |SUSPITV = 0xE .... 14.5 SPICLK clock cycle.
  56. * | | |SUSPITV = 0xF .... 15.5 SPICLK clock cycle.
  57. * |[12:8] |DWIDTH |Data Width
  58. * | | |This field specifies how many bits can be transmitted / received in one transaction
  59. * | | |The minimum bit length is 8 bits and can up to 32 bits.
  60. * | | |DWIDTH = 0x08 .... 8 bits.
  61. * | | |DWIDTH = 0x09 .... 9 bits.
  62. * | | |.....
  63. * | | |DWIDTH = 0x1F .... 31 bits.
  64. * | | |DWIDTH = 0x00 .... 32 bits.
  65. * | | |Note: For SPI1~SPI4, this bit field will decide the depth of TX/RX FIFO configuration in SPI mode
  66. * | | |Therefore, changing this bit field will clear TX/RX FIFO by hardware automatically in SPI1~SPI4.
  67. * |[13] |LSB |Send LSB First
  68. * | | |0 = The MSB, which bit of transmit/receive register depends on the setting of DWIDTH, is transmitted/received first.
  69. * | | |1 = The LSB, bit 0 of the SPI TX register, is sent first to the SPI data output pin, and the first bit received from the SPI data input pin will be put in the LSB position of the RX register (bit 0 of SPI_RX).
  70. * |[14] |HALFDPX |SPI Half-duplex Transfer Enable Bit
  71. * | | |This bit is used to select full-duplex or half-duplex for SPI transfer
  72. * | | |The bit field DATDIR (SPIx_CTL[20]) can be used to set the data direction in half-duplex transfer.
  73. * | | |0 = SPI operates in full-duplex transfer.
  74. * | | |1 = SPI operates in half-duplex transfer.
  75. * |[15] |RXONLY |Receive-only Mode Enable Bit (Master Only)
  76. * | | |This bit field is only available in Master mode
  77. * | | |In receive-only mode, SPI Master will generate SPI bus clock continuously for receiving data bit from SPI slave device and assert the BUSY status.
  78. * | | |0 = Receive-only mode Disabled.
  79. * | | |1 = Receive-only mode Enabled.
  80. * |[17] |UNITIEN |Unit Transfer Interrupt Enable Bit
  81. * | | |0 = SPI unit transfer interrupt Disabled.
  82. * | | |1 = SPI unit transfer interrupt Enabled.
  83. * |[18] |SLAVE |Slave Mode Control
  84. * | | |0 = Master mode.
  85. * | | |1 = Slave mode.
  86. * |[19] |REORDER |Byte Reorder Function Enable Bit
  87. * | | |0 = Byte Reorder function Disabled.
  88. * | | |1 = Byte Reorder function Enabled
  89. * | | |A byte suspend interval will be inserted among each byte
  90. * | | |The period of the byte suspend interval depends on the setting of SUSPITV.
  91. * | | |Note: Byte Reorder function is only available if DWIDTH is defined as 16, 24, and 32 bits.
  92. * |[20] |DATDIR |Data Port Direction Control
  93. * | | |This bit is used to select the data input/output direction in half-duplex transfer and Dual/Quad transfer
  94. * | | |0 = SPI data is input direction.
  95. * | | |1 = SPI data is output direction.
  96. * @var SPI_T::CLKDIV
  97. * Offset: 0x04 SPI Clock Divider Register
  98. * ---------------------------------------------------------------------------------------------------
  99. * |Bits |Field |Descriptions
  100. * | :----: | :----: | :---- |
  101. * |[8:0] |DIVIDER |Clock Divider
  102. * | | |The value in this field is the frequency divider for generating the peripheral clock, fspi_eclk, and the SPI bus clock of SPI Master
  103. * | | |The frequency is obtained according to the following equation.
  104. * | | |where
  105. * | | |is the peripheral clock source, which is defined in the clock control register, CLK_CLKSEL2.
  106. * | | |Note: Not supported in I2S mode.
  107. * @var SPI_T::SSCTL
  108. * Offset: 0x08 SPI Slave Select Control Register
  109. * ---------------------------------------------------------------------------------------------------
  110. * |Bits |Field |Descriptions
  111. * | :----: | :----: | :---- |
  112. * |[0] |SS |Slave Selection Control (Master Only)
  113. * | | |If AUTOSS bit is cleared to 0,
  114. * | | |0 = set the SPIx_SS line to inactive state.
  115. * | | |1 = set the SPIx_SS line to active state.
  116. * | | |If the AUTOSS bit is set to 1,
  117. * | | |0 = Keep the SPIx_SS line at inactive state.
  118. * | | |1 = SPIx_SS line will be automatically driven to active state for the duration of data transfer, and will be driven to inactive state for the rest of the time
  119. * | | |The active state of SPIx_SS is specified in SSACTPOL (SPIx_SSCTL[2]).
  120. * |[2] |SSACTPOL |Slave Selection Active Polarity
  121. * | | |This bit defines the active polarity of slave selection signal (SPIx_SS).
  122. * | | |0 = The slave selection signal SPIx_SS is active low.
  123. * | | |1 = The slave selection signal SPIx_SS is active high.
  124. * |[3] |AUTOSS |Automatic Slave Selection Function Enable Bit (Master Only)
  125. * | | |0 = Automatic slave selection function Disabled
  126. * | | |Slave selection signal will be asserted/de-asserted according to SS (SPIx_SSCTL[0]).
  127. * | | |1 = Automatic slave selection function Enabled.
  128. * |[8] |SLVBEIEN |Slave Mode Bit Count Error Interrupt Enable Bit
  129. * | | |0 = Slave mode bit count error interrupt Disabled.
  130. * | | |1 = Slave mode bit count error interrupt Enabled.
  131. * |[9] |SLVURIEN |Slave Mode TX Under Run Interrupt Enable Bit
  132. * | | |0 = Slave mode TX under run interrupt Disabled.
  133. * | | |1 = Slave mode TX under run interrupt Enabled.
  134. * |[12] |SSACTIEN |Slave Select Active Interrupt Enable Bit
  135. * | | |0 = Slave select active interrupt Disabled.
  136. * | | |1 = Slave select active interrupt Enabled.
  137. * |[13] |SSINAIEN |Slave Select Inactive Interrupt Enable Bit
  138. * | | |0 = Slave select inactive interrupt Disabled.
  139. * | | |1 = Slave select inactive interrupt Enabled.
  140. * @var SPI_T::PDMACTL
  141. * Offset: 0x0C SPI PDMA Control Register
  142. * ---------------------------------------------------------------------------------------------------
  143. * |Bits |Field |Descriptions
  144. * | :----: | :----: | :---- |
  145. * |[0] |TXPDMAEN |Transmit PDMA Enable Bit
  146. * | | |0 = Transmit PDMA function Disabled.
  147. * | | |1 = Transmit PDMA function Enabled.
  148. * | | |Note: In SPI Master mode with full duplex transfer, if both TX and RX PDMA functions are enabled, RX PDMA function cannot be enabled prior to TX PDMA function
  149. * | | |User can enable TX PDMA function firstly or enable both functions simultaneously.
  150. * |[1] |RXPDMAEN |Receive PDMA Enable Bit
  151. * | | |0 = Receive PDMA function Disabled.
  152. * | | |1 = Receive PDMA function Enabled.
  153. * |[2] |PDMARST |PDMA Reset
  154. * | | |0 = No effect.
  155. * | | |1 = Reset the PDMA control logic of the SPI controller. This bit will be automatically cleared to 0.
  156. * @var SPI_T::FIFOCTL
  157. * Offset: 0x10 SPI FIFO Control Register
  158. * ---------------------------------------------------------------------------------------------------
  159. * |Bits |Field |Descriptions
  160. * | :----: | :----: | :---- |
  161. * |[0] |RXRST |Receive Reset
  162. * | | |0 = No effect.
  163. * | | |1 = Reset receive FIFO pointer and receive circuit
  164. * | | |The RXFULL bit will be cleared to 0 and the RXEMPTY bit will be set to 1
  165. * | | |This bit will be cleared to 0 by hardware about 3 system clock cycles + 2 peripheral clock cycles after it is set to 1
  166. * | | |User can read TXRXRST (SPIx_STATUS[23]) to check if reset is accomplished or not.
  167. * |[1] |TXRST |Transmit Reset
  168. * | | |0 = No effect.
  169. * | | |1 = Reset transmit FIFO pointer and transmit circuit
  170. * | | |The TXFULL bit will be cleared to 0 and the TXEMPTY bit will be set to 1
  171. * | | |This bit will be cleared to 0 by hardware about 3 system clock cycles + 2 peripheral clock cycles after it is set to 1
  172. * | | |User can read TXRXRST (SPIx_STATUS[23]) to check if reset is accomplished or not.
  173. * | | |Note: If TX underflow event occurs in SPI Slave mode, this bit can be used to make SPI return to idle state.
  174. * |[2] |RXTHIEN |Receive FIFO Threshold Interrupt Enable Bit
  175. * | | |0 = RX FIFO threshold interrupt Disabled.
  176. * | | |1 = RX FIFO threshold interrupt Enabled.
  177. * |[3] |TXTHIEN |Transmit FIFO Threshold Interrupt Enable Bit
  178. * | | |0 = TX FIFO threshold interrupt Disabled.
  179. * | | |1 = TX FIFO threshold interrupt Enabled.
  180. * |[4] |RXTOIEN |Slave Receive Time-out Interrupt Enable Bit
  181. * | | |0 = Receive time-out interrupt Disabled.
  182. * | | |1 = Receive time-out interrupt Enabled.
  183. * |[5] |RXOVIEN |Receive FIFO Overrun Interrupt Enable Bit
  184. * | | |0 = Receive FIFO overrun interrupt Disabled.
  185. * | | |1 = Receive FIFO overrun interrupt Enabled.
  186. * |[6] |TXUFPOL |TX Underflow Data Polarity
  187. * | | |0 = The SPI data out is keep 0 if there is TX underflow event in Slave mode.
  188. * | | |1 = The SPI data out is keep 1 if there is TX underflow event in Slave mode.
  189. * | | |Note:
  190. * | | |1. The TX underflow event occurs if there is no any data in TX FIFO when the slave selection signal is active.
  191. * | | |2. This bit should be set as 0 in I2S mode.
  192. * | | |3. When TX underflow event occurs, SPIx_MISO pin state will be determined by this setting even though TX FIFO is not empty afterward
  193. * | | |Data stored in TX FIFO will be sent through SPIx_MISO pin in the next transfer frame.
  194. * |[7] |TXUFIEN |TX Underflow Interrupt Enable Bit
  195. * | | |When TX underflow event occurs in Slave mode, TXUFIF (SPIx_STATUS[19]) will be set to 1
  196. * | | |This bit is used to enable the TX underflow interrupt.
  197. * | | |0 = Slave TX underflow interrupt Disabled.
  198. * | | |1 = Slave TX underflow interrupt Enabled.
  199. * |[8] |RXFBCLR |Receive FIFO Buffer Clear
  200. * | | |0 = No effect.
  201. * | | |1 = Clear receive FIFO pointer
  202. * | | |The RXFULL bit will be cleared to 0 and the RXEMPTY bit will be set to 1
  203. * | | |This bit will be cleared to 0 by hardware about 1 system clock after it is set to 1.
  204. * | | |Note: The RX shift register will not be cleared.
  205. * |[9] |TXFBCLR |Transmit FIFO Buffer Clear
  206. * | | |0 = No effect.
  207. * | | |1 = Clear transmit FIFO pointer
  208. * | | |The TXFULL bit will be cleared to 0 and the TXEMPTY bit will be set to 1
  209. * | | |This bit will be cleared to 0 by hardware about 1 system clock after it is set to 1.
  210. * | | |Note: The TX shift register will not be cleared.
  211. * |[26:24] |RXTH |Receive FIFO Threshold
  212. * | | |If the valid data count of the receive FIFO buffer is larger than the RXTH setting, the RXTHIF bit will be set to 1, else the RXTHIF bit will be cleared to 0
  213. * | | |For SPI1~SPI4, the MSB of this bit field is only meaningful while SPI mode 8~16 bits of data length.
  214. * |[30:28] |TXTH |Transmit FIFO Threshold
  215. * | | |If the valid data count of the transmit FIFO buffer is less than or equal to the TXTH setting, the TXTHIF bit will be set to 1, else the TXTHIF bit will be cleared to 0
  216. * | | |For SPI1~SPI4, the MSB of this bit field is only meaningful while SPI mode 8~16 bits of data length
  217. * @var SPI_T::STATUS
  218. * Offset: 0x14 SPI Status Register
  219. * ---------------------------------------------------------------------------------------------------
  220. * |Bits |Field |Descriptions
  221. * | :----: | :----: | :---- |
  222. * |[0] |BUSY |Busy Status (Read Only)
  223. * | | |0 = SPI controller is in idle state.
  224. * | | |1 = SPI controller is in busy state.
  225. * | | |The following listing are the bus busy conditions:
  226. * | | |a. SPIx_CTL[0] = 1 and TXEMPTY = 0.
  227. * | | |b
  228. * | | |For SPI Master mode, SPIx_CTL[0] = 1 and TXEMPTY = 1 but the current transaction is not finished yet.
  229. * | | |c. For SPI Master mode, SPIx_CTL[0] = 1 and RXONLY = 1.
  230. * | | |d
  231. * | | |For SPI Slave mode, the SPIx_CTL[0] = 1 and there is serial clock input into the SPI core logic when slave select is active.
  232. * | | |For SPI Slave mode, the SPIx_CTL[0] = 1 and the transmit buffer or transmit shift register is not empty even if the slave select is inactive.
  233. * |[1] |UNITIF |Unit Transfer Interrupt Flag
  234. * | | |0 = No transaction has been finished since this bit was cleared to 0.
  235. * | | |1 = SPI controller has finished one unit transfer.
  236. * | | |Note: This bit will be cleared by writing 1 to it.
  237. * |[2] |SSACTIF |Slave Select Active Interrupt Flag
  238. * | | |0 = Slave select active interrupt was cleared or not occurred.
  239. * | | |1 = Slave select active interrupt event occurred.
  240. * | | |Note: Only available in Slave mode. This bit will be cleared by writing 1 to it.
  241. * |[3] |SSINAIF |Slave Select Inactive Interrupt Flag
  242. * | | |0 = Slave select inactive interrupt was cleared or not occurred.
  243. * | | |1 = Slave select inactive interrupt event occurred.
  244. * | | |Note: Only available in Slave mode. This bit will be cleared by writing 1 to it.
  245. * |[4] |SSLINE |Slave Select Line Bus Status (Read Only)
  246. * | | |0 = The slave select line status is 0.
  247. * | | |1 = The slave select line status is 1.
  248. * | | |Note: This bit is only available in Slave mode
  249. * | | |If SSACTPOL (SPIx_SSCTL[2]) is set 0, and the SSLINE is 1, the SPI slave select is in inactive status.
  250. * |[6] |SLVBEIF |Slave Mode Bit Count Error Interrupt Flag
  251. * | | |In Slave mode, when the slave select line goes to inactive state, if bit counter is mismatch with DWIDTH, this interrupt flag will be set to 1.
  252. * | | |0 = No Slave mode bit count error event.
  253. * | | |1 = Slave mode bit count error event occurs.
  254. * | | |Note: If the slave select active but there is no any bus clock input, the SLVBEIF also active when the slave select goes to inactive state
  255. * | | |This bit will be cleared by writing 1 to it.
  256. * |[7] |SLVURIF |Slave Mode TX Under Run Interrupt Flag
  257. * | | |In Slave mode, if TX underflow event occurs and the slave select line goes to inactive state, this interrupt flag will be set to 1.
  258. * | | |0 = No Slave TX under run event.
  259. * | | |1 = Slave TX under run event occurs.
  260. * | | |Note: This bit will be cleared by writing 1 to it.
  261. * |[8] |RXEMPTY |Receive FIFO Buffer Empty Indicator (Read Only)
  262. * | | |0 = Receive FIFO buffer is not empty.
  263. * | | |1 = Receive FIFO buffer is empty.
  264. * |[9] |RXFULL |Receive FIFO Buffer Full Indicator (Read Only)
  265. * | | |0 = Receive FIFO buffer is not full.
  266. * | | |1 = Receive FIFO buffer is full.
  267. * |[10] |RXTHIF |Receive FIFO Threshold Interrupt Flag (Read Only)
  268. * | | |0 = The valid data count within the receive FIFO buffer is smaller than or equal to the setting value of RXTH.
  269. * | | |1 = The valid data count within the receive FIFO buffer is larger than the setting value of RXTH.
  270. * |[11] |RXOVIF |Receive FIFO Overrun Interrupt Flag
  271. * | | |When the receive FIFO buffer is full, the follow-up data will be dropped and this bit will be set to 1.
  272. * | | |0 = No FIFO is overrun.
  273. * | | |1 = Receive FIFO is overrun.
  274. * | | |Note: This bit will be cleared by writing 1 to it.
  275. * |[12] |RXTOIF |Receive Time-out Interrupt Flag
  276. * | | |0 = No receive FIFO time-out event.
  277. * | | |1 = Receive FIFO buffer is not empty and no read operation on receive FIFO buffer over 64 SPI peripheral clock periods in Master mode or over 576 SPI peripheral clock periods in Slave mode
  278. * | | |When the received FIFO buffer is read by software, the time-out status will be cleared automatically.
  279. * | | |Note: This bit will be cleared by writing 1 to it.
  280. * |[15] |SPIENSTS |SPI Enable Status (Read Only)
  281. * | | |0 = The SPI controller is disabled.
  282. * | | |1 = The SPI controller is enabled.
  283. * | | |Note: The SPI peripheral clock is asynchronous with the system clock
  284. * | | |In order to make sure the SPI control logic is disabled, this bit indicates the real status of SPI controller.
  285. * |[16] |TXEMPTY |Transmit FIFO Buffer Empty Indicator (Read Only)
  286. * | | |0 = Transmit FIFO buffer is not empty.
  287. * | | |1 = Transmit FIFO buffer is empty.
  288. * |[17] |TXFULL |Transmit FIFO Buffer Full Indicator (Read Only)
  289. * | | |0 = Transmit FIFO buffer is not full.
  290. * | | |1 = Transmit FIFO buffer is full.
  291. * |[18] |TXTHIF |Transmit FIFO Threshold Interrupt Flag (Read Only)
  292. * | | |0 = The valid data count within the transmit FIFO buffer is larger than the setting value of TXTH.
  293. * | | |1 = The valid data count within the transmit FIFO buffer is less than or equal to the setting value of TXTH.
  294. * |[19] |TXUFIF |TX Underflow Interrupt Flag
  295. * | | |When the TX underflow event occurs, this bit will be set to 1, the state of data output pin depends on the setting of TXUFPOL.
  296. * | | |0 = No effect.
  297. * | | |1 = No data in Transmit FIFO and TX shift register when the slave selection signal is active.
  298. * | | |Note 1: This bit will be cleared by writing 1 to it.
  299. * | | |Note 2: If reset slave's transmission circuit when slave selection signal is active, this flag will be set to 1 after 2 peripheral clock cycles + 3 system clock cycles since the reset operation is done.
  300. * |[23] |TXRXRST |TX or RX Reset Status (Read Only)
  301. * | | |0 = The reset function of TXRST or RXRST is done.
  302. * | | |1 = Doing the reset function of TXRST or RXRST.
  303. * | | |Note: Both the reset operations of TXRST and RXRST need 3 system clock cycles + 2 peripheral clock cycles
  304. * | | |User can check the status of this bit to monitor the reset function is doing or done.
  305. * |[27:24] |RXCNT |Receive FIFO Data Count (Read Only)
  306. * | | |This bit field indicates the valid data count of receive FIFO buffer.
  307. * |[31:28] |TXCNT |Transmit FIFO Data Count (Read Only)
  308. * | | |This bit field indicates the valid data count of transmit FIFO buffer.
  309. * @var SPI_T::TX
  310. * Offset: 0x20 SPI Data Transmit Register
  311. * ---------------------------------------------------------------------------------------------------
  312. * |Bits |Field |Descriptions
  313. * | :----: | :----: | :---- |
  314. * |[31:0] |TX |Data Transmit Register
  315. * | | |The data transmit registers pass through the transmitted data into the 4-level transmit FIFO buffers
  316. * | | |The number of valid bits depends on the setting of DWIDTH (SPIx_CTL[12:8]) in SPI mode or WDWIDTH (SPIx_I2SCTL[5:4]) in I2S mode.
  317. * | | |In SPI mode, if DWIDTH is set to 0x08, the bits TX[7:0] will be transmitted
  318. * | | |If DWIDTH is set to 0x00 , the SPI controller will perform a 32-bit transfer.
  319. * | | |In I2S mode, if WDWIDTH (SPIx_I2SCTL[5:4]) is set to 0x2, the data width of audio channel is 24-bit and corresponding to TX[23:0]
  320. * | | |If WDWIDTH is set as 0x0, 0x1, or 0x3, all bits of this field are valid and referred to the data arrangement in I2S mode FIFO operation section
  321. * | | |Note: In Master mode, SPI controller will start to transfer the SPI bus clock after 1 APB clock and 6 peripheral clock cycles after user writes to this register.
  322. * @var SPI_T::RX
  323. * Offset: 0x30 SPI Data Receive Register
  324. * ---------------------------------------------------------------------------------------------------
  325. * |Bits |Field |Descriptions
  326. * | :----: | :----: | :---- |
  327. * |[31:0] |RX |Data Receive Register
  328. * | | |There are 4-level FIFO buffers in this controller
  329. * | | |The data receive register holds the data received from SPI data input pin
  330. * | | |If the RXEMPTY (SPIx_STATUS[8] or SPIx_I2SSTS[8]) is not set to 1, the receive FIFO buffers can be accessed through software by reading this register
  331. * | | |This is a read only register.
  332. */
  333. __IO uint32_t CTL; /*!< [0x0000] SPI Control Register */
  334. __IO uint32_t CLKDIV; /*!< [0x0004] SPI Clock Divider Register */
  335. __IO uint32_t SSCTL; /*!< [0x0008] SPI Slave Select Control Register */
  336. __IO uint32_t PDMACTL; /*!< [0x000c] SPI PDMA Control Register */
  337. __IO uint32_t FIFOCTL; /*!< [0x0010] SPI FIFO Control Register */
  338. __IO uint32_t STATUS; /*!< [0x0014] SPI Status Register */
  339. /// @cond HIDDEN_SYMBOLS
  340. __I uint32_t RESERVE0[2];
  341. /// @endcond //HIDDEN_SYMBOLS
  342. __O uint32_t TX; /*!< [0x0020] SPI Data Transmit Register */
  343. /// @cond HIDDEN_SYMBOLS
  344. __I uint32_t RESERVE1[3];
  345. /// @endcond //HIDDEN_SYMBOLS
  346. __I uint32_t RX; /*!< [0x0030] SPI Data Receive Register */
  347. /// @cond HIDDEN_SYMBOLS
  348. __I uint32_t RESERVE2[11];
  349. /// @endcond //HIDDEN_SYMBOLS
  350. } SPI_T;
  351. /**
  352. @addtogroup SPI_CONST SPI Bit Field Definition
  353. Constant Definitions for SPI Controller
  354. @{ */
  355. #define SPI_CTL_SPIEN_Pos (0) /*!< SPI_T::CTL: SPIEN Position */
  356. #define SPI_CTL_SPIEN_Msk (0x1ul << SPI_CTL_SPIEN_Pos) /*!< SPI_T::CTL: SPIEN Mask */
  357. #define SPI_CTL_RXNEG_Pos (1) /*!< SPI_T::CTL: RXNEG Position */
  358. #define SPI_CTL_RXNEG_Msk (0x1ul << SPI_CTL_RXNEG_Pos) /*!< SPI_T::CTL: RXNEG Mask */
  359. #define SPI_CTL_TXNEG_Pos (2) /*!< SPI_T::CTL: TXNEG Position */
  360. #define SPI_CTL_TXNEG_Msk (0x1ul << SPI_CTL_TXNEG_Pos) /*!< SPI_T::CTL: TXNEG Mask */
  361. #define SPI_CTL_CLKPOL_Pos (3) /*!< SPI_T::CTL: CLKPOL Position */
  362. #define SPI_CTL_CLKPOL_Msk (0x1ul << SPI_CTL_CLKPOL_Pos) /*!< SPI_T::CTL: CLKPOL Mask */
  363. #define SPI_CTL_SUSPITV_Pos (4) /*!< SPI_T::CTL: SUSPITV Position */
  364. #define SPI_CTL_SUSPITV_Msk (0xful << SPI_CTL_SUSPITV_Pos) /*!< SPI_T::CTL: SUSPITV Mask */
  365. #define SPI_CTL_DWIDTH_Pos (8) /*!< SPI_T::CTL: DWIDTH Position */
  366. #define SPI_CTL_DWIDTH_Msk (0x1ful << SPI_CTL_DWIDTH_Pos) /*!< SPI_T::CTL: DWIDTH Mask */
  367. #define SPI_CTL_LSB_Pos (13) /*!< SPI_T::CTL: LSB Position */
  368. #define SPI_CTL_LSB_Msk (0x1ul << SPI_CTL_LSB_Pos) /*!< SPI_T::CTL: LSB Mask */
  369. #define SPI_CTL_HALFDPX_Pos (14) /*!< SPI_T::CTL: HALFDPX Position */
  370. #define SPI_CTL_HALFDPX_Msk (0x1ul << SPI_CTL_HALFDPX_Pos) /*!< SPI_T::CTL: HALFDPX Mask */
  371. #define SPI_CTL_RXONLY_Pos (15) /*!< SPI_T::CTL: RXONLY Position */
  372. #define SPI_CTL_RXONLY_Msk (0x1ul << SPI_CTL_RXONLY_Pos) /*!< SPI_T::CTL: RXONLY Mask */
  373. #define SPI_CTL_UNITIEN_Pos (17) /*!< SPI_T::CTL: UNITIEN Position */
  374. #define SPI_CTL_UNITIEN_Msk (0x1ul << SPI_CTL_UNITIEN_Pos) /*!< SPI_T::CTL: UNITIEN Mask */
  375. #define SPI_CTL_SLAVE_Pos (18) /*!< SPI_T::CTL: SLAVE Position */
  376. #define SPI_CTL_SLAVE_Msk (0x1ul << SPI_CTL_SLAVE_Pos) /*!< SPI_T::CTL: SLAVE Mask */
  377. #define SPI_CTL_REORDER_Pos (19) /*!< SPI_T::CTL: REORDER Position */
  378. #define SPI_CTL_REORDER_Msk (0x1ul << SPI_CTL_REORDER_Pos) /*!< SPI_T::CTL: REORDER Mask */
  379. #define SPI_CTL_DATDIR_Pos (20) /*!< SPI_T::CTL: DATDIR Position */
  380. #define SPI_CTL_DATDIR_Msk (0x1ul << SPI_CTL_DATDIR_Pos) /*!< SPI_T::CTL: DATDIR Mask */
  381. #define SPI_CLKDIV_DIVIDER_Pos (0) /*!< SPI_T::CLKDIV: DIVIDER Position */
  382. #define SPI_CLKDIV_DIVIDER_Msk (0x1fful << SPI_CLKDIV_DIVIDER_Pos) /*!< SPI_T::CLKDIV: DIVIDER Mask */
  383. #define SPI_SSCTL_SS_Pos (0) /*!< SPI_T::SSCTL: SS Position */
  384. #define SPI_SSCTL_SS_Msk (0x1ul << SPI_SSCTL_SS_Pos) /*!< SPI_T::SSCTL: SS Mask */
  385. #define SPI_SSCTL_SSACTPOL_Pos (2) /*!< SPI_T::SSCTL: SSACTPOL Position */
  386. #define SPI_SSCTL_SSACTPOL_Msk (0x1ul << SPI_SSCTL_SSACTPOL_Pos) /*!< SPI_T::SSCTL: SSACTPOL Mask */
  387. #define SPI_SSCTL_AUTOSS_Pos (3) /*!< SPI_T::SSCTL: AUTOSS Position */
  388. #define SPI_SSCTL_AUTOSS_Msk (0x1ul << SPI_SSCTL_AUTOSS_Pos) /*!< SPI_T::SSCTL: AUTOSS Mask */
  389. #define SPI_SSCTL_SLVBEIEN_Pos (8) /*!< SPI_T::SSCTL: SLVBEIEN Position */
  390. #define SPI_SSCTL_SLVBEIEN_Msk (0x1ul << SPI_SSCTL_SLVBEIEN_Pos) /*!< SPI_T::SSCTL: SLVBEIEN Mask */
  391. #define SPI_SSCTL_SLVURIEN_Pos (9) /*!< SPI_T::SSCTL: SLVURIEN Position */
  392. #define SPI_SSCTL_SLVURIEN_Msk (0x1ul << SPI_SSCTL_SLVURIEN_Pos) /*!< SPI_T::SSCTL: SLVURIEN Mask */
  393. #define SPI_SSCTL_SSACTIEN_Pos (12) /*!< SPI_T::SSCTL: SSACTIEN Position */
  394. #define SPI_SSCTL_SSACTIEN_Msk (0x1ul << SPI_SSCTL_SSACTIEN_Pos) /*!< SPI_T::SSCTL: SSACTIEN Mask */
  395. #define SPI_SSCTL_SSINAIEN_Pos (13) /*!< SPI_T::SSCTL: SSINAIEN Position */
  396. #define SPI_SSCTL_SSINAIEN_Msk (0x1ul << SPI_SSCTL_SSINAIEN_Pos) /*!< SPI_T::SSCTL: SSINAIEN Mask */
  397. #define SPI_SSCTL_SLVTOCNT_Pos (16) /*!< SPI_T::SSCTL: SLVTOCNT Position */
  398. #define SPI_SSCTL_SLVTOCNT_Msk (0xfffful << SPI_SSCTL_SLVTOCNT_Pos) /*!< SPI_T::SSCTL: SLVTOCNT Mask */
  399. #define SPI_PDMACTL_TXPDMAEN_Pos (0) /*!< SPI_T::PDMACTL: TXPDMAEN Position */
  400. #define SPI_PDMACTL_TXPDMAEN_Msk (0x1ul << SPI_PDMACTL_TXPDMAEN_Pos) /*!< SPI_T::PDMACTL: TXPDMAEN Mask */
  401. #define SPI_PDMACTL_RXPDMAEN_Pos (1) /*!< SPI_T::PDMACTL: RXPDMAEN Position */
  402. #define SPI_PDMACTL_RXPDMAEN_Msk (0x1ul << SPI_PDMACTL_RXPDMAEN_Pos) /*!< SPI_T::PDMACTL: RXPDMAEN Mask */
  403. #define SPI_PDMACTL_PDMARST_Pos (2) /*!< SPI_T::PDMACTL: PDMARST Position */
  404. #define SPI_PDMACTL_PDMARST_Msk (0x1ul << SPI_PDMACTL_PDMARST_Pos) /*!< SPI_T::PDMACTL: PDMARST Mask */
  405. #define SPI_FIFOCTL_RXRST_Pos (0) /*!< SPI_T::FIFOCTL: RXRST Position */
  406. #define SPI_FIFOCTL_RXRST_Msk (0x1ul << SPI_FIFOCTL_RXRST_Pos) /*!< SPI_T::FIFOCTL: RXRST Mask */
  407. #define SPI_FIFOCTL_TXRST_Pos (1) /*!< SPI_T::FIFOCTL: TXRST Position */
  408. #define SPI_FIFOCTL_TXRST_Msk (0x1ul << SPI_FIFOCTL_TXRST_Pos) /*!< SPI_T::FIFOCTL: TXRST Mask */
  409. #define SPI_FIFOCTL_RXTHIEN_Pos (2) /*!< SPI_T::FIFOCTL: RXTHIEN Position */
  410. #define SPI_FIFOCTL_RXTHIEN_Msk (0x1ul << SPI_FIFOCTL_RXTHIEN_Pos) /*!< SPI_T::FIFOCTL: RXTHIEN Mask */
  411. #define SPI_FIFOCTL_TXTHIEN_Pos (3) /*!< SPI_T::FIFOCTL: TXTHIEN Position */
  412. #define SPI_FIFOCTL_TXTHIEN_Msk (0x1ul << SPI_FIFOCTL_TXTHIEN_Pos) /*!< SPI_T::FIFOCTL: TXTHIEN Mask */
  413. #define SPI_FIFOCTL_RXTOIEN_Pos (4) /*!< SPI_T::FIFOCTL: RXTOIEN Position */
  414. #define SPI_FIFOCTL_RXTOIEN_Msk (0x1ul << SPI_FIFOCTL_RXTOIEN_Pos) /*!< SPI_T::FIFOCTL: RXTOIEN Mask */
  415. #define SPI_FIFOCTL_RXOVIEN_Pos (5) /*!< SPI_T::FIFOCTL: RXOVIEN Position */
  416. #define SPI_FIFOCTL_RXOVIEN_Msk (0x1ul << SPI_FIFOCTL_RXOVIEN_Pos) /*!< SPI_T::FIFOCTL: RXOVIEN Mask */
  417. #define SPI_FIFOCTL_TXUFPOL_Pos (6) /*!< SPI_T::FIFOCTL: TXUFPOL Position */
  418. #define SPI_FIFOCTL_TXUFPOL_Msk (0x1ul << SPI_FIFOCTL_TXUFPOL_Pos) /*!< SPI_T::FIFOCTL: TXUFPOL Mask */
  419. #define SPI_FIFOCTL_TXUFIEN_Pos (7) /*!< SPI_T::FIFOCTL: TXUFIEN Position */
  420. #define SPI_FIFOCTL_TXUFIEN_Msk (0x1ul << SPI_FIFOCTL_TXUFIEN_Pos) /*!< SPI_T::FIFOCTL: TXUFIEN Mask */
  421. #define SPI_FIFOCTL_RXFBCLR_Pos (8) /*!< SPI_T::FIFOCTL: RXFBCLR Position */
  422. #define SPI_FIFOCTL_RXFBCLR_Msk (0x1ul << SPI_FIFOCTL_RXFBCLR_Pos) /*!< SPI_T::FIFOCTL: RXFBCLR Mask */
  423. #define SPI_FIFOCTL_TXFBCLR_Pos (9) /*!< SPI_T::FIFOCTL: TXFBCLR Position */
  424. #define SPI_FIFOCTL_TXFBCLR_Msk (0x1ul << SPI_FIFOCTL_TXFBCLR_Pos) /*!< SPI_T::FIFOCTL: TXFBCLR Mask */
  425. #define SPI_FIFOCTL_RXTH_Pos (24) /*!< SPI_T::FIFOCTL: RXTH Position */
  426. #define SPI_FIFOCTL_RXTH_Msk (0x7ul << SPI_FIFOCTL_RXTH_Pos) /*!< SPI_T::FIFOCTL: RXTH Mask */
  427. #define SPI_FIFOCTL_TXTH_Pos (28) /*!< SPI_T::FIFOCTL: TXTH Position */
  428. #define SPI_FIFOCTL_TXTH_Msk (0x7ul << SPI_FIFOCTL_TXTH_Pos) /*!< SPI_T::FIFOCTL: TXTH Mask */
  429. #define SPI_STATUS_BUSY_Pos (0) /*!< SPI_T::STATUS: BUSY Position */
  430. #define SPI_STATUS_BUSY_Msk (0x1ul << SPI_STATUS_BUSY_Pos) /*!< SPI_T::STATUS: BUSY Mask */
  431. #define SPI_STATUS_UNITIF_Pos (1) /*!< SPI_T::STATUS: UNITIF Position */
  432. #define SPI_STATUS_UNITIF_Msk (0x1ul << SPI_STATUS_UNITIF_Pos) /*!< SPI_T::STATUS: UNITIF Mask */
  433. #define SPI_STATUS_SSACTIF_Pos (2) /*!< SPI_T::STATUS: SSACTIF Position */
  434. #define SPI_STATUS_SSACTIF_Msk (0x1ul << SPI_STATUS_SSACTIF_Pos) /*!< SPI_T::STATUS: SSACTIF Mask */
  435. #define SPI_STATUS_SSINAIF_Pos (3) /*!< SPI_T::STATUS: SSINAIF Position */
  436. #define SPI_STATUS_SSINAIF_Msk (0x1ul << SPI_STATUS_SSINAIF_Pos) /*!< SPI_T::STATUS: SSINAIF Mask */
  437. #define SPI_STATUS_SSLINE_Pos (4) /*!< SPI_T::STATUS: SSLINE Position */
  438. #define SPI_STATUS_SSLINE_Msk (0x1ul << SPI_STATUS_SSLINE_Pos) /*!< SPI_T::STATUS: SSLINE Mask */
  439. #define SPI_STATUS_SLVBEIF_Pos (6) /*!< SPI_T::STATUS: SLVBEIF Position */
  440. #define SPI_STATUS_SLVBEIF_Msk (0x1ul << SPI_STATUS_SLVBEIF_Pos) /*!< SPI_T::STATUS: SLVBEIF Mask */
  441. #define SPI_STATUS_SLVURIF_Pos (7) /*!< SPI_T::STATUS: SLVURIF Position */
  442. #define SPI_STATUS_SLVURIF_Msk (0x1ul << SPI_STATUS_SLVURIF_Pos) /*!< SPI_T::STATUS: SLVURIF Mask */
  443. #define SPI_STATUS_RXEMPTY_Pos (8) /*!< SPI_T::STATUS: RXEMPTY Position */
  444. #define SPI_STATUS_RXEMPTY_Msk (0x1ul << SPI_STATUS_RXEMPTY_Pos) /*!< SPI_T::STATUS: RXEMPTY Mask */
  445. #define SPI_STATUS_RXFULL_Pos (9) /*!< SPI_T::STATUS: RXFULL Position */
  446. #define SPI_STATUS_RXFULL_Msk (0x1ul << SPI_STATUS_RXFULL_Pos) /*!< SPI_T::STATUS: RXFULL Mask */
  447. #define SPI_STATUS_RXTHIF_Pos (10) /*!< SPI_T::STATUS: RXTHIF Position */
  448. #define SPI_STATUS_RXTHIF_Msk (0x1ul << SPI_STATUS_RXTHIF_Pos) /*!< SPI_T::STATUS: RXTHIF Mask */
  449. #define SPI_STATUS_RXOVIF_Pos (11) /*!< SPI_T::STATUS: RXOVIF Position */
  450. #define SPI_STATUS_RXOVIF_Msk (0x1ul << SPI_STATUS_RXOVIF_Pos) /*!< SPI_T::STATUS: RXOVIF Mask */
  451. #define SPI_STATUS_RXTOIF_Pos (12) /*!< SPI_T::STATUS: RXTOIF Position */
  452. #define SPI_STATUS_RXTOIF_Msk (0x1ul << SPI_STATUS_RXTOIF_Pos) /*!< SPI_T::STATUS: RXTOIF Mask */
  453. #define SPI_STATUS_SPIENSTS_Pos (15) /*!< SPI_T::STATUS: SPIENSTS Position */
  454. #define SPI_STATUS_SPIENSTS_Msk (0x1ul << SPI_STATUS_SPIENSTS_Pos) /*!< SPI_T::STATUS: SPIENSTS Mask */
  455. #define SPI_STATUS_TXEMPTY_Pos (16) /*!< SPI_T::STATUS: TXEMPTY Position */
  456. #define SPI_STATUS_TXEMPTY_Msk (0x1ul << SPI_STATUS_TXEMPTY_Pos) /*!< SPI_T::STATUS: TXEMPTY Mask */
  457. #define SPI_STATUS_TXFULL_Pos (17) /*!< SPI_T::STATUS: TXFULL Position */
  458. #define SPI_STATUS_TXFULL_Msk (0x1ul << SPI_STATUS_TXFULL_Pos) /*!< SPI_T::STATUS: TXFULL Mask */
  459. #define SPI_STATUS_TXTHIF_Pos (18) /*!< SPI_T::STATUS: TXTHIF Position */
  460. #define SPI_STATUS_TXTHIF_Msk (0x1ul << SPI_STATUS_TXTHIF_Pos) /*!< SPI_T::STATUS: TXTHIF Mask */
  461. #define SPI_STATUS_TXUFIF_Pos (19) /*!< SPI_T::STATUS: TXUFIF Position */
  462. #define SPI_STATUS_TXUFIF_Msk (0x1ul << SPI_STATUS_TXUFIF_Pos) /*!< SPI_T::STATUS: TXUFIF Mask */
  463. #define SPI_STATUS_TXRXRST_Pos (23) /*!< SPI_T::STATUS: TXRXRST Position */
  464. #define SPI_STATUS_TXRXRST_Msk (0x1ul << SPI_STATUS_TXRXRST_Pos) /*!< SPI_T::STATUS: TXRXRST Mask */
  465. #define SPI_STATUS_RXCNT_Pos (24) /*!< SPI_T::STATUS: RXCNT Position */
  466. #define SPI_STATUS_RXCNT_Msk (0xful << SPI_STATUS_RXCNT_Pos) /*!< SPI_T::STATUS: RXCNT Mask */
  467. #define SPI_STATUS_TXCNT_Pos (28) /*!< SPI_T::STATUS: TXCNT Position */
  468. #define SPI_STATUS_TXCNT_Msk (0xful << SPI_STATUS_TXCNT_Pos) /*!< SPI_T::STATUS: TXCNT Mask */
  469. #define SPI_TX_TX_Pos (0) /*!< SPI_T::TX: TX Position */
  470. #define SPI_TX_TX_Msk (0xfffffffful << SPI_TX_TX_Pos) /*!< SPI_T::TX: TX Mask */
  471. #define SPI_RX_RX_Pos (0) /*!< SPI_T::RX: RX Position */
  472. #define SPI_RX_RX_Msk (0xfffffffful << SPI_RX_RX_Pos) /*!< SPI_T::RX: RX Mask */
  473. /**@}*/ /* SPI_CONST */
  474. /**@}*/ /* end of SPI register group */
  475. /**@}*/ /* end of REGISTER group */
  476. #define SPI0 ((SPI_T *) SPI0_BA)
  477. #define SPI1 ((SPI_T *) SPI1_BA)
  478. /** @addtogroup Standard_Driver Standard Driver
  479. @{
  480. */
  481. /** @addtogroup SPI_Driver SPI Driver
  482. @{
  483. */
  484. /** @addtogroup SPI_EXPORTED_CONSTANTS SPI Exported Constants
  485. @{
  486. */
  487. #define SPI_MODE_0 (SPI_CTL_TXNEG_Msk) /*!< CLKPOL=0; RXNEG=0; TXNEG=1 \hideinitializer */
  488. #define SPI_MODE_1 (SPI_CTL_RXNEG_Msk) /*!< CLKPOL=0; RXNEG=1; TXNEG=0 \hideinitializer */
  489. #define SPI_MODE_2 (SPI_CTL_CLKPOL_Msk | SPI_CTL_RXNEG_Msk) /*!< CLKPOL=1; RXNEG=1; TXNEG=0 \hideinitializer */
  490. #define SPI_MODE_3 (SPI_CTL_CLKPOL_Msk | SPI_CTL_TXNEG_Msk) /*!< CLKPOL=1; RXNEG=0; TXNEG=1 \hideinitializer */
  491. #define SPI_SLAVE (SPI_CTL_SLAVE_Msk) /*!< Set as slave \hideinitializer */
  492. #define SPI_MASTER (0x0U) /*!< Set as master \hideinitializer */
  493. #define SPI_SS (SPI_SSCTL_SS_Msk) /*!< Set SS \hideinitializer */
  494. #define SPI_SS_ACTIVE_HIGH (SPI_SSCTL_SSACTPOL_Msk) /*!< SS active high \hideinitializer */
  495. #define SPI_SS_ACTIVE_LOW (0x0U) /*!< SS active low \hideinitializer */
  496. /* SPI Interrupt Mask */
  497. #define SPI_UNIT_INT_MASK (0x001U) /*!< Unit transfer interrupt mask \hideinitializer */
  498. #define SPI_SSACT_INT_MASK (0x002U) /*!< Slave selection signal active interrupt mask \hideinitializer */
  499. #define SPI_SSINACT_INT_MASK (0x004U) /*!< Slave selection signal inactive interrupt mask \hideinitializer */
  500. #define SPI_SLVUR_INT_MASK (0x008U) /*!< Slave under run interrupt mask \hideinitializer */
  501. #define SPI_SLVBE_INT_MASK (0x010U) /*!< Slave bit count error interrupt mask \hideinitializer */
  502. #define SPI_TXUF_INT_MASK (0x040U) /*!< Slave TX underflow interrupt mask \hideinitializer */
  503. #define SPI_FIFO_TXTH_INT_MASK (0x080U) /*!< FIFO TX threshold interrupt mask \hideinitializer */
  504. #define SPI_FIFO_RXTH_INT_MASK (0x100U) /*!< FIFO RX threshold interrupt mask \hideinitializer */
  505. #define SPI_FIFO_RXOV_INT_MASK (0x200U) /*!< FIFO RX overrun interrupt mask \hideinitializer */
  506. #define SPI_FIFO_RXTO_INT_MASK (0x400U) /*!< FIFO RX time-out interrupt mask \hideinitializer */
  507. /* SPI Status Mask */
  508. #define SPI_BUSY_MASK (0x01U) /*!< Busy status mask \hideinitializer */
  509. #define SPI_RX_EMPTY_MASK (0x02U) /*!< RX empty status mask \hideinitializer */
  510. #define SPI_RX_FULL_MASK (0x04U) /*!< RX full status mask \hideinitializer */
  511. #define SPI_TX_EMPTY_MASK (0x08U) /*!< TX empty status mask \hideinitializer */
  512. #define SPI_TX_FULL_MASK (0x10U) /*!< TX full status mask \hideinitializer */
  513. #define SPI_TXRX_RESET_MASK (0x20U) /*!< TX or RX reset status mask \hideinitializer */
  514. #define SPI_SPIEN_STS_MASK (0x40U) /*!< SPIEN status mask \hideinitializer */
  515. #define SPI_SSLINE_STS_MASK (0x80U) /*!< SPIx_SS line status mask \hideinitializer */
  516. /*@}*/ /* end of group SPI_EXPORTED_CONSTANTS */
  517. /** @addtogroup SPI_EXPORTED_FUNCTIONS SPI Exported Functions
  518. @{
  519. */
  520. /**
  521. * @brief Clear the unit transfer interrupt flag.
  522. * @param[in] spi The pointer of the specified SPI module.
  523. * @return None.
  524. * @details Write 1 to UNITIF bit of SPI_STATUS register to clear the unit transfer interrupt flag.
  525. * \hideinitializer
  526. */
  527. #define SPI_CLR_UNIT_TRANS_INT_FLAG(spi) ((spi)->STATUS = SPI_STATUS_UNITIF_Msk)
  528. /**
  529. * @brief Trigger RX PDMA function.
  530. * @param[in] spi The pointer of the specified SPI module.
  531. * @return None.
  532. * @details Set RXPDMAEN bit of SPI_PDMACTL register to enable RX PDMA transfer function.
  533. * \hideinitializer
  534. */
  535. #define SPI_TRIGGER_RX_PDMA(spi) ((spi)->PDMACTL |= SPI_PDMACTL_RXPDMAEN_Msk)
  536. /**
  537. * @brief Trigger TX PDMA function.
  538. * @param[in] spi The pointer of the specified SPI module.
  539. * @return None.
  540. * @details Set TXPDMAEN bit of SPI_PDMACTL register to enable TX PDMA transfer function.
  541. * \hideinitializer
  542. */
  543. #define SPI_TRIGGER_TX_PDMA(spi) ((spi)->PDMACTL |= SPI_PDMACTL_TXPDMAEN_Msk)
  544. /**
  545. * @brief Trigger TX and RX PDMA function.
  546. * @param[in] spi The pointer of the specified SPI module.
  547. * @return None.
  548. * @details Set TXPDMAEN bit and RXPDMAEN bit of SPI_PDMACTL register to enable TX and RX PDMA transfer function.
  549. * \hideinitializer
  550. */
  551. #define SPI_TRIGGER_TX_RX_PDMA(spi) ((spi)->PDMACTL |= (SPI_PDMACTL_TXPDMAEN_Msk | SPI_PDMACTL_RXPDMAEN_Msk))
  552. /**
  553. * @brief Disable RX PDMA transfer.
  554. * @param[in] spi The pointer of the specified SPI module.
  555. * @return None.
  556. * @details Clear RXPDMAEN bit of SPI_PDMACTL register to disable RX PDMA transfer function.
  557. * \hideinitializer
  558. */
  559. #define SPI_DISABLE_RX_PDMA(spi) ( (spi)->PDMACTL &= ~SPI_PDMACTL_RXPDMAEN_Msk )
  560. /**
  561. * @brief Disable TX PDMA transfer.
  562. * @param[in] spi The pointer of the specified SPI module.
  563. * @return None.
  564. * @details Clear TXPDMAEN bit of SPI_PDMACTL register to disable TX PDMA transfer function.
  565. * \hideinitializer
  566. */
  567. #define SPI_DISABLE_TX_PDMA(spi) ( (spi)->PDMACTL &= ~SPI_PDMACTL_TXPDMAEN_Msk )
  568. /**
  569. * @brief Disable TX and RX PDMA transfer.
  570. * @param[in] spi The pointer of the specified SPI module.
  571. * @return None.
  572. * @details Clear TXPDMAEN bit and RXPDMAEN bit of SPI_PDMACTL register to disable TX and RX PDMA transfer function.
  573. * \hideinitializer
  574. */
  575. #define SPI_DISABLE_TX_RX_PDMA(spi) ( (spi)->PDMACTL &= ~(SPI_PDMACTL_TXPDMAEN_Msk | SPI_PDMACTL_RXPDMAEN_Msk) )
  576. /**
  577. * @brief Get the count of available data in RX FIFO.
  578. * @param[in] spi The pointer of the specified SPI module.
  579. * @return The count of available data in RX FIFO.
  580. * @details Read RXCNT (SPI_STATUS[27:24]) to get the count of available data in RX FIFO.
  581. * \hideinitializer
  582. */
  583. #define SPI_GET_RX_FIFO_COUNT(spi) (((spi)->STATUS & SPI_STATUS_RXCNT_Msk) >> SPI_STATUS_RXCNT_Pos)
  584. /**
  585. * @brief Get the RX FIFO empty flag.
  586. * @param[in] spi The pointer of the specified SPI module.
  587. * @retval 0 RX FIFO is not empty.
  588. * @retval 1 RX FIFO is empty.
  589. * @details Read RXEMPTY bit of SPI_STATUS register to get the RX FIFO empty flag.
  590. * \hideinitializer
  591. */
  592. #define SPI_GET_RX_FIFO_EMPTY_FLAG(spi) (((spi)->STATUS & SPI_STATUS_RXEMPTY_Msk)>>SPI_STATUS_RXEMPTY_Pos)
  593. /**
  594. * @brief Get the TX FIFO empty flag.
  595. * @param[in] spi The pointer of the specified SPI module.
  596. * @retval 0 TX FIFO is not empty.
  597. * @retval 1 TX FIFO is empty.
  598. * @details Read TXEMPTY bit of SPI_STATUS register to get the TX FIFO empty flag.
  599. * \hideinitializer
  600. */
  601. #define SPI_GET_TX_FIFO_EMPTY_FLAG(spi) (((spi)->STATUS & SPI_STATUS_TXEMPTY_Msk)>>SPI_STATUS_TXEMPTY_Pos)
  602. /**
  603. * @brief Get the TX FIFO full flag.
  604. * @param[in] spi The pointer of the specified SPI module.
  605. * @retval 0 TX FIFO is not full.
  606. * @retval 1 TX FIFO is full.
  607. * @details Read TXFULL bit of SPI_STATUS register to get the TX FIFO full flag.
  608. * \hideinitializer
  609. */
  610. #define SPI_GET_TX_FIFO_FULL_FLAG(spi) (((spi)->STATUS & SPI_STATUS_TXFULL_Msk)>>SPI_STATUS_TXFULL_Pos)
  611. /**
  612. * @brief Get the datum read from RX register.
  613. * @param[in] spi The pointer of the specified SPI module.
  614. * @return Data in RX register.
  615. * @details Read SPI_RX register to get the received datum.
  616. * \hideinitializer
  617. */
  618. #define SPI_READ_RX(spi) ((spi)->RX)
  619. /**
  620. * @brief Write datum to TX register.
  621. * @param[in] spi The pointer of the specified SPI module.
  622. * @param[in] u32TxData The datum which user attempt to transfer through SPI bus.
  623. * @return None.
  624. * @details Write u32TxData to SPI_TX register.
  625. * \hideinitializer
  626. */
  627. #define SPI_WRITE_TX(spi, u32TxData) ((spi)->TX = (u32TxData))
  628. /**
  629. * @brief Set SPIx_SS pin to high state.
  630. * @param[in] spi The pointer of the specified SPI module.
  631. * @return None.
  632. * @details Disable automatic slave selection function and set SPIx_SS pin to high state.
  633. * \hideinitializer
  634. */
  635. #define SPI_SET_SS_HIGH(spi) ((spi)->SSCTL = ((spi)->SSCTL & (~SPI_SSCTL_AUTOSS_Msk)) | (SPI_SSCTL_SSACTPOL_Msk | SPI_SSCTL_SS_Msk))
  636. /**
  637. * @brief Set SPIx_SS pin to low state.
  638. * @param[in] spi The pointer of the specified SPI module.
  639. * @return None.
  640. * @details Disable automatic slave selection function and set SPIx_SS pin to low state.
  641. * \hideinitializer
  642. */
  643. #define SPI_SET_SS_LOW(spi) ((spi)->SSCTL = ((spi)->SSCTL & (~(SPI_SSCTL_AUTOSS_Msk | SPI_SSCTL_SSACTPOL_Msk))) | SPI_SSCTL_SS_Msk)
  644. /**
  645. * @brief Enable Byte Reorder function.
  646. * @param[in] spi The pointer of the specified SPI module.
  647. * @return None.
  648. * @details Enable Byte Reorder function. The suspend interval depends on the setting of SUSPITV (SPI_CTL[7:4]).
  649. * \hideinitializer
  650. */
  651. #define SPI_ENABLE_BYTE_REORDER(spi) ((spi)->CTL |= SPI_CTL_REORDER_Msk)
  652. /**
  653. * @brief Disable Byte Reorder function.
  654. * @param[in] spi The pointer of the specified SPI module.
  655. * @return None.
  656. * @details Clear REORDER bit field of SPI_CTL register to disable Byte Reorder function.
  657. * \hideinitializer
  658. */
  659. #define SPI_DISABLE_BYTE_REORDER(spi) ((spi)->CTL &= ~SPI_CTL_REORDER_Msk)
  660. /**
  661. * @brief Set the length of suspend interval.
  662. * @param[in] spi The pointer of the specified SPI module.
  663. * @param[in] u32SuspCycle Decides the length of suspend interval. It could be 0 ~ 15.
  664. * @return None.
  665. * @details Set the length of suspend interval according to u32SuspCycle.
  666. * The length of suspend interval is ((u32SuspCycle + 0.5) * the length of one SPI bus clock cycle).
  667. * \hideinitializer
  668. */
  669. #define SPI_SET_SUSPEND_CYCLE(spi, u32SuspCycle) ((spi)->CTL = ((spi)->CTL & ~SPI_CTL_SUSPITV_Msk) | ((u32SuspCycle) << SPI_CTL_SUSPITV_Pos))
  670. /**
  671. * @brief Set the SPI transfer sequence with LSB first.
  672. * @param[in] spi The pointer of the specified SPI module.
  673. * @return None.
  674. * @details Set LSB bit of SPI_CTL register to set the SPI transfer sequence with LSB first.
  675. * \hideinitializer
  676. */
  677. #define SPI_SET_LSB_FIRST(spi) ((spi)->CTL |= SPI_CTL_LSB_Msk)
  678. /**
  679. * @brief Set the SPI transfer sequence with MSB first.
  680. * @param[in] spi The pointer of the specified SPI module.
  681. * @return None.
  682. * @details Clear LSB bit of SPI_CTL register to set the SPI transfer sequence with MSB first.
  683. * \hideinitializer
  684. */
  685. #define SPI_SET_MSB_FIRST(spi) ((spi)->CTL &= ~SPI_CTL_LSB_Msk)
  686. /**
  687. * @brief Set the data width of a SPI transaction.
  688. * @param[in] spi The pointer of the specified SPI module.
  689. * @param[in] u32Width The bit width of one transaction.
  690. * @return None.
  691. * @details The data width can be 8 ~ 32 bits.
  692. * \hideinitializer
  693. */
  694. #define SPI_SET_DATA_WIDTH(spi, u32Width) ((spi)->CTL = ((spi)->CTL & ~SPI_CTL_DWIDTH_Msk) | (((u32Width)&0x1F) << SPI_CTL_DWIDTH_Pos))
  695. /**
  696. * @brief Get the SPI busy state.
  697. * @param[in] spi The pointer of the specified SPI module.
  698. * @retval 0 SPI controller is not busy.
  699. * @retval 1 SPI controller is busy.
  700. * @details This macro will return the busy state of SPI controller.
  701. * \hideinitializer
  702. */
  703. #define SPI_IS_BUSY(spi) ( ((spi)->STATUS & SPI_STATUS_BUSY_Msk)>>SPI_STATUS_BUSY_Pos )
  704. /**
  705. * @brief Enable SPI controller.
  706. * @param[in] spi The pointer of the specified SPI module.
  707. * @return None.
  708. * @details Set SPIEN (SPI_CTL[0]) to enable SPI controller.
  709. * \hideinitializer
  710. */
  711. #define SPI_ENABLE(spi) ((spi)->CTL |= SPI_CTL_SPIEN_Msk)
  712. /**
  713. * @brief Disable SPI controller.
  714. * @param[in] spi The pointer of the specified SPI module.
  715. * @return None.
  716. * @details Clear SPIEN (SPI_CTL[0]) to disable SPI controller.
  717. * \hideinitializer
  718. */
  719. #define SPI_DISABLE(spi) ((spi)->CTL &= ~SPI_CTL_SPIEN_Msk)
  720. /* Function prototype declaration */
  721. uint32_t SPI_Open(SPI_T *spi, uint32_t u32MasterSlave, uint32_t u32SPIMode, uint32_t u32DataWidth, uint32_t u32BusClock);
  722. void SPI_Close(SPI_T *spi);
  723. void SPI_ClearRxFIFO(SPI_T *spi);
  724. void SPI_ClearTxFIFO(SPI_T *spi);
  725. void SPI_DisableAutoSS(SPI_T *spi);
  726. void SPI_EnableAutoSS(SPI_T *spi, uint32_t u32SSPinMask, uint32_t u32ActiveLevel);
  727. void SPI_SetFIFO(SPI_T *spi, uint32_t u32TxThreshold, uint32_t u32RxThreshold);
  728. uint32_t SPI_GetBusClock(SPI_T *spi);
  729. void SPI_EnableInt(SPI_T *spi, uint32_t u32Mask);
  730. void SPI_DisableInt(SPI_T *spi, uint32_t u32Mask);
  731. uint32_t SPI_GetIntFlag(SPI_T *spi, uint32_t u32Mask);
  732. void SPI_ClearIntFlag(SPI_T *spi, uint32_t u32Mask);
  733. uint32_t SPI_GetStatus(SPI_T *spi, uint32_t u32Mask);
  734. /*@}*/ /* end of group SPI_EXPORTED_FUNCTIONS */
  735. /*@}*/ /* end of group SPI_Driver */
  736. /*@}*/ /* end of group Standard_Driver */
  737. #ifdef __cplusplus
  738. }
  739. #endif
  740. #endif
  741. /*** (C) COPYRIGHT 2018 Nuvoton Technology Corp. ***/