2015-03-29 23:34:48 +02:00
|
|
|
/****************************************************************************
|
2009-09-23 04:09:40 +02:00
|
|
|
* arch/arm/src/stm32/stm32_rtc.h
|
|
|
|
*
|
2011-04-15 18:20:25 +02:00
|
|
|
* Copyright (C) 2011 Uros Platise. All rights reserved.
|
2017-06-14 23:32:54 +02:00
|
|
|
* Copyright (C) 2011-2013, 2015-2017 Gregory Nutt. All rights reserved.
|
2013-02-09 17:39:59 +01:00
|
|
|
* Author: Uros Platise <uros.platise@isotel.eu> (Original for the F1)
|
|
|
|
* Gregory Nutt <gnutt@nuttx.org> (On-going support and development)
|
2009-09-23 04:09:40 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2015-03-29 23:34:48 +02:00
|
|
|
****************************************************************************/
|
2009-09-23 04:09:40 +02:00
|
|
|
|
2015-03-29 23:34:48 +02:00
|
|
|
/****************************************************************************
|
2009-09-23 04:09:40 +02:00
|
|
|
* Included Files
|
2015-03-29 23:34:48 +02:00
|
|
|
****************************************************************************/
|
2009-09-23 04:09:40 +02:00
|
|
|
|
2011-04-15 18:20:25 +02:00
|
|
|
#ifndef __ARCH_ARM_SRC_STM32_STM32_RTC_H
|
|
|
|
#define __ARCH_ARM_SRC_STM32_STM32_RTC_H
|
|
|
|
|
2009-09-23 04:09:40 +02:00
|
|
|
#include <nuttx/config.h>
|
2009-12-16 21:05:51 +01:00
|
|
|
|
2009-09-23 04:09:40 +02:00
|
|
|
#include "chip.h"
|
2013-02-09 17:39:59 +01:00
|
|
|
|
|
|
|
/* The STM32 F1 has a simple battery-backed counter for its RTC and has a separate
|
|
|
|
* block for the BKP registers.
|
|
|
|
*/
|
|
|
|
|
2011-11-21 19:55:54 +01:00
|
|
|
#if defined(CONFIG_STM32_STM32F10XX)
|
2013-02-09 17:39:59 +01:00
|
|
|
# include "chip/stm32_rtc.h"
|
2011-11-21 19:55:54 +01:00
|
|
|
# include "chip/stm32_bkp.h"
|
2013-02-09 17:39:59 +01:00
|
|
|
|
|
|
|
/* The other families use a more traditional Realtime Clock/Calendar (RTCC) with
|
|
|
|
* broken-out data/time in BCD format. The backup registers are integrated into
|
|
|
|
* the RTCC in these families.
|
|
|
|
*/
|
|
|
|
|
2015-03-29 23:34:48 +02:00
|
|
|
#elif defined(CONFIG_STM32_STM32L15XX) || defined(CONFIG_STM32_STM32F20XX) || \
|
2017-07-06 18:20:14 +02:00
|
|
|
defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F4XXX)
|
2013-02-09 17:39:59 +01:00
|
|
|
# include "chip/stm32_rtcc.h"
|
2011-11-21 19:55:54 +01:00
|
|
|
#endif
|
2009-09-23 04:09:40 +02:00
|
|
|
|
2016-04-02 18:46:10 +02:00
|
|
|
/* Alarm function differs from part to part */
|
|
|
|
|
2017-10-20 19:15:17 +02:00
|
|
|
#if defined(CONFIG_STM32_STM32F4XXX)
|
2016-04-02 18:46:10 +02:00
|
|
|
# include "stm32f40xxx_alarm.h"
|
2017-10-20 19:15:17 +02:00
|
|
|
#elif defined(CONFIG_STM32_STM32L15XX)
|
|
|
|
# include "stm32l15xxx_alarm.h"
|
2016-04-02 18:46:10 +02:00
|
|
|
#else
|
|
|
|
# include "stm32_alarm.h"
|
|
|
|
#endif
|
|
|
|
|
2015-03-29 23:34:48 +02:00
|
|
|
/****************************************************************************
|
2009-12-16 21:05:51 +01:00
|
|
|
* Pre-processor Definitions
|
2015-03-29 23:34:48 +02:00
|
|
|
****************************************************************************/
|
2009-09-23 04:09:40 +02:00
|
|
|
|
2017-06-14 23:32:54 +02:00
|
|
|
#define STM32_RTC_PRESCALER_SECOND 32767 /* Default prescaler to get a
|
|
|
|
* second base */
|
|
|
|
#define STM32_RTC_PRESCALER_MIN 1 /* Maximum speed of 16384 Hz */
|
2009-09-23 04:09:40 +02:00
|
|
|
|
2017-06-14 22:36:40 +02:00
|
|
|
#if defined(CONFIG_STM32_STM32F10XX)
|
2017-06-14 23:32:54 +02:00
|
|
|
/* RTC is only a counter, store RTC data in backup domain register DR1 (if
|
|
|
|
* CONFIG_RTC_HIRES) and DR2 (state).
|
|
|
|
*/
|
2017-06-14 22:36:40 +02:00
|
|
|
|
2016-06-16 17:52:15 +02:00
|
|
|
#if !defined(CONFIG_RTC_MAGIC)
|
2017-06-14 23:32:54 +02:00
|
|
|
# define CONFIG_RTC_MAGIC (0xface) /* only 16 bit */
|
2016-06-16 17:52:15 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-14 23:32:54 +02:00
|
|
|
#define RTC_MAGIC_REG STM32_BKP_DR2
|
2017-06-14 22:36:40 +02:00
|
|
|
|
|
|
|
#else /* !CONFIG_STM32_STM32F10XX */
|
|
|
|
|
|
|
|
#if !defined(CONFIG_RTC_MAGIC)
|
2017-12-25 20:56:06 +01:00
|
|
|
# define CONFIG_RTC_MAGIC (0xfacefeed)
|
2017-04-06 17:53:11 +02:00
|
|
|
#endif
|
|
|
|
|
2016-06-16 17:52:15 +02:00
|
|
|
#if !defined(CONFIG_RTC_MAGIC_REG)
|
2017-06-14 23:32:54 +02:00
|
|
|
# define CONFIG_RTC_MAGIC_REG (0)
|
2016-06-16 17:52:15 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-14 23:32:54 +02:00
|
|
|
#define RTC_MAGIC_REG STM32_RTC_BKR(CONFIG_RTC_MAGIC_REG)
|
2017-06-14 22:36:40 +02:00
|
|
|
|
|
|
|
#endif /* CONFIG_STM32_STM32F10XX */
|
|
|
|
|
2017-06-14 23:32:54 +02:00
|
|
|
#define RTC_MAGIC CONFIG_RTC_MAGIC
|
|
|
|
#define RTC_MAGIC_TIME_SET CONFIG_RTC_MAGIC_TIME_SET
|
2017-06-14 22:36:40 +02:00
|
|
|
|
|
|
|
#if !defined(CONFIG_RTC_MAGIC_TIME_SET)
|
2017-06-14 23:32:54 +02:00
|
|
|
# define CONFIG_RTC_MAGIC_TIME_SET (CONFIG_RTC_MAGIC + 1)
|
2017-06-14 22:36:40 +02:00
|
|
|
#endif
|
2016-06-16 17:52:15 +02:00
|
|
|
|
2015-02-13 15:41:34 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-04-15 18:20:25 +02:00
|
|
|
#ifndef __ASSEMBLY__
|
2009-09-23 04:09:40 +02:00
|
|
|
|
2015-02-13 15:41:34 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-04-15 18:20:25 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
2015-02-13 15:41:34 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2011-04-15 18:20:25 +02:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
2009-09-23 04:09:40 +02:00
|
|
|
|
2015-03-29 23:34:48 +02:00
|
|
|
/****************************************************************************
|
2011-04-15 18:20:25 +02:00
|
|
|
* Public Functions
|
2015-03-29 23:34:48 +02:00
|
|
|
****************************************************************************/
|
2009-09-23 04:09:40 +02:00
|
|
|
|
2017-12-25 20:56:06 +01:00
|
|
|
/****************************************************************************
|
2017-06-14 22:36:40 +02:00
|
|
|
* Name: stm32_rtc_irqinitialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize IRQs for RTC, not possible during up_rtc_initialize because
|
|
|
|
* up_irqinitialize is called later.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success; a negated errno on failure
|
|
|
|
*
|
2017-12-25 20:56:06 +01:00
|
|
|
****************************************************************************/
|
2017-06-14 22:36:40 +02:00
|
|
|
|
|
|
|
int stm32_rtc_irqinitialize(void);
|
|
|
|
|
2015-03-29 23:34:48 +02:00
|
|
|
/****************************************************************************
|
2015-02-16 14:18:09 +01:00
|
|
|
* Name: stm32_rtc_getdatetime_with_subseconds
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the current date and time from the date/time RTC. This interface
|
|
|
|
* is only supported by the date/time RTC hardware implementation.
|
2015-03-29 23:34:48 +02:00
|
|
|
* It is used to replace the system timer. It is only used by the RTOS
|
|
|
|
* during initialization to set up the system time when CONFIG_RTC and
|
|
|
|
* CONFIG_RTC_DATETIME are selected (and CONFIG_RTC_HIRES is not).
|
2015-02-16 14:18:09 +01:00
|
|
|
*
|
2015-03-29 23:34:48 +02:00
|
|
|
* NOTE: Some date/time RTC hardware is capability of sub-second accuracy.
|
|
|
|
* Thatsub-second accuracy is returned through 'nsec'.
|
2015-02-16 14:18:09 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tp - The location to return the high resolution time value.
|
|
|
|
* nsec - The location to return the subsecond time value.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success; a negated errno on failure
|
|
|
|
*
|
2015-03-29 23:34:48 +02:00
|
|
|
****************************************************************************/
|
2015-02-16 14:18:09 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
|
|
|
|
int stm32_rtc_getdatetime_with_subseconds(FAR struct tm *tp, FAR long *nsec);
|
|
|
|
#endif
|
|
|
|
|
2015-03-29 23:34:48 +02:00
|
|
|
/****************************************************************************
|
2015-02-13 19:56:58 +01:00
|
|
|
* Name: stm32_rtc_setdatetime
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the RTC to the provided time. RTC implementations which provide
|
2015-03-29 23:34:48 +02:00
|
|
|
* up_rtc_getdatetime() (CONFIG_RTC_DATETIME is selected) should provide
|
|
|
|
* this function.
|
2015-02-13 19:56:58 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* tp - the time to use
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success; a negated errno on failure
|
|
|
|
*
|
2015-03-29 23:34:48 +02:00
|
|
|
****************************************************************************/
|
2015-02-13 19:56:58 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_DATETIME
|
|
|
|
struct tm;
|
|
|
|
int stm32_rtc_setdatetime(FAR const struct tm *tp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_rtc_lowerhalf
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Instantiate the RTC lower half driver for the STM32. General usage:
|
|
|
|
*
|
2015-04-01 20:37:44 +02:00
|
|
|
* #include <nuttx/timers/rtc.h>
|
2017-12-25 20:56:06 +01:00
|
|
|
* #include "stm32_rtc.h"
|
2015-02-13 19:56:58 +01:00
|
|
|
*
|
|
|
|
* struct rtc_lowerhalf_s *lower;
|
|
|
|
* lower = stm32_rtc_lowerhalf();
|
|
|
|
* rtc_initialize(0, lower);
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, a non-NULL RTC lower interface is returned. NULL is
|
|
|
|
* returned on any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_DRIVER
|
2015-02-15 17:11:01 +01:00
|
|
|
struct rtc_lowerhalf_s;
|
|
|
|
FAR struct rtc_lowerhalf_s *stm32_rtc_lowerhalf(void);
|
2015-02-13 19:56:58 +01:00
|
|
|
#endif
|
|
|
|
|
2011-04-15 18:20:25 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* __ASSEMBLY__ */
|
2009-09-23 04:09:40 +02:00
|
|
|
#endif /* __ARCH_ARM_SRC_STM32_STM32_RTC_H */
|