#include "stdio.h"
#include "OB90R32A2.h"
#include "timer32.h"
#include "uart.h"
#include "gpio.h"

extern uint32_t g_T32B0Interrupt;
extern uint32_t g_T32B1Interrupt;

int main(void)
{
    uint32_t nBuff;

    SystemCoreClockUpdate();

    GPIO_SetPinMFType(OB_GPIO0, GPIO_PIN1, GPIO_MF_UART0_RX);   // P0.1
    GPIO_SetPinMFType(OB_GPIO0, GPIO_PIN0, GPIO_MF_UART0_TX);   // P0.0
    UART_Open(OB_UART0, 19200);

    printf("\n T32B0 interrupt is generated when MR1 match TC\n\r");    // T32B0
    printf("\n toggle P0.6\n\r");

    GPIO_SetPinMode(OB_GPIO0,GPIO_PIN6, GPIO_PINMODE_PULL_UP);//GPIO Mode = Pull up
    //---------------NVIC enable--------------------
    NVIC_EnableIRQ(CT32B0_IRQn);
    //--------------------------------------------
    //Delay 1m second
    nBuff = 1000;
    TIMER32_Delay_Interrupt(OB_CT32B0, TIMER32_MR1, (TIMER32_MR_I | TIMER32_MR_R), nBuff);//unit 1us
    while(1)
    {
        while(1)
        {
            OB_GPIO0->DATA_b.GPIOXDATA6 = ~OB_GPIO0->DATA_b.GPIOXDATA6;
            g_T32B0Interrupt = 0x00;
            while(1)
            {
                if (g_T32B0Interrupt == 0x01)
                {
                    g_T32B0Interrupt = 0x00;
                    break;
                }
            }
        }
    }
}
