NetBurner 3.3.4
PDF Version
IOSYS - I/O System

Modules

 FD Change Type
 
 I/O Control Command Flags
 
 I/O Control Options
 

Typedefs

typedef void FDCallBack(int fd, FDChangeType change, void *pData)
 Define the function signature for file descriptor notification callbacks. More...
 

Functions

int close (int fd)
 Close the specified file descriptor and free the associated resources. More...
 
int read (int fd, char *buf, int nbytes)
 Read data from a file descriptor (fd). This function will block forever until at least one byte is available to be read (as opposed to the ReadWithTimeout() function which reads data from a file descriptor with a specified time-out value). This function can be used to read from stdio, TCP sockets, or Serial ports. More...
 
int peek (int fd, char *c)
 Peek at the data for the specified file descriptor (fd). Will block forever until at least one byte is available to be read. The byte returned is not removed from the fd buffer, it will be the first byte of data returned on any subsequent read operation. More...
 
int write (int fd, const char *buf, int nbytes)
 Write data to the stream associated with a file descriptor (fd). Can be used to write data to stdio, a TCP socket, or a Serial port. More...
 
int writestring (int fd, const char *str)
 Write a null terminated ascii string to the stream associated with a file descriptor (fd). Can be used to write data to stdio, a TCP socket, or a Serial port. More...
 
int writeall (int fd, const char *buf, int nbytes=0)
 Write the specified number of bytes to a file descriptor. Will block until all bytes are sent, or a file descriptor error occurs (such as a TCP socket error). Can be used to write data to stdio, a TCP socket, or a Serial port. More...
 
int ReadWithTimeout (int fd, char *buf, int nbytes, unsigned long timeout)
 Read data from a file descriptor (fd), or return if at least one byte is not read within the specified timeout. Can be used instead of the read() function, which will block forever until at least one byte is read. Can be used to read from stdio, TCP sockets, or Serial ports. More...
 
int ReadAllWithTimeout (int fd, char *buf, int nbytes, unsigned long timeout)
 Attempt to read the specified number of bytes from a file descriptor, or return with the number of bytes read if the timeout value has expired. More...
 
int readall (int fd, char *buf, int nbytes)
 Read the specified number of bytes from a file descriptor (fd). This function will block until either the requested number of bytes have been read, or a file descriptor error occurs. It can be used to read from stdio, TCP sockets, or Serial ports. More...
 
int PeekWithTimeout (int fd, char *c, unsigned long timeout)
 This function peeks at data from a file descriptor (fd), with a specified timeout value (as opposed to the peek function which will block forever until at least one byte is available to be read). This function can be used to peek from stdio, TCP sockets, or Serial ports. More...
 
int dataavail (int fd)
 Check the specified file descriptor to detmeine if data is available to be read. More...
 
int writeavail (int fd)
 Check the specified file descriptor to determine data can be written. More...
 
int haserror (int fd)
 Check if a file descriptor has an error. More...
 
int charavail ()
 Checks to see if data is available for read on stdin. By default, stdin is the boot/debug serial port. More...
 
void RegisterFDCallBack (int fd, FDCallBack *fp, void *pData)
 Register a callback function to receive notification when an FD state changes. Register a NULL fp to remove the notification. More...
 
void FD_ZERO (fd_set *pfds)
 Clear (set to 0) a fd_set (file descriptor set) so no file descriptors (fds) are selected. More...
 
void FD_CLR (int fd, fd_set *pfds)
 A fd_set (file descriptor set) holds a set of file descriptors (fds). This function clears or removes a specific file descriptor in an fd_set. More...
 
void FD_SET (int fd, fd_set *pfds)
 A fd_set (file descriptor set) holds a set of file descriptors (fds). This function sets or adds a specific file descriptor to an fd_set. More...
 
int FD_ISSET (int fd, fd_set *pfds)
 A fd_set (file descriptor set) holds a set of file descriptors (fds). This function checks whether or not a particular fd is set in the specified fd_set. More...
 
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, unsigned long timeout)
 Wait for events to occur on one or more I/O resources associated with a set of file descriptors (fds), such as data available to be read, a resource is available to write data, or an error has occurred. More...
 
