echo '' ;

Embedded Protocol – XMODEM

Ward Christensen developed XMODEM, a straightforward file transfer protocol, in 1977. It frequently finds application between two computers employing the XMODEM protocol. The protocol initiates transmission with the ‘C’ character, followed by packets. The receiver provides proper acknowledgment (ACK) for each packet. Identification of the last packet is facilitated by EOT, and the completion of transmission is signaled by ETB.

Packet Format

Byte-1Byte-2Byte-3Byte 4-129Byte 130-131
Start of HeaderPacket NumberInverse Packet NumberPacket Data16-bit CRC
XMODEM CRC packet Format

Here Byte-1,2,3 are consider as XMODEM protocol Headers. XMODEM Transmission Reception : Image Link

Packet Size and Range

Total size of the packet is 132 Bytes and payload size is 128bytes.

  • Start of the header: Size – 1Byte, Value – (0x01).
  • Packet Number: Size – 1Byte, Value – 0 to 255, Packet numbering starts with 1, not Zero.
  • Inverse of Packet Number: Size – 1Byte, Value – 255 to 0.
  • Packet Data: Size – 128Byte.
  • CRC XMODEM Size – 2Byte.

Control Characters Definitions

Control CharacterDescriptionValue
SOHStart of the Header0x01
EOTEnd of Transmission0x04
ACKAcknowledge0x06
NAKNot Acknowledge0x15
ETBEnd of Transmission Block0x17
CANCancel 0x18
CASCII “C”0x43C
X-MODEM Control character List

XMODEM CRC Calculation Code

CRC16 (XMODEM) information’s

  • Check = 0x31C3.
  • Poly = 0x1021.
  • Init = 0x0000.
  • RefIn = False.
  • RefOut = False.
  • XorOut = 0x0000.
int calcrc(char *ptr, int count)
{
    int  crc;
    char i;
    crc = 0;
    while (--count >= 0)
    {
        crc = crc ^ (int) *ptr++ << 8;
        i = 8;
        do
        {
            if (crc & 0x8000)
                crc = crc << 1 ^ 0x1021;
            else
                crc = crc << 1;
        } while(--i);
    }
    return (crc);
}
Function NameParametersDescription
calcrcchar *ptr, int countCalculates the cyclic redundancy check (CRC) value for a given data block.

Explanation:

  • *char ptr: A pointer to the data block for which the CRC is to be calculated.
  • int count: Specifies the length of the data block.

The function initializes the CRC value to 0 and iterates over each byte in the data block. For each byte, it XORs the CRC value with the byte left-shifted by 8 bits (multiplied by 256). Then, it performs a bitwise left shift on the CRC value by 1 bit and checks the most significant bit.If the most significant bit is set, the function performs an XOR operation with the polynomial 0x1021. This process continues for 8 iterations (for each bit in the byte). After processing all the bytes in the data block, the function returns the calculated CRC value.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from ArunEworld

Subscribe now to keep reading and get access to the full archive.

Continue reading