uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc17xx_ssp.h
Go to the documentation of this file.
1 /***********************************************************************/
21 /* Peripheral group ----------------------------------------------------------- */
27 #ifndef LPC17XX_SSP_H_
28 #define LPC17XX_SSP_H_
29 
30 /* Includes ------------------------------------------------------------------- */
31 #include "LPC17xx.h"
32 #include "lpc_types.h"
33 
34 
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39 
40 /* Public Macros -------------------------------------------------------------- */
45 /*********************************************************************/
49 #define SSP_CPHA_FIRST ((uint32_t)(0))
50 #define SSP_CPHA_SECOND SSP_CR0_CPHA_SECOND
51 
52 
54 /* There's no bug here!!!
55  * - If bit[6] in SSPnCR0 is 0: SSP controller maintains the bus clock low between frames.
56  * That means the active clock is in HI state.
57  * - If bit[6] in SSPnCR0 is 1 (SSP_CR0_CPOL_HI): SSP controller maintains the bus clock
58  * high between frames. That means the active clock is in LO state.
59  */
60 #define SSP_CPOL_HI ((uint32_t)(0))
61 #define SSP_CPOL_LO SSP_CR0_CPOL_HI
62 
64 #define SSP_SLAVE_MODE SSP_CR1_SLAVE_EN
65 #define SSP_MASTER_MODE ((uint32_t)(0))
66 
68 #define SSP_DATABIT_4 SSP_CR0_DSS(4)
69 #define SSP_DATABIT_5 SSP_CR0_DSS(5)
70 #define SSP_DATABIT_6 SSP_CR0_DSS(6)
71 #define SSP_DATABIT_7 SSP_CR0_DSS(7)
72 #define SSP_DATABIT_8 SSP_CR0_DSS(8)
73 #define SSP_DATABIT_9 SSP_CR0_DSS(9)
74 #define SSP_DATABIT_10 SSP_CR0_DSS(10)
75 #define SSP_DATABIT_11 SSP_CR0_DSS(11)
76 #define SSP_DATABIT_12 SSP_CR0_DSS(12)
77 #define SSP_DATABIT_13 SSP_CR0_DSS(13)
78 #define SSP_DATABIT_14 SSP_CR0_DSS(14)
79 #define SSP_DATABIT_15 SSP_CR0_DSS(15)
80 #define SSP_DATABIT_16 SSP_CR0_DSS(16)
84 #define SSP_FRAME_SPI SSP_CR0_FRF_SPI
85 
86 #define SSP_FRAME_TI SSP_CR0_FRF_TI
87 
88 #define SSP_FRAME_MICROWIRE SSP_CR0_FRF_MICROWIRE
89 
90 /*********************************************************************/
94 #define SSP_STAT_TXFIFO_EMPTY SSP_SR_TFE
95 
96 #define SSP_STAT_TXFIFO_NOTFULL SSP_SR_TNF
97 
98 #define SSP_STAT_RXFIFO_NOTEMPTY SSP_SR_RNE
99 
100 #define SSP_STAT_RXFIFO_FULL SSP_SR_RFF
101 
102 #define SSP_STAT_BUSY SSP_SR_BSY
103 
104 /*********************************************************************/
108 #define SSP_INTCFG_ROR SSP_IMSC_ROR
109 
110 #define SSP_INTCFG_RT SSP_IMSC_RT
111 
112 #define SSP_INTCFG_RX SSP_IMSC_RX
113 
114 #define SSP_INTCFG_TX SSP_IMSC_TX
115 
116 /*********************************************************************/
120 #define SSP_INTSTAT_ROR SSP_MIS_ROR
121 
122 #define SSP_INTSTAT_RT SSP_MIS_RT
123 
124 #define SSP_INTSTAT_RX SSP_MIS_RX
125 
126 #define SSP_INTSTAT_TX SSP_MIS_TX
127 
128 /*********************************************************************/
132 #define SSP_INTSTAT_RAW_ROR SSP_RIS_ROR
133 
134 #define SSP_INTSTAT_RAW_RT SSP_RIS_RT
135 
136 #define SSP_INTSTAT_RAW_RX SSP_RIS_RX
137 
138 #define SSP_INTSTAT_RAW_TX SSP_RIS_TX
139 
140 /*********************************************************************/
145 #define SSP_INTCLR_ROR SSP_ICR_ROR
146 
148 #define SSP_INTCLR_RT SSP_ICR_RT
149 
150 /*********************************************************************/
154 #define SSP_DMA_RX SSP_DMA_RXDMA_EN
155 
156 #define SSP_DMA_TX SSP_DMA_TXDMA_EN
157 
158 /* SSP Status Implementation definitions */
159 #define SSP_STAT_DONE (1UL<<8)
160 #define SSP_STAT_ERROR (1UL<<9)
166 /* Private Macros ------------------------------------------------------------- */
167 
171 /* --------------------- BIT DEFINITIONS -------------------------------------- */
172 /*********************************************************************/
176 #define SSP_CR0_DSS(n) ((uint32_t)((n-1)&0xF))
177 
178 #define SSP_CR0_FRF_SPI ((uint32_t)(0<<4))
179 
180 #define SSP_CR0_FRF_TI ((uint32_t)(1<<4))
181 
182 #define SSP_CR0_FRF_MICROWIRE ((uint32_t)(2<<4))
183 
185 #define SSP_CR0_CPOL_HI ((uint32_t)(1<<6))
186 
188 #define SSP_CR0_CPHA_SECOND ((uint32_t)(1<<7))
189 
191 #define SSP_CR0_SCR(n) ((uint32_t)((n&0xFF)<<8))
192 
193 #define SSP_CR0_BITMASK ((uint32_t)(0xFFFF))
194 
195 /*********************************************************************/
199 #define SSP_CR1_LBM_EN ((uint32_t)(1<<0))
200 
201 #define SSP_CR1_SSP_EN ((uint32_t)(1<<1))
202 
203 #define SSP_CR1_SLAVE_EN ((uint32_t)(1<<2))
204 
206 #define SSP_CR1_SO_DISABLE ((uint32_t)(1<<3))
207 
208 #define SSP_CR1_BITMASK ((uint32_t)(0x0F))
209 
210 /*********************************************************************/
214 #define SSP_DR_BITMASK(n) ((n)&0xFFFF)
215 
216 /*********************************************************************/
220 #define SSP_SR_TFE ((uint32_t)(1<<0))
221 
222 #define SSP_SR_TNF ((uint32_t)(1<<1))
223 
224 #define SSP_SR_RNE ((uint32_t)(1<<2))
225 
226 #define SSP_SR_RFF ((uint32_t)(1<<3))
227 
228 #define SSP_SR_BSY ((uint32_t)(1<<4))
229 
230 #define SSP_SR_BITMASK ((uint32_t)(0x1F))
231 
232 /*********************************************************************/
236 #define SSP_CPSR_CPDVSR(n) ((uint32_t)(n&0xFF))
237 
238 #define SSP_CPSR_BITMASK ((uint32_t)(0xFF))
239 
240 /*********************************************************************/
244 #define SSP_IMSC_ROR ((uint32_t)(1<<0))
245 
246 #define SSP_IMSC_RT ((uint32_t)(1<<1))
247 
248 #define SSP_IMSC_RX ((uint32_t)(1<<2))
249 
250 #define SSP_IMSC_TX ((uint32_t)(1<<3))
251 
252 #define SSP_IMSC_BITMASK ((uint32_t)(0x0F))
253 
254 /*********************************************************************/
258 #define SSP_RIS_ROR ((uint32_t)(1<<0))
259 
260 #define SSP_RIS_RT ((uint32_t)(1<<1))
261 
262 #define SSP_RIS_RX ((uint32_t)(1<<2))
263 
264 #define SSP_RIS_TX ((uint32_t)(1<<3))
265 
266 #define SSP_RIS_BITMASK ((uint32_t)(0x0F))
267 
268 /*********************************************************************/
272 #define SSP_MIS_ROR ((uint32_t)(1<<0))
273 
274 #define SSP_MIS_RT ((uint32_t)(1<<1))
275 
276 #define SSP_MIS_RX ((uint32_t)(1<<2))
277 
278 #define SSP_MIS_TX ((uint32_t)(1<<3))
279 
280 #define SSP_MIS_BITMASK ((uint32_t)(0x0F))
281 
282 /*********************************************************************/
287 #define SSP_ICR_ROR ((uint32_t)(1<<0))
288 
290 #define SSP_ICR_RT ((uint32_t)(1<<1))
291 
292 #define SSP_ICR_BITMASK ((uint32_t)(0x03))
293 
294 /*********************************************************************/
298 #define SSP_DMA_RXDMA_EN ((uint32_t)(1<<0))
299 
300 #define SSP_DMA_TXDMA_EN ((uint32_t)(1<<1))
301 
302 #define SSP_DMA_BITMASK ((uint32_t)(0x03))
303 
304 
305 /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
307 #define PARAM_SSPx(n) ((((uint32_t *)n)==((uint32_t *)LPC_SSP0)) \
308 || (((uint32_t *)n)==((uint32_t *)LPC_SSP1)))
309 
311 #define PARAM_SSP_CPHA(n) ((n==SSP_CPHA_FIRST) || (n==SSP_CPHA_SECOND))
312 
314 #define PARAM_SSP_CPOL(n) ((n==SSP_CPOL_HI) || (n==SSP_CPOL_LO))
315 
316 /* Macro check master/slave mode */
317 #define PARAM_SSP_MODE(n) ((n==SSP_SLAVE_MODE) || (n==SSP_MASTER_MODE))
318 
319 /* Macro check databit value */
320 #define PARAM_SSP_DATABIT(n) ((n==SSP_DATABIT_4) || (n==SSP_DATABIT_5) \
321 || (n==SSP_DATABIT_6) || (n==SSP_DATABIT_16) \
322 || (n==SSP_DATABIT_7) || (n==SSP_DATABIT_8) \
323 || (n==SSP_DATABIT_9) || (n==SSP_DATABIT_10) \
324 || (n==SSP_DATABIT_11) || (n==SSP_DATABIT_12) \
325 || (n==SSP_DATABIT_13) || (n==SSP_DATABIT_14) \
326 || (n==SSP_DATABIT_15))
327 
328 /* Macro check frame type */
329 #define PARAM_SSP_FRAME(n) ((n==SSP_FRAME_SPI) || (n==SSP_FRAME_TI)\
330 || (n==SSP_FRAME_MICROWIRE))
331 
332 /* Macro check SSP status */
333 #define PARAM_SSP_STAT(n) ((n==SSP_STAT_TXFIFO_EMPTY) || (n==SSP_STAT_TXFIFO_NOTFULL) \
334 || (n==SSP_STAT_RXFIFO_NOTEMPTY) || (n==SSP_STAT_RXFIFO_FULL) \
335 || (n==SSP_STAT_BUSY))
336 
337 /* Macro check interrupt configuration */
338 #define PARAM_SSP_INTCFG(n) ((n==SSP_INTCFG_ROR) || (n==SSP_INTCFG_RT) \
339 || (n==SSP_INTCFG_RX) || (n==SSP_INTCFG_TX))
340 
341 /* Macro check interrupt status value */
342 #define PARAM_SSP_INTSTAT(n) ((n==SSP_INTSTAT_ROR) || (n==SSP_INTSTAT_RT) \
343 || (n==SSP_INTSTAT_RX) || (n==SSP_INTSTAT_TX))
344 
345 /* Macro check interrupt status raw value */
346 #define PARAM_SSP_INTSTAT_RAW(n) ((n==SSP_INTSTAT_RAW_ROR) || (n==SSP_INTSTAT_RAW_RT) \
347 || (n==SSP_INTSTAT_RAW_RX) || (n==SSP_INTSTAT_RAW_TX))
348 
349 /* Macro check interrupt clear mode */
350 #define PARAM_SSP_INTCLR(n) ((n==SSP_INTCLR_ROR) || (n==SSP_INTCLR_RT))
351 
352 /* Macro check DMA mode */
353 #define PARAM_SSP_DMA(n) ((n==SSP_DMA_TX) || (n==SSP_DMA_RX))
354 
359 /* Public Types --------------------------------------------------------------- */
365 typedef struct {
366  uint32_t Databit;
368  uint32_t CPHA;
371  uint32_t CPOL;
374  uint32_t Mode;
377  uint32_t FrameFormat;
381  uint32_t ClockRate;
382 } SSP_CFG_Type;
383 
387 typedef enum {
391 
395 typedef struct {
396  void *tx_data;
397  uint32_t tx_cnt;
398  void *rx_data;
399  uint32_t rx_cnt;
400  uint32_t length;
401  uint32_t status;
403 
404 
410 /* Public Functions ----------------------------------------------------------- */
415 /* SSP Init/DeInit functions --------------------------------------------------*/
416 void SSP_Init(LPC_SSP_TypeDef *SSPx, SSP_CFG_Type *SSP_ConfigStruct);
417 void SSP_DeInit(LPC_SSP_TypeDef* SSPx);
418 
419 /* SSP configure functions ----------------------------------------------------*/
420 void SSP_ConfigStructInit(SSP_CFG_Type *SSP_InitStruct);
421 
422 /* SSP enable/disable functions -----------------------------------------------*/
423 void SSP_Cmd(LPC_SSP_TypeDef* SSPx, FunctionalState NewState);
424 void SSP_LoopBackCmd(LPC_SSP_TypeDef* SSPx, FunctionalState NewState);
426 void SSP_DMACmd(LPC_SSP_TypeDef *SSPx, uint32_t DMAMode, FunctionalState NewState);
427 
428 /* SSP get information functions ----------------------------------------------*/
429 FlagStatus SSP_GetStatus(LPC_SSP_TypeDef* SSPx, uint32_t FlagType);
430 uint8_t SSP_GetDataSize(LPC_SSP_TypeDef* SSPx);
431 IntStatus SSP_GetRawIntStatus(LPC_SSP_TypeDef *SSPx, uint32_t RawIntType);
433 IntStatus SSP_GetIntStatus (LPC_SSP_TypeDef *SSPx, uint32_t IntType);
434 
435 /* SSP transfer data functions ------------------------------------------------*/
436 void SSP_SendData(LPC_SSP_TypeDef* SSPx, uint16_t Data);
437 uint16_t SSP_ReceiveData(LPC_SSP_TypeDef* SSPx);
438 int32_t SSP_ReadWrite (LPC_SSP_TypeDef *SSPx, SSP_DATA_SETUP_Type *dataCfg, \
439  SSP_TRANSFER_Type xfType);
440 
441 /* SSP IRQ function ------------------------------------------------------------*/
442 void SSP_IntConfig(LPC_SSP_TypeDef *SSPx, uint32_t IntType, FunctionalState NewState);
443 void SSP_ClearIntPending(LPC_SSP_TypeDef *SSPx, uint32_t IntType);
444 
445 
450 #ifdef __cplusplus
451 }
452 #endif
453 
454 #endif /* LPC17XX_SSP_H_ */
455 
460 /* --------------------------------- End Of File ------------------------------ */