]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/LPCOpen/lpc_core/lpc_ip/ssp_001.h
Add extra debug comment into list.c.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / LPCOpen / lpc_core / lpc_ip / ssp_001.h
1 /*\r
2  * @brief SSP Registers and control functions\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * All rights reserved.\r
7  *\r
8  * @par\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
22  *\r
23  * @par\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
29  * this code.\r
30  */\r
31 \r
32 #ifndef __SSP_001_H_\r
33 #define __SSP_001_H_\r
34 \r
35 #include "sys_config.h"\r
36 #include "cmsis.h"\r
37 \r
38 #ifdef __cplusplus\r
39 extern "C" {\r
40 #endif\r
41 \r
42 /** @defgroup IP_SSP_001 IP: SSP register block and driver\r
43  * @ingroup IP_Drivers\r
44  * @{\r
45  */\r
46 \r
47 /**\r
48  * @brief SSP register block structure\r
49  */\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
63 #endif\r
64 } IP_SSP_001_T;\r
65 \r
66 /**\r
67  * Macro defines for CR0 register\r
68  */\r
69 \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
96 \r
97 /**\r
98  * Macro defines for CR1 register\r
99  */\r
100 \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
109    mode */\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
113 \r
114 /** SSP CPSR bit mask */\r
115 #define SSP_CPSR_BITMASK    ((uint32_t) (0xFF))\r
116 /**\r
117  * Macro defines for DR register\r
118  */\r
119 \r
120 /** SSP data bit mask */\r
121 #define SSP_DR_BITMASK(n)   ((n) & 0xFFFF)\r
122 \r
123 /**\r
124  * Macro defines for SR register\r
125  */\r
126 \r
127 /** SSP SR bit mask */\r
128 #define SSP_SR_BITMASK  ((uint32_t) (0x1F))\r
129 \r
130 /** ICR bit mask */\r
131 #define SSP_ICR_BITMASK ((uint32_t) (0x03))\r
132 \r
133 /**\r
134  * @brief SSP Type of Status\r
135  */\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
142 } IP_SSP_STATUS_T;\r
143 \r
144 /**\r
145  * @brief SSP Type of Interrupt Mask\r
146  */\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
154 \r
155 /**\r
156  * @brief SSP Type of Mask Interrupt Status\r
157  */\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
165 \r
166 /**\r
167  * @brief SSP Type of Raw Interrupt Status\r
168  */\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
176 \r
177 typedef enum IP_SSP_INTCLEAR {\r
178         SSP_RORIC = 0x0,\r
179         SSP_RTIC = 0x1,\r
180         SSP_INT_CLEAR_BITMASK = 0x3,\r
181 } IP_SSP_INTCLEAR_T;\r
182 \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
187 } IP_SSP_DMA_T;\r
188 \r
189 /**\r
190  * @brief       Disable SSP operation\r
191  * @param       pSSP    : The base of SSP peripheral on the chip\r
192  * @return       Nothing\r
193  * @note        The SSP controller is disabled\r
194  */\r
195 STATIC INLINE void IP_SSP_DeInit(IP_SSP_001_T *pSSP)\r
196 {\r
197         pSSP->CR1 &= (~SSP_CR1_SSP_EN) & SSP_CR1_BITMASK;\r
198 }\r
199 \r
200 /**\r
201  * @brief       Enable SSP operation\r
202  * @param       pSSP            : The base of SSP peripheral on the chip\r
203  * @return       Nothing\r
204  */\r
205 STATIC INLINE void IP_SSP_Enable(IP_SSP_001_T *pSSP)\r
206 {\r
207         pSSP->CR1 |= SSP_CR1_SSP_EN;\r
208 }\r
209 \r
210 /**\r
211  * @brief       Disable SSP operation\r
212  * @param       pSSP            : The base of SSP peripheral on the chip\r
213  * @return       Nothing\r
214  */\r
215 STATIC INLINE void IP_SSP_Disable(IP_SSP_001_T *pSSP)\r
216 {\r
217         pSSP->CR1 &= (~SSP_CR1_SSP_EN) & SSP_CR1_BITMASK;\r
218 }\r
219 \r
220 /**\r
221  * @brief       Enable loopback mode\r
222  * @param       pSSP            : The base of SSP peripheral on the chip\r
223  * @return       Nothing\r
224  * @note        Serial input is taken from the serial output (MOSI or MISO) rather\r
225  * than the serial input pin\r
226  */\r
227 STATIC INLINE void IP_SSP_EnableLoopBack(IP_SSP_001_T *pSSP)\r
228 {\r
229         pSSP->CR1 |= SSP_CR1_LBM_EN;\r
230 }\r
231 \r
232 /**\r
233  * @brief       Disable loopback mode\r
234  * @param       pSSP            : The base of SSP peripheral on the chip\r
235  * @return       Nothing\r
236  * @note        Serial input is taken from the serial output (MOSI or MISO) rather\r
237  * than the serial input pin\r
238  */\r
239 STATIC INLINE void IP_SSP_DisableLoopBack(IP_SSP_001_T *pSSP)\r
240 {\r
241         pSSP->CR1 &= (~SSP_CR1_LBM_EN) & SSP_CR1_BITMASK;\r
242 }\r
243 \r
244 /**\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
248  *                                              - SSP_STAT_TFE\r
249  *                                              - SSP_STAT_TNF\r
250  *                                              - SSP_STAT_RNE\r
251  *                                              - SSP_STAT_RFF\r
252  *                                              - SSP_STAT_BSY\r
253  * @return       SSP controller status, SET or RESET\r
254  */\r
255 STATIC INLINE FlagStatus IP_SSP_GetStatus(IP_SSP_001_T *pSSP, IP_SSP_STATUS_T Stat)\r
256 {\r
257         return (pSSP->SR & Stat) ? SET : RESET;\r
258 }\r
259 \r
260 /**\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
265  */\r
266 STATIC INLINE uint32_t IP_SSP_GetIntStatus(IP_SSP_001_T *pSSP)\r
267 {\r
268         return pSSP->MIS;\r
269 }\r
270 \r
271 /**\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
275  *                                              - SSP_RORRIS\r
276  *                                              - SSP_RTRIS\r
277  *                                              - SSP_RXRIS\r
278  *                                              - SSP_TXRIS\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
281  */\r
282 STATIC INLINE IntStatus IP_SSP_GetRawIntStatus(IP_SSP_001_T *pSSP, IP_SSP_RAWINTSTATUS_T RawInt)\r
283 {\r
284         return (pSSP->RIS & RawInt) ? SET : RESET;\r
285 }\r
286 \r
287 /**\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
292  */\r
293 STATIC INLINE uint8_t IP_SSP_GetDataSize(IP_SSP_001_T *pSSP)\r
294 {\r
295         return SSP_CR0_DSS(pSSP->CR0);\r
296 }\r
297 \r
298 /**\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
302  *                                              - SSP_RORIC\r
303  *                                              - SSP_RTIC\r
304  * @return       Nothing\r
305  * @note        Software can clear one or more interrupt condition(s) in the SSP controller\r
306  */\r
307 STATIC INLINE void IP_SSP_ClearIntPending(IP_SSP_001_T *pSSP, IP_SSP_INTCLEAR_T IntClear)\r
308 {\r
309         pSSP->ICR = IntClear;\r
310 }\r
311 \r
312 /**\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
316  *                                                      - SSP_RORIM\r
317  *                                                      - SSP_RTIM\r
318  *                                                      - SSP_RXIM\r
319  *                                                      - SSP_TXIM\r
320  * @return       Nothing\r
321  */\r
322 STATIC INLINE void IP_SSP_Int_Enable(IP_SSP_001_T *pSSP, IP_SSP_INTMASK_T IntType)\r
323 {\r
324         pSSP->IMSC |= IntType;\r
325 }\r
326 \r
327 /**\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
331  *                                                      - SSP_RORIM\r
332  *                                                      - SSP_RTIM\r
333  *                                                      - SSP_RXIM\r
334  *                                                      - SSP_TXIM\r
335  * @return       Nothing\r
336  */\r
337 STATIC INLINE void IP_SSP_Int_Disable(IP_SSP_001_T *pSSP, IP_SSP_INTMASK_T IntType)\r
338 {\r
339         pSSP->IMSC &= (~IntType);\r
340 }\r
341 \r
342 /**\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
346  */\r
347 STATIC INLINE uint16_t IP_SSP_ReceiveFrame(IP_SSP_001_T *pSSP)\r
348 {\r
349         return (uint16_t) (SSP_DR_BITMASK(pSSP->DR));\r
350 }\r
351 \r
352 /**\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
356  * @return       Nothing\r
357  */\r
358 STATIC INLINE void IP_SSP_SendFrame(IP_SSP_001_T *pSSP, uint16_t tx_data)\r
359 {\r
360         pSSP->DR = SSP_DR_BITMASK(tx_data);\r
361 }\r
362 \r
363 /**\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
368  * @return       Nothing\r
369  * @note        The bit frequency is PCLK / (prescale x[clk_rate+1])\r
370  */\r
371 void IP_SSP_Set_ClockRate(IP_SSP_001_T *pSSP, uint32_t clk_rate, uint32_t prescale);\r
372 \r
373 /**\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
386  * @return       Nothing\r
387  * @note        Note: The clockFormat is only used in SPI mode\r
388  */\r
389 STATIC INLINE void IP_SSP_SetFormat(IP_SSP_001_T *pSSP, uint32_t bits, uint32_t frameFormat, uint32_t clockMode)\r
390 {\r
391         pSSP->CR0 = (pSSP->CR0 & ~0xFF) | bits | frameFormat | clockMode;\r
392 }\r
393 \r
394 /**\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
399  *                                              - SSP_MODE_SLAVE\r
400  * @return       Nothing\r
401  */\r
402 STATIC INLINE void IP_SSP_Set_Mode(IP_SSP_001_T *pSSP, uint32_t mode)\r
403 {\r
404         pSSP->CR1 = (pSSP->CR1 & ~(1 << 2)) | mode;\r
405 }\r
406 \r
407 #if !defined(CHIP_LPC110X) && !defined(CHIP_LPC11XXLV) && !defined(CHIP_LPC11AXX) && \\r
408         !defined(CHIP_LPC11CXX) && !defined(CHIP_LPC11EXX) && !defined(CHIP_LPC11UXX)\r
409 /**\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
413  *                                                      - SSP_DMA_RX\r
414  *                                                      - SSP_DMA_TX\r
415  * @return       Nothing\r
416  */\r
417 STATIC INLINE void IP_SSP_DMA_Enable(IP_SSP_001_T *pSSP, IP_SSP_DMA_T flag)\r
418 {\r
419         pSSP->DMACR |= flag;\r
420 }\r
421 \r
422 /**\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
426  *                                                      - SSP_DMA_RX\r
427  *                                                      - SSP_DMA_TX\r
428  * @return       Nothing\r
429  */\r
430 STATIC INLINE void IP_SSP_DMA_Disable(IP_SSP_001_T *pSSP, IP_SSP_DMA_T flag)\r
431 {\r
432         pSSP->DMACR &= ~flag;\r
433 }\r
434 \r
435 #endif\r
436 \r
437 /**\r
438  * @}\r
439  */\r
440 \r
441 #ifdef __cplusplus\r
442 }\r
443 #endif\r
444 \r
445 #endif /* __SSP_001_H_ */\r