2013-08-04 13:38:53 +00:00
|
|
|
/*
|
2015-01-11 13:56:55 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
Concepts and parts of this file have been contributed by Uladzimir Pylinsky
|
|
|
|
aka barthess.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file STM32/RTCv1/rtc_lld.c
|
|
|
|
* @brief STM32 RTC subsystem low level driver header.
|
|
|
|
*
|
|
|
|
* @addtogroup RTC
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
#if HAL_USE_RTC || defined(__DOXYGEN__)
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief RTC driver identifier.
|
|
|
|
*/
|
|
|
|
RTCDriver RTCD1;
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local variables and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wait for synchronization of RTC registers with APB1 bus.
|
|
|
|
* @details This function must be invoked before trying to read RTC registers
|
|
|
|
* in the backup domain: DIV, CNT, ALR. CR registers can always
|
|
|
|
* be read.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
static void rtc_apb1_sync(void) {
|
2014-12-22 09:19:37 +00:00
|
|
|
|
|
|
|
while ((RTC->CRL & RTC_CRL_RSF) == 0)
|
2014-11-01 13:22:15 +00:00
|
|
|
;
|
|
|
|
}
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wait for for previous write operation complete.
|
|
|
|
* @details This function must be invoked before writing to any RTC registers
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
static void rtc_wait_write_completed(void) {
|
2014-12-22 09:19:37 +00:00
|
|
|
|
|
|
|
while ((RTC->CRL & RTC_CRL_RTOFF) == 0)
|
2014-11-01 13:22:15 +00:00
|
|
|
;
|
|
|
|
}
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Acquires write access to RTC registers.
|
|
|
|
* @details Before writing to the backup domain RTC registers the previous
|
|
|
|
* write operation must be completed. Use this function before
|
|
|
|
* writing to PRL, CNT, ALR registers.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
static void rtc_acquire_access(void) {
|
2014-12-22 09:19:37 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_wait_write_completed();
|
2014-12-22 09:19:37 +00:00
|
|
|
RTC->CRL |= RTC_CRL_CNF;
|
2014-11-01 13:22:15 +00:00
|
|
|
}
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Releases write access to RTC registers.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
static void rtc_release_access(void) {
|
2014-12-22 09:19:37 +00:00
|
|
|
|
|
|
|
RTC->CRL &= ~RTC_CRL_CNF;
|
2014-11-01 13:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Converts time from timespec to seconds counter.
|
|
|
|
*
|
|
|
|
* @param[in] timespec pointer to a @p RTCDateTime structure
|
|
|
|
* @return the TR register encoding.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
static time_t rtc_encode(const RTCDateTime *timespec) {
|
|
|
|
struct tm tim;
|
|
|
|
|
2015-03-28 18:10:58 +00:00
|
|
|
rtcConvertDateTimeToStructTm(timespec, &tim, NULL);
|
2014-11-01 13:22:15 +00:00
|
|
|
return mktime(&tim);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Converts time from seconds/milliseconds to timespec.
|
|
|
|
*
|
|
|
|
* @param[in] tv_sec seconds value
|
|
|
|
* @param[in] tv_msec milliseconds value
|
|
|
|
* @param[out] timespec pointer to a @p RTCDateTime structure
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2015-06-27 09:12:43 +00:00
|
|
|
static void rtc_decode(uint32_t tv_sec,
|
|
|
|
uint32_t tv_msec,
|
|
|
|
RTCDateTime *timespec) {
|
2014-11-01 13:22:15 +00:00
|
|
|
struct tm tim;
|
2015-06-27 09:12:43 +00:00
|
|
|
struct tm *t;
|
2014-11-01 13:22:15 +00:00
|
|
|
|
|
|
|
/* If the conversion is successful the function returns a pointer
|
|
|
|
to the object the result was written into.*/
|
2015-06-27 09:12:43 +00:00
|
|
|
#if defined __GNUC__
|
|
|
|
t = localtime_r((time_t *)&(tv_sec), &tim);
|
|
|
|
osalDbgAssert(t != NULL, "conversion failed");
|
|
|
|
#else
|
|
|
|
struct tm *t = localtime(&tv_sec);
|
|
|
|
memcpy(&timp, t, sizeof(struct tm));
|
|
|
|
#endif
|
2014-11-01 13:22:15 +00:00
|
|
|
|
|
|
|
rtcConvertStructTmToDateTime(&tim, tv_msec, timespec);
|
|
|
|
}
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver interrupt handlers. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief RTC interrupt handler.
|
|
|
|
*
|
|
|
|
* @isr
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
OSAL_IRQ_HANDLER(STM32_RTC1_HANDLER) {
|
2013-08-04 13:38:53 +00:00
|
|
|
uint16_t flags;
|
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
OSAL_IRQ_PROLOGUE();
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
/* Code hits this wait only when AHB1 bus was previously powered off by any
|
|
|
|
reason (standby, reset, etc). In other cases there is no waiting.*/
|
|
|
|
rtc_apb1_sync();
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/* Mask of all enabled and pending sources.*/
|
2014-11-01 13:22:15 +00:00
|
|
|
flags = RTCD1.rtc->CRH & RTCD1.rtc->CRL;
|
|
|
|
RTCD1.rtc->CRL &= ~(RTC_CRL_SECF | RTC_CRL_ALRF | RTC_CRL_OWF);
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
if (flags & RTC_CRL_SECF)
|
|
|
|
RTCD1.callback(&RTCD1, RTC_EVENT_SECOND);
|
|
|
|
|
|
|
|
if (flags & RTC_CRL_ALRF)
|
|
|
|
RTCD1.callback(&RTCD1, RTC_EVENT_ALARM);
|
|
|
|
|
|
|
|
if (flags & RTC_CRL_OWF)
|
|
|
|
RTCD1.callback(&RTCD1, RTC_EVENT_OVERFLOW);
|
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
OSAL_IRQ_EPILOGUE();
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Load value of RTCCLK to prescaler registers.
|
|
|
|
* @note The pre-scaler must not be set on every reset as RTC clock
|
|
|
|
* counts are lost when it is set.
|
|
|
|
* @note This function designed to be called from
|
|
|
|
* hal_lld_backup_domain_init(). Because there is only place
|
|
|
|
* where possible to detect BKP domain reset event reliably.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
void rtc_lld_set_prescaler(void) {
|
|
|
|
syssts_t sts;
|
|
|
|
|
|
|
|
/* Entering a reentrant critical zone.*/
|
|
|
|
sts = chSysGetStatusAndLockX();
|
|
|
|
|
|
|
|
rtc_acquire_access();
|
2014-12-22 09:19:37 +00:00
|
|
|
RTC->PRLH = (uint16_t)((STM32_RTCCLK - 1) >> 16) & 0x000F;
|
|
|
|
RTC->PRLL = (uint16_t)(((STM32_RTCCLK - 1)) & 0xFFFF);
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_release_access();
|
|
|
|
|
|
|
|
/* Leaving a reentrant critical zone.*/
|
|
|
|
chSysRestoreStatusX(sts);
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize RTC.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
void rtc_lld_init(void) {
|
|
|
|
|
2014-11-27 15:07:26 +00:00
|
|
|
/* RTC object initialization.*/
|
|
|
|
rtcObjectInit(&RTCD1);
|
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
/* RTC pointer initialization.*/
|
|
|
|
RTCD1.rtc = RTC;
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/* RSF bit must be cleared by software after an APB1 reset or an APB1 clock
|
|
|
|
stop. Otherwise its value will not be actual. */
|
2014-11-01 13:22:15 +00:00
|
|
|
RTCD1.rtc->CRL &= ~RTC_CRL_RSF;
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/* Required because access to PRL.*/
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_apb1_sync();
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/* All interrupts initially disabled.*/
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_wait_write_completed();
|
|
|
|
RTCD1.rtc->CRH = 0;
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/* Callback initially disabled.*/
|
|
|
|
RTCD1.callback = NULL;
|
|
|
|
|
|
|
|
/* IRQ vector permanently assigned to this driver.*/
|
2014-11-01 13:22:15 +00:00
|
|
|
nvicEnableVector(STM32_RTC1_NUMBER, STM32_RTC_IRQ_PRIORITY);
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set current time.
|
|
|
|
* @note Fractional part will be silently ignored. There is no possibility
|
|
|
|
* to change it on STM32F1xx platform.
|
2014-11-01 15:50:19 +00:00
|
|
|
* @note The function can be called from any context.
|
2013-08-04 13:38:53 +00:00
|
|
|
*
|
|
|
|
* @param[in] rtcp pointer to RTC driver structure
|
|
|
|
* @param[in] timespec pointer to a @p RTCTime structure
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
void rtc_lld_set_time(RTCDriver *rtcp, const RTCDateTime *timespec) {
|
|
|
|
time_t tv_sec = rtc_encode(timespec);
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
rtcSTM32SetSec(rtcp, tv_sec);
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get current time.
|
2014-11-01 15:50:19 +00:00
|
|
|
* @note The function can be called from any context.
|
2013-08-04 13:38:53 +00:00
|
|
|
*
|
|
|
|
* @param[in] rtcp pointer to RTC driver structure
|
|
|
|
* @param[in] timespec pointer to a @p RTCTime structure
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
void rtc_lld_get_time(RTCDriver *rtcp, RTCDateTime *timespec) {
|
|
|
|
uint32_t tv_sec, tv_msec;
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
rtcSTM32GetSecMsec(rtcp, &tv_sec, &tv_msec);
|
|
|
|
rtc_decode(tv_sec, tv_msec, timespec);
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set alarm time.
|
|
|
|
*
|
2014-11-01 15:50:19 +00:00
|
|
|
* @note Default value after BKP domain reset is 0xFFFFFFFF
|
|
|
|
* @note The function can be called from any context.
|
2013-08-04 13:38:53 +00:00
|
|
|
*
|
|
|
|
* @param[in] rtcp pointer to RTC driver structure
|
|
|
|
* @param[in] alarm alarm identifier
|
|
|
|
* @param[in] alarmspec pointer to a @p RTCAlarm structure
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void rtc_lld_set_alarm(RTCDriver *rtcp,
|
2014-11-01 13:22:15 +00:00
|
|
|
rtcalarm_t alarm_number,
|
2013-08-04 13:38:53 +00:00
|
|
|
const RTCAlarm *alarmspec) {
|
2014-11-01 13:22:15 +00:00
|
|
|
syssts_t sts;
|
|
|
|
(void)alarm_number;
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
/* Entering a reentrant critical zone.*/
|
|
|
|
sts = chSysGetStatusAndLockX();
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_acquire_access();
|
2013-08-04 13:38:53 +00:00
|
|
|
if (alarmspec != NULL) {
|
2014-11-01 13:22:15 +00:00
|
|
|
rtcp->rtc->ALRH = (uint16_t)(alarmspec->tv_sec >> 16);
|
|
|
|
rtcp->rtc->ALRL = (uint16_t)(alarmspec->tv_sec & 0xFFFF);
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-11-01 13:22:15 +00:00
|
|
|
rtcp->rtc->ALRH = 0;
|
|
|
|
rtcp->rtc->ALRL = 0;
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_release_access();
|
|
|
|
|
|
|
|
/* Leaving a reentrant critical zone.*/
|
|
|
|
chSysRestoreStatusX(sts);
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get current alarm.
|
|
|
|
* @note If an alarm has not been set then the returned alarm specification
|
|
|
|
* is not meaningful.
|
2014-11-01 15:50:19 +00:00
|
|
|
* @note The function can be called from any context.
|
2013-08-04 13:38:53 +00:00
|
|
|
* @note Default value after BKP domain reset is 0xFFFFFFFF.
|
|
|
|
*
|
|
|
|
* @param[in] rtcp pointer to RTC driver structure
|
|
|
|
* @param[in] alarm alarm identifier
|
|
|
|
* @param[out] alarmspec pointer to a @p RTCAlarm structure
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void rtc_lld_get_alarm(RTCDriver *rtcp,
|
2014-11-01 13:22:15 +00:00
|
|
|
rtcalarm_t alarm_number,
|
2013-08-04 13:38:53 +00:00
|
|
|
RTCAlarm *alarmspec) {
|
2014-11-01 13:22:15 +00:00
|
|
|
syssts_t sts;
|
|
|
|
(void)alarm_number;
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
/* Entering a reentrant critical zone.*/
|
|
|
|
sts = chSysGetStatusAndLockX();
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/* Required because access to ALR.*/
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_apb1_sync();
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
alarmspec->tv_sec = ((rtcp->rtc->ALRH << 16) + rtcp->rtc->ALRL);
|
|
|
|
|
|
|
|
/* Leaving a reentrant critical zone.*/
|
|
|
|
chSysRestoreStatusX(sts);
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enables or disables RTC callbacks.
|
|
|
|
* @details This function enables or disables callbacks, use a @p NULL pointer
|
|
|
|
* in order to disable a callback.
|
2014-11-01 15:50:19 +00:00
|
|
|
* @note The function can be called from any context.
|
2013-08-04 13:38:53 +00:00
|
|
|
*
|
|
|
|
* @param[in] rtcp pointer to RTC driver structure
|
|
|
|
* @param[in] callback callback function pointer or @p NULL
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback) {
|
2014-11-01 13:22:15 +00:00
|
|
|
syssts_t sts;
|
|
|
|
|
|
|
|
/* Entering a reentrant critical zone.*/
|
|
|
|
sts = chSysGetStatusAndLockX();
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
if (callback != NULL) {
|
|
|
|
|
|
|
|
/* IRQ sources enabled only after setting up the callback.*/
|
|
|
|
rtcp->callback = callback;
|
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_wait_write_completed();
|
|
|
|
rtcp->rtc->CRL &= ~(RTC_CRL_OWF | RTC_CRL_ALRF | RTC_CRL_SECF);
|
|
|
|
rtcp->rtc->CRH = RTC_CRH_OWIE | RTC_CRH_ALRIE | RTC_CRH_SECIE;
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_wait_write_completed();
|
|
|
|
rtcp->rtc->CRH = 0;
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/* Callback set to NULL only after disabling the IRQ sources.*/
|
|
|
|
rtcp->callback = NULL;
|
|
|
|
}
|
2014-11-01 13:22:15 +00:00
|
|
|
|
|
|
|
/* Leaving a reentrant critical zone.*/
|
|
|
|
chSysRestoreStatusX(sts);
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
/**
|
|
|
|
* @brief Get seconds and (optionally) milliseconds from RTC.
|
2014-11-01 15:50:19 +00:00
|
|
|
* @note The function can be called from any context.
|
2014-11-01 13:22:15 +00:00
|
|
|
*
|
|
|
|
* @param[in] rtcp pointer to RTC driver structure
|
|
|
|
* @param[out] tv_sec pointer to seconds value
|
|
|
|
* @param[out] tv_msec pointer to milliseconds value, set it
|
|
|
|
* to @p NULL if not needed
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void rtcSTM32GetSecMsec(RTCDriver *rtcp, uint32_t *tv_sec, uint32_t *tv_msec) {
|
|
|
|
uint32_t time_frac;
|
|
|
|
syssts_t sts;
|
|
|
|
|
|
|
|
osalDbgCheck((NULL != tv_sec) && (NULL != rtcp));
|
|
|
|
|
|
|
|
/* Entering a reentrant critical zone.*/
|
|
|
|
sts = chSysGetStatusAndLockX();
|
|
|
|
|
|
|
|
/* Required because access to CNT and DIV.*/
|
|
|
|
rtc_apb1_sync();
|
|
|
|
|
|
|
|
/* Loops until two consecutive read returning the same value.*/
|
|
|
|
do {
|
|
|
|
*tv_sec = ((uint32_t)(rtcp->rtc->CNTH) << 16) + rtcp->rtc->CNTL;
|
|
|
|
time_frac = (((uint32_t)rtcp->rtc->DIVH) << 16) + (uint32_t)rtcp->rtc->DIVL;
|
|
|
|
} while ((*tv_sec) != (((uint32_t)(rtcp->rtc->CNTH) << 16) + rtcp->rtc->CNTL));
|
|
|
|
|
|
|
|
/* Leaving a reentrant critical zone.*/
|
|
|
|
chSysRestoreStatusX(sts);
|
|
|
|
|
|
|
|
if (NULL != tv_msec)
|
|
|
|
*tv_msec = (((uint32_t)STM32_RTCCLK - 1 - time_frac) * 1000) / STM32_RTCCLK;
|
|
|
|
}
|
2013-08-04 13:38:53 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-01 13:22:15 +00:00
|
|
|
* @brief Set seconds in RTC.
|
2014-11-01 15:50:19 +00:00
|
|
|
* @note The function can be called from any context.
|
2013-08-04 13:38:53 +00:00
|
|
|
*
|
|
|
|
* @param[in] rtcp pointer to RTC driver structure
|
2014-11-01 13:22:15 +00:00
|
|
|
* @param[in] tv_sec seconds value
|
2013-08-04 13:38:53 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-11-01 13:22:15 +00:00
|
|
|
void rtcSTM32SetSec(RTCDriver *rtcp, uint32_t tv_sec) {
|
|
|
|
syssts_t sts;
|
|
|
|
|
|
|
|
osalDbgCheck(NULL != rtcp);
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
/* Entering a reentrant critical zone.*/
|
|
|
|
sts = chSysGetStatusAndLockX();
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
rtc_acquire_access();
|
|
|
|
rtcp->rtc->CNTH = (uint16_t)(tv_sec >> 16);
|
|
|
|
rtcp->rtc->CNTL = (uint16_t)(tv_sec & 0xFFFF);
|
|
|
|
rtc_release_access();
|
2013-08-04 13:38:53 +00:00
|
|
|
|
2014-11-01 13:22:15 +00:00
|
|
|
/* Leaving a reentrant critical zone.*/
|
|
|
|
chSysRestoreStatusX(sts);
|
2013-08-04 13:38:53 +00:00
|
|
|
}
|
2014-11-01 13:22:15 +00:00
|
|
|
|
2013-08-04 13:38:53 +00:00
|
|
|
#endif /* HAL_USE_RTC */
|
|
|
|
|
|
|
|
/** @} */
|