Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PLC PRIME CRC Calculation

This module provides configuration and utils to calculate the CRC for PRIME messages in a PLC network.

Macros

#define PCRC_CRC_INVALID   0xFFFFFFFF
 
#define PCRC_HT_BEACON   2
 
#define PCRC_HT_GENERIC   0
 
#define PCRC_HT_PROMOTION   1
 
#define PCRC_HT_USI   3
 
#define PCRC_PROMOTION_CRC_LENGTH   13
 
#define SNA_SIZE   6
 

Enumerations

enum  PCRC_CRC_types {
  PCRC_CRC_TYPE_8 = 0,
  PCRC_CRC_TYPE_16 = 1,
  PCRC_CRC_TYPE_24 = 2,
  PCRC_CRC_TYPE_32 = 3
}
 

Functions

static uint16_t _eval_crc_16 (const uint8_t *puc_buf_ptr, uint32_t ul_len, uint32_t ul_crc_init)
 This function calculates the CRC16 of the input data. More...
 
static uint32_t _eval_crc_32 (const uint8_t *puc_buf_ptr, uint32_t ul_len, uint32_t ul_crc_init)
 This function calculates the CRC32 of the input data. More...
 
static uint8_t _eval_crc_8 (const uint8_t *puc_buf_ptr, uint32_t ul_len, uint32_t ul_crc_init)
 This function calculates the CRC8 of the input data. More...
 
static uint8_t _eval_crc_8_usi (const uint8_t *puc_buf_ptr, uint32_t ul_len, uint32_t ul_crc_init)
 This function calculates the CRC8 of the input data for USI. More...
 
uint32_t pcrc_calculate_prime_crc (uint8_t *puc_buf, uint32_t ul_len, uint8_t uc_header_type, uint8_t uc_crc_type)
 Calculates the CRC of the input buffer according to the PRIME spec. More...
 
void pcrc_configure_sna (uint8_t *puc_sna)
 Through this function, the SNA is configured for the PCRC service. More...
 

Variables

static const uint8_t puc_crc8_table [256]
 
static uint8_t puc_SNA [SNA_SIZE] = {0, 0, 0, 0, 0, 0}
 
static const uint32_t pul_crc32_table [256]
 
static const uint16_t pus_crc16_table [256]
 
static uint8_t uc_SNA_crc_8 = 0
 
static uint32_t ul_SNA_crc_32 = 0
 

#define PCRC_CRC_INVALID   0xFFFFFFFF
#define PCRC_HT_BEACON   2
#define PCRC_HT_GENERIC   0
#define PCRC_HT_PROMOTION   1
#define PCRC_HT_USI   3
#define PCRC_PROMOTION_CRC_LENGTH   13
#define SNA_SIZE   6

Referenced by pcrc_configure_sna().

Enumerator
PCRC_CRC_TYPE_8 
PCRC_CRC_TYPE_16 
PCRC_CRC_TYPE_24 
PCRC_CRC_TYPE_32 

static uint16_t _eval_crc_16 ( const uint8_t *  puc_buf_ptr,
uint32_t  ul_len,
uint32_t  ul_crc_init 
)
static

This function calculates the CRC16 of the input data.

Parameters
puc_buf_ptrPointer to the input data
ul_lenLength of data to evaluate
ul_crc_initInitial value for the CRC calculation algorithm
Return values
calculatedCRC

Referenced by pcrc_calculate_prime_crc().

static uint32_t _eval_crc_32 ( const uint8_t *  puc_buf_ptr,
uint32_t  ul_len,
uint32_t  ul_crc_init 
)
static

This function calculates the CRC32 of the input data.

Parameters
puc_buf_ptrPointer to the input data
ul_lenLength of data to evaluate
ul_crc_initInitial value for the CRC calculation algorithm
Return values
calculatedCRC

Referenced by pcrc_calculate_prime_crc(), and pcrc_configure_sna().

static uint8_t _eval_crc_8 ( const uint8_t *  puc_buf_ptr,
uint32_t  ul_len,
uint32_t  ul_crc_init 
)
static

This function calculates the CRC8 of the input data.

Parameters
puc_buf_ptrPointer to the input data
ul_lenLength of data to evaluate
ul_crc_initInitial value for the CRC calculation algorithm
Return values
calculatedCRC

Referenced by pcrc_calculate_prime_crc(), and pcrc_configure_sna().

static uint8_t _eval_crc_8_usi ( const uint8_t *  puc_buf_ptr,
uint32_t  ul_len,
uint32_t  ul_crc_init 
)
static

This function calculates the CRC8 of the input data for USI.

Parameters
puc_buf_ptrPointer to the input data
ul_lenLength of data to evaluate
ul_crc_initInitial value for the CRC calculation algorithm
Return values
calculatedCRC

Referenced by pcrc_calculate_prime_crc().

uint32_t pcrc_calculate_prime_crc ( uint8_t *  puc_buf,
uint32_t  ul_len,
uint8_t  uc_header_type,
uint8_t  uc_crc_type 
)

Calculates the CRC of the input buffer according to the PRIME spec.

Parameters
puc_bufInput buffer
ul_lenData length
uc_header_typeHeader Type
uc_crc_typeCRC type (only needed for USI messages)
Return values
crcvalue (PCRC_CRC_INVALID if SNA not configured and needed)

References _eval_crc_16(), _eval_crc_32(), _eval_crc_8(), _eval_crc_8_usi(), PCRC_CRC_INVALID, PCRC_CRC_TYPE_16, PCRC_CRC_TYPE_32, PCRC_CRC_TYPE_8, PCRC_HT_BEACON, PCRC_HT_GENERIC, PCRC_HT_PROMOTION, PCRC_HT_USI, and PCRC_PROMOTION_CRC_LENGTH.

Referenced by _doEoMsg(), _usi_encode_and_send(), pal_data_request_ex(), and pal_get_rx().

void pcrc_configure_sna ( uint8_t *  puc_sna)

Through this function, the SNA is configured for the PCRC service.

Parameters
puc_snaPointer to the SNA

References _eval_crc_32(), _eval_crc_8(), Disable_global_interrupt, Enable_global_interrupt, and SNA_SIZE.

Referenced by pal_set_cfg_ex().

const uint8_t puc_crc8_table[256]
static
uint8_t puc_SNA[SNA_SIZE] = {0, 0, 0, 0, 0, 0}
static
const uint32_t pul_crc32_table[256]
static
const uint16_t pus_crc16_table[256]
static
uint8_t uc_SNA_crc_8 = 0
static
uint32_t ul_SNA_crc_32 = 0
static