Specifications

7.4. SOFTWARE DESIGN
interrupt, thereby providing exactly one second de lay between decrements.
Once the timer value has decremented down to zero, it is time to poll that
peripheral. This timer array is a 16 bit number and the maximum polling
period is thus 65535 seconds (approximately 18 hours). The status array is
checked to ensure that a poll is not currently already under way. If not, the
status byte is changed to “request peripheral poll” and the peripheral’s timer
is reset to the value stored in the p eripheral poll period array. This occurs
during the following timer de crement procedure.
An FSM in the main system loop constantly checks the status bytes of
all installed peripherals. If one of them is found to be “request peripheral
poll” and the I
2
C bus is available, then the I
2
C bus is initialised with a data
request using that peripheral’s address (as extracted from the peripheral
address array). That peripheral’s poll request status is then changed to
“request issued, awaiting response”. The peripheral poll FSM now waits for
the I
2
C FSM to complete the exchange. If the I
2
C returns a “successful”
result, then the exchange is complete; the peripheral’s poll status is changed
back to idle and the received data is stored for reporting to the device
operator. I f not, an error message is displayed on the LCD display and
the poll request is cancelled.
If a peripheral requires polling, but the I
2
C bus is occupied, then the
request is queued until the bus is free. This is simply achieved by ignoring the
poll request until the I
2
C bus is available. Its request to be polled is stored in
its status byte and remains pending until the I
2
C bus is available. Priorities
are inherently catered for: if two peripherals require polling simultaneously,
then peripheral with a lower value is polled first as it’s status byte is checked
first. The second request will be ignored until the first one has completed or
has returned an error.
7.4.5 I
2
C FSM
The choice to use I
2
C simplifies software development as the generation of
bus events is catered for by on-board hardware. The Microchip C18 C-
compiler package includes I
2
C functions, however, we were unable to use
them reliably. Thus, custom libraries were written which invoke the hardware
79