368
Platforms
©2000-2008 Tibbo Technology Inc.
On many devices, a number of I/O lines may be shared with inputs/outputs of
special function blocks (serial ports, etc.). When a special function block is
enabled, I/O lines it uses cannot (should not) be manipulated though the io object.
Controlling Output Buffers
As far as the I/O line/port control goes, there are two kinds of Tibbo devices and
corresponding platforms -- those without output buffer control, and those with
output buffer control. You can find this information in the "Platform-dependent
Programming Information" of your platform documentation.
On devices without the output buffer control each I/O line's output driver is always
enabled. If you want to use this line as an input, set its state to HIGH. After that,
you can read this line's state. If the line is left unconnected or is not being pulled
low externally you will read HIGH. If the line is being pulled low externally you will
read LOW. Pulling the line LOW externally while this line's output driver is at HIGH
will do no damage to the line.
Here is a code example in which we wait for the line #1 to become LOW:
io.num=PL_IO_NUM_1
'select the line
io.state=HIGH
'set it to HIGH so we can use it as an input
While
io.state=HIGH
'wait until the line is pulled LOW externally
Wend
On devices with explicit output buffer control, you need to define whether the line
is an output (set
= 1- YES) or input (set
= 0- NO).
Trying to read the line while it is in the output mode will simply return the state of
the line's own output driver. Forcing the line externally while it works as an output
may cause a permanent damage to the device. For this kind of devices, the above
code must be modified to look like this:
io.num=PL_IO_NUM_1
'select the line
io.enabled=NO
'disable the output driver (line will function as an input
now)
While
io.state=HIGH
'wait until the line is pulled LOW externally
Wend
Since ports consist of individual lines, the same applies to ports as well. What
needs to be understood is that each port line can be configured as input or output
individually. Hence, a particular port doesn't have to be "all outputs" or "all
inputs". Here is an example where the lower half of the port lines is configured for
output, and the rest of the lines serve as inputs:
'This is an example for devices with explicit output buffer control
io.portnum=PL_IO_PORT_1
io.portenabled= &h0F
'configure lower 4 lines as outputs, the rest will be
used as inputs
Some I/O lines are shared with inputs/outputs of special function blocks (serial
ports, etc.). When a special function block is enabled, certain (not all) I/O lines it
370
370