AUTOSAR and CRC calculation

If you find yourself reading AUTOSAR document Specification of CRC Routines you are probably looking for a solution on how to implement it in your code. This is short instruction without explaining how CRC works. It includes working CRC code with examples from the mentioned documentation.

Explanation of CRC8

CRC 8 it means, the polynomial of CRC is 8 bit long. 


Explaining chapter 7.2.1:
  • CRC result width - it is the return value, it says it is 8 bits long
  • Polynomial - this value is used to calculate CRC. In this case, it is 0x1D
  • Initial value - CRC calculation start with this value. It is usually all F's or zeros. 
  • Input data reflection - it says if the data which you want to do CRC need to be reflected or not.
    Example of data reflection: hex: 0x73 or binary: 1110011, reflected value is: 1100111 or hex 0x67
  • Result data reflected - same as input data, but the only result is reflected
  • XOR value - result value need to be XOR-ed with this value before is returned. Usually zeros or F's. 
  • Check or Magic check is not important for now. 

For other CRCs apply the same rules. 

You can find the example with CRC8, CRC16, CRC32, and version with templates for calculation any of these three CRCs. This code also induces a generator for the lookup table.

Link to code: https://goo.gl/HT9v85

Next table shows the input data and expected CRC. You can use this table to check if your CRC work correctly or for writing a unit test. 



Code from Github link also includes tests:

  • 8-bit SAE J1850 CRC Calculation
  • 8-bit 0x2F polynomial CRC Calculation
  • 16-bit CCITT-FALSE CRC16
  • 32-bit Ethernet CRC Calculation

If you find my post or code on GitHub useful you can by me a coffee

Buy Me A Coffee

Comments

Popular posts from this blog

Flashing/debugging/running code at external memory in the memory-mapped mode

Debugging EK-TM4C123GXL with Visual Studio Code on Linux