WRITING AN EMBEDDED APPLICATION LOADER
7
LZT 123 8094 R1A
The easiest and fastest way to calculate the CRC is to use
a lookup table.
The first byte the downloader sends is referred to as the
NCGbyte, in the case of the GR47 it is C in ASCII.
2.3.1.2 The Actual Transfer
The uploader waits until the downloader sends an NCG
byte. The NCG byte is the signal that the downloader is
ready to start. If the downloader takes too long or an error
occurs then the uploader time out after 20 seconds. If this
happens the file transfer must be restarted (a CAN byte is
sent by the module and an error code is output)
Each packet consists of the following elements:
1 SOH byte (1 byte)
2 The packet number (1 byte)
3 The 1's complement of the packet number (1 byte)
4 The packet (128 bytes)
5 The high byte of the CRC-16 (1 byte)
6 The low byte of the CRC-16 (1 byte)
Note!
The CRC is calculated on the data packet only not
including the header. The CRC is also sent little-endian so
above should be 5 low byte CRC, 6 high byte CRC.
The downloader:
1. Ensures that the packet number sent matches the
actual packet number received (If the third block sent
has a '4' as the second byte, something is wrong -->
CANCEL TRANSFER (send CAN byte)).
2. Adds the packet number and the 1's complement of it
together to make sure that they add up to 255. If they
don't --> CANCEL TRANSFER.
3. Sets the CRC to 0xFFFFFFFF and then calculates the
CRC for the 128 bytes of data.
4. Compares the received CRC-16 with the calculated
one.