int main(int argc, char **argv) { if (argc < 3) { fprintf(stderr, "USAGE: %s <imgname> <filename>\n", argv[0]); fprintf(stderr, " Reads a file within a FAT16 image file to stdout\n"); return -1; } diskfilename = argv[1]; FATFS fatfs; if (pf_mount(&fatfs) != FR_OK) { fprintf(stderr, "pf_mount failed\n"); return -2; } if (pf_open(argv[2]) != FR_OK) { fprintf(stderr, "pf_open(%s) failed\n", argv[2]); return -3; } char buf[128]; WORD bytesRead=0; do { if (pf_read(buf, 128, &bytesRead)) { fprintf(stderr, "pf_read failed\n"); return -4; } fwrite(buf, 1, bytesRead, stdout); } while (bytesRead == 128); return 0; }
alien_rc SDCARD_config (void * parameters) { // check the params alien_rc rc = SDCARD_check_params(parameters); if (rc != DRIVER_PARAMETER_OK) return rc; // setup the parameters SDCARD_info_t *current_parameters = parameters; // check if the LED you need has a PID assigned to it if (SDCARD_locked_by_PID != NO_PID) return DRIVER_BUSY; // lock the SDCARD for you SDCARD_locked_by_PID = scheduler_running_PID (); // try and open the file current_parameters->_rc = FR_NOT_READY; current_parameters->_no_bytes = 2048; current_parameters->_rc = pf_mount (&(current_parameters->_fs)); if (current_parameters->_rc != FR_OK) return DRIVER_CONFIG_ERROR; current_parameters->_rc = pf_open (current_parameters->_filename); if (current_parameters->_rc != FR_OK) return DRIVER_CONFIG_ERROR; // finished return DRIVER_CONFIG_OK; }
FRESULT PFFS::open ( const CHAR *path /* Pointer to the file name */ //unsigned char mode /* Access mode and file open mode flags */ ) { return pf_open(path); //ok }
void CircularBuffer_init(char * file, FATFS * fatfs) { //fill the buffer FRESULT rc = pf_mount(fatfs); if (rc) die(rc); rc = pf_open(file); if (rc) die(rc); print("SD card initialized, opened "); print(file); RET(); WORD br; rc = pf_read(buf0, sizeof(buf0), &br); die(rc); //set breakpoint see if dissasembly is shift right wordsAvailable = br >> 1; //div by two rc = pf_read(buf1, sizeof(buf1), &br); die(rc); wordsAvailable += br >> 1; //div by two offset = 0; //set the queued pointer to buf0 queued = buf0; dequeued = buf1; state = STATE_FILLED_DEQUEUED; }
uint8_t CheckBMPImage(char *fileName) { uint8_t buffer[SD_BLOCK_SIZE]; if (pf_open(fileName) == FR_OK) { pf_read(buffer, SD_BLOCK_SIZE, &br); if (br != SD_BLOCK_SIZE) { return 1; } BMPReadInfoHeaders(&fileHeader, &imageHeader, buffer); if (BMPValidateImageParameters(&fileHeader, &imageHeader) != RES_OK) { return 1; } } else { return 1; } return 0; }
static UINT play (const char *fn) { DWORD sz; FRESULT res; unsigned char read2; uint16_t size = 256; if ((res = pf_open(fn)) == FR_OK) { Timer0_init(); Timer1_init(); sz = load_header(); /* Load file header */ if (sz < 256) return (UINT)sz; FifoCt = 0; FifoRi = 0; FifoWi = 0; /* Reset FIFO */ pf_read(Buff1, 512 - (Fs.fptr % 512), &rb); /* Snip sector unaligned part */ sz -= rb; res = pf_read(Buff1, size, &rb); if (res != FR_OK) { PORTC = 0x08; while (FifoCt) ; return res; } sync = 1; do { read2 = read1; if(read1 == 1) res = pf_read(Buff2, size, &rb); else res = pf_read(Buff1, size, &rb); if (res != FR_OK) { PORTC = 0x08; break; } while(read2 == read1); if(!(PINB&(1<<PB1))) { sync = 0; _delay_ms(500); break; } } while (rb == size); /* Repeat until all data read */ sync = 0; } while (FifoCt) ; /* Wait for FIFO empty */ return res; }
int main (void) { FRESULT res; char *dir; BYTE org_osc = OSCCAL; MCUSR = 0; WDTCR = _BV(WDE) | 0b110; /* Enable WDT reset in timeout of 1s */ PORTB = 0b101001; /* Initialize port: - - H L H L L P */ DDRB = 0b111110; sei(); for (;;) { if (pf_mount(&Fs) == FR_OK) { /* Initialize FS */ wdt_reset(); sendDiag(MOUNT_OK); Buff[0] = 0; if (!pf_open("osccal")) pf_read(Buff, 1, &rb); /* Adjust frequency */ OSCCAL = org_osc + Buff[0]; res = pf_opendir(&Dir, dir = "wav"); /* Open sound file directory */ if (res == FR_NO_PATH){ res = pf_opendir(&Dir, dir = ""); /* Open root directory */ sendDiag(OPEN_ROOT_DIR); } else{ sendDiag(OPEN_WAV_DIR); } while (res == FR_OK) { /* Repeat in the dir */ res = pf_readdir(&Dir, 0); /* Rewind dir */ while (res == FR_OK) { /* Play all wav files in the dir */ wdt_reset(); res = pf_readdir(&Dir, &Fno); /* Get a dir entry */ if (res || !Fno.fname[0]){ if(res) sendDiag(DIR_ERROR); else sendDiag(END_OF_DIR); break; } /* Break on error or end of dir */ if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, ".WAV")){ sendFilename(Fno.fname); wdt_reset(); sendDiag(PLAY_SONG); res = play(dir, Fno.fname); /* Play file */ } sendDiag(FINISH); } } } else{ sendDiag(MOUNT_FAIL); } delay500(); } }
static FRESULT play ( const char *dir, /* Directory */ const char *fn /* File */ ) { DWORD sz; FRESULT res; BYTE sw; WORD btr; wdt_reset(); res = pf_open((char*)Buff); /* Open sound file */ if (res == FR_OK) { sz = load_header(); /* Check file format and ready to play */ if (sz < 1024) return 255; /* Cannot play this file */ FifoCt = 0; FifoRi = 0; FifoWi = 0; /* Reset audio FIFO */ if (!TCCR1) { /* Enable audio out if not enabled */ PLLCSR = 0b00000110; /* Select PLL clock for TC1.ck */ GTCCR = 0b01100000; /* Enable OC1B as PWM */ TCCR1 = MODE ? 0b01100001 : 0b00000001; /* Start TC1 and enable OC1A as PWM if needed */ TCCR0A = 0b00000010; /* Statr TC0 as interval timer at 2MHz */ TCCR0B = 0b00000010; TIMSK = _BV(OCIE0A); ramp(1); } pf_read(0, 512 - (Fs.fptr % 512), &rb); /* Snip sector unaligned part */ sz -= rb; sw = 1; /* Button status flag */ do { /* Data transfer loop */ wdt_reset(); btr = (sz > 1024) ? 1024 : (WORD)sz;/* A chunk of audio data */ res = pf_read(0, btr, &rb); /* Forward the data into audio FIFO */ if (rb != 1024) break; /* Break on error or end of data */ sz -= rb; /* Decrease data counter */ sw <<= 1; /* Break on button down */ } while ((PINB & 1) || ++sw != 1); } else{ sendDiag(PLAY_FAIL); } while (FifoCt) ; /* Wait for audio FIFO empty */ OCR1A = 128; OCR1B = 128; /* Return output to center level */ return res; }
void SD_::init() { #ifdef SKIPBLANKSD this->WorkingSDCard = true; while ( ! check( pf_mount(&this->SDCard) ) ); while ( ! check( pf_open("data.txt") )); this->SDOffset = 0; while ( ! check( pf_lseek(this->SDOffset) )); WORD written; while ( ! check (pf_write(0,0,&written)); if( WorkingSDCard ) { char InputBuffer[512]; WORD size; while(true) { pf_read(&InputBuffer, 512, &size); if((InputBuffer[0] == '%' && InputBuffer[1] == '$') || (InputBuffer[1] == '%' && InputBuffer[0] == '$')) { this->SDOffset += 512; pf_lseek(this->SDOffset); return; } this->SDOffset += 512; pf_lseek(this->SDOffset); } } #else this->TimeStamp = 0; WorkingSDCard = true; while ( ! check( pf_mount(&this->SDCard) )); while ( ! check( pf_open("data.txt") )); this->SDOffset = 0; while ( ! check( pf_lseek(this->SDOffset) )); #endif }
void playBuu() { rcv = pf_mount(&fatfs); rcv = pf_open("buu.wav"); if (rcv == FR_OK) { if (initSpiker()) { //inicjacja nagłówków wave{ if (play()) { } } } rcv = pf_mount(0); }
int main () { int x, n, i; unsigned int* spi = (unsigned int *)0177714; puts ("hello.jpg\n"); disk_sbuf(buffer); do { puts("SD "); x = pf_mount(&fatfs); puts(x == FR_OK ? "mounted\n" : "fail\n"); } while (x != FR_OK); puts("Opening BK0010/ "); puts(pf_opndir(&dir, "BK0010") == FR_OK ? "opened\n" : "fail\n"); /*return 0;*/ for (x=0;; x++) { if (pf_rddir(&dir,&fno) == FR_OK) { if (!fno.fname[0]) break; puts(fno.fname); if (fno.fattrib & AM_DIR) { puts("/"); } else { for(i=0; fname[i+7]=fno.fname[i]; i++); puts("\nTrying to open: "); puts(fname); puts(" size=0x"); printq(fno.fsize,1); if (pf_open(fname) == FR_OK) { for(; pf_read(buf, sizeof(buf), &n) == FR_OK;) { /*putchar('[');printhex(n);putchar(']');*/ for (i = 0; i < n; i++) { putchar(buf[i]); } if (n < sizeof(buf)) break; } } else { puts(" - couldn't open"); } } puts("\n"); } } return 0; }
/***************************************************************** 函数原型:zbClerkReadFile(void) 功能描述:操作员文件初始化 参数描述: 返回值: OK ? NOTOK 作 者: 刘及华 日 期: 2012-11-24 修改历史: 日期 修改人 修改描述 ------ --------- ------------- *****************************************************************/ char zbClerkReadFile(void) { uchar ucOpenID; uint uiRecnum; pf_open((void *)clerkFileName, &ucOpenID); pf_read(ucOpenID, 1, 1, &uiRecnum, (uchar *)clerk_list); pf_close(ucOpenID); return TRUE; }
/***************************************************************** 函数原型:zbClerkSaveFile(void) 功能描述:操作员文件初始化 参数描述: 返回值: OK ? NOTOK 作 者: 刘及华 日 期: 2012-11-24 修改历史: 日期 修改人 修改描述 ------ --------- ------------- *****************************************************************/ char zbClerkSaveFile(void) { // uchar ucret; uchar ucOpenID; pf_open((void *)clerkFileName, &ucOpenID); pf_write(ucOpenID, 0, (uchar *)clerk_list); pf_close(ucOpenID); return TRUE; }
void OpenFile(char *fileName) { uint8_t buffer[SD_BLOCK_SIZE]; if (pf_open(fileName) == FR_OK) { pf_read(buffer, SD_BLOCK_SIZE, &br); BMPReadInfoHeaders(&fileHeader, &imageHeader, buffer); if (BMPValidateImageParameters(&fileHeader, &imageHeader) != RES_OK) { HollyFuckHappened(); } } }
// Reads board from SD card. tU8 readBoard(Field *board, tU8 boardHeight, tU8 boardWidth) { tU8 initResult = findAndInitSD(); if (initResult == FALSE) { return initResult; } printf("Proba otwarcia pliku z plansza.\n"); result = pf_open("board.txt"); if (result) { printf("Nie udalo sie otworzyc pliku.\n"); if (FR_NO_FILE == result) { printf("Nie ma takiego pliku\n"); } else if (FR_NOT_ENABLED == result) { printf("Problem z systemem plikow\n"); } return FALSE; } printf("Proba odczytu z pliku z plansza.\n"); WORD bytesRead = 0; result = pf_read(boardBuffer, BOARD_BUFFER_SIZE, &bytesRead); printf("Odczyt zakonczony\n"); if (result) { printf("Nie udalo sie odczytac wszystkich danych z pliku. Odczytano %d bajtow\n", bytesRead); return FALSE; } else { printf("Odczytano wszystkie dane z pliku.\n"); } int i, j = 0; for (i = 0; i < BOARD_BUFFER_SIZE && boardBuffer[i] != 0; ++i) { if (boardBuffer[i] == '\n' || boardBuffer[i] == '\r') { continue; } board[j] = boardBuffer[i] - '0'; ++j; } printf("Wprowadzono dane do tablicy.\n"); return TRUE; }
void Map_Read(uint8_t layer, int x, int y, uint8_t orientation) { WORD bytesRead; #if REMOUNT_ON_READ pf_mount(&FileSystem); pf_open("map.dat"); #endif if(orientation == MapRead_Horizontal) { pf_lseek(sizeof(Map_Header_t) + ((2 * layer) * Map_Header.width * Map_Header.height) + (y * Map_Header.width + x)); } else { pf_lseek(sizeof(Map_Header_t) + ((2 * layer + 1) * Map_Header.width * Map_Header.height) + (x * Map_Header.height + y)); } pf_read(Map_ReadBuffer, MAP_READ_LENGTH, &bytesRead); #if REMOUNT_ON_READ pf_mount(NULL); #endif #if 0 Map_Header.width = 128; Map_Header.height = 128; if(orientation == MapRead_Horizontal) { for(int n = 0; n < MAP_READ_LENGTH; n++) { Map_ReadBuffer[n] = (y % 3) == 0 || ((x + n) % 3) == 0 ? 1 : 0; } } else { for(int n = 0; n < MAP_READ_LENGTH; n++) { Map_ReadBuffer[n] = ((y + n) % 3) == 0 || ((x) % 3) == 0 ? 1 : 0; } } #endif }
int write_sdcard(void) { FATFS fs; /* Work area (file system object) for the volume */ BYTE buff[16]; /* File read buffer */ UINT br; /* File read count */ FRESULT res; /* Petit FatFs function common result code */ res = pf_mount(&fs); if (res) return res; res = pf_open("srcfile.dat"); if (res) return res; res = pf_write(buff, 16, &br); return res; }
// Reggie added for julspower, autoboot if zimage is present on sd card int check_autoboot(unsigned char *cSel){ // WORD read_size; FATFS ffs; FRESULT fres; fres = pf_mount(&ffs); if ( fres ) { return (fres<<16) | 1; } fres = pf_open("autoboot"); if ( fres ) { return (fres<<16) | 2; } //Since file exist try to read a valid number from it fres = pf_read(cSel, 1, NULL); if(fres == FR_OK) { *cSel -= 48; //Have a number instead of ascii if(*cSel > 5) *cSel = 5; } return 0; }
int main() { FATFS fs; UINT br; char rd_buff[0x1e] = {0}; //Global interrupt enable. /*CyGlobalIntEnable;*/ SD_test(); /* Open a text file and type it */ if (pf_mount(&fs) == FR_OK && pf_open("HELLO.TXT") == FR_OK) { pf_read(rd_buff, 0x1e, &br); /* Direct output to the console */ } for (;;) ; }
int main (void) { FATFS fs; UINT br; /* Initialize GPIO ports */ PORTB = 0b101011; /* u z H L H u */ DDRB = 0b001110; /* Open a text file and type it */ if (pf_mount(&fs) == FR_OK && pf_open("hello.txt") == FR_OK) { do { pf_read(0, 16384, &br); /* Direct output to the console */ } while (br == 16384); } for (;;) ; }
int load_dtb(char *name, void *dest, int max_bytes) { #if CONFIG_DEVTREE == 1 FRESULT res = FR_OK; unsigned int len; unsigned long bytes_read; res = pf_open(name); if (res != FR_OK) { putstr("DTB not found\n"); goto err; } char str[32]; str[0] = '\0'; _strcat(str, "Open "); _strcat(str, name); _strcat(str, " OK"); _strcat(str, "\n"); putstr(str); len = pf_size(); if (len > max_bytes || len == 0) { putstr("Invalid DTB length\n"); goto err; } res = pf_lseek(0); if (res != FR_OK) { putstr("DTB lseek(0) failed"); goto err; } res = pf_read_long(dest, len, &bytes_read); if (res != FR_OK) { putstr("DTB read failed"); goto err; } putstr("Loaded DTB\n"); return 0; err: putstr("Failed to load DTB\n"); return -1; #else return -1; #endif }
// ****************** funkcja P L A Y ******************************** static UINT play ( const char *fn ) { FRESULT res; if ((res = pf_open(fn)) == FR_OK) { pf_lseek(44); TMR_START; // start Timera0 (samplowanie) pf_read(&buf[0][0], BUF_SIZE , &rb); // za³aduj pierwsz¹ czêœæ bufora pf_read(&buf[1][0], BUF_SIZE , &rb); // za³aduj drug¹ czêœæ bufora //TMR_START; // start Timera0 (samplowanie) while(1) { if( can_read ) { // jeœli flaga ustawiona w obs³udze przerwania pf_read(&buf[ nr_buf ^ 0x01 ][0], BUF_SIZE , &rb); // odczytaj kolejny bufor if( rb < BUF_SIZE ) break; // jeœli koniec pliku przerwij pêtlê while(1) can_read = 0; } if (playstop==1) //przerwanie odtwarzania { playstop=0; break; } if (ButtonPressed(0, PIND, 7, 30000) && buttondisable==0) //aktywowanie sekwencji POWER DOWN { buttondisable=1; shutdown=1; playstop=1; breakdisablehigh=1; breakdisablelow=0; } } TMR_STOP; // wy³¹czenie Timera0 (samplowania) } return res; }
void component_init() { power_screen(true); LED_Light(led_red, true); LED_Light(led_green, true); LED_Light(led_blue, true); screen_step(0); RTC_Clock clock = { 0, 0, 30, 23, 0, 8, 8, 12 }; SetTime(&clock); screen_step(1); screen_step(2); mobile_state(); screen_step(3); screen_step(4); prepare_mobile(false); screen_step(5); play_media(rand() % 9 + 1); screen_step(6); { char szSize[piece_size]; sprintf(szSize, "mount tf card %s", (pf_open("temp") == FR_OK) ? "correcttly" : "fault"); post_trace(szSize); } screen_step(7); screen_step(8); report_content("初始化过程完成,现在开始运行测试程序"); screen_step(9); screen_step(10); LED_Light(led_red, false); LED_Light(led_green, false); LED_Light(led_blue, false); display_clear(); power_screen(false); }
static int sd_load(char *name, u8 *address) { WORD read_size; FATFS ffs; FRESULT fres; fres = pf_mount(&ffs); if ( fres ) { return (fres<<16) | 1; } // fres = pf_open("u-boot.bin"); fres = pf_open(name); if ( fres ) { return (fres<<16) | 2; } do { fres = pf_read(address,4096,&read_size); if ( fres ) { return (fres<<16) | 3; } address += read_size; offset += read_size; renderHexU32(45,29,(u32)offset); } while(read_size == 4096); return 0; }
void Map_Load() { int tries = 0; Print(0, SCREEN_SCROLL_HEIGHT, PSTR("LOADING..")); while(tries < NUM_READ_TRIES) { tries++; if(pf_mount(&FileSystem) == FR_OK) { if(pf_open("map.dat") == FR_OK) { WORD bytesRead; pf_read(&Map_Header, sizeof(Map_Header), &bytesRead); Print(0, SCREEN_SCROLL_HEIGHT, PSTR("MAP LOADED! ")); Print(0, SCREEN_SCROLL_HEIGHT + 1, PSTR("MAP SIZE: ,")); PrintInt(13, SCREEN_SCROLL_HEIGHT + 1, 128, false); PrintInt(19, SCREEN_SCROLL_HEIGHT + 1, 128, false); } else { Print(0, SCREEN_SCROLL_HEIGHT, PSTR("MAP LOAD FAILED")); } #if REMOUNT_ON_READ pf_mount(NULL); #endif return; } else { pf_mount(NULL); Print(0, SCREEN_SCROLL_HEIGHT, PSTR("RETRYING MOUNT ")); } } Print(0, SCREEN_SCROLL_HEIGHT, PSTR("DISK MOUNT FAILED")); }
static int cmdline_load(char *name, u8 *address) { WORD read_size; FATFS ffs; FRESULT fres; u8 max_cmdline = 255; fres = pf_mount(&ffs); if ( fres ) { return (fres<<16) | 1; } // fres = pf_open("u-boot.bin"); fres = pf_open(name); if ( fres ) { return (fres<<16) | 2; } db_puts("opened file\n"); do { //fres = pf_read(address,166,&read_size); fres = pf_read(address,max_cmdline,&read_size); if ( fres ) { return (fres<<16) | 3; } address += read_size; offset += read_size; renderHexU32(45,29,(u32)offset); } while(fres!= NULL); return 0; }
int _open_r (struct _reent *r, const char *file, int flags, int mode) { (void)r; (void)flags; (void)mode; int fd; #ifdef MEDIA_DRIVE if (strncmp(file, "media/", 6) == 0) { _drive_num = 1; if (strcmp(file + strlen(file) - 4, ".fon") == 0 || strcmp(file + strlen(file) - 4, ".mod") == 0) { fd = 4; } else { fd = 5; } } else { _drive_num = 0; fd = 3; } #else fd = (strcmp(file + strlen(file) - 4, ".fon") == 0) || strcmp(file + strlen(file) - 4, ".mod") == 0 ? 4 : 3; #endif if(file_open[fd-3]) { dbgprintf("_open_r(%d): file already open.\n", fd-3); return -1; } else { pf_switchfile(&fat[fd-3]); int res=pf_open(file); if(res==FR_OK) { dbgprintf("_open_r(%d): pf_open (%s) flags: %d, mode: %d ok\r\n", fd-3, file, flags, mode); if (flags & O_CREAT) pf_maximize_file_size(); file_open[fd-3]=true; return fd; } else { dbgprintf("_open_r(%d): pf_open failed: %d\r\n", fd-3, res); return -1; } } }
bool ProgrammerConfig_ProcessConfiguration(void) { memset(&ProgrammerConfig, sizeof(ProgrammerConfig), 0x00); if (!(pf_open("CONF.txt") == FR_OK)) { puts(" >> ERROR: CONF.txt File Not Found.\r\n"); return false; } char LineBuff[100]; char* CurrentLine; do { CurrentLine = fgets(LineBuff, sizeof(LineBuff), &DiskStream); if (CurrentLine) { sscanf(CurrentLine, "SIGNATURE = %02x %02x %02x %02x", &ProgrammerConfig.SigBytes[0], &ProgrammerConfig.SigBytes[1], &ProgrammerConfig.SigBytes[2], &ProgrammerConfig.SigBytes[3]); sscanf(CurrentLine, "SPEED = %lu", &ProgrammerConfig.ProgrammingSpeed); } } while (CurrentLine); printf(" >> *** Configuration: ***\r\n"); printf(" >> Device Signature: 0x%02x 0x%02x 0x%02x 0x%02x\r\n", ProgrammerConfig.SigBytes[0], ProgrammerConfig.SigBytes[1], ProgrammerConfig.SigBytes[2], ProgrammerConfig.SigBytes[3]); printf(" >> Programming Speed: %lu Hz\r\n", ProgrammerConfig.ProgrammingSpeed); return true; }
void image_loadimagefromfile(FATFS* fs, image* image, const char* path, bool compressed) { FRESULT result; uint16_t len; // open the file result = pf_open(path); // get the width and height pf_read(&(image->width), 2, &len); pf_read(&(image->height), 2, &len); // get the size of the file if this is a compressed image unsigned cdatalen = fs->fsize - 4; // calculate the size of the raw data unsigned int rlen = 2 * (image->width * image->height); //printf("compressed image is %u * %u, compressed data is %u bytes\n", (unsigned) image->width, // (unsigned) image->height, cdatalen); uint8_t* rawdata = malloc(rlen); if (compressed) { uint8_t* compresseddata = malloc(cdatalen); pf_read(compresseddata, cdatalen, &len); if (lzfx_decompress(compresseddata, cdatalen, rawdata, &rlen) == 0) { //printf("decompressed!\n"); free(compresseddata); } } else { pf_read(rawdata, rlen, &len); } image->data = rawdata; }
uint16_t testSDCard(void) { FATFS fatfs; /* File system object */ DIR dir; /* Directory object */ FILINFO fno; /* File information object */ WORD bw, br, i; BYTE buff[64]; print("Mount a volume."); RET(); FRESULT rc = pf_mount(&fatfs); if (rc) die(rc); print("Open a test file (message.txt)."); RET(); rc = pf_open("MESSAGE.TXT"); if (rc) die(rc); print("Type the file content."); RET(); for (;;) { rc = pf_read(buff, sizeof(buff), &br); /* Read a chunk of file */ if (rc || !br) break; /* Error or end of file */ for (i = 0; i < br; i++) /* Type the data */ putchar(buff[i]); } if (rc) die(rc); #if _USE_WRITE sprintf(string,"\nOpen a file to write (write.txt).\n"); print(string); rc = pf_open("WRITE.TXT"); if (rc) die(rc); sprintf(string,"\nWrite a text data. (Hello world!)\n"); print(string); for (;;) { rc = pf_write("Hello world!\r\n", 14, &bw); if (rc || !bw) break; } if (rc) die(rc); sprintf(string,"\nTerminate the file write process.\n"); print(string); rc = pf_write(0, 0, &bw); if (rc) die(rc); #endif #if _USE_DIR print("Open root directory."); RET(); rc = pf_opendir(&dir, ""); if (rc) die(rc); print("Directory listing..."); RET(); for (;;) { rc = pf_readdir(&dir, &fno); /* Read a directory item */ if (rc || !fno.fname[0]) break; /* Error or end of dir */ if (fno.fattrib & AM_DIR) { print(" <dir> "); print(fno.fname); RET(); } else { printInt((uint8_t*)&fno.fsize, sizeof(fno.fsize)); print(fno.fname); RET(); } } if (rc) die(rc); #endif print("\nTest completed.\n"); while(1) { delay_ten_us(50000); delay_ten_us(50000); P1OUT ^= (1 << RED_LED); } return 0xaa55; }