o cleanup debug

This commit is contained in:
david
2009-06-03 17:06:02 +02:00
parent dfcf4016b1
commit 3ecc61adf4
8 changed files with 116 additions and 26 deletions

View File

@@ -15,4 +15,7 @@
#define SHARED_SIZE 512
#define SHARED_ADDR 0x3f0000
#define SHARED_ADDR 0x3f0000
#undef MMIO_DEBUG
#undef FATFS_DEBUG

View File

@@ -55,11 +55,13 @@ DSTATUS disk_initialize (BYTE drv) {
lseek(fd,0,SEEK_SET);
image_addr = (BYTE*)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
#ifdef MMIO_DEBUG
printf("DISKIO::disk_initialize: Open Image (size %i) %p\n",size,image_addr);
#endif
if (image_addr == MAP_FAILED) {
close(fd);
perror("DISKIO::disk_initialize: Error mmapping the file");
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */
@@ -94,9 +96,13 @@ DRESULT disk_read (
DWORD offset = sector * 512;
int size = count * 512;
#ifdef MMIO_DEBUG
printf("DISKIO::disk_read: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size);
#endif
memcpy(buff,image_addr + offset,size);
#ifdef MMIO_DEBUG
printf("DISKIO::disk_read: done\n");
#endif
return RES_OK;
}
@@ -118,7 +124,9 @@ DRESULT disk_write (
DWORD offset = sector * 512;
int size = count * 512;
#ifdef MMIO_DEBUG
printf("disk_write: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size);
#endif
memcpy(image_addr + offset,buff,size);
return RES_OK;
}
@@ -143,17 +151,23 @@ DRESULT disk_ioctl (
switch (ctrl) {
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
#ifdef MMIO_DEBUG
printf("disk_ioctl: GET_SECTOR_COUNT\n");
#endif
ofs = 60; w = 2; n = 0;
break;
case GET_SECTOR_SIZE : /* Get sectors on the disk (WORD) */
#ifdef MMIO_DEBUG
printf("disk_ioctl: GET_SECTOR_SIZE\n");
#endif
*(WORD*)buff = 512;
return RES_OK;
case GET_BLOCK_SIZE : /* Get erase block size in sectors (DWORD) */
#ifdef MMIO_DEBUG
printf("disk_ioctl: GET_BLOCK_SIZE\n");
#endif
*(DWORD*)buff = 32;
return RES_OK;

View File

@@ -47,16 +47,22 @@ void FATFS::fetchMem() {
void FATFS::pushMem() {
for ( int i=0;i<SHARED_SIZE;i++){
bus.write(SHARED_ADDR + i,scratch_buffer[i]);
#ifdef FATFS_DEBUG
if ( i < 8)
printf("0x%02x ",scratch_buffer[i]);
#endif
}
#ifdef FATFS_DEBUG
printf("\n");
#endif
}
uint8 FATFS::mmio_read(unsigned addr) {
addr &= 0xffff;
if (addr == MMIO_RETVAL){
#ifdef FATFS_DEBUG
printf("FATFS::mmio_read retal=%i\n",retval);
#endif
return retval;
}
return cpu.regs.mdr;
@@ -64,36 +70,50 @@ uint8 FATFS::mmio_read(unsigned addr) {
void FATFS::mmio_write(unsigned addr, uint8 data) {
addr &= 0xffff;
#ifdef FATFS_DEBUG
printf("FATFS::mmio_write 0x%04x 0x%02x (%i)\n",addr,data,data);
#endif
if (addr == 0x3010){
switch(data){
case CMD_INIT:
#ifdef FATFS_DEBUG
printf("FATFS::mmio_write CMD_INIT \n");
#endif
command = CMD_INIT;
retval = disk_initialize(0);
break;
case CMD_READ:
#ifdef FATFS_DEBUG
printf("FATFS::mmio_write CMD_READ \n");
#endif
command = CMD_READ;
break;
case CMD_WRITE:
command = CMD_WRITE;
#ifdef FATFS_DEBUG
printf("FATFS::mmio_write CMD_WRITE \n");
#endif
break;
default:
command = CMD_NONE;
#ifdef FATFS_DEBUG
printf("FATFS::mmio_write CMD_NONE \n");
#endif
break;
}
fflush(stderr);
}
if (addr >= MMIO_SECTOR01 && addr <= MMIO_SECTOR04){
sector = data << ( (3 - ( addr - MMIO_SECTOR01)) << 3);
#ifdef FATFS_DEBUG
printf("FATFS::mmio_write set sector: byte=%i val=%i sector=%i \n",(3 - ( addr - MMIO_SECTOR01)),data,sector);
#endif
}
if (addr == MMIO_COUNT){
count = data;
#ifdef FATFS_DEBUG
printf("FATFS::mmio_write set count: count=%i \n",count);
#endif
if (command == CMD_READ) {
retval = disk_read (0, (BYTE*)scratch_buffer, sector, count);
if (!retval)
@@ -102,11 +122,15 @@ void FATFS::mmio_write(unsigned addr, uint8 data) {
fetchMem();
retval = disk_write (0, (BYTE*)scratch_buffer, sector, count);
} else{
#ifdef FATFS_DEBUG
printf("FATFS::mmio_write set offset: no command to trigger \n");
#endif
}
}
if (addr == MMIO_RETVAL){
#ifdef FATFS_DEBUG
printf("FATFS::mmio_write reg 0x3016 reset\n");
#endif
retval = STA_VOID;
}
}