SemiDrive SSDK Appication Program Interface PTG3.0
Data Structures | Functions
sdrv_rtc.h File Reference
#include <stdint.h>
#include <types.h>
#include <sdrv_common.h>
#include <reg.h>
#include <regs_base.h>

Go to the source code of this file.

Data Structures

struct  rtc_time
 
struct  sdrv_rtc
 
struct  rtc_wkalrm
 

Functions

static void sdrv_rtc_reg_parity_err_int_enable (uint32_t base)
 
static void sdrv_rtc_reg_parity_err_int_disable (uint32_t base)
 
static bool is_leap_year (uint32_t year)
 
uint64_t rtc_to_epoch (struct rtc_time *tm)
 
status_t epoch_to_rtc (struct rtc_time *tm, uint64_t epoch_sec)
 
uint64_t rtc_to_epoch_ms (struct rtc_time *tm)
 
status_t epoch_ms_to_rtc (struct rtc_time *tm, uint64_t epoch_millisec)
 
status_t sdrv_rtc_enable (sdrv_rtc_t *dev, bool enable)
 
status_t sdrv_rtc_wakeup_enable (sdrv_rtc_t *dev, sdrv_rtc_wakeup_enable_type_e type, bool enable)
 
bool sdrv_rtc_get_wakeup_status (sdrv_rtc_t *dev)
 
status_t sdrv_rtc_clear_wakeup_status (sdrv_rtc_t *dev)
 
sdrv_rtc_violation_e sdrv_rtc_get_violation_status (sdrv_rtc_t *dev)
 
status_t sdrv_rtc_clear_violation_status (sdrv_rtc_t *dev, sdrv_rtc_violation_e vio)
 
status_t sdrv_rtc_violation_intr_enable (sdrv_rtc_t *dev, sdrv_rtc_violation_e vio, bool en)
 
status_t sdrv_rtc_get_time (sdrv_rtc_t *dev, struct rtc_time *tm)
 
status_t sdrv_rtc_set_time (sdrv_rtc_t *dev, struct rtc_time *tm)
 
status_t sdrv_rtc_get_alarm (sdrv_rtc_t *dev, struct rtc_wkalrm *alrm)
 
status_t sdrv_rtc_set_alarm (sdrv_rtc_t *dev, struct rtc_wkalrm *alrm)
 
status_t sdrv_rtc_enable_alarm (sdrv_rtc_t *dev, bool enable)
 
status_t sdrv_rtc_enable_it (uint32_t source, void *arg, rtc_cb_t cb)
 
status_t sdrv_rtc_disable_it (uint32_t source)
 
uint32_t sdrv_rtc_read_general_purpose_reg (sdrv_rtc_t *dev, sdrv_general_purpose_e gp_num)
 
status_t sdrv_rtc_write_general_purpose_reg (sdrv_rtc_t *dev, sdrv_general_purpose_e gp_num, uint32_t value)
 
status_t sdrv_rtc_lock (sdrv_rtc_t *dev)
 

Detailed Description

Macro Definition Documentation

◆ SDRV_RTC_REG_PARITY_ERR_DISABLE

#define SDRV_RTC_REG_PARITY_ERR_DISABLE ( )
Value:
sdrv_rtc_reg_parity_err_int_disable(APB_RTC2_BASE);
static void sdrv_rtc_reg_parity_err_int_disable(uint32_t base)
Disable RTC Register parity error interrupt status.
Definition: sdrv_rtc.h:108

◆ SDRV_RTC_REG_PARITY_ERR_ENABLE

#define SDRV_RTC_REG_PARITY_ERR_ENABLE ( )
Value:
sdrv_rtc_reg_parity_err_int_enable(APB_RTC2_BASE);
static void sdrv_rtc_reg_parity_err_int_enable(uint32_t base)
Enable RTC Register parity error interrupt status.
Definition: sdrv_rtc.h:98

Typedef Documentation

◆ rtc_cb_t

typedef int(* rtc_cb_t) (uint32_t irq, void *arg)

◆ sdrv_general_purpose_e

◆ sdrv_rtc_t

typedef struct sdrv_rtc sdrv_rtc_t

RTC device structure.

◆ sdrv_rtc_violation_e

◆ sdrv_rtc_wakeup_enable_type_e

Enumeration Type Documentation

◆ sdrv_general_purpose

Enumerator
SDRV_RTC_GP0 
SDRV_RTC_GP1 
SDRV_RTC_GP2 
SDRV_RTC_GP3 

