Flash Programmer Protokoll
From FujitsuWiki
Paketaufbau
Die einzelnen Datenpakete besitzen folgenden Aufbau:
SOF | LEN | CMD | Data | CRC | |||
0xA5 | [LEN] | [CMD] | [Data] | [CRC] | |||
1 Byte | 1 Byte | 1 Byte | 0 - 64 Byte | 2 Byte | |||
[LEN] Byte |
Field | Size | Values | Info |
SOF | 1 Byte | 0xA5 | Start-of-Frame (constant) |
[DLEN] | 1 Byte | Total number of bytes of message (incl. SOF and CRC) | |
[CMD] | 1 Byte | Command identifier | |
[Data] | 0 - 64 Byte | Data field (size depending on command) | |
[CRC] | 2 Byte | CRC checksum |
Befehle
Der Befehl-Typ wird zum Steuern des Adapters vom PC aus verwendet. Das Feld CTRL setzt sich zusammen aus dem Type Of Frame (die höchstwertigen 3 Bits) sowie dem Befehltyp (die restlichen 5 Bits).
Initialisierung
SOF | LEN | CMD | Data | CRC | |||
0xA5 | 0x09 | 0x01 | [BRP] | [PSEG] | [JPW] | [SAM] | [CRC] |
1 Byte | 1 Byte | 1 Byte | 4 Byte | 2 Byte | |||
9 Byte |
Field | Size | Values | Info |
[BRP] | 1 Byte | 0x00-0xff | Prescaler-Value |
[PSEG] | 1 Byte | 0x00-0x08 | TQ PropSeg |
[JPW] | 1 Byte | 0x00-0x04 | TQ Jump width |
[SAM] | 1 Byte | 0x01 / 0x03 | Number of samples |
CRC
Die Prüfsumme der Pakete wird nach folgendem Algorithmus gebildet:
uint16_t calc_crc(void *data, uint16_t len) { uint32_t sum = 0; for (;;) { if (len < 2) break; sum += *((uint16_t *)data); data += 2; len -= 2; } if (len) sum += *(uint8_t *) data; while ((len = (uint16_t) (sum >> 16)) != 0) sum = (uint16_t) sum + len; return (uint16_t) sum ^ 0xFFFF; }
Dabei zählen alle Bytes bis auf das Startbyte und die CRC-Bytes