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 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; }
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; }
fs::inode_ptr petit< Block >::mount() { m_block.init(); m_block.open(); // Pass block device bindings // that will be used by internal fat routines m_fat.disk = { reinterpret_cast< void * >(&m_block), disk_initialize, disk_writep, disk_readp }; // TODO: error check! auto res = pf_mount(&m_fat); if (res == FR_OK) { ecl::cout << "Mounted!" << ecl::endl; } else { ecl::cout << "Mount error: " << res << ecl::endl; } auto iptr = ecl::allocate_shared< dir_inode >(m_alloc, &m_fat, m_alloc); iptr->set_weak(iptr); // TODO; return iptr; }
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(); } }
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 FS_Mount() { int res = pf_mount(&fat[0]); dbgprintf("Mount: %d\n", res); #ifdef MEDIA_DRIVE _drive_num = 1; int res2 = pf_mount(&fat[2]); (void)res2; dbgprintf("Mount2: %d\n", res2); fat[1] = fat[2]; _drive_num = 0; #else fat[1] = fat[0]; #endif if (res == FR_OK) { init_err_handler(); pf_switchfile(&fat[0]); } return (res == FR_OK); }
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")); }
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 }
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; }
FRESULT PFFS::mount ( //unsigned char vol, /* Logical drive number to be mounted/unmounted */ FATFS *fs /* Pointer to new file system object (NULL for unmount) */ ) { FRESULT res; //SPI.setClockDivider(128); SPI_SET_DIVIDER(_clkdivider); res = pf_mount(fs); //ok //SPI.setClockDivider(_clkdivider); SPI_SET_DIVIDER(_clkdivider); return res; }
void EVENT_USB_Host_DeviceEnumerationComplete(void) { LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); uint16_t ConfigDescriptorSize; uint8_t ConfigDescriptorData[512]; if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData, sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } if (MS_Host_ConfigurePipes(&DiskHost_MS_Interface, ConfigDescriptorSize, ConfigDescriptorData) != MS_ENUMERROR_NoError) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } uint8_t MaxLUNIndex; if (MS_Host_GetMaxLUN(&DiskHost_MS_Interface, &MaxLUNIndex)) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } if (MS_Host_ResetMSInterface(&DiskHost_MS_Interface)) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } SCSI_Request_Sense_Response_t SenseData; if (MS_Host_RequestSense(&DiskHost_MS_Interface, 0, &SenseData) != 0) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } pf_mount(&DiskFATState); LEDs_SetAllLEDs(LEDMASK_USB_READY); }
// Tries to init SD card static tU8 findAndInitSD() { result = pf_mount(&fatfs); if (result) { if (FR_DISK_ERR == result || FR_NOT_READY == result) { printf("Blad interfejsu"); } else if (FR_NO_FILESYSTEM == result) { printf("Nieprawidlowy system plikow lub jego brak na karcie pamieci"); } return FALSE; } return TRUE; }
void FileInit() { fprintf_P(stderr, PSTR("FileInit()\n")); #ifdef AVR fprintf_P(stderr, PSTR("Probing for SD Card...\n")); #else diskfilename = getenv("FAT"); if (!diskfilename) ERRORreturn("No FAT environment variable set to fat image\n"); else fprintf(stderr, "FileInit trying to use image %s\n",diskfilename); #endif int res = disk_initialize(); if (res != FR_OK) ERRORreturn("disk_initialize failed"); fprintf_P(stderr, PSTR("pf_mount...\n")); res = pf_mount(&fatfs); if (res != FR_OK) ERRORreturn("pf_mount failed"); }
// 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 (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 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; }
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 (;;) ; }
void setup_lcd_fs(void){ _disable_interrupts(); WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_16MHZ; /* Set DCO for 16 MHz */ DCOCTL = CALDCO_16MHZ; delay_ms(100); // Initialize SD card: spi_initialize(); dres = disk_initialize(); tft_init_hw(); tft_begin(); tft_fillScreen(ILI9340_WHITE); tft_setCursor(0, 1); tft_setTextColor(ILI9340_BLACK); tft_setTextSize(1); if (dres){ sprintf(buffer, "Disk error = %d\n", (int) dres); tft_writeString(buffer); while (1); } pres = pf_mount(&fs); if (pres){ sprintf(buffer, "PFF error 1 = %d\n", (int) pres); tft_writeString(buffer); while (1); } tft_fillScreen(ILI9340_WHITE); P1DIR |= BIT0 | BIT1; P1OUT &= ~ (BIT0 | BIT1); }
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; }
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; }
BOOL PETITFS::begin() { rc = pf_mount(&fatfs); return (!rc)? TRUE:FALSE; }
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; }
int main(void) { FRESULT res; WORD br; sei(); // Globally enable interrupts hibernate_init(); DAC_init(); keys_init(); if (pf_mount(&fs)) { sound_osch(); } else { sound_gut(); } while(1) { cli(); // disable interrupts to avoid race condition with sleep function if (FLAG_CHECK(NEW_SOUND)) { hibernate_timer_stop(); FLAG_CLEAR(NEW_SOUND); sei(); switch (special_mode) { case 1: if (new_sound_id == old_sound_id - 1) { special_mode = 2; goto sound_ende; } else if (new_sound_id == old_sound_id + 1) { special_mode = 4; goto sound_ende; } else if (new_sound_id == old_sound_id) { credits_counter = CREDITS_COUNTER_MAX - 5; special_mode = 0; goto sound_ende; } else special_mode = 0; break; case 2: special_mode = 3; break; case 4: special_mode = 5; break; default: special_mode = 0; } if (new_sound_id == 36) { special_mode = 1; goto sound_ende; } old_sound_id = new_sound_id; char* filename; if (++credits_counter > CREDITS_COUNTER_MAX) { credits_counter = 0; filename = "image.hex"; } else { if (new_sound_id == 255) goto sound_ende; filename = filenames(bank, new_sound_id); } uint8_t tries = 3; while (pf_open(filename) && pf_open("error1.wav")) { if ((tries--) == 0) goto sound_ende; _delay_ms(10); pf_mount(&fs); } if (parse_wav_header()) { if (pf_open("error2.wav") || parse_wav_header()) goto sound_ende; } do { #define read_length 16384 if (wavinfo.data_length > read_length) { res = pf_read(0, read_length, &br); wavinfo.data_length -= read_length; } else { res = pf_read(0, wavinfo.data_length, &br); break; } } while (res==0 && br==read_length && wavinfo.data_length>0 && !FLAG_CHECK(NEW_SOUND)); stop_audio(); sound_ende: hibernate_timer_init(); } else { sleep_enable(); sei(); sleep_cpu(); sleep_disable(); } hibernate_check(); } }
/* Main */ int main (void) { // setare pin 5 (difuzor) si pin 6 (CS_SD) al portului A ca pin de iesire DDRD |= (1<<PD5) | (1<<PD6); // setam toti pinii portului C ca pini de iesire DDRC = 0xFF; DDRB &= ~(1<<PB0); DDRB &= ~(1<<PB1); PORTB |= (1<<PB1) | (1<<PB0); PORTD &= ~((1<<PD5) | (1<<PD6)); PORTD &= ~((1<<PD5) | (1<<PD6)); LCD_init(); sei(); for (;;) { _delay_ms(1000); /* Delay 1000ms for things to settle down */ if (pf_mount(&Fs)) { continue; /* Initialize FS */ } if (pf_opendir(&Dir, "wav")) break; /* Open /wav folder */ int state = STAHPED; char* filename, first_wav, last_wav_played; if (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) /* go to next file*/ { if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, "WAV")) /* filter out all the folders, hidden files and the files that are not "WAV" */ { /* display the filename on the LCD */ LCD_print(Fno.fname); strcpy(first_wav, Fno.fname); } } while(1) { /* check if button on PA3 (start/stahp) is pressed */ if (!(PINA & (1 << PA3))) { if (state == STAHPED) { state = STARTED; LCD_print(Fno.fname); play(strcat("wav", Fno.fname)); // play song } else { state = STAHPED; LCD_print(Fno.fname); FifoCt = 0; // stop melody } } /* check if button on PA2 (next) is pressed */ if (!(PINA & (1 << PA2))) { sprintf(last_wav_played, "%s", Fno.fname); if (state == STARTED) { if (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) /* go to next file*/ { if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, "WAV")) /* filter out all the folders, hidden files and the files that are not "WAV" */ { /* display the filename on the LCD */ LCD_print(Fno.fname); /* play the WAV file */ play(strcat("wav", Fno.fname)); } } } else { if (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) /* go to next file*/ { if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, "WAV")) /* filter out all the folders, hidden files and the files that are not "WAV" */ { /* display the filename on the LCD */ LCD_print(Fno.fname); } } } } /* check if button on PA1 (previous) is pressed */ if (!(PINA & (1 << PA1))) { if (state == STARTED) { if (strcmp(last_wav_played, first_wav) != 0 ) { /* display the filename on the LCD */ LCD_print(last_wav_played); /* play the WAV file */ play(strcat("wav", last_wav_played)); } else /* display the filename on the LCD */ LCD_print(first_wav); } else if (strcmp(last_wav_played, first_wav) != 0 ) /* display the filename on the LCD */ LCD_print(last_wav_played); } } } return 1; }
void FS_Unmount() { pf_mount(0); }
int main(void) { lcd_init(); ds1307_init(); adc_init(); timer_init(); asm("sei"); /* //test lcd_str("Hello, World"); lcd_gotoxy(1,0); lcd_str("by shtomik"); _delay_ms(1000); lcd_clr(); lcd_str("after clr");*/ start_t(); //test ds1307_setdate(12, 12, 31, 23, 01, 35); //смонтировать microSD res = pf_mount(&fs); if(res == FR_OK) { //диск смонтирован и мы продолжаем работу if(pf_open("test.txt") == FR_OK) { //открыли файл в корне test.txt //... pf_lseek(0); //заполняем буффер, надо набрать 512 байт инфы и писать //иначе будет много лишних пробелов //sprintf(buff, "%s\n%s", "Hello,World!", "by_sht"); //записываем его на карту pf_write(buff, 512, &br); //финализируем запись pf_write(NULL, 0, &br); pf_lseek(512); pf_write(buff, 512, &br); //финализируем запись pf_write(NULL, 0, &br); lcd_clr(); lcd_str("ok"); } else { //file not found or ... lcd_str("file not found"); } //демонтируем диск передав функции нулевой указатель pf_mount(NULL); lcd_clr(); lcd_str("file write"); } else { //не удалось смонтировать диск lcd_clr(); lcd_str("not flash"); } while( 1 ) { ; } return 0; }
int main (void) { FRESULT res; char *dir; BYTE org_osc = OSCCAL; BYTE ndir = 0; BYTE nskip = 0; BYTE nplay = 0; // 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(); /*-----------------------------------------------------------------------*/ /* POWER ON and RESET */ ndir = eeprom_read_byte((uint8_t*)DIR_EEADR); if(bit_is_set(MCUSR, PORF)) { // Power on - resume playback! MCUSR = 0; // clear MCUSR } if(bit_is_set(MCUSR, WDRF)) { // WatchDog reset - on error! MCUSR = 0; // clear MCUSR if (ndir !=0) { ndir = 0; // resetdirectory nskip = 0; // resetdirectory eeprom_write_byte ((uint8_t*)SKIP_EEADR, (uint8_t*) nskip); eeprom_write_byte ((uint8_t*)DIR_EEADR, (uint8_t*) ndir); // for (;;) { // PORTB ^= _BV(PB1); // delay_ms(200); // wdt_reset(); // } } } if(bit_is_set(MCUSR, EXTRF)) { // Reset button. MCUSR = 0; // clear MCUSR ndir++; // advance mode // for (;;) {wdt_reset();} wdt_reset(); if(ndir > MAX_DIR) { ndir = 0; // resetdirectory } nskip = 0; // resetdirectory eeprom_write_byte ((uint8_t*)SKIP_EEADR, (uint8_t*) nskip); eeprom_write_byte ((uint8_t*)DIR_EEADR, (uint8_t*) ndir); } /*-----------------------------------------------------------------------*/ /* How many songs need to skip */ str[0] =48+ndir/10; str[1] = 48+ndir%10; str[2] = 0; PLAYMOD=0; if (pf_mount(&Fs) == FR_OK) { /* Initialize FS */ res = pf_opendir(&Dir, dir = str); /* Open sound file directory */ res = play(dir, "i"); /* Play intro file */ res = play(dir, "n"); /* Play name file */ /* PLAY mode 0 normal, 1 repeat loop, 2 only one file */ if (play(dir, "r") == FR_OK) { PLAYMOD=1; //repeat loop } if (play(dir, "o") == FR_OK) { PLAYMOD=2; //only one file } } nskip = eeprom_read_byte((uint8_t*)SKIP_EEADR); // FR_OK = 0 for (;;) { if (pf_mount(&Fs) == FR_OK) { /* Initialize FS */ wdt_reset(); // Buff[0] = 0; // if (!pf_open("osccal")) pf_read(Buff, 1, &rb); /* Adjust frequency */ // OSCCAL = org_osc + Buff[0]; res = pf_opendir(&Dir, dir = str); /* Open sound file directory */ if (res == FR_NO_PATH) res = pf_opendir(&Dir, dir = ""); /* Open root directory */ while (res == FR_OK) { /* Repeat in the dir */ res = pf_readdir(&Dir, 0); /* Rewind dir */ nplay=0; 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]) break; /* Break on error or end of dir */ if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, ".WAV")) if (nplay >= nskip) { do { res = play(dir, Fno.fname); /* Play file */ wdt_reset(); } while (((PINB & 1) == 1) && (PLAYMOD == 1)); delay500(); /* Delay 500ms in low power sleep mode */ if (res == FR_OK) { eeprom_write_byte ((uint8_t*)SKIP_EEADR, (uint8_t*) nplay+1); nskip=0; /* PLAY mode 0 normal, 1 repeat loop, 2 only one file */ // PORTB ^= _BV(PB1); if (PLAYMOD == 2) { do { delay_ms(30); wdt_reset(); } while ((PINB & 1) == 1); do { delay_ms(50); wdt_reset(); } while ((PINB & 1) == 0); delay_ms(500); } } } nplay++; // playing song nr } } } } }
/** Event to handle mode changes in the library, to clear the FAT library's drive state structure when transitioning * between modes. This ensures that the library always works with current disk data. */ void EVENT_USB_UIDChange(void) { pf_mount(&DiskFATState); }