Simon Ford / Mbed 2 deprecated WiiRacing

Dependencies:   mbed m3pi ID12RFIDIRQ

Committer:
simon
Date:
Mon Apr 11 23:03:22 2011 +0000
Revision:
0:e2ef12467862

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:e2ef12467862 1 #include "mbed.h"
simon 0:e2ef12467862 2 #include "FATFileSystem.h"
simon 0:e2ef12467862 3 #include "Utils.h"
simon 0:e2ef12467862 4
simon 0:e2ef12467862 5 int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
simon 0:e2ef12467862 6 int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
simon 0:e2ef12467862 7 int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
simon 0:e2ef12467862 8
simon 0:e2ef12467862 9 class USBFileSystem : public FATFileSystem
simon 0:e2ef12467862 10 {
simon 0:e2ef12467862 11 int _device;
simon 0:e2ef12467862 12 u32 _blockSize;
simon 0:e2ef12467862 13 u32 _blockCount;
simon 0:e2ef12467862 14
simon 0:e2ef12467862 15 public:
simon 0:e2ef12467862 16 USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0)
simon 0:e2ef12467862 17 {
simon 0:e2ef12467862 18 }
simon 0:e2ef12467862 19
simon 0:e2ef12467862 20 void SetDevice(int device)
simon 0:e2ef12467862 21 {
simon 0:e2ef12467862 22 _device = device;
simon 0:e2ef12467862 23 }
simon 0:e2ef12467862 24
simon 0:e2ef12467862 25 virtual int disk_initialize()
simon 0:e2ef12467862 26 {
simon 0:e2ef12467862 27 return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
simon 0:e2ef12467862 28 }
simon 0:e2ef12467862 29
simon 0:e2ef12467862 30 virtual int disk_write(const char *buffer, int block_number)
simon 0:e2ef12467862 31 {
simon 0:e2ef12467862 32 return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
simon 0:e2ef12467862 33 }
simon 0:e2ef12467862 34
simon 0:e2ef12467862 35 virtual int disk_read(char *buffer, int block_number)
simon 0:e2ef12467862 36 {
simon 0:e2ef12467862 37 return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
simon 0:e2ef12467862 38 }
simon 0:e2ef12467862 39
simon 0:e2ef12467862 40 virtual int disk_sectors()
simon 0:e2ef12467862 41 {
simon 0:e2ef12467862 42 return _blockCount;
simon 0:e2ef12467862 43 }
simon 0:e2ef12467862 44 };
simon 0:e2ef12467862 45
simon 0:e2ef12467862 46 void DumpFS(int depth, int count)
simon 0:e2ef12467862 47 {
simon 0:e2ef12467862 48 DIR *d = opendir("/usb");
simon 0:e2ef12467862 49 if (!d)
simon 0:e2ef12467862 50 {
simon 0:e2ef12467862 51 printf("USB file system borked\n");
simon 0:e2ef12467862 52 return;
simon 0:e2ef12467862 53 }
simon 0:e2ef12467862 54
simon 0:e2ef12467862 55 printf("\nDumping root dir\n");
simon 0:e2ef12467862 56 struct dirent *p;
simon 0:e2ef12467862 57 for(;;)
simon 0:e2ef12467862 58 {
simon 0:e2ef12467862 59 p = readdir(d);
simon 0:e2ef12467862 60 if (!p)
simon 0:e2ef12467862 61 break;
simon 0:e2ef12467862 62 int len = sizeof( dirent);
simon 0:e2ef12467862 63 printf("%s %d\n", p->d_name, len);
simon 0:e2ef12467862 64 }
simon 0:e2ef12467862 65 closedir(d);
simon 0:e2ef12467862 66 }
simon 0:e2ef12467862 67
simon 0:e2ef12467862 68 int OnDiskInsert(int device)
simon 0:e2ef12467862 69 {
simon 0:e2ef12467862 70 USBFileSystem fs;
simon 0:e2ef12467862 71 fs.SetDevice(device);
simon 0:e2ef12467862 72 DumpFS(0,0);
simon 0:e2ef12467862 73 return 0;
simon 0:e2ef12467862 74 }