STM32 RTC driver now compiles and links without error (still untested)

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4177 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-12-14 19:59:06 +00:00
parent 9922992d84
commit 69fabd1351
10 changed files with 210 additions and 49 deletions

View File

@ -57,7 +57,7 @@ CHIP_CSRCS = stm32_allocateheap.c stm32_start.c stm32_rcc.c stm32_lse.c \
stm32_gpio.c stm32_exti.c stm32_flash.c stm32_irq.c \
stm32_timerisr.c stm32_dma.c stm32_lowputc.c stm32_serial.c \
stm32_spi.c stm32_usbdev.c stm32_sdio.c stm32_tim.c stm32_i2c.c \
stm32_pwr.c stm32_idle.c stm32_waste.c
stm32_idle.c stm32_waste.c
ifeq ($(CONFIG_STM32_ETHMAC),y)
CHIP_CSRCS += stm32_eth.c
@ -67,6 +67,10 @@ ifeq ($(CONFIG_STM32_RCCLOCK),y)
CHIP_CSRCS += stm32_rcclock.c
endif
ifeq ($(CONFIG_STM32_PWR),y)
CHIP_CSRCS += stm32_pwr.c
endif
ifeq ($(CONFIG_RTC),y)
CHIP_CSRCS += stm32_rtc.c
endif

View File

@ -99,7 +99,7 @@
# define EXTI_OTGHS_WAKEUP (1 << 20) /* EXTI line 20 is connected to the USB OTG HS Wakeup event */
# define EXTI_RTC_TAMPER (1 << 21) /* EXTI line 21 is connected to the RTC Tamper and TimeStamp events */
# define EXTI_RTC_TIMESTAMP (1 << 22) /* EXTI line 21 is connected to the RTC Tamper and TimeStamp events */
# define EXTI_RTC_WAKEUP (1 << 23) /* EXTI line 22 is connected to the RTC Wakeup event
# define EXTI_RTC_WAKEUP (1 << 23) /* EXTI line 22 is connected to the RTC Wakeup event */
#endif
/* Interrupt mask register */

View File

@ -43,6 +43,9 @@
#include <nuttx/irq.h>
#include <nuttx/rtc.h>
#include <time.h>
#include <errno.h>
#include <arch/board/board.h>
#include "up_arch.h"
@ -61,10 +64,14 @@
# error "CONFIG_RTC_DATETIME must be set to use this driver"
#endif
#ifndef CONFIG_RTC_HIRES
#ifdef CONFIG_RTC_HIRES
# error "CONFIG_RTC_HIRES must NOT be set with this driver"
#endif
#ifndef CONFIG_STM32_PWR
# error "CONFIG_STM32_PWR must selected to use this driver"
#endif
/* Constants ************************************************************************/
#define SYNCHRO_TIMEOUT (0x00020000)
@ -243,6 +250,7 @@ static int rtc_enterinit(void)
break;
}
}
}
return ret;
}
@ -357,7 +365,7 @@ static int rtc_setup(void)
/* Set Initialization mode */
ret = rtc_enterinit()
ret = rtc_enterinit();
if (ret == OK)
{
/* Set the 24 hour format by clearing the FMT bit in the RTC
@ -365,7 +373,7 @@ static int rtc_setup(void)
*/
regval = getreg32(STM32_RTC_CR);
regval &= ~RTC_CR_FMT
regval &= ~RTC_CR_FMT;
putreg32(regval, STM32_RTC_CR);
/* Configure RTC pre-scaler to the required, default values for
@ -405,7 +413,9 @@ static int rtc_setup(void)
static int rtc_resume(void)
{
#ifdef CONFIG_RTC_ALARM
uint32_t regval;
#endif
int ret;
/* Wait for the RTC Time and Date registers to be syncrhonized with RTC APB
@ -473,6 +483,7 @@ static int rtc_interrupt(int irq, void *context)
int up_rtcinitialize(void)
{
uint32_t regval;
int ret;
/* Clocking for the PWR block must be provided. However, this is done
* unconditionally in stm32f40xxx_rcc.c on power up. This done unconditionally
@ -551,7 +562,7 @@ int up_rtcinitialize(void)
*
************************************************************************************/
int up_rtc_getdatetime(FAR const struct tm *tp)
int up_rtc_getdatetime(FAR struct tm *tp)
{
uint32_t dr;
uint32_t tr;
@ -575,13 +586,13 @@ int up_rtc_getdatetime(FAR const struct tm *tp)
* register.
*/
tmp = (uint8_t)(tr & (RTC_TR_SU_MASK|RTC_TR_ST_MASK)) >> RTC_TR_SU_SHIFT;
tmp = (tr & (RTC_TR_SU_MASK|RTC_TR_ST_MASK)) >> RTC_TR_SU_SHIFT;
tp->tm_sec = rtc_bcd2bin(tmp);
tmp = (tr & RTC_TR_MNU_MASK|RTC_TR_MNT_MASK) >> RTC_TR_MNU_SHIFT;
tmp = (tr & (RTC_TR_MNU_MASK|RTC_TR_MNT_MASK)) >> RTC_TR_MNU_SHIFT;
tp->tm_min = rtc_bcd2bin(tmp);
tmp = (tr & RTC_TR_HU_MASK|RTC_TR_HT_MASK) >> RTC_TR_HU_SHIFT;
tmp = (tr & (RTC_TR_HU_MASK|RTC_TR_HT_MASK)) >> RTC_TR_HU_SHIFT;
tp->tm_hour = rtc_bcd2bin(tmp);
/* Now convert the RTC date to fields in struct tm format:
@ -593,13 +604,13 @@ int up_rtc_getdatetime(FAR const struct tm *tp)
* years 2000-2099? I'll assume so.
*/
tmp = (dr & RTC_DR_DU_MASK|RTC_DR_DT_MASK) >> RTC_DR_DU_SHIFT;
tmp = (dr & (RTC_DR_DU_MASK|RTC_DR_DT_MASK)) >> RTC_DR_DU_SHIFT;
tp->tm_mday = rtc_bcd2bin(tmp);
tmp = (dr & RTC_DR_MU_MASK|RTC_DR_MT) >> RTC_DR_MU_SHIFT;
tmp = (dr & (RTC_DR_MU_MASK|RTC_DR_MT)) >> RTC_DR_MU_SHIFT;
tp->tm_mon = rtc_bcd2bin(tmp) - 1;
tmp = (dr & RTC_DR_YU_MASK|RTC_DR_YT_MASK) >> RTC_DR_YU_SHIFT; /* Year units, BCD 0-99 */
tmp = (dr & (RTC_DR_YU_MASK|RTC_DR_YT_MASK)) >> RTC_DR_YU_SHIFT;
tp->tm_year = rtc_bcd2bin(tmp) + 100;
return OK;
}
@ -637,9 +648,9 @@ int up_rtc_settime(FAR const struct timespec *tp)
* register.
*/
tr = (rtc_bin2bcd(tp->tm_sec) << RTC_TR_SU_SHIFT) |
(rtc_bin2bcd(tp->tm_min) << RTC_TR_MNU_SHIFT) |
(rtc_bin2bcd(tp->tm_hour) << RTC_TR_HU_SHIFT);
tr = (rtc_bin2bcd(newtime.tm_sec) << RTC_TR_SU_SHIFT) |
(rtc_bin2bcd(newtime.tm_min) << RTC_TR_MNU_SHIFT) |
(rtc_bin2bcd(newtime.tm_hour) << RTC_TR_HU_SHIFT);
tr &= ~RTC_TR_RESERVED_BITS;
/* Now convert the fields in struct tm format to the RTC date register fields:
@ -651,9 +662,9 @@ int up_rtc_settime(FAR const struct timespec *tp)
* years 2000-2099? I'll assume so.
*/
dr = (rtc_bin2bcd(tp->tm_mday) << RTC_DR_DU_SHIFT) |
((rtc_bin2bcd(tp->tm_mon) + 1) << RTC_DR_MU_SHIFT) |
((rtc_bin2bcd(tp->tm_year) - 100) << RTC_DR_YU_SHIFT);
dr = (rtc_bin2bcd(newtime.tm_mday) << RTC_DR_DU_SHIFT) |
((rtc_bin2bcd(newtime.tm_mon) + 1) << RTC_DR_MU_SHIFT) |
((rtc_bin2bcd(newtime.tm_year) - 100) << RTC_DR_YU_SHIFT);
dr &= ~RTC_DR_RESERVED_BITS;
/* Disable the write protection for RTC registers */
@ -662,7 +673,7 @@ int up_rtc_settime(FAR const struct timespec *tp)
/* Set Initialization mode */
ret = rtc_enterinit()
ret = rtc_enterinit();
if (ret == OK)
{
/* Set the RTC TR and DR registers */
@ -674,7 +685,7 @@ int up_rtc_settime(FAR const struct timespec *tp)
* registers to be synchronized with RTC APB clock.
*/
rtc_enterinit()
rtc_exitinit();
ret = rtc_synchwait();
}

View File

@ -611,18 +611,27 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_RTC - Enables general support for a hardware RTC. Specific
architectures may require other specific settings.
CONFIG_RTC_HIRES - The typical RTC keeps time to resolution of 1
second, usually supporting a 32-bit time_t value. In this case,
the RTC is used to &quot;seed&quot; the normal NuttX timer and the
NuttX timer provides for higher resoution time. If CONFIG_RTC_HIRES
is enabled in the NuttX configuration, then the RTC provides higher
resolution time and completely replaces the system timer for purpose of
date and time.
CONFIG_RTC_FREQUENCY - If CONFIG_RTC_HIRES is defined, then the
frequency of the high resolution RTC must be provided. If CONFIG_RTC_HIRES
is not defined, CONFIG_RTC_FREQUENCY is assumed to be one.
CONFIG_RTC_ALARM - Enable if the RTC hardware supports setting of an alarm.
A callback function will be executed when the alarm goes off
CONFIG_RTC_DATETIME - There are two general types of RTC: (1) A simple
battery backed counter that keeps the time when power is down, and (2)
A full date / time RTC the provides the date and time information, often
in BCD format. If CONFIG_RTC_DATETIME is selected, it specifies this
second kind of RTC. In this case, the RTC is used to "seed" the normal
NuttX timer and the NuttX system timer provides for higher resoution
time.
CONFIG_RTC_HIRES - If CONFIG_RTC_DATETIME not selected, then the simple,
battery backed counter is used. There are two different implementations
of such simple counters based on the time resolution of the counter:
The typical RTC keeps time to resolution of 1 second, usually
supporting a 32-bit time_t value. In this case, the RTC is used to
"seed" the normal NuttX timer and the NuttX timer provides for higher
resoution time. If CONFIG_RTC_HIRES is enabled in the NuttX configuration,
then the RTC provides higher resolution time and completely replaces the
system timer for purpose of date and time.
CONFIG_RTC_FREQUENCY - If CONFIG_RTC_HIRES is defined, then the frequency
of the high resolution RTC must be provided. If CONFIG_RTC_HIRES is
not defined, CONFIG_RTC_FREQUENCY is assumed to be one.
CONFIG_RTC_ALARM - Enable if the RTC hardware supports setting of an
alarm. A callback function will be executed when the alarm goes off
SPI driver

View File

@ -335,6 +335,7 @@ STM3240G-EVAL-specific Configuration Options
CONFIG_STM32_CAN1
CONFIG_STM32_CAN2
CONFIG_STM32_DAC
CONFIG_STM32_PWR -- Required for RTC
APB2
----

View File

@ -161,6 +161,7 @@ CONFIG_STM32_I2C3=n
CONFIG_STM32_CAN1=n
CONFIG_STM32_CAN2=n
CONFIG_STM32_DAC=n
CONFIG_STM32_PWR=n
# APB2:
CONFIG_STM32_TIM1=n
CONFIG_STM32_TIM8=n
@ -754,6 +755,39 @@ CONFIG_NET_BROADCAST=y
CONFIG_NET_DHCP_LIGHT=n
CONFIG_NET_RESOLV_ENTRIES=4
#
# RTC Configuration
#
# CONFIG_RTC - Enables general support for a hardware RTC. Specific
# architectures may require other specific settings.
# CONFIG_RTC_DATETIME - There are two general types of RTC: (1) A simple
# battery backed counter that keeps the time when power is down, and (2)
# A full date / time RTC the provides the date and time information, often
# in BCD format. If CONFIG_RTC_DATETIME is selected, it specifies this
# second kind of RTC. In this case, the RTC is used to "seed" the normal
# NuttX timer and the NuttX system timer provides for higher resoution
# time.
# CONFIG_RTC_HIRES - If CONFIG_RTC_DATETIME not selected, then the simple,
# battery backed counter is used. There are two different implementations
# of such simple counters based on the time resolution of the counter:
# The typical RTC keeps time to resolution of 1 second, usually
# supporting a 32-bit time_t value. In this case, the RTC is used to
# "seed" the normal NuttX timer and the NuttX timer provides for higher
# resoution time. If CONFIG_RTC_HIRES is enabled in the NuttX configuration,
# then the RTC provides higher resolution time and completely replaces the
# system timer for purpose of date and time.
# CONFIG_RTC_FREQUENCY - If CONFIG_RTC_HIRES is defined, then the frequency
# of the high resolution RTC must be provided. If CONFIG_RTC_HIRES is
# not defined, CONFIG_RTC_FREQUENCY is assumed to be one.
# CONFIG_RTC_ALARM - Enable if the RTC hardware supports setting of an
# alarm. A callback function will be executed when the alarm goes off
#
CONFIG_RTC=n
CONFIG_RTC_DATETIME=y
CONFIG_RTC_HIRES=n
CONFIG_RTC_FREQUENCY=n
CONFIG_RTC_ALARM=n
#
# USB Device Configuration
#

View File

@ -161,6 +161,7 @@ CONFIG_STM32_I2C3=n
CONFIG_STM32_CAN1=n
CONFIG_STM32_CAN2=n
CONFIG_STM32_DAC=n
CONFIG_STM32_PWR=n
# APB2:
CONFIG_STM32_TIM1=n
CONFIG_STM32_TIM8=n
@ -754,6 +755,39 @@ CONFIG_NET_BROADCAST=n
CONFIG_NET_DHCP_LIGHT=n
CONFIG_NET_RESOLV_ENTRIES=4
#
# RTC Configuration
#
# CONFIG_RTC - Enables general support for a hardware RTC. Specific
# architectures may require other specific settings.
# CONFIG_RTC_DATETIME - There are two general types of RTC: (1) A simple
# battery backed counter that keeps the time when power is down, and (2)
# A full date / time RTC the provides the date and time information, often
# in BCD format. If CONFIG_RTC_DATETIME is selected, it specifies this
# second kind of RTC. In this case, the RTC is used to "seed" the normal
# NuttX timer and the NuttX system timer provides for higher resoution
# time.
# CONFIG_RTC_HIRES - If CONFIG_RTC_DATETIME not selected, then the simple,
# battery backed counter is used. There are two different implementations
# of such simple counters based on the time resolution of the counter:
# The typical RTC keeps time to resolution of 1 second, usually
# supporting a 32-bit time_t value. In this case, the RTC is used to
# "seed" the normal NuttX timer and the NuttX timer provides for higher
# resoution time. If CONFIG_RTC_HIRES is enabled in the NuttX configuration,
# then the RTC provides higher resolution time and completely replaces the
# system timer for purpose of date and time.
# CONFIG_RTC_FREQUENCY - If CONFIG_RTC_HIRES is defined, then the frequency
# of the high resolution RTC must be provided. If CONFIG_RTC_HIRES is
# not defined, CONFIG_RTC_FREQUENCY is assumed to be one.
# CONFIG_RTC_ALARM - Enable if the RTC hardware supports setting of an
# alarm. A callback function will be executed when the alarm goes off
#
CONFIG_RTC=n
CONFIG_RTC_DATETIME=y
CONFIG_RTC_HIRES=n
CONFIG_RTC_FREQUENCY=n
CONFIG_RTC_ALARM=n
#
# USB Device Configuration
#

View File

@ -161,6 +161,7 @@ CONFIG_STM32_I2C3=n
CONFIG_STM32_CAN1=n
CONFIG_STM32_CAN2=n
CONFIG_STM32_DAC=n
CONFIG_STM32_PWR=n
# APB2:
CONFIG_STM32_TIM1=n
CONFIG_STM32_TIM8=n
@ -758,6 +759,39 @@ CONFIG_NET_BROADCAST=n
CONFIG_NET_DHCP_LIGHT=n
CONFIG_NET_RESOLV_ENTRIES=4
#
# RTC Configuration
#
# CONFIG_RTC - Enables general support for a hardware RTC. Specific
# architectures may require other specific settings.
# CONFIG_RTC_DATETIME - There are two general types of RTC: (1) A simple
# battery backed counter that keeps the time when power is down, and (2)
# A full date / time RTC the provides the date and time information, often
# in BCD format. If CONFIG_RTC_DATETIME is selected, it specifies this
# second kind of RTC. In this case, the RTC is used to "seed" the normal
# NuttX timer and the NuttX system timer provides for higher resoution
# time.
# CONFIG_RTC_HIRES - If CONFIG_RTC_DATETIME not selected, then the simple,
# battery backed counter is used. There are two different implementations
# of such simple counters based on the time resolution of the counter:
# The typical RTC keeps time to resolution of 1 second, usually
# supporting a 32-bit time_t value. In this case, the RTC is used to
# "seed" the normal NuttX timer and the NuttX timer provides for higher
# resoution time. If CONFIG_RTC_HIRES is enabled in the NuttX configuration,
# then the RTC provides higher resolution time and completely replaces the
# system timer for purpose of date and time.
# CONFIG_RTC_FREQUENCY - If CONFIG_RTC_HIRES is defined, then the frequency
# of the high resolution RTC must be provided. If CONFIG_RTC_HIRES is
# not defined, CONFIG_RTC_FREQUENCY is assumed to be one.
# CONFIG_RTC_ALARM - Enable if the RTC hardware supports setting of an
# alarm. A callback function will be executed when the alarm goes off
#
CONFIG_RTC=n
CONFIG_RTC_DATETIME=y
CONFIG_RTC_HIRES=n
CONFIG_RTC_FREQUENCY=n
CONFIG_RTC_ALARM=n
#
# USB Device Configuration
#

View File

@ -161,6 +161,7 @@ CONFIG_STM32_I2C3=n
CONFIG_STM32_CAN1=n
CONFIG_STM32_CAN2=n
CONFIG_STM32_DAC=n
CONFIG_STM32_PWR=n
# APB2:
CONFIG_STM32_TIM1=n
CONFIG_STM32_TIM8=n
@ -714,6 +715,39 @@ CONFIG_NET_BROADCAST=n
CONFIG_NET_DHCP_LIGHT=n
CONFIG_NET_RESOLV_ENTRIES=4
#
# RTC Configuration
#
# CONFIG_RTC - Enables general support for a hardware RTC. Specific
# architectures may require other specific settings.
# CONFIG_RTC_DATETIME - There are two general types of RTC: (1) A simple
# battery backed counter that keeps the time when power is down, and (2)
# A full date / time RTC the provides the date and time information, often
# in BCD format. If CONFIG_RTC_DATETIME is selected, it specifies this
# second kind of RTC. In this case, the RTC is used to "seed" the normal
# NuttX timer and the NuttX system timer provides for higher resoution
# time.
# CONFIG_RTC_HIRES - If CONFIG_RTC_DATETIME not selected, then the simple,
# battery backed counter is used. There are two different implementations
# of such simple counters based on the time resolution of the counter:
# The typical RTC keeps time to resolution of 1 second, usually
# supporting a 32-bit time_t value. In this case, the RTC is used to
# "seed" the normal NuttX timer and the NuttX timer provides for higher
# resoution time. If CONFIG_RTC_HIRES is enabled in the NuttX configuration,
# then the RTC provides higher resolution time and completely replaces the
# system timer for purpose of date and time.
# CONFIG_RTC_FREQUENCY - If CONFIG_RTC_HIRES is defined, then the frequency
# of the high resolution RTC must be provided. If CONFIG_RTC_HIRES is
# not defined, CONFIG_RTC_FREQUENCY is assumed to be one.
# CONFIG_RTC_ALARM - Enable if the RTC hardware supports setting of an
# alarm. A callback function will be executed when the alarm goes off
#
CONFIG_RTC=n
CONFIG_RTC_DATETIME=y
CONFIG_RTC_HIRES=n
CONFIG_RTC_FREQUENCY=n
CONFIG_RTC_ALARM=n
#
# USB Device Configuration
#

View File

@ -217,7 +217,7 @@ EXTERN int up_rtc_gettime(FAR struct timespec *tp);
************************************************************************************/
#ifdef CONFIG_RTC_DATETIME
EXTERN int up_rtc_getdatetime(FAR const struct tm *tp);
EXTERN int up_rtc_getdatetime(FAR struct tm *tp);
#endif
/************************************************************************************