crcengine package¶
Module contents¶
Package exports
- exception crcengine.AlgorithmNotFoundError¶
Bases:
Exception
Exception raised when an unrecognized algorithm is requested.
- class crcengine.CrcParams(polynomial: int, width: int, seed: int, reflect_in: bool, reflect_out: bool, xor_out: int)¶
Bases:
NamedTuple
Basic parameters for specifying a CRC algorithm
- polynomial: int¶
Alias for field number 0
- reflect_in: bool¶
Alias for field number 3
- reflect_out: bool¶
Alias for field number 4
- seed: int¶
Alias for field number 2
- validate() None ¶
raise an InvalidParametersError if the specified CRC parameters are not mutually consistent
- width: int¶
Alias for field number 1
- xor_out: int¶
Alias for field number 5
- crcengine.algorithms_available() Iterable[str] ¶
Obtain an iterable of available named CRC algorithms
- crcengine.available_calculation_engines() Iterable[str] ¶
Return the list of available calculation back-ends. These can be used with
crcengine.create()
- crcengine.bit_reverse_byte(byte: int) int ¶
Bit-bashing reversal of a byte
- crcengine.bit_reverse_n(value: int, num_bits: int) int ¶
Mirror the bits in an integer
- Parameters:
value – the integer to reverse
num_bits – the number of bits to reverse
- Returns:
mirrored value
- crcengine.create(poly=None, width=None, seed=None, ref_in=True, ref_out=True, name='', xor_out=16777215, params: Optional[CrcParams] = None, calc_engine='table')¶
Create a table-driven CRC calculation engine
- Parameters:
poly – polynomial (deprecated)
width – polynomial width in bits (deprecated)
seed – seed value for the CRC calculation to use (deprecated)
ref_in – reflect input bits (deprecated)
ref_out – reflect output bits (deprecated)
name – associate a name with this algorithm (deprecated)
xor_out – exclusive-or the output with this value (deprecated)
params – CRC parameters, same as specifying individual parameters
calc_engine – back-end calculation engine to use
- Returns:
- crcengine.create_from_params(params: CrcParams, calc_engine='table')¶
Create a CRC calculation algorithm instance based on params using calculation engine calc_engine as the back end
- Parameters:
params –
calc_engine –
- Returns:
- crcengine.create_generic(poly: int, width: int, seed: int, ref_in: bool, ref_out: bool, xor_out: int, name='')¶
Create generic non-table-driven CRC calculator
- Parameters:
poly – Polynomial
width – calculator width in bits e.g. 32
seed – calculation seed value
ref_in – reflect incoming bits
ref_out – reflect result bits
name – name to assign to calculator
xor_out – pattern to XOR into result
- Returns:
A CRC calculation engine
- crcengine.create_lsb_table(poly, width)¶
Calculate a CRC lookup table for the selected algorithm definition producing a table that can be used for the lsbit algorithm
- Returns:
table of reflected
- crcengine.create_msb_table(poly, width)¶
Calculate a CRC lookup table for the selected algorithm definition :return: list of CRC values
- crcengine.generate_code(crc_name_params, output_dir='out/', language='C', seed_parameter=False, func_name=None)¶
Generate code implementing a specific CRC. Currently only language=C is supported
- crcengine.generate_test(name, output_dir)¶
Generate a Ceedling C-test wrapper for a given algorithm’s generated code
- Parameters:
name – name of algorithm
output_dir – directory into which output should be written
- Returns:
- crcengine.generic_crc(params: CrcParams)¶
Return a general-purpose MSB-first CRC algorithm
- Parameters:
params – CRC algorithm parameters
- Returns:
CRC algorithm
- crcengine.get_algorithm_params(name: str, include_check=False) Dict[str, Union[str, int, bool]] ¶
Obtain the parameters for a named CRC algorithm Optionally the ‘check’ field can be included, this field is not part of the definition of the algorithm and so is omitted by default
- Parameters:
name – Name of algorithm (lowercase)
include_check – if True include the ‘check’ field in the output
- Returns:
dict of algorithm parameters
- Raises:
AlgorithmNotFoundError if algorithm with name cannot be found
- crcengine.get_bits_max_value(nbits)¶
Convenience function returning largest unsigned integer for a given number of bits
- crcengine.lookup_params(name: str) CrcParams ¶
Look up CRC parameters given an algorithm name. A list of algorithms can be obtained using algorithms_available()
- Parameters:
name – name of CRC algorithm
- Raises:
AlgorithmNotFoundError – if algorithm name cannot be found
- crcengine.new(name: str, calc_engine='table')¶
Create a new CRC calculation instance
- crcengine.register_algorithm(name, polynomial, width, seed, reflect, xor_out, check=0)¶
Register a CRC algorithm with custom parameters
- crcengine.register_algorithm_params(name: str, params: CrcParams, check=None) None ¶
Register a CRC algorithm with custom parameters
- crcengine.unregister_algorithm(name: str) None ¶
Remove an algorithm registration
Submodules¶
crcengine.codegen module¶
Generation of C code for CRC calculation
- crcengine.codegen.generate_code(crc_name_params, output_dir='out/', language='C', seed_parameter=False, func_name=None)¶
Generate code implementing a specific CRC. Currently only language=C is supported
- crcengine.codegen.generate_test(name, output_dir)¶
Generate a Ceedling C-test wrapper for a given algorithm’s generated code
- Parameters:
name – name of algorithm
output_dir – directory into which output should be written
- Returns:
Back to the index: CrcEngine documentation