arch: S32K/Kinetis: Fix RTC settime prescaler

This commit is contained in:
Peter van der Perk
2020-12-28 12:58:44 +01:00
committed by Abdelatif Guettouche
parent 10adf76209
commit 673a4b5b39
2 changed files with 27 additions and 27 deletions
+26 -26
View File
@@ -174,12 +174,12 @@ static void rtc_dumptime(FAR struct tm *tp, FAR const char *msg)
#if defined(CONFIG_RTC_ALARM) #if defined(CONFIG_RTC_ALARM)
static int kinetis_rtc_interrupt(int irq, void *context, FAR void *arg) static int kinetis_rtc_interrupt(int irq, void *context, FAR void *arg)
{ {
uint16_t rtc_sr; uint16_t rtc_sr;
/* if alarm */ /* if alarm */
rtc_sr = getreg32( KINETIS_RTC_SR); rtc_sr = getreg32(KINETIS_RTC_SR);
if (rtc_sr & RTC_SR_TAF ) if (rtc_sr & RTC_SR_TAF)
{ {
if (g_alarmcb != NULL) if (g_alarmcb != NULL)
{ {
@@ -209,7 +209,7 @@ static int kinetis_rtc_interrupt(int irq, void *context, FAR void *arg)
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: RTC_Reset * Name: rtc_reset
* *
* Description: * Description:
* Reset the RTC to known state * Reset the RTC to known state
@@ -222,16 +222,16 @@ static int kinetis_rtc_interrupt(int irq, void *context, FAR void *arg)
* *
****************************************************************************/ ****************************************************************************/
static inline void RTC_Reset(void) static inline void rtc_reset(void)
{ {
putreg32(( RTC_CR_SWR | getreg32(KINETIS_RTC_CR)),KINETIS_RTC_CR); putreg32((RTC_CR_SWR | getreg32(KINETIS_RTC_CR)), KINETIS_RTC_CR);
putreg32((~RTC_CR_SWR & getreg32(KINETIS_RTC_CR)),KINETIS_RTC_CR); putreg32((~RTC_CR_SWR & getreg32(KINETIS_RTC_CR)), KINETIS_RTC_CR);
/* Set TSR register to 0x1 to avoid the timer invalid (TIF) bit being /* Set TSR register to 0x1 to avoid the timer invalid (TIF) bit being
* set in the SR register * set in the SR register
*/ */
putreg32(1,KINETIS_RTC_TSR); putreg32(1, KINETIS_RTC_TSR);
} }
/**************************************************************************** /****************************************************************************
@@ -243,7 +243,7 @@ static inline void RTC_Reset(void)
* *
* Description: * Description:
* Initialize the hardware RTC irq. * Initialize the hardware RTC irq.
* This only needs to be called once when first used. * This only needs to be called once when first used.
* *
* Input Parameters: * Input Parameters:
* None * None
@@ -260,11 +260,11 @@ int up_rtc_irq_attach(void)
if (!rtc_irq_state) if (!rtc_irq_state)
{ {
rtc_irq_state=true; rtc_irq_state = true;
/* Clear TAF if pending */ /* Clear TAF if pending */
rtc_sr = getreg32( KINETIS_RTC_SR); rtc_sr = getreg32(KINETIS_RTC_SR);
if ((rtc_sr & RTC_SR_TAF) != 0) if ((rtc_sr & RTC_SR_TAF) != 0)
{ {
putreg32(0, KINETIS_RTC_TAR); putreg32(0, KINETIS_RTC_TAR);
@@ -324,8 +324,8 @@ int up_rtc_initialize(void)
*/ */
regval = getreg32(KINETIS_RTC_MCLR); regval = getreg32(KINETIS_RTC_MCLR);
if ((CONFIG_RTC_MAGICL == regval ) && if ((CONFIG_RTC_MAGICL == regval) &&
(CONFIG_RTC_MAGICH == getreg32(KINETIS_RTC_MCHR)) ) (CONFIG_RTC_MAGICH == getreg32(KINETIS_RTC_MCHR)))
#endif #endif
{ {
rtc_valid = true; rtc_valid = true;
@@ -343,7 +343,7 @@ int up_rtc_initialize(void)
else else
{ {
rtcinfo("Do setup\n"); rtcinfo("Do setup\n");
RTC_Reset(); rtc_reset();
#ifdef KINETIS_RTC_GEN2 #ifdef KINETIS_RTC_GEN2
/* Configure the RTC to be initialized */ /* Configure the RTC to be initialized */
@@ -354,7 +354,7 @@ int up_rtc_initialize(void)
/* Setup the update mode and supervisor access mode */ /* Setup the update mode and supervisor access mode */
putreg32((~(RTC_CR_UM|RTC_CR_SUP) & getreg32(KINETIS_RTC_CR)), putreg32((~(RTC_CR_UM | RTC_CR_SUP) & getreg32(KINETIS_RTC_CR)),
KINETIS_RTC_CR); KINETIS_RTC_CR);
/* Disable counters (just in case) */ /* Disable counters (just in case) */
@@ -363,12 +363,12 @@ int up_rtc_initialize(void)
/* Enable oscilator - must have Vbat else hard fault */ /* Enable oscilator - must have Vbat else hard fault */
putreg32((BOARD_RTC_CAP | RTC_CR_OSCE ), KINETIS_RTC_CR); putreg32((BOARD_RTC_CAP | RTC_CR_OSCE), KINETIS_RTC_CR);
/* TODO - add capability to accurately tune RTC /* TODO - add capability to accurately tune RTC
* This is a per individual board customization and requires * This is a per individual board customization and requires
* parameters to be configurable and stored in non-volatile eg flash. * parameters to be configurable and stored in non-volatile eg flash.
*/ */
/* TODO: delay some time (1024 cycles? would be 30ms) */ /* TODO: delay some time (1024 cycles? would be 30ms) */
} }
@@ -489,7 +489,7 @@ int up_rtc_settime(FAR const struct timespec *tp)
uint32_t prescaler; uint32_t prescaler;
seconds = tp->tv_sec; seconds = tp->tv_sec;
prescaler = tp->tv_nsec * (CONFIG_RTC_FREQUENCY / 1000000000); prescaler = tp->tv_nsec / (1000000000 / CONFIG_RTC_FREQUENCY);
flags = enter_critical_section(); flags = enter_critical_section();
@@ -587,7 +587,7 @@ int kinetis_rtc_cancelalarm(void)
} }
#endif #endif
/************************************************************************************ /****************************************************************************
* Name: kinetis_rtc_rdalarm * Name: kinetis_rtc_rdalarm
* *
* Description: * Description:
@@ -599,7 +599,7 @@ int kinetis_rtc_cancelalarm(void)
* Returned Value: * Returned Value:
* Zero (OK) on success; a negated errno on failure * Zero (OK) on success; a negated errno on failure
* *
************************************************************************************/ ****************************************************************************/
#ifdef CONFIG_RTC_ALARM #ifdef CONFIG_RTC_ALARM
int kinetis_rtc_rdalarm(FAR struct timespec *tp) int kinetis_rtc_rdalarm(FAR struct timespec *tp)
+1 -1
View File
@@ -304,7 +304,7 @@ int up_rtc_settime(FAR const struct timespec *ts)
seconds = ts->tv_sec; seconds = ts->tv_sec;
#ifdef CONFIG_RTC_HIRES #ifdef CONFIG_RTC_HIRES
prescaler = ts->tv_nsec * (CONFIG_RTC_FREQUENCY / 1000000000); prescaler = ts->tv_nsec / (1000000000 / CONFIG_RTC_FREQUENCY);
#else #else
prescaler = 0; prescaler = 0;
#endif #endif