This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IWR6843: CRC 64 bit software model

Part Number: IWR6843

Hi,

I am using the CRC peripheral to compute a 64 bit CRC. I would like to have the same implementation in plain C code. From the SDK tests I read the following:

/* This is the computed CRC using the software algorithm:
* Refer to the following link:
* www.zorc.breitbandkatze.de/crc.html
* NOTE: If the data is modified then there will be a failure
* and a new CRC64 has to be generated from the above link */
CRC64Bit = 0x77c41a42f112ad04;

If my reading is correct the test code uses this input data:

uint8_t         realData[] = { 0x70, 0x61, 0x6e, 0x6b, 0x61, 0x6a, 0x20, 0x6b, 0x61, 0x70, 0x6f, 0x6f, 0x72, 0x21, 0x21, 0x21 };

In this test the CRC is configured with these parameters: CRC_BitSwap_MSB, CRC_ByteSwap_ENABLED, CRC_DataLen_64_BIT

By using the above web page I cannot get the expected 64 bits CRC (0x77c41a42f112ad04). Maybe I am not using the proper polynomial but I am not sure which one I should use.

My questions:

1) can you please tell me how to "configure" the web page to get the proper value?

2) is there a 64 bits reference implementation available? (in the SDK I only found the 32 bits one)

3) what is the effect of CRC_BitWasp_* and CRC_ByteSwap_* in full CPU mode?

Thank you and best regards,

Marco

  • Marco:

    Before we get started can you please provide the paths to the files that you are referencing so that I am looking at the same files as you are. Additionally, can you provide some context to what you are trying do that requires computing a 64 bit CRC?

    Best regards,

    Connor Desmond

  • Hi Connor,

    the CRC test source file I referred to is part of the MMWave SDK (CRC driver) at this path:

    mmwave_sdk_03_05_00_04/packages/ti/drivers/crc/test/common/crc_test.c

    I am using a modified version of the Secondary Boot Loader provided by TI in the MMWave SDK. This bootloader decodes a multicore image whose header contains 64 bit CRCs which are generated at build time by the tool "mmwave_sdk_03_05_00_04/packages/scripts/ImageCreator/crc_multicore_image/crc_multicore_image.exe" (as explained here: mmwave_sdk_03_05_00_04/packages/scripts/ImageCreator/Image_Creator_User_Guide.pdf) . This tool is not available on OSX (Mac) and I never found the source code anywhere. The documentation by TI is pretty clear about what the tool does so I would like to write my own tool but I need to understand how to generate these CRC on the build machine.

    If I manage to generete these CRC I think I have all the bits and pieces to properly build binaries on OSX without relying on Windows emulation.

    Thanks,

    Marco 

  • Marco:

    I was able to successfully generate the following CRC from the realdata[] array: 0x77c41a42f112ad04

    I first went to the following site:

    When I play around with CRC I use the following site: https://en.wikipedia.org/wiki/Cyclic_redundancy_check

    Here I found the 64 bit CRC according to the IS0 3909 standard. This is noted on line 561 in crc_test.c. This particular CRC is found at the bottom of the large list of CRCs that are available. What is taken away from this, and what uniquely identifies one CRC from another is the generator polynomial. For our CRC this is: 0x000000000000001B 

    Next I used the following site:

    http://www.sunshine2k.de/coding/javascript/crc/crc_js.html

    I prefer this site compared to others because the data input format is more clear. Note: if you do not put the data in correctly it will make assumptions and the wrong CRC will be generated.

    1. Select 64-bit radio button.

    2. By default they don't have our CRC, so we will have to do a custom CRC, so select "Custom" radio button.

    3. Next in the polynomial field enter the following: 0x000000000000001B 

    4. Next copy the following into the data field: 0x70 0x61 0x6e 0x6b 0x61 0x6a 0x20 0x6b 0x61 0x70 0x6f 0x6f 0x72 0x21 0x21 0x21 . Make sure that the "Bytes" field is selected.

    5. Press "Calculate CRC!" and you should see: 0x77c41a42f112ad04 in greed!

    Best regards,

    Connor Desmond

  • Hello Connor,

    thank you very much for the information, I managed to solve my problem this way.

    In case it may help others please find below the C code that computes CRC64 with byte swap enabled.

    Best regards,

    Marco

    #include <stdio.h>
    #include <stdint.h>
    
    uint64_t poly = 0x000000000000001B;
    //uint64_t poly = 0xC96C5795D7870F42;
    
    uint64_t table[256];
    
    void generate_table()
    {
        for(int32_t i=0; i<256; ++i)
        {
        	uint64_t crc = i;
            // Shift left because we want byte swap enabled
            crc = (crc << 56) & 0xFFFFFFFFFFFFFFFFU;
    
        	for(uint32_t j=0; j<8; ++j)
        	{
                if ((crc & 0x8000000000000000U) != 0) {
                    crc  = crc << 1;
                    crc ^= poly;
                } else {
                    crc  = crc << 1;
                }
            }
        
            table[i] = crc;
            //printf("Table[%d] = %llx\n",i,crc);
        }
    }
    
    uint64_t calculate_crc(uint8_t* stream, uint32_t n)
    {
        uint64_t crc = 0;
        for (int i = 0; i < n; i++) {
    
            uint8_t curByte = stream[i] & 0xFF;
    
            // Should we handle bit inversion this is the place to take care of it
    
            // update the MSB of crc value with next input byte
            // Shift left because we want byte swap enabled
            uint64_t curByteShifted56 = ((uint64_t)curByte) << 56; 
            crc ^= curByteShifted56;
    
            /* this MSB byte value is the index into the lookup table */
            uint32_t pos = (crc >> 56) & 0xFFU;
            /* shift out this index */
            crc = crc << 8;
            /* XOR-in remainder from lookup table using the calculated index */
            crc ^= table[pos];
        }
        // XOR with the final value
        crc ^= 0;
        return crc;
    }
    
    int main(int ac, char **av)
    {
        generate_table();
    
        uint64_t result;
    
        uint8_t realData[] = { 0x70, 0x61, 0x6e, 0x6b, 0x61, 0x6a, 0x20, 0x6b, 0x61, 0x70, 0x6f, 0x6f, 0x72, 0x21, 0x21, 0x21 };
        result = calculate_crc(realData, 16);
        printf("CRC 64: %llx\n", result);
    
        return 0;
    }