5 #define SPI_SCI2_SMR ((volatile uint8 *)0xFFFFC0)
6 #define SPI_SCI2_BRR ((volatile uint8 *)0xFFFFC1)
7 #define SPI_SCI2_SCR ((volatile uint8 *)0xFFFFC2)
8 #define SPI_SCI2_TDR ((volatile uint8 *)0xFFFFC3)
9 #define SPI_SCI2_SSR ((volatile uint8 *)0xFFFFC4)
10 #define SPI_SCI2_RDR ((volatile uint8 *)0xFFFFC5)
11 #define SPI_SCI2_SCMR ((volatile uint8 *)0xFFFFC6)
13 #define SSR_BIT_TDRE (1 << 7)
14 #define SSR_BIT_RDRF (1 << 6)
15 #define SSR_BIT_ORER (1 << 5)
16 #define SSR_BIT_FER (1 << 4)
17 #define SSR_BIT_PER (1 << 3)
19 #define CK_H() do { *PORTCONF_PBDR |= PORTCONF_PBBIT_SCLK; } while (0) /* Set MMC SCLK "high" */
20 #define CK_L() do { *PORTCONF_PBDR &= ~PORTCONF_PBBIT_SCLK; } while (0) /* Set MMC SCLK "low" */
21 #define DI_H() do { *PORTCONF_PBDR |= PORTCONF_PBBIT_MOSI; } while (0) /* Set MMC DI "high" */
22 #define DI_L() do { *PORTCONF_PBDR &= ~PORTCONF_PBBIT_MOSI; } while (0) /* Set MMC DI "low" */
23 #define DO ((*PORTCONF_PBDR & PORTCONF_PBBIT_MISO) ? 1 : 0) /* Get MMC DO value (high:true, low:false) */
25 #define VS1011E_CTRL_H() do { *PORTCONF_P4DR |= PORTCONF_P4BIT_VSCCS; } while (0)
26 #define VS1011E_CTRL_L() do { *PORTCONF_P4DR &= ~PORTCONF_P4BIT_VSCCS; } while (0)
27 #define VS1011E_DATA_H() do { *PORTCONF_P4DR |= PORTCONF_P4BIT_VSDCS; } while (0)
28 #define VS1011E_DATA_L() do { *PORTCONF_P4DR &= ~PORTCONF_P4BIT_VSDCS; } while (0)
29 #define SDCARD_H() do { *PORTCONF_P4DR |= PORTCONF_P4BIT_SDCCS; } while (0) /* Set MMC CS "high" */
30 #define SDCARD_L() do { *PORTCONF_P4DR &= ~PORTCONF_P4BIT_SDCCS; } while (0) /* Set MMC CS "low" */
38 for (i = 0; i < 20; i++) { asm("nop;"); }
40 *SPI_SCI2_SCMR = 0xFA;
46 *SPI_SCI2_SSR &= ~(SSR_BIT_TDRE | SSR_BIT_ORER | SSR_BIT_FER | SSR_BIT_PER);
47 while (!(*SPI_SCI2_SSR & SSR_BIT_RDRF)) {
49 *SPI_SCI2_SSR &= ~(SSR_BIT_RDRF);
56 *SPI_SCI2_SSR &= ~(SSR_BIT_TDRE | SSR_BIT_ORER | SSR_BIT_FER | SSR_BIT_PER);
57 while (!(*SPI_SCI2_SSR & SSR_BIT_RDRF)) {
60 *SPI_SCI2_SSR &= ~(SSR_BIT_RDRF);
64 void spi_select(SpiTarget st)
68 case SpiTarget_VS1011E_CTRL:
71 case SpiTarget_VS1011E_DATA:
74 case SpiTarget_SDCARD:
80 void spi_deselect(void)