Driver API for RTC (plib_rtc.h) More...
Data Structures | |
| struct | RTC_TIME |
| RTC time value, BCD-encoded per datasheet RTC_TIMR format. More... | |
| struct | RTC_CALENDAR |
| RTC calendar value, BCD-encoded per datasheet RTC_CALR format. More... | |
| struct | RTC_TIME_ALARM |
| Time alarm configuration. More... | |
| struct | RTC_CALENDAR_ALARM |
| Calendar alarm configuration. More... | |
Typedefs | |
| typedef void(* | RTC_CALLBACK_HANDLER) (void) |
| Function pointer type for RTC callback. | |
| typedef uint8_t | RTC_CALENDAR_MODE |
| RTC calendar mode identifier. | |
| typedef uint8_t | RTC_HOUR_MODE |
| RTC hour mode identifier. | |
| typedef uint8_t | RTC_WAVEFORM_OUTPUT |
| RTC output channel identifier. | |
| typedef uint8_t | RTC_WAVEFORM_TYPE |
| RTC waveform type identifier. | |
| typedef uint8_t | RTC_TPERIOD |
| RTC programmable-pulse period identifier. | |
| typedef uint8_t | RTC_THIGH |
| RTC programmable-pulse high-duration identifier. | |
| typedef uint8_t | RTC_TIME_EVENT |
| RTC time-event selector identifier. | |
| typedef uint8_t | RTC_CALENDAR_EVENT |
| RTC calendar-event selector identifier. | |
Functions | |
| void | RTC_ClearUpdateRequest (void) |
| Clears a latched UPDTIM/UPDCAL update request in RTC_CR. Use this to abort an in-progress or stale time/calendar update handshake (e.g. one left set by a previous run) before starting a fresh one. | |
| bool | RTC_SetTime (const RTC_TIME *time_value) |
| Sets the current time in the RTC peripheral. | |
| bool | RTC_GetTime (RTC_TIME *time_value) |
| Gets the current time from the RTC peripheral. | |
| bool | RTC_SetCalendar (const RTC_CALENDAR *calendar) |
| Sets the current calendar in the RTC peripheral. | |
| bool | RTC_GetCalendar (RTC_CALENDAR *calendar) |
| Gets the current calendar from the RTC peripheral. | |
| bool | RTC_SetDateTime (const RTC_TIME *time_value, const RTC_CALENDAR *calendar) |
| Sets both time and calendar atomically. | |
| bool | RTC_SetTimeAlarm (const RTC_TIME_ALARM *alarm) |
| Configures the time alarm. | |
| bool | RTC_SetCalendarAlarm (const RTC_CALENDAR_ALARM *alarm) |
| Configures the calendar alarm. | |
| void | RTC_EnableInterrupt (uint32_t interrupt_mask) |
| Enables one or more RTC interrupt sources. | |
| void | RTC_DisableInterrupt (uint32_t interrupt_mask) |
| Disables one or more RTC interrupt sources. | |
| void | RTC_SetCallbackHandler (RTC_CALLBACK_HANDLER callback) |
| Registers the callback handler to be invoked from the RTC ISR. | |
| void | RTC_SelectCalendarMode (RTC_CALENDAR_MODE mode) |
| Selects the calendar mode (Gregorian or Persian). | |
| void | RTC_SetHourMode (RTC_HOUR_MODE mode) |
| Sets the hour mode (12h or 24h). | |
| void | RTC_SetWaveformOutput (RTC_WAVEFORM_OUTPUT output, RTC_WAVEFORM_TYPE type) |
| Configures the RTCOUT0 or RTCOUT1 output waveform. | |
| void | RTC_SetProgrammablePulse (RTC_TPERIOD period, RTC_THIGH high) |
| Configures the programmable pulse generator (RTC_MR.TPERIOD/THIGH). | |
| void | RTC_SetTimeEventSelection (RTC_TIME_EVENT event) |
| Selects which time-event trigger asserts RTC_SR.TIMEV. | |
| void | RTC_SetCalendarEventSelection (RTC_CALENDAR_EVENT event) |
| Selects which calendar-event trigger asserts RTC_SR.CALEV. | |
| void | RTC_ClearStatus (uint32_t status_mask) |
| Clears one or more status flags via RTC_SCCR. | |
| uint32_t | RTC_GetStatus (void) |
| Reads RTC_SR. | |
Variables | |
| uint8_t | RTC_TIME::hour |
| uint8_t | RTC_TIME::minute |
| uint8_t | RTC_TIME::second |
| uint8_t | RTC_TIME::am_pm |
| uint8_t | RTC_CALENDAR::century |
| uint8_t | RTC_CALENDAR::year |
| uint8_t | RTC_CALENDAR::month |
| uint8_t | RTC_CALENDAR::date |
| uint8_t | RTC_CALENDAR::day |
| uint8_t | RTC_TIME_ALARM::hour |
| uint8_t | RTC_TIME_ALARM::minute |
| uint8_t | RTC_TIME_ALARM::second |
| uint8_t | RTC_TIME_ALARM::am_pm |
| uint8_t | RTC_TIME_ALARM::enable_hour |
| uint8_t | RTC_TIME_ALARM::enable_minute |
| uint8_t | RTC_TIME_ALARM::enable_second |
| uint8_t | RTC_CALENDAR_ALARM::date |
| uint8_t | RTC_CALENDAR_ALARM::month |
| uint8_t | RTC_CALENDAR_ALARM::enable_date |
| uint8_t | RTC_CALENDAR_ALARM::enable_month |
Driver API for RTC (plib_rtc.h)
The following example demonstrates typical usage of the RTC peripheral:
RTC calendar-event selector identifier.
Raw 2-bit code for RTC_CR.CALEVSEL. Accepted values are RTC_CR_CALEVSEL_*_Val macros from the device header.
RTC calendar mode identifier.
Selects Gregorian or Persian calendar (RTC_MR.PERSIAN). Valid values: 0 (Gregorian), 1 (Persian).
| typedef void(* RTC_CALLBACK_HANDLER) (void) |
Function pointer type for RTC callback.
RTC hour mode identifier.
Selects 24-hour or 12-hour time representation (RTC_MR.HRMOD). Valid values: 0 (24h), 1 (12h).
RTC programmable-pulse high-duration identifier.
Raw 3-bit code for RTC_MR.THIGH. Accepted values are RTC_MR_THIGH_H_*_Val macros from the device header.
RTC time-event selector identifier.
Raw 2-bit code for RTC_CR.TIMEVSEL. Accepted values are RTC_CR_TIMEVSEL_*_Val macros from the device header.
RTC programmable-pulse period identifier.
Raw 2-bit code for RTC_MR.TPERIOD. Accepted values are RTC_MR_TPERIOD_P_*_Val macros from the device header.
RTC output channel identifier.
Selects which RTCOUT pin (0 or 1) a waveform configuration targets.
RTC waveform type identifier.
Raw 3-bit source code for the selected RTC_MR.OUTx field. Accepted values are the RTC_MR_OUT0_*_Val macros from the device header (e.g. RTC_MR_OUT0_FREQ1HZ_Val, RTC_MR_OUT0_ALARM_FLAG_Val).
| void RTC_ClearStatus | ( | uint32_t | status_mask | ) |
Clears one or more status flags via RTC_SCCR.
| status_mask | Bitwise OR of RTC_SCCR_*_Msk values from the DFP. |
| void RTC_ClearUpdateRequest | ( | void | ) |
Clears a latched UPDTIM/UPDCAL update request in RTC_CR. Use this to abort an in-progress or stale time/calendar update handshake (e.g. one left set by a previous run) before starting a fresh one.
| void RTC_DisableInterrupt | ( | uint32_t | interrupt_mask | ) |
Disables one or more RTC interrupt sources.
| interrupt_mask | Bitwise OR of RTC_IDR_*_Msk values from the DFP. |
| void RTC_EnableInterrupt | ( | uint32_t | interrupt_mask | ) |
Enables one or more RTC interrupt sources.
| interrupt_mask | Bitwise OR of RTC_IER_*_Msk values from the DFP. |
| bool RTC_GetCalendar | ( | RTC_CALENDAR * | calendar | ) |
Gets the current calendar from the RTC peripheral.
| calendar | Pointer to destination structure. Must not be NULL. |
| uint32_t RTC_GetStatus | ( | void | ) |
Reads RTC_SR.
| bool RTC_GetTime | ( | RTC_TIME * | time_value | ) |
Gets the current time from the RTC peripheral.
| time_value | Pointer to destination structure. Must not be NULL. |
| void RTC_SelectCalendarMode | ( | RTC_CALENDAR_MODE | mode | ) |
Selects the calendar mode (Gregorian or Persian).
| mode | RTC_CALENDAR_MODE value (0 = Gregorian, 1 = Persian). |
| bool RTC_SetCalendar | ( | const RTC_CALENDAR * | calendar | ) |
Sets the current calendar in the RTC peripheral.
| calendar | Pointer to BCD-encoded calendar. Must not be NULL. |
| bool RTC_SetCalendarAlarm | ( | const RTC_CALENDAR_ALARM * | alarm | ) |
Configures the calendar alarm.
| alarm | Pointer to alarm configuration. Must not be NULL. |
| void RTC_SetCalendarEventSelection | ( | RTC_CALENDAR_EVENT | event | ) |
Selects which calendar-event trigger asserts RTC_SR.CALEV.
| event | RTC_CALENDAR_EVENT value (raw RTC_CR.CALEVSEL code). |
| void RTC_SetCallbackHandler | ( | RTC_CALLBACK_HANDLER | callback | ) |
Registers the callback handler to be invoked from the RTC ISR.
| callback | Pointer to the callback function (NULL to clear). |
| bool RTC_SetDateTime | ( | const RTC_TIME * | time_value, |
| const RTC_CALENDAR * | calendar ) |
Sets both time and calendar atomically.
| time_value | Pointer to BCD-encoded time. Must not be NULL. |
| calendar | Pointer to BCD-encoded calendar. Must not be NULL. |
| void RTC_SetHourMode | ( | RTC_HOUR_MODE | mode | ) |
Sets the hour mode (12h or 24h).
| mode | RTC_HOUR_MODE value (0 = 24h, 1 = 12h). |
| void RTC_SetProgrammablePulse | ( | RTC_TPERIOD | period, |
| RTC_THIGH | high ) |
Configures the programmable pulse generator (RTC_MR.TPERIOD/THIGH).
| period | Pulse period selector. |
| high | Pulse high-duration selector. |
| bool RTC_SetTime | ( | const RTC_TIME * | time_value | ) |
Sets the current time in the RTC peripheral.
| time_value | Pointer to BCD-encoded time. Must not be NULL. |
| bool RTC_SetTimeAlarm | ( | const RTC_TIME_ALARM * | alarm | ) |
Configures the time alarm.
| alarm | Pointer to alarm configuration. Must not be NULL. |
| void RTC_SetTimeEventSelection | ( | RTC_TIME_EVENT | event | ) |
Selects which time-event trigger asserts RTC_SR.TIMEV.
| event | RTC_TIME_EVENT value (raw RTC_CR.TIMEVSEL code). |
| void RTC_SetWaveformOutput | ( | RTC_WAVEFORM_OUTPUT | output, |
| RTC_WAVEFORM_TYPE | type ) |
Configures the RTCOUT0 or RTCOUT1 output waveform.
| output | Which output to program (0 or 1). |
| type | Waveform source (raw RTC_MR_OUTx code). |
| uint8_t RTC_TIME::am_pm |
AM/PM (0=AM, 1=PM; 12h mode only)
| uint8_t RTC_TIME_ALARM::am_pm |
AM/PM (12h mode only)
| uint8_t RTC_CALENDAR::century |
Century (BCD, 0x19..0x20)
| uint8_t RTC_CALENDAR::date |
Day of month (BCD, 0x01-0x31)
| uint8_t RTC_CALENDAR_ALARM::date |
Day of month (BCD)
| uint8_t RTC_CALENDAR::day |
Day of week (BCD, 0x01-0x07)
| uint8_t RTC_CALENDAR_ALARM::enable_date |
1 = match date, 0 = mask
| uint8_t RTC_TIME_ALARM::enable_hour |
1 = match hour, 0 = mask
| uint8_t RTC_TIME_ALARM::enable_minute |
1 = match minute, 0 = mask
| uint8_t RTC_CALENDAR_ALARM::enable_month |
1 = match month, 0 = mask
| uint8_t RTC_TIME_ALARM::enable_second |
1 = match second, 0 = mask
| uint8_t RTC_TIME::hour |
Hour (BCD, 0x00-0x23 or 0x01-0x12)
| uint8_t RTC_TIME_ALARM::hour |
Hour (BCD)
| uint8_t RTC_TIME::minute |
Minute (BCD, 0x00-0x59)
| uint8_t RTC_TIME_ALARM::minute |
Minute (BCD)
| uint8_t RTC_CALENDAR::month |
Month (BCD, 0x01-0x12)
| uint8_t RTC_CALENDAR_ALARM::month |
Month (BCD)
| uint8_t RTC_TIME::second |
Second (BCD, 0x00-0x59)
| uint8_t RTC_TIME_ALARM::second |
Second (BCD)
| uint8_t RTC_CALENDAR::year |
Year within century (BCD, 0x00-0x99)