Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Real-Time Clock (RTC)

See Quickstart guide for SAM RTC driver.

The RTC provides a full binary-coded decimal (BCD) clock that includes century (19/20), year (with leap years), month, date, day, hour, minute and second.

Modules

 
 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the Real-Time Clock (RTC).
 

Macros

#define BCD_FACTOR   10
 
#define BCD_MASK   0xfu
 
#define BCD_SHIFT   4
 
#define RTC_WP_KEY   (0x525443)
 

Functions

void rtc_clear_date_alarm (Rtc *p_rtc)
 Clear the RTC date alarm setting. More...
 
void rtc_clear_status (Rtc *p_rtc, uint32_t ul_clear)
 Set the RTC SCCR to clear status bits. More...
 
void rtc_clear_time_alarm (Rtc *p_rtc)
 Clear the RTC time alarm setting. More...
 
void rtc_disable_interrupt (Rtc *p_rtc, uint32_t ul_sources)
 Disable RTC interrupts. More...
 
void rtc_enable_interrupt (Rtc *p_rtc, uint32_t ul_sources)
 Enable RTC interrupts. More...
 
uint32_t rtc_get_calendar_mode (Rtc *p_rtc)
 Get the RTC calendar mode. More...
 
void rtc_get_date (Rtc *p_rtc, uint32_t *pul_year, uint32_t *pul_month, uint32_t *pul_day, uint32_t *pul_week)
 Get the RTC date value. More...
 
uint32_t rtc_get_hour_mode (Rtc *p_rtc)
 Get the RTC hour mode. More...
 
uint32_t rtc_get_interrupt_mask (Rtc *p_rtc)
 Read RTC interrupt mask. More...
 
uint32_t rtc_get_milliseconds (Rtc *p_rtc)
 Get the RTC milliseconds value. More...
 
uint32_t rtc_get_status (Rtc *p_rtc)
 Get the RTC status. More...
 
void rtc_get_tamper_date (Rtc *p_rtc, uint32_t *pul_year, uint32_t *pul_month, uint32_t *pul_day, uint32_t *pul_week, uint8_t reg_num)
 Get the RTC tamper date. More...
 
uint32_t rtc_get_tamper_event_counter (Rtc *p_rtc)
 Get the RTC tamper event counter. More...
 
uint32_t rtc_get_tamper_source (Rtc *p_rtc, uint8_t reg_num)
 Get the RTC tamper source. More...
 
void rtc_get_tamper_time (Rtc *p_rtc, uint32_t *pul_hour, uint32_t *pul_minute, uint32_t *pul_second, uint8_t reg_num)
 Get the RTC tamper time value. More...
 
void rtc_get_time (Rtc *p_rtc, uint32_t *pul_hour, uint32_t *pul_minute, uint32_t *pul_second)
 Get the RTC time value. More...
 
uint32_t rtc_get_valid_entry (Rtc *p_rtc)
 Get the RTC valid entry. More...
 
bool rtc_is_tamper_occur_in_backup_mode (Rtc *p_rtc, uint8_t reg_num)
 Check the system is in backup mode when RTC tamper event happen. More...
 
void rtc_set_calendar_event (Rtc *p_rtc, uint32_t ul_selection)
 Set the RTC calendar event selection. More...
 
void rtc_set_calendar_mode (Rtc *p_rtc, uint32_t ul_mode)
 Set the RTC calendar mode. More...
 
void rtc_set_calibration (Rtc *p_rtc, uint32_t ul_direction_ppm, uint32_t ul_correction, uint32_t ul_range_ppm)
 Set the RTC calibration. More...
 
uint32_t rtc_set_date (Rtc *p_rtc, uint32_t ul_year, uint32_t ul_month, uint32_t ul_day, uint32_t ul_week)
 Set the RTC date. More...
 
uint32_t rtc_set_date_alarm (Rtc *p_rtc, uint32_t ul_month_flag, uint32_t ul_month, uint32_t ul_day_flag, uint32_t ul_day)
 Set the RTC alarm date value. More...
 
void rtc_set_hour_mode (Rtc *p_rtc, uint32_t ul_mode)
 Set the RTC hour mode. More...
 
void rtc_set_pulse_parameter (Rtc *p_rtc, uint32_t ul_time_high, uint32_t ul_period)
 Set the pulse output waveform parameters. More...
 
