STM32 F4 RTC: Fix some long lines
This commit is contained in:
parent
2ed1295528
commit
c40c107e7a
@ -1,4 +1,4 @@
|
|||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* arch/arm/src/stm32/stm32f40xxx_rtcc.c
|
* arch/arm/src/stm32/stm32f40xxx_rtcc.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012-2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012-2016 Gregory Nutt. All rights reserved.
|
||||||
@ -32,11 +32,11 @@
|
|||||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
@ -60,10 +60,11 @@
|
|||||||
|
|
||||||
#ifdef CONFIG_RTC
|
#ifdef CONFIG_RTC
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
/* Configuration ********************************************************************/
|
|
||||||
|
/* Configuration ************************************************************/
|
||||||
/* This RTC implementation supports
|
/* This RTC implementation supports
|
||||||
* - date/time RTC hardware
|
* - date/time RTC hardware
|
||||||
* - extended functions Alarm A and B for STM32F4xx and onwards
|
* - extended functions Alarm A and B for STM32F4xx and onwards
|
||||||
@ -81,12 +82,12 @@
|
|||||||
# error "CONFIG_STM32_PWR must selected to use this driver"
|
# error "CONFIG_STM32_PWR must selected to use this driver"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Constants ************************************************************************/
|
/* Constants ****************************************************************/
|
||||||
|
|
||||||
#define SYNCHRO_TIMEOUT (0x00020000)
|
#define SYNCHRO_TIMEOUT (0x00020000)
|
||||||
#define INITMODE_TIMEOUT (0x00010000)
|
#define INITMODE_TIMEOUT (0x00010000)
|
||||||
|
|
||||||
/* Proxy definitions to make the same code work for all the STM32 series ************/
|
/* Proxy definitions to make the same code work for all the STM32 series ****/
|
||||||
|
|
||||||
# define STM32_RCC_XXX STM32_RCC_BDCR
|
# define STM32_RCC_XXX STM32_RCC_BDCR
|
||||||
# define RCC_XXX_YYYRST RCC_BDCR_BDRST
|
# define RCC_XXX_YYYRST RCC_BDCR_BDRST
|
||||||
@ -101,10 +102,6 @@
|
|||||||
#define MINUTES_IN_HOUR 60
|
#define MINUTES_IN_HOUR 60
|
||||||
#define HOURS_IN_DAY 24
|
#define HOURS_IN_DAY 24
|
||||||
|
|
||||||
/* Can't exceed 24hours-2min without providing extra logic for carry over for day. */
|
|
||||||
|
|
||||||
#define MAX_RTC_ALARM_REL_MINUTES (24*MINUTES_IN_HOUR)-2
|
|
||||||
|
|
||||||
#define hours_add(parm_hrs) \
|
#define hours_add(parm_hrs) \
|
||||||
time->tm_hour += parm_hrs;\
|
time->tm_hour += parm_hrs;\
|
||||||
if ((HOURS_IN_DAY-1) < (time->tm_hour))\
|
if ((HOURS_IN_DAY-1) < (time->tm_hour))\
|
||||||
@ -117,9 +114,9 @@
|
|||||||
#define RTC_ALRMR_DIS_DATE_MASK (RTC_ALRMR_MSK4)
|
#define RTC_ALRMR_DIS_DATE_MASK (RTC_ALRMR_MSK4)
|
||||||
#define RTC_ALRMR_ENABLE (0)
|
#define RTC_ALRMR_ENABLE (0)
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC_ALARM
|
#ifdef CONFIG_RTC_ALARM
|
||||||
typedef unsigned int rtc_alarmreg_t;
|
typedef unsigned int rtc_alarmreg_t;
|
||||||
@ -131,9 +128,9 @@ struct alm_cbinfo_s
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC_ALARM
|
#ifdef CONFIG_RTC_ALARM
|
||||||
/* Callback to use when an EXTI is activated */
|
/* Callback to use when an EXTI is activated */
|
||||||
@ -141,17 +138,17 @@ struct alm_cbinfo_s
|
|||||||
static struct alm_cbinfo_s g_alarmcb[RTC_ALARM_LAST];
|
static struct alm_cbinfo_s g_alarmcb[RTC_ALARM_LAST];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* g_rtc_enabled is set true after the RTC has successfully initialized */
|
/* g_rtc_enabled is set true after the RTC has successfully initialized */
|
||||||
|
|
||||||
volatile bool g_rtc_enabled = false;
|
volatile bool g_rtc_enabled = false;
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC_ALARM
|
#ifdef CONFIG_RTC_ALARM
|
||||||
static int rtchw_check_alrawf(void);
|
static int rtchw_check_alrawf(void);
|
||||||
@ -162,11 +159,11 @@ static int rtchw_set_alrmbr(rtc_alarmreg_t alarmreg);
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_dumpregs
|
* Name: rtc_dumpregs
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -178,7 +175,7 @@ static int rtchw_set_alrmbr(rtc_alarmreg_t alarmreg);
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_RTC_INFO
|
#ifdef CONFIG_DEBUG_RTC_INFO
|
||||||
static void rtc_dumpregs(FAR const char *msg)
|
static void rtc_dumpregs(FAR const char *msg)
|
||||||
@ -215,7 +212,7 @@ static void rtc_dumpregs(FAR const char *msg)
|
|||||||
# define rtc_dumpregs(msg)
|
# define rtc_dumpregs(msg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_dumptime
|
* Name: rtc_dumptime
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -227,7 +224,7 @@ static void rtc_dumpregs(FAR const char *msg)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_RTC_INFO
|
#ifdef CONFIG_DEBUG_RTC_INFO
|
||||||
static void rtc_dumptime(FAR const struct tm *tp, FAR const char *msg)
|
static void rtc_dumptime(FAR const struct tm *tp, FAR const char *msg)
|
||||||
@ -244,7 +241,7 @@ static void rtc_dumptime(FAR const struct tm *tp, FAR const char *msg)
|
|||||||
# define rtc_dumptime(tp, msg)
|
# define rtc_dumptime(tp, msg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_wprunlock
|
* Name: rtc_wprunlock
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -256,7 +253,7 @@ static void rtc_dumptime(FAR const struct tm *tp, FAR const char *msg)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void rtc_wprunlock(void)
|
static void rtc_wprunlock(void)
|
||||||
{
|
{
|
||||||
@ -279,7 +276,7 @@ static void rtc_wprunlock(void)
|
|||||||
putreg32(0x53, STM32_RTC_WPR);
|
putreg32(0x53, STM32_RTC_WPR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_wprlock
|
* Name: rtc_wprlock
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -291,7 +288,7 @@ static void rtc_wprunlock(void)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static inline void rtc_wprlock(void)
|
static inline void rtc_wprlock(void)
|
||||||
{
|
{
|
||||||
@ -299,14 +296,14 @@ static inline void rtc_wprlock(void)
|
|||||||
|
|
||||||
putreg32(0xff, STM32_RTC_WPR);
|
putreg32(0xff, STM32_RTC_WPR);
|
||||||
|
|
||||||
/* Disable write access to the backup domain (RTC registers, RTC backup data
|
/* Disable write access to the backup domain (RTC registers, RTC backup
|
||||||
* registers and backup SRAM).
|
* data registers and backup SRAM).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(void)stm32_pwr_enablebkp(false);
|
(void)stm32_pwr_enablebkp(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_synchwait
|
* Name: rtc_synchwait
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -319,7 +316,7 @@ static inline void rtc_wprlock(void)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int rtc_synchwait(void)
|
static int rtc_synchwait(void)
|
||||||
{
|
{
|
||||||
@ -358,7 +355,7 @@ static int rtc_synchwait(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_enterinit
|
* Name: rtc_enterinit
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -370,7 +367,7 @@ static int rtc_synchwait(void)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int rtc_enterinit(void)
|
static int rtc_enterinit(void)
|
||||||
{
|
{
|
||||||
@ -406,7 +403,7 @@ static int rtc_enterinit(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_exitinit
|
* Name: rtc_exitinit
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -418,7 +415,7 @@ static int rtc_enterinit(void)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void rtc_exitinit(void)
|
static void rtc_exitinit(void)
|
||||||
{
|
{
|
||||||
@ -429,7 +426,7 @@ static void rtc_exitinit(void)
|
|||||||
putreg32(regval, STM32_RTC_ISR);
|
putreg32(regval, STM32_RTC_ISR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_bin2bcd
|
* Name: rtc_bin2bcd
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -441,7 +438,7 @@ static void rtc_exitinit(void)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* The value in BCD representation
|
* The value in BCD representation
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static uint32_t rtc_bin2bcd(int value)
|
static uint32_t rtc_bin2bcd(int value)
|
||||||
{
|
{
|
||||||
@ -456,7 +453,7 @@ static uint32_t rtc_bin2bcd(int value)
|
|||||||
return (msbcd << 4) | value;
|
return (msbcd << 4) | value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_bin2bcd
|
* Name: rtc_bin2bcd
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -468,7 +465,7 @@ static uint32_t rtc_bin2bcd(int value)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* The value in binary representation
|
* The value in binary representation
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int rtc_bcd2bin(uint32_t value)
|
static int rtc_bcd2bin(uint32_t value)
|
||||||
{
|
{
|
||||||
@ -476,13 +473,13 @@ static int rtc_bcd2bin(uint32_t value)
|
|||||||
return (int)(tens + (value & 0x0f));
|
return (int)(tens + (value & 0x0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_setup
|
* Name: rtc_setup
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Performs first time configuration of the RTC. A special value written into
|
* Performs first time configuration of the RTC. A special value written
|
||||||
* back-up register 0 will prevent this function from being called on sub-sequent
|
* into back-up register 0 will prevent this function from being called on
|
||||||
* resets or power up.
|
* sub-sequent resets or power up.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* None
|
* None
|
||||||
@ -490,7 +487,7 @@ static int rtc_bcd2bin(uint32_t value)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int rtc_setup(void)
|
static int rtc_setup(void)
|
||||||
{
|
{
|
||||||
@ -544,12 +541,12 @@ static int rtc_setup(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtc_resume
|
* Name: rtc_resume
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Called when the RTC was already initialized on a previous power cycle. This
|
* Called when the RTC was already initialized on a previous power cycle.
|
||||||
* just brings the RTC back into full operation.
|
* This just brings the RTC back into full operation.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* None
|
* None
|
||||||
@ -557,7 +554,7 @@ static int rtc_setup(void)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void rtc_resume(void)
|
static void rtc_resume(void)
|
||||||
{
|
{
|
||||||
@ -576,7 +573,7 @@ static void rtc_resume(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: stm32_rtc_alarm_handler
|
* Name: stm32_rtc_alarm_handler
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -589,7 +586,7 @@ static void rtc_resume(void)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; A negated errno value on failure.
|
* Zero (OK) on success; A negated errno value on failure.
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC_ALARM
|
#ifdef CONFIG_RTC_ALARM
|
||||||
static int stm32_rtc_alarm_handler(int irq, void *context)
|
static int stm32_rtc_alarm_handler(int irq, void *context)
|
||||||
@ -659,7 +656,7 @@ static int stm32_rtc_alarm_handler(int irq, void *context)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: rtchw_check_alrXwf X= a or B
|
* Name: rtchw_check_alrXwf X= a or B
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
@ -671,7 +668,7 @@ static int stm32_rtc_alarm_handler(int irq, void *context)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC_ALARM
|
#ifdef CONFIG_RTC_ALARM
|
||||||
static int rtchw_check_alrawf(void)
|
static int rtchw_check_alrawf(void)
|
||||||
@ -725,12 +722,12 @@ static int rtchw_check_alrbwf(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: stm32_rtchw_set_alrmXr X is a or b
|
* Name: stm32_rtchw_set_alrmXr X is a or b
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Set the alarm (A or B) hardware registers, using the required hardware access
|
* Set the alarm (A or B) hardware registers, using the required hardware
|
||||||
* protocol
|
* access protocol
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* alarmreg - the register
|
* alarmreg - the register
|
||||||
@ -738,7 +735,7 @@ static int rtchw_check_alrbwf(void)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC_ALARM
|
#ifdef CONFIG_RTC_ALARM
|
||||||
static int rtchw_set_alrmar(rtc_alarmreg_t alarmreg)
|
static int rtchw_set_alrmar(rtc_alarmreg_t alarmreg)
|
||||||
@ -814,16 +811,16 @@ rtchw_set_alrmbr_exit:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_rtc_initialize
|
* Name: up_rtc_initialize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Initialize the hardware RTC per the selected configuration. This function is
|
* Initialize the hardware RTC per the selected configuration. This
|
||||||
* called once during the OS initialization sequence
|
* function is called once during the OS initialization sequence
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* None
|
* None
|
||||||
@ -831,7 +828,7 @@ rtchw_set_alrmbr_exit:
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int up_rtc_initialize(void)
|
int up_rtc_initialize(void)
|
||||||
{
|
{
|
||||||
@ -843,9 +840,9 @@ int up_rtc_initialize(void)
|
|||||||
int nretry = 0;
|
int nretry = 0;
|
||||||
|
|
||||||
/* Clocking for the PWR block must be provided. However, this is done
|
/* Clocking for the PWR block must be provided. However, this is done
|
||||||
* unconditionally in stm32f40xxx_rcc.c on power up. This done unconditionally
|
* unconditionally in stm32f40xxx_rcc.c on power up. This done
|
||||||
* because the PWR block is also needed to set the internal voltage regulator for
|
* unconditionally because the PWR block is also needed to set the
|
||||||
* maximum performance.
|
* internal voltage regulator for maximum performance.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Select the clock source */
|
/* Select the clock source */
|
||||||
@ -857,9 +854,9 @@ int up_rtc_initialize(void)
|
|||||||
|
|
||||||
if (regval != RTC_MAGIC)
|
if (regval != RTC_MAGIC)
|
||||||
{
|
{
|
||||||
/* Some boards do not have the external 32khz oscillator installed, for those
|
/* Some boards do not have the external 32khz oscillator installed,
|
||||||
* boards we must fallback to the crummy internal RC clock or the external high
|
* for those boards we must fallback to the crummy internal RC clock
|
||||||
* rate clock
|
* or the external high rate clock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_RTC_HSECLOCK
|
#ifdef CONFIG_RTC_HSECLOCK
|
||||||
@ -942,8 +939,8 @@ int up_rtc_initialize(void)
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
/* Wait for the RTC Time and Date registers to be synchronized with RTC APB
|
/* Wait for the RTC Time and Date registers to be synchronized with RTC
|
||||||
* clock.
|
* APB clock.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = rtc_synchwait();
|
ret = rtc_synchwait();
|
||||||
@ -1014,12 +1011,12 @@ int up_rtc_initialize(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_RTC_ALARM
|
#ifdef CONFIG_RTC_ALARM
|
||||||
/* Configure RTC interrupt to catch alarm interrupts. All RTC interrupts are
|
/* Configure RTC interrupt to catch alarm interrupts. All RTC interrupts
|
||||||
* connected to the EXTI controller. To enable the RTC Alarm interrupt, the
|
* are connected to the EXTI controller. To enable the RTC Alarm
|
||||||
* following sequence is required:
|
* interrupt, the following sequence is required:
|
||||||
*
|
*
|
||||||
* 1. Configure and enable the EXTI Line 17 RTC ALARM in interrupt mode and select the
|
* 1. Configure and enable the EXTI Line 17 RTC ALARM in interrupt mode
|
||||||
* rising edge sensitivity.
|
* and select the rising edge sensitivity.
|
||||||
* For STM32F4xx
|
* For STM32F4xx
|
||||||
* EXTI line 21 RTC Tamper & Timestamp
|
* EXTI line 21 RTC Tamper & Timestamp
|
||||||
* EXTI line 22 RTC Wakeup
|
* EXTI line 22 RTC Wakeup
|
||||||
@ -1037,18 +1034,18 @@ int up_rtc_initialize(void)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: stm32_rtc_getdatetime_with_subseconds
|
* Name: stm32_rtc_getdatetime_with_subseconds
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Get the current date and time from the date/time RTC. This interface
|
* Get the current date and time from the date/time RTC. This interface
|
||||||
* is only supported by the date/time RTC hardware implementation.
|
* is only supported by the date/time RTC hardware implementation.
|
||||||
* It is used to replace the system timer. It is only used by the RTOS during
|
* It is used to replace the system timer. It is only used by the RTOS
|
||||||
* initialization to set up the system time when CONFIG_RTC and CONFIG_RTC_DATETIME
|
* during initialization to set up the system time when CONFIG_RTC and
|
||||||
* are selected (and CONFIG_RTC_HIRES is not).
|
* CONFIG_RTC_DATETIME are selected (and CONFIG_RTC_HIRES is not).
|
||||||
*
|
*
|
||||||
* NOTE: Some date/time RTC hardware is capability of sub-second accuracy. That
|
* NOTE: Some date/time RTC hardware is capability of sub-second accuracy.
|
||||||
* sub-second accuracy is returned through 'nsec'.
|
* That sub-second accuracy is returned through 'nsec'.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* tp - The location to return the high resolution time value.
|
* tp - The location to return the high resolution time value.
|
||||||
@ -1057,7 +1054,7 @@ int up_rtc_initialize(void)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
|
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
|
||||||
int stm32_rtc_getdatetime_with_subseconds(FAR struct tm *tp, FAR long *nsec)
|
int stm32_rtc_getdatetime_with_subseconds(FAR struct tm *tp, FAR long *nsec)
|
||||||
@ -1072,9 +1069,9 @@ int up_rtc_getdatetime(FAR struct tm *tp)
|
|||||||
uint32_t tr;
|
uint32_t tr;
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
|
|
||||||
/* Sample the data time registers. There is a race condition here... If we sample
|
/* Sample the data time registers. There is a race condition here... If
|
||||||
* the time just before midnight on December 31, the date could be wrong because
|
* we sample the time just before midnight on December 31, the date could
|
||||||
* the day rolled over while were sampling.
|
* be wrong because the day rolled over while were sampling.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
do
|
do
|
||||||
@ -1158,20 +1155,20 @@ int up_rtc_getdatetime(FAR struct tm *tp)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_rtc_getdatetime
|
* Name: up_rtc_getdatetime
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Get the current date and time from the date/time RTC. This interface
|
* Get the current date and time from the date/time RTC. This interface
|
||||||
* is only supported by the date/time RTC hardware implementation.
|
* is only supported by the date/time RTC hardware implementation.
|
||||||
* It is used to replace the system timer. It is only used by the RTOS during
|
* It is used to replace the system timer. It is only used by the RTOS
|
||||||
* initialization to set up the system time when CONFIG_RTC and CONFIG_RTC_DATETIME
|
* during initialization to set up the system time when CONFIG_RTC and
|
||||||
* are selected (and CONFIG_RTC_HIRES is not).
|
* CONFIG_RTC_DATETIME are selected (and CONFIG_RTC_HIRES is not).
|
||||||
*
|
*
|
||||||
* NOTE: Some date/time RTC hardware is capability of sub-second accuracy. That
|
* NOTE: Some date/time RTC hardware is capability of sub-second accuracy.
|
||||||
* sub-second accuracy is lost in this interface. However, since the system time
|
* That sub-second accuracy is lost in this interface. However, since the
|
||||||
* is reinitialized on each power-up/reset, there will be no timing inaccuracy in
|
* system time is reinitialized on each power-up/reset, there will be no
|
||||||
* the long run.
|
* timing inaccuracy in the long run.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* tp - The location to return the high resolution time value.
|
* tp - The location to return the high resolution time value.
|
||||||
@ -1179,7 +1176,7 @@ int up_rtc_getdatetime(FAR struct tm *tp)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
|
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
|
||||||
int up_rtc_getdatetime(FAR struct tm *tp)
|
int up_rtc_getdatetime(FAR struct tm *tp)
|
||||||
@ -1188,13 +1185,13 @@ int up_rtc_getdatetime(FAR struct tm *tp)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: stm32_rtc_setdatetime
|
* Name: stm32_rtc_setdatetime
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Set the RTC to the provided time. RTC implementations which provide
|
* Set the RTC to the provided time. RTC implementations which provide
|
||||||
* up_rtc_getdatetime() (CONFIG_RTC_DATETIME is selected) should provide this
|
* up_rtc_getdatetime() (CONFIG_RTC_DATETIME is selected) should provide
|
||||||
* function.
|
* this function.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* tp - the time to use
|
* tp - the time to use
|
||||||
@ -1202,7 +1199,7 @@ int up_rtc_getdatetime(FAR struct tm *tp)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int stm32_rtc_setdatetime(FAR const struct tm *tp)
|
int stm32_rtc_setdatetime(FAR const struct tm *tp)
|
||||||
{
|
{
|
||||||
@ -1223,11 +1220,14 @@ int stm32_rtc_setdatetime(FAR const struct tm *tp)
|
|||||||
(rtc_bin2bcd(tp->tm_min) << RTC_TR_MNU_SHIFT) |
|
(rtc_bin2bcd(tp->tm_min) << RTC_TR_MNU_SHIFT) |
|
||||||
(rtc_bin2bcd(tp->tm_hour) << RTC_TR_HU_SHIFT);
|
(rtc_bin2bcd(tp->tm_hour) << RTC_TR_HU_SHIFT);
|
||||||
|
|
||||||
/* Now convert the fields in struct tm format to the RTC date register fields:
|
/* Now convert the fields in struct tm format to the RTC date register
|
||||||
* Days: 1-31 match in both cases.
|
* fields:
|
||||||
* Month: STM32 is 1-12, struct tm is 0-11.
|
*
|
||||||
* Years: STM32 is 00-99, struct tm is years since 1900.
|
* Days: 1-31 match in both cases.
|
||||||
* WeekDay: STM32 is 1 = Mon - 7 = Sun
|
* Month: STM32 is 1-12, struct tm is 0-11.
|
||||||
|
* Years: STM32 is 00-99, struct tm is years since 1900.
|
||||||
|
* WeekDay: STM32 is 1 = Mon - 7 = Sun
|
||||||
|
*
|
||||||
* Issue: I am not sure what the STM32 years mean. Are these the
|
* Issue: I am not sure what the STM32 years mean. Are these the
|
||||||
* years 2000-2099? I'll assume so.
|
* years 2000-2099? I'll assume so.
|
||||||
*/
|
*/
|
||||||
@ -1270,12 +1270,12 @@ int stm32_rtc_setdatetime(FAR const struct tm *tp)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************************
|
/****************************************************************************
|
||||||
* Name: up_rtc_settime
|
* Name: up_rtc_settime
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Set the RTC to the provided time. All RTC implementations must be able to
|
* Set the RTC to the provided time. All RTC implementations must be able
|
||||||
* set their time based on a standard timespec.
|
* to set their time based on a standard timespec.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* tp - the time to use
|
* tp - the time to use
|
||||||
@ -1283,13 +1283,15 @@ int stm32_rtc_setdatetime(FAR const struct tm *tp)
|
|||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) on success; a negated errno on failure
|
* Zero (OK) on success; a negated errno on failure
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int up_rtc_settime(FAR const struct timespec *tp)
|
int up_rtc_settime(FAR const struct timespec *tp)
|
||||||
{
|
{
|
||||||
FAR struct tm newtime;
|
FAR struct tm newtime;
|
||||||
|
|
||||||
/* Break out the time values (not that the time is set only to units of seconds) */
|
/* Break out the time values (not that the time is set only to units of
|
||||||
|
* seconds)
|
||||||
|
*/
|
||||||
|
|
||||||
(void)gmtime_r(&tp->tv_sec, &newtime);
|
(void)gmtime_r(&tp->tv_sec, &newtime);
|
||||||
return stm32_rtc_setdatetime(&newtime);
|
return stm32_rtc_setdatetime(&newtime);
|
||||||
|
Loading…
Reference in New Issue
Block a user