1 /**********************************************************************
\r
2 * $Id$ lpc18xx_ssp.h 2011-06-02
\r
4 * @file lpc18xx_ssp.h
\r
5 * @brief Contains all macro definitions and function prototypes
\r
6 * support for SSP firmware library on LPC18xx
\r
8 * @date 02. June. 2011
\r
9 * @author NXP MCU SW Application Team
\r
11 * Copyright(C) 2011, NXP Semiconductor
\r
12 * All rights reserved.
\r
14 ***********************************************************************
\r
15 * Software that is described herein is for illustrative purposes only
\r
16 * which provides customers with programming information regarding the
\r
17 * products. This software is supplied "AS IS" without any warranties.
\r
18 * NXP Semiconductors assumes no responsibility or liability for the
\r
19 * use of the software, conveys no license or title under any patent,
\r
20 * copyright, or mask work right to the product. NXP Semiconductors
\r
21 * reserves the right to make changes in the software without
\r
22 * notification. NXP Semiconductors also make no representation or
\r
23 * warranty that such application will be suitable for the specified
\r
24 * use without further testing or modification.
\r
25 **********************************************************************/
\r
27 /* Peripheral group ----------------------------------------------------------- */
\r
28 /** @defgroup SSP SSP (Synchronous Serial Port)
\r
29 * @ingroup LPC1800CMSIS_FwLib_Drivers
\r
33 #ifndef LPC18XX_SSP_H_
\r
34 #define LPC18XX_SSP_H_
\r
36 /* Includes ------------------------------------------------------------------- */
\r
37 #include "LPC18xx.h"
\r
38 #include "lpc_types.h"
\r
46 /* Public Macros -------------------------------------------------------------- */
\r
47 /** @defgroup SSP_Private_Macros SSP Private Macros
\r
51 /*********************************************************************//**
\r
52 * SSP configuration parameter defines
\r
53 **********************************************************************/
\r
54 /** Clock phase control bit */
\r
55 #define SSP_CPHA_FIRST ((uint32_t)(0))
\r
56 #define SSP_CPHA_SECOND SSP_CR0_CPHA_SECOND
\r
59 /** Clock polarity control bit */
\r
60 /* There's no bug here!!!
\r
61 * - If bit[6] in SSPnCR0 is 0: SSP controller maintains the bus clock low between frames.
\r
62 * That means the active clock is in HI state.
\r
63 * - If bit[6] in SSPnCR0 is 1 (SSP_CR0_CPOL_HI): SSP controller maintains the bus clock
\r
64 * high between frames. That means the active clock is in LO state.
\r
66 #define SSP_CPOL_HI ((uint32_t)(0))
\r
67 #define SSP_CPOL_LO SSP_CR0_CPOL_HI
\r
69 /** SSP master mode enable */
\r
70 #define SSP_SLAVE_MODE SSP_CR1_SLAVE_EN
\r
71 #define SSP_MASTER_MODE ((uint32_t)(0))
\r
73 /** SSP data bit number defines */
\r
74 #define SSP_DATABIT_4 SSP_CR0_DSS(4) /*!< Databit number = 4 */
\r
75 #define SSP_DATABIT_5 SSP_CR0_DSS(5) /*!< Databit number = 5 */
\r
76 #define SSP_DATABIT_6 SSP_CR0_DSS(6) /*!< Databit number = 6 */
\r
77 #define SSP_DATABIT_7 SSP_CR0_DSS(7) /*!< Databit number = 7 */
\r
78 #define SSP_DATABIT_8 SSP_CR0_DSS(8) /*!< Databit number = 8 */
\r
79 #define SSP_DATABIT_9 SSP_CR0_DSS(9) /*!< Databit number = 9 */
\r
80 #define SSP_DATABIT_10 SSP_CR0_DSS(10) /*!< Databit number = 10 */
\r
81 #define SSP_DATABIT_11 SSP_CR0_DSS(11) /*!< Databit number = 11 */
\r
82 #define SSP_DATABIT_12 SSP_CR0_DSS(12) /*!< Databit number = 12 */
\r
83 #define SSP_DATABIT_13 SSP_CR0_DSS(13) /*!< Databit number = 13 */
\r
84 #define SSP_DATABIT_14 SSP_CR0_DSS(14) /*!< Databit number = 14 */
\r
85 #define SSP_DATABIT_15 SSP_CR0_DSS(15) /*!< Databit number = 15 */
\r
86 #define SSP_DATABIT_16 SSP_CR0_DSS(16) /*!< Databit number = 16 */
\r
88 /** SSP Frame Format definition */
\r
89 /** Motorola SPI mode */
\r
90 #define SSP_FRAME_SPI SSP_CR0_FRF_SPI
\r
91 /** TI synchronous serial mode */
\r
92 #define SSP_FRAME_TI SSP_CR0_FRF_TI
\r
93 /** National Micro-wire mode */
\r
94 #define SSP_FRAME_MICROWIRE SSP_CR0_FRF_MICROWIRE
\r
96 /*********************************************************************//**
\r
97 * SSP Status defines
\r
98 **********************************************************************/
\r
99 /** SSP status TX FIFO Empty bit */
\r
100 #define SSP_STAT_TXFIFO_EMPTY SSP_SR_TFE
\r
101 /** SSP status TX FIFO not full bit */
\r
102 #define SSP_STAT_TXFIFO_NOTFULL SSP_SR_TNF
\r
103 /** SSP status RX FIFO not empty bit */
\r
104 #define SSP_STAT_RXFIFO_NOTEMPTY SSP_SR_RNE
\r
105 /** SSP status RX FIFO full bit */
\r
106 #define SSP_STAT_RXFIFO_FULL SSP_SR_RFF
\r
107 /** SSP status SSP Busy bit */
\r
108 #define SSP_STAT_BUSY SSP_SR_BSY
\r
110 /*********************************************************************//**
\r
111 * SSP Interrupt Configuration defines
\r
112 **********************************************************************/
\r
113 /** Receive Overrun */
\r
114 #define SSP_INTCFG_ROR SSP_IMSC_ROR
\r
115 /** Receive TimeOut */
\r
116 #define SSP_INTCFG_RT SSP_IMSC_RT
\r
117 /** Rx FIFO is at least half full */
\r
118 #define SSP_INTCFG_RX SSP_IMSC_RX
\r
119 /** Tx FIFO is at least half empty */
\r
120 #define SSP_INTCFG_TX SSP_IMSC_TX
\r
122 /*********************************************************************//**
\r
123 * SSP Configured Interrupt Status defines
\r
124 **********************************************************************/
\r
125 /** Receive Overrun */
\r
126 #define SSP_INTSTAT_ROR SSP_MIS_ROR
\r
127 /** Receive TimeOut */
\r
128 #define SSP_INTSTAT_RT SSP_MIS_RT
\r
129 /** Rx FIFO is at least half full */
\r
130 #define SSP_INTSTAT_RX SSP_MIS_RX
\r
131 /** Tx FIFO is at least half empty */
\r
132 #define SSP_INTSTAT_TX SSP_MIS_TX
\r
134 /*********************************************************************//**
\r
135 * SSP Raw Interrupt Status defines
\r
136 **********************************************************************/
\r
137 /** Receive Overrun */
\r
138 #define SSP_INTSTAT_RAW_ROR SSP_RIS_ROR
\r
139 /** Receive TimeOut */
\r
140 #define SSP_INTSTAT_RAW_RT SSP_RIS_RT
\r
141 /** Rx FIFO is at least half full */
\r
142 #define SSP_INTSTAT_RAW_RX SSP_RIS_RX
\r
143 /** Tx FIFO is at least half empty */
\r
144 #define SSP_INTSTAT_RAW_TX SSP_RIS_TX
\r
146 /*********************************************************************//**
\r
147 * SSP Interrupt Clear defines
\r
148 **********************************************************************/
\r
149 /** Writing a 1 to this bit clears the "frame was received when
\r
150 * RxFIFO was full" interrupt */
\r
151 #define SSP_INTCLR_ROR SSP_ICR_ROR
\r
152 /** Writing a 1 to this bit clears the "Rx FIFO was not empty and
\r
153 * has not been read for a timeout period" interrupt */
\r
154 #define SSP_INTCLR_RT SSP_ICR_RT
\r
156 /*********************************************************************//**
\r
158 **********************************************************************/
\r
159 /** SSP bit for enabling RX DMA */
\r
160 #define SSP_DMA_TX SSP_DMA_RXDMA_EN
\r
161 /** SSP bit for enabling TX DMA */
\r
162 #define SSP_DMA_RX SSP_DMA_TXDMA_EN
\r
164 /* SSP Status Implementation definitions */
\r
165 #define SSP_STAT_DONE (1UL<<8) /**< Done */
\r
166 #define SSP_STAT_ERROR (1UL<<9) /**< Error */
\r
169 /* --------------------- BIT DEFINITIONS -------------------------------------- */
\r
170 /*********************************************************************//**
\r
171 * Macro defines for CR0 register
\r
172 **********************************************************************/
\r
173 /** SSP data size select, must be 4 bits to 16 bits */
\r
174 #define SSP_CR0_DSS(n) ((uint32_t)((n-1)&0xF))
\r
175 /** SSP control 0 Motorola SPI mode */
\r
176 #define SSP_CR0_FRF_SPI ((uint32_t)(0<<4))
\r
177 /** SSP control 0 TI synchronous serial mode */
\r
178 #define SSP_CR0_FRF_TI ((uint32_t)(1<<4))
\r
179 /** SSP control 0 National Micro-wire mode */
\r
180 #define SSP_CR0_FRF_MICROWIRE ((uint32_t)(2<<4))
\r
181 /** SPI clock polarity bit (used in SPI mode only), (1) = maintains the
\r
182 bus clock high between frames, (0) = low */
\r
183 #define SSP_CR0_CPOL_HI ((uint32_t)(1<<6))
\r
184 /** SPI clock out phase bit (used in SPI mode only), (1) = captures data
\r
185 on the second clock transition of the frame, (0) = first */
\r
186 #define SSP_CR0_CPHA_SECOND ((uint32_t)(1<<7))
\r
187 /** SSP serial clock rate value load macro, divider rate is
\r
188 PERIPH_CLK / (cpsr * (SCR + 1)) */
\r
189 #define SSP_CR0_SCR(n) ((uint32_t)((n&0xFF)<<8))
\r
190 /** SSP CR0 bit mask */
\r
191 #define SSP_CR0_BITMASK ((uint32_t)(0xFFFF))
\r
193 /*********************************************************************//**
\r
194 * Macro defines for CR1 register
\r
195 **********************************************************************/
\r
196 /** SSP control 1 loopback mode enable bit */
\r
197 #define SSP_CR1_LBM_EN ((uint32_t)(1<<0))
\r
198 /** SSP control 1 enable bit */
\r
199 #define SSP_CR1_SSP_EN ((uint32_t)(1<<1))
\r
200 /** SSP control 1 slave enable */
\r
201 #define SSP_CR1_SLAVE_EN ((uint32_t)(1<<2))
\r
202 /** SSP control 1 slave out disable bit, disables transmit line in slave
\r
204 #define SSP_CR1_SO_DISABLE ((uint32_t)(1<<3))
\r
205 /** SSP CR1 bit mask */
\r
206 #define SSP_CR1_BITMASK ((uint32_t)(0x0F))
\r
208 /*********************************************************************//**
\r
209 * Macro defines for DR register
\r
210 **********************************************************************/
\r
211 /** SSP data bit mask */
\r
212 #define SSP_DR_BITMASK(n) ((n)&0xFFFF)
\r
214 /*********************************************************************//**
\r
215 * Macro defines for SR register
\r
216 **********************************************************************/
\r
217 /** SSP status TX FIFO Empty bit */
\r
218 #define SSP_SR_TFE ((uint32_t)(1<<0))
\r
219 /** SSP status TX FIFO not full bit */
\r
220 #define SSP_SR_TNF ((uint32_t)(1<<1))
\r
221 /** SSP status RX FIFO not empty bit */
\r
222 #define SSP_SR_RNE ((uint32_t)(1<<2))
\r
223 /** SSP status RX FIFO full bit */
\r
224 #define SSP_SR_RFF ((uint32_t)(1<<3))
\r
225 /** SSP status SSP Busy bit */
\r
226 #define SSP_SR_BSY ((uint32_t)(1<<4))
\r
227 /** SSP SR bit mask */
\r
228 #define SSP_SR_BITMASK ((uint32_t)(0x1F))
\r
230 /*********************************************************************//**
\r
231 * Macro defines for CPSR register
\r
232 **********************************************************************/
\r
233 /** SSP clock prescaler */
\r
234 #define SSP_CPSR_CPDVSR(n) ((uint32_t)(n&0xFF))
\r
235 /** SSP CPSR bit mask */
\r
236 #define SSP_CPSR_BITMASK ((uint32_t)(0xFF))
\r
238 /*********************************************************************//**
\r
239 * Macro define for (IMSC) Interrupt Mask Set/Clear registers
\r
240 **********************************************************************/
\r
241 /** Receive Overrun */
\r
242 #define SSP_IMSC_ROR ((uint32_t)(1<<0))
\r
243 /** Receive TimeOut */
\r
244 #define SSP_IMSC_RT ((uint32_t)(1<<1))
\r
245 /** Rx FIFO is at least half full */
\r
246 #define SSP_IMSC_RX ((uint32_t)(1<<2))
\r
247 /** Tx FIFO is at least half empty */
\r
248 #define SSP_IMSC_TX ((uint32_t)(1<<3))
\r
249 /** IMSC bit mask */
\r
250 #define SSP_IMSC_BITMASK ((uint32_t)(0x0F))
\r
252 /*********************************************************************//**
\r
253 * Macro define for (RIS) Raw Interrupt Status registers
\r
254 **********************************************************************/
\r
255 /** Receive Overrun */
\r
256 #define SSP_RIS_ROR ((uint32_t)(1<<0))
\r
257 /** Receive TimeOut */
\r
258 #define SSP_RIS_RT ((uint32_t)(1<<1))
\r
259 /** Rx FIFO is at least half full */
\r
260 #define SSP_RIS_RX ((uint32_t)(1<<2))
\r
261 /** Tx FIFO is at least half empty */
\r
262 #define SSP_RIS_TX ((uint32_t)(1<<3))
\r
263 /** RIS bit mask */
\r
264 #define SSP_RIS_BITMASK ((uint32_t)(0x0F))
\r
266 /*********************************************************************//**
\r
267 * Macro define for (MIS) Masked Interrupt Status registers
\r
268 **********************************************************************/
\r
269 /** Receive Overrun */
\r
270 #define SSP_MIS_ROR ((uint32_t)(1<<0))
\r
271 /** Receive TimeOut */
\r
272 #define SSP_MIS_RT ((uint32_t)(1<<1))
\r
273 /** Rx FIFO is at least half full */
\r
274 #define SSP_MIS_RX ((uint32_t)(1<<2))
\r
275 /** Tx FIFO is at least half empty */
\r
276 #define SSP_MIS_TX ((uint32_t)(1<<3))
\r
277 /** MIS bit mask */
\r
278 #define SSP_MIS_BITMASK ((uint32_t)(0x0F))
\r
280 /*********************************************************************//**
\r
281 * Macro define for (ICR) Interrupt Clear registers
\r
282 **********************************************************************/
\r
283 /** Writing a 1 to this bit clears the "frame was received when
\r
284 * RxFIFO was full" interrupt */
\r
285 #define SSP_ICR_ROR ((uint32_t)(1<<0))
\r
286 /** Writing a 1 to this bit clears the "Rx FIFO was not empty and
\r
287 * has not been read for a timeout period" interrupt */
\r
288 #define SSP_ICR_RT ((uint32_t)(1<<1))
\r
289 /** ICR bit mask */
\r
290 #define SSP_ICR_BITMASK ((uint32_t)(0x03))
\r
292 /*********************************************************************//**
\r
293 * Macro defines for DMACR register
\r
294 **********************************************************************/
\r
295 /** SSP bit for enabling RX DMA */
\r
296 #define SSP_DMA_RXDMA_EN ((uint32_t)(1<<0))
\r
297 /** SSP bit for enabling TX DMA */
\r
298 #define SSP_DMA_TXDMA_EN ((uint32_t)(1<<1))
\r
299 /** DMACR bit mask */
\r
300 #define SSP_DMA_BITMASK ((uint32_t)(0x03))
\r
303 /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
\r
304 /** Macro to determine if it is valid SSP port number */
\r
305 #define PARAM_SSPx(n) ((((uint32_t *)n)==((uint32_t *)LPC_SSP0)) \
\r
306 || (((uint32_t *)n)==((uint32_t *)LPC_SSP1)))
\r
308 /** Macro check clock phase control mode */
\r
309 #define PARAM_SSP_CPHA(n) ((n==SSP_CPHA_FIRST) || (n==SSP_CPHA_SECOND))
\r
311 /** Macro check clock polarity mode */
\r
312 #define PARAM_SSP_CPOL(n) ((n==SSP_CPOL_HI) || (n==SSP_CPOL_LO))
\r
314 /* Macro check master/slave mode */
\r
315 #define PARAM_SSP_MODE(n) ((n==SSP_SLAVE_MODE) || (n==SSP_MASTER_MODE))
\r
317 /* Macro check databit value */
\r
318 #define PARAM_SSP_DATABIT(n) ((n==SSP_DATABIT_4) || (n==SSP_DATABIT_5) \
\r
319 || (n==SSP_DATABIT_6) || (n==SSP_DATABIT_16) \
\r
320 || (n==SSP_DATABIT_7) || (n==SSP_DATABIT_8) \
\r
321 || (n==SSP_DATABIT_9) || (n==SSP_DATABIT_10) \
\r
322 || (n==SSP_DATABIT_11) || (n==SSP_DATABIT_12) \
\r
323 || (n==SSP_DATABIT_13) || (n==SSP_DATABIT_14) \
\r
324 || (n==SSP_DATABIT_15))
\r
326 /* Macro check frame type */
\r
327 #define PARAM_SSP_FRAME(n) ((n==SSP_FRAME_SPI) || (n==SSP_FRAME_TI)\
\r
328 || (n==SSP_FRAME_MICROWIRE))
\r
330 /* Macro check SSP status */
\r
331 #define PARAM_SSP_STAT(n) ((n==SSP_STAT_TXFIFO_EMPTY) || (n==SSP_STAT_TXFIFO_NOTFULL) \
\r
332 || (n==SSP_STAT_RXFIFO_NOTEMPTY) || (n==SSP_STAT_RXFIFO_FULL) \
\r
333 || (n==SSP_STAT_BUSY))
\r
335 /* Macro check interrupt configuration */
\r
336 #define PARAM_SSP_INTCFG(n) ((n==SSP_INTCFG_ROR) || (n==SSP_INTCFG_RT) \
\r
337 || (n==SSP_INTCFG_RX) || (n==SSP_INTCFG_TX))
\r
339 /* Macro check interrupt status value */
\r
340 #define PARAM_SSP_INTSTAT(n) ((n==SSP_INTSTAT_ROR) || (n==SSP_INTSTAT_RT) \
\r
341 || (n==SSP_INTSTAT_RX) || (n==SSP_INTSTAT_TX))
\r
343 /* Macro check interrupt status raw value */
\r
344 #define PARAM_SSP_INTSTAT_RAW(n) ((n==SSP_INTSTAT_RAW_ROR) || (n==SSP_INTSTAT_RAW_RT) \
\r
345 || (n==SSP_INTSTAT_RAW_RX) || (n==SSP_INTSTAT_RAW_TX))
\r
347 /* Macro check interrupt clear mode */
\r
348 #define PARAM_SSP_INTCLR(n) ((n==SSP_INTCLR_ROR) || (n==SSP_INTCLR_RT))
\r
350 /* Macro check DMA mode */
\r
351 #define PARAM_SSP_DMA(n) ((n==SSP_DMA_TX) || (n==SSP_DMA_RX))
\r
357 /* Public Types --------------------------------------------------------------- */
\r
358 /** @defgroup SSP_Public_Types SSP Public Types
\r
362 /** @brief SSP configuration structure */
\r
364 uint32_t Databit; /** Databit number, should be SSP_DATABIT_x,
\r
365 where x is in range from 4 - 16 */
\r
366 uint32_t CPHA; /** Clock phase, should be:
\r
367 - SSP_CPHA_FIRST: first clock edge
\r
368 - SSP_CPHA_SECOND: second clock edge */
\r
369 uint32_t CPOL; /** Clock polarity, should be:
\r
370 - SSP_CPOL_HI: high level
\r
371 - SSP_CPOL_LO: low level */
\r
372 uint32_t Mode; /** SSP mode, should be:
\r
373 - SSP_MASTER_MODE: Master mode
\r
374 - SSP_SLAVE_MODE: Slave mode */
\r
375 uint32_t FrameFormat; /** Frame Format:
\r
376 - SSP_FRAME_SPI: Motorola SPI frame format
\r
377 - SSP_FRAME_TI: TI frame format
\r
378 - SSP_FRAME_MICROWIRE: National Microwire frame format */
\r
379 uint32_t ClockRate; /** Clock rate,in Hz */
\r
383 * @brief SSP Transfer Type definitions
\r
386 SSP_TRANSFER_POLLING = 0, /**< Polling transfer */
\r
387 SSP_TRANSFER_INTERRUPT /**< Interrupt transfer */
\r
388 } SSP_TRANSFER_Type;
\r
391 * @brief SPI Data configuration structure definitions
\r
394 void *tx_data; /**< Pointer to transmit data */
\r
395 uint32_t tx_cnt; /**< Transmit counter */
\r
396 void *rx_data; /**< Pointer to transmit data */
\r
397 uint32_t rx_cnt; /**< Receive counter */
\r
398 uint32_t length; /**< Length of transfer data */
\r
399 uint32_t status; /**< Current status of SSP activity */
\r
400 } SSP_DATA_SETUP_Type;
\r
408 /* Public Functions ----------------------------------------------------------- */
\r
409 /** @defgroup SSP_Public_Functions SSP Public Functions
\r
413 void SSP_Init(LPC_SSPn_Type *SSPx, SSP_CFG_Type *SSP_ConfigStruct);
\r
414 void SSP_DeInit(LPC_SSPn_Type* SSPx);
\r
416 void SSP_ConfigStructInit(SSP_CFG_Type *SSP_InitStruct);
\r
417 void SSP_Cmd(LPC_SSPn_Type* SSPx, FunctionalState NewState);
\r
418 void SSP_LoopBackCmd(LPC_SSPn_Type* SSPx, FunctionalState NewState);
\r
419 void SSP_SlaveOutputCmd(LPC_SSPn_Type* SSPx, FunctionalState NewState);
\r
420 void SSP_SendData(LPC_SSPn_Type* SSPx, uint16_t Data);
\r
421 uint16_t SSP_ReceiveData(LPC_SSPn_Type* SSPx);
\r
422 int32_t SSP_ReadWrite (LPC_SSPn_Type *SSPx, SSP_DATA_SETUP_Type *dataCfg, \
\r
423 SSP_TRANSFER_Type xfType);
\r
424 FlagStatus SSP_GetStatus(LPC_SSPn_Type* SSPx, uint32_t FlagType);
\r
425 uint8_t SSP_GetDataSize(LPC_SSPn_Type* SSPx);
\r
426 void SSP_IntConfig(LPC_SSPn_Type *SSPx, uint32_t IntType, FunctionalState NewState);
\r
427 IntStatus SSP_GetRawIntStatus(LPC_SSPn_Type *SSPx, uint32_t RawIntType);
\r
428 IntStatus SSP_GetIntStatus (LPC_SSPn_Type *SSPx, uint32_t IntType);
\r
429 void SSP_ClearIntPending(LPC_SSPn_Type *SSPx, uint32_t IntType);
\r
430 void SSP_DMACmd(LPC_SSPn_Type *SSPx, uint32_t DMAMode, FunctionalState NewState);
\r
440 #endif /* LPC18XX_SSP_H_ */
\r
446 /* --------------------------------- End Of File ------------------------------ */
\r