◆ sdrv_rtc_error

RTC status error code.

Enumerator
SDRV_RTC_STATUS_INVALID_RTC_TIME 
SDRV_RTC_STATUS_LOCK 

◆ sdrv_rtc_violation_enum

Enumerator
SDRV_RTC_VIO_NONE 
SDRV_RTC_VIO_OVERFLOW 
SDRV_RTC_VIO_DISABLE 
SDRV_RTC_VIO_ALL 

◆ sdrv_rtc_wakeup_enable_type

Enumerator
SDRV_WKUP_ENABLE 
SDRV_WKUP_ENABLE_IRQ 
SDRV_WKUP_ENABLE_REQ 
SDRV_WKUP_ENABLE_ALL 

Function Documentation

◆ epoch_ms_to_rtc()

status_t epoch_ms_to_rtc ( struct rtc_time tm,
uint64_t  epoch_millisec 
)

Simple algorithm to convert epoch milliseconds to RTC time.

Epoch milliseconds starts from 1970-1-1, 00:00:00.001

Parameters
[out]tmrtc time
[in]epoch_millisecuint64_t number of milliseconds since epoch.
Returns
0 success, otherwise failed.

◆ epoch_to_rtc()

status_t epoch_to_rtc ( struct rtc_time tm,
uint64_t  epoch_sec 
)

Simple algorithm to convert epoch seconds to RTC time.

Epoch seconds starts from 1970-1-1, 00:00:01

Parameters
[out]tmrtc time
[in]epoch_secuint64_t number of seconds since epoch.
Returns
0 success, otherwise failed.

◆ is_leap_year()

static bool is_leap_year ( uint32_t  year)
inlinestatic

check is leap yaer

Parameters
[in]year
Returns
true is leap year, false is not leap year.

◆ rtc_to_epoch()

uint64_t rtc_to_epoch ( struct rtc_time tm)

Simple algorithm to convert RTC time to Epoch seconds.

Epoch seconds starts from 1970-1-1, 00:00:01

Parameters
[in]tmrtc time.
Returns
uint64_t Number of seconds since Epoch.

◆ rtc_to_epoch_ms()

uint64_t rtc_to_epoch_ms ( struct rtc_time tm)

Simple algorithm to convert RTC time to Epoch milliseconds.

Epoch seconds starts from 1970-1-1, 00:00:00.001

Parameters
[in]tmrtc time.
Returns
uint64_t number of milliseconds since epoch.

◆ sdrv_rtc_clear_violation_status()

status_t sdrv_rtc_clear_violation_status ( sdrv_rtc_t dev,
sdrv_rtc_violation_e  vio 
)

sdrv rtc clear violation status.

Parameters
[in]devsdrv rtc controller
[in]viosdrv rtc violation type
Returns
0 success, otherwise failed.

◆ sdrv_rtc_clear_wakeup_status()

status_t sdrv_rtc_clear_wakeup_status ( sdrv_rtc_t dev)

sdrv clear rtc wake up status.

Parameters
[in]devsdrv rtc controller
Returns
0 success, otherwise failed.

◆ sdrv_rtc_disable_it()

status_t sdrv_rtc_disable_it ( uint32_t  source)

disable rtc interrput.

Parameters
sourcertc wakeup/periodical/violation interrupt num.
Returns
0 success, otherwise failed.

◆ sdrv_rtc_enable()

status_t sdrv_rtc_enable ( sdrv_rtc_t dev,
bool  enable 
)

sdrv rtc enable.

Parameters
[in]devsdrv rtc controller
[in]enableenable or disable
Returns
0 success, otherwise failed.

◆ sdrv_rtc_enable_alarm()

status_t sdrv_rtc_enable_alarm ( sdrv_rtc_t dev,
bool  enable 
)

Enable rtc alarm.

Parameters
[in]devsdrv rtc controller
[in]enableenable or disable
Returns
0 success, otherwise failed.

◆ sdrv_rtc_enable_it()

status_t sdrv_rtc_enable_it ( uint32_t  source,
void *  arg,
rtc_cb_t  cb 
)

Enable rtc interrupt.

Parameters
[in]sourcertc wakeup/periodical/violation interrupt num.
[in]argpointer to interrupt arg(rtc device structure).
[in]cbcallback function.

◆ sdrv_rtc_get_alarm()

status_t sdrv_rtc_get_alarm ( sdrv_rtc_t dev,
struct rtc_wkalrm alrm 
)

