MindSDK_MM32F5270/driver_examples/crc/crc_basic/main.c
Yilin Sun 3977144e90
Initial MM32F527x commit.
Signed-off-by: Yilin Sun <imi415@imi.moe>
2023-03-27 21:54:40 +08:00

69 lines
1.7 KiB
C

/*
* Copyright 2021 MindMotion Microelectronics Co., Ltd.
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "board_init.h"
/*
* Macros.
*/
#define APP_CRC_POLYNOMIAL 0x19 /* When the bit width of the polynomial is 8 bits, the polynomial is: x^8+x^4+x^3+1. */
#define APP_CRC_SEED 0xff /* Initial value of polynomial. */
/*
* Variables.
*/
uint32_t app_crc_in_buf[3] = {0x11, 0x22, 0x33};
uint32_t app_crc_expout = 0x33; /* Expected result calculated by CRC. */
CRC_Init_Type app_init;
/*
* Declerations.
*/
/*
* Functions.
*/
int main(void)
{
uint32_t app_crc_result;
BOARD_Init();
printf("crc examples.\r\n");
/* CRC initialization. */
app_init.Polynomial = APP_CRC_POLYNOMIAL;
app_init.PolynomialWidth = CRC_PolynomialWidth_8b;
app_init.InEndian = CRC_DataEndian_LittleEndian;
app_init.OutEndian = CRC_DataEndian_LittleEndian;
app_init.InRev = CRC_Rev_Normal;
app_init.OutRev = CRC_Rev_Normal;
CRC_Init(BOARD_DEBUG_CRC_PORT, &app_init);
CRC_SetSeed(BOARD_DEBUG_CRC_PORT, APP_CRC_SEED); /* Set the value in CRC calculation unit as the initial value. */
for (uint8_t i = 0u; i < 3u; i++)
{
CRC_SetData(BOARD_DEBUG_CRC_PORT, app_crc_in_buf[i]); /* Set data for CRC calculation. */
}
app_crc_result = CRC_GetResult(BOARD_DEBUG_CRC_PORT); /* Get the final calculation result. */
if (app_crc_result == app_crc_expout) /* Whether the current calculation result is the same as the theoretical calculation value. */
{
printf("matched.\r\n");
}
else
{
printf("mismatched.\r\n");
}
while (1)
{
}
}
/* EOF. */