Get RTC-counter via ti-lib
#include "ti-lib.h"
/*---------------------------------------------------------------------------*/
static volatile uint64_t count;
+
+/**< Num. fractions in sub-second. Important to cast to 64-bit */
+#define RTC_SUBSEC_FRAC ((uint64_t)1 << 32)
/*---------------------------------------------------------------------------*/
static void
power_domain_on(void)
@@ -110,18 +113,12 @@ clock_init(void)
static void
update_clock_variable(void)
{
- uint32_t aon_rtc_secs_now;
- uint32_t aon_rtc_secs_now2;
- uint16_t aon_rtc_ticks_now;
-
- do {
- aon_rtc_secs_now = HWREG(AON_RTC_BASE + AON_RTC_O_SEC);
- aon_rtc_ticks_now = HWREG(AON_RTC_BASE + AON_RTC_O_SUBSEC) >> 16;
- aon_rtc_secs_now2 = HWREG(AON_RTC_BASE + AON_RTC_O_SEC);
- } while(aon_rtc_secs_now != aon_rtc_secs_now2);
-
- /* Convert AON RTC ticks to clock tick counter */
- count = (aon_rtc_secs_now * CLOCK_SECOND) + (aon_rtc_ticks_now >> 9);
+ /*
+ * RTC counter is in a 64-bits format (SEC[31:0].SUBSEC[31:0]), where SUBSEC
+ * is represented in fractions of a second (VALUE/2^32).
+ */
+ uint64_t now = ti_lib_aon_rtc_current_64_bit_value_get();
+ count = (clock_time_t)(now / (RTC_SUBSEC_FRAC / CLOCK_SECOND));
}
/*---------------------------------------------------------------------------*/
clock_time_t
