Merge pull request #7998 from NXPmicro/MIMXRT1050_Add_RTC

MIMXRT1050_EVK: Add RTC support
pull/8298/head
Martin Kojtal 2018-10-01 11:47:10 +02:00 committed by GitHub
commit c48c2ec89f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 16 deletions

View File

@ -17,21 +17,26 @@
#if DEVICE_RTC
#include "fsl_snvs_hp.h"
#include "fsl_snvs_lp.h"
static bool rtc_time_set = false;
void rtc_init(void)
{
snvs_hp_rtc_config_t snvsRtcConfig;
snvs_lp_srtc_config_t snvsRtcConfig;
SNVS_HP_RTC_GetDefaultConfig(&snvsRtcConfig);
SNVS_HP_RTC_Init(SNVS, &snvsRtcConfig);
SNVS_LP_SRTC_GetDefaultConfig(&snvsRtcConfig);
SNVS_LP_SRTC_Init(SNVS, &snvsRtcConfig);
SNVS_HP_RTC_StartTimer(SNVS);
SNVS_LP_SRTC_StartTimer(SNVS);
}
void rtc_free(void)
{
SNVS_HP_RTC_Deinit(SNVS);
#if (!(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && \
defined(SNVS_LP_CLOCKS))
CLOCK_DisableClock(kCLOCK_SnvsLp0);
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
}
/*
@ -40,19 +45,31 @@ void rtc_free(void)
*/
int rtc_isenabled(void)
{
return (int)((SNVS->HPCR & SNVS_HPCR_RTC_EN_MASK) >> SNVS_HPCR_RTC_EN_SHIFT);
#if (!(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && \
defined(SNVS_LP_CLOCKS))
CLOCK_EnableClock(kCLOCK_SnvsLp0);
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
const bool rtc_init_done = ((SNVS->LPCR & SNVS_LPCR_SRTC_ENV_MASK) >> SNVS_LPCR_SRTC_ENV_SHIFT);
/* If RTC is not initialized, then disable the clock gate on exit. */
if(!rtc_init_done) {
rtc_free();
}
return (rtc_init_done & rtc_time_set);
}
time_t rtc_read(void)
{
uint64_t seconds = 0;
uint64_t tmp = 0;
uint32_t seconds = 0;
uint32_t tmp = 0;
/* Do consecutive reads until value is correct */
do
{
do {
seconds = tmp;
tmp = SNVS->HPRTCLR;
tmp = (SNVS->LPSRTCMR << 17U) | (SNVS->LPSRTCLR >> 15U);
} while (tmp != seconds);
return (time_t)seconds;
@ -63,11 +80,15 @@ void rtc_write(time_t t)
if (t == 0) {
t = 1;
}
SNVS_HP_RTC_StopTimer(SNVS);
SNVS->HPRTCLR = (uint32_t)t;
SNVS_LP_SRTC_StopTimer(SNVS);
SNVS_HP_RTC_StartTimer(SNVS);
SNVS->LPSRTCMR = (uint32_t)(t >> 17U);
SNVS->LPSRTCLR = (uint32_t)(t << 15U);
SNVS_LP_SRTC_StartTimer(SNVS);
rtc_time_set = true;
}
#endif

View File

@ -766,7 +766,7 @@
"macros": ["CPU_MIMXRT1052DVL6B", "FSL_RTOS_MBED", "XIP_BOOT_HEADER_ENABLE=1", "XIP_EXTERNAL_FLASH=1", "XIP_BOOT_HEADER_DCD_ENABLE=1", "SKIP_SYSCLK_INIT"],
"inherits": ["Target"],
"detect_code": ["0227"],
"device_has": ["SLEEP", "USTICKER", "LPTICKER", "ANALOGIN", "I2C", "I2CSLAVE", "ERROR_RED", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"device_has": ["RTC", "SLEEP", "USTICKER", "LPTICKER", "ANALOGIN", "I2C", "I2CSLAVE", "ERROR_RED", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"release_versions": ["2", "5"],
"device_name": "MIMXRT1052"
},