#include <stdio.h>
#include "OB6627.h"
#include "uart.h"
#include "gpio.h"

extern volatile uint8_t  g_UartRxData[UART_RX_SIZE];
extern volatile uint32_t g_UartRxCounter;
extern volatile uint32_t g_UartInterrupt;

int main(void)
{
    uint32_t nLoop;

    SystemCoreClockUpdate();
    GPIO_SetPinMFType(OB_GPIO2, GPIO_PIN0, GPIO_MF_UART1_RX);
    GPIO_SetPinMFType(OB_GPIO2, GPIO_PIN1, GPIO_MF_UART1_TX);
    UART_Open(OB_UART1, 19200);
    //--------------- Set FIFO to be 14 BYTE--------------------------------
    OB_UART1->UFCR = (OB_UART1->UFCR  & 0x3F)| UART_FIFO_LEVEL_14BYTE;
    //--------------- enable Interrupt--------------------------------
    NVIC_EnableIRQ(UART1_IRQn);
    //--------------------------Put the DATA into FIFO ------------------------------------
    for (nLoop = 0x00; nLoop < 14; nLoop++)
    {
        OB_UART1->UTHR  = nLoop;
    }

    //--------------------------------------
    // Notice : This interrupt happens if FIFO being empty.
    //          You must put the DATA into FIFO before enable the interrupt.
    //          The interrupt vector will close the interrupt,
    //          and must enable the interrupt again on the next time.
    UART_EnableInt(OB_UART1, UART_INT_THRE);
    g_UartInterrupt = 0x00;
    while(1)
    {
        if (g_UartInterrupt == 1)
            break;
    }
    while(1);

}
