Teste semf



The Crc interface class has as its main purpose the computation of cyclic redundancy check (CRC) of the input data. The crc can be computed in one step using calculate(const uint8_t* input, size_t inputSize) function, or it can be calculated in many steps, where every time a certain chunk of data is fed to the function accumulate(const uint8_t* input, size_t inputSize).

For computing the crc of a new data, one has to reset the crc object using void reset() function.

CrcSoftware class inherits from Crc interface, and it computes the crc of the input data using the main processing unit. If the hardware has a specific controller to compute the crc value, a class that inherits from Crc should be declared and used.

In the following example we use the 32 bit software crc from the semf library.


#include "Components/Processing/crcsoftware.h"

// buffer for storing some data, has to be filled somewhere in the code
uint8_t buff1[4*100];  
// another buffer for storing some data, has to be filled somewhere in the code
uint8_t buff2[4*100];  

// create a 'CrcSoftware' object with a specific 
// datatype, polynomial, initial value, and final xor.
semf::CrcSoftware<uint32_t, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF> crcSoftware1;

// or
// create a default/predefined 'CrcSoftware' object for uint32_t datatype
semf::Crc32Software crcSoftware2;


// compute the crc of the buff1 in one step
const uint32_t* crcOut1 = nullptr;
crcOut1 = reinterpret_cast<uint32_t*>(crcSoftware1.calculate(buff1, sizeof(buff1)));
// and check if the crc is as expected
const uint32_t expectedCrc = 0x12345678;
if (crcSoftware1.isEqual(&reinterpret_cast(expectedCrc))
	// Do something ...

// compute the crc of the buff2 in multiple steps
const uint32_t *crcOut2 = nullptr;
for (uint8_t i=0; i < 100; i++ )
	// intermediate result of crc 
	crcOut2 = reinterpret_cast<uint32_t*>(crcSoftware2.accumlate(buff2[i*4], 4));

zurück zur Dokumentation