ssp_11xx.h
Go to the documentation of this file.
1 /*
2  * @brief LPC11xx SSP Registers and control functions
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __SSP_11XX_H_
33 #define __SSP_11XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
47 typedef struct {
57 } LPC_SSP_T;
58 
64 #define SSP_CR0_DSS(n) ((uint32_t) ((n) & 0xF))
65 
66 #define SSP_CR0_FRF_SPI ((uint32_t) (0 << 4))
67 
68 #define SSP_CR0_FRF_TI ((uint32_t) (1 << 4))
69 
70 #define SSP_CR0_FRF_MICROWIRE ((uint32_t) (2 << 4))
71 
73 #define SSP_CR0_CPOL_LO ((uint32_t) (0))
74 #define SSP_CR0_CPOL_HI ((uint32_t) (1 << 6))
75 
77 #define SSP_CR0_CPHA_FIRST ((uint32_t) (0))
78 #define SSP_CR0_CPHA_SECOND ((uint32_t) (1 << 7))
79 
81 #define SSP_CR0_SCR(n) ((uint32_t) ((n & 0xFF) << 8))
82 
83 #define SSP_CR0_BITMASK ((uint32_t) (0xFFFF))
84 
85 #define SSP_CR0_BITMASK ((uint32_t) (0xFFFF))
86 
88 #define SSP_CR0_SCR(n) ((uint32_t) ((n & 0xFF) << 8))
89 
95 #define SSP_CR1_LBM_EN ((uint32_t) (1 << 0))
96 
97 #define SSP_CR1_SSP_EN ((uint32_t) (1 << 1))
98 
99 #define SSP_CR1_SLAVE_EN ((uint32_t) (1 << 2))
100 #define SSP_CR1_MASTER_EN ((uint32_t) (0))
101 
103 #define SSP_CR1_SO_DISABLE ((uint32_t) (1 << 3))
104 
105 #define SSP_CR1_BITMASK ((uint32_t) (0x0F))
106 
108 #define SSP_CPSR_BITMASK ((uint32_t) (0xFF))
109 
114 #define SSP_DR_BITMASK(n) ((n) & 0xFFFF)
115 
121 #define SSP_SR_BITMASK ((uint32_t) (0x1F))
122 
124 #define SSP_ICR_BITMASK ((uint32_t) (0x03))
125 
129 typedef enum _SSP_STATUS {
130  SSP_STAT_TFE = ((uint32_t)(1 << 0)),
131  SSP_STAT_TNF = ((uint32_t)(1 << 1)),
132  SSP_STAT_RNE = ((uint32_t)(1 << 2)),
133  SSP_STAT_RFF = ((uint32_t)(1 << 3)),
134  SSP_STAT_BSY = ((uint32_t)(1 << 4)),
135 } SSP_STATUS_T;
136 
140 typedef enum _SSP_INTMASK {
141  SSP_RORIM = ((uint32_t)(1 << 0)),
142  SSP_RTIM = ((uint32_t)(1 << 1)),
143  SSP_RXIM = ((uint32_t)(1 << 2)),
144  SSP_TXIM = ((uint32_t)(1 << 3)),
146 } SSP_INTMASK_T;
147 
151 typedef enum _SSP_MASKINTSTATUS {
152  SSP_RORMIS = ((uint32_t)(1 << 0)),
153  SSP_RTMIS = ((uint32_t)(1 << 1)),
154  SSP_RXMIS = ((uint32_t)(1 << 2)),
155  SSP_TXMIS = ((uint32_t)(1 << 3)),
158 
162 typedef enum _SSP_RAWINTSTATUS {
163  SSP_RORRIS = ((uint32_t)(1 << 0)),
164  SSP_RTRIS = ((uint32_t)(1 << 1)),
165  SSP_RXRIS = ((uint32_t)(1 << 2)),
166  SSP_TXRIS = ((uint32_t)(1 << 3)),
169 
170 typedef enum _SSP_INTCLEAR {
171  SSP_RORIC = 0x0,
172  SSP_RTIC = 0x1,
175 
176 /*
177  * @brief SSP clock format
178  */
179 typedef enum CHIP_SSP_CLOCK_FORMAT {
181  SSP_CLOCK_CPHA0_CPOL1 = (1u << 6),
182  SSP_CLOCK_CPHA1_CPOL0 = (2u << 6),
183  SSP_CLOCK_CPHA1_CPOL1 = (3u << 6),
189 
190 /*
191  * @brief SSP frame format
192  */
193 typedef enum CHIP_SSP_FRAME_FORMAT {
194  SSP_FRAMEFORMAT_SPI = (0 << 4),
198 
199 /*
200  * @brief Number of bits per frame
201  */
202 typedef enum CHIP_SSP_BITS {
203  SSP_BITS_4 = (3u << 0),
204  SSP_BITS_5 = (4u << 0),
205  SSP_BITS_6 = (5u << 0),
206  SSP_BITS_7 = (6u << 0),
207  SSP_BITS_8 = (7u << 0),
208  SSP_BITS_9 = (8u << 0),
209  SSP_BITS_10 = (9u << 0),
210  SSP_BITS_11 = (10u << 0),
211  SSP_BITS_12 = (11u << 0),
212  SSP_BITS_13 = (12u << 0),
213  SSP_BITS_14 = (13u << 0),
214  SSP_BITS_15 = (14u << 0),
215  SSP_BITS_16 = (15u << 0),
217 
218 /*
219  * @brief SSP config format
220  */
221 typedef struct SSP_ConfigFormat {
223  CHIP_SSP_CLOCK_MODE_T clockMode;
226 
233 {
234  pSSP->CR1 |= SSP_CR1_SSP_EN;
235 }
236 
243 {
244  pSSP->CR1 &= (~SSP_CR1_SSP_EN) & SSP_CR1_BITMASK;
245 }
246 
255 {
256  pSSP->CR1 |= SSP_CR1_LBM_EN;
257 }
258 
267 {
268  pSSP->CR1 &= (~SSP_CR1_LBM_EN) & SSP_CR1_BITMASK;
269 }
270 
283 {
284  return (pSSP->SR & Stat) ? SET : RESET;
285 }
286 
294 {
295  return pSSP->MIS;
296 }
297 
310 {
311  return (pSSP->RIS & RawInt) ? SET : RESET;
312 }
313 
321 {
322  return SSP_CR0_DSS(pSSP->CR0);
323 }
324 
335 {
336  pSSP->ICR = IntClear;
337 }
338 
345 {
346  pSSP->IMSC |= SSP_TXIM;
347 }
348 
355 {
356  pSSP->IMSC &= (~SSP_TXIM);
357 }
358 
365 {
366  return (uint16_t) (SSP_DR_BITMASK(pSSP->DR));
367 }
368 
376 {
377  pSSP->DR = SSP_DR_BITMASK(tx_data);
378 }
379 
388 void Chip_SSP_SetClockRate(LPC_SSP_T *pSSP, uint32_t clk_rate, uint32_t prescale);
389 
407 {
408  pSSP->CR0 = (pSSP->CR0 & ~0xFF) | bits | frameFormat | clockMode;
409 }
410 
420 {
421  pSSP->CR1 = (pSSP->CR1 & ~(1 << 2)) | mode;
422 }
423 
424 /*
425  * @brief SSP mode
426  */
427 typedef enum CHIP_SSP_MODE {
428  SSP_MODE_MASTER = (0 << 2),
429  SSP_MODE_SLAVE = (1u << 2),
431 
432 /*
433  * @brief SPI address
434  */
435 typedef struct {
438 } SPI_Address_t;
439 
440 /*
441  * @brief SSP data setup structure
442  */
443 typedef struct {
444  void *tx_data;
446  void *rx_data;
450 
453 #define SSP_CPHA_FIRST SSP_CR0_CPHA_FIRST
454 #define SSP_CPHA_SECOND SSP_CR0_CPHA_SECOND
455 
457 /* There's no bug here!!!
458  * - If bit[6] in SSPnCR0 is 0: SSP controller maintains the bus clock low between frames.
459  * That means the active clock is in HI state.
460  * - If bit[6] in SSPnCR0 is 1 (SSP_CR0_CPOL_HI): SSP controller maintains the bus clock
461  * high between frames. That means the active clock is in LO state.
462  */
463 #define SSP_CPOL_HI SSP_CR0_CPOL_LO
464 #define SSP_CPOL_LO SSP_CR0_CPOL_HI
465 
467 #define SSP_SLAVE_MODE SSP_CR1_SLAVE_EN
468 #define SSP_MASTER_MODE SSP_CR1_MASTER_EN
469 
476 
485 
494 
507 
519 
531 
537 void Chip_SSP_Init(LPC_SSP_T *pSSP);
538 
545 void Chip_SSP_DeInit(LPC_SSP_T *pSSP);
546 
553 void Chip_SSP_SetMaster(LPC_SSP_T *pSSP, bool master);
554 
561 void Chip_SSP_SetBitRate(LPC_SSP_T *pSSP, uint32_t bitRate);
562 
567 #ifdef __cplusplus
568 }
569 #endif
570 
571 #endif /* __SSP_11XX_H_ */
_SSP_INTCLEAR
Definition: ssp_11xx.h:170
std::uint8_t uint8_t
Definition: std.hpp:24
enum CHIP_SSP_BITS CHIP_SSP_BITS_T
STATIC INLINE IntStatus Chip_SSP_GetRawIntStatus(LPC_SSP_T *pSSP, SSP_RAWINTSTATUS_T RawInt)
Get the raw interrupt status.
Definition: ssp_11xx.h:309
STATIC INLINE void Chip_SSP_Enable(LPC_SSP_T *pSSP)
Enable SSP operation.
Definition: ssp_11xx.h:232
#define STATIC
Definition: lpc_types.h:140
uint32_t Chip_SSP_RWFrames_Blocking(LPC_SSP_T *pSSP, Chip_SSP_DATA_SETUP_T *xf_setup)
SSP Polling Read/Write in blocking mode.
#define SSP_CR0_DSS(n)
Definition: ssp_11xx.h:64
enum _SSP_STATUS SSP_STATUS_T
SSP Type of Status.
STATIC INLINE void Chip_SSP_Int_Enable(LPC_SSP_T *pSSP)
Enable interrupt for the SSP.
Definition: ssp_11xx.h:344
STATIC INLINE void Chip_SSP_Set_Mode(LPC_SSP_T *pSSP, uint32_t mode)
Set the SSP working as master or slave mode.
Definition: ssp_11xx.h:419
CHIP_SSP_BITS_T bits
Definition: ssp_11xx.h:222
uint8_t pin
Definition: ssp_11xx.h:437
#define SSP_CR1_LBM_EN
Definition: ssp_11xx.h:95
__IO uint32_t CR1
Definition: ssp_11xx.h:49
STATIC INLINE uint16_t Chip_SSP_ReceiveFrame(LPC_SSP_T *pSSP)
Get received SSP data.
Definition: ssp_11xx.h:364
__IO uint32_t CR0
Definition: ssp_11xx.h:48
_SSP_RAWINTSTATUS
SSP Type of Raw Interrupt Status.
Definition: ssp_11xx.h:162
STATIC INLINE FlagStatus Chip_SSP_GetStatus(LPC_SSP_T *pSSP, SSP_STATUS_T Stat)
Get the current status of SSP controller.
Definition: ssp_11xx.h:282
void Chip_SSP_Init(LPC_SSP_T *pSSP)
Initialize the SSP.
STATIC INLINE void Chip_SSP_Disable(LPC_SSP_T *pSSP)
Disable SSP operation.
Definition: ssp_11xx.h:242
CHIP_SSP_CLOCK_MODE_T clockMode
Definition: ssp_11xx.h:223
STATIC INLINE void Chip_SSP_ClearIntPending(LPC_SSP_T *pSSP, SSP_INTCLEAR_T IntClear)
Clear the corresponding interrupt condition(s) in the SSP controller.
Definition: ssp_11xx.h:334
__I uint32_t SR
Definition: ssp_11xx.h:51
__IO uint32_t IMSC
Definition: ssp_11xx.h:53
#define __I
Definition: core_cm0.h:151
enum CHIP_SSP_MODE CHIP_SSP_MODE_T
#define SSP_CR1_BITMASK
Definition: ssp_11xx.h:105
FlagStatus
Boolean Type definition.
Definition: lpc_types.h:62
uint32_t Chip_SSP_ReadFrames_Blocking(LPC_SSP_T *pSSP, uint8_t *buffer, uint32_t buffer_len)
SSP Polling Read in blocking mode.
_SSP_INTMASK
SSP Type of Interrupt Mask.
Definition: ssp_11xx.h:140
STATIC INLINE uint32_t Chip_SSP_GetIntStatus(LPC_SSP_T *pSSP)
Get the masked interrupt status.
Definition: ssp_11xx.h:293
#define __IO
Definition: core_cm0.h:154
void Chip_SSP_DeInit(LPC_SSP_T *pSSP)
Deinitialise the SSP.
Definition: lpc_types.h:62
CHIP_SSP_FRAME_FORMAT_T frameFormat
Definition: ssp_11xx.h:224
enum CHIP_SSP_CLOCK_FORMAT CHIP_SSP_CLOCK_MODE_T
_SSP_STATUS
SSP Type of Status.
Definition: ssp_11xx.h:129
CHIP_SSP_FRAME_FORMAT
Definition: ssp_11xx.h:193
__IO uint32_t DR
Definition: ssp_11xx.h:50
std::uint32_t uint32_t
Definition: std.hpp:26
void Chip_SSP_SetMaster(LPC_SSP_T *pSSP, bool master)
Set the SSP operating modes, master or slave.
__I uint32_t MIS
Definition: ssp_11xx.h:55
uint8_t port
Definition: ssp_11xx.h:436
STATIC INLINE void Chip_SSP_SetFormat(LPC_SSP_T *pSSP, uint32_t bits, uint32_t frameFormat, uint32_t clockMode)
Set up the SSP frame format.
Definition: ssp_11xx.h:406
void Chip_SSP_SetClockRate(LPC_SSP_T *pSSP, uint32_t clk_rate, uint32_t prescale)
Set up output clocks per bit for SSP bus.
#define SSP_DR_BITMASK(n)
Definition: ssp_11xx.h:114
#define INLINE
Definition: lpc_types.h:205
CHIP_SSP_CLOCK_FORMAT
Definition: ssp_11xx.h:179
Status
Definition: lpc_types.h:74
STATIC INLINE void Chip_SSP_EnableLoopBack(LPC_SSP_T *pSSP)
Enable loopback mode.
Definition: ssp_11xx.h:254
STATIC INLINE void Chip_SSP_SendFrame(LPC_SSP_T *pSSP, uint16_t tx_data)
Send SSP 16-bit data.
Definition: ssp_11xx.h:375
void Chip_SSP_SetBitRate(LPC_SSP_T *pSSP, uint32_t bitRate)
Set the clock frequency for SSP interface.
void Chip_SSP_Int_FlushData(LPC_SSP_T *pSSP)
Clean all data in RX FIFO of SSP.
STATIC INLINE void Chip_SSP_DisableLoopBack(LPC_SSP_T *pSSP)
Disable loopback mode.
Definition: ssp_11xx.h:266
__I uint32_t RIS
Definition: ssp_11xx.h:54
Status Chip_SSP_Int_RWFrames8Bits(LPC_SSP_T *pSSP, Chip_SSP_DATA_SETUP_T *xf_setup)
SSP Interrupt Read/Write with 8-bit frame width.
enum _SSP_RAWINTSTATUS SSP_RAWINTSTATUS_T
SSP Type of Raw Interrupt Status.
struct SSP_ConfigFormat SSP_ConfigFormat
SSP register block structure.
Definition: ssp_11xx.h:47
enum _SSP_MASKINTSTATUS SSP_MASKINTSTATUS_T
SSP Type of Mask Interrupt Status.
std::uint16_t uint16_t
Definition: std.hpp:25
enum _SSP_INTCLEAR SSP_INTCLEAR_T
_SSP_MASKINTSTATUS
SSP Type of Mask Interrupt Status.
Definition: ssp_11xx.h:151
enum _SSP_INTMASK SSP_INTMASK_T
SSP Type of Interrupt Mask.
#define __O
Definition: core_cm0.h:153
STATIC INLINE void Chip_SSP_Int_Disable(LPC_SSP_T *pSSP)
Disable interrupt for the SSP.
Definition: ssp_11xx.h:354
Status Chip_SSP_Int_RWFrames16Bits(LPC_SSP_T *pSSP, Chip_SSP_DATA_SETUP_T *xf_setup)
SSP Interrupt Read/Write with 16-bit frame width.
enum FlagStatus IntStatus
enum CHIP_SSP_FRAME_FORMAT CHIP_SSP_FRAME_FORMAT_T
#define SSP_CR1_SSP_EN
Definition: ssp_11xx.h:97
CHIP_SSP_MODE
Definition: ssp_11xx.h:427
uint32_t Chip_SSP_WriteFrames_Blocking(LPC_SSP_T *pSSP, uint8_t *buffer, uint32_t buffer_len)
SSP Polling Write in blocking mode.
__O uint32_t ICR
Definition: ssp_11xx.h:56
CHIP_SSP_BITS
Definition: ssp_11xx.h:202
__IO uint32_t CPSR
Definition: ssp_11xx.h:52
STATIC INLINE uint8_t Chip_SSP_GetDataSize(LPC_SSP_T *pSSP)
Get the number of bits transferred in each frame.
Definition: ssp_11xx.h:320


uavcan_communicator
Author(s):
autogenerated on Wed Jan 11 2023 03:59:39