Real Time Clock Driver

Detailed Description

Real Time Clock Driver Peripheral Driver.

Data Structures

struct  rtc_timedate_t
 RTC Time Date structure Implements : rtc_timedate_t_Class. More...
 
struct  rtc_init_config_t
 RTC Initialization structure Implements : rtc_init_config_t_Class. More...
 
struct  rtc_alarm_config_t
 RTC alarm configuration Implements : rtc_alarm_config_t_Class. More...
 
struct  rtc_interrupt_config_t
 RTC interrupt configuration. It is used to configure interrupt other than Time Alarm and Time Seconds interrupt Implements : rtc_interrupt_config_t_Class. More...
 
struct  rtc_seconds_int_config_t
 RTC Seconds Interrupt Configuration Implements : rtc_seconds_int_config_t_Class. More...
 
struct  rtc_register_lock_config_t
 RTC Register Lock Configuration Implements : rtc_register_lock_config_t_Class. More...
 

Macros

#define SECONDS_IN_A_DAY   (86400UL)
 
#define SECONDS_IN_A_HOUR   (3600U)
 
#define SECONDS_IN_A_MIN   (60U)
 
#define MINS_IN_A_HOUR   (60U)
 
#define HOURS_IN_A_DAY   (24U)
 
#define DAYS_IN_A_YEAR   (365U)
 
#define DAYS_IN_A_LEAP_YEAR   (366U)
 
#define YEAR_RANGE_START   (1970U)
 
#define YEAR_RANGE_END   (2099U)
 

Enumerations

enum  rtc_second_int_cfg_t {
  RTC_INT_1HZ = 0x00U, RTC_INT_2HZ = 0x01U, RTC_INT_4HZ = 0x02U, RTC_INT_8HZ = 0x03U,
  RTC_INT_16HZ = 0x04U, RTC_INT_32HZ = 0x05U, RTC_INT_64HZ = 0x06U, RTC_INT_128HZ = 0x07U
}
 RTC Seconds interrupt configuration Implements : rtc_second_int_cfg_t_Class. More...
 
enum  rtc_clk_out_config_t { RTC_CLKOUT_DISABLED = 0x00U, RTC_CLKOUT_SRC_TSIC = 0x01U, RTC_CLKOUT_SRC_32KHZ = 0x02U }
 RTC CLKOUT pin configuration Implements : rtc_clk_out_config_t_Class. More...
 
enum  rtc_clk_select_t { RTC_CLK_SRC_OSC_32KHZ = 0x00U, RTC_CLK_SRC_LPO_1KHZ = 0x01U }
 RTC clock select Implements : rtc_clk_select_t_Class. More...
 
enum  rtc_lock_register_select_t { RTC_LOCK_REG_LOCK = 0x00U, RTC_STATUS_REG_LOCK = 0x01U, RTC_CTRL_REG_LOCK = 0x02U, RTC_TCL_REG_LOCK = 0x03U }
 RTC register lock Implements : rtc_lock_register_select_t_Class. More...
 

Functions

status_t RTC_DRV_Init (uint32_t instance, const rtc_init_config_t *const rtcUserCfg)
 This function initializes the RTC instance with the settings provided by the user via the rtcUserCfg parameter. The user must ensure that clock is enabled for the RTC instance used. If the Control register is locked then this method returns STATUS_ERROR. In order to clear the CR Lock the user must perform a power-on reset. More...
 
status_t RTC_DRV_Deinit (uint32_t instance)
 This function deinitializes the RTC instance. If the Control register is locked then this method returns STATUS_ERROR. More...
 
void RTC_DRV_GetDefaultConfig (rtc_init_config_t *const config)
 This function will set the default configuration values into the structure passed as a parameter. More...
 
status_t RTC_DRV_StartCounter (uint32_t instance)
 Start RTC instance counter. Before calling this function the user should use RTC_DRV_SetTimeDate to configure the start time. More...
 
status_t RTC_DRV_StopCounter (uint32_t instance)
 Disable RTC instance counter. More...
 
