mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
This commit addes support for the i.MXRT RTC. This initial commit is code complete (with limited featurs and options) but untested.
Squashed commit of the following:
arch/arm/src/imxrt: Fix some first time compile issues.
arch/arm/src/imxrt: This brings the RTC implement to code complete but still untested.
arch/arm/src/imxrt: Add some RTC initialization logic.
arch/arm/src/imxrt: Flesh out most of the RTC driver lower half and LPSRTC support.
arch/arm/src/imxrt: Some inital, partial implementation of the HPRTC and LPSRTC.
arch/arm/src/imxrt: Add HPSRTC/HPRTC file framework (no logic, just skeleton files).
arch/arm/src/imxrt: Add HPRTC header file.
Some initial configuration logic for SNVS LPRTC and HP RTC.
This commit is contained in:
@@ -136,6 +136,15 @@ config IMXRT_SEMC
|
|||||||
bool "Smart External Memory Controller (SEMC)"
|
bool "Smart External Memory Controller (SEMC)"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
|
config IMXRT_SNVS_LPSRTC
|
||||||
|
bool "LP SRTC"
|
||||||
|
default n
|
||||||
|
select IMXRT_SNVS_HPRTC
|
||||||
|
|
||||||
|
config IMXRT_SNVS_HPRTC
|
||||||
|
bool "HP RTC"
|
||||||
|
default n
|
||||||
|
|
||||||
endmenu # i.MX RT Peripheral Selection
|
endmenu # i.MX RT Peripheral Selection
|
||||||
|
|
||||||
menuconfig IMXRT_GPIO_IRQ
|
menuconfig IMXRT_GPIO_IRQ
|
||||||
@@ -452,4 +461,23 @@ config IMXRT_EDMA_EDBG
|
|||||||
system exits debug mode or the EDBG bit is cleared
|
system exits debug mode or the EDBG bit is cleared
|
||||||
|
|
||||||
endmenu # eDMA Global Configuration
|
endmenu # eDMA Global Configuration
|
||||||
|
|
||||||
|
menu "RTC Configuration"
|
||||||
|
depends on IMXRT_SNVS_HPRTC
|
||||||
|
|
||||||
|
config IMXRT_RTC_MAGIC_REG
|
||||||
|
int "RTC SNVS GPR"
|
||||||
|
default 0
|
||||||
|
range 0 3
|
||||||
|
---help---
|
||||||
|
The BKP register used to store/check the Magic value to determine if
|
||||||
|
RTC is already setup
|
||||||
|
|
||||||
|
config IMXRT_RTC_MAGIC
|
||||||
|
hex "RTC Magic 1"
|
||||||
|
default 0xfacefeed
|
||||||
|
---help---
|
||||||
|
Value used as Magic to determine if the RTC is already setup
|
||||||
|
|
||||||
|
endmenu
|
||||||
endif # ARCH_CHIP_IMXRT
|
endif # ARCH_CHIP_IMXRT
|
||||||
|
|||||||
@@ -120,6 +120,17 @@ ifeq ($(CONFIG_IMXRT_EDMA),y)
|
|||||||
CHIP_CSRCS += imxrt_edma.c
|
CHIP_CSRCS += imxrt_edma.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_IMXRT_SNVS_LPSRTC),y)
|
||||||
|
CHIP_CSRCS += imxrt_lpsrtc.c
|
||||||
|
CHIP_CSRCS += imxrt_hprtc.c
|
||||||
|
else ifeq ($(CONFIG_IMXRT_SNVS_HPRTC),y)
|
||||||
|
CHIP_CSRCS += imxrt_hprtc.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_RTC_DRIVER),y)
|
||||||
|
CHIP_CSRCS += imxrt_rtc_lowerhalf.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_IMXRT_ENET),y)
|
ifeq ($(CONFIG_IMXRT_ENET),y)
|
||||||
CHIP_CSRCS += imxrt_enet.c
|
CHIP_CSRCS += imxrt_enet.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -47,6 +47,8 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#define IMXRT_SNVS_LP_MAXTAMPER 10
|
||||||
|
|
||||||
/* Register offsets *************************************************************************/
|
/* Register offsets *************************************************************************/
|
||||||
|
|
||||||
#define IMXRT_SNVS_HPLR_OFFSET 0x0000 /* SNVS_HP Lock Register */
|
#define IMXRT_SNVS_HPLR_OFFSET 0x0000 /* SNVS_HP Lock Register */
|
||||||
@@ -127,7 +129,9 @@
|
|||||||
/* Bits 0-3: Reserved */
|
/* Bits 0-3: Reserved */
|
||||||
#define SNVS_HPCOMR_LPSWR (1 << 4) /* Bit 4: LP Software Reset */
|
#define SNVS_HPCOMR_LPSWR (1 << 4) /* Bit 4: LP Software Reset */
|
||||||
#define SNVS_HPCOMR_LPSWRDIS (1 << 5) /* Bit 5: LP Software Reset Disable */
|
#define SNVS_HPCOMR_LPSWRDIS (1 << 5) /* Bit 5: LP Software Reset Disable */
|
||||||
/* Bits 6-30: Reserved */
|
/* Bits 6-7: Reserved */
|
||||||
|
#define SNVS_HPCOMR_SWSV (1 << 8) /* Bit 8: */
|
||||||
|
/* Bits 9-30: Reserved */
|
||||||
#define SNVS_HPCOMR_NPSWAEN (1 << 31) /* Bit 31: Non-Privileged Software Access Enable */
|
#define SNVS_HPCOMR_NPSWAEN (1 << 31) /* Bit 31: Non-Privileged Software Access Enable */
|
||||||
|
|
||||||
/* SNVS_HP Control Register */
|
/* SNVS_HP Control Register */
|
||||||
@@ -143,6 +147,7 @@
|
|||||||
/* Bit 9: Reserved */
|
/* Bit 9: Reserved */
|
||||||
#define SNVS_HPCR_HPCALBVAL_SHIFT (10) /* Bits 10-14: HP Calibration Value */
|
#define SNVS_HPCR_HPCALBVAL_SHIFT (10) /* Bits 10-14: HP Calibration Value */
|
||||||
#define SNVS_HPCR_HPCALBVAL_MASK (31 << SNVS_HPCR_HPCALBVAL_SHIFT)
|
#define SNVS_HPCR_HPCALBVAL_MASK (31 << SNVS_HPCR_HPCALBVAL_SHIFT)
|
||||||
|
# define SNVS_HPCR_HPCALBVAL(n) ((uint32_t)(n) << SNVS_HPCR_HPCALBVAL_SHIFT)
|
||||||
# define SNVS_HPCR_HPCALBVAL_ZERO (0 << SNVS_HPCR_HPCALBVAL_SHIFT) /* +0 counts per 32768 ticks */
|
# define SNVS_HPCR_HPCALBVAL_ZERO (0 << SNVS_HPCR_HPCALBVAL_SHIFT) /* +0 counts per 32768 ticks */
|
||||||
# define SNVS_HPCR_HPCALBVAL_P1 (1 << SNVS_HPCR_HPCALBVAL_SHIFT) /* +1 counts per 32768 ticks */
|
# define SNVS_HPCR_HPCALBVAL_P1 (1 << SNVS_HPCR_HPCALBVAL_SHIFT) /* +1 counts per 32768 ticks */
|
||||||
# define SNVS_HPCR_HPCALBVAL_P2 (2 << SNVS_HPCR_HPCALBVAL_SHIFT) /* +2 counts per 32768 ticks */
|
# define SNVS_HPCR_HPCALBVAL_P2 (2 << SNVS_HPCR_HPCALBVAL_SHIFT) /* +2 counts per 32768 ticks */
|
||||||
@@ -151,7 +156,9 @@
|
|||||||
# define SNVS_HPCR_HPCALBVAL_M15 (17 << SNVS_HPCR_HPCALBVAL_SHIFT) /* -15 counts per 32768 ticks */
|
# define SNVS_HPCR_HPCALBVAL_M15 (17 << SNVS_HPCR_HPCALBVAL_SHIFT) /* -15 counts per 32768 ticks */
|
||||||
# define SNVS_HPCR_HPCALBVAL_M2 (30 << SNVS_HPCR_HPCALBVAL_SHIFT) /* -2 counts per 32768 ticks */
|
# define SNVS_HPCR_HPCALBVAL_M2 (30 << SNVS_HPCR_HPCALBVAL_SHIFT) /* -2 counts per 32768 ticks */
|
||||||
# define SNVS_HPCR_HPCALBVAL_M1 (31 << SNVS_HPCR_HPCALBVAL_SHIFT) /* -1 counts per 32768 ticks */
|
# define SNVS_HPCR_HPCALBVAL_M1 (31 << SNVS_HPCR_HPCALBVAL_SHIFT) /* -1 counts per 32768 ticks */
|
||||||
/* Bits 15-23: Reserved */
|
/* Bits 15: Reserved */
|
||||||
|
#define SNVS_HPCR_HPTS (1 << 16) /* Bit 16: LPSRTC time sychronization */
|
||||||
|
/* Bits 17-23: Reserved */
|
||||||
#define SNVS_HPCR_BTNCONFIG_SHIFT (24) /* Bits 24-26: Button Configuration */
|
#define SNVS_HPCR_BTNCONFIG_SHIFT (24) /* Bits 24-26: Button Configuration */
|
||||||
#define SNVS_HPCR_BTNCONFIG_MASK (7 << SNVS_HPCR_BTNCONFIG_SHIFT)
|
#define SNVS_HPCR_BTNCONFIG_MASK (7 << SNVS_HPCR_BTNCONFIG_SHIFT)
|
||||||
# define SNVS_HPCR_BTNCONFIG_ LOW (0 << SNVS_HPCR_BTNCONFIG_SHIFT) /* Button signal active low */
|
# define SNVS_HPCR_BTNCONFIG_ LOW (0 << SNVS_HPCR_BTNCONFIG_SHIFT) /* Button signal active low */
|
||||||
@@ -183,8 +190,6 @@
|
|||||||
|
|
||||||
#define SNVS_HPTAMR_MASK 0x00007fff /* Bits 0-14: HP Time Alarm, most-significant 15 bits */
|
#define SNVS_HPTAMR_MASK 0x00007fff /* Bits 0-14: HP Time Alarm, most-significant 15 bits */
|
||||||
|
|
||||||
#define SNVS_HPTALR_
|
|
||||||
|
|
||||||
/* SNVS_LP Lock Register */
|
/* SNVS_LP Lock Register */
|
||||||
|
|
||||||
/* Bits 0-3: Reserved */
|
/* Bits 0-3: Reserved */
|
||||||
@@ -203,6 +208,20 @@
|
|||||||
#define SNVS_LPCR_TOP (1 << 6) /* Bit 6: Turn off System Power */
|
#define SNVS_LPCR_TOP (1 << 6) /* Bit 6: Turn off System Power */
|
||||||
#define SNVS_LPCR_PWRGLITCHEN (1 << 7) /* Bit 7: Power Glitch Enable */
|
#define SNVS_LPCR_PWRGLITCHEN (1 << 7) /* Bit 7: Power Glitch Enable */
|
||||||
/* Bits 8-15: Reserved */
|
/* Bits 8-15: Reserved */
|
||||||
|
#define SNVS_LPCR_LPCALBEN (1 << 8) /* Bit 8: LP Real Time Counter Calibration Enabled */
|
||||||
|
/* Bit 9: Reserved */
|
||||||
|
#define SNVS_LPCR_LPCALBVAL_SHIFT (10) /* Bits 10-14: LP Calibration Value */
|
||||||
|
#define SNVS_LPCR_LPCALBVAL_MASK (31 << SNVS_LPCR_LPCALBVAL_SHIFT)
|
||||||
|
# define SNVS_LPCR_LPCALBVAL(n) ((uint32_t)(n) << SNVS_LPCR_LPCALBVAL_SHIFT)
|
||||||
|
# define SNVS_LPCR_LPCALBVAL_ZERO (0 << SNVS_LPCR_LPCALBVAL_SHIFT) /* +0 counts per 32768 ticks */
|
||||||
|
# define SNVS_LPCR_LPCALBVAL_P1 (1 << SNVS_LPCR_LPCALBVAL_SHIFT) /* +1 counts per 32768 ticks */
|
||||||
|
# define SNVS_LPCR_LPCALBVAL_P2 (2 << SNVS_LPCR_LPCALBVAL_SHIFT) /* +2 counts per 32768 ticks */
|
||||||
|
# define SNVS_LPCR_LPCALBVAL_P15 (15 << SNVS_LPCR_LPCALBVAL_SHIFT) /* +15 counts per 32768 ticks */
|
||||||
|
# define SNVS_LPCR_LPCALBVAL_M16 (16 << SNVS_LPCR_LPCALBVAL_SHIFT) /* -16 counts per 32768 ticks */
|
||||||
|
# define SNVS_LPCR_LPCALBVAL_M15 (17 << SNVS_LPCR_LPCALBVAL_SHIFT) /* -15 counts per 32768 ticks */
|
||||||
|
# define SNVS_LPCR_LPCALBVAL_M2 (30 << SNVS_LPCR_LPCALBVAL_SHIFT) /* -2 counts per 32768 ticks */
|
||||||
|
# define SNVS_LPCR_LPCALBVAL_M1 (31 << SNVS_LPCR_LPCALBVAL_SHIFT) /* -1 counts per 32768 ticks */
|
||||||
|
/* Bit 15: Reserved */
|
||||||
#define SNVS_LPCR_BTNPRESSTIME_SHIFT (16) /* Bits 16-17: PMIC button press time out values */
|
#define SNVS_LPCR_BTNPRESSTIME_SHIFT (16) /* Bits 16-17: PMIC button press time out values */
|
||||||
#define SNVS_LPCR_BTNPRESSTIME_MASK (3 << SNVS_LPCR_BTNPRESSTIME_SHIFT)
|
#define SNVS_LPCR_BTNPRESSTIME_MASK (3 << SNVS_LPCR_BTNPRESSTIME_SHIFT)
|
||||||
# define SNVS_LPCR_BTNPRESSTIME_5SEC (0 << SNVS_LPCR_BTNPRESSTIME_SHIFT) /* 5 secs */
|
# define SNVS_LPCR_BTNPRESSTIME_5SEC (0 << SNVS_LPCR_BTNPRESSTIME_SHIFT) /* 5 secs */
|
||||||
@@ -229,7 +248,7 @@
|
|||||||
|
|
||||||
/* Bits 0-1: Reserved */
|
/* Bits 0-1: Reserved */
|
||||||
#define SNVS_LPSR_MCR (1 << 2) /* Bit 2: Monotonic Counter Rollover */
|
#define SNVS_LPSR_MCR (1 << 2) /* Bit 2: Monotonic Counter Rollover */
|
||||||
/* Bits 3-16: Reserved */ */
|
/* Bits 3-16: Reserved */
|
||||||
#define SNVS_LPSR_EO (1 << 17) /* Bit 17: Emergency Off */
|
#define SNVS_LPSR_EO (1 << 17) /* Bit 17: Emergency Off */
|
||||||
#define SNVS_LPSR_SPO (1 << 18) /* Bit 18: Set Power Off */
|
#define SNVS_LPSR_SPO (1 << 18) /* Bit 18: Set Power Off */
|
||||||
/* Bits 19-31: Reserved */
|
/* Bits 19-31: Reserved */
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,255 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/arm/src/imxrt/imxrt_hprtc.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ARCH_ARM_SRC_IMXRT_IMXRT_HPRTC_H
|
||||||
|
#define __ARCH_ARM_SRC_IMXRT_IMXRT_HPRTC_H
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include "chip.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_IMXRT_SNVS_HPRTC
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Preprocessor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_DATETIME
|
||||||
|
# error CONFIG_RTC_DATETIME should not be selected with this driver
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_PERIODIC
|
||||||
|
# error CONFIG_RTC_PERIODIC should not be selected with this driver
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* REVISIT: This is probably supportable. The 47 bit timer does have
|
||||||
|
* accuracy greater than 1 second.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef CONFIG_RTC_HIRES
|
||||||
|
# error CONFIG_RTC_PERIODIC should not be selected with this driver
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Callback type used by the HPRTC log to notify the RTC driver when the
|
||||||
|
* alarm expires.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef CODE void (*hprtc_alarm_callback_t)(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if !defined(CONFIG_IMXRT_SNVS_LPSRTC) && defined(CONFIG_RTC_DRIVER)
|
||||||
|
bool g_hprtc_timset; /* True: time has been set since power up */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Functions used only for HPRTC
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Logic Common to LPSRTC and HPRTC
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: imxrt_rtc_lowerhalf
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Instantiate the RTC lower half driver for the i.MXRT. General usage:
|
||||||
|
*
|
||||||
|
* #include <nuttx/timers/rtc.h>
|
||||||
|
* #include "imxrt_hprtc.h"
|
||||||
|
*
|
||||||
|
* struct rtc_lowerhalf_s *lower;
|
||||||
|
* lower = imxrt_hprtc_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
|
||||||
|
struct rtc_lowerhalf_s;
|
||||||
|
FAR struct rtc_lowerhalf_s *imxrt_rtc_lowerhalf(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: imxrt_hprtc_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the LPSRTC per the selected configuration. This function is called
|
||||||
|
* via up_rtc_initialize (see imxrt_hprtc.c).
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
int imxrt_hprtc_initialize(void);
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: imxrt_hprtc_synchronize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Synchronize the HPRTC to the LPSRTC and enable the HPRTC timer.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_IMXRT_SNVS_LPSRTC
|
||||||
|
void imxrt_hprtc_synchronize(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: imxrt_hprtc_time
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the current time in seconds. This is the underlying implementation of the
|
||||||
|
* up_rtc_tim() function that is used by the RTOS during initialization to set up
|
||||||
|
* the system time.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The current time in seconds
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
uint32_t imxrt_hprtc_time(void);
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: imxrt_hprtc_getalarm
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the current alarm setting in seconds. This is only used by the lower half
|
||||||
|
* RTC driver.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The current alarm setting in seconds
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_RTC_ALARM) && defined(CONFIG_RTC_DRIVER)
|
||||||
|
uint32_t imxrt_hprtc_getalarm(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: imxrt_hprtc_setalarm
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set the alarm (in seconds) and enable alarm interrupts. This is only used by
|
||||||
|
* the lower half RTC driver.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* sec - The new alarm setting
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The current alarm setting in seconds
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_RTC_ALARM) && defined(CONFIG_RTC_DRIVER)
|
||||||
|
int imxrt_hprtc_setalarm(FAR struct timespec *ts, hprtc_alarm_callback_t cb);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: imxrt_hprtc_alarmdisable
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Disable alarm interrupts. Used internally after the receipt of the alarm
|
||||||
|
* interrupt. Also called by the lower-half RTC driver in order to cancel an
|
||||||
|
* alarm.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_RTC_ALARM) && defined(CONFIG_RTC_DRIVER)
|
||||||
|
void imxrt_hprtc_alarmdisable(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
|
||||||
|
#endif /* CONFIG_IMXRT_SNVS_HPRTC */
|
||||||
|
#endif /* __ARCH_ARM_SRC_IMXRT_IMXRT_HPRTC_H */
|
||||||
@@ -0,0 +1,258 @@
|
|||||||
|
/************************************************************************************
|
||||||
|
* arch/arm/src/imxrt/imxrt_lpsrtc.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/irq.h>
|
||||||
|
#include <nuttx/timers/rtc.h>
|
||||||
|
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
|
#include "up_arch.h"
|
||||||
|
|
||||||
|
#include "chip/imxrt_snvs.h"
|
||||||
|
#include "imxrt_periphclks.h"
|
||||||
|
#include "imxrt_hprtc.h"
|
||||||
|
#include "imxrt_lpsrtc.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_IMXRT_SNVS_LPSRTC
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: imxrt_lpsrtc_enable
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Enable/start the LPRTC time counter.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
static void imxrt_lpsrtc_enable(void)
|
||||||
|
{
|
||||||
|
uint32_t regval;
|
||||||
|
|
||||||
|
/* Enable the LPSRTC */
|
||||||
|
|
||||||
|
regval = getreg32(IMXRT_SNVS_LPCR);
|
||||||
|
regval |= SNVS_LPCR_MCENV;
|
||||||
|
putreg32(regval, IMXRT_SNVS_LPCR);
|
||||||
|
|
||||||
|
while ((getreg32(IMXRT_SNVS_LPCR) & SNVS_LPCR_MCENV) == 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: imxrt_lpsrtc_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the LPSRTC per the selected configuration. This function is called
|
||||||
|
* via up_rtc_initialize (see imxrt_hprtc.c).
|
||||||
|
*
|
||||||
|
* NOTE that the LPSRTC is always configured synchronized with the HPRTC. This
|
||||||
|
* means that the time is set via the LPSRTC but read via the HPRTC. Also, only
|
||||||
|
* the alarms from the HPRTC are used.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
int imxrt_lpsrtc_initialize(void)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_IMXRTC_LPSRTC_CALENABLE
|
||||||
|
uint32_t regval;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Initialize the HPRTC */
|
||||||
|
|
||||||
|
imxrt_hprtc_initialize();
|
||||||
|
|
||||||
|
/* Enable clocking to the the SNVS LP module.
|
||||||
|
* Clock is on during all modes, except STOP mode.
|
||||||
|
*/
|
||||||
|
|
||||||
|
imxrt_clockall_snvs_lp();
|
||||||
|
|
||||||
|
#ifdef CONFIG_IMXRTC_LPSRTC_CALENABLE
|
||||||
|
/* Set the LPSRTC calibration value */
|
||||||
|
|
||||||
|
regval = getreg32(IMXRT_SNVS_LPCR);
|
||||||
|
regval &= ~SNVS_LPCR_LPCALBVAL_MASK;
|
||||||
|
regval |= SNVS_LPCR_LPCALBVAL(CONFIG_IMXRTC_LPSRTC_CALVALUE);
|
||||||
|
regval |= SNVS_LPCR_LPCALBEN;
|
||||||
|
putreg32(regval, IMXRT_SNVS_LPCR);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Disable tamper pins.
|
||||||
|
* TODO: I don't think this applies the currently supported device.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Enable the LPSRTC */
|
||||||
|
|
||||||
|
imxrt_lpsrtc_enable();
|
||||||
|
|
||||||
|
/* Synchronize HPRTC time with the LPSRTC and enable HPRTC */
|
||||||
|
|
||||||
|
imxrt_hprtc_synchronize();
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: up_rtc_time
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the current time in seconds. This is similar to the standard time()
|
||||||
|
* function. This interface is only required if the low-resolution RTC/counter
|
||||||
|
* hardware implementation selected. It is only used by the RTOS during
|
||||||
|
* initialization to set up the system time when CONFIG_RTC is set but neither
|
||||||
|
* CONFIG_RTC_HIRES nor CONFIG_RTC_DATETIME are set.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The current time in seconds
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_RTC_HIRES
|
||||||
|
time_t up_rtc_time(void)
|
||||||
|
{
|
||||||
|
/* Delegate to imxrt_hprtc_time() */
|
||||||
|
|
||||||
|
return imxrt_hprtc_time();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: up_rtc_settime
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set the RTC to the provided time. All RTC implementations must be able to
|
||||||
|
* set their time based on a standard timespec.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* tp - the time to use
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
int up_rtc_settime(FAR const struct timespec *ts)
|
||||||
|
{
|
||||||
|
uint32_t regval;
|
||||||
|
|
||||||
|
DEBUGASSERT(ts != NULL);
|
||||||
|
|
||||||
|
/* Disable the LPSRTC */
|
||||||
|
|
||||||
|
regval = getreg32(IMXRT_SNVS_LPCR);
|
||||||
|
regval &= ~SNVS_LPCR_MCENV;
|
||||||
|
putreg32(regval, IMXRT_SNVS_LPCR);
|
||||||
|
|
||||||
|
while ((getreg32(IMXRT_SNVS_LPCR) & SNVS_LPCR_MCENV) != 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set LPSRTC time in seconds. We could do better by accounting for the
|
||||||
|
* ts->tv_nsec unused residual.
|
||||||
|
*
|
||||||
|
* IMXRT_SNVS_LPSMCMR Bits 9-14 = 15-bit MSB of alarm setting.
|
||||||
|
* IMXRT_SNVS_LPSMCLR 32-bit LSB of alarm setting.
|
||||||
|
*/
|
||||||
|
|
||||||
|
putreg32((uint32_t)ts->tv_sec >> 17, IMXRT_SNVS_LPSMCMR);
|
||||||
|
putreg32((uint32_t)ts->tv_sec << 15, IMXRT_SNVS_LPSMCLR);
|
||||||
|
|
||||||
|
/* The time has been set */
|
||||||
|
|
||||||
|
putreg32(CONFIG_IMXRT_RTC_MAGIC,
|
||||||
|
IMXRT_SNVS_LPGPR(CONFIG_IMXRT_RTC_MAGIC_REG));
|
||||||
|
|
||||||
|
/* Unconditionally re-enable the LPSRTC */
|
||||||
|
|
||||||
|
imxrt_lpsrtc_enable();
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: imxrt_lpsrtc_havesettime
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Check if the LPSRTC time has been set
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Returns true if RTC date-time have been previously set.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool imxrt_lpsrtc_havesettime(void)
|
||||||
|
{
|
||||||
|
return (getreg32(IMXRT_SNVS_LPGPR(CONFIG_IMXRT_RTC_MAGIC_REG)) ==
|
||||||
|
CONFIG_IMXRT_RTC_MAGIC);
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_IMXRT_SNVS_LPSRTC */
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/arm/src/imxrt/imxrt_lpsrtc.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ARCH_ARM_SRC_IMXRT_IMXRT_LPSRTC_H
|
||||||
|
#define __ARCH_ARM_SRC_IMXRT_IMXRT_LPSRTC_H
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include "chip.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_IMXRT_SNVS_LPSRTC
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Preprocessor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
# ifdef CONFIG_RTC_DATETIME
|
||||||
|
# error CONFIG_RTC_DATETIME should not be selected with this driver
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifdef CONFIG_RTC_PERIODIC
|
||||||
|
# error CONFIG_RTC_PERIODIC should not be selected with this driver
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* REVISIT: This is probably supportable. The 47 bit timer does have
|
||||||
|
* accuracy greater than 1 second.
|
||||||
|
*/
|
||||||
|
|
||||||
|
# ifdef CONFIG_RTC_HIRES
|
||||||
|
# error CONFIG_RTC_PERIODIC should not be selected with this driver
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: imxrt_lpsrtc_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the LPSRTC per the selected configuration. This function is called
|
||||||
|
* via up_rtc_initialize (see imxrt_hprtc.c).
|
||||||
|
*
|
||||||
|
* NOTE that the LPSRTC is always configured synchronized with the HPRTC. This
|
||||||
|
* means that the time is set via the LPSRTC but read via the HPRTC. Also, only
|
||||||
|
* the alarms from the HPRTC are used.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno on failure
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
int imxrt_lpsrtc_initialize(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: imxrt_lpsrtc_havesettime
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Check if the LPSRTC time has been set
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Returns true if RTC date-time have been previously set.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool imxrt_lpsrtc_havesettime(void);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* CONFIG_IMXRT_SNVS_LPSRTC */
|
||||||
|
#endif /* __ARCH_ARM_SRC_IMXRT_IMXRT_LPSRTC_H */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -289,10 +289,6 @@ Configuration sub-directories
|
|||||||
CONFIG_NSH_NETINIT_THREAD_PRIORITY=80
|
CONFIG_NSH_NETINIT_THREAD_PRIORITY=80
|
||||||
CONFIG_NSH_NETINIT_THREAD_STACKSIZE=1568
|
CONFIG_NSH_NETINIT_THREAD_STACKSIZE=1568
|
||||||
|
|
||||||
STATUS: As of this writing, I get a hardfault when I enable the PHY
|
|
||||||
interrupt so I suspect that there is something incorrect in that
|
|
||||||
pin configuration.
|
|
||||||
|
|
||||||
nsh:
|
nsh:
|
||||||
|
|
||||||
Configures the NuttShell (nsh) located at examples/nsh. This NSH
|
Configures the NuttShell (nsh) located at examples/nsh. This NSH
|
||||||
|
|||||||
Reference in New Issue
Block a user