1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-04-26 12:27:47 +00:00

Tests with SD card emulation

This commit is contained in:
harbaum
2014-08-28 09:23:45 +00:00
parent c3508f9c9b
commit 9a76ad2e0e
3 changed files with 133 additions and 6 deletions

18
menu.c
View File

@@ -351,7 +351,7 @@ void HandleUI(void)
/******************************************************************/
case MENU_8BIT_MAIN1: {
char entry=1;
char entry=0;
menumask=0;
// string at first index is the core name
@@ -362,12 +362,12 @@ void HandleUI(void)
// check if there's a file type supported
p = user_io_8bit_get_string(1);
if(p && strlen(p)) {
menumask = (menumask << 1) | 1;
entry = 1;
menumask = 1;
strcpy(s, " Load *.");
strcat(s, p);
OsdWrite(0, s, menusub==0, 0);
} else
OsdWrite(0, " No file I/O", 0,1);
}
// add options as requested by core
i = 2;
@@ -430,16 +430,22 @@ void HandleUI(void)
if (menu)
menustate = MENU_NONE1;
if(select) {
p = user_io_8bit_get_string(1+menusub);
char fs_present;
p = user_io_8bit_get_string(1);
fs_present = p && strlen(p);
// entry 0 = file selector
if(!menusub) {
if(!menusub && fs_present) {
p = user_io_8bit_get_string(1);
// use a local copy of "p" since SelectFile will destroy the buffer behind it
static char ext[4];
strncpy(ext, p, 4);
while(strlen(ext) < 3) strcat(ext, " ");
SelectFile(ext, SCAN_DIR | SCAN_LFN, MENU_8BIT_MAIN_FILE_SELECTED, MENU_8BIT_MAIN1, 1);
} else {
p = user_io_8bit_get_string(menusub + (fs_present?1:2));
// determine which status bit is affected
unsigned char mask = 1<<(p[1]-'0');
unsigned char status = user_io_8bit_set_status(0,0); // 0,0 gets status

119
user_io.c
View File

@@ -230,6 +230,26 @@ void user_io_eth_send_mac(uint8_t *mac) {
DisableIO();
}
// read 8+32 bit sd card status word from FPGA
uint8_t user_io_sd_get_status(uint32_t *lba) {
uint32_t s;
uint8_t c;
EnableIO();
SPI(UIO_GET_SDSTAT);
c = SPI(0);
s = SPI(0);
s = (s<<8) | SPI(0);
s = (s<<8) | SPI(0);
s = (s<<8) | SPI(0);
DisableIO();
if(lba)
*lba = s;
return c;
}
// read 32 bit ethernet status word from FPGA
uint32_t user_io_eth_get_status(void) {
uint32_t s;
@@ -452,6 +472,15 @@ char *user_io_8bit_get_string(char index) {
return buffer;
}
uint8_t checksum(uint8_t *buffer) {
int i;
uint8_t sum=0;
for(i=0;i<512;i++)
sum += buffer[i];
return sum;
}
unsigned char user_io_8bit_set_status(unsigned char new_status, unsigned char mask) {
static unsigned char status = 0;
@@ -606,6 +635,96 @@ void user_io_poll() {
}
if(core_type == CORE_TYPE_8BIT) {
unsigned char c = 1, f;
// check for serial data to be sent
// check for incoming serial data. this is directly forwarded to the
// arm rs232 and mixes with debug output. Useful for debugging only of
// e.g. the diagnostic cartridge
EnableIO();
SPI(UIO_SERIAL_IN);
// status byte is 1000000A with A=1 if data is available
if((f = SPI(0)) == 0x81) {
iprintf("\033[1;36m");
// character 0xff is returned if FPGA isn't configured
while((f == 0x81) && (c!= 0xff) && (c != 0x00)) {
c = SPI(0);
if(c != 0xff && c != 0x00) {
iprintf("%c", c);
f = SPI(0);
}
}
iprintf("\033[0m");
}
DisableIO();
// sd card emulation
{
static char buffer[512];
static uint32_t buffer_lba = 0xffffffff;
static uint8_t buffer_chk;
uint32_t lba;
uint8_t c = user_io_sd_get_status(&lba);
// valid sd commands start with "5x" to avoid problems with
// cores that don't implement this command
if((c & 0xf0) == 0x50) {
if((c & 0x03) == 0x01) {
// iprintf("%s sector read %ld\n", (c&0x04)?"SDHC":"SD", lba);
// sector read
// read sector from sd card if it is not already present in
// the buffer
if(buffer_lba != lba) {
DISKLED_ON;
if(MMC_Read(lba, buffer)) {
buffer_lba = lba;
buffer_chk = checksum(buffer);
}
DISKLED_OFF;
}
#if 0
// verify by re-read
{ char buf2[512];
if(MMC_Read(lba, buf2)) {
if(memcmp(buffer, buf2, 512) != 0)
iprintf("verify error lba %d\n", lba);
} else
iprintf("read error lba %d\n", lba);
}
#endif
if(buffer_lba == lba) {
// data is now stored in buffer. send it to fpga
EnableIO();
SPI(UIO_SECTOR_RD);
SPI_block_write(buffer);
SPI(buffer_chk);
DisableIO();
// the end of this transfer acknowledges the FPGA internal
// sd card emulation
// read status byte incl the checksum verification bit
c = user_io_sd_get_status(NULL);
if(!(c & 0x08)) iprintf("checksum failure in lbs %d\n", lba);
}
// just load the next sector now, so it may be prefetched
// for the next request already
DISKLED_ON;
if(MMC_Read(lba+1, buffer)) {
buffer_lba = lba+1;
buffer_chk = checksum(buffer);
}
DISKLED_OFF;
}
}
}
// raw sector io for the atari800 core which include a full
// file system driver usually implemented using a second cpu
static unsigned long bit8_status = 0;

View File

@@ -41,6 +41,8 @@
// codes as currently used by 8bit only
#define UIO_GET_STRING 0x14
#define UIO_SET_STATUS 0x15
#define UIO_GET_SDSTAT 0x16 // read status of sd card emulation
#define UIO_SECTOR_RD 0x17
// codes as used by 8bit (atari 800, zx81) via SS2
#define UIO_GET_STATUS 0x50