23 #ifndef SSP_PRIVATE_H__ 24 #define SSP_PRIVATE_H__ 39 static inline void ssp_set_max_clock(
LPC_SSP_TypeDef *pSSP,
unsigned int max_clock_mhz)
41 unsigned int divider = 2;
49 while(max_clock_mhz < (cpuClockMhz / divider) && divider <= 254)
65 ssp_set_max_clock(pSSP, 1);
78 while(pSSP->
SR & (1 << 4));
88 const uint32_t rx_fifo_half_full_bitmask = (1 << 2);
89 const uint32_t spi_busy_bitmask = (1 << 4);
90 const int spi_fifo_size = 8;
91 const int spi_half_fifo_size = spi_fifo_size / 2;
93 char *dataOut = (
char*)data;
94 char *dataIn = (
char*)data;
97 if (len >= spi_fifo_size) {
98 pSSP->
DR = *dataOut++; pSSP->
DR = *dataOut++; pSSP->
DR = *dataOut++; pSSP->
DR = *dataOut++;
99 pSSP->
DR = *dataOut++; pSSP->
DR = *dataOut++; pSSP->
DR = *dataOut++; pSSP->
DR = *dataOut++;
102 len -= spi_fifo_size;
103 while (!(pSSP->
RIS & rx_fifo_half_full_bitmask));
104 *dataIn++ = pSSP->
DR; *dataIn++ = pSSP->
DR; *dataIn++ = pSSP->
DR; *dataIn++ = pSSP->
DR;
107 while(pSSP->
SR & spi_busy_bitmask);
108 *dataIn++ = pSSP->
DR; *dataIn++ = pSSP->
DR; *dataIn++ = pSSP->
DR; *dataIn++ = pSSP->
DR;
110 else if (len >= spi_half_fifo_size) {
111 pSSP->
DR = *dataOut++; pSSP->
DR = *dataOut++; pSSP->
DR = *dataOut++; pSSP->
DR = *dataOut++;
112 len -= spi_half_fifo_size;
113 while(pSSP->
SR & spi_busy_bitmask);
114 *dataIn++ = pSSP->
DR; *dataIn++ = pSSP->
DR; *dataIn++ = pSSP->
DR; *dataIn++ = pSSP->
DR;
117 pSSP->
DR = *dataOut++;
119 while(pSSP->
SR & spi_busy_bitmask);
120 *dataIn++ = pSSP->
DR;
unsigned int sys_get_cpu_clock()
Definition: sys_clock.cpp:377
__IO uint32_t CR0
Definition: LPC17xx.h:459
__IO uint32_t DR
Definition: LPC17xx.h:461
unsigned int unsigned int len
Definition: startup.cpp:197
__IO uint32_t CR1
Definition: LPC17xx.h:460
Definition: LPC17xx.h:457
__IO uint32_t CPSR
Definition: LPC17xx.h:463
This file provides the configurable parameters for your project.
CMSIS Cortex-M3 Core Peripheral Access Layer Header File for NXP LPC17xx Device Series.
__IO uint32_t RIS
Definition: LPC17xx.h:465
__I uint32_t SR
Definition: LPC17xx.h:462