status_t RTC_DRV_GetCurrentTimeDate (uint32_t instance, rtc_timedate_t *const currentTime)
 Get current time and date from RTC instance. More...
 
status_t RTC_DRV_SetTimeDate (uint32_t instance, const rtc_timedate_t *const time)
 Set time and date for RTC instance. The user must stop the counter before using this function. Otherwise it will return an error. More...
 
status_t RTC_DRV_ConfigureRegisterLock (uint32_t instance, const rtc_register_lock_config_t *const lockConfig)
 This method configures register lock for the corresponding RTC instance. Remember that all the registers are unlocked only by software reset or power on reset. (Except for CR that is unlocked only by POR). More...
 
void RTC_DRV_GetRegisterLock (uint32_t instance, rtc_register_lock_config_t *const lockConfig)
 Get which registers are locked for RTC instance. More...
 
status_t RTC_DRV_ConfigureTimeCompensation (uint32_t instance, uint8_t compInterval, int8_t compensation)
 This method configures time compensation. Data is passed by the compInterval and compensation parameters. For more details regarding coefficient calculation see the Reference Manual. More...
 
void RTC_DRV_GetTimeCompensation (uint32_t instance, uint8_t *compInterval, int8_t *compensation)
 This retrieves the time compensation coefficients and saves them on the variables referenced by the parameters. More...
 
void RTC_DRV_ConfigureFaultInt (uint32_t instance, rtc_interrupt_config_t *const intConfig)
 This method configures fault interrupts such as: More...
 
void RTC_DRV_ConfigureSecondsInt (uint32_t instance, rtc_seconds_int_config_t *const intConfig)
 This method configures the Time Seconds Interrupt with the configuration from the intConfig parameter. More...
 
status_t RTC_DRV_ConfigureAlarm (uint32_t instance, rtc_alarm_config_t *const alarmConfig)
 This method configures the alarm with the configuration from the alarmConfig parameter. More...
 
void RTC_DRV_GetAlarmConfig (uint32_t instance, rtc_alarm_config_t *alarmConfig)
 Get alarm configuration for RTC instance. More...
 
bool RTC_DRV_IsAlarmPending (uint32_t instance)
 Check if alarm is pending. More...
 
void RTC_DRV_ConvertSecondsToTimeDate (const uint32_t *seconds, rtc_timedate_t *const timeDate)
 Convert seconds to rtc_timedate_t structure. More...
 
void RTC_DRV_ConvertTimeDateToSeconds (const rtc_timedate_t *const timeDate, uint32_t *const seconds)
 Convert seconds to rtc_timedate_t structure. More...
 
bool RTC_DRV_IsYearLeap (uint16_t year)
 Check if the current year is leap. More...
 
bool RTC_DRV_IsTimeDateCorrectFormat (const rtc_timedate_t *const timeDate)
 Check if the date time struct is configured properly. More...
 
status_t RTC_DRV_GetNextAlarmTime (uint32_t instance, rtc_timedate_t *const alarmTime)
 Gets the next alarm time. More...
 
void RTC_DRV_IRQHandler (uint32_t instance)
 This method is the API's Interrupt handler for generic and alarm IRQ. It will handle the alarm repetition and calls the user callbacks if they are not NULL. More...
 
void RTC_DRV_SecondsIRQHandler (uint32_t instance)
 This method is the API's Interrupt handler for RTC Second interrupt. This ISR will call the user callback if defined. More...
 

Macro Definition Documentation

#define DAYS_IN_A_LEAP_YEAR   (366U)

Definition at line 42 of file rtc_driver.h.

#define DAYS_IN_A_YEAR   (365U)

Definition at line 41 of file rtc_driver.h.

#define HOURS_IN_A_DAY   (24U)

Definition at line 40 of file rtc_driver.h.

#define MINS_IN_A_HOUR   (60U)

Definition at line 39 of file rtc_driver.h.

#define SECONDS_IN_A_DAY   (86400UL)