uint32_t rtc_set_time (Rtc *p_rtc, uint32_t ul_hour, uint32_t ul_minute, uint32_t ul_second)
 Set the RTC time value. More...
 
uint32_t rtc_set_time_alarm (Rtc *p_rtc, uint32_t ul_hour_flag, uint32_t ul_hour, uint32_t ul_minute_flag, uint32_t ul_minute, uint32_t ul_second_flag, uint32_t ul_second)
 Set the RTC alarm time value. More...
 
void rtc_set_time_event (Rtc *p_rtc, uint32_t ul_selection)
 Set the RTC time event selection. More...
 
void rtc_set_waveform (Rtc *p_rtc, uint32_t ul_channel, uint32_t ul_value)
 Set the RTC output waveform. More...
 
void rtc_set_writeprotect (Rtc *p_rtc, uint32_t ul_enable)
 Enable or disable write protection of RTC registers. More...
 

#define BCD_MASK   0xfu
#define RTC_WP_KEY   (0x525443)

Referenced by rtc_set_writeprotect().

void rtc_clear_date_alarm ( Rtc *  p_rtc)

Clear the RTC date alarm setting.

Parameters
p_rtcPointer to an RTC instance.

Referenced by main().

void rtc_clear_status ( Rtc *  p_rtc,
uint32_t  ul_clear 
)

Set the RTC SCCR to clear status bits.

Parameters
p_rtcPointer to an RTC instance.
ul_clearSome flag bits which will be cleared.

Referenced by RTC_Handler().

void rtc_clear_time_alarm ( Rtc *  p_rtc)

Clear the RTC time alarm setting.

Parameters
p_rtcPointer to an RTC instance.

Referenced by main().

void rtc_disable_interrupt ( Rtc *  p_rtc,
uint32_t  ul_sources 
)

Disable RTC interrupts.

Parameters
p_rtcPointer to an RTC instance.
ul_sourcesInterrupts to be disabled.

Referenced by app_widget_launch_lpm_backup(), RTC_Handler(), and sys_enter_wait_mode().

void rtc_enable_interrupt ( Rtc *  p_rtc,
uint32_t  ul_sources 
)

Enable RTC interrupts.

Parameters
p_rtcPointer to an RTC instance.
ul_sourcesInterrupts to be enabled.

Referenced by main(), and RTC_Handler().

uint32_t rtc_get_calendar_mode ( Rtc *  p_rtc)

Get the RTC calendar mode.

Note
This function is only available on SAM3S8/3SD8/4S/4N/4C/G devices.
Parameters
p_rtcPointer to an RTC instance.
Returns
1 for Persian calendar, 0 for Gregorian calendar.
void rtc_get_date ( Rtc *  p_rtc,
uint32_t *  pul_year,
uint32_t *  pul_month,
uint32_t *  pul_day,
uint32_t *  pul_week 
)

Get the RTC date value.

Parameters
p_rtcPointer to an RTC instance.
pul_yearCurrent year.
pul_monthCurrent month.
pul_dayCurrent day.
pul_weekCurrent day in current week.

References BCD_FACTOR, BCD_MASK, and BCD_SHIFT.

Referenced by get_fattime(), refresh_display(), and task_win().

uint32_t rtc_get_hour_mode ( Rtc *  p_rtc)

Get the RTC hour mode.

Parameters
p_rtcPointer to an RTC instance.
Returns
1 for 12-hour mode, 0 for 24-hour mode.
uint32_t rtc_get_interrupt_mask ( Rtc *  p_rtc)

Read RTC interrupt mask.

Parameters
p_rtcPointer to an RTC instance.
Returns
The interrupt mask value.
uint32_t rtc_get_milliseconds ( Rtc *  p_rtc)

Get the RTC milliseconds value.

Note
This function is only available on SAMG55 devices.
Parameters
p_rtcPointer to an RTC instance.
Returns
Number of 1/1024 seconds elapsed within one second.
uint32_t rtc_get_status ( Rtc *  p_rtc)

Get the RTC status.

Parameters
p_rtcPointer to an RTC instance.
Returns
Status of the RTC.

Referenced by RTC_Handler().

