User guide
Chapter 6
Cintpos De vi ces
Cintpos allows asynchronous communication with peripheral devices using the qpkt
and taskwait functi ons. If the pkt id field of packet given to qpkt is negative, the
packet is sent to the identified device. It is returned when the device has complet e d
the requested operation. Most de v i c es have device control blocks (DCBs) that contain
device related data. There is a device table poi nted to by rootnode!rtn_devtab
whose upper bound is held in its zeroth element. The n
th
element of the device table
is zero if the device does not exist, otherwise it points to the DCB of device -n. Most
devices are implemented using threads of the host operating system , but some devices
such as the clock and screen are special and use a poll i ng mechanism implemented
entirely within the interpreter thread. The extra overhead for this is small since the
interpreter only performs the polling operation ab out once every 10000 or so Cintcode
instructions. This figure is typically adjusted to cause polling to take place about once
per millisecond. When Cintpos has no work to do it should enter the Idle task and
stop executing Cintcode instructions so that other progr ams can run. For the polling
mechanism to work, such suspensions must be short. This is normally impleme nted
using the waitirq sys function with a short timeout. Each time waitirq returns, a
counter in the intepreter is set to zer o to cause the polling mechanism to be activated.
The resident Cintpos dev i c es are described below.
6.0.4 The Clock Device
This device has identifier -1 and is treated specially by both qpkt and the inter-
preter. The pkt
arg1 field of its packet holds the number of milliseconds that the
packet should remain wi t h the clock before being returned. The time stamp of when
it should be returned is calculated by qpkt and placed in the pkt
res1 and pkt res2
fields of the packet. It is then inserted into the time ordered clock queue held in
rootnode!rtn_clwkq. Every time the interpreter performs the polling operation it
tests the packets at the star t of the clock queue r e tur n i ng though that have expired to
their task.
135