4.11 RTC APIs

The Demo Meter application can set the date and time in BCD format as well as other functionalities, by means of the following functions:

  • uint8_t RTCProcSetTimeBCD(uint8_t bcd_hr, uint8_t bcd_min, uint8_t bcd_sec)
  • uint8_t RTCProcSetDateBCD(uint8_t bcd_year, uint8_t bcd_month, uint8_t bcd_day, uint8_t bcd_day_week)
  • uint8_t RTCProcGetDaysOfMonth(uint8_t year, uint8_t month)

Some of these functions are based on the drivers provided by the SEF (/drivers/rtc folder). All the APIs included in the SEF start with the “rtc_” prefix. These are some of them:

Get Date API:

void rtc_get_date(Rtc *p_rtc, uint32_t *pul_year, uint32_t *pul_month, uint32_t *pul_day, uint32_t *pul_week);

Calling example:

rtc_get_date(RTC, &rtc.date.year, &rtc.date.month, &rtc.date.day, &rtc.date.week);

Get Time API:

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

Calling example:

rtc_get_time(RTC, &rtc.time.hour, &rtc.time.minute, &rtc.time.second);

Set Date API:

uint32_t rtc_set_date(Rtc *p_rtc, uint32_t ul_year, uint32_t ul_month, uint32_t ul_day, uint32_t ul_week);

Calling example:

status = rtc_set_date(RTC, new_date.year, new_date.month, new_date.day, new_date.week);

Set Time API:

uint32_t rtc_set_time(Rtc *p_rtc, uint32_t ul_hour, uint32_t ul_minute, uint32_t ul_second);

Calling example:

status = rtc_set_time(RTC, new_time.hour, new_time.minute, new_time.second);