#ifndef _GW3323_RTC_H
#define _GW3323_RTC_H

#include "include.h"

//--------------- RTC Flag Definition ---------------//
#define RTC_FLAG_1S         ((uint32_t)0x00040000)
#define RTC_FLAG_ALM        ((uint32_t)0x00020000)
//---------------- RTC IT Definition ----------------//
#define RTC_IT_ALM          ((uint32_t)0x00000010)
#define RTC_IT_1S           ((uint32_t)0x00000008)

// RTC clock source type flag.
typedef enum {
    RTC_32K768_CLK_MODE     = 0x00,
    RTC_32K_CLK_MODE        = 0x40,
} RTC_32K_SEL_TYPEDEF;

// RTC clock source select.
typedef enum {
    RTC_RC2M_SOURCE         = 0x0000,
    RTC_X24MDIV8_SOURCE     = 0x0100,
} RTC_CLK_SOURCE_TYPEDEF;

// RTC wakeup sleep frequency select.
typedef enum {
    RTC_WAKEUP_110MS        = 0x0000,
    RTC_WAKEUP_220MS        = 0x0100,
    RTC_WAKEUP_440MS        = 0x0200,
    RTC_WAKEUP_880MS        = 0x0300,
} RTC_WAKEUP_PERIOD_TYPEDEF;

// RTC clock configuration structure.
typedef struct {
    uint8_t                 external_enable;
    RTC_32K_SEL_TYPEDEF     clk_value_flag;
    RTC_CLK_SOURCE_TYPEDEF  clk_source_sel;
} rtc_clk_typedef;

// RTC time structure.
typedef struct {
    uint8_t     hour;
    uint8_t     minute;
    uint8_t     second;
} rtc_time_typedef;

// RTC date structure.
typedef struct {
    u16 year;
    u8  month;
    u8  day;
    u8  weekday;
}rtc_date_typedef;

//--------------- Function used to configure or get get time ---------------//
void rtc_set_counter(uint32_t cnt);
uint32_t rtc_get_counter(void);
void rtc_set_alarm(uint32_t alm);
uint32_t rtc_get_alarm(void);
//------------- Function used to configure clock or interrupt --------------//
void rtc_clk_config(rtc_clk_typedef *clk_struct);
void rtc_pic_config(isr_t isr, int pr, uint16_t rtc_ie_bit, FUNCTIONAL_STATE state);
void rtc_wakeup_period_config(uint16_t period_select);
FLAG_STATE rtc_get_flag(uint32_t rtc_flag);
void rtc_clear_flag(uint32_t rtc_flag);

#endif // _GW3323_RTC_H