int ZeroWaitSelect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds)
 Returns whether events have occurred on one or more I/O resources associated with a set of file descriptors (fds), and returns immediately. More...
 
int ioctl (int fd, int cmd)
 This function controls the selection of input/output control options for stdio: stdin = 0, stdout = 1 and stderr = 2. More...
 
int ReplaceStdio (int stdio_fd, int new_fd)
 Maps stdio to any file descriptor (fd). More...
 
int CurrentStdioFD (int stdio_fd)
 Returns the current file descriptor mapped to the stdio file descriptor. More...
 
void IrqStdio ()
 Open the system default serial port in interrupt mode using the system default baud rate, and assign this serial port to stdin, stdout and stderr.
 

Detailed Description

I/O system functions use file descriptors for communication and status of network interfaces, serial interfaces, and any custom file descriptors created by an application.

Typedef Documentation

◆ FDCallBack

typedef void FDCallBack(int fd, FDChangeType change, void *pData)

Define the function signature for file descriptor notification callbacks.

Parameters
fdThe file descriptor number
changeThe reason for the call back, FDChangeType
*pDataA void pointer passed into the register function. Can be used to reference objects or other data
See also
FDChangeType
RegisterFDCallBack

Function Documentation

◆ charavail()

int charavail ( )

Checks to see if data is available for read on stdin. By default, stdin is the boot/debug serial port.

Return values
1Data available
0No data available
See also
dataavail()
writeavail()
read()

◆ close()

int close ( int  fd)

Close the specified file descriptor and free the associated resources.

Parameters
fdThe file descriptor number
Returns
0 on success, or a resource specific error on failure.
See also
peek()
PeekWithTimeout()
read()
ReadWithTimeout()
write()

◆ CurrentStdioFD()

int CurrentStdioFD ( int  stdio_fd)

Returns the current file descriptor mapped to the stdio file descriptor.

Parameters
stdio_fdThe stdio file descriptor to check. Options are stdin (0), stdout (1), and stderr (2).
Returns
The current file descriptor mapped to stdio_fd

◆ dataavail()

int dataavail ( int  fd)

Check the specified file descriptor to detmeine if data is available to be read.

Parameters
fdThe file descriptor number
Return values
1Data available
0No data available
See also
charavail()
peek()
read()
ReadWithTimeout()

◆ FD_CLR()

void FD_CLR ( int  fd,
fd_set *  pfds 
)

A fd_set (file descriptor set) holds a set of file descriptors (fds). This function clears or removes a specific file descriptor in an fd_set.

Parameters
fdThe file descriptor number
*pfdsPointer to the fd_set to modify
See also
FD_ZERO()
FD_SET()
FD_ISSET()
select()

◆ FD_ISSET()

int FD_ISSET ( int  fd,
fd_set *  pfds 
)

A fd_set (file descriptor set) holds a set of file descriptors (fds). This function checks whether or not a particular fd is set in the specified fd_set.

For example:

if ( FD_ISSET( fdListen, &readFds ) )
{
// do processing for fdListen
}
int FD_ISSET(int fd, fd_set *pfds)
A fd_set (file descriptor set) holds a set of file descriptors (fds). This function checks whether or...
Definition: iosys.cpp:256
Parameters
fdThe file descriptor number
*pfdsA pointer to the fd_set to test
Return values
0File descriptor is not set in the file descriptor set
>0File descriptor is set in the file descriptor set
See also
FD_ZERO()
FD_CLR()
FD_SET()
select()

◆ FD_SET()

void FD_SET ( int  fd,
fd_set *  pfds 
)

A fd_set (file descriptor set) holds a set of file descriptors (fds). This function sets or adds a specific file descriptor to an fd_set.

Parameters
fdThe file descriptor number
*pfdsPointer to the fd_set to modify
See also
FD_ZERO()
FD_CLR()
FD_ISSET()
select()

◆ FD_ZERO()

void FD_ZERO ( fd_set *  pfds)

Clear (set to 0) a fd_set (file descriptor set) so no file descriptors (fds) are selected.

Parameters
*pfdsPointer to the file descriptor set
See also
FD_CLR()
FD_SET()
FD_ISSET()
select()

◆ haserror()

int haserror ( int  fd)

Check if a file descriptor has an error.

Parameters
fdFile descriptor number
Return values
1The file descriptor has an error
0The file descriptor does not have an error
See also
dataavail()
writeavail()
charavail()

◆ ioctl()

int ioctl ( int  fd,
int  cmd 
)

This function controls the selection of input/output control options for stdio: stdin = 0, stdout = 1 and stderr = 2.

The legal options are listed in I/O Control Options.

Parameters
fdThe file descriptor number. The three options are stdin (0), stdout (1), and stderr (2).
cmdThe ioctl command options are I/O Control Command Flags and the bit of the associated options as defined by I/O Control Options.
Returns
The old option value.
ioctl(0,IOCTL_SET| IOCTL_ALL_OPTIONS); // Sets all options
ioctl(1,IOCTL_CLR| IOCTL_ALL_OPTIONS); // Clears all options
int ioctl(int fd, int cmd)
This function controls the selection of input/output control options for stdio: stdin = 0,...
Definition: fileio.cpp:83
#define IOCTL_SET
Set an option.
Definition: iosys.h:591
#define IOCTL_CLR
Clear an option.
Definition: iosys.h:592
#define IOCTL_RX_PROCESS_EDITS
When set, process backspace and do simple line editing.
Definition: iosys.h:581
#define IOCTL_RX_CHANGE_CRLF
When set, received \r\n get turned into \n
Definition: iosys.h:580
#define IOCTL_ALL_OPTIONS
When set, turns on all options.
Definition: iosys.h:584
See also
ReplaceStdio()

◆ peek()

int peek ( int  fd,
char *  c 
)

Peek at the data for the specified file descriptor (fd). Will block forever until at least one byte is available to be read. The byte returned is not removed from the fd buffer, it will be the first byte of data returned on any subsequent read operation.

Parameters
fdFile descriptor
*cPointer to the read destination character string
Return values
1Number of bytes peeked
<0Error when reading from file descriptor
See also
TCP Socket Status
close()
read()
PeekWithTimeout()
ReadWithTimeout()
write()

◆ PeekWithTimeout()

int PeekWithTimeout ( int  fd,
char *  c,
unsigned long  timeout 
)

This function peeks at data from a file descriptor (fd), with a specified timeout value (as opposed to the peek function which will block forever until at least one byte is available to be read). This function can be used to peek from stdio, TCP sockets, or Serial ports.

The byte returned is not removed from the fd. The byte returned will be the first byte of data returned on the first subsequent read().

Parameters
fdThe file descriptor number
*cA pointer to the read destination
timeoutThe number if time ticks to wait for at least 1 byte of data
Return values
0Timeout, but the file descriptor is still valid
1Number of bytes peeked
<0 Error when reading from file descriptor
See also
TCP Socket Status
close()
peek()
read()
ReadWithTimeout()
write()

◆ read()

int read ( int  fd,
char *  buf,
int  nbytes 
)

Read data from a file descriptor (fd). This function will block forever until at least one byte is available to be read (as opposed to the ReadWithTimeout() function which reads data from a file descriptor with a specified time-out value). This function can be used to read from stdio, TCP sockets, or Serial ports.

Parameters
fdThe file descriptor number.
*bufA pointer to the read destination.
nbytesMaximum number of bytes to read.
Return values
>0Number of bytes read
<0Error when reading from file descriptor
See also
TCP Socket Status
close()
peek()
PeekWithTimeout()
ReadWithTimeout()
ReadAllWithTimeout()
readall()
write()

◆ readall()

int readall ( int  fd,
char *  buf,
int  nbytes 
)

Read the specified number of bytes from a file descriptor (fd). This function will block until either the requested number of bytes have been read, or a file descriptor error occurs. It can be used to read from stdio, TCP sockets, or Serial ports.

Parameters
fdFile descriptor
*bufPointer to the read destination buffer
nbytesNumber of bytes to read
Return values
0Timeout
>0The number of bytes read
-1File descriptor error, such a TCP socket error
See also
close()
peek()
read()
PeekWithTimeout()
ReadWithTimeout()
ReadAllWithTimeout()
write()

◆ ReadAllWithTimeout()

int ReadAllWithTimeout ( int  fd,
char *  buf,
int  nbytes,
unsigned long  timeout 
)

Attempt to read the specified number of bytes from a file descriptor, or return with the number of bytes read if the timeout value has expired.

This function can be used to read from stdio, TCP sockets, or Serial ports. This function will block until on of the following conditions occurs:

  • The requested number of bytes have been read.
  • The timeout expires. The number of bytes read are returned, and buf contains the data.
  • An error occurs on the file descripor, such as a TCP socet error.
Note
The return value must be checked to verify the number of bytes read and that a timeout or error did not occur.
Parameters
fdThe file descriptor number
*bufA pointer to the read destination
nbytesNumber of bytes to read
timeoutThe number of timer ticks to wait for data
Returns
  • <0: File descriptor error, such as an invalid TCP socket
  • >=0 but less than nbytes: Timeout occurred, returns number of bytes read.
  • nbytes: Successfully read the specified number of bytes within the timeout period
See also
close()
peek()
read()
PeekWithTimeout()
ReadWithTimeout()
readall()
write()

◆ ReadWithTimeout()

int ReadWithTimeout ( int  fd,
char *  buf,
int  nbytes,
unsigned long  timeout 
)

Read data from a file descriptor (fd), or return if at least one byte is not read within the specified timeout. Can be used instead of the read() function, which will block forever until at least one byte is read. Can be used to read from stdio, TCP sockets, or Serial ports.

Note
This function operates like the read function in that it reads all available bytes up to the maximum and returns. The addition of a timeout does not cause the function to block until the specified maximum number of bytes are available. As with read, the application must use the return value of the ReadWithTimeout function to determine how many bytes were read, and call the function again if necessary.
Parameters
fdThe file descriptor number.
*bufA pointer to the read destination.
nbytesMaximum number of bytes to read.
timeoutThe number of timer ticks to wait for data.
Return values
0Timeout
>0The number of bytes read
-1Invalid file descriptor, such as if a TCP connection is no longer valid
See also
close()
peek()
read()
PeekWithTimeout()
ReadWithTimeout()
ReadAllWithTimeout()
readall()
write()

◆ RegisterFDCallBack()

void RegisterFDCallBack ( int  fd,
FDCallBack fp,
void *  pData 
)

Register a callback function to receive notification when an FD state changes. Register a NULL fp to remove the notification.

Parameters
fdThe file descriptor number
*fpThe function pointer to call back
*pDataA void * passed to the callback function, can be used for any purpose, such as object references
See also
FDChangeType
FDCCallBack

◆ ReplaceStdio()

int ReplaceStdio ( int  stdio_fd,
int  new_fd 
)

Maps stdio to any file descriptor (fd).

If the file descriptor generates an error (such as a closed TCP connection), then stdio will be remapped to a negative fd (this will cause stdio to generate errors). When this function is used to remap a stdio channel that has errored, then the error will be cleared.

Parameters
stdio_fdThe stdio file descriptor to map to. Options are stdin (0), stdout (1), and stderr (2).
new_fdThe file descriptor to replace stdio with. A value of 0 returns stdio to the default debug monitor based traps.
Return values
0If stdio had not been previously mapped
>0The value of the fd for the previous stdio override
See also
ioctl()

◆ select()

int select ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  errorfds,
unsigned long  timeout 
)

Wait for events to occur on one or more I/O resources associated with a set of file descriptors (fds), such as data available to be read, a resource is available to write data, or an error has occurred.

The most common use for this function is to monitor multiple serial and/or TCP file descriptors at one time to read incoming data. For example, an application could use a single RTOS task and a select() to process incoming data on multiple TCP sockets at one time, instead of using multiple tasks or looping through each fd sequentially.

The file descriptors of interest are specified with file descriptor sets (fds) for read, write and error conditions. select() will block until one of the fd conditions are true, or the specified timeout occurs (a value of 0 blocks forever). For example, if the readfds is used for multiple TCP sockets, select() will return if data is available to read on one or more of them. The application would then use macros such as FD_ISSET() to handle reading the data.

