spaces removal - fs

pull/339/head
0xc0170 2014-05-29 15:39:05 +02:00
parent f09322274a
commit a5e0dea136
5 changed files with 43 additions and 43 deletions

View File

@ -14,7 +14,7 @@ using namespace mbed;
DSTATUS disk_initialize (
BYTE drv /* Physical drive nmuber (0..) */
)
)
{
debug_if(FFS_DBG, "disk_initialize on drv [%d]\n", drv);
return (DSTATUS)FATFileSystem::_ffs[drv]->disk_initialize();
@ -22,7 +22,7 @@ DSTATUS disk_initialize (
DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
)
)
{
debug_if(FFS_DBG, "disk_status on drv [%d]\n", drv);
return (DSTATUS)FATFileSystem::_ffs[drv]->disk_status();

View File

@ -38,13 +38,13 @@ int FATFileHandle::close() {
ssize_t FATFileHandle::write(const void* buffer, size_t length) {
UINT n;
FRESULT res = f_write(&_fh, buffer, length, &n);
if (res) {
if (res) {
debug_if(FFS_DBG, "f_write() failed: %d", res);
return -1;
}
return n;
}
ssize_t FATFileHandle::read(void* buffer, size_t length) {
debug_if(FFS_DBG, "read(%d)\n", length);
UINT n;

View File

@ -69,7 +69,7 @@ FileHandle *FATFileSystem::open(const char* name, int flags) {
debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%d]\n", name, _name, _fsid);
char n[64];
sprintf(n, "%d:/%s", _fsid, name);
/* POSIX flags -> FatFS open mode */
BYTE openmode;
if (flags & O_RDWR) {
@ -86,10 +86,10 @@ FileHandle *FATFileSystem::open(const char* name, int flags) {
openmode |= FA_OPEN_ALWAYS;
}
}
FIL fh;
FRESULT res = f_open(&fh, n, openmode);
if (res) {
if (res) {
debug_if(FFS_DBG, "f_open('w') failed: %d\n", res);
return NULL;
}
@ -98,10 +98,10 @@ FileHandle *FATFileSystem::open(const char* name, int flags) {
}
return new FATFileHandle(fh);
}
int FATFileSystem::remove(const char *filename) {
FRESULT res = f_unlink(filename);
if (res) {
if (res) {
debug_if(FFS_DBG, "f_unlink() failed: %d\n", res);
return -1;
}

View File

@ -153,13 +153,13 @@ int SDFileSystem::initialise_card() {
for (int i = 0; i < 16; i++) {
_spi.write(0xFF);
}
// send CMD0, should return with all zeros except IDLE STATE set (bit 0)
if (_cmd(0, 0) != R1_IDLE_STATE) {
debug("No disk, or could not put SD card in to SPI idle state\n");
return SDCARD_FAIL;
}
// send CMD8 to determine whther it is ver 2.x
int r = _cmd8();
if (r == R1_IDLE_STATE) {
@ -181,7 +181,7 @@ int SDFileSystem::initialise_card_v1() {
return SDCARD_V1;
}
}
debug("Timeout waiting for v1.x card\n");
return SDCARD_FAIL;
}
@ -198,7 +198,7 @@ int SDFileSystem::initialise_card_v2() {
return SDCARD_V2;
}
}
debug("Timeout waiting for v2.x card\n");
return SDCARD_FAIL;
}
@ -211,7 +211,7 @@ int SDFileSystem::disk_initialize() {
}
debug_if(SD_DBG, "init card = %d\n", _is_initialized);
_sectors = _sd_sectors();
// Set block length to 512 (CMD16)
if (_cmd(16, 512) != 0) {
debug("Set 512-byte block timed out\n");
@ -232,7 +232,7 @@ int SDFileSystem::disk_write(const uint8_t *buffer, uint64_t block_number) {
if (_cmd(24, block_number * cdv) != 0) {
return 1;
}
// send the data block
_write(buffer, 512);
return 0;
@ -247,7 +247,7 @@ int SDFileSystem::disk_read(uint8_t *buffer, uint64_t block_number) {
if (_cmd(17, block_number * cdv) != 0) {
return 1;
}
// receive the data
_read(buffer, 512);
return 0;
@ -269,7 +269,7 @@ uint64_t SDFileSystem::disk_sectors() { return _sectors; }
// PRIVATE FUNCTIONS
int SDFileSystem::_cmd(int cmd, int arg) {
_cs = 0;
// send a command
_spi.write(0x40 | cmd);
_spi.write(arg >> 24);
@ -277,7 +277,7 @@ int SDFileSystem::_cmd(int cmd, int arg) {
_spi.write(arg >> 8);
_spi.write(arg >> 0);
_spi.write(0x95);
// wait for the repsonse (response[7] == 0)
for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) {
int response = _spi.write(0xFF);
@ -293,7 +293,7 @@ int SDFileSystem::_cmd(int cmd, int arg) {
}
int SDFileSystem::_cmdx(int cmd, int arg) {
_cs = 0;
// send a command
_spi.write(0x40 | cmd);
_spi.write(arg >> 24);
@ -301,7 +301,7 @@ int SDFileSystem::_cmdx(int cmd, int arg) {
_spi.write(arg >> 8);
_spi.write(arg >> 0);
_spi.write(0x95);
// wait for the repsonse (response[7] == 0)
for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) {
int response = _spi.write(0xFF);
@ -318,7 +318,7 @@ int SDFileSystem::_cmdx(int cmd, int arg) {
int SDFileSystem::_cmd58() {
_cs = 0;
int arg = 0;
// send a command
_spi.write(0x40 | 58);
_spi.write(arg >> 24);
@ -326,7 +326,7 @@ int SDFileSystem::_cmd58() {
_spi.write(arg >> 8);
_spi.write(arg >> 0);
_spi.write(0x95);
// wait for the repsonse (response[7] == 0)
for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) {
int response = _spi.write(0xFF);
@ -347,7 +347,7 @@ int SDFileSystem::_cmd58() {
int SDFileSystem::_cmd8() {
_cs = 0;
// send a command
_spi.write(0x40 | 8); // CMD8
_spi.write(0x00); // reserved
@ -355,7 +355,7 @@ int SDFileSystem::_cmd8() {
_spi.write(0x01); // 3.3v
_spi.write(0xAA); // check pattern
_spi.write(0x87); // crc
// wait for the repsonse (response[7] == 0)
for (int i = 0; i < SD_COMMAND_TIMEOUT * 1000; i++) {
char response[5];
@ -376,17 +376,17 @@ int SDFileSystem::_cmd8() {
int SDFileSystem::_read(uint8_t *buffer, uint32_t length) {
_cs = 0;
// read until start byte (0xFF)
while (_spi.write(0xFF) != 0xFE);
// read data
for (uint32_t i = 0; i < length; i++) {
buffer[i] = _spi.write(0xFF);
}
_spi.write(0xFF); // checksum
_spi.write(0xFF);
_cs = 1;
_spi.write(0xFF);
return 0;
@ -394,29 +394,29 @@ int SDFileSystem::_read(uint8_t *buffer, uint32_t length) {
int SDFileSystem::_write(const uint8_t*buffer, uint32_t length) {
_cs = 0;
// indicate start of block
_spi.write(0xFE);
// write the data
for (uint32_t i = 0; i < length; i++) {
_spi.write(buffer[i]);
}
// write the checksum
_spi.write(0xFF);
_spi.write(0xFF);
// check the response token
if ((_spi.write(0xFF) & 0x1F) != 0x05) {
_cs = 1;
_spi.write(0xFF);
return 1;
}
// wait for write to finish
while (_spi.write(0xFF) == 0);
_cs = 1;
_spi.write(0xFF);
return 0;
@ -440,33 +440,33 @@ uint64_t SDFileSystem::_sd_sectors() {
uint32_t block_len, mult, blocknr, capacity;
uint32_t hc_c_size;
uint64_t blocks;
// CMD9, Response R2 (R1 byte + 16-byte block read)
if (_cmdx(9, 0) != 0) {
debug("Didn't get a response from the disk\n");
return 0;
}
uint8_t csd[16];
if (_read(csd, 16) != 0) {
debug("Couldn't read csd response from disk\n");
return 0;
}
// csd_structure : csd[127:126]
// c_size : csd[73:62]
// c_size_mult : csd[49:47]
// read_bl_len : csd[83:80] - the *maximum* read block length
int csd_structure = ext_bits(csd, 127, 126);
switch (csd_structure) {
case 0:
cdv = 512;
c_size = ext_bits(csd, 73, 62);
c_size_mult = ext_bits(csd, 49, 47);
read_bl_len = ext_bits(csd, 83, 80);
block_len = 1 << read_bl_len;
mult = 1 << (c_size_mult + 2);
blocknr = (c_size + 1) * mult;
@ -474,14 +474,14 @@ uint64_t SDFileSystem::_sd_sectors() {
blocks = capacity / 512;
debug_if(SD_DBG, "\n\rSDCard\n\rc_size: %d \n\rcapacity: %ld \n\rsectors: %lld\n\r", c_size, capacity, blocks);
break;
case 1:
cdv = 1;
hc_c_size = ext_bits(csd, 63, 48);
blocks = (hc_c_size+1)*1024;
debug_if(SD_DBG, "\n\rSDHC Card \n\rhc_c_size: %d\n\rcapacity: %lld \n\rsectors: %lld\n\r", hc_c_size, blocks*512, blocks);
break;
default:
debug("CSD struct unsupported\r\n");
return 0;

View File

@ -33,7 +33,7 @@
* #include "SDFileSystem.h"
*
* SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs
*
*
* int main() {
* FILE *fp = fopen("/sd/myfile.txt", "w");
* fprintf(fp, "Hello World!\n");
@ -68,7 +68,7 @@ protected:
int initialise_card();
int initialise_card_v1();
int initialise_card_v2();
int _read(uint8_t * buffer, uint32_t length);
int _write(const uint8_t *buffer, uint32_t length);
uint64_t _sd_sectors();