// toggle the LED next to the display (labeled SD) static void SetLED(BOOLEAN On) { if (On) { WRITEREG32(FIO0CLR, SD_LED_BIT); } else { WRITEREG32(FIO0SET, SD_LED_BIT); } }
void rtc_intr_hdlr (void *data) { static u8 c = 33; static u8 hr = 0, min = 0, sec = 0; /* disable RTC interrupts till you process current interrupt * for this, set the interrupt mask bit for the RTC interrupt * - i.e, the 11th bit in MIR2, bits0-63 are in MIR0-1 -- TRM 6.3 & 6.5.1.31 */ WRITEREG32(INTC_MIR2_SET, 0x01 << 11); /* process the interrupt - print to uart an ascii chart * and system up time */ ++sec; if (sec >= 60) { sec = 0; ++min; if (min >= 60) { min = 0; ++hr; if (hr >= 24) { hr = 0; } } } hal_uart_putstr("RTC - "); hal_uart_putchar(hr/10 + '0'); hal_uart_putchar(hr%10 + '0'); hal_uart_putchar(':'); hal_uart_putchar(min/10 + '0'); hal_uart_putchar(min%10 + '0'); hal_uart_putchar(':'); hal_uart_putchar(sec/10 + '0'); hal_uart_putchar(sec%10 + '0'); hal_uart_putstr(" - "); hal_uart_putchar(c++); hal_uart_putchar('\n'); if (c > 126) c = 33; /* re-enable RTC interrupts */ WRITEREG32(INTC_MIR2_CLEAR, 0x01 << 11); }
/* SpiInit - initialize the SPI port */ static INT8U SpiInit(PSPI_DEVICE pDevice, INT32U ClockRate) { // pinsel0_P0 must be previously setup for SSP use. // set their direction WRITEREG32(FIO0DIR, (READREG32(FIO0DIR) | pDevice->PinSck | pDevice->PinMOSI) & ~pDevice->PinMISO); // set master mode, 8-bits, sample on first clock edge, no ints WRITEREG16(pDevice->pSSPnCR0, SSP_SPIMODE); SpiSetClock(pDevice, SPI_DEFAULT_CLOCK); //enable WRITEREG16(pDevice->pSSPnCR1, SSP_ENABLE); return OS_DRV_NO_ERR; }
/* Mp3Init - initialize the SPI port */ static INT8U Mp3Init(PMP3_EXT pContext, HANDLE hSpi) { const INT8U SetMode[] = {0x02, 0x00, 0x08, 0x00}; const INT8U SetClockF[] = {0x02, 0x03, 0x98, 0x00}; //?? const INT8U SetVol[] = {0x02, 0x0B, 0x20, 0x20}; const INT8U SetVol[] = {0x02, 0x0B, 0x00, 0x00}; INT8U buffer[4]; INT8U err; INT32U len; //setup the GPIO pin directions WRITEREG32(FIO0DIR, (READREG32(FIO0DIR) | MP3_CS_BIT | MP3_EEPROM_BIT | MP3_DCS_BIT | MP3_RESET_BIT) & ~MP3_DREQ_BIT); //no pullup DCS WRITEREG32(PINMODE1, (READREG32(PINMODE1) | (0x3 << 0))); #if 0 #define SCK0_BIT (1<<15) #define SCK0(x) ((x) ? WRITEREG32(FIO0CLR, SCK0_BIT) : WRITEREG32(FIO0SET, SCK0_BIT)) //test bits WRITEREG32(FIO0DIR, 0xFFFFFFFF); WRITEREG32(FIO0CLR, 0xFFFFFFFF); WRITEREG32(FIO0SET, 0xFFFFFFFF); WRITEREG32(FIO0CLR, 0xFFFFFFFF); WRITEREG32(FIO0SET, 0xFFFFFFFF); WRITEREG32(FIO0CLR, 0xFFFFFFFF); for (len = 0; len < 32; len++) { WRITEREG32(FIO0SET, (1<<len)); } WRITEREG32(FIO0SET, 0xFFFFFFFF); for (len = 0; len < 32; len++) { WRITEREG32(FIO0CLR, (1<<len)); } MP3_DCS(1); len = len; MP3_DCS(0); len = len; SCK0(1); len = len; SCK0(0); len = len; MP3_CS(1); len = len; MP3_CS(0); len = len; MP3_EEPROM(1); len = len; MP3_EEPROM(0); len = len; MP3_RESET(1); len = len; MP3_RESET(0); len = len; #endif //reset MP3_CS(0); MP3_EEPROM(1); // initialize the VS1002 chip MP3_RESET(1); OSTimeDly(2); MP3_RESET(0); //wait for ready while (!MP3_DREQ()); //program chip MP3_CS(1); len = sizeof(SetMode); memcpy(buffer, SetMode, len); err = Write(hSpi, buffer, &len); MP3_CS(0); if (err != OS_DRV_NO_ERR) { DEBUGMSG(TRUE, ("MP3_DRV failed to initilaize mode, err: %d\n\r", err)); return err; } OSTimeDly(2); MP3_CS(1); len = sizeof(SetClockF); memcpy(buffer, SetClockF, len); err = Write(hSpi, buffer, &len); MP3_CS(0); if (err != OS_DRV_NO_ERR) { DEBUGMSG(TRUE, ("MP3_DRV failed to initilaize ClockF, err: %d\n\r", err)); return err; } OSTimeDly(2); MP3_CS(1); len = sizeof(SetVol); memcpy(buffer, SetVol, len); err = Write(hSpi, buffer, &len); MP3_CS(0); if (err != OS_DRV_NO_ERR) { DEBUGMSG(TRUE, ("MP3_DRV failed to initilaize SetVol, err: %d\n\r", err)); return err; } OSTimeDly(2); return OS_DRV_NO_ERR; }