/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2023. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */
/******************************************************************************
 * @version: V1.0.0 demo
 ******************************************************************************/

/*!
* @file crc.c
*
* @brief This file contains the user crc function..
*
*/

/* ===========================================  Includes  =========================================== */
#include "crc.h"

/* ============================================  Define  ============================================ */

/* ===========================================  Typedef  ============================================ */

/* ==========================================  Variables  =========================================== */
uint32_t tmpResult = 0;
CRC_ProtocolType tmpCRCType = CRC_PROTOCOL_32BIT;

const uint32_t CRC_data[] =
{
    0x9421FFE0, 0x7C0802A6, 
};

/* ====================================  Functions declaration  ===================================== */

/* ======================================  Functions define  ======================================== */

/*!
 * @brief CRC Init
 *
 * @param[in] instance: none
 * @return none
 */
void CRC_InitTest(void)
{
    CRC_ConfigType CrcConfig;
    memset(&CrcConfig, 0, sizeof(CrcConfig));

    CrcConfig.crcProtocolType = tmpCRCType;

    if (tmpCRCType == CRC_PROTOCOL_32BIT)
    {
        CrcConfig.finalXOR = DISABLE;                            /* Enable/disable result XOR */
        CrcConfig.poly = 0x04C11DB7;                             /* CRC polynomial */
        CrcConfig.readTransposeType = CRC_READ_TRANSPOSE_BITS_BYTES;   /* CRC read out without tranpose */
        CrcConfig.writeBytesNumOnce = CRC_WRITE_4_BYTE_ONCE;     /* CRC write 1 byte once */
        CrcConfig.writeTransposeType = CRC_WRITE_TRANSPOSE_BITS_BYTES; /* CRC write in without tranpose */
    }
    else
    {
        CrcConfig.finalXOR = DISABLE;                            /* Enable/disable result XOR */
        CrcConfig.poly = 0x1021;                                 /* CRC polynomial */
        CrcConfig.readTransposeType = CRC_READ_TRANSPOSE_BITS_BYTES;   /* CRC read out without tranpose */
        CrcConfig.writeBytesNumOnce = CRC_WRITE_4_BYTE_ONCE;     /* CRC write 1 byte once */
        CrcConfig.writeTransposeType = CRC_WRITE_TRANSPOSE_BITS_BYTES; /* CRC write in without tranpose */
    }

    CRC_Init(&CrcConfig); /* Initialize CRC module */

    tmpResult = CRC_Check(CRC32_SEED, (const uint8_t *)CRC_data, CRC_DATA_SIZE); /* Calculate CRC value for CRC_data with configuration of 16 bit wide result */

    printf("CRC result is: 0x%X\r\n", tmpResult);
}

/* =============================================  EOF  ============================================== */
