PKP
VS1000 P
ROGRAMMER
’
S
G
UIDE
VSMPG
/// Read a block from EEPROM
///
\
param blockn number of 512-byte sector 0..32767
///
\
param dptr pointer to data block
u_int16 EEReadBlock(u_int16 blockn, u_int16 *dptr) {
EEWaitGetStatus();
// Wait until EEPROM is not busy
SPI_MASTER_8BIT_CSLO;
// Bring xCS low
SpiSendReceive(SPI_EEPROM_COMMAND_READ);
SpiSendReceive(blockn7);
// Address[23:16] = blockn[14:7]
SpiSendReceive((blockn1)&0xff);
// Address[15:8] = blockn[6:0]0
SpiSendReceive(0);
// Address[7:0]
= 00000000
SPI_MASTER_16BIT_CSLO;
// Switch to 16-bit mode
{ int n;
for (n=0; n<256; n++){
*dptr++ = SpiSendReceive(0);
// Receive Data
}
}
SPI_MASTER_8BIT_CSHI;
// Bring xCS back to high
return 0;
}
// Disk image is prommed to EEPROM at sector 0x80 onwards, leaving
// the first 64 kilobytes (1 erasable block) free for boot code
#define FAT_START_SECTOR 0x80
// This function will replace ReadDiskSector() functionality
auto u_int16 MyReadDiskSector(register __i0 u_int16 *buffer,
register __a u_int32 sector) {
PERIP(GPIO1_MODE) |= 0x1f;
// Set SPI pins to be peripheral controlled
EEReadBlock(FAT_START_SECTOR, buffer);
return 0;
}
// Initialize SPI and hook in own disk read function.
// This example plays ogg files from a FAT image that has been
// previously written to a serial EEPROM.
void main(void) {
InitSpi();
// Hook in own disk sector read function
SetHookFunction((u_int16)ReadDiskSector, MyReadDiskSector);
} // Return to ROM code. Player will now play from EEPROM
Rev. 0.20
2011-10-04
Page