2 * @brief SSP Registers and control functions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __SSP_001_H_
\r
33 #define __SSP_001_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_SSP_001 IP: SSP register block and driver
\r
43 * @ingroup IP_Drivers
\r
48 * @brief SSP register block structure
\r
50 typedef struct { /*!< SSPn Structure */
\r
51 __IO uint32_t CR0; /*!< Control Register 0. Selects the serial clock rate, bus type, and data size. */
\r
52 __IO uint32_t CR1; /*!< Control Register 1. Selects master/slave and other modes. */
\r
53 __IO uint32_t DR; /*!< Data Register. Writes fill the transmit FIFO, and reads empty the receive FIFO. */
\r
54 __I uint32_t SR; /*!< Status Register */
\r
55 __IO uint32_t CPSR; /*!< Clock Prescale Register */
\r
56 __IO uint32_t IMSC; /*!< Interrupt Mask Set and Clear Register */
\r
57 __I uint32_t RIS; /*!< Raw Interrupt Status Register */
\r
58 __I uint32_t MIS; /*!< Masked Interrupt Status Register */
\r
59 __O uint32_t ICR; /*!< SSPICR Interrupt Clear Register */
\r
60 #if !defined(CHIP_LPC110X) && !defined(CHIP_LPC11XXLV) && !defined(CHIP_LPC11AXX) && \
\r
61 !defined(CHIP_LPC11CXX) && !defined(CHIP_LPC11EXX) && !defined(CHIP_LPC11UXX)
\r
62 __IO uint32_t DMACR; /*!< SSPn DMA control register */
\r
67 * Macro defines for CR0 register
\r
70 /** SSP data size select, must be 4 bits to 16 bits */
\r
71 #define SSP_CR0_DSS(n) ((uint32_t) ((n) & 0xF))
\r
72 /** SSP control 0 Motorola SPI mode */
\r
73 #define SSP_CR0_FRF_SPI ((uint32_t) (0 << 4))
\r
74 /** SSP control 0 TI synchronous serial mode */
\r
75 #define SSP_CR0_FRF_TI ((uint32_t) (1 << 4))
\r
76 /** SSP control 0 National Micro-wire mode */
\r
77 #define SSP_CR0_FRF_MICROWIRE ((uint32_t) (2 << 4))
\r
78 /** SPI clock polarity bit (used in SPI mode only), (1) = maintains the
\r
79 bus clock high between frames, (0) = low */
\r
80 #define SSP_CR0_CPOL_LO ((uint32_t) (0))
\r
81 #define SSP_CR0_CPOL_HI ((uint32_t) (1 << 6))
\r
82 /** SPI clock out phase bit (used in SPI mode only), (1) = captures data
\r
83 on the second clock transition of the frame, (0) = first */
\r
84 #define SSP_CR0_CPHA_FIRST ((uint32_t) (0))
\r
85 #define SSP_CR0_CPHA_SECOND ((uint32_t) (1 << 7))
\r
86 /** SSP serial clock rate value load macro, divider rate is
\r
87 PERIPH_CLK / (cpsr * (SCR + 1)) */
\r
88 #define SSP_CR0_SCR(n) ((uint32_t) ((n & 0xFF) << 8))
\r
89 /** SSP CR0 bit mask */
\r
90 #define SSP_CR0_BITMASK ((uint32_t) (0xFFFF))
\r
91 /** SSP CR0 bit mask */
\r
92 #define SSP_CR0_BITMASK ((uint32_t) (0xFFFF))
\r
93 /** SSP serial clock rate value load macro, divider rate is
\r
94 PERIPH_CLK / (cpsr * (SCR + 1)) */
\r
95 #define SSP_CR0_SCR(n) ((uint32_t) ((n & 0xFF) << 8))
\r
98 * Macro defines for CR1 register
\r
101 /** SSP control 1 loopback mode enable bit */
\r
102 #define SSP_CR1_LBM_EN ((uint32_t) (1 << 0))
\r
103 /** SSP control 1 enable bit */
\r
104 #define SSP_CR1_SSP_EN ((uint32_t) (1 << 1))
\r
105 /** SSP control 1 slave enable */
\r
106 #define SSP_CR1_SLAVE_EN ((uint32_t) (1 << 2))
\r
107 #define SSP_CR1_MASTER_EN ((uint32_t) (0))
\r
108 /** SSP control 1 slave out disable bit, disables transmit line in slave
\r
110 #define SSP_CR1_SO_DISABLE ((uint32_t) (1 << 3))
\r
111 /** SSP CR1 bit mask */
\r
112 #define SSP_CR1_BITMASK ((uint32_t) (0x0F))
\r
114 /** SSP CPSR bit mask */
\r
115 #define SSP_CPSR_BITMASK ((uint32_t) (0xFF))
\r
117 * Macro defines for DR register
\r
120 /** SSP data bit mask */
\r
121 #define SSP_DR_BITMASK(n) ((n) & 0xFFFF)
\r
124 * Macro defines for SR register
\r
127 /** SSP SR bit mask */
\r
128 #define SSP_SR_BITMASK ((uint32_t) (0x1F))
\r
130 /** ICR bit mask */
\r
131 #define SSP_ICR_BITMASK ((uint32_t) (0x03))
\r
134 * @brief SSP Type of Status
\r
136 typedef enum IP_SSP_STATUS {
\r
137 SSP_STAT_TFE = ((uint32_t)(1 << 0)),/**< TX FIFO Empty */
\r
138 SSP_STAT_TNF = ((uint32_t)(1 << 1)),/**< TX FIFO not full */
\r
139 SSP_STAT_RNE = ((uint32_t)(1 << 2)),/**< RX FIFO not empty */
\r
140 SSP_STAT_RFF = ((uint32_t)(1 << 3)),/**< RX FIFO full */
\r
141 SSP_STAT_BSY = ((uint32_t)(1 << 4)),/**< SSP Busy */
\r
145 * @brief SSP Type of Interrupt Mask
\r
147 typedef enum IP_SSP_INTMASK {
\r
148 SSP_RORIM = ((uint32_t)(1 << 0)), /**< Overun */
\r
149 SSP_RTIM = ((uint32_t)(1 << 1)),/**< TimeOut */
\r
150 SSP_RXIM = ((uint32_t)(1 << 2)),/**< Rx FIFO is at least half full */
\r
151 SSP_TXIM = ((uint32_t)(1 << 3)),/**< Tx FIFO is at least half empty */
\r
152 SSP_INT_MASK_BITMASK = ((uint32_t)(0xF)),
\r
153 } IP_SSP_INTMASK_T;
\r
156 * @brief SSP Type of Mask Interrupt Status
\r
158 typedef enum IP_SSP_MASKINTSTATUS {
\r
159 SSP_RORMIS = ((uint32_t)(1 << 0)), /**< Overun */
\r
160 SSP_RTMIS = ((uint32_t)(1 << 1)), /**< TimeOut */
\r
161 SSP_RXMIS = ((uint32_t)(1 << 2)), /**< Rx FIFO is at least half full */
\r
162 SSP_TXMIS = ((uint32_t)(1 << 3)), /**< Tx FIFO is at least half empty */
\r
163 SSP_MASK_INT_STAT_BITMASK = ((uint32_t)(0xF)),
\r
164 } IP_SSP_MASKINTSTATUS_T;
\r
167 * @brief SSP Type of Raw Interrupt Status
\r
169 typedef enum IP_SSP_RAWINTSTATUS {
\r
170 SSP_RORRIS = ((uint32_t)(1 << 0)), /**< Overun */
\r
171 SSP_RTRIS = ((uint32_t)(1 << 1)), /**< TimeOut */
\r
172 SSP_RXRIS = ((uint32_t)(1 << 2)), /**< Rx FIFO is at least half full */
\r
173 SSP_TXRIS = ((uint32_t)(1 << 3)), /**< Tx FIFO is at least half empty */
\r
174 SSP_RAW_INT_STAT_BITMASK = ((uint32_t)(0xF)),
\r
175 } IP_SSP_RAWINTSTATUS_T;
\r
177 typedef enum IP_SSP_INTCLEAR {
\r
180 SSP_INT_CLEAR_BITMASK = 0x3,
\r
181 } IP_SSP_INTCLEAR_T;
\r
183 typedef enum IP_SSP_DMA {
\r
184 SSP_DMA_RX = (1u), /**< DMA RX Enable */
\r
185 SSP_DMA_TX = (1u << 1), /**< DMA TX Enable */
\r
186 SSP_DMA_BITMASK = ((uint32_t)(0x3)),
\r
190 * @brief Disable SSP operation
\r
191 * @param pSSP : The base of SSP peripheral on the chip
\r
193 * @note The SSP controller is disabled
\r
195 STATIC INLINE void IP_SSP_DeInit(IP_SSP_001_T *pSSP)
\r
197 pSSP->CR1 &= (~SSP_CR1_SSP_EN) & SSP_CR1_BITMASK;
\r
201 * @brief Enable SSP operation
\r
202 * @param pSSP : The base of SSP peripheral on the chip
\r
205 STATIC INLINE void IP_SSP_Enable(IP_SSP_001_T *pSSP)
\r
207 pSSP->CR1 |= SSP_CR1_SSP_EN;
\r
211 * @brief Disable SSP operation
\r
212 * @param pSSP : The base of SSP peripheral on the chip
\r
215 STATIC INLINE void IP_SSP_Disable(IP_SSP_001_T *pSSP)
\r
217 pSSP->CR1 &= (~SSP_CR1_SSP_EN) & SSP_CR1_BITMASK;
\r
221 * @brief Enable loopback mode
\r
222 * @param pSSP : The base of SSP peripheral on the chip
\r
224 * @note Serial input is taken from the serial output (MOSI or MISO) rather
\r
225 * than the serial input pin
\r
227 STATIC INLINE void IP_SSP_EnableLoopBack(IP_SSP_001_T *pSSP)
\r
229 pSSP->CR1 |= SSP_CR1_LBM_EN;
\r
233 * @brief Disable loopback mode
\r
234 * @param pSSP : The base of SSP peripheral on the chip
\r
236 * @note Serial input is taken from the serial output (MOSI or MISO) rather
\r
237 * than the serial input pin
\r
239 STATIC INLINE void IP_SSP_DisableLoopBack(IP_SSP_001_T *pSSP)
\r
241 pSSP->CR1 &= (~SSP_CR1_LBM_EN) & SSP_CR1_BITMASK;
\r
245 * @brief Get the current status of SSP controller
\r
246 * @param pSSP : The base of SSP peripheral on the chip
\r
247 * @param Stat : Type of status, should be :
\r
253 * @return SSP controller status, SET or RESET
\r
255 STATIC INLINE FlagStatus IP_SSP_GetStatus(IP_SSP_001_T *pSSP, IP_SSP_STATUS_T Stat)
\r
257 return (pSSP->SR & Stat) ? SET : RESET;
\r
261 * @brief Get the masked interrupt status
\r
262 * @param pSSP : The base of SSP peripheral on the chip
\r
263 * @return SSP Masked Interrupt Status Register value
\r
264 * @note The return value contains a 1 for each interrupt condition that is asserted and enabled (masked)
\r
266 STATIC INLINE uint32_t IP_SSP_GetIntStatus(IP_SSP_001_T *pSSP)
\r
272 * @brief Get the raw interrupt status
\r
273 * @param pSSP : The base of SSP peripheral on the chip
\r
274 * @param RawInt : Interrupt condition to be get status, shoud be :
\r
279 * @return Raw interrupt status corresponding to interrupt condition , SET or RESET
\r
280 * @note Get the status of each interrupt condition ,regardless of whether or not the interrupt is enabled
\r
282 STATIC INLINE IntStatus IP_SSP_GetRawIntStatus(IP_SSP_001_T *pSSP, IP_SSP_RAWINTSTATUS_T RawInt)
\r
284 return (pSSP->RIS & RawInt) ? SET : RESET;
\r
288 * @brief Get the number of bits transferred in each frame
\r
289 * @param pSSP : The base of SSP peripheral on the chip
\r
290 * @return the number of bits transferred in each frame minus one
\r
291 * @note The return value is 0x03 -> 0xF corresponding to 4bit -> 16bit transfer
\r
293 STATIC INLINE uint8_t IP_SSP_GetDataSize(IP_SSP_001_T *pSSP)
\r
295 return SSP_CR0_DSS(pSSP->CR0);
\r
299 * @brief Clear the corresponding interrupt condition(s) in the SSP controller
\r
300 * @param pSSP : The base of SSP peripheral on the chip
\r
301 * @param IntClear: Type of cleared interrupt, should be :
\r
305 * @note Software can clear one or more interrupt condition(s) in the SSP controller
\r
307 STATIC INLINE void IP_SSP_ClearIntPending(IP_SSP_001_T *pSSP, IP_SSP_INTCLEAR_T IntClear)
\r
309 pSSP->ICR = IntClear;
\r
313 * @brief Enable interrupt for the SSP
\r
314 * @param pSSP : The base of SSP peripheral on the chip
\r
315 * @param IntType : Type of interrupt condition to be enable/disable, should be :
\r
322 STATIC INLINE void IP_SSP_Int_Enable(IP_SSP_001_T *pSSP, IP_SSP_INTMASK_T IntType)
\r
324 pSSP->IMSC |= IntType;
\r
328 * @brief Disable interrupt for the SSP
\r
329 * @param pSSP : The base of SSP peripheral on the chip
\r
330 * @param IntType : Type of interrupt condition to be enable/disable, should be :
\r
337 STATIC INLINE void IP_SSP_Int_Disable(IP_SSP_001_T *pSSP, IP_SSP_INTMASK_T IntType)
\r
339 pSSP->IMSC &= (~IntType);
\r
343 * @brief Get received SSP data
\r
344 * @param pSSP : The base of SSP peripheral on the chip
\r
345 * @return SSP 16-bit data received
\r
347 STATIC INLINE uint16_t IP_SSP_ReceiveFrame(IP_SSP_001_T *pSSP)
\r
349 return (uint16_t) (SSP_DR_BITMASK(pSSP->DR));
\r
353 * @brief Send SSP 16-bit data
\r
354 * @param pSSP : The base of SSP peripheral on the chip
\r
355 * @param tx_data : SSP 16-bit data to be transmited
\r
358 STATIC INLINE void IP_SSP_SendFrame(IP_SSP_001_T *pSSP, uint16_t tx_data)
\r
360 pSSP->DR = SSP_DR_BITMASK(tx_data);
\r
364 * @brief Set up output clocks per bit for SSP bus
\r
365 * @param pSSP : The base of SSP peripheral on the chip
\r
366 * @param clk_rate fs: The number of prescaler-output clocks per bit on the bus, minus one
\r
367 * @param prescale : The factor by which the Prescaler divides the SSP peripheral clock PCLK
\r
369 * @note The bit frequency is PCLK / (prescale x[clk_rate+1])
\r
371 void IP_SSP_Set_ClockRate(IP_SSP_001_T *pSSP, uint32_t clk_rate, uint32_t prescale);
\r
374 * @brief Set up the SSP frame format
\r
375 * @param pSSP : The base of SSP peripheral on the chip
\r
376 * @param bits : The number of bits transferred in each frame, should be SSP_BITS_4 to SSP_BITS_16
\r
377 * @param frameFormat : Frame format, should be :
\r
378 * - SSP_FRAMEFORMAT_SPI
\r
379 * - SSP_FRAME_FORMAT_TI
\r
380 * - SSP_FRAMEFORMAT_MICROWIRE
\r
381 * @param clockMode : Select Clock polarity and Clock phase, should be :
\r
382 * - SSP_CLOCK_CPHA0_CPOL0
\r
383 * - SSP_CLOCK_CPHA0_CPOL1
\r
384 * - SSP_CLOCK_CPHA1_CPOL0
\r
385 * - SSP_CLOCK_CPHA1_CPOL1
\r
387 * @note Note: The clockFormat is only used in SPI mode
\r
389 STATIC INLINE void IP_SSP_SetFormat(IP_SSP_001_T *pSSP, uint32_t bits, uint32_t frameFormat, uint32_t clockMode)
\r
391 pSSP->CR0 = (pSSP->CR0 & ~0xFF) | bits | frameFormat | clockMode;
\r
395 * @brief Set the SSP working as master or slave mode
\r
396 * @param pSSP : The base of SSP peripheral on the chip
\r
397 * @param mode : Operating mode, should be
\r
398 * - SSP_MODE_MASTER
\r
402 STATIC INLINE void IP_SSP_Set_Mode(IP_SSP_001_T *pSSP, uint32_t mode)
\r
404 pSSP->CR1 = (pSSP->CR1 & ~(1 << 2)) | mode;
\r
407 #if !defined(CHIP_LPC110X) && !defined(CHIP_LPC11XXLV) && !defined(CHIP_LPC11AXX) && \
\r
408 !defined(CHIP_LPC11CXX) && !defined(CHIP_LPC11EXX) && !defined(CHIP_LPC11UXX)
\r
410 * @brief Enable DMA for SSP
\r
411 * @param pSSP : The base of SSP peripheral on the chip
\r
412 * @param flag : DMA flag for transmit/receive SSP, should be
\r
417 STATIC INLINE void IP_SSP_DMA_Enable(IP_SSP_001_T *pSSP, IP_SSP_DMA_T flag)
\r
419 pSSP->DMACR |= flag;
\r
423 * @brief Disable DMA for SSP
\r
424 * @param pSSP : The base of SSP peripheral on the chip
\r
425 * @param flag : DMA flag for transmit/receive SSP, should be
\r
430 STATIC INLINE void IP_SSP_DMA_Disable(IP_SSP_001_T *pSSP, IP_SSP_DMA_T flag)
\r
432 pSSP->DMACR &= ~flag;
\r
445 #endif /* __SSP_001_H_ */
\r