
PID No. 18413B
1 of 3
AMD
29K
Family
Technical
Bulletin
EPD Systems Engineering
Using the HIF ioctl Service
for Nonblocking Reads
March 20, 1995
Purpose
The Host Interface (HIF) kernel of Release 3.0 or
later of the MiniMON29K
product adds support for
nonblocking read operations. This new feature allows
application programs to continue processing while
waiting for input data to be transferred. (To use this
feature, MiniMON29K Release 3.0 or later must be
loaded on both the target and the host.)
This bulletin shows example code that demonstrates
how a nonblocking read can be used to create an
interactive menu that allows subsequent processing to
continue while waiting for user input.
Affected Product
The information in this bulletin affects the following
product:
Product
MiniMON29K
Release
3.0 or later
The Problem
The default input mode used by the HIF kernel of the
MiniMON29K product is COOKED (0x0000), which
blocks (suspends) the application program issuing a
read
operation from the standard input device
(terminal) until the input data has been transferred.
While blocked mode may be effective for some
applications, it makes it difficult to implement and
debug interactive menu-driven applications that
require processing to continue while waiting for user
input.
The Solution
The HIF kernel of the MiniMON29K Release 3.0 (or
later) product implements nonblocking read support
for standard input devices (terminals). Using the HIF
ioctl
service, the input mode of the standard input
device can be changed from COOKED to NBLOCK
mode, which allows the application program to
continue processing while waiting for input data to be
transferred.
The HIF ioctl Service
The HIF
ioctl
service establishes the operation mode
of a specified file or device. It is intended to be
applied primarily to terminal-like devices; however,
certain modes apply to mass-storage files or to other
related input/output devices.
In COOKED (0x0000) mode (the default input
mode), when a
read
operation for a terminal-like
device is issued by the application program, the
kernel blocks (suspends) any further execution of the
application program until the data has been
transferred. Using the HIF
ioctl
service, the input
mode of the standard input device can be set to
NBLOCK (0x0010) mode, which specifies that
subsequent read operations be executed without
suspending (blocking) the application program
issuing the
read
request.
The HIF read Service
After setting standard input to NBLOCK mode, a HIF
read
operation on the standard input device returns
immediately to the application program. The return
value of the
read
service contains the number of
characters currently available, or –1 if none are
available. The application program examines the
return value from the
read
service to determine if any
input data is available. If the return value is –1, the
application program continues other processing while
waiting for the input data.
Example Code
Following is a short code example showing how the
technique explained above can be used for the
creation of an interactive menu. The code in boldface
highlights the use of the HIF
ioctl
service.