/* -------------------------------------------------- */ int main(int argc, char **argv) { int ret; efs_init(); ret = efs_create("afile", 0644); ret = efs_shell_ww(100, 1024*1024); return 0; }
PROCESS_THREAD(sdcard_process, ev , data) { int fd; static struct etimer timer; PROCESS_BEGIN(); /* Mark all file descriptors as free */ for (fd = 0; fd < MAX_FDS; fd++) { file_setAttr(&file_descriptors[fd], FILE_STATUS_OPEN,0); } /* Card not inserted */ sdcard_efs.myCard.sectorCount = 0; init_spi(); etimer_set(&timer, CLOCK_SECOND); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT || ev== PROCESS_EVENT_TIMER || ev == PROCESS_EVENT_POLL); if (ev == PROCESS_EVENT_EXIT) break; if (ev == PROCESS_EVENT_TIMER) { if (!(GPIOA->IDR & (1<<0))) { if (sdcard_efs.myCard.sectorCount == 0) { etimer_set(&timer,CLOCK_SECOND/2); PROCESS_WAIT_EVENT_UNTIL(ev== PROCESS_EVENT_TIMER); if (efs_init(&sdcard_efs,0) == 0) { if (event_process) { process_post(event_process, sdcard_inserted_event, NULL); } printf("SD card inserted\n"); } else { printf("SD card insertion failed\n"); } } } else { if (sdcard_efs.myCard.sectorCount != 0) { /* Card removed */ fs_umount(&sdcard_efs.myFs); sdcard_efs.myCard.sectorCount = 0; if (event_process) { process_post(event_process, sdcard_removed_event, NULL); } printf("SD card removed\n"); } } etimer_set(&timer, CLOCK_SECOND); } } PROCESS_END(); }
PROCESS_THREAD(sdcard_process, ev , data) { static struct etimer timer; PROCESS_BEGIN(); *AT91C_PIOA_PER = AT91C_PIO_PA20 | AT91C_PIO_PA1; *AT91C_PIOA_ODR = AT91C_PIO_PA20 | AT91C_PIO_PA1; /* Card not inserted */ sdcard_efs.myCard.sectorCount = 0; init_spi(); while(1) { if (!(*AT91C_PIOA_PDSR & AT91C_PA20_IRQ0)) { if (sdcard_efs.myCard.sectorCount == 0) { if (efs_init(&sdcard_efs,0) == 0) { if (event_process) { process_post(event_process, sdcard_inserted_event, NULL); } printf("SD card inserted\n"); } else { printf("SD card insertion failed\n"); } } } else { if (sdcard_efs.myCard.sectorCount != 0) { /* Card removed */ fs_umount(&sdcard_efs.myFs); sdcard_efs.myCard.sectorCount = 0; if (event_process) { process_post(event_process, sdcard_removed_event, NULL); } printf("SD card removed\n"); } } etimer_set(&timer, CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT || ev == PROCESS_EVENT_TIMER); if (ev == PROCESS_EVENT_EXIT) break; if (!(*AT91C_PIOA_PDSR & AT91C_PA20_IRQ0)) { /* Wait for card to be preperly inserted */ etimer_set(&timer,CLOCK_SECOND/2); PROCESS_WAIT_EVENT_UNTIL(ev== PROCESS_EVENT_TIMER); } } PROCESS_END(); }
int main(int argc, char** argv) { EmbeddedFileSystem efs; EmbeddedFile file; unsigned short e; unsigned short bufsize; signed short ret; char *buf; FILE *localfile; if(argc<4){ fprintf(stderr,"Argument error : cpa <fs> <local_read> <file_append> [bufsize]\n"); exit(-1); } if(argc==5) bufsize=atoi(argv[4]); else bufsize=4096; buf=malloc(bufsize); if(efs_init(&efs,argv[1])!=0){ printf("Could not open filesystem.\n"); return(-1); } ret=file_fopen(&file,&efs.myFs,argv[3],'a'); if((ret!=0)){ printf("Could not open file %s (return value: %d).\n",argv[3],ret); return(-2); } if(!(localfile=fopen(argv[2],"r"))){ printf("Could not open local file.\n"); return(-3); } while((e=fread(buf,1,bufsize,localfile))){ file_write(&file,e,buf); } file_fclose(&file); fclose(localfile); fs_umount(&(efs.myFs)); return(0); }
int main(int argc, char **argv) { EmbeddedFileSystem efs; if(argc<3){ fprintf(stderr,"Argument error : mkdir <fs> <dirname>\n"); exit(-1); } if(efs_init(&efs,argv[1])!=0){ printf("Could not open filesystem.\n"); return(-1); } if(!mkdir(&(efs.myFs),argv[2])){ printf("Unable to make directory\n"); fs_umount(&(efs.myFs)); exit(-1); } fs_umount(&(efs.myFs)); return(0); }
int main() { int8_t res; uint32_t n, m, p, cnt; uint32_t cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU); uint32_t filesize = 0; uint32_t time_end; // SystemInit(); SysTick_Config(cclk/1000 - 1); /* Generate interrupt each 1 ms */ debug_frmwrk_init(); // UART0 xfunc_out = put_char; xfunc_in = get_char; xprintf("%s",mciFsMenu); xprintf("\nMMC/SD Card Filesystem Test (P:LPC1788 L:EFSL)\n"); xprintf("\nCARD init..."); // init file system if ( ( res = efs_init( &efs, 0 ) ) != 0 ) { xprintf("failed with %d\n",res); } else { xprintf("ok\n"); xprintf("Card type: "); switch (CardConfig.CardType) { case MCI_MMC_CARD: xprintf("MMC\n"); break; case MCI_SDSC_V1_CARD: xprintf("Version 1.x Standard Capacity SD card.\n"); break; case MCI_SDSC_V2_CARD: xprintf("Version 2.0 or later Standard Capacity SD card.\n"); break; case MCI_SDHC_SDXC_CARD: xprintf("Version 2.0 or later High/eXtended Capacity SD card.\n"); break; default: break; } xprintf("Sector size: %d bytes\n", CardConfig.SectorSize); xprintf("Sector count: %d\n", CardConfig.SectorCount); xprintf("Block size: %d sectors\n", CardConfig.BlockSize); xprintf("Card capacity: %d MByte\n\n", (((CardConfig.SectorCount >> 10) * CardConfig.SectorSize)) >> 10); xprintf("\nDirectory of 'root':\n"); /* list files in root directory */ ls_openDir( &list, &(efs.myFs) , "/"); while ( ls_getNext( &list ) == 0 ) { // list.currentEntry is the current file list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0'; xprintf("%s, 0x%x bytes\n", list.currentEntry.FileName, list.currentEntry.FileSize ) ; } #if READ_TEST_ENABLED!=0 /* Read test */ xprintf("\nFile read test:\n"); xprintf("Open file %s ...", FILE_NAME_R); xmemset(Buff,0,sizeof(Buff)); if (file_fopen( &filer, &efs.myFs , FILE_NAME_R , 'r' ) == 0 ) { xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE); n=FILE_RW_SIZE; m = 0; Timer = 0; xprintf("File's content:\n"); while (n) { if (n>=blen) {cnt = blen; n -= blen;} else {cnt = n; n = 0;} p = file_read( &filer, cnt, &Buff[m] ); xprintf("%s",&Buff[m]); m += p; if (p != cnt) break; } filesize = m; time_end = Timer; xprintf("\n%lu bytes read in %lu milisec.\n", m, time_end); file_fclose( &filer ); } else { xprintf (" Failed.\n"); } #endif #if WRITE_TEST_ENABLED!=0 /* Write test*/ xprintf("\nFile write test:\n"); xprintf("Open file %s ...", FILE_NAME_W); if (file_fopen( &filew, &efs.myFs , FILE_NAME_W , 'a' ) == 0 ) { xprintf(" OK. \nWriting %lu bytes ...\n", filesize); n=filesize; m = 0; Timer = 0; while (n) { if (n>=blen) { cnt = blen; n -= blen; } else { cnt = n; n = 0; } p = file_write( &filew, cnt, &Buff[m] ); m += p; if (p != cnt) break; } time_end = Timer; xprintf("%lu bytes written in %lu milisec.\n", m, time_end); file_fclose( &filew ); } else { xprintf (" Failed.\n"); } #endif #if READ_TEST_ENABLED!=0 /* Read test */ xprintf("\nFile read test:\n"); xprintf("Open file %s ...", FILE_NAME_W); xmemset(Buff,0,sizeof(Buff)); if (file_fopen( &filer, &efs.myFs , FILE_NAME_W , 'r' ) == 0 ) { xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE); n=FILE_RW_SIZE; m = 0; Timer = 0; xprintf("File's content:\n"); while (n) { if (n>=blen) {cnt = blen; n -= blen;} else {cnt = n; n = 0;} p = file_read( &filer, cnt, &Buff[m] ); xprintf("%s",&Buff[m]); m += p; if (p != cnt) break; } filesize = m; time_end = Timer; xprintf("\n%lu bytes read in %lumiliseconds.\n", m, time_end); file_fclose( &filer ); } else { xprintf (" Failed.\n"); } #endif /* close file system */ fs_umount( &efs.myFs ) ; } xprintf("\nEFSL test complete.\n"); while (1); }
/* for each new request (data in p->payload) from addr:port, * create a new port to serve the response, and start the response * process */ void process_tftp_request(struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port) { tftp_opcode op = tftp_decode_op(pkt_buf->payload); char FileName[30]; struct udp_pcb *upcb; err_t err; u32_t IPaddress; u8_t iptxt[20]; volatile u8_t iptab[4]; IPaddress = addr->addr; printf("\n\rTFTP RRQ (read request) from: %d.%d.%d.%d\n\r", (u8_t)(IPaddress), (u8_t)(IPaddress >> 8),(u8_t)(IPaddress >> 16),(u8_t)(IPaddress >> 24)); /* read its IP address */ iptab[0] = (u8_t)(IPaddress >> 24); iptab[1] = (u8_t)(IPaddress >> 16); iptab[2] = (u8_t)(IPaddress >> 8); iptab[3] = (u8_t)(IPaddress); sprintf((char*)iptxt, "TFTP: %d.%d.%d.%d ", iptab[3], iptab[2], iptab[1], iptab[0]); LCD_DisplayStringLine(Line7, iptxt); /* create new UDP PCB structure */ upcb = udp_new(); if (!upcb) { /* Error creating PCB. Out of Memory */ return; } /* bind to port 0 to receive next available free port */ /* NOTE: This is how TFTP works. There is a UDP PCB for the standard port * 69 which al transactions begin communication on, however, _all_ subsequent * transactions for a given "stream" occur on another port! */ err = udp_bind(upcb, IP_ADDR_ANY, 0); if (err != ERR_OK) { /* Unable to bind to port */ return; } switch (op) { case TFTP_RRQ: /* TFTP RRQ (read request) */ /* Read the name of the file asked by the client to be sent from the SD card */ tftp_extract_filename(FileName, pkt_buf->payload); printf("\n\rTFTP RRQ (read request)"); printf("\n\rONLY EFS filesystem(NTFS in WinXp) is support"); /* If Could not open filesystem */ if (efs_init(&efs1, 0) != 0) { printf("\n\rIf Could not open filesystem"); return; } printf("\n\rCould open filesystem\n\r"); /* If Could not open the selected directory */ if (ls_openDir(&list1, &(efs1.myFs), "/") != 0) { printf("\n\rIf Could not open the selected directory"); return; } /* Start the TFTP read mode*/ printf("\n\rStart the TFTP read mode...."); tftp_process_read(upcb, addr, port, FileName); break; case TFTP_WRQ: /* TFTP WRQ (write request) */ /* Read the name of the file asked by the client to received and writen in the SD card */ tftp_extract_filename(FileName, pkt_buf->payload); /* If Could not open filesystem */ if (efs_init(&efs2, 0) != 0) { return; } /* If Could not open the selected directory */ if (ls_openDir(&list2, &(efs2.myFs), "/") != 0) { return; } /* Start the TFTP write mode*/ tftp_process_write(upcb, addr, port, FileName); break; default: /* sEndTransfera generic access violation message */ tftp_send_error_message(upcb, addr, port, TFTP_ERR_ACCESS_VIOLATION); /* TFTP unknown request op */ /* no need to use tftp_cleanup_wr because no "tftp_connection_args" struct has been malloc'd */ udp_remove(upcb); break; } }
int main() { int8_t res; uint32_t n, m, p, cnt; // SystemInit(); SysTick_Config(SystemCoreClock/1000 - 1); /* Generate interrupt each 1 ms */ LPC17xx_UART_Init(115200); // UART0 xfunc_out = LPC17xx_UART_PutChar; xfunc_in = LPC17xx_UART_GetChar; xprintf("\nMMC/SD Card Filesystem Test (P:LPC1768 L:EFSL)\n"); xprintf("\nCARD init..."); // init file system if ( ( res = efs_init( &efs, 0 ) ) != 0 ) { xprintf("failed with %i\n",res); } else { xprintf("ok\n"); xprintf("Card type: "); switch (CardType) { case CARDTYPE_MMC: xprintf("MMC\n"); break; case CARDTYPE_SDV1: xprintf("Version 1.x Standard Capacity SD card.\n"); break; case CARDTYPE_SDV2_SC: xprintf("Version 2.0 or later Standard Capacity SD card.\n"); break; case CARDTYPE_SDV2_HC: xprintf("Version 2.0 or later High/eXtended Capacity SD card.\n"); break; default: break; } xprintf("Sector size: %d bytes\n", CardConfig.sectorsize); xprintf("Sector count: %d\n", CardConfig.sectorcnt); xprintf("Block size: %d sectors\n", CardConfig.blocksize); xprintf("Card capacity: %d MByte\n\n", (((CardConfig.sectorcnt >> 10) * CardConfig.sectorsize)) >> 10); xprintf("\nDirectory of 'root':\n"); /* list files in root directory */ ls_openDir( &list, &(efs.myFs) , "/"); while ( ls_getNext( &list ) == 0 ) { // list.currentEntry is the current file list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0'; xprintf("%s, 0x%x bytes\n", list.currentEntry.FileName, list.currentEntry.FileSize ) ; } #if WRITE_TEST_ENABLED!=0 /* Write test*/ xprintf("\nFile write test:\n"); xprintf("Open file %s ...", FILE_NAME); if (file_fopen( &filew, &efs.myFs , FILE_NAME , 'a' ) == 0 ) { xprintf(" OK. \nWriting %lu bytes ...\n", FILE_RW_SIZE); xmemset(Buff, 0xAA, blen); n=FILE_RW_SIZE; m = 0; Timer = 0; while (n) { if (n>=blen) { cnt = blen; n -= blen; } else { cnt = n; n = 0; } p = file_write( &filew, cnt, Buff ); m += p; if (p != cnt) break; } xprintf("%lu bytes written with %lu kB/sec.\n", m, Timer ? (m / Timer) : 0); file_fclose( &filew ); } else { xprintf (" Failed.\n"); } #endif #if READ_TEST_ENABLED!=0 /* Read test */ xprintf("\nFile read test:\n"); xprintf("Open file %s ...", FILE_NAME); if (file_fopen( &filer, &efs.myFs , FILE_NAME , 'r' ) == 0 ) { xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE); n=FILE_RW_SIZE; m = 0; Timer = 0; while (n) { if (n>=blen) {cnt = blen; n -= blen;} else {cnt = n; n = 0;} p = file_read( &filer, cnt, Buff ); m += p; if (p != cnt) break; } xprintf("%lu bytes read with %lu kB/sec.\n", m, Timer ? (m / Timer) : 0); file_fclose( &filer ); } else { xprintf (" Failed.\n"); } #endif /* close file system */ fs_umount( &efs.myFs ) ; } xprintf("\nEFSL test complete.\n"); while (1); }
void main(void) { EmbeddedFileSystem efs; EmbeddedFile file_w; unsigned short i; unsigned char e; unsigned char t; signed char err; unsigned char offset1; unsigned char offset2; char path[100]; debug_init(); DBG((TXT("Welcome (2).\n-------------\n\n"))); if(efs_init(&efs,0)!=0){ DBG((TXT("Could not init filesystem.\n"))); hang(); } for(i=1;i<=4;i++){ offset1=c2str(1,path); path[offset1++]='/'; for(e=1;e<=12;e++){ offset2=offset1; offset2+=c2str(e,path+offset1); DBG((TXT("Dir name: %s.\n"),path)); } } /*for(i=1;i<10;i++){ path[0]='D'; path[1]='I'; path[2]='R'; path[3]=0x30+((i%10000)/1000); path[4]=0x30+((i%1000)/100); path[5]=0x30+((i%100)/10); path[6]=0x30+((i%10)/1); path[7]='\0'; err=mkdir(&efs.myFs,path); if(err!=0){ DBG((TXT("ERROR: Could not create directory %s (%d) - returned ERR %d.\n"),path,i,err)); hang(); } DBG((TXT("DIR %s created.\n"),path)); for(e=1;e<6;e++){ path[7]='/'; path[8]=0x40+e; path[9]='\0'; err=mkdir(&efs.myFs,path); if(err!=0){ DBG((TXT("ERROR: Could not create directory %s (%d) - returned ERR %d.\n"),path,i,err)); hang(); } DBG((TXT("DIR %s created.\n"),path)); for(t=0;t<26;t++){ path[9]='/'; path[10]='t'; path[11]='e'; path[12]='s'; path[13]='t'; path[14]='-'; path[15]=0x41+t; path[16]='.'; path[17]='t'; path[18]='x'; path[19]='t'; path[20]='\0'; if(file_fopen(&file_w,&efs.myFs,path,'w')!=0){ DBG((TXT("Could not open file %s for writing.\n"),path)); hang(); } file_write(&file_w,15,"Dit is een test"); file_fclose(&file_w); } } }*/ file_fclose(&file_w); fs_umount(&efs.myFs); DBG((TXT("Done :-)\n\n"))); hang(); }
/* for each new request (data in p->payload) from addr:port, * create a new port to serve the response, and start the response * process */ void process_tftp_request(struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port) { tftp_opcode op = tftp_decode_op(pkt_buf->payload); char FileName[30]; struct udp_pcb *upcb; err_t err; /* create new UDP PCB structure */ upcb = udp_new(); if (!upcb) { /* Error creating PCB. Out of Memory */ return; } /* bind to port 0 to receive next available free port */ /* NOTE: This is how TFTP works. There is a UDP PCB for the standard port * 69 which al transactions begin communication on, however, _all_ subsequent * transactions for a given "stream" occur on another port! */ err = udp_bind(upcb, IP_ADDR_ANY, 0); if (err != ERR_OK) { /* Unable to bind to port */ return; } switch (op) { case TFTP_RRQ: /* TFTP RRQ (read request) */ /* Read the name of the file asked by the client to be sent from the SD card */ tftp_extract_filename(FileName, pkt_buf->payload); /* If Could not open filesystem */ if (efs_init(&efs1, 0) != 0) { return; } /* If Could not open the selected directory */ if (ls_openDir(&list1, &(efs1.myFs), "/") != 0) { return; } /* Start the TFTP read mode*/ tftp_process_read(upcb, addr, port, FileName); break; case TFTP_WRQ: /* TFTP WRQ (write request) */ /* Read the name of the file asked by the client to received and writen in the SD card */ tftp_extract_filename(FileName, pkt_buf->payload); /* If Could not open filesystem */ if (efs_init(&efs2, 0) != 0) { return; } /* If Could not open the selected directory */ if (ls_openDir(&list2, &(efs2.myFs), "/") != 0) { return; } /* Start the TFTP write mode*/ tftp_process_write(upcb, addr, port, FileName); break; default: /* sEndTransfera generic access violation message */ tftp_send_error_message(upcb, addr, port, TFTP_ERR_ACCESS_VIOLATION); /* TFTP unknown request op */ /* no need to use tftp_cleanup_wr because no "tftp_connection_args" struct has been malloc'd */ udp_remove(upcb); break; } }
int main(void) { int ch; int8_t res; systemInit(); gpioInit(); uart1Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART uart1Puts("\r\nMMC/SD Card Filesystem Test (P:LPC2138 L:EFSL)\r\n"); uart1Puts("efsl LPC2000-port and this Demo-Application\r\n"); uart1Puts("done by Martin Thomas, Kaiserslautern, Germany\r\n"); /* init efsl debug-output */ lpc2000_debug_devopen(uart1Putch); ledToggle(); rprintf("CARD init..."); if ( ( res = efs_init( &efs, 0 ) ) != 0 ) { rprintf("failed with %i\n",res); } else { rprintf("ok\n"); rprintf("Directory of 'root':\n"); ls_openDir( &list, &(efs.myFs) , "/"); while ( ls_getNext( &list ) == 0 ) { list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0'; rprintf( "%s ( %li bytes )\n" , list.currentEntry.FileName, list.currentEntry.FileSize ) ; } if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) { rprintf("File %s open. Content:\n", LogFileName); while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) { buf[e]='\0'; uart1Puts((char*)buf); } rprintf("\n"); file_fclose( &filer ); } if ( file_fopen( &filew, &efs.myFs , LogFileName , 'a' ) == 0 ) { rprintf("File %s open for append. Appending...", LogFileName); strcpy((char*)buf, "Martin hat's angehaengt\r\n"); if ( file_write( &filew, strlen((char*)buf), buf ) == strlen((char*)buf) ) { rprintf("ok\n"); } else { rprintf("fail\n"); } file_fclose( &filew ); } if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) { rprintf("File %s open. Content:\n", LogFileName); while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) { buf[e]='\0'; uart1Puts((char*)buf); } rprintf("\n"); file_fclose( &filer ); } fs_umount( &efs.myFs ) ; } while(1) { if ((ch = uart1Getch()) >= 0) { uart1Puts("You pressed : "); uart1Putch(ch); uart1Puts("\r\n"); if ( ch == 'M' ) { rprintf("Creating FS\n"); mkfs_makevfat(&efs.myPart); } ledToggle(); } } return 0; /* never reached */ }
/** ******************************************************************************************** Function Name : fs_init() Description : Input : Output : Void Note : ******************************************************************************************** */ S32 fs_init(void) { return efs_init( &efs, 0 ); }