Specifications

66 Chapter 5 - Software Interface
SERIAL.C - Machine-Independent Serial Driver Code
The following machine-independent code implements the getpacket() and
sendpacket() functions for the E271-2200 and E271-2210 serial controllers.
Machine-dependent code to initialize the serial port, enable and disable it, and send
and receive characters, is supplied in a separate module, such as PC_COMM.C
(found on the Companion Disk).
The getpacket() function discards all packets until the requested packet is received.
The getanypacketserial() function synchronizes with the packets in the data stream
by looking for a 'U' Lead-in byte and verifying the trailing Checksum byte. The
sendpacket() function computes and transmits the trailing Checksum. See Serial
Controllers, page 51, for information on communicating with serial controllers.
/************ E271-2200, E271-2210 controller dependent code *************/
#define COMPORT 1 /* 1 or 2 */
#define BAUDRATE 5 /* 0=300,1=600,2=1200,3=2400,4=4800,5=9600,6=19.2,7=38.4 */
#include "pc_comm.c" /* PC dependant serial communications code */
int initserial(void);
int clearserial(void);
boolean getanypacketserial(packettype packet);
void initcontroller(void)
{
packettype ack,quiet = {'Q',2,0,0,0,0,0,0};
int msg;
if ((msg = initserial()) != OK)
quit(errormsg(msg));
if ((msg = clearserial()) != OK)
quit(errormsg(msg));
sendpacket(quiet);
if (!getanypacketserial(ack))
quit(errormsg(NORESPONSE));
if (*ack != 'A')
quit(errormsg(WRONGRESPONSE));
}
int initserial(void)
{
if (!comport_init(COMPORT, BAUDRATE, 0, 0, 0)) /* NONE, 8, 1 */
return(NOCONTROLLER);
return(OK);
}
int clearserial(void)
{
static packettype ack = {'a',0,0,0,0,0,0,0};
int count=200, i;
if (!comport_send(0x11)) /* send ^Q in case handshaked off */
return(CANTSEND);
for (i=0; i<10; i++) /* 10 chars to fill any partial packet */
comport_send(0);
if (!sendpacket(ack))
return(CANTSEND);
do {
if (getanypacketserial(ack))
count ;
else
return(OK);
} while (count > 0);
return(SHORTED);
}
void disablecontroller(void)
/* not needed for serial */
{
}
boolean getpacket(packettype packet, byte p)
{
for (;;) {