diff --git a/SD/Sd2Card.c b/SD/Sd2Card.c index 1e5179d8e71ac4c6ac52a3e0b41099aeeaa29eec..daeea8210b3af507e17f639ee501288c91dabf8e 100644 --- a/SD/Sd2Card.c +++ b/SD/Sd2Card.c @@ -294,7 +294,7 @@ info->partialBlockRead_ = value; */ uint8_t readData(SD_info *info, uint32_t block, uint16_t offset, uint16_t count, uint8_t* dst) { if(count==0) return true; -if((count+offset)>256){ goto fail; } +if((count+offset)>512){ goto fail; } if(!info->inBlock_||block!=info->block_||offset<info->offset_){ info->block_=block; // use address if not SDHC card @@ -315,7 +315,7 @@ uint16_t i; for(i=0;i<count;i++) dst[i]=spi_exch(0xff); info->offset_ += count; -if(!info->partialBlockRead_||info->offset_>=256){ +if(!info->partialBlockRead_||info->offset_>=512){ // read rest of data, checksum and set chip select high readEnd(info); } @@ -337,15 +337,15 @@ return false; * the value zero, false, is returned for failure. */ uint8_t readBlockSD(SD_info *info, uint32_t block, uint8_t* dst) { -return readData(info, block, 0, 256, dst); +return readData(info, block, 0, 512, dst); } -/* + //------------------------------------------------------------------------------ // send one block of data for write block or write multiple blocks static uint8_t writeData_(SD_info *info, uint8_t token, const uint8_t* src) { spi_exch(token); uint16_t i; -for(i=0;i<256;i++) spi_exch(src[i]); +for(i=0;i<512;i++) spi_exch(src[i]); spi_exch(0xff); // dummy crc spi_exch(0xff); // dummy crc info->status_=spi_exch(0xff); @@ -356,28 +356,6 @@ if((info->status_&DATA_RES_MASK)!=DATA_RES_ACCEPTED){ } return true; } -*/ - -static uint8_t writeData_(SD_info *info, uint8_t token, uint16_t offset, uint16_t count, const uint8_t* src) { - spi_exch(token); - uint16_t i; - if(count==0) return true; - if((count+offset)>256){ goto fail; } - for (i = offset; i < 256; i++) { - spi_exch(src[i-offset]); //on prend en compte l'offset quand on lit la source - } - spi_exch(0xff); // dummy crc - spi_exch(0xff); // dummy crc - info->status_ = spi_exch(0xff); - if ((info->status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) { - error(info, SD_CARD_ERROR_WRITE); - chipSelectHigh(); - return false; - } - return true; -} - - //------------------------------------------------------------------------------ /** Write one data block in a multiple block write sequence */ diff --git a/SD/picofs.c b/SD/picofs.c index 3d7c93a93c7dca3af6d88e27b2d386ec1e326837..21c41bac92ced51717250d3a95f6053632455b2b 100644 --- a/SD/picofs.c +++ b/SD/picofs.c @@ -12,8 +12,8 @@ #define CHUNK_SIZE 64 - -#define BLOCK_SIZE 256 +#define BLOC_NO 16 +#define BLOCK_SIZE 512 #define MAX_FILENAME_LENGTH 16 #define MAX_BLOCKS_PER_FILE 16 #define MAX_FILES_IN_DIRECTORY 64 @@ -22,22 +22,20 @@ #define MAX_BLOCKS_PER_FILE_DESCRIPTION 16 #define FIRST_DATA_BLOCK 1040 -//pour writeData -#define TOKEN - void readBlock(SD_info *sd, unsigned int num, int offset, unsigned char *storage, int size) { //lire à un endroit spécifique du bloc de la carte SD - - readData(sd,num,offset, size, storage); + //uint8_t * buffer_storage; + //readData(sd,num,offset, size, buffer_storage); + //storage = (unsigned char *)buffer_storage; } void writeBlock(SD_info *sd, unsigned int num, int offset, const unsigned char *storage, int size) { //écrire à un endroit spécifique du bloc de la carte SD - writeData(sd,TOKEN,offset,size,storage); - + // writeBlockSD(sd,num,offset,size, (uint8_t *)storage); + } @@ -471,7 +469,7 @@ void CP(SD_info *sd, const char *source_filename, const char *destination_filena int main(int argc, char *argv[]) { #ifdef TEST_WRITE - uint8_t blocW[BLOCK_SIZE]={0xac,0xbc,0xcc}; + uint8_t blocW[BLOCK_SIZE]={0xaa,0xbb,0xcc}; #endif #ifdef TEST_READ uint8_t blocR[BLOCK_SIZE]; @@ -490,26 +488,23 @@ int main(int argc, char *argv[]) { uint32_t size=cardSize(&sd); printf("taille=%ld\n",size); #endif - #ifdef TEST_WRITE - int statutWrite=writeBlockSD(&sd,16,blocW); //écriture dans bloc 16 - #endif + int statutWrite=writeBlockSD(&sd,BLOC_NO,blocW); #ifdef DEBUG - printf("statutWrite=%x\n",statutWrite); + printf("writeStatus=%x\n",statutWrite); #endif - - - #ifdef TEST_READ - int statutRead=readBlockSD(&sd,16,blocR); #endif + #ifdef TEST_READ + int statutRead=readBlockSD(&sd,BLOC_NO,blocR); #ifdef DEBUG - printf("statutRead=%x\n",statutRead); + printf("readstatus=%x\n",statutRead); int i; - for(i=0;i<3;i++) printf("blocR[%d]=%x ",i,blocR[i]); + for(i=0;i<3;i++) printf("bloc[%d]=%x ",i,blocR[i]); printf("\n"); #endif - - return 0; + #endif + return 0; + // // Vérification du nombre d'arguments // if (argc < 3) { // printf("Usage: %s filesystem_path ACTION [arguments...]\n", argv[0]);