2011-12-08 21:17:19 +00:00
|
|
|
/*
|
2013-03-30 10:32:37 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
2011-12-08 21:17:19 +00:00
|
|
|
|
2013-03-30 10:32:37 +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
|
2011-12-08 21:17:19 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2011-12-08 21:17:19 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
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.
|
2011-12-08 21:17:19 +00:00
|
|
|
*/
|
2011-12-29 18:07:02 +00:00
|
|
|
/*
|
|
|
|
Concepts and parts of this file have been contributed by Uladzimir Pylinsky
|
|
|
|
aka barthess.
|
|
|
|
*/
|
2011-12-08 21:17:19 +00:00
|
|
|
|
|
|
|
/**
|
2011-12-11 23:40:49 +00:00
|
|
|
* @file STM32/RTCv2/rtc_lld.h
|
|
|
|
* @brief STM32L1xx/STM32F2xx/STM32F4xx RTC low level driver header.
|
2011-12-08 21:17:19 +00:00
|
|
|
*
|
|
|
|
* @addtogroup RTC
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _RTC_LLD_H_
|
|
|
|
#define _RTC_LLD_H_
|
|
|
|
|
|
|
|
#if HAL_USE_RTC || defined(__DOXYGEN__)
|
|
|
|
|
2012-01-07 07:36:07 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver constants. */
|
|
|
|
/*===========================================================================*/
|
2011-12-08 21:17:19 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-29 17:44:23 +00:00
|
|
|
* @brief Two alarm comparators available on STM32F4x and STM32F2x.
|
2011-12-08 21:17:19 +00:00
|
|
|
*/
|
2013-09-29 17:44:23 +00:00
|
|
|
#if !defined(STM32F0XX)
|
|
|
|
#define RTC_ALARMS 2
|
|
|
|
#else
|
|
|
|
#define RTC_ALARMS 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief STM32F0x has no periodic wakeups.
|
|
|
|
*/
|
|
|
|
#if !defined(STM32F0XX)
|
|
|
|
#define RTC_HAS_PERIODIC_WAKEUPS TRUE
|
|
|
|
#else
|
|
|
|
#define RTC_HAS_PERIODIC_WAKEUPS FALSE
|
|
|
|
#endif
|
2011-12-08 21:17:19 +00:00
|
|
|
|
2011-12-12 10:56:51 +00:00
|
|
|
/**
|
2012-03-04 14:27:03 +00:00
|
|
|
* @brief Data offsets in RTC date and time registers.
|
2011-12-12 10:56:51 +00:00
|
|
|
*/
|
2012-03-04 14:27:03 +00:00
|
|
|
#define RTC_TR_PM_OFFSET 22
|
|
|
|
#define RTC_TR_HT_OFFSET 20
|
|
|
|
#define RTC_TR_HU_OFFSET 16
|
|
|
|
#define RTC_TR_MNT_OFFSET 12
|
|
|
|
#define RTC_TR_MNU_OFFSET 8
|
|
|
|
#define RTC_TR_ST_OFFSET 4
|
|
|
|
#define RTC_TR_SU_OFFSET 0
|
|
|
|
|
|
|
|
#define RTC_DR_YT_OFFSET 20
|
|
|
|
#define RTC_DR_YU_OFFSET 16
|
|
|
|
#define RTC_DR_WDU_OFFSET 13
|
|
|
|
#define RTC_DR_MT_OFFSET 12
|
|
|
|
#define RTC_DR_MU_OFFSET 8
|
|
|
|
#define RTC_DR_DT_OFFSET 4
|
|
|
|
#define RTC_DR_DU_OFFSET 0
|
2011-12-12 10:56:51 +00:00
|
|
|
|
2011-12-08 21:17:19 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#if HAL_USE_RTC && !STM32_HAS_RTC
|
|
|
|
#error "RTC not present in the selected device"
|
|
|
|
#endif
|
|
|
|
|
2012-01-07 07:36:07 +00:00
|
|
|
#if !(STM32_RTCSEL == STM32_RTCSEL_LSE) && \
|
|
|
|
!(STM32_RTCSEL == STM32_RTCSEL_LSI) && \
|
|
|
|
!(STM32_RTCSEL == STM32_RTCSEL_HSEDIV)
|
2011-12-08 21:17:19 +00:00
|
|
|
#error "invalid source selected for RTC clock"
|
|
|
|
#endif
|
|
|
|
|
2012-03-04 14:27:03 +00:00
|
|
|
#if !defined(RTC_USE_INTERRUPTS) || defined(__DOXYGEN__)
|
|
|
|
#define RTC_USE_INTERRUPTS FALSE
|
2011-12-11 20:05:55 +00:00
|
|
|
#endif
|
|
|
|
|
2013-09-29 17:44:23 +00:00
|
|
|
#if defined(STM32_PCLK1) /* For devices without STM32_PCLK1 (STM32F0xx) */
|
2012-03-04 16:22:51 +00:00
|
|
|
#if STM32_PCLK1 < (STM32_RTCCLK * 7)
|
|
|
|
#error "STM32_PCLK1 frequency is too low to handle RTC without ugly workaround"
|
|
|
|
#endif
|
2013-09-29 17:44:23 +00:00
|
|
|
#endif /* defined(STM32_PCLK1) */
|
2012-03-04 16:22:51 +00:00
|
|
|
|
2011-12-08 21:17:19 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2011-12-11 23:40:49 +00:00
|
|
|
* @brief Type of a structure representing an RTC alarm time stamp.
|
2011-12-08 21:17:19 +00:00
|
|
|
*/
|
|
|
|
typedef struct RTCAlarm RTCAlarm;
|
|
|
|
|
2011-12-11 23:40:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of a structure representing an RTC wakeup period.
|
|
|
|
*/
|
|
|
|
typedef struct RTCWakeup RTCWakeup;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Type of a structure representing an RTC callbacks config.
|
|
|
|
*/
|
|
|
|
typedef struct RTCCallbackConfig RTCCallbackConfig;
|
|
|
|
|
2011-12-08 21:17:19 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of an RTC alarm.
|
2011-12-11 23:40:49 +00:00
|
|
|
* @details Meaningful on platforms with more than 1 alarm comparator.
|
2011-12-08 21:17:19 +00:00
|
|
|
*/
|
|
|
|
typedef uint32_t rtcalarm_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Structure representing an RTC time stamp.
|
|
|
|
*/
|
|
|
|
struct RTCTime {
|
|
|
|
/**
|
2011-12-11 20:05:55 +00:00
|
|
|
* @brief RTC date register in STM32 BCD format.
|
2011-12-08 21:17:19 +00:00
|
|
|
*/
|
2011-12-09 13:58:19 +00:00
|
|
|
uint32_t tv_date;
|
2011-12-08 21:17:19 +00:00
|
|
|
/**
|
2011-12-11 20:05:55 +00:00
|
|
|
* @brief RTC time register in STM32 BCD format.
|
2011-12-08 21:17:19 +00:00
|
|
|
*/
|
2011-12-09 13:58:19 +00:00
|
|
|
uint32_t tv_time;
|
2012-03-04 14:27:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Set this to TRUE to use 12 hour notation.
|
|
|
|
*/
|
|
|
|
bool_t h12;
|
2011-12-11 20:05:55 +00:00
|
|
|
/**
|
|
|
|
* @brief Fractional part of time.
|
|
|
|
*/
|
2011-12-13 09:03:41 +00:00
|
|
|
#if STM32_RTC_HAS_SUBSECONDS
|
2011-12-11 23:40:49 +00:00
|
|
|
uint32_t tv_msec;
|
2011-12-13 09:03:41 +00:00
|
|
|
#endif
|
2011-12-08 21:17:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-12-11 23:40:49 +00:00
|
|
|
* @brief Structure representing an RTC alarm time stamp.
|
2011-12-08 21:17:19 +00:00
|
|
|
*/
|
|
|
|
struct RTCAlarm {
|
|
|
|
/**
|
2011-12-11 20:05:55 +00:00
|
|
|
* @brief Date and time of alarm in STM32 BCD.
|
2011-12-08 21:17:19 +00:00
|
|
|
*/
|
2011-12-09 22:14:09 +00:00
|
|
|
uint32_t tv_datetime;
|
2011-12-08 21:17:19 +00:00
|
|
|
};
|
|
|
|
|
2013-09-29 17:44:23 +00:00
|
|
|
#if RTC_HAS_PERIODIC_WAKEUPS
|
2011-12-11 23:40:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Structure representing an RTC periodic wakeup period.
|
|
|
|
*/
|
|
|
|
struct RTCWakeup {
|
|
|
|
/**
|
2011-12-12 10:56:51 +00:00
|
|
|
* @brief RTC WUTR register.
|
|
|
|
* @details Bits [15:0] contain value of WUTR register
|
|
|
|
* Bits [18:16] contain value of WUCKSEL bits in CR register
|
|
|
|
*
|
2012-12-16 17:47:19 +00:00
|
|
|
* @note ((WUTR == 0) || (WUCKSEL == 3)) is forbidden combination.
|
2011-12-11 23:40:49 +00:00
|
|
|
*/
|
2011-12-12 10:56:51 +00:00
|
|
|
uint32_t wakeup;
|
2011-12-11 23:40:49 +00:00
|
|
|
};
|
2013-09-29 17:44:23 +00:00
|
|
|
#endif /* RTC_HAS_PERIODIC_WAKEUPS */
|
2011-12-11 23:40:49 +00:00
|
|
|
|
2011-12-08 21:17:19 +00:00
|
|
|
/**
|
|
|
|
* @brief Structure representing an RTC driver.
|
|
|
|
*/
|
|
|
|
struct RTCDriver{
|
|
|
|
/**
|
2011-12-11 23:40:49 +00:00
|
|
|
* @brief Pointer to the RTC registers block.
|
|
|
|
*/
|
|
|
|
RTC_TypeDef *id_rtc;
|
2011-12-08 21:17:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#if !defined(__DOXYGEN__)
|
|
|
|
extern RTCDriver RTCD1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void rtc_lld_init(void);
|
|
|
|
void rtc_lld_set_time(RTCDriver *rtcp, const RTCTime *timespec);
|
|
|
|
void rtc_lld_get_time(RTCDriver *rtcp, RTCTime *timespec);
|
|
|
|
void rtc_lld_set_alarm(RTCDriver *rtcp,
|
|
|
|
rtcalarm_t alarm,
|
|
|
|
const RTCAlarm *alarmspec);
|
|
|
|
void rtc_lld_get_alarm(RTCDriver *rtcp,
|
|
|
|
rtcalarm_t alarm,
|
|
|
|
RTCAlarm *alarmspec);
|
2013-09-29 17:44:23 +00:00
|
|
|
#if RTC_HAS_PERIODIC_WAKEUPS
|
2012-03-04 14:27:03 +00:00
|
|
|
void rtcSetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec);
|
|
|
|
void rtcGetPeriodicWakeup_v2(RTCDriver *rtcp, RTCWakeup *wakeupspec);
|
2013-09-29 17:44:23 +00:00
|
|
|
#endif /* RTC_HAS_PERIODIC_WAKEUPS */
|
2012-09-20 15:01:28 +00:00
|
|
|
uint32_t rtc_lld_get_time_fat(RTCDriver *rtcp);
|
2011-12-08 21:17:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* HAL_USE_RTC */
|
|
|
|
|
|
|
|
#endif /* _RTC_LLD_H_ */
|
|
|
|
|
|
|
|
/** @} */
|