>> Semiconductor Home > Applications
Application Report Abstract

Reading and Writing Binary Files on Targets with More Than 8-bit Chars
The run-time support (RTS) library shipped with the code generation toolset includes functions such as fread() and fwrite() that can perform input/output (I/O) on host files. On some targets such as TMS320C2000?, TMS320C3000?, and TMS320C5000?, the size of a char on the target (16 or 32 bits) differs from the size of a byte on the host (8 bits). The tools have two basic alternatives for dealing with this mismatch: to pack host bytes into target words, or not to pack host bytes into target words. Either choice creates a different set of issues for reading and writing binary files. This application report describes the problem, the two alternative solutions, and the tradeoffs between them. It also explains our choice (not packed), the rationale for our choice, and the implications of that choice on application code.
o Affected tools: Code Generation Tools, Code Composer StudioE Integrated Development Environment (IDE)
o Affected targets: TMS320C54x? DSP, TMS320C55x? DSP, TMS320C20x? DSP, TMS320C24x? DSP, TMS320C27x? DSP, TMS320C28x? DSP TMS320C3x? DSP
o Applies to: fread() and fwrite() functions in RTS library
o Common customer problem reports:
? ?fread only reads a byte at a time?
? ?fread and fwrite don?t read the right number of bits?
? ?fwrite truncates data to 8 bits?