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

extern uint32_t g_T16B0Interrupt;
extern uint32_t g_T16B1Interrupt;

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 CAP0(P0.7) = RISING EDGE\n\r");  // T16B0_CAP0
    //----------------------timer 16 ---------------------------------------
    GPIO_SetPinMFType(OB_GPIO0, GPIO_PIN7, GPIO_MF_TIMER16B0_CAP);
    OB_CT16B0->TMR16PR = 0x00;
    NVIC_EnableIRQ(CT16B0_IRQn);
    TIMER16_EnableCapture(OB_CT16B0, TIMER16_CAPTURE0, (TIMER16_CAPTURE_RISING_EDGE | TIMER16_CAPTURE_INTERRUPT));
    TIMER16_Enable(OB_CT16B0);
    //------------------------------------------
    g_T16B0Interrupt = 0x00;
    while(1)
    {
        if (g_T16B0Interrupt == 0x01)
        {
            g_T16B0Interrupt = 0x00;
            nBuff = OB_CT16B0->TMR16CR0;  //get data
            printf(" The value of CAP0 = 0x%04X \n\r", nBuff);
        }
    }
}