Definition at line 36 of file rtc_driver.h.

#define SECONDS_IN_A_HOUR   (3600U)

Definition at line 37 of file rtc_driver.h.

#define SECONDS_IN_A_MIN   (60U)

Definition at line 38 of file rtc_driver.h.

#define YEAR_RANGE_END   (2099U)

Definition at line 44 of file rtc_driver.h.

#define YEAR_RANGE_START   (1970U)

Definition at line 43 of file rtc_driver.h.

Enumeration Type Documentation

RTC CLKOUT pin configuration Implements : rtc_clk_out_config_t_Class.

Enumerator
RTC_CLKOUT_DISABLED 

Clock out pin is disabled

RTC_CLKOUT_SRC_TSIC 

Output on RTC_CLKOUT as configured on Time seconds interrupt

RTC_CLKOUT_SRC_32KHZ 

Output on RTC_CLKOUT of the 32KHz clock

Definition at line 66 of file rtc_driver.h.

RTC clock select Implements : rtc_clk_select_t_Class.

Enumerator
RTC_CLK_SRC_OSC_32KHZ 

RTC Prescaler increments using 32 KHz crystal

RTC_CLK_SRC_LPO_1KHZ 

RTC Prescaler increments using 1KHz LPO

Definition at line 77 of file rtc_driver.h.

RTC register lock Implements : rtc_lock_register_select_t_Class.

Enumerator
RTC_LOCK_REG_LOCK 

RTC Lock Register lock

RTC_STATUS_REG_LOCK 

RTC Status Register lock

RTC_CTRL_REG_LOCK 

RTC Control Register lock

RTC_TCL_REG_LOCK 

RTC Time Compensation Reg lock

Definition at line 87 of file rtc_driver.h.

RTC Seconds interrupt configuration Implements : rtc_second_int_cfg_t_Class.

Enumerator
RTC_INT_1HZ 

RTC seconds interrupt occurs at 1 Hz

RTC_INT_2HZ 

RTC seconds interrupt occurs at 2 Hz

RTC_INT_4HZ 

RTC seconds interrupt occurs at 4 Hz

RTC_INT_8HZ 

RTC seconds interrupt occurs at 8 Hz

RTC_INT_16HZ 

RTC seconds interrupt occurs at 16 Hz

RTC_INT_32HZ 

RTC seconds interrupt occurs at 32 Hz

RTC_INT_64HZ 

RTC seconds interrupt occurs at 64 Hz

RTC_INT_128HZ 

RTC seconds interrupt occurs at 128 Hz

Definition at line 50 of file rtc_driver.h.

Function Documentation

status_t RTC_DRV_ConfigureAlarm ( uint32_t  instance,
rtc_alarm_config_t *const  alarmConfig 
)

This method configures the alarm with the configuration from the alarmConfig parameter.

Parameters
[in]instanceThe number of the RTC instance used
[in]alarmConfigPointer to the structure which holds the alarm configuration
Returns
STATUS_SUCCESS if the configuration is successful or STATUS_ERROR if the alarm time is invalid.

Definition at line 934 of file rtc_driver.c.

void RTC_DRV_ConfigureFaultInt ( uint32_t  instance,
rtc_interrupt_config_t *const  intConfig 
)

This method configures fault interrupts such as:

  • Time Overflow Interrupt
  • Time Invalid Interrupt with the user provided configuration struct intConfig.
Parameters
[in]instanceThe number of the RTC instance used
[in]intConfigPointer to the structure which holds the configuration
Returns
None

Definition at line 877 of file rtc_driver.c.

status_t RTC_DRV_ConfigureRegisterLock ( uint32_t  instance,
const rtc_register_lock_config_t *const  lockConfig 
)

This method configures register lock for the corresponding RTC instance. Remember that all the registers are unlocked only by software reset or power on reset. (Except for CR that is unlocked only by POR).

Parameters
[in]instanceThe number of the RTC instance used
[in]lockConfigPointer to the lock configuration structure
Returns
STATUS_SUCCESS if the operation was successful, STATUS_ERROR if the Lock Register is locked.

Definition at line 427 of file rtc_driver.c.

void RTC_DRV_ConfigureSecondsInt ( uint32_t  instance,
rtc_seconds_int_config_t *const  intConfig 
)

This method configures the Time Seconds Interrupt with the configuration from the intConfig parameter.

Parameters
[in]instanceThe number of the RTC instance used
[in]intConfigPointer to the structure which holds the configuration
Returns
None

Definition at line 904 of file rtc_driver.c.

status_t RTC_DRV_ConfigureTimeCompensation ( uint32_t  instance,
uint8_t  compInterval,
int8_t  compensation 
)

This method configures time compensation. Data is passed by the compInterval and compensation parameters. For more details regarding coefficient calculation see the Reference Manual.

Parameters
[in]instanceThe number of the RTC instance used
[in]compIntervalCompensation interval
[in]compensationCompensation value
Returns
STATUS_SUCCESS if the operation was successful, STATUS_ERROR if the TC Register is locked.

Definition at line 502 of file rtc_driver.c.

void RTC_DRV_ConvertSecondsToTimeDate ( const uint32_t *  seconds,
rtc_timedate_t *const  timeDate 
)

Convert seconds to rtc_timedate_t structure.

Parameters
[in]secondsPointer to the seconds
[out]timeDatePointer to the structure in which to store the result
Returns
None

Definition at line 552 of file rtc_driver.c.

void RTC_DRV_ConvertTimeDateToSeconds ( const rtc_timedate_t *const  timeDate,
uint32_t *const  seconds 
)

Convert seconds to rtc_timedate_t structure.

Parameters
[in]timeDatePointer to the source struct
[out]secondsPointer to the variable in which to store the result
Returns
None

Definition at line 646 of file rtc_driver.c.

status_t RTC_DRV_Deinit ( uint32_t  instance)

This function deinitializes the RTC instance. If the Control register is locked then this method returns STATUS_ERROR.

Parameters
[in]instanceThe number of the RTC instance used
Returns
STATUS_SUCCESS if the operation was successful or STATUS_ERROR if Control register is locked.

Definition at line 159 of file rtc_driver.c.

void RTC_DRV_GetAlarmConfig ( uint32_t  instance,
rtc_alarm_config_t alarmConfig 
)

Get alarm configuration for RTC instance.

Parameters
[in]instanceThe number of the RTC instance used
[out]alarmConfigPointer to the structure in which to store the alarm configuration
Returns
None

Definition at line 988 of file rtc_driver.c.

status_t RTC_DRV_GetCurrentTimeDate ( uint32_t  instance,
rtc_timedate_t *const  currentTime 
)

Get current time and date from RTC instance.

Parameters
[in]instanceThe number of the RTC instance used
[out]currentTimePointer to the variable in which to store the result
Returns
STATUS_SUCCESS if the operation was successful, STATUS_ERROR if there was a problem.

Definition at line 328 of file rtc_driver.c.

void RTC_DRV_GetDefaultConfig ( rtc_init_config_t *const  config)

This function will set the default configuration values into the structure passed as a parameter.

Parameters
[out]configPointer to the structure in which the configuration will be saved.
Returns
None

Definition at line 195 of file rtc_driver.c.

status_t RTC_DRV_GetNextAlarmTime ( uint32_t  instance,
rtc_timedate_t *const  alarmTime 
)

Gets the next alarm time.

Parameters
[in]instanceThe number of the RTC instance used
[out]alarmTimePointer to the variable in which to store the data
Returns
STATUS_SUCCESS if the next alarm time is valid, STATUS_ERROR if there is no new alarm or alarm configuration specified.

Definition at line 1020 of file rtc_driver.c.

void RTC_DRV_GetRegisterLock ( uint32_t  instance,
rtc_register_lock_config_t *const  lockConfig 
)

Get which registers are locked for RTC instance.

