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; }
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; }
static DWORD load_header (void) /* 0:Invalid format, 1:I/O error, >=1024:Number of samples */ { DWORD sz, f; BYTE b, al = 0; if (pf_read(Buff, 12, &rb)) return 1; /* Load file header (12 bytes) */ if (rb != 12 || LD_DWORD(Buff+8) != FCC('W','A','V','E')) return 0; for (;;) { wdt_reset(); pf_read(Buff, 8, &rb); /* Get Chunk ID and size */ if (rb != 8) return 0; sz = LD_DWORD(&Buff[4]); /* Chunk size */ switch (LD_DWORD(&Buff[0])) { /* Switch by chunk ID */ case FCC('f','m','t',' ') : /* 'fmt ' chunk */ if (sz & 1) sz++; /* Align chunk size */ if (sz > 100 || sz < 16) return 0; /* Check chunk size */ pf_read(Buff, sz, &rb); /* Get content */ if (rb != sz) return 0; if (Buff[0] != 1) return 0; /* Check coding type (LPCM) */ b = Buff[2]; if (b != 1 && b != 2) return 0; /* Check channels (1/2) */ GPIOR0 = al = b; /* Save channel flag */ b = Buff[14]; if (b != 8 && b != 16) return 0; /* Check resolution (8/16 bit) */ GPIOR0 |= b; /* Save resolution flag */ if (b & 16) al <<= 1; f = LD_DWORD(&Buff[4]); /* Check sampling freqency (8k-48k) */ if (f < 8000 || f > 48000) return 4; OCR0A = (BYTE)(F_CPU / 8 / f) - 1; /* Set sampling interval */ break; case FCC('d','a','t','a') : /* 'data' chunk */ if (!al) return 0; /* Check if format is valid */ if (sz < 1024 || (sz & (al - 1))) return 0; /* Check size */ if (Fs.fptr & (al - 1)) return 0; /* Check word alignment */ return sz; /* Start to play */ case FCC('D','I','S','P') : /* 'DISP' chunk */ case FCC('L','I','S','T') : /* 'LIST' chunk */ case FCC('f','a','c','t') : /* 'fact' chunk */ if (sz & 1) sz++; /* Align chunk size */ pf_lseek(Fs.fptr + sz); /* Skip this chunk */ break; default : /* Unknown chunk */ return 0; } } return 0; }
tBool play() { bufferPlayed = 0; bufferToDownload = 0; sample = 0; totalPlayed = 0; refil = FALSE; bytesReaded = 0; tU32 i = 0; pf_lseek(ws2.byteToOmmit); //wypełniamy na sam początek czymś do { rc = pf_read(buffer[i], sizeof(buffer[i]), &bytesReaded); i++; } while (i < BUFFCOUNT && !rc && bytesReaded); tU32 uplynelo = 0; tU32 czasCalkowity = ws2.subChunkSize / ws1.byteRate; //ilość próbek przez prędkosć odtwarzania tU32 pozostalo = 0; while (totalPlayed < ws2.subChunkSize) { if (sample >= (BUFFSIZE)) { sample = 0; bufferToDownload = bufferPlayed++; refil = TRUE; } if (bufferPlayed >= BUFFCOUNT) bufferPlayed = 0; if (ws1.bitsPerSample == 8) DACR = buffer[bufferPlayed][sample++] << 5; else if (ws1.bitsPerSample == 16) DACR = ((buffer[bufferPlayed][sample++] << 8) + (buffer[bufferPlayed][sample++])) << 5; if (refil) { //uzupełnij bufor nawet jak zapauzowane rc = pf_read(buffer[bufferToDownload], sizeof(buffer[bufferToDownload]), &bytesReaded); refil = FALSE; } else if (refil == FALSE) { if (totalPlayed % ws1.byteRate != 0) sleep(1000000 / (ws1.byteRate + 2500)); //trzeba przyśpieszyć mimo wszystko o jakieś 2500 próbek //ekran bowiem daje za duże opóźnienia :/ i tak to nie jest //doskonałe //gdy odczyt z karty, to on służy za opóxnienie, więc nie czekaj } totalPlayed++; } return TRUE; }
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; }
static uint8_t seek(uint32_t offset) { uint8_t dummy[8]; WORD br; while (offset>8) { if (pf_read(&dummy, 8, &br)) return 1; if (br != 8) return 1; offset -= 8; } if (pf_read(&dummy, offset, &br)) return 1; if (br != offset) return 1; return 0; }
/* Read data in chunks from the storage and report progress */ static unsigned long read_progress(void *dst, /* Pointer to the read buffer */ unsigned long blength, /* Number of bytes to read */ /* progress and total are used to track and report progress */ unsigned long *progress, unsigned long total) { unsigned short len; unsigned short brs; FRESULT res = FR_OK; while (blength) { if (blength > 0xFFFF) len = 0xFFFF; else len = blength; res = pf_read(dst, len, &brs); if (res != FR_OK) { break; } *progress += len; dst += len; blength -= len; report_load_progress(*progress, total); } return res; }
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; }
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; }
/** Returns exception on error, number of bytes read on success (or partial * success) **/ int FileRead(char *buf, uint32_t len) { ++fileStateVersion; WORD bytesRead=0; if (pf_read(buf, len, &bytesRead) != RES_OK) ERRORreturn2("FileRead failed",0); return bytesRead; }
FRESULT PFFS::read ( void *buff, /* Pointer to data buffer */ WORD btr, /* Number of bytes to read */ WORD *br /* Pointer to number of bytes read */ ) { return pf_read(buff, btr, br); //ok }
int PETITFS::read() { rc = pf_read(buff, sizeof(char), &br); /* Read a chunk of file */ if (rc || !br) return -1; /* Error or end of file */ else return (int)buff[0]; }
static DWORD load_header (void) /* 0:Invalid format, 1:I/O error, >1:Number of samples */ { DWORD sz; if (pf_read(Buff1, 12, &rb)) return 1; /* Load file header (12 bytes) */ if (rb != 12 || LD_DWORD(Buff1+8) != FCC('W','A','V','E')) return 0; for (;;) { pf_read(Buff1, 8, &rb); /* Get Chunk ID and size */ if (rb != 8) return 0; sz = LD_DWORD(&Buff1[4]); /* Chunk size */ switch (LD_DWORD(&Buff1[0])) { /* FCC */ case FCC('f','m','t',' ') : /* 'fmt ' chunk */ if (sz > 100 || sz < 16) return 0; /* Check chunk size */ pf_read(Buff1, sz, &rb); /* Get content */ if (rb != sz) return 0; if (Buff1[0] != 1) return 0; /* Check coding type (1) */ if (Buff1[2] != 1 && Buff1[2] != 2) /* Check channels (1/2) */ return 0; if (Buff1[14] != 8 && Buff1[14] != 16) /* Check resolution (8/16) */ return 0; OCR0A = (BYTE)(F_CPU/8/LD_WORD(&Buff1[4]))-1; /* Sampling freq */ break; case FCC('d','a','t','a') : /* 'data' chunk (start to play) */ return sz; case FCC('L','I','S','T') : /* 'LIST' chunk (skip) */ case FCC('f','a','c','t') : /* 'fact' chunk (skip) */ pf_lseek(Fs.fptr + sz); break; default : /* Unknown chunk (error) */ return 0; } } return 0; }
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(); } }
int main(int argc, char *argv[]) { if (pf_init()) err(1, "pf_init"); if (pf_read()) err(1, "pf_read"); return (0); }
/** Stream character fetching routine for the FAT driver so that characters from the currently open file can be * read in sequence when applied to a stdio stream. */ static int Disk_getchar(FILE* Stream) { char ReadByte; WORD ByteWasRead; if (pf_read(&ReadByte, 1, &ByteWasRead) != FR_OK) return _FDEV_ERR; return (ByteWasRead ? ReadByte : _FDEV_EOF); }
uint8_t parse_wav_header(void) { WAVChunk_t WAVChunk; WAVfmtChunkData_t WAVfmt; WORD br; pf_read(&WAVChunk, sizeof(WAVChunk_t), &br); if (br != sizeof(WAVChunk_t)) return 1; if (WAVChunk.chunk_id != 0x46464952) return 1; // "RIFF" pf_read(&WAVChunk, 4, &br); if (br != 4) return 1; if (WAVChunk.chunk_id != 0x45564157) return 1; // "WAVE" while(1) { if (pf_read(&WAVChunk, sizeof(WAVChunk_t), &br)) return 1; if (br != sizeof(WAVChunk_t)) return 1; switch (WAVChunk.chunk_id) { case 0x20746d66: // "fmt " if (WAVChunk.chunk_size < sizeof(WAVfmtChunkData_t)) return 1; if (pf_read(&WAVfmt, sizeof(WAVfmtChunkData_t), &br)) return 1; if (br != sizeof(WAVfmtChunkData_t)) return 1; if (WAVfmt.audio_format != 1 || (WAVfmt.num_channels != 1 && WAVfmt.num_channels != 2) || (WAVfmt.sample_rate != 48000 && WAVfmt.sample_rate != 44100 && WAVfmt.sample_rate != 22050 && WAVfmt.sample_rate != 11025 && WAVfmt.sample_rate != 8000) || (WAVfmt.bits_per_sample != 8 && WAVfmt.bits_per_sample != 16) || (WAVfmt.num_channels == 2 && WAVfmt.sample_rate == 48000 && WAVfmt.bits_per_sample == 16) || WAVfmt.block_align > 4) return 2; wavinfo.num_channels = WAVfmt.num_channels; wavinfo.sample_rate = WAVfmt.sample_rate; wavinfo.bits_per_sample = WAVfmt.bits_per_sample; wavinfo.block_align = WAVfmt.block_align; if (WAVChunk.chunk_size > sizeof(WAVfmtChunkData_t)) { if (seek(WAVChunk.chunk_size - sizeof(WAVfmtChunkData_t))) return 1; } break; case 0x61746164: // "data" wavinfo.data_length = WAVChunk.chunk_size; return 0; default: if (seek(WAVChunk.chunk_size)) return 1; } } }
// ****************** 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; }
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; }
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; }
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; }
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 _read_r (struct _reent *r, int fd, char * ptr, int len) { (void)r; if(fd>2 && file_open[fd-3]) { #ifdef MEDIA_DRIVE _drive_num = fd == 3 ? 0 : 1; #endif if(len <= 0xffff) { WORD bytes_read; pf_switchfile(&fat[fd-3]); int res=pf_read(ptr, len, &bytes_read); dbgprintf("_read_r: len %d, bytes_read %d, result %d\r\n", len, bytes_read, res); if(res==FR_OK) return bytes_read; } } errno=EINVAL; return -1; }
// 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; }
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 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 (;;) ; }
alien_rc SDCARD_read (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 SDCARD you need has been locked for you if (SDCARD_locked_by_PID != scheduler_running_PID ()) return DRIVER_INCORRECT_PID; // now read from the file current_parameters->_rc = pf_read (current_parameters->_buffer, current_parameters->_no_bytes, &(current_parameters->_read)); if (current_parameters->_rc == FR_OK) return DRIVER_READ_OK; else return DRIVER_READ_ERROR; }
int CircularBuffer_task(void) { if (state == STATE_SOURCE_EXAUSTED) return -1; if (state == STATE_FILL_DEQUEUED) { WORD bytesRead; FRESULT rc; rc = pf_read(dequeued, sizeof(uint16_t) * SIZE, &bytesRead); die(rc); if (bytesRead < (sizeof(uint16_t) * SIZE)) { state = STATE_SOURCE_EXAUSTED; } //divide by two wordsAvailable += bytesRead >> 1; state = STATE_FILLED_DEQUEUED; }