/**
 * @brief CRC-所有内置的CRC模型
 * @details
 * 先后计算01 02 03 04 05不同模型下的结果，然后和已知的CRC结果进行对比。
 */
#include "lks32mc09x_lib.h"

u8 crc_data[5] = {1, 2, 3, 4, 5};
volatile uint32_t crc8_answer, crc8_ITU_answer, crc8_ROHC_answer, crc8_MAXIM_answer;
volatile uint32_t crc16_IBM_answer, crc16_MAXIM_answer, crc16_USB_answer, crc16_MODBUS_answer, crc16_CCITT_answer, crc16_CCITT_FALSE_answer, crc16_X25_answer, crc16_XMODEM_answer, crc16_DNP_answer;
volatile uint32_t crc32_answer, crc32_MPEG_2_answer;

volatile uint32_t crc8_errflg = 0;
volatile uint32_t crc8_ITU_errflg = 0;
volatile uint32_t crc8_ROHC_errflg = 0;
volatile uint32_t crc8_MAXIM_errflg = 0;
volatile uint32_t crc16_IBM_errflg = 0;
volatile uint32_t crc16_MAXIM_errflg = 0;
volatile uint32_t crc16_USB_errflg = 0;
volatile uint32_t crc16_MODBUS_errflg = 0;
volatile uint32_t crc16_CCITT_errflg = 0;
volatile uint32_t crc16_CCITT_FALSE_errflg = 0;
volatile uint32_t crc16_X25_errflg = 0;
volatile uint32_t crc16_XMODEM_errflg = 0;
volatile uint32_t crc16_DNP_errflg = 0;
volatile uint32_t crc32_errflg = 0;
volatile uint32_t crc32_MPEG_2_errflg = 0;

int main(void)
{
    crc8_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_8);                           ///< 计算CRC_8
    crc8_ITU_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_8_ITU);                   ///< 计算CRC_8_ITU
    crc8_ROHC_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_8_ROHC);                 ///< 计算CRC_8_ROHC
    crc8_MAXIM_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_8_MAXIMx);              ///< 计算CRC_8_MAXIMx
    crc16_IBM_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_16_IBMx1);               ///< 计算CRC_16_IBMx1
    crc16_MAXIM_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_16_MAXIM);             ///< 计算CRC_16_MAXIM
    crc16_USB_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_16_USBx1);               ///< 计算CRC_16_USBx1
    crc16_MODBUS_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_16_MODBU);            ///< 计算CRC_16_MODBU
    crc16_CCITT_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_16_CCITT);             ///< 计算CRC_16_CCITT
    crc16_CCITT_FALSE_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_16_CCITT_FALSE); ///< 计算CRC_16_CCITT_FALSE
    crc16_X25_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_16_X25);                 ///< 计算CRC_16_X25
    crc16_XMODEM_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_16_XMODEM);           ///< 计算CRC_16_XMODEM
    crc16_DNP_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_16_DNP);                 ///< 计算CRC_16_DNP
    crc32_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_32);                         ///< 计算CRC_32
    crc32_MPEG_2_answer = CRC_CalcCommon(CRC0, crc_data, sizeof(crc_data), CRC_MODEL_CRC_32_MPEG_2);           ///< 计算CRC_32_MPEG_2

    if (crc8_answer != 0xbc)
    {
        crc8_errflg = 1;
    }
    if (crc8_ITU_answer != 0xe9)
    {
        crc8_ITU_errflg = 1;
    }
    if (crc8_ROHC_answer != 0xfe)
    {
        crc8_ROHC_errflg = 1;
    }
    if (crc8_MAXIM_answer != 0x2a)
    {
        crc8_MAXIM_errflg = 1;
    }
    if (crc16_IBM_answer != 0xbb0e)
    {
        crc16_IBM_errflg = 1;
    }
    if (crc16_MAXIM_answer != 0x44f1)
    {
        crc16_MAXIM_errflg = 1;
    }
    if (crc16_USB_answer != 0x44d5)
    {
        crc16_USB_errflg = 1;
    }
    if (crc16_MODBUS_answer != 0xbb2a)
    {
        crc16_MODBUS_errflg = 1;
    }
    if (crc16_CCITT_answer != 0xed9b)
    {
        crc16_CCITT_errflg = 1;
    }
    if (crc16_CCITT_FALSE_answer != 0x9304)
    {
        crc16_CCITT_FALSE_errflg = 1;
    }
    if (crc16_X25_answer != 0x22ec)
    {
        crc16_X25_errflg = 1;
    }
    if (crc16_XMODEM_answer != 0x8208)
    {
        crc16_XMODEM_errflg = 1;
    }
    if (crc16_DNP_answer != 0xe674)
    {
        crc16_DNP_errflg = 1;
    }
    if (crc32_answer != 0x470b99f4)
    {
        crc32_errflg = 1;
    }
    if (crc32_MPEG_2_answer != 0xe28f4b83)
    {
        crc32_MPEG_2_errflg = 1;
    }
    for (;;)
    {
    }
}