Note
A timeout value can be used to cause select() to return periodically for any type of processing an application would like to do in the event no activity is occurring on the fd sets.
Parameters
nfdsThe number of file descriptors to examine (This parameter is currently ignored)
*readfdsPointer to the fd_set to select for read events, or null if no read events are to be monitored. It is modified on exit to reflect the read availability of the selected fds in the set.
*writefdsPointer to the fd_set to select for write availability events, or null if no events are to be monitored. If non-null, it is modified on exit to reflect the write availability of the selected fds in the set.
*errorfdsPointer to the fd_set to select for error events, or null if no error events are to be monitored. It is modified on exit to reflect the error state of the selected fds in the set.
timeoutThe number of system time ticks to wait before timing out if no events occurred in the selected fd sets. Note: The TICKS_PER_SECOND multiplier should be used to specify the timeout in seconds. For example, TICKS_PER_SECOND * 5 to specify a timeout of 5 seconds.
Return values
0Timeout occurred
>0The number of fds in all of the non-null fd_sets
See also
FD_ZERO()
FD_CLR()
FD_SET()
FD_ISSET()

◆ write()

int write ( int  fd,
const char *  buf,
int  nbytes 
)

Write data to the stream associated with a file descriptor (fd). Can be used to write data to stdio, a TCP socket, or a Serial port.

Note
The write function will block until at least one byte is written, but may not write all the bytes requested. For example, if you want to write 100 bytes, and there was only room in the buffer for 5, then the write() function would return 5.
Parameters
fdFile descriptor
*bufPointer to the buffer to write
nbytesMaximum number of bytes to write
Return values
0Timeout
>0The actual number of bytes written (Note: Can be less than the number of bytes requested)
<0Error occurred, such as a TCP socket error
See also
close()
peek()
read()
PeekWithTimeout()
ReadWithTimeout()
writestring()
writeall()

◆ writeall()

int writeall ( int  fd,
const char *  buf,
int  nbytes = 0 
)

Write the specified number of bytes to a file descriptor. Will block until all bytes are sent, or a file descriptor error occurs (such as a TCP socket error). Can be used to write data to stdio, a TCP socket, or a Serial port.

Parameters
fdFile descriptor
*bufPointer to the buffer to write
nbytesMaximum number of bytes to write
Return values
>=0The number of bytes written
<0Error occurred
See also
close()
peek()
read()
PeekWithTimeout()
ReadWithTimeout()
write()
writestring()

◆ writeavail()

int writeavail ( int  fd)

Check the specified file descriptor to determine data can be written.

Parameters
fdFile descriptor number
Return values
1Data can be written
0Data cannot be written, such as when an output buffer if full
See also
dataavail()
charavail()
haserror()

◆ writestring()

int writestring ( int  fd,
const char *  str 
)

Write a null terminated ascii string to the stream associated with a file descriptor (fd). Can be used to write data to stdio, a TCP socket, or a Serial port.

Parameters
fdFile descriptor
*strPointer to the null terminated string to write
Return values
0Timeout occurred
>0The number of bytes written (Note: Can be less than the number of bytes requested)
<0Error occurred, such as a TCP socket error
See also
close()
peek()
read()
PeekWithTimeout()
ReadWithTimeout()
write()
writeall()

◆ ZeroWaitSelect()

int ZeroWaitSelect ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  errorfds 
)

Returns whether events have occurred on one or more I/O resources associated with a set of file descriptors (fds), and returns immediately.

Parameters
nfdsThe number of file descriptors to examine. Note: This parameter is currently ignored.
*readfdsA pointer to the fd_set to select for read events. Note: This parameter can be NULL. It is modified on exit to reflect the read availability of the selected fds in the set.
*writefdsA pointer to the fd_set to select for write availability events. Note: This parameter can be NULL. It is modified on exit to reflect the write availability of the selected fds in the set.
*errorfdsA pointer to the fd_set to select for error events. Note: This parameter can be NULL. It is modified on exit to reflect the error state of the selected fds in the set.
Return values
0If there is no valid fds
>0The number of fds in all of the non null fd_sets
See also
select()
FD_ZERO()
FD_CLR()
FD_SET()
FD_ISSET()