Skip to content
Snippets Groups Projects
Commit 7a79a977 authored by root's avatar root
Browse files

avancee fonction ecriture et lecture pico ordi

parent cd35b56c
No related branches found
No related tags found
No related merge requests found
...@@ -23,21 +23,35 @@ ...@@ -23,21 +23,35 @@
#define FIRST_DATA_BLOCK 1040 #define FIRST_DATA_BLOCK 1040
void readBlock(SD_info *sd, unsigned int num, int offset, unsigned char *storage, int size) { void readBlock(SD_info *sd, unsigned int numBlock, int offset, unsigned char *storage, int size) {
//lire à un endroit spécifique du bloc de la carte SD //lire à un endroit spécifique du bloc de la carte SD
//uint8_t * buffer_storage; uint8_t * buffer_read = malloc (sizeof(char)*BLOCK_SIZE);
//readData(sd,num,offset, size, buffer_storage); readData(sd,numBlock,offset, size, buffer_read);
//storage = (unsigned char *)buffer_storage; strcpy(storage,(unsigned char *)buffer_read);
free(buffer_read);
} }
void writeBlock(SD_info *sd, unsigned int num, int offset, const unsigned char *storage, int size) { void writeBlock(SD_info *sd, unsigned int numBlock, int offset, unsigned char *source, int size) {
//écrire à un endroit spécifique du bloc de la carte SD //écrire à un endroit spécifique du bloc de la carte SD
// writeBlockSD(sd,num,offset,size, (uint8_t *)storage); uint8_t * buffer_write = malloc (sizeof(char)*BLOCK_SIZE); //sauve les données du bloc
if(buffer_write == NULL) printf("erreur malloc write");
readData(sd, numBlock, 0, size, buffer_write);
if(offset + size > 512 )
{
printf("data to write is too big");
return;
}
for (int i = size - 1; i >= 0; i--) {
source[i + offset] = source[i];
}
// Ajouter les zéros au début de la chaîne
for (int j = 0; j < offset; j++) {
source[j] = buffer_write[j];
}
writeBlockSD(sd,numBlock, (uint8_t *)source);
free(buffer_write);
} }
void LS(SD_info *sd) { void LS(SD_info *sd) {
unsigned char buffer[MAX_FILENAME_LENGTH]; unsigned char buffer[MAX_FILENAME_LENGTH];
...@@ -468,43 +482,31 @@ void CP(SD_info *sd, const char *source_filename, const char *destination_filena ...@@ -468,43 +482,31 @@ void CP(SD_info *sd, const char *source_filename, const char *destination_filena
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
#ifdef TEST_WRITE char user_data;
uint8_t blocW[BLOCK_SIZE]={0xaa,0xbb,0xcc};
#endif
#ifdef TEST_READ
uint8_t blocR[BLOCK_SIZE];
#endif
#ifdef DEBUG
init_printf();
#endif
SD_info sd; SD_info sd;
init_printf();
spi_init(); spi_init();
uint8_t result = sd_init(&sd); uint8_t result = sd_init(&sd);
#ifdef DEBUG
printf("result=%x\n",result); printf("result=%x\n",result);
printf("status=%x\n",sd.status_); printf("status=%x\n",sd.status_);
printf("erreur=%x\n",sd.errorCode_); printf("erreur=%x\n",sd.errorCode_);
printf("type=%x\n",sd.type_); printf("type=%x\n",sd.type_);
uint32_t size=cardSize(&sd); uint32_t size=cardSize(&sd);
printf("taille=%ld\n",size); printf("taille=%ld\n",size);
#endif
#ifdef TEST_WRITE
int statutWrite=writeBlockSD(&sd,BLOC_NO,blocW);
#ifdef DEBUG
printf("writeStatus=%x\n",statutWrite);
#endif
#endif
#ifdef TEST_READ
int statutRead=readBlockSD(&sd,BLOC_NO,blocR);
#ifdef DEBUG
printf("readstatus=%x\n",statutRead);
int i;
for(i=0;i<3;i++) printf("bloc[%d]=%x ",i,blocR[i]);
printf("\n");
#endif
#endif
return 0;
LS(&sd);
while(1)
{
_delay_ms(10);
user_data = get_serial();
printf("%c", user_data);
/*if(user_data == '\r' )
{
}*/
}
// // Vérification du nombre d'arguments // // Vérification du nombre d'arguments
// if (argc < 3) { // if (argc < 3) {
// printf("Usage: %s filesystem_path ACTION [arguments...]\n", argv[0]); // printf("Usage: %s filesystem_path ACTION [arguments...]\n", argv[0]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment