STM32 F4: Add a custom RTC driver

This commit is contained in:
Neil Hancock 2016-04-02 10:46:10 -06:00 committed by Gregory Nutt
parent 472115eda9
commit 5ac54013d2
6 changed files with 1733 additions and 49 deletions

View File

@ -0,0 +1,115 @@
/****************************************************************************
* arch/arm/src/stm32/stm32_alarm.h
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
* Copyright (C) 2011-2013, 2015-2016 Gregory Nutt. All rights reserved.
* Author: Uros Platise <uros.platise@isotel.eu> (Original for the F1)
* Gregory Nutt <gnutt@nuttx.org> (On-going support and development)
*
* 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.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_STM32_STM32_ALARM_H
#define __ARCH_ARM_SRC_STM32_STM32_ALARM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "chip.h"
#ifdef CONFIG_RTC_ALARM
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
/* The form of an alarm callback */
typedef CODE void (*alarmcb_t)(void);
/****************************************************************************
* Public Functions
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: stm32_rtc_setalarm
*
* Description:
* Set up an alarm.
*
* Input Parameters:
* tp - the time to set the alarm
* callback - the function to call when the alarm expires.
*
* Returned Value:
* Zero (OK) on success; a negated errno on failure
*
****************************************************************************/
struct timespec;
int stm32_rtc_setalarm(FAR const struct timespec *tp, alarmcb_t callback);
/****************************************************************************
* Name: stm32_rtc_cancelalarm
*
* Description:
* Cancel a pending alarm alarm
*
* Input Parameters:
* none
*
* Returned Value:
* Zero (OK) on success; a negated errno on failure
*
****************************************************************************/
int stm32_rtc_cancelalarm(void);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* CONFIG_RTC_ALARM */
#endif /* __ARCH_ARM_SRC_STM32_STM32_ALARM_H */

View File

@ -80,6 +80,8 @@
*/
#elif defined(CONFIG_STM32_STM32L15XX) || defined(CONFIG_STM32_STM32F20XX) || \
defined(CONFIG_STM32_STM32F30XX) || defined(CONFIG_STM32_STM32F40XX)
defined(CONFIG_STM32_STM32F30XX)
# include "stm32_rtcc.c"
#elif defined(CONFIG_STM32_STM32F40XX)
# include "stm32f40xxx_rtcc.c"
#endif

View File

@ -2,7 +2,7 @@
* arch/arm/src/stm32/stm32_rtc.h
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
* Copyright (C) 2011-2013, 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2013, 2015-2016 Gregory Nutt. All rights reserved.
* Author: Uros Platise <uros.platise@isotel.eu> (Original for the F1)
* Gregory Nutt <gnutt@nuttx.org> (On-going support and development)
*
@ -64,6 +64,14 @@
# include "chip/stm32_rtcc.h"
#endif
/* Alarm function differs from part to part */
#ifdef CONFIG_STM32_STM32F40XX
# include "stm32f40xxx_alarm.h"
#else
# include "stm32_alarm.h"
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -77,10 +85,6 @@
#ifndef __ASSEMBLY__
/* The form of an alarm callback */
typedef CODE void (*alarmcb_t)(void);
/****************************************************************************
* Public Data
****************************************************************************/
@ -145,44 +149,6 @@ struct tm;
int stm32_rtc_setdatetime(FAR const struct tm *tp);
#endif
/****************************************************************************
* Name: stm32_rtc_setalarm
*
* Description:
* Set up an alarm.
*
* Input Parameters:
* tp - the time to set the alarm
* callback - the function to call when the alarm expires.
*
* Returned Value:
* Zero (OK) on success; a negated errno on failure
*
****************************************************************************/
#ifdef CONFIG_RTC_ALARM
struct timespec;
int stm32_rtc_setalarm(FAR const struct timespec *tp, alarmcb_t callback);
#endif
/****************************************************************************
* Name: stm32_rtc_cancelalarm
*
* Description:
* Cancel a pending alarm alarm
*
* Input Parameters:
* none
*
* Returned Value:
* Zero (OK) on success; a negated errno on failure
*
****************************************************************************/
#ifdef CONFIG_RTC_ALARM
int stm32_rtc_cancelalarm(void);
#endif
/****************************************************************************
* Name: stm32_rtc_lowerhalf
*

View File

@ -1,7 +1,7 @@
/************************************************************************************
* arch/arm/src/stm32/stm32_rtcc.c
*
* Copyright (C) 2012-2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2012-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -270,7 +270,7 @@ static void rtc_wprunlock(void)
}
/************************************************************************************
* Name: rtc_wprunlock
* Name: rtc_wprlock
*
* Description:
* Enable RTC write protection
@ -567,10 +567,10 @@ static void rtc_resume(void)
}
/************************************************************************************
* Name: rtc_interrupt
* Name: rtc_wkup_interrupt
*
* Description:
* RTC interrupt service routine
* RTC WKUP interrupt service routine through the EXTI line
*
* Input Parameters:
* irq - The IRQ number that generated the interrupt
@ -582,7 +582,7 @@ static void rtc_resume(void)
************************************************************************************/
#ifdef CONFIG_RTC_ALARM
static int rtc_interrupt(int irq, void *context)
static int rtc_wkup_interrupt(int irq, void *context)
{
#warning "Missing logic"
return OK;

View File

@ -0,0 +1,129 @@
/****************************************************************************
* arch/arm/src/include/stm32/stm32f0xxx_alarm.h
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Neil hancock - delegated to Gregory Nutt Mar 30, 2016
*
* 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.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_STM32_STM32F0XXX_ALARM_H
#define __ARCH_ARM_SRC_STM32_STM32F0XXX_ALARM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_RTC_ALARM
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define RTC_ALRMR_DIS_MASK (RTC_ALRMR_MSK4 | RTC_ALRMR_MSK3 | \
RTC_ALRMR_MSK2 | RTC_ALRMR_MSK1)
#define RTC_ALRMR_DIS_DATE_HOURS_MASK (RTC_ALRMR_MSK4 | RTC_ALRMR_MSK3)
#define RTC_ALRMR_DIS_DATE_MASK (RTC_ALRMR_MSK4 )
/****************************************************************************
* Public Types
****************************************************************************/
typedef CODE void (*rtc_ext_cb_t)(void);
typedef unsigned int rtc_alarmreg_t;
/* These features are known to map to STM32 RTC from stm32F4xx and appear to
* map to beyond stm32F4xx, & stm32L0xx there appears to be a small variant
* with stm32F3 but do not map to stm32F0, F1, F2
*/
enum rtc_ext_type_e
{
RTC_ALARMA_REL, /* EXTI RTC_ALARM Event */
RTC_ALARMB_REL, /* EXTI RTC_ALARM Event */
RTC_EXT_LAST
};
union rtc_ext_param_u
{
int alm_minutes;
/* Other param can share the space */
};
struct up_alarm_update_s
{
int alm_type; /* enum rtc_ext_type_e */
union rtc_ext_param_u param;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: stm32_rtc_ext_set_cb
*
* Description:
* Set up an alarm callback for alarm A /B
*
* Input Parameters:
* callback - function address
*
* Returned Value:
* OK if completed else -1 if failed set the callback
*
****************************************************************************/
int stm32_rtc_ext_set_cb(int rtc_ext_type_e, rtc_ext_cb_t callback);
/****************************************************************************
* Name: stm32_rtc_ext_update
*
* Description:
* Set up the STM32 RTC hardware. This includes
* - two alarms (ALARM A and ALARM B).
* - other functions that it can be extended to as required
*
* Input Parameters:
* alm_setup - the details of the alarm
* alm_type RTC_ALARMA_REL/RTC_ALARMB_REL - set a relative alarm in minutes using associated hardware
* all other types not implemented
*
* Returned Value:
* Zero (OK) on success; a negated errno on failure
*
****************************************************************************/
int stm32_rtc_ext_update(struct up_alarm_update_s *alm_setup);
#endif /* CONFIG_RTC_ALARM */
#endif /* __ARCH_ARM_SRC_STM32_STM32F0XXX_ALARM_H */

File diff suppressed because it is too large Load Diff