#include "stdio.h"
#include "OB6626.h"
#include "uart.h"
#include "rtc.h"
#include "gpio.h"

extern volatile uint32_t g_RTCInterrupt;
int main(void)
{
    RTC_TIME_INFO time_info;

    SystemCoreClockUpdate();

    // Open UART
    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);
    RTC_Open();

    printf("+----------------------------------------------------------------------+\n\r");
    printf("|                       RTC Driver Sample Code                         |\n\r");
    printf("+----------------------------------------------------------------------+\n\r");
    printf("\n\r");

    time_info.nSecond   = 15;
    time_info.nMinute   = 35;
    time_info.nHour     = 14;
    time_info.nDate     = 14;
    time_info.nDay      = 5;
    time_info.nMonth    = 7;
    time_info.nYear     = 17;
    RTC_SetFullTime(&time_info);

    RTC_SetInterrupt(RTC_INT_SEC);

    while(1)
    {
        if (g_RTCInterrupt != 0x00)
        {
            g_RTCInterrupt = 0x00;

            RTC_GetFullTime(&time_info);
            printf("%d-%d-%d(%d)_%d:%d:%d\r\n", time_info.nYear, time_info.nMonth, time_info.nDate, time_info.nDay,
                                                time_info.nHour, time_info.nMinute, time_info.nSecond);
        }
    }
}


