2 * Based on PNG CRC implementation
5 #include <utils/ardrone_crc_32.h>
7 /* Table of CRCs of all 8-bit messages. */
8 uint32_t crc_table[256];
10 /* Flag: has the table been computed? Initially false. */
11 int32_t crc_table_computed = 0;
13 /* Make the table for a fast CRC. */
14 void ardrone_make_crc_table(void)
19 for (n = 0; n < 256; n++)
22 for (k = 0; k < 8; k++)
25 c = 0xedb88320L ^ (c >> 1);
31 crc_table_computed = 1;
34 /* Update a running CRC with the bytes buf[0..len-1]--the CRC
35 should be initialized to all 1's, and the transmitted value
36 is the 1's complement of the final running CRC (see the
37 crc() routine below). */
39 uint32_t ardrone_update_crc(uint32_t crc, const uint8_t *buf,
45 if (!crc_table_computed)
46 ardrone_make_crc_table();
47 for (n = 0; n < len; n++)
49 c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
54 /* Return the CRC of the bytes buf[0..len-1]. */
55 uint32_t ardrone_crc_32(const uint8_t *buf, int32_t len)
57 return ardrone_update_crc(0xffffffffL, buf, len) ^ 0xffffffffL;