Parameters
[in]instanceThe number of the RTC instance used
[out]lockConfigPointer to the lock configuration structure in which to save the data
Returns
None

Definition at line 474 of file rtc_driver.c.

void RTC_DRV_GetTimeCompensation ( uint32_t  instance,
uint8_t *  compInterval,
int8_t *  compensation 
)

This retrieves the time compensation coefficients and saves them on the variables referenced by the parameters.

Parameters
[in]instanceThe number of the RTC instance used
[out]compIntervalPointer to the variable in which to save the compensation interval
[out]compensationPointer to the variable in which to save the compensation value
Returns
None

Definition at line 535 of file rtc_driver.c.

status_t RTC_DRV_Init ( uint32_t  instance,
const rtc_init_config_t *const  rtcUserCfg 
)

This function initializes the RTC instance with the settings provided by the user via the rtcUserCfg parameter. The user must ensure that clock is enabled for the RTC instance used. If the Control register is locked then this method returns STATUS_ERROR. In order to clear the CR Lock the user must perform a power-on reset.

Parameters
[in]instanceThe number of the RTC instance used
[in]rtcUserCfgPointer to the user's configuration structure
Returns
STATUS_SUCCESS if the operation was successful, STATUS_ERROR if Control is locked.

Definition at line 100 of file rtc_driver.c.

void RTC_DRV_IRQHandler ( uint32_t  instance)

This method is the API's Interrupt handler for generic and alarm IRQ. It will handle the alarm repetition and calls the user callbacks if they are not NULL.

Parameters
[in]instanceRTC instance used
Returns
None

Definition at line 774 of file rtc_driver.c.

bool RTC_DRV_IsAlarmPending ( uint32_t  instance)

Check if alarm is pending.

Parameters
[in]instanceThe number of the RTC instance used
Returns
True if the alarm has occurred, false if not

Definition at line 1003 of file rtc_driver.c.

bool RTC_DRV_IsTimeDateCorrectFormat ( const rtc_timedate_t *const  timeDate)

Check if the date time struct is configured properly.

Parameters
[in]timeDateStructure to check to check
Returns
True if the time date is in the correct format, false if not

Definition at line 696 of file rtc_driver.c.

bool RTC_DRV_IsYearLeap ( uint16_t  year)

Check if the current year is leap.

Parameters
[in]yearYear to check
Returns
True if the year is leap, false if not

Definition at line 738 of file rtc_driver.c.

void RTC_DRV_SecondsIRQHandler ( uint32_t  instance)

This method is the API's Interrupt handler for RTC Second interrupt. This ISR will call the user callback if defined.

Parameters
[in]instanceRTC instance used
Returns
None

Definition at line 851 of file rtc_driver.c.

status_t RTC_DRV_SetTimeDate ( uint32_t  instance,
const rtc_timedate_t *const  time 
)

Set time and date for RTC instance. The user must stop the counter before using this function. Otherwise it will return an error.

Parameters
[in]instanceThe number of the RTC instance used
[in]timePointer to the variable in which the time is stored
Returns
STATUS_SUCCESS if the operation was successful, STATUS_ERROR if the time provided was invalid or if the counter was not stopped.

Definition at line 383 of file rtc_driver.c.

status_t RTC_DRV_StartCounter ( uint32_t  instance)

Start RTC instance counter. Before calling this function the user should use RTC_DRV_SetTimeDate to configure the start time.

Parameters
[in]instanceThe number of the RTC instance used
Returns
STATUS_SUCCESS if the operation was successful, STATUS_ERROR if the counter cannot be enabled or is already enabled.

Definition at line 266 of file rtc_driver.c.

status_t RTC_DRV_StopCounter ( uint32_t  instance)

Disable RTC instance counter.

Parameters
[in]instanceThe number of the RTC instance used
Returns
STATUS_SUCCESS if the operation was successful, STATUS_ERROR if the counter could not be stopped.

Definition at line 297 of file rtc_driver.c.