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

extern uint32_t g_GPIO0Interrupt;
extern uint32_t g_GPIO1Interrupt;
extern uint32_t g_GPIO2Interrupt;
extern uint32_t g_GPIO3Interrupt;

void Dealay(uint32_t nCount)
{
    while(nCount--);
}

int main(void)
{
    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\r");
    printf("|                       GPIO Interrupt                         |\n\r");
    printf("|          P3.0 trigger GPIO Interrupt, in ISR toggle P1       |\n\r");
    printf("+--------------------------------------------------------------+\n\r");
    printf("\n\r");

    OB_GPIO3->MODE = 0x00;  // P3 as pull up mode
    OB_GPIO1->MODE = 0x00;  // P1 as pull up mode
    //----------------P3.0-----------------------
    GPIO_EnableINT(OB_GPIO3, GPIO_PIN0, GPIO_INTMODE_FALLING_EDGE);
    while(1)
    {
      OB_GPIO3->DATA = 0xFFFF;  // P3.0 = 1
      Dealay(20000);
      OB_GPIO3->DATA = 0xFFFE;  // P3.0 = 0
      Dealay(20000);
    }
}