rtc get alarm

Get rtc alarm time, rtc will trigger interrupt when rtc time arrives at alarm time.

Parameters
[in]devsdrv rtc controller
[in]alrmrtc wakeup alarm infomation
Returns
0 success, otherwise failed.

◆ sdrv_rtc_get_time()

status_t sdrv_rtc_get_time ( sdrv_rtc_t dev,
struct rtc_time tm 
)

rtc get time

Get current rtc time.

Parameters
[in]devsdrv rtc controller
[in]tmrtc time
Returns
0 success, otherwise failed.

◆ sdrv_rtc_get_violation_status()

sdrv_rtc_violation_e sdrv_rtc_get_violation_status ( sdrv_rtc_t dev)

sdrv get rtc violation status.

Parameters
[in]devsdrv rtc controller
Returns
0 no violation, 1 overflow violation, 2 disable violation, 3 overflow & disable

◆ sdrv_rtc_get_wakeup_status()

bool sdrv_rtc_get_wakeup_status ( sdrv_rtc_t dev)

sdrv get rtc wake up status.

Parameters
[in]devsdrv rtc controller
Returns
1 wakeup, 0 not wakeup.

◆ sdrv_rtc_lock()

status_t sdrv_rtc_lock ( sdrv_rtc_t dev)

rtc lock.

Once set rtc lock, rtc enable can not be changed until next power on reset.

Parameters
[in]devsdrv rtc controller
Returns
0 success, otherwise failed.

◆ sdrv_rtc_read_general_purpose_reg()

uint32_t sdrv_rtc_read_general_purpose_reg ( sdrv_rtc_t dev,
sdrv_general_purpose_e  gp_num 
)

Read rtc general purpose register.

Data in general purpose register will not be lost until RTC power down.

Parameters
[in]devsdrv rtc controller
[in]gp_numsdrv general purpose register num
Returns
general purpose register value

◆ sdrv_rtc_reg_parity_err_int_disable()

static void sdrv_rtc_reg_parity_err_int_disable ( uint32_t  base)
inlinestatic

Disable RTC Register parity error interrupt status.

Parameters
baseRTC Controller Base.

◆ sdrv_rtc_reg_parity_err_int_enable()

static void sdrv_rtc_reg_parity_err_int_enable ( uint32_t  base)
inlinestatic

Enable RTC Register parity error interrupt status.

Parameters
baseRTC Controller Base.

◆ sdrv_rtc_set_alarm()

status_t sdrv_rtc_set_alarm ( sdrv_rtc_t dev,
struct rtc_wkalrm alrm 
)

rtc set alarm

Set rtc alarm time, rtc will trigger interrupt when rtc time arrives at alarm time.

Parameters
[in]devsdrv rtc controller
[in]alrmrtc wakeup alarm config
Returns
0 success, otherwise failed.

◆ sdrv_rtc_set_time()

status_t sdrv_rtc_set_time ( sdrv_rtc_t dev,
struct rtc_time tm 
)

rtc set time

Set current rtc time.

Parameters
[in]devsdrv rtc controller
[in]tmrtc time
Returns
0 success, otherwise failed.

◆ sdrv_rtc_violation_intr_enable()

status_t sdrv_rtc_violation_intr_enable ( sdrv_rtc_t dev,
sdrv_rtc_violation_e  vio,
bool  en 
)

sdrv rtc violation enable.

Parameters
[in]devsdrv rtc controller
[in]vio_masksdrv rtc violation type
[in]enviolation enable or disable
Returns
0 success, otherwise failed.

◆ sdrv_rtc_wakeup_enable()

status_t sdrv_rtc_wakeup_enable ( sdrv_rtc_t dev,
sdrv_rtc_wakeup_enable_type_e  type,
bool  enable 
)

sdrv enable rtc wake up.

Parameters
[in]devsdrv rtc controller
[in]typesdrv rtc wake up type
[in]enableenable or disable
Returns
0 success, otherwise failed.

◆ sdrv_rtc_write_general_purpose_reg()

status_t sdrv_rtc_write_general_purpose_reg ( sdrv_rtc_t dev,
sdrv_general_purpose_e  gp_num,
uint32_t  value 
)

Write rtc general purpose register.

Parameters
[in]devsdrv rtc controller
[in]gp_numsdrv general purpose register num
[in]valuegeneral purpose register value
Returns
0 success, otherwise failed.