void rtc_get_tamper_date ( Rtc *  p_rtc,
uint32_t *  pul_year,
uint32_t *  pul_month,
uint32_t *  pul_day,
uint32_t *  pul_week,
uint8_t  reg_num 
)

Get the RTC tamper date.

Note
This function is only available on SAM4C devices.
This function should be called before rtc_get_tamper_source() function call, Otherwise the tamper date will be cleared.
Parameters
p_rtcPointer to an RTC instance.
pul_yearCurrent year.
pul_monthCurrent month.
pul_dayCurrent day.
pul_weekCurrent day in current week.
reg_numCurrent tamper register set number.

References BCD_FACTOR, BCD_MASK, and BCD_SHIFT.

uint32_t rtc_get_tamper_event_counter ( Rtc *  p_rtc)

Get the RTC tamper event counter.

Note
This function is only available on SAM4C devices.
This function should be called before rtc_get_tamper_source() function call, Otherwise the tamper event counter will be cleared.
Parameters
p_rtcPointer to an RTC instance.
Returns
Tamper event counter
uint32_t rtc_get_tamper_source ( Rtc *  p_rtc,
uint8_t  reg_num 
)

Get the RTC tamper source.

Note
This function is only available on SAM4C devices.
Parameters
p_rtcPointer to an RTC instance.
reg_numCurrent tamper register set number.
Returns
Tamper source.
void rtc_get_tamper_time ( Rtc *  p_rtc,
uint32_t *  pul_hour,
uint32_t *  pul_minute,
uint32_t *  pul_second,
uint8_t  reg_num 
)

Get the RTC tamper time value.

Note
This function is only available on SAM4C devices.
This function should be called before rtc_get_tamper_source() function call, Otherwise the tamper time will be cleared.
Parameters
p_rtcPointer to an RTC instance.
pul_hourCurrent hour, 24-hour mode.
pul_minuteCurrent minute.
pul_secondCurrent second.
reg_numCurrent tamper register set number.

References BCD_FACTOR, BCD_MASK, and BCD_SHIFT.

void rtc_get_time ( Rtc *  p_rtc,
uint32_t *  pul_hour,
uint32_t *  pul_minute,
uint32_t *  pul_second 
)

Get the RTC time value.

Parameters
p_rtcPointer to an RTC instance.
pul_hourCurrent hour, 24-hour mode.
pul_minuteCurrent minute.
pul_secondCurrent second.

References BCD_FACTOR, BCD_MASK, and BCD_SHIFT.

Referenced by app_widget_launch_settings_time(), get_fattime(), refresh_display(), and task_win().

uint32_t rtc_get_valid_entry ( Rtc *  p_rtc)

Get the RTC valid entry.

Parameters
p_rtcPointer to an RTC instance.
Returns
0 for no invalid data, else has contained invalid data.
bool rtc_is_tamper_occur_in_backup_mode ( Rtc *  p_rtc,
uint8_t  reg_num 
)

Check the system is in backup mode when RTC tamper event happen.

Note
This function is only available on SAM4C devices.
This function should be called before rtc_get_tamper_source() function call, Otherwise the flag indicates tamper occur in backup mode will be cleared.
Parameters
p_rtcPointer to an RTC instance.
reg_numCurrent tamper register set number.
Returns
True - The system is in backup mode when the tamper event occurs. Flase - The system is different from backup mode.
void rtc_set_calendar_event ( Rtc *  p_rtc,
uint32_t  ul_selection 
)

Set the RTC calendar event selection.

Parameters
p_rtcPointer to an RTC instance.
ul_selectionCalendar event selection to be enabled..
void rtc_set_calendar_mode ( Rtc *  p_rtc,
uint32_t  ul_mode 
)

Set the RTC calendar mode.

Note
This function is only available on SAM3S8/3SD8/4S/4N/4C/G devices.
Parameters
p_rtcPointer to an RTC instance.
ul_mode1 for Persian mode,0 for Gregorian mode.
void rtc_set_calibration ( Rtc *  p_rtc,
uint32_t  ul_direction_ppm,
uint32_t  ul_correction,
uint32_t  ul_range_ppm 
)

Set the RTC calibration.

