mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
MbedCRC< polynomial, width > Class Template Reference
[Drivers]
CRC object provides CRC generation through hardware/software. More...
#include <MbedCRC.h>
Public Member Functions | |
MbedCRC (uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder) | |
Lifetime of CRC object. | |
int32_t | compute (void *buffer, crc_data_size_t size, uint32_t *crc) |
Compute CRC for the data input. | |
int32_t | compute_partial (void *buffer, crc_data_size_t size, uint32_t *crc) |
Compute partial CRC for the data input. | |
int32_t | compute_partial_start (uint32_t *crc) |
Compute partial start, indicate start of partial computation. | |
int32_t | compute_partial_stop (uint32_t *crc) |
Get the final CRC value of partial computation. | |
uint32_t | get_polynomial (void) const |
Get the current CRC polynomial. | |
uint8_t | get_width (void) const |
Get the current CRC width. |
Detailed Description
template<uint32_t polynomial = POLY_32BIT_ANSI, uint8_t width = 32>
class mbed::MbedCRC< polynomial, width >
CRC object provides CRC generation through hardware/software.
ROM polynomial tables for supported polynomials (:: crc_polynomial_t) will be used for software CRC computation, if ROM tables are not available then CRC is computed runtime bit by bit for all data input.
- Template Parameters:
-
polynomial CRC polynomial value in hex width CRC polynomial width
Example: Compute CRC data
#include "mbed.h" int main() { MbedCRC<POLY_32BIT_ANSI, 32> ct; char test[] = "123456789"; uint32_t crc = 0; printf("\nPolynomial = 0x%lx Width = %d \n", ct.get_polynomial(), ct.get_width()); ct.compute((void *)test, strlen((const char*)test), &crc); printf("The CRC of data \"123456789\" is : 0x%lx\n", crc); return 0; }
Example: Compute CRC with data available in parts
#include "mbed.h" int main() { MbedCRC<POLY_32BIT_ANSI, 32> ct; char test[] = "123456789"; uint32_t crc = 0; printf("\nPolynomial = 0x%lx Width = %d \n", ct.get_polynomial(), ct.get_width()); ct.compute_partial_start(&crc); ct.compute_partial((void *)&test, 4, &crc); ct.compute_partial((void *)&test[4], 5, &crc); ct.compute_partial_stop(&crc); printf("The CRC of data \"123456789\" is : 0x%lx\n", crc); return 0; }
Definition at line 94 of file MbedCRC.h.
Constructor & Destructor Documentation
MbedCRC | ( | uint32_t | initial_xor, |
uint32_t | final_xor, | ||
bool | reflect_data, | ||
bool | reflect_remainder | ||
) |
Lifetime of CRC object.
- Parameters:
-
initial_xor Inital value/seed to Xor final_xor Final Xor value reflect_data reflect_remainder
- Note:
- Default constructor without any arguments is valid only for supported CRC polynomials. :: crc_polynomial_t MbedCRC <POLY_7BIT_SD, 7> ct; --- Valid POLY_7BIT_SD MbedCRC <0x1021, 16> ct; --- Valid POLY_16BIT_CCITT MbedCRC <POLY_16BIT_CCITT, 32> ct; --- Invalid, compilation error MbedCRC <POLY_16BIT_CCITT, 32> ct (i,f,rd,rr) Consturctor can be used for not supported polynomials MbedCRC<POLY_16BIT_CCITT, 16> sd(0, 0, false, false); Constructor can also be used for supported polynomials with different intial/final/reflect values
Member Function Documentation
int32_t compute | ( | void * | buffer, |
crc_data_size_t | size, | ||
uint32_t * | crc | ||
) |
int32_t compute_partial | ( | void * | buffer, |
crc_data_size_t | size, | ||
uint32_t * | crc | ||
) |
Compute partial CRC for the data input.
CRC data if not available fully, CRC can be computed in parts with available data. Previous CRC output should be passed as argument to the current compute_partial call.
- Precondition:
- : Call compute_partial_start to start the partial CRC calculation.
- Postcondition:
- : Call compute_partial_stop to get the final CRC value.
- Parameters:
-
buffer Data bytes size Size of data crc CRC value is intermediate CRC value filled by API.
- Returns:
- 0 on success or a negative error code on failure
- Note:
- : CRC as output in compute_partial is not final CRC value, call compute_partial_stop to get final correct CRC value.
int32_t compute_partial_start | ( | uint32_t * | crc ) |
Compute partial start, indicate start of partial computation.
This API should be called before performing any partial computation with compute_partial API.
- Parameters:
-
crc Initial CRC value set by the API
- Returns:
- 0 on success or a negative in case of failure
- Note:
- : CRC is an out parameter and must be reused with compute_partial and compute_partial_stop without any modifications in application.
int32_t compute_partial_stop | ( | uint32_t * | crc ) |
Get the final CRC value of partial computation.
CRC value available in partial computation is not correct CRC, as some algorithms require remainder to be reflected and final value to be XORed This API is used to perform final computation to get correct CRC value.
- Parameters:
-
crc CRC result
uint32_t get_polynomial | ( | void | ) | const |
Generated on Tue Jul 12 2022 20:37:47 by 1.7.2