Machine States/The Serial Interface

See all articles from Update April 1995
Publication: Update Magazine
Pub Details: Update April 1995
Date: April 1995
Pages: 39-43

Machine States

One of the interesting features of the Z88 is its ability to selectively shut down parts of the internal circuitry when it is not required and thus maximise battery life. There are four operational states:

1) Active       The Z80 clock is running and the display is on. ie. the Z80
                running program instructions.

2) Snooze       The Z80 clock stopped but the display still on. eg. the
                Z88 waiting for keyboard input. This state can be
                achieved by executing a HALT instruction. (This
                must only be done by the operating system, never
                by the user.)

3)Doze:         The Z80 clock running and the display off. eg.
                programming an EPROM.

4) Coma:        The Z80 clock stopped and the LCD display off. eg. Z88
                shut down.

The maskable interupt, INTL, is used by the BLINK chip to attract the processor’s attention. The Z80 will read the interupt register in BLINK to determine the source. There are two other cause of INTL which are to indicate battery low condition and a keyboard scan request.

The non-maskable interupt, NMIL, this interupt will cause the machine to enter the coma state, by saving the current state of the machine and then executing a HALT instruction. NMIL is generated by when the timeout counter in BLINK (as set by the Panel) expires, when the the flap at the front of the machine is opened, or when in response to the SNSL signal. The SNSL signal flags a power failure or the plugging in of a memory card or device on the expansion port.

The RSTL usually needs to be pulled low twice. The first action starts the processor clock if, as is the case most of the time, the machine is in the snooze (or even coma) state and the second which actually initiates the reset process. The BLINK chip is also reset by this line. The reset button on the side of the machine simply brings RSTL low, and subsequently the button generally needs to be pressed twice.

The Serial Interface

The Z88 has a single serial port which has to be shared by all applications, so it is important that applications use the system to access the port to avoid interfering with the correct operation of other applications running in the machine. The system runs the serial port using interupts and buffering, so most of its operation is transparent,but there are certain operations, such as directly controlling the RTS line (required for auto-dialling by some modems), which the system calls do not support and in these cases the hardware is accessed more directly (see section 2.19) The serial port specification is reproduced here for convenience:

Baud rates:        75, 300, 600, 1200, 2400, 9600, 19200, 38400
                   Send and receive rates are independent.
Parity:            None, Odd, Even, Mark, Space
                   Note the Z88 generates the appropriate parity, but will
                   ignore, but not strip, the parity of incoming data.
Flow control:      Hardware handshaking or XON/XOFF.
Timeout            This defaults to 10 minutes. (ie. the Z88 will wait
                   for input for 10 minutes before giving up.)

Using the Serial Port

The serial port is accessed by opening the device :COM, using gn_opf, and then using the standard file i/o routines: gn_gb, gn_pb, gn_gbt, gn_pbt and os_mv. The device should be closed after the operation is complete. For most applications this level of access should be sufficent, however, it may be necessary to change the serial port parameters from within an application. This is done by writing new values to the Panel, using the os_sp call, and then issuing a ‘Soft Reset’ command to the serial driver. Changing the Panel setting may affect other software in the machine, so should not be undertaken lightly. It would be appropriate to reset the Panel to its original setting after serial operations are complete. This can be achieved by first reading the Panel settings with os_nq. os_sp and os_nq are covered in detail in section 2.18.

The ‘Soft Reset’ operation is carried out by using the os_si call. This call also provides other serial operations, which might be useful for some applications.

os_si - serial interface

RST &20
DEFB &8D

In:

L  - reason code

The reason codes are as follows:

SI.HRD (&00)        Hard reset the serial port
SI.SFT (&03)        Soft reset the serial port
SI.INT (&06)        Interupt entry point. DO NOT USE!
SI.GBT (&09)        Get byte from serial port
SI.PBT (&0C)        Put byte to serial port
SI.ENQ (&0F)        Status enquiry
SI.FTX (&12)        Flush Tx (transmit) buffer
SI.FRX (&15)        Flush Rx (receive) buffer
SI.TMO (&18)        Set timeout

SI.HRD

No parameters. This resets the UART in the gate array and performs a soft reset (see below). This call should not need to be used.

AFBCDEHL/IXIY       same
............../......  different
afbcdehl            different

