7-16
EPSOn
S5U1C17001C ManUal
(C COMPilEr PaCkagE fOr S1C17 faMily) (Ver. 1.5.0)
7 liBrary
7.3.4 lower-level functions
The following three functions (
read
,
write
, and
_exit
) are the lower-level functions called by library
functions. A
read
and a
write
function have been defined in the
libstdio.a
library. Before these functions
can be used, include "
\include\libstdio.h
" in the C source program and call the
_init_sys()
function.
The
_exit
function must be defined in the user program.
For how to use the
libstdio.a
, refer to the sample file "
\gnu17\sample\S1C17common\simulator\
simulatedIO
".
read
function
Contents of
read
function
Format:
int read(int fd, char *buf, int nbytes);
Argument:
int fd;
File descriptor denoting input
When called from a library function, 0 (stdin) is passed.
char *buf;
Pointer to the buffer that stores input data
int nbytes;
Number of bytes transferred
Functionality: This function reads up to
nbytes
of data from the user-defined input buffer, and stores it
in the buffer indicated by
buf
.
Returned value: Number of bytes actually read from the input buffer
If the input buffer is empty (EOF) or
nbytes
= 0, 0 is returned.
If an error occurs, -1 is returned.
Library functions that call the
read
function:
Direct call: f
read
,
getc
,
_doscan
(
_doscan
is a
scanf
-series internal function)
Indirect call:
fgetc
,
fgets
,
getchar
,
gets
(calls
getc
)
scanf
,
fscanf
,
sscanf
(calls
_doscan
)
Definition of input buffer
Format:
unsigned char READ_BUF[65];
(Variable name is arbitrary; size is fixed to 65 bytes)
unsigned char READ_EOF;
Buffer contents: The size of the input data (1 to max. 64) is stored at the beginning of the buffer
(
READ_BUF[0]
). 0 denotes EOF.
The input data is stored in
READ_BUF[1]
, and the following locations.
READ_EOF
stores the status that indicates whether EOF is reached.
Precautions on using a simulated i/O
When using the debugger's simulated I/O, define in the
read
function the global label
READ_FLASH
that
is required for the debugger to update the input buffer, then create the function so that new data will be
read into the input buffer at that position. (For details about the simulated I/O function, refer to the chapter
where the debugger is discussed.)
A
read
function has been defined in the
libstdio.a
library. To use the
read
function, link
libstdio.a
and call the
_init_sys()
function from the boot routine in the user program.
Summary of Contents for S5U1C17001C
Page 6: ......
Page 17: ...1 General S5U1C17001C Manual 1 General ...
Page 18: ......
Page 21: ...1 2 Install S5U1C17001C Manual 2 Installation ...
Page 22: ......
Page 29: ...3 SoftDev S5U1C17001C Manual 3 Software Development Procedures ...
Page 30: ......
Page 103: ...4 SrcFiles S5U1C17001C Manual 4 Source files ...
Page 104: ......
Page 121: ...5 IDE S5U1C17001C Manual 5 gnU17 iDE ...
Page 122: ......
Page 365: ...6 Compiler S5U1C17001C Manual 6 C Compiler ...
Page 366: ......
Page 385: ...7 Library S5U1C17001C Manual 7 library ...
Page 386: ......
Page 405: ...8 Assemblr S5U1C17001C Manual 8 assembler ...
Page 406: ......
Page 439: ...9 Linker S5U1C17001C Manual 9 linker ...
Page 440: ......
Page 449: ...10 Debugger S5U1C17001C Manual 10 Debugger ...
Page 450: ......
Page 626: ...11 Tools S5U1C17001C Manual 11 Other Tools ...
Page 627: ......
Page 696: ...S1C17 Family C Compiler Package Quick Reference Reference ...