These files have been made freely available by SGS-Thomson and may not be used to generate commercial products without explicit permission and agreed licensing terms OR placed in a public archive or given to third parties without explicit written permission from SGS-Thomson in Bristol.
Tony Debling, SGS-Thomson Microelectronics Ltd, 1000 Aztec West, Almondsbury, Bristol BS12 4SQ, England. June 7, 1995.
Converted to HTML via RTFtoHTML, PERL5 and by hand by Dave Beckett <D.J.Beckett@ukc.ac.uk>.
WARNING: This has been converted from RTF format and may have mistakes compared to the printed version. If you find any in this file, please send them to me, and I will update it.
Dave Beckett <D.J.Beckett@ukc.ac.uk>
A cyclic redundancy check value is the remainder from modulo 2 polynomial division. Consider bit sequences as representing the coefficients of polynomials; for example, the bit sequence 10100100 (where the leading bit is the most significant bit (msb)) corresponds to P(x) = x^(7) + x^(5) + x^(2). The routines in the library calculate the remainder of the modulo 2 polynomial division:
(x ^(k+n) H(x) + x^(n )F(x)) / G(x)
F(x) corresponds to InputString
When representing G(x) in the word PolynomialGenerator, note that there is an understood bit before the msb of PolynomialGenerator. For example, on a 16 bit processor, with G(x) =x^(16) + x^(12) + x^(5) + 1, which is #11021, then PolynomialGenerator must be assigned #1021, because the bit corresponding to x^(16) is understood. Thus, a value of #9603 for PolynomialGenerator, corresponds to G(x) = x^(16) + x^(15) + x^(12) +x^(10) + x^(9) + x + 1, for a 16 bit processor.
A similar situation holds on a 32 bit processor, so that:
G(x) = x^(32) + x^(26) + x^(23) +x^(22) + x^(16) + x^(12) + x^(11) + x^(10) + x^(8) + x^(7) + x^(5) +x^(4) + x^(2) + x + 1
is encoded in PolynomialGenerator as #04C11DB7.
It is possible, however, to calculate a 16 bit CRC on a 32 bit processor. For example, if G(x) = x^(16) + x^(12) + x^(5) + 1, then PolynomialGenerator is #10210000. This is because the most significant 16 bits of the 32 bit integer form a 16 bit generator; the least significant 16 bits of OldCRC form the initial CRC value; and the calculated CRC is the most significant 16 bits of the result from CRCFROMMSB and the least significant 16 bits of the result from CRCFROMLSB.
First CRCFROMMSB is given the message as an input string, the result is placed into the first four bytes of data and the message is sent. The receiver can either:
Give the received data (which is (size.message + 4) bytes long) to CRCFROMMSB and expect a result of zero,
or:
Give the received [data FROM 4 FOR (size.message)] to CRCFROMMSB and check that the result is equal to the INT contained in the received [data FROM 0 FOR 4].
These methods of checking are equivalent. If the check fails then the transmitted data was corrupted and re transmission can be requested; if the check passes then it is most probable that the data was transmitted without corruption just how probable depends on many factors, associated with the transmission media.
Note: The occam predefines CRCBYTE and CRCWORD can be chained together to help calculate a CRC from a byte string, and this is indeed the use to which they are put in CRCFROMMSB and CRCFROMLSB. However, because these latter routines shift the polynomial F(x) corresponding to InputString by x^(n), these routines should not be chained together over segments of a byte string to find its CRC; the whole string must be used in a single call to CRCFROMMSB or CRCFROMLSB.
INT FUNCTION CRCFROMMSB (VAL []BYTE InputString,
VAL INT PolynomialGenerator,
VAL INT OldCRC)
INT FUNCTION CRCFROMLSB (VAL []BYTE InputString,
VAL INT PolynomialGenerator,
VAL INT OldCRC)
Procedure Parameter Specifiers InputOrFail.t CHAN OF ANY c, []BYTE mess,
TIMER t, VAL INT time, BOOL aborted OutputOrFail.t CHAN OF ANY c, VAL []BYTE mess,
TIMER t, VAL INT time, BOOL aborted InputOrFail.c CHAN OF ANY c, []BYTE mess
CHAN OF INT kill, BOOL aborted OutputOrFail.c CHAN OF ANY c, VAL []BYTE mess,
CHAN OF INT kill, BOOL aborted Reinitialise CHAN OF ANY c
CAUTION:
Use of the routines in xlink.lib during interactive debugging will lead to undefined results. In addition these routines may only be used for channel communication on a link; they must not be used for communications between processes on the same processor.
Note: In rare circumstances aborted may be set to TRUE even though the communication is successful. This happens if the communication terminates successfully in the interval between the timeout/abort and channel renitialization. The likelihood of this event is very small. InputOrFail.t
PROC InputOrFail.t (CHAN OF ANY c, []BYTE mess,
TIMER t, VAL INT time,
BOOL aborted)
PROC OutputOrFail.t (CHAN OF ANY c,
VAL []BYTE mess,
TIMER t, VAL INT time,
BOOL aborted)
PROC InputOrFail.c (CHAN OF ANY c, []BYTE mess,
CHAN OF INT kill,
BOOL aborted)
PROC OutputOrFail.c (CHAN OF ANY c,
VAL []BYTE mess,
CHAN OF INT kill,
BOOL aborted)
PROC Reinitialise (CHAN OF ANY c)
Procedure Parameter Specifiers DEBUG.STOP () DEBUG.ASSERT VAL BOOL assertion DEBUG.MESSAGE VAL []BYTE message DEBUG.TIMER CHAN OF INT stop
PROC DEBUG.ASSERT (VAL BOOL assertion)
PROC DEBUG.MESSAGE (VAL []BYTE message)
PROC DEBUG.STOP ()
PROC DEBUG.TIMER (CHAN OF INT stop)
Caution: Programs that use this DOS specific library will not be portable to versions of the toolset on other hosts.
Procedure Parameter Specifiers dos.receive.block CHAN OF SP fs, ts,
VAL INT32 location,
INT bytes.read, []BYTE block,
BYTE result dos.send.block CHAN OF SP fs, ts,
VAL INT32 location,
VAL []BYTE block,
INT len, BYTE result dos.call.interrupt CHAN OF SP fs, ts,
VAL INT16 interrupt,
VAL[dos.interrupt.regs.size]BYTE
registe r.block.in,
BYTE carry.flag,
[dos.interrupt.regs.size]BYTE
register. block.out,
BYTE result dos.read.regs CHAN OF SP fs, ts,
[dos.read.regs.size] BYTE registers,
BYTE result dos.port.read CHAN OF SP fs, ts,
VAL INT16 port.location,
BYTE value, result dos.port.write CHAN OF SP fs, ts,
VAL INT16 port.location,
VAL BYTE value, BYTE result
PROC dos.receive.block (CHAN OF SP fs, ts,
VAL INT32 location,
INT bytes.read,
[]BYTE block,
BYTE result)
spr.ok The read operation was successful. spr.bad.packet.size Too many bytes were requested to be read: (SIZE[block]) >
dos.max.receive.block.buffer.size. .spr.operation.failed The read failed, so bytes.read = 0. If
result . spr.operation.failed then this denotes a server returned failure. (See section C.2 in the Toolset Reference Manual.)
dos.send.block
PROC dos.send.block (CHAN OF SP fs, ts,
VAL INT32 location,
VAL []BYTE block,
INT len, BYTE result)
spr.ok The write operation was successful. spr.bad.packet.size Too many bytes were requested to be written: (SIZE[block]) >
dos.max.send.block.buffer.size. .spr.operation.failed The write failed. If result takes a value . spr.operation.failed then this denotes a server returned failure. (See section C.2 in the Toolset Reference Manual.)
dos.call.interrupt
PROC dos.call.interrupt
(CHAN OF SP fs, ts,
VAL INT16 interrupt,
VAL [dos.interrupt.regs.size] BYTE register.block.in,
BYTE carry.flag,
[dos.interrupt.regs.size] BYTE register.block.out,
BYTE result)
Register Start position in block End position in block (least significant byte) (most significant byte) ax 0 3 bx 4 7 cx 8 11 dx 12 15 di 16 19 si 20 23 cs 24 27 ds 28 31 es 32 35 ss 36 39
spr.ok The interrupt was successful. .spr.operation.failed The interrupt failed. If result takes a value . spr.operation.failed then this denotes a server returned failure. (See section C.2 in the Toolset Reference Manual.)
dos.read.regs
PROC dos.read.regs
(CHAN OF SP fs, ts,
[dos.read.regs.size] BYTE registers,
BYTE result)
Register Start position in block End position in block (least significant byte) (most significant byte) ax 0 3 bx 4 7 cx 8 11 dx 12 15
spr.ok The read was successful. .spr.operation.failed The read failed. If result takes a value . spr.operation.failed then this denotes a server returned failure. (See section C.2 in the Toolset Reference Manual.)
dos.port.read
PROC dos.port.read (CHAN OF SP fs, ts,
VAL INT16 port.location,
BYTE value, result)
spr.ok The read was successful. .spr.operation.failed The read failed. If result takes a value . spr.operation.failed then this denotes a server returned failure. (See section C.2 in the Toolset Reference Manual.)
dos.port.write
PROC dos.port.write (CHAN OF SP fs, ts,
VAL INT16 port.location,
VAL BYTE value, BYTE result)
spr.ok The write was successful. .spr.operation.failed The write failed. If result takes a value . spr.operation.failed then this denotes a server returned failure. (See section C.2 in the Toolset Reference Manual.)