blob: 4d1dea7259c3651653da91ec8d89681eed7b73c5 [file] [log] [blame]
Brian Silverman8cbf8332013-12-11 13:59:42 -08001#ifndef BBB_CRC_H_
2#define BBB_CRC_H_
3
Brian Silverman1662a0e2013-12-19 17:50:01 -08004#include <string.h>
Brian Silverman8cbf8332013-12-11 13:59:42 -08005#include <stdint.h>
6
Brian Silverman04fac622014-01-26 18:32:15 -08007namespace bbb {
8
9class ByteReaderInterface;
10
11} // namespace bbb
Brian Silverman8cbf8332013-12-11 13:59:42 -080012namespace cape {
13
14// Calculates a CRC32 checksum for data. This is definitely the same one as the
15// cape MCU does in hardware which seems to be the same one as Ethernet etc use.
Brian Silverman04fac622014-01-26 18:32:15 -080016// length is the number of bytes of data to read. It must be a multiple of 4.
17// initial can be a previous return value to continue the same checksum over
18// more data.
19uint32_t CalculateChecksum(uint8_t *data, size_t length,
20 uint32_t initial = 0xFFFFFFFF);
21// Reads all data out of reader and does a checksum over all of it in reasonably
22// sized pieces. Does all of the reads with a timeout of 0. Stops on the first
23// timeout.
24uint32_t CalculateChecksum(::bbb::ByteReaderInterface *reader);
Brian Silverman8cbf8332013-12-11 13:59:42 -080025
26} // namespace cape
27
28#endif // BBB_CRC_H_