Microchip® Advanced Software Framework

common/services/crc32/crc32.c File Reference

32-bit CRC implementation.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include "crc32.h"
#include <status_codes.h>

Macros

#define COMPLEMENT_CRC(c)   ((c) ^ 0xffffffffUL)
 Convenience macro for inverting the CRC. More...
 
#define CRC32_POLYNOMIAL   0xEDB88320UL
 Polynomial for 32-bit CRC in IEEE 802.3. More...
 
#define WORD_ALIGNMENT_MASK   ~((uintptr_t)WORD_SIZE - 1)
 Bitmask for word-aligning an address. More...
 
#define WORD_SIZE   (sizeof(word_t))
 Convenience macro for size of a word. More...
 

Typedefs

typedef unsigned int word_t
 Convenience typedef for words. More...
 

Functions

static crc32_t _crc32_recalculate_bytes_helper (word_t data, crc32_t crc, uint_fast8_t bytes)
 Recalculate 32-bit CRC for bytes within a word. More...
 
enum status_code crc32_recalculate (const void *data, size_t length, crc32_t *crc)
 Recalculate 32-bit CRC for another block. More...
 

#define COMPLEMENT_CRC (   c)    ((c) ^ 0xffffffffUL)

Convenience macro for inverting the CRC.

Referenced by crc32_recalculate().

#define CRC32_POLYNOMIAL   0xEDB88320UL

Polynomial for 32-bit CRC in IEEE 802.3.

Referenced by _crc32_recalculate_bytes_helper().

#define WORD_ALIGNMENT_MASK   ~((uintptr_t)WORD_SIZE - 1)

Bitmask for word-aligning an address.

Referenced by crc32_recalculate().

#define WORD_SIZE   (sizeof(word_t))

Convenience macro for size of a word.

Referenced by crc32_recalculate().

typedef unsigned int word_t

Convenience typedef for words.

Note
This type has an architecture dependent size, and is used to optimize the CRC algorithm with regards to the number of databus accesses.

static crc32_t _crc32_recalculate_bytes_helper ( word_t  data,
crc32_t  crc,
uint_fast8_t  bytes 
)
inlinestatic

Recalculate 32-bit CRC for bytes within a word.

Parameters
[in]dataData to recalculate for.
[in]crcInitial/current CRC value.
[in]bytesNumber of data bytes in word.
Returns
New CRC value.
Attention
This implementation assumes a little-endian architecture.

References CRC32_POLYNOMIAL, and data.

Referenced by crc32_recalculate().