#include "stdio.h"
#include "OB6628.h"
#include "gpio.h"
#include "uart.h"
#include "crc.h"


int main(void)
{
    uint32_t nCRCResult = 0;
    uint32_t nLoop = 0;
    uint8_t  DataBlock[256];

    SystemCoreClockUpdate();

    // Open UART
    GPIO_SetPinMFType(OB_GPIO2, GPIO_PIN9, GPIO_MF_UART0_TX);
    GPIO_SetPinMFType(OB_GPIO2, GPIO_PIN10, GPIO_MF_UART0_RX);
    UART_Open(OB_UART0, 19200);


    for (nLoop = 0x00; nLoop < 256; nLoop++)
    {
        DataBlock[nLoop] = nLoop;
    }

    // CRC-CCITT
    CRC_Open(CRC_POLY_CRCCCITT, CRC_WDL_8, 0);
    nCRCResult = CRC_Calculate(DataBlock, 256);
    CRC_Close();
    printf("CRC-CCITT Result: 0x%08X \r\n", nCRCResult);

    // CRC-32
    CRC_Open(CRC_POLY_CRC32, CRC_WDL_8, 0);
    nCRCResult = CRC_Calculate(DataBlock, 256);
    CRC_Close();
    printf("CRC-32 Result: 0x%08X \r\n", nCRCResult);

    // CRC-16
    CRC_Open(CRC_POLY_CRC16, CRC_WDL_8, 0);
    nCRCResult = CRC_Calculate(DataBlock, 256);
    CRC_Close();
    printf("CRC-16 Result: 0x%08X \r\n", nCRCResult);

    // CRC-8
    CRC_Open(CRC_POLY_CRC8, CRC_WDL_8, 0);
    nCRCResult = CRC_Calculate(DataBlock, 256);
    CRC_Close();
    printf("CRC-8 Result: 0x%08X \r\n", nCRCResult);

    while(1);
}
