[an error occurred while processing this directive]
|
To implement low-level functionality of the stdin and stdout streams, you must write
the functions __read and __write, respectively. You can find template source code for
these functions in the arm/src directory.
If you intend to rebuild the library, the source files are available in the template library
project, see Building and using a customized library, page 51. Note that customizing the
low-level routines for input and output does not require you to rebuild the library.
Note: If you write your own variants of __read or __write, special considerations
for the C-SPY runtime interface are needed, see C-SPY Debugger runtime interface,
page 64.
Example of using __write and __read
The code in the following examples use memory-mapped I/O to write to an LCD
display:
__no_init volatile unsigned char LCD_IO @ address;
size_t __write(int Handle, const unsigned char * Buf, size_t
Bufsize)
{
int nChars = 0;
/* Check for stdout and stderr
(only necessary if file descriptors are enabled. */
if (Handle != 1 && Handle != 2)
{
return -1;
}
for (/*Empty */; Bufsize > 0; --Bufsize)
{
LCD_IO =* Buff++;
++nChars;
}
return nChars;
}
size_t __read(int Handle, unsigned char *Buf, size_t BufSize)
{
int nChars = 0;
/* Check for stdin
(only necessary if FILE descriptors are enabled) */
if (Handle != 0)
{
return -1;
}
for (/*Empty*/; BufSize > 0; --BufSize)
{
int c = LCD_IO;
if (c < 0)
break;
*Buf ++= c;
++nChars;
}
return nChars;
}
For information about the @operator, see Data and function placement in segments,
page 38.
E-mail: info@telesys.ru