Note
This function is only available on SAM3S8/3SD8/4S/4N/4C/G devices.
Parameters
p_rtcPointer to an RTC instance.
ul_direction_ppmPositive/negative correction.
ul_correctionCorrection value.
ul_range_ppmLow/high range correction.
uint32_t rtc_set_date ( Rtc *  p_rtc,
uint32_t  ul_year,
uint32_t  ul_month,
uint32_t  ul_day,
uint32_t  ul_week 
)

Set the RTC date.

Parameters
p_rtcPointer to an RTC instance.
ul_yearCurrent year.
ul_monthCurrent month.
ul_dayCurrent day.
ul_weekCurrent day in current week.
Returns
0 for OK, else invalid setting.

References BCD_FACTOR, and BCD_SHIFT.

Referenced by main(), and widget_settings_date_setup_command_handler().

uint32_t rtc_set_date_alarm ( Rtc *  p_rtc,
uint32_t  ul_month_flag,
uint32_t  ul_month,
uint32_t  ul_day_flag,
uint32_t  ul_day 
)

Set the RTC alarm date value.

Parameters
p_rtcPointer to an RTC instance.
ul_month_flag1 for setting, 0 for not setting.
ul_monthAlarm month value.
ul_day_flag1 for setting, 0 for not setting.
ul_dayAlarm day value.
Returns
0 for OK, else invalid setting.

References BCD_FACTOR, and BCD_SHIFT.

Referenced by main().

void rtc_set_hour_mode ( Rtc *  p_rtc,
uint32_t  ul_mode 
)

Set the RTC hour mode.

Parameters
p_rtcPointer to an RTC instance.
ul_mode1 for 12-hour mode, 0 for 24-hour mode.

Referenced by disk_initialize(), and main().

void rtc_set_pulse_parameter ( Rtc *  p_rtc,
uint32_t  ul_time_high,
uint32_t  ul_period 
)

Set the pulse output waveform parameters.

Note
This function is only available on SAM3S8/3SD8/4S/4C/V/S/E devices.
Parameters
p_rtcPointer to an RTC instance.
ul_time_highHigh duration of the output pulse.
ul_periodPeriod of the output pulse.
uint32_t rtc_set_time ( Rtc *  p_rtc,
uint32_t  ul_hour,
uint32_t  ul_minute,
uint32_t  ul_second 
)

Set the RTC time value.

Parameters
p_rtcPointer to an RTC instance.
ul_hourCurrent hour, 24-hour mode.
ul_minuteCurrent minute.
ul_secondCurrent second.
Returns
0 for OK, else invalid setting.

References BCD_FACTOR, and BCD_SHIFT.

Referenced by main(), and widget_settings_time_setup_command_handler().

uint32_t rtc_set_time_alarm ( Rtc *  p_rtc,
uint32_t  ul_hour_flag,
uint32_t  ul_hour,
uint32_t  ul_minute_flag,
uint32_t  ul_minute,
uint32_t  ul_second_flag,
uint32_t  ul_second 
)

Set the RTC alarm time value.

Parameters
p_rtcPointer to an RTC instance.
ul_hour_flag1 for setting, 0 for not setting.
ul_hourAlarm hour value, 24-hour mode.
ul_minute_flag1 for setting, 0 for not setting.
ul_minuteAlarm minute value.
ul_second_flag1 for setting, 0 for not setting.
ul_secondAlarm second value.
Returns
0 for OK, else invalid setting.

References BCD_FACTOR, and BCD_SHIFT.

Referenced by main().

void rtc_set_time_event ( Rtc *  p_rtc,
uint32_t  ul_selection 
)

Set the RTC time event selection.

Parameters
p_rtcPointer to an RTC instance.
ul_selectionTime event selection to be enabled.
void rtc_set_waveform ( Rtc *  p_rtc,
uint32_t  ul_channel,
uint32_t  ul_value 
)

Set the RTC output waveform.

Note
This function is only available on SAM3S8/3SD8/4S/4C/G/V/S/E devices.
Parameters
p_rtcPointer to an RTC instance.
ul_channelOutput channel selection.
ul_valueOutput source selection value.

Referenced by main().

void rtc_set_writeprotect ( Rtc *  p_rtc,
uint32_t  ul_enable 
)

Enable or disable write protection of RTC registers.

Note
This function is only available on SAM3N/3U/3XA devices.
Parameters
p_rtcPointer to an RTC instance.
ul_enable1 to enable, 0 to disable.

References RTC_WP_KEY.