SI.SFT

No parameters. This call should be used to install new panel settings or to when starting low level (ie. using SI.GBT, SI.PBT etc.) serial operations. It carries out the following:

1- Empty receive and transmit buffers
2- Reset the XON and XOFF flags
3- Reset baud rates, parity and flow control settings according to the PANEL values.
4- Assert RTS
5- Resets the serial port timeout to its default of 10 minutes.

SI.INT

This should not be used.

SI.GBT – Get byte from serial port

In:
BC - timeout in centiseconds

Out if call succeeded:
Fc=0
A  - byte received
BC - remaining time

Out if call failed:
Fc=1
A - RC.TIME  (if no data available before timeout)

....BCDEHL/IXIY     same
AF............/.....    different
afbcdehl            different

SI.PBT – Put byte to serial port

In:
A  - byte to send
BC - timeout in centiseconds. If BC=&FFFF then default timeout is used.

Out if call succeeded:
Fc=0
BC - remaining time

Out if call failed:
Fc=1
A - RC.TIME

....BCDEHL/IXIY     same
AF........... /......  different
afbcdehl            different

This call will return immediately if there is space in the transmit buffer, otherwise it will wait until there is space for as long as the timeout. If the timeout is exceeded it will return with an error.

SI.ENQ – Status enquiry

In:

-

Out if call succeeded:

D  - number of full slots in the Tx (transmit) buffer
E  - number of empty slots in the Tx (transmit) buffer
B  - number of full slots in Rx (receive) buffer
C  - number of empty slots in Rx (receive) buffer

A7 - Rx shift register full
A6 - DCD interupt
A5 - CTS interupt
A4 - Tx register empty
A3 - undefined
A2 - Rx register full
A1 - DCD level (inverse of the value on the D-connector)
A0 - CTS level (inverse of the value on the D-connector)

............HL/IXIY     same
AFBCDE..../......       different
afbcdehl                different

Notes:

A slot, in this context, is the set of bits required to transmit one character. This will include 8 data bits plus start and stop bits.

SI.FTX – Flush transmit buffer

In:
-

Out:
Fc=0

AFBCDEHL/IXIY       same
............../......  different
afbcdehl            different

SI.FRX – Flush receive buffer

In:
-

Out:
Fc=0

AFBCDEHL/IXIY       same
............../......  different
afbcdehl            different

SI.TMO – set default timeout

In:
BC - new value for default timeout

Out:
Fc=0

AFBCDEHL/IXIY       same
afbcdehl            different

If you set the default to &FFFF then when the defualt is used (by setting a timeout value of &FFFF in get and put routines) then the system will wait forever. A soft reset sets the default timeout to 10 minutes. This timeout is completely independent of the system timeout, which is set by the Panel.

Flow Control

Flow control can be controlled either by software or hardware. The hardware handshaking is always active, so if you want to use software exclusively you will need to wire a cable to set the handshaking lines high at all times. (Tie pins 5, 8 and 9 together on the Z88 D-connector.)

An external device can ask the Z88 to stop sending by either sending an XOFF character or by de-asserting (bringing low) the CTS line. With software flow control transmission can only stop when the XOFF character has been processed, so there is potentially a slight delay in response, while previously sent characters are read. With hardware control transmission stop on the next character boundary. Transmission is resumed on the recipt of an XON character, in the case of software control, or be re-asserting CTS ie. bringing it high. The output buffer is around 95 bytes long.

If software control is used the Z88 will send an XOFF to an external device once the receive buffer is more than half full. Characters will continue to be received until there are only 15 character spaces left in the buffer. At this point an XOFF will be sent for every character subsequently sent by the external device. If the receive buffer overflows then data is lost forever. The Z88 will send an XON when the receive buffer has been cleared to less than a quarter full. Under hardware control, the Z88 will de-assert (bring low) RTS when the receive buffer is less than half full and the re-assert (bring high) when it has become less than a quarter full. The input buffer is around 127 bytes long.

Serial Port Lines

1 -        unswitched  +5v at 10 uA    output
2 TxD      transmit data               output
3 RxD      receive data                input
4 RTS      ready to send               output
5 CTS      clear to send               input
6 -        reserved for future use
7 GND
8 DCD      data carrier detect         input
9 DTR      switched +5v at 1mA         output