This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C File I/O (fread) Problem

I'm using CCS 3.3.82.13 along with the cgtools 6.1.13. the target is the CPU cycle-accurate 64xx simulator.

I'm building an application to read some test vectors into the DSP from the PC filesystem using the C file I/O system (fopen, fread, fwrite, fclose, feof).The application is a simple C application (no DSP/BIOS) running in the 512kB core SRAM.

The problem is in the fread()/feof() functions. I'm first reading a few bytes of header information with fread(), then I begin reading 16-bit samples in chunks of BUFFER_LENGTH. The header fread()s work perfectly. However, after 50 or so bytes of samples are read (the exact number changes somewhat), fread() begins returning 0 bytes read and feof() returns true, even though the actual file size is about 32k bytes. 

Here are the things I've tried:

  1. Varying the BUFFER_LENGTH from 1 to 16 to 128 to 256 to 1024 - no change.

   2. Increasing the heap (.sysmem) and stack (.stack) to 128k bytes each. no change.

  3. Creating a linker command file and explicitly placing all the sections.

  4. Aligning the .cio section to a 256-byte boundary.

  5. Upgrading the toolchain (the previous version was 6.0.x).

 

Please help!

 

--Randy Yates

  • If the file is a binary file, make sure that you open it in "rb" mode or else make sure there are no Ctrl-Z's in the file.  Otherwise, there's nothing I can think of which would be configurable which could potentially cause this sort of problem.  It sounds more like a stray write trashing the CIO data structures than anything else.  Once you've gotten one read to work, they should all work properly.  If you have a cutdown which reproduces the problem, we could have a look at it.

  • "rb" was it! Thanks so much, Archaeologist!!!!

     

    --Randy