Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CRC32.h « Storage « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f42260db69d3a0f4834e9aedbf6ca99d7c064cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef CRC32_H
#define CRC32_H

#include <RepRapFirmware.h>

#if SAME5x
# define USE_SAME5x_HARDWARE_CRC	1
#else
# define USE_SAME5x_HARDWARE_CRC	0
#endif

// Note: when USE_SAME5x_HARDWARE_CRC is true, the Update methods must not be called from an ISR!
class CRC32
{
private:
	uint32_t crc;

public:
	CRC32() noexcept;

	void Update(char c) noexcept;
	void Update(const char *s, size_t len) noexcept
		__attribute__((optimize("no-unroll-loops")));	// we already optimised the loops, and on the SAME5x unrolling them could make us feed data to the CRC unit too fast
	void Reset(uint32_t initialValue = 0xFFFFFFFF) noexcept;
	uint32_t Get() const noexcept;
};

inline uint32_t CRC32::Get() const noexcept
{
	return ~crc;
}

inline void CRC32::Reset(uint32_t initialValue) noexcept
{
	crc = initialValue;
}

#endif