|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
-
-
- #include "imxrt.h"
- #include "debug/printf.h"
-
-
- unsigned long rtc_get(void)
- {
- uint32_t hi1 = SNVS_HPRTCMR;
- uint32_t lo1 = SNVS_HPRTCLR;
- while (1) {
- uint32_t hi2 = SNVS_HPRTCMR;
- uint32_t lo2 = SNVS_HPRTCLR;
- if (lo1 == lo2 && hi1 == hi2) {
- return (hi2 << 17) | (lo2 >> 15);
- }
- hi1 = hi2;
- lo1 = lo2;
- }
- }
-
- void rtc_set(unsigned long t)
- {
-
- SNVS_HPCR &= ~(SNVS_HPCR_RTC_EN | SNVS_HPCR_HP_TS);
- while (SNVS_HPCR & SNVS_HPCR_RTC_EN);
-
- SNVS_LPCR &= ~SNVS_LPCR_SRTC_ENV;
- while (SNVS_LPCR & SNVS_LPCR_SRTC_ENV);
-
- SNVS_LPSRTCLR = t << 15;
- SNVS_LPSRTCMR = t >> 17;
-
- SNVS_LPCR |= SNVS_LPCR_SRTC_ENV;
- while (!(SNVS_LPCR & SNVS_LPCR_SRTC_ENV));
-
- SNVS_HPCR |= SNVS_HPCR_RTC_EN | SNVS_HPCR_HP_TS;
- }
-
- void rtc_compensate(int adjust)
- {
- }
-
|