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.

TMS320F28388D: how to use VCU library to generate endat crc

Part Number: TMS320F28388D
Other Parts Discussed in Thread: C2000WARE

i am trouble in vcu library ,sadly

my endat data size is 27 ,CRC size is 5

what should i do to design the routine?

I refer to the program as the flowing pic

the flowing design by myself ,how to fix this to get the correct routine

  • this is endat data exchange

    • Can someone help me this poor boy

  • An expert should get back to you very soon on this. Thanks.

  • Hi,

    You need to set the values of  CRC.nMsgBits ,CRC.dataSize and also specify the polynomial  CRC.polynomial and polynomial size CRC.polySize. can you share with me your changes and setting you have done for these for the data you are processing.?

    Thanks

    Aravindhan

  • this is my change

  • this is my change

  • by the way,can i ask what's the mean of “data size”,according to the endat pic i provide,how should i set the number of data size

  • Data size is the data on which we want to run CRC at a time (this is internal CRC engine data size to work on)  - Please see the user guide in the C2000WARE - C2000Ware_3_03_00_00\libraries\dsp\VCU\c28\docs - page numbers 74 - section 7 and it will give you a good idea. let me know if you need further help.

    Thanks

    Aravindhan

  • yes,i think i need further help ,thank you

    so as the above i say,if i want to run the endat crc5 ,what should the crc.datasize number  i set,is it 5?

  • yes,i think i need further help ,thank you

    so as the above i say,if i want to run the endat crc5 ,what should the crc.datasize number  i set,is it 5 or 8?

    • Do I need to write my own CRC5lookuptable?

  • and my crc5 poly is 0x0b

    this is my main.c

    how should i fix it

    //###############################################################################
    //! \file /2838x_vcrc_config_poly/vcrc_configpoly.c
    //!
    //! \brief  Demo code for the configurable polynomial and data sizes (VCRC and C)
    //!
    //! \date   April 9, 2020
    //!
    //! This example shows how to
    //! -# use the VCRC supported configurable polynomial and datasizes
    //
    //  Group:             C2000
    //  Target Family:     F2838x
    //
    //#############################################################################
    // $TI Release: C28x VCU Library V2.20.00.00 $
    // $Release Date: May 26, 2020 $
    // $Copyright: Copyright (C) 2019 Texas Instruments Incorporated -
    //             http://www.ti.com/ ALL RIGHTS RESERVED $
    //#############################################################################

    //*****************************************************************************
    // includes
    //*****************************************************************************
    #include <stdio.h>
    #include "vcu2_types.h"
    #include "vcu2_crc.h"
    #include "vcrc_configpoly.h"
    #include "vcrc_configpoly_example.h"
    #include "dsp_examples_setup.h"
    #include "crctable0x7.h"
    #include "crctable0x7reflected.h"
    #include "crctable0x8005.h"
    #include "crctable0x1021.h"
    #include "crctable0x8005reflected.h"
    #include "crctable0x1021reflected.h"
    #include "crctable0x04c11db7.h"
    #include "crctable0x1edc6f41.h"
    #include "crctable0x04c11db7reflected.h"
    #include "crctable0x1edc6f41reflected.h"
    #include "dsp_examples_setup.h"


    //*****************************************************************************
    // defines
    //*****************************************************************************
    #define CRC_INIT_4 0x0
    #define CRC_INIT_5 0x1f
    #define CRC_INIT_8 0x0
    #define CRC_INIT_16 0x0
    #define CRC_INIT_CRC16MODBUS  0xFFFF
    #define CRC_INIT_CRC32 0xFFFFFFFF
    #define POLYNOMIAL_4 0x0003
    #define POLYNOMIAL_5 0x0b
    #define POLYNOMIAL_8 0x0007
    #define POLYNOMIAL_17 0x1685B
    #define POLYNOMIAL_16_P2 0x1021
    #define POLYNOMIAL_16_P1 0x8005
    #define POLYNOMIAL_32_P1 0x04C11DB7
    #define POLYNOMIAL_32_P2 0x1EDC6F41
    #define NO_OF_TESTS 22
    #define NBYTES1 128
    #define NWORDS1 NBYTES1/2

    //*****************************************************************************
    // globals
    //*****************************************************************************

    uint32_t TestOutput[NO_OF_TESTS];
    uint32_t goldenOutput[NO_OF_TESTS];
    uint16_t pass,fail;

    CRC_Obj CRC;
    CRC_Handle handleCRC;

    //位置数据从F开始01_01_1100_0000_0110_0110_0000_000(27个),CRC=3/0x5c06, 0x6000,
    //位置数据从H开始000_0000_0110_0110_0000_0011_10_10(27个)
    #pragma DATA_SECTION(testInput,"testInput")
    uint16_t testInput[NWORDS1] = {
        0x5c06, 0x6000,
    };

    #pragma DATA_SECTION(TestOutput,"TestOutput")

    main()
    {
        // Locals
        int16_t index = 0;

        //
        // Setup system clocking
        //
        DSP_Example_setupSysCtrl();

        //******************************************************************************************************
        // Note -
        // Polynomial size - size of of 1 bit - indicated by programming a value of 0x0
        // Polynomial size - size of of 32bits - indicated by programming a value of 0x1F
        // Datasize refers to the integral unit on which the CRC is computed
        // Data size - size of 1 bit - indicated by programming a value of 0x0
        // Data size - size of 8 bits is indicated by programming a value of 0x7
        // These are to be set in the VCRCSIZE register - PSIZE and DSIZE fields and they are
        // set in the functions _CRC_runConfigPolyBytes and _CRC_runConfigPolyBits implemented in the asm file
        // vcrc_configpoly_asm.asm
        // Total size of the message on which the CRC to be computed is specified by 2 elements MsgBytes and MsgBits
        // If the size of the message is in bytes - then set the value of CRC.nMsgBytes to the size of the message
        // and call the function - CRC_runConfigPolyBytes
        // if the size of the message cannot be specified in bytes - then set the value of CRC.nMsgBits to the size
        // of the message in bits and call the function - _CRC_runConfigPolyBits

        //******************************************************************************************************
        //EXAMPLE 1 and 2 - Byte wise 4 bit CRC computation for different Msg Sizes -> 128, 7 bytes respectively

        // Step 1: Initialize CRC objects
        CRC.seedValue      = CRC_INIT_5;                        //enter the seed value for CRC computation
        CRC.nMsgBytes      = 4;                                 //enter the number of bytes on which the CRC is to be computated
        CRC.nMsgBits       = 0;                                 //enter the number of bits for CRC computation
        CRC.parity         = CRC_parity_odd;                   //choose to compute CRC for lower byte(8 bits) first or upper byte first based on the parity value
        CRC.crcResult      = 0;                                 //CRC result would be stored in the location
        CRC.pMsgBuffer     = 0;                                 //pointer to the message buffer
        CRC.polynomial     = POLYNOMIAL_5;                      //user polynomial
        CRC.polySize       = SIZE_5_BITS;                       //polynomial size
        CRC.dataSize       = SIZE_8_BITS;                       //data size
        CRC.reflected      = 0;                                 //Whether the computation is to be done from LSB or MSB, if CRC.reflected = 1 then the data bytes would be flipped before CRC computation
        CRC.init           = (void (*)(void *))CRC_init16Bit;   //initialize the CRC routine by context save and context restore calls
                            //取函数的地址,并将其传入的参数由实体改为地址
        CRC.run            = (void (*)(void *))CRC_run4BitENDATTableLookupC;  //函数地址赋值,并没有运行

        // Step 2: Initialize the handle
        handleCRC = &CRC;


            CRC.nMsgBits   = 27;                                       //add the number of data bits to compute CRC
            CRC.nMsgBytes  = 0;                                       //we can keep MsgBytes = 0 for bit mode test as it is not required
            CRC.pMsgBuffer = testInput;                                //point to the test input

            // Step 1: Calculate the golden value using the C routine
            CRC.run = (void (*)(void *))CRC_run4BitENDATBitTableLookupC_Generic;//函数地址赋值,并没有运行
            CRC.run(handleCRC);//这里运行的run函数时,run函数已经变为CRC_run4BitENDATBitTableLookupC_Generic
            goldenOutput[index] = (uint16_t)CRC.crcResult;

            // Step 2: run the CRC module with the VCRC assembly code
            CRC.run = (void (*)(void *))CRC_runConfigPolyBytes;
            CRC.run(handleCRC);
            TestOutput[index++] = (uint16_t)CRC.crcResult;




    //     // self checking
    //     pass = 0;
    //     fail = 0;
    //
    //     for(index = 0; index < NO_OF_TESTS; index ++){
    //        if(TestOutput[index] == goldenOutput[index]){
    //            pass++;
    //        }else{
    //            fail++;
    //        }
    //     }
    //
    //     //if the any of the example fails - code will loop forever in error function
    //     if (pass != NO_OF_TESTS) {
    //        error();
    //     }













    }

    //传入CRC结构体地址
    void CRC_run4BitENDATTableLookupC(CRC_Handle hndCRC)
    {
        int16_t  i,j;
        uint16_t data;
        uint16_t parity        = (uint16_t)hndCRC->parity;
        uint16_t accumulator   = hndCRC->seedValue;
        uint16_t *pInputVector = (uint16_t *)hndCRC->pMsgBuffer;
        uint16_t poly = 0x000b;
        uint16_t polySize = 5;

        // The assumption is the message bytes are packed into 16-bit words
        // and the calculation starts from either the high or low byte
        // The memory arrangement is as follows:
        // Address|_LB__|_HB__|
        // 0x0000 |_D0L_|_D0H_|
        // 0x0001 |_D1L_|_D1H_|
        // 0x0002 |_D2L_|_D2H_|
        // 0x0003 |_D3L_|_D3H_|
        // 0x0004 |_D4L_|_D4H_|
        // ...

        poly <<= (8 - polySize);

        for(i = 0; i < hndCRC->nMsgBytes; i++, parity++){
            // __byte selects either the low(0) or high(1) byte in a word
            // the initial selection provided by the enumeration parity
            // the table index is calculated from the high byte of the accumulator
            // XOR'd with the low and high bytes of each word in the input vector
            data = (uint16_t) __byte((int *)pInputVector, parity);
            accumulator ^= data;
            for (j = 0; j < 8; j++) {
                accumulator <<= 1;
                if (accumulator & 0x0100) {
                    accumulator ^= poly;
                }
            }
            accumulator &= 0x00FF;
        }
        // Save the CRC result
        hndCRC->crcResult = (uint32_t)accumulator >> (8 - polySize);
    }
    void CRC_run4BitENDATBitTableLookupC_Generic(CRC_Handle hndCRC)
    {
        int16_t  i;
        uint16_t data;

        uint16_t parity        = (uint16_t)hndCRC->parity;
        uint16_t accumulator   = hndCRC->seedValue;
        uint16_t *pInputVector = (uint16_t *)hndCRC->pMsgBuffer;

        uint16_t poly = 0x0003;
        uint32_t NumOfBits = hndCRC->nMsgBits;
        uint16_t bitPlace = 7;
        uint16_t newWordNext = 1;

        // The assumption is the message bytes are packed into 16-bit words
        // and the calculation starts from either the high or low byte
        // The memory arrangement is as follows:
        // Address|_LB__|_HB__|
        // 0x0000 |_D0L_|_D0H_|
        // 0x0001 |_D1L_|_D1H_|
        // 0x0002 |_D2L_|_D2H_|
        // 0x0003 |_D3L_|_D3H_|
        // 0x0004 |_D4L_|_D4H_|
        // ...

        for(i = 0; i < NumOfBits; i++){
            // __byte selects either the low(0) or high(1) byte in a word
            // the initial selection provided by the enumeration parity
            // the table index is calculated from the high byte of the accumulator
            // XOR'd with the low and high bytes of each word in the input vector
            if (newWordNext) {
                data = (uint16_t) __byte((int *)pInputVector, parity);
                parity++;
                newWordNext = 0;
                if ((NumOfBits - i) <= 8) {
                    bitPlace = NumOfBits - i - 1;
                }
            }
            accumulator <<= 1;
            if (((accumulator & 0x0010)>>4) != (((data & (1<<bitPlace)))>>bitPlace)) {
                accumulator ^= poly;
            }
            accumulator &= 0x00F;
            if (!bitPlace) {
                newWordNext = 1;
                bitPlace = 7;
            } else {
                bitPlace--;
            }
        }
        // Save the CRC result
        hndCRC->crcResult = (uint32_t)accumulator;
    }

    void error(void)
    {
        ESTOP0;  //Test failed!! Stop!
        for (;;);
    }

  • yes i think i need further help

    this is my mian.c

    according to the above i said, how to fix it to correct endat crc

     //###############################################################################
    //! \file /2838x_vcrc_config_poly/vcrc_configpoly.c
    //!
    //! \brief  Demo code for the configurable polynomial and data sizes (VCRC and C)
    //!
    //! \date   April 9, 2020
    //!
    //! This example shows how to
    //! -# use the VCRC supported configurable polynomial and datasizes
    //
    //  Group:             C2000
    //  Target Family:     F2838x
    //
    //#############################################################################
    // $TI Release: C28x VCU Library V2.20.00.00 $
    // $Release Date: May 26, 2020 $
    // $Copyright: Copyright (C) 2019 Texas Instruments Incorporated -
    //             http://www.ti.com/ ALL RIGHTS RESERVED $
    //#############################################################################

    //*****************************************************************************
    // includes
    //*****************************************************************************
    #include <stdio.h>
    #include "vcu2_types.h"
    #include "vcu2_crc.h"
    #include "vcrc_configpoly.h"
    #include "vcrc_configpoly_example.h"
    #include "dsp_examples_setup.h"
    #include "crctable0x7.h"
    #include "crctable0x7reflected.h"
    #include "crctable0x8005.h"
    #include "crctable0x1021.h"
    #include "crctable0x8005reflected.h"
    #include "crctable0x1021reflected.h"
    #include "crctable0x04c11db7.h"
    #include "crctable0x1edc6f41.h"
    #include "crctable0x04c11db7reflected.h"
    #include "crctable0x1edc6f41reflected.h"
    #include "dsp_examples_setup.h"


    //*****************************************************************************
    // defines
    //*****************************************************************************
    #define CRC_INIT_4 0x0
    #define CRC_INIT_5 0x1f
    #define CRC_INIT_8 0x0
    #define CRC_INIT_16 0x0
    #define CRC_INIT_CRC16MODBUS  0xFFFF
    #define CRC_INIT_CRC32 0xFFFFFFFF
    #define POLYNOMIAL_4 0x0003
    #define POLYNOMIAL_5 0x0b
    #define POLYNOMIAL_8 0x0007
    #define POLYNOMIAL_17 0x1685B
    #define POLYNOMIAL_16_P2 0x1021
    #define POLYNOMIAL_16_P1 0x8005
    #define POLYNOMIAL_32_P1 0x04C11DB7
    #define POLYNOMIAL_32_P2 0x1EDC6F41
    #define NO_OF_TESTS 22
    #define NBYTES1 128
    #define NWORDS1 NBYTES1/2

    //*****************************************************************************
    // globals
    //*****************************************************************************

    uint32_t TestOutput[NO_OF_TESTS];
    uint32_t goldenOutput[NO_OF_TESTS];
    uint16_t pass,fail;

    CRC_Obj CRC;
    CRC_Handle handleCRC;

    //位置数据从F开始01_01_1100_0000_0110_0110_0000_000(27个),CRC=3/0x5c06, 0x6000,
    //位置数据从H开始000_0000_0110_0110_0000_0011_10_10(27个)
    #pragma DATA_SECTION(testInput,"testInput")
    uint16_t testInput[NWORDS1] = {
        0x5c06, 0x6000,
    };

    #pragma DATA_SECTION(TestOutput,"TestOutput")

    main()
    {
        // Locals
        int16_t index = 0;

        //
        // Setup system clocking
        //
        DSP_Example_setupSysCtrl();

        //******************************************************************************************************
        // Note -
        // Polynomial size - size of of 1 bit - indicated by programming a value of 0x0
        // Polynomial size - size of of 32bits - indicated by programming a value of 0x1F
        // Datasize refers to the integral unit on which the CRC is computed
        // Data size - size of 1 bit - indicated by programming a value of 0x0
        // Data size - size of 8 bits is indicated by programming a value of 0x7
        // These are to be set in the VCRCSIZE register - PSIZE and DSIZE fields and they are
        // set in the functions _CRC_runConfigPolyBytes and _CRC_runConfigPolyBits implemented in the asm file
        // vcrc_configpoly_asm.asm
        // Total size of the message on which the CRC to be computed is specified by 2 elements MsgBytes and MsgBits
        // If the size of the message is in bytes - then set the value of CRC.nMsgBytes to the size of the message
        // and call the function - CRC_runConfigPolyBytes
        // if the size of the message cannot be specified in bytes - then set the value of CRC.nMsgBits to the size
        // of the message in bits and call the function - _CRC_runConfigPolyBits

        //******************************************************************************************************
        //EXAMPLE 1 and 2 - Byte wise 4 bit CRC computation for different Msg Sizes -> 128, 7 bytes respectively

        // Step 1: Initialize CRC objects
        CRC.seedValue      = CRC_INIT_5;                        //enter the seed value for CRC computation
        CRC.nMsgBytes      = 4;                                 //enter the number of bytes on which the CRC is to be computated
        CRC.nMsgBits       = 0;                                 //enter the number of bits for CRC computation
        CRC.parity         = CRC_parity_odd;                   //choose to compute CRC for lower byte(8 bits) first or upper byte first based on the parity value
        CRC.crcResult      = 0;                                 //CRC result would be stored in the location
        CRC.pMsgBuffer     = 0;                                 //pointer to the message buffer
        CRC.polynomial     = POLYNOMIAL_5;                      //user polynomial
        CRC.polySize       = SIZE_5_BITS;                       //polynomial size
        CRC.dataSize       = SIZE_8_BITS;                       //data size
        CRC.reflected      = 0;                                 //Whether the computation is to be done from LSB or MSB, if CRC.reflected = 1 then the data bytes would be flipped before CRC computation
        CRC.init           = (void (*)(void *))CRC_init16Bit;   //initialize the CRC routine by context save and context restore calls
                            //取函数的地址,并将其传入的参数由实体改为地址
        CRC.run            = (void (*)(void *))CRC_run4BitENDATTableLookupC;  //函数地址赋值,并没有运行

        // Step 2: Initialize the handle
        handleCRC = &CRC;


            CRC.nMsgBits   = 27;                                       //add the number of data bits to compute CRC
            CRC.nMsgBytes  = 0;                                       //we can keep MsgBytes = 0 for bit mode test as it is not required
            CRC.pMsgBuffer = testInput;                                //point to the test input

            // Step 1: Calculate the golden value using the C routine
            CRC.run = (void (*)(void *))CRC_run4BitENDATBitTableLookupC_Generic;//函数地址赋值,并没有运行
            CRC.run(handleCRC);//这里运行的run函数时,run函数已经变为CRC_run4BitENDATBitTableLookupC_Generic
            goldenOutput[index] = (uint16_t)CRC.crcResult;

            // Step 2: run the CRC module with the VCRC assembly code
            CRC.run = (void (*)(void *))CRC_runConfigPolyBytes;
            CRC.run(handleCRC);
            TestOutput[index++] = (uint16_t)CRC.crcResult;




    //     // self checking
    //     pass = 0;
    //     fail = 0;
    //
    //     for(index = 0; index < NO_OF_TESTS; index ++){
    //        if(TestOutput[index] == goldenOutput[index]){
    //            pass++;
    //        }else{
    //            fail++;
    //        }
    //     }
    //
    //     //if the any of the example fails - code will loop forever in error function
    //     if (pass != NO_OF_TESTS) {
    //        error();
    //     }













    }

    //传入CRC结构体地址
    void CRC_run4BitENDATTableLookupC(CRC_Handle hndCRC)
    {
        int16_t  i,j;
        uint16_t data;
        uint16_t parity        = (uint16_t)hndCRC->parity;
        uint16_t accumulator   = hndCRC->seedValue;
        uint16_t *pInputVector = (uint16_t *)hndCRC->pMsgBuffer;
        uint16_t poly = 0x000b;
        uint16_t polySize = 5;

        // The assumption is the message bytes are packed into 16-bit words
        // and the calculation starts from either the high or low byte
        // The memory arrangement is as follows:
        // Address|_LB__|_HB__|
        // 0x0000 |_D0L_|_D0H_|
        // 0x0001 |_D1L_|_D1H_|
        // 0x0002 |_D2L_|_D2H_|
        // 0x0003 |_D3L_|_D3H_|
        // 0x0004 |_D4L_|_D4H_|
        // ...

        poly <<= (8 - polySize);

        for(i = 0; i < hndCRC->nMsgBytes; i++, parity++){
            // __byte selects either the low(0) or high(1) byte in a word
            // the initial selection provided by the enumeration parity
            // the table index is calculated from the high byte of the accumulator
            // XOR'd with the low and high bytes of each word in the input vector
            data = (uint16_t) __byte((int *)pInputVector, parity);
            accumulator ^= data;
            for (j = 0; j < 8; j++) {
                accumulator <<= 1;
                if (accumulator & 0x0100) {
                    accumulator ^= poly;
                }
            }
            accumulator &= 0x00FF;
        }
        // Save the CRC result
        hndCRC->crcResult = (uint32_t)accumulator >> (8 - polySize);
    }
    void CRC_run4BitENDATBitTableLookupC_Generic(CRC_Handle hndCRC)
    {
        int16_t  i;
        uint16_t data;

        uint16_t parity        = (uint16_t)hndCRC->parity;
        uint16_t accumulator   = hndCRC->seedValue;
        uint16_t *pInputVector = (uint16_t *)hndCRC->pMsgBuffer;

        uint16_t poly = 0x0003;
        uint32_t NumOfBits = hndCRC->nMsgBits;
        uint16_t bitPlace = 7;
        uint16_t newWordNext = 1;

        // The assumption is the message bytes are packed into 16-bit words
        // and the calculation starts from either the high or low byte
        // The memory arrangement is as follows:
        // Address|_LB__|_HB__|
        // 0x0000 |_D0L_|_D0H_|
        // 0x0001 |_D1L_|_D1H_|
        // 0x0002 |_D2L_|_D2H_|
        // 0x0003 |_D3L_|_D3H_|
        // 0x0004 |_D4L_|_D4H_|
        // ...

        for(i = 0; i < NumOfBits; i++){
            // __byte selects either the low(0) or high(1) byte in a word
            // the initial selection provided by the enumeration parity
            // the table index is calculated from the high byte of the accumulator
            // XOR'd with the low and high bytes of each word in the input vector
            if (newWordNext) {
                data = (uint16_t) __byte((int *)pInputVector, parity);
                parity++;
                newWordNext = 0;
                if ((NumOfBits - i) <= 8) {
                    bitPlace = NumOfBits - i - 1;
                }
            }
            accumulator <<= 1;
            if (((accumulator & 0x0010)>>4) != (((data & (1<<bitPlace)))>>bitPlace)) {
                accumulator ^= poly;
            }
            accumulator &= 0x00F;
            if (!bitPlace) {
                newWordNext = 1;
                bitPlace = 7;
            } else {
                bitPlace--;
            }
        }
        // Save the CRC result
        hndCRC->crcResult = (uint32_t)accumulator;
    }

    void error(void)
    {
        ESTOP0;  //Test failed!! Stop!
        for (;;);
    }

  • Hi,

    can i consider this issue to be resolved ? let me know.

    thanks

    Aravindhan