SSP_LPC18xx.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* --------------------------------------------------------------------------
  2. * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * $Date: 02. March 2016
  19. * $Revision: V2.2
  20. *
  21. * Project: SSP Driver Definitions for NXP LPC18xx
  22. * -------------------------------------------------------------------------- */
  23. #ifndef __SSP_LPC18XX_H
  24. #define __SSP_LPC18XX_H
  25. #include "LPC18xx.h"
  26. #include "SCU_LPC18xx.h"
  27. #include "GPIO_LPC18xx.h"
  28. #include "GPDMA_LPC18xx.h"
  29. #include "Driver_SPI.h"
  30. /* SSP Register Interface Definitions */
  31. #define CGU_BASE_SSPx_CLK_PD (0x01 << 0) /*!< CGU BASE_SSPx_CLK: PD Mask */
  32. #define CGU_BASE_SSPx_CLK_AUTOBLOCK (0x01 << 11) /*!< CGU BASE_SSPx_CLK: AUTOBLOCK Mask */
  33. #define CGU_BASE_SSPx_CLK_CLK_SEL (0x1F << 24) /*!< CGU BASE_SSPx_CLK: CLK_SEL Mask */
  34. #define CCU1_CLK_M3_SSPx_CFG_RUN (0x01 << 0) /*!< CCU1 CLK_M3_SSPx_CFG: RUN Mask */
  35. #define CCU1_CLK_M3_SSPx_CFG_AUTO (0x01 << 1) /*!< CCU1 CLK_M3_SSPx_CFG: AUTO Mask */
  36. #define CCU1_CLK_M3_SSPx_CFG_WAKEUP (0x01 << 2) /*!< CCU1 CLK_M3_SSPx_CFG: WAKEUP Mask */
  37. #define CCU1_CLK_M3_SSPx_STAT_RUN (0x01 << 0) /*!< CCU1 CLK_M3_SSPx_STAT: RUN Mask */
  38. #define CCU1_CLK_M3_SSPx_STAT_AUTO (0x01 << 1) /*!< CCU1 CLK_M3_SSPx_STAT: AUTO Mask */
  39. #define CCU1_CLK_M3_SSPx_STAT_WAKEUP (0x01 << 2) /*!< CCU1 CLK_M3_SSPx_STAT: WAKEUP Mask */
  40. #define CCU2_BASE_STAT_BASE_SSP1_CLK (0x01 << 5) /*!< CCU2 BASE_STAT: BASE_SSP1_CLK Mask */
  41. #define CCU2_BASE_STAT_BASE_SSP0_CLK (0x01 << 6) /*!< CCU2 BASE_STAT: BASE_SSP0_CLK Mask */
  42. #define CCU2_CLK_APBn_SSPx_CFG_RUN (0x01 << 0) /*!< CCU2 CLK_APBn_SSPx_CFG: RUN Mask */
  43. #define CCU2_CLK_APBn_SSPx_CFG_AUTO (0x01 << 1) /*!< CCU2 CLK_APBn_SSPx_CFG: AUTO Mask */
  44. #define CCU2_CLK_APBn_SSPx_CFG_WAKEUP (0x01 << 2) /*!< CCU2 CLK_APBn_SSPx_CFG: WAKEUP Mask */
  45. #define CCU2_CLK_APBn_SSPx_STAT_RUN (0x01 << 0) /*!< CCU2 CLK_APBn_SSPx_STAT: RUN Mask */
  46. #define CCU2_CLK_APBn_SSPx_STAT_AUTO (0x01 << 1) /*!< CCU2 CLK_APBn_SSPx_STAT: AUTO Mask */
  47. #define CCU2_CLK_APBn_SSPx_STAT_WAKEUP (0x01 << 2) /*!< CCU2 CLK_APBn_SSPx_STAT: WAKEUP Mask */
  48. #define RGU_RESET_CTRL1_SSP0_RST (0x01 << 18) /*!< RGU RESET_CTRL1: SSP0_RST Mask */
  49. #define RGU_RESET_CTRL1_SSP1_RST (0x01 << 19) /*!< RGU RESET_CTRL1: SSP1_RST Mask */
  50. #define RGU_RESET_STATUS3_SSP0_RST (0x03 << 4) /*!< RGU RESET_STATUS3: SSP0_RST Mask */
  51. #define RGU_RESET_STATUS3_SSP1_RST (0x03 << 6) /*!< RGU RESET_STATUS3: SSP1_RST Mask */
  52. #define RGU_RESET_ACTIVE_STATUS1_SSP0_RST (0x01 << 18) /*!< RGU RESET_ACTIVE_STATUS1: SSP0_RST Mask */
  53. #define RGU_RESET_ACTIVE_STATUS1_SSP1_RST (0x01 << 19) /*!< RGU RESET_ACTIVE_STATUS1: SSP1_RST Mask */
  54. #define SSPx_CR0_DSS (0x0F << 0) /*!< SSPx CR0: DSS Mask */
  55. #define SSPx_CR0_FRF (0x03 << 4) /*!< SSPx CR0: FRF Mask */
  56. #define SSPx_CR0_CPOL (0x01 << 6) /*!< SSPx CR0: CPOL Mask */
  57. #define SSPx_CR0_CPHA (0x01 << 7) /*!< SSPx CR0: CPHA Mask */
  58. #define SSPx_CR0_SCR (0xFF << 8) /*!< SSPx CR0: SCR Mask */
  59. #define SSPx_CR1_LBM (0x01 << 0) /*!< SSPx CR1: LBM Mask */
  60. #define SSPx_CR1_SSE (0x01 << 1) /*!< SSPx CR1: SSE Mask */
  61. #define SSPx_CR1_MS (0x01 << 2) /*!< SSPx CR1: MS Mask */
  62. #define SSPx_CR1_SOD (0x01 << 3) /*!< SSPx CR1: SOD Mask */
  63. #define SSPx_DR_DATA (0xFFFF<<0) /*!< SSPx DR: DATA Mask */
  64. #define SSPx_SR_TFE (0x01 << 0) /*!< SSPx SR: TFE Mask */
  65. #define SSPx_SR_TNF (0x01 << 1) /*!< SSPx SR: TNF Mask */
  66. #define SSPx_SR_RNE (0x01 << 2) /*!< SSPx SR: RNE Mask */
  67. #define SSPx_SR_RFF (0x01 << 3) /*!< SSPx SR: RFF Mask */
  68. #define SSPx_SR_BSY (0x01 << 4) /*!< SSPx SR: BSY Mask */
  69. #define SSPx_CPSR_CPSDVSR (0xFF << 0) /*!< SSPx CPSR: CPSDVSR Mask */
  70. #define SSPx_IMSC_RORIM (0x01 << 0) /*!< SSPx IMSC: RORIM Mask */
  71. #define SSPx_IMSC_RTIM (0x01 << 1) /*!< SSPx IMSC: RTIM Mask */
  72. #define SSPx_IMSC_RXIM (0x01 << 2) /*!< SSPx IMSC: RXIM Mask */
  73. #define SSPx_IMSC_TXIM (0x01 << 3) /*!< SSPx IMSC: TXIM Mask */
  74. #define SSPx_RIS_RORRIS (0x01 << 0) /*!< SSPx RIS: RORRIS Mask */
  75. #define SSPx_RIS_RTRIS (0x01 << 1) /*!< SSPx RIS: RTRIS Mask */
  76. #define SSPx_RIS_RXRIS (0x01 << 2) /*!< SSPx RIS: RXRIS Mask */
  77. #define SSPx_RIS_TXRIS (0x01 << 3) /*!< SSPx RIS: TXRIS Mask */
  78. #define SSPx_MIS_RORMIS (0x01 << 0) /*!< SSPx MIS: RORMIS Mask */
  79. #define SSPx_MIS_RTMIS (0x01 << 1) /*!< SSPx MIS: RTMIS Mask */
  80. #define SSPx_MIS_RXMIS (0x01 << 2) /*!< SSPx MIS: RXMIS Mask */
  81. #define SSPx_MIS_TXMIS (0x01 << 3) /*!< SSPx MIS: TXMIS Mask */
  82. #define SSPx_ICR_RORIC (0x01 << 0) /*!< SSPx ICR: RORIC Mask */
  83. #define SSPx_ICR_RTIC (0x01 << 1) /*!< SSPx ICR: RTIC Mask */
  84. #define SSPx_DMACR_RXDMAE (0x01 << 0) /*!< SSPx DMACR: RXDMAE Mask */
  85. #define SSPx_DMACR_TXDMAE (0x01 << 1) /*!< SSPx DMACR: TXDMAE Mask */
  86. #define CLK_SRC_PLL1 0x09 // SSP clock source
  87. /* Current driver status flag definition */
  88. #define SSP_INITIALIZED (1 << 0) // SSP initialized
  89. #define SSP_POWERED (1 << 1) // SSP powered on
  90. #define SSP_CONFIGURED (1 << 2) // SSP configured
  91. #define SSP_DATA_LOST (1 << 3) // SSP data lost occurred
  92. #define SSP_MODE_FAULT (1 << 4) // SSP mode fault occurred
  93. /* SSP Pins Configuration */
  94. typedef const struct _SSP_PINS {
  95. PIN_ID *sck; // SCK pin
  96. PIN_ID *miso; // MISO pin
  97. PIN_ID *mosi; // MOSI pin
  98. PIN_ID *ssel; // SSEL pin
  99. GPIO_ID *gpio_ssel; // SSEL gpio
  100. uint8_t gpio_ssel_af; // SSEL gpio alternate function
  101. } SSP_PINS;
  102. /* Clocks Configuration */
  103. typedef const struct _SSP_CLOCK {
  104. uint32_t reg_cfg_val; // SSP register interface clock configuration register value
  105. volatile uint32_t *reg_cfg; // SSP register interface clock configuration register
  106. uint32_t peri_cfg_val; // SSP peripheral clock configuration register value
  107. volatile uint32_t *peri_cfg; // SSP peripheral clock configuration register
  108. uint32_t peri_stat_val; // SSP peripheral clock status register value
  109. const volatile uint32_t *peri_stat; // SSP peripheral clock status register
  110. } SSP_CLOCKS;
  111. /* Reset Configuration */
  112. typedef const struct _SSP_RESET {
  113. uint32_t reg_cfg_val; // SSP register interface clock configuration register value
  114. volatile uint32_t *reg_cfg; // SSP register interface clock configuration register
  115. uint32_t reg_stat_val; // SSP peripheral clock status register value
  116. const volatile uint32_t *reg_stat; // SSP peripheral clock status register
  117. } SSP_RESET;
  118. /* DMA Configuration */
  119. typedef const struct _SSP_DMA {
  120. uint8_t tx_en; // Transmit channel enabled
  121. uint8_t tx_ch; // Transmit channel number
  122. uint8_t tx_peri; // Transmit peripheral
  123. uint8_t tx_peri_sel; // Transmit peripheral mux selection
  124. void (*tx_callback)(uint32_t event); // Transmit callback
  125. uint8_t rx_en; // Receive channel enabled
  126. uint8_t rx_ch; // Receive channel number
  127. uint8_t rx_peri; // Receive peripheral
  128. uint8_t rx_peri_sel; // Receive peripheral mux selection
  129. void (*rx_callback)(uint32_t event); // Receive callback
  130. } SSP_DMA;
  131. /* SSP status */
  132. typedef struct _SSP_STATUS {
  133. uint8_t busy; // Transmitter/Receiver busy flag
  134. uint8_t data_lost; // Data lost: Receive overflow / Transmit underflow (cleared on start of transfer operation)
  135. uint8_t mode_fault; // Mode fault detected; optional (cleared on start of transfer operation)
  136. } SSP_STATUS;
  137. /* SSP Information (Run-time) */
  138. typedef struct _SSP_INFO {
  139. ARM_SPI_SignalEvent_t cb_event; // Event Callback
  140. SSP_STATUS status; // Status flags
  141. uint8_t state; // Current SSP state
  142. uint32_t mode; // Current SSP mode
  143. } SSP_INFO;
  144. /* SSP Transfer Information (Run-Time) */
  145. typedef struct _SSP_TRANSFER_INFO {
  146. uint32_t num; // Total number of transfers
  147. uint8_t *rx_buf; // Pointer to in data buffer
  148. uint8_t *tx_buf; // Pointer to out data buffer
  149. uint32_t rx_cnt; // Number of data received
  150. uint32_t tx_cnt; // Number of data sent
  151. uint32_t dump_val; // Variable for dumping DMA data
  152. uint16_t def_val; // Default transfer value
  153. } SSP_TRANSFER_INFO;
  154. /* SSP Resources */
  155. typedef struct {
  156. LPC_SSPn_Type *reg; // SSP peripheral register interface
  157. SSP_PINS pin; // SSP pins configuration
  158. SSP_CLOCKS clk; // SSP clocks configuration
  159. SSP_RESET rst; // SSP reset configuration
  160. SSP_DMA dma; // SSP DMA configuration
  161. IRQn_Type irq_num; // SSP IRQ number
  162. SSP_INFO *info; // SSP Run-time information
  163. SSP_TRANSFER_INFO *xfer; // SSP transfer information
  164. } const SSP_RESOURCES;
  165. #endif /* __SSP_LPC18XX_H */