mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #7998 from NXPmicro/MIMXRT1050_Add_RTC
MIMXRT1050_EVK: Add RTC supportpull/8298/head
commit
c48c2ec89f
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue