where : ibrtses embedded

the ibrt short message protocol

This simple and compact protocol is especially suited for general purpose bus interaction with embedded devices. The protocol is a binary master-slave with a CRC protection for 2^16 bits, or 8kbytes. The single byte length field restricts the message length to 255 bytes though.

the fields

The message is composed of fields :
[SYN+] STX Len SRC DST Cmd [Data] CRC
where the protocol bounding rules Additional to the bounding rules

the CRC

the 16bit CRC allows to detect single bit errors withing 2^16bits, or 8KBytes. The CRC is calculated as
PROCEDURE calcCRCbyte(data:BYTE;VAR crc:WORD);
VAR i:BYTE;
BEGIN
 FOR i:=0 TO 7 DO BEGIN
   IF ((data and $01)XOR(crc AND $0001)<>0) THEN BEGIN
     crc:=crc shr 1;
     crc:= crc XOR $A001;
    END
   ELSE BEGIN
     crc:=crc shr 1;
    END;
   data:=data shr 1;
  END;
END;

The command to be sent is assumed zero aligned, eg STX is on address 0, 
and SYN is not included in the CRC

FUNCTION CRC(VAR DATA;size:byte):WORD;
VAR i:byte;
BEGIN
 CRC:=0;
 FOR i:=0 TO size-1 DO BEGIN
   calcCRCbyte(DATA[i],CRC);
 END;
END;

the receiving state machine

The state machine operates with the following states