Controlling Output Buffers
On the Size 3 Linux Tibbo Project PCB (LTPP3), Gen. 2, you need to define whether a line is an output (set io.enabled = 1 — YES) or input (set io.enabled = 0 — NO). Trying to read the line while it is in the output mode will simply return the state of the line's output driver. Forcing the line externally while it works as an output may cause permanent damage to the device. Here is a code example in which we wait for line 1 to become LOW:
io.num = PL_IO_NUM_1; // Select the line
io.enabled = NO; // Disable the output driver (the line will function as an input now)
while (io.state == HIGH); // Wait until the line is pulled LOW externally
Since ports consist of individual lines, the same applies to ports as well. What you need to understand is that each port line can be configured as an 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:
io.portnum = PL_IO_PORT_NUM_1;
io.portenabled = 0x0F; // Configure the lower four lines as outputs;
// the rest will be used as inputs
Some I/O lines are shared with the inputs/outputs of special function blocks (serial ports, etc.). When a special function block is enabled, certain (not all) I/O lines it uses may be configured for input or output automatically. For such lines, when the corresponding special function block is disabled, the state of the output buffer is restored automatically to what it used to be prior to enabling this function block.
I/O line and port names are defined by the pl_io_num and pl_io_port_num enums, respectively.