Browse Source

Merge pull request #1290 from liu2guang/master

[BSP] add rt1050 hp rtc driver.| 添加RT1050 高功耗RTC驱动.
Tanek 7 years ago
parent
commit
c4c729f014

+ 4 - 2
bsp/imxrt1052-evk/.config

@@ -130,7 +130,9 @@ CONFIG_RT_USING_I2C_BITOPS=y
 CONFIG_RT_USING_PIN=y
 # CONFIG_RT_USING_MTD_NOR is not set
 # CONFIG_RT_USING_MTD_NAND is not set
-# CONFIG_RT_USING_RTC is not set
+CONFIG_RT_USING_RTC=y
+# CONFIG_RT_USING_SOFT_RTC is not set
+# CONFIG_RTC_SYNC_USING_NTP is not set
 CONFIG_RT_USING_SDIO=y
 # CONFIG_RT_USING_SPI is not set
 # CONFIG_RT_USING_WDT is not set
@@ -312,5 +314,5 @@ CONFIG_LWIP_NETIF_LOOPBACK=0
 # CONFIG_PKG_USING_HELLO is not set
 # CONFIG_PKG_USING_MULTIBUTTON is not set
 CONFIG_SOC_IMXRT1052=y
-CONFIG_RT_USING_UART=y
 CONFIG_RT_USING_UART1=y
+CONFIG_RT_USING_HP_RTC=y

+ 9 - 7
bsp/imxrt1052-evk/Kconfig

@@ -23,13 +23,15 @@ config SOC_IMXRT1052
     select ARCH_ARM_CORTEX_M7
     default y
 
-config RT_USING_UART
-    bool "Using RT_USING_UART"
-    default y
-
-if RT_USING_UART
+if RT_USING_SERIAL
 config RT_USING_UART1
     bool "Using RT_USING_UART1"
-    default y      
+    default y 
 endif
- 
+
+if RT_USING_RTC
+config RT_USING_HP_RTC
+    bool "Using RT_USING_HP_RTC"
+    default n 
+endif
+

+ 3 - 0
bsp/imxrt1052-evk/drivers/SConscript

@@ -18,6 +18,9 @@ CPPDEFINES = []
 if GetDepend('RT_USING_PIN'):
     src += ['drv_pin.c']
 
+if GetDepend('RT_USING_HP_RTC'):
+    src += ['drv_hp_rtc.c']
+
 if GetDepend('RT_USING_LWIP'):
     src += ['drv_eth.c', 'fsl_phy.c']
     CPPDEFINES += ['FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE']

+ 150 - 0
bsp/imxrt1052-evk/drivers/drv_hp_rtc.c

@@ -0,0 +1,150 @@
+/*
+ * File      : drv_hp_rtc.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006-2013, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2018-03-15     Liuguang     the first version.
+ */
+#include "drv_hp_rtc.h" 
+#include <time.h>
+#include "fsl_common.h" 
+#include "fsl_snvs_hp.h"
+#include "fsl_snvs_lp.h"
+
+#ifdef RT_USING_RTC
+
+#if defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL
+    #error "Please don't define 'FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL'!"
+#endif
+
+static time_t get_timestamp(void) 
+{
+    struct tm tm_new = {0}; 
+    snvs_hp_rtc_datetime_t rtcDate; 
+    
+    SNVS_HP_RTC_GetDatetime(SNVS, &rtcDate); 
+    
+    tm_new.tm_sec  = rtcDate.second; 
+    tm_new.tm_min  = rtcDate.minute; 
+    tm_new.tm_hour = rtcDate.hour;
+    
+    tm_new.tm_mday = rtcDate.day; 
+    tm_new.tm_mon  = rtcDate.month - 1;  
+    tm_new.tm_year = rtcDate.year - 1900; 
+
+    return mktime(&tm_new);
+}
+
+static int set_timestamp(time_t timestamp)
+{
+    struct tm *p_tm;
+    snvs_hp_rtc_datetime_t rtcDate; 
+    
+    p_tm = localtime(&timestamp);
+    
+    rtcDate.second = p_tm->tm_sec ; 
+    rtcDate.minute = p_tm->tm_min ; 
+    rtcDate.hour   = p_tm->tm_hour; 
+
+    rtcDate.day    = p_tm->tm_mday; 
+    rtcDate.month  = p_tm->tm_mon  + 1;  
+    rtcDate.year   = p_tm->tm_year + 1900; 
+    
+    SNVS_HP_RTC_SetDatetime(SNVS, &rtcDate); 
+    
+    return RT_EOK;
+}
+
+/* Çý¶¯½Ó¿Ú */
+static rt_err_t rt1052_hp_rtc_init(rt_device_t dev)
+{
+    snvs_hp_rtc_config_t snvsRtcConfig;
+    
+    SNVS_HP_RTC_GetDefaultConfig(&snvsRtcConfig);
+    SNVS_HP_RTC_Init(SNVS, &snvsRtcConfig);
+    
+    SNVS_HP_RTC_StartTimer(SNVS); 
+    
+    return RT_EOK; 
+}
+
+static rt_err_t rt1052_hp_rtc_open(rt_device_t dev, rt_uint16_t oflag)
+{
+    return RT_EOK; 
+}
+
+static rt_err_t rt1052_hp_rtc_close(rt_device_t dev) 
+{
+    return RT_EOK; 
+} 
+
+static rt_size_t rt1052_hp_rtc_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
+{
+    return 0; 
+}
+
+static rt_size_t rt1052_hp_rtc_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
+{
+    return 0; 
+}
+
+static rt_err_t rt1052_hp_rtc_control(rt_device_t dev, int cmd, void *args)
+{
+    RT_ASSERT(dev != RT_NULL);
+    
+    switch(cmd)
+    {
+        case RT_DEVICE_CTRL_RTC_GET_TIME: 
+        {
+            *(uint32_t *)args = get_timestamp(); 
+        }
+        break;
+            
+        case RT_DEVICE_CTRL_RTC_SET_TIME: 
+        {
+            set_timestamp(*(time_t *)args); 
+        }
+        break;
+            
+        /* ÎÞЧ²ÎÊý */
+        default:
+            return RT_EINVAL; 
+    }
+    
+    return RT_EOK; 
+}
+
+static struct rt_device device = 
+{
+    .type    = RT_Device_Class_RTC, 
+    .init    = rt1052_hp_rtc_init, 
+    .open    = rt1052_hp_rtc_open, 
+    .close   = rt1052_hp_rtc_close, 
+    .read    = rt1052_hp_rtc_read,
+    .write   = rt1052_hp_rtc_write,
+    .control = rt1052_hp_rtc_control, 
+};
+
+int rt_hw_hp_rtc_init(void)
+{
+    rt_err_t ret = RT_EOK;
+    
+    ret = rt_device_register(&device, "rtc", RT_DEVICE_FLAG_RDWR); 
+    if(ret != RT_EOK)
+    {
+        return ret; 
+    }
+    
+    rt_device_open(&device, RT_DEVICE_OFLAG_RDWR); 
+    
+    return RT_EOK; 
+}
+INIT_DEVICE_EXPORT(rt_hw_hp_rtc_init); 
+
+#endif /*RT_USING_RTC */

+ 23 - 0
bsp/imxrt1052-evk/drivers/drv_hp_rtc.h

@@ -0,0 +1,23 @@
+/*
+ * File      : drv_hp_rtc.h
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006-2013, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2018-03-15     Liuguang     the first version. 
+ */
+ 
+#ifndef __DRV_RTC_H__
+#define __DRV_RTC_H__
+
+#include <rtthread.h> 
+#include <rtdevice.h> 
+
+int rt_hw_hp_rtc_init(void);
+
+#endif

+ 2 - 2
bsp/imxrt1052-evk/drivers/usart.c

@@ -18,7 +18,7 @@
 #include "fsl_lpuart.h"
 #include "fsl_iomuxc.h"
 
-#ifdef RT_USING_UART
+#ifdef RT_USING_SERIAL
 
 #if !defined(RT_USING_UART0) && !defined(RT_USING_UART1) && \
     !defined(RT_USING_UART2) && !defined(RT_USING_UART3) && \
@@ -380,4 +380,4 @@ int imxrt_hw_usart_init(void)
 }
 INIT_BOARD_EXPORT(imxrt_hw_usart_init);
 
-#endif /*RT_USING_UART*/
+#endif /*RT_USING_SERIAL */

+ 1 - 1
bsp/imxrt1052-evk/drivers/usart.h

@@ -9,7 +9,7 @@
  *
  * Change Logs:
  * Date           Author       Notes
- * 2013-11-15     bright       the first version
+ * 2017-10-10     Tanek        the first version
  */
 
 #ifndef __USART_H__

+ 6 - 13
bsp/imxrt1052-evk/project.uvoptx

@@ -73,7 +73,7 @@
         <LExpSel>0</LExpSel>
       </OPTXL>
       <OPTFL>
-        <tvExp>0</tvExp>
+        <tvExp>1</tvExp>
         <tvExpOptDlg>0</tvExpOptDlg>
         <IsCurrentTarget>1</IsCurrentTarget>
       </OPTFL>
@@ -101,9 +101,7 @@
         <sRunDeb>0</sRunDeb>
         <sLrtime>0</sLrtime>
         <bEvRecOn>1</bEvRecOn>
-        <bSchkAxf>0</bSchkAxf>
-        <bTchkAxf>0</bTchkAxf>
-        <nTsel>3</nTsel>
+        <nTsel>2</nTsel>
         <sDll></sDll>
         <sDllPa></sDllPa>
         <sDlgDll></sDlgDll>
@@ -166,16 +164,11 @@
       <LintExecutable></LintExecutable>
       <LintConfigFile></LintConfigFile>
       <bLintAuto>0</bLintAuto>
+      <Lin2Executable></Lin2Executable>
+      <Lin2ConfigFile></Lin2ConfigFile>
+      <bLin2Auto>0</bLin2Auto>
       <bAutoGenD>0</bAutoGenD>
-      <LntExFlags>0</LntExFlags>
-      <pMisraName></pMisraName>
-      <pszMrule></pszMrule>
-      <pSingCmds></pSingCmds>
-      <pMultCmds></pMultCmds>
-      <pMisraNamep></pMisraNamep>
-      <pszMrulep></pszMrulep>
-      <pSingCmdsp></pSingCmdsp>
-      <pMultCmdsp></pMultCmdsp>
+      <bAuto2GenD>0</bAuto2GenD>
     </TargetOption>
   </Target>
 

+ 16 - 4
bsp/imxrt1052-evk/project.uvprojx

@@ -8,13 +8,11 @@
       <ToolsetNumber>0x4</ToolsetNumber>
       <ToolsetName>ARM-ADS</ToolsetName>
       <pCCUsed>5060528::V5.06 update 5 (build 528)::ARMCC</pCCUsed>
-      <uAC6>0</uAC6>
       <TargetOption>
         <TargetCommonOption>
           <Device>MIMXRT1052:M7</Device>
           <Vendor>NXP</Vendor>
-          <PackID>NXP.iMXRT_DFP.1.0.2</PackID>
-          <PackURL>http://mcuxpresso.nxp.com/cmsis_pack/repo/</PackURL>
+          <PackID>NXP.iMXRT_DFP.1.0.1</PackID>
           <Cpu>IRAM(0x20000000,0x00060000) IRAM2(0x00000000,0x00020000) CPUTYPE("Cortex-M7") FPU3(SFPU) CLOCK(12000000) ELITTLE</Cpu>
           <FlashUtilSpec />
           <StartupFile />
@@ -333,7 +331,7 @@
               <MiscControls>--library_interface=armcc --library_type=standardlib --diag_suppress=66,1296,186</MiscControls>
               <Define>SKIP_SYSCLK_INIT, CPU_MIMXRT1052DVL6A, FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL=1, EVK_MCIMXRM, FSL_FEATURE_PHYKSZ8081_USE_RMII50M_MODE, RT_USING_ARM_LIBC</Define>
               <Undefine />
-              <IncludePath>applications;.;drivers;Libraries;Libraries\drivers;Libraries\utilities;Libraries\CMSIS\Include;..\..\include;..\..\libcpu\arm\cortex-m7;..\..\libcpu\arm\common;..\..\components\dfs\include;..\..\components\dfs\filesystems\devfs;..\..\components\dfs\filesystems\elmfat;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\finsh;..\..\components\libc\compilers\armlibc;..\..\components\net\lwip-2.0.2\src;..\..\components\net\lwip-2.0.2\src\include;..\..\components\net\lwip-2.0.2\src\include\ipv4;..\..\components\net\lwip-2.0.2\src\arch\include;..\..\components\net\lwip-2.0.2\src\include\netif;..\..\components\net\lwip-2.0.2\src\include\posix</IncludePath>
+              <IncludePath>applications;.;drivers;Libraries;Libraries\drivers;Libraries\utilities;Libraries\CMSIS\Include;..\..\include;..\..\libcpu\arm\cortex-m7;..\..\libcpu\arm\common;..\..\components\dfs\include;..\..\components\dfs\filesystems\devfs;..\..\components\dfs\filesystems\elmfat;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\finsh;..\..\components\libc\compilers\armlibc;..\..\components\net\lwip-2.0.2\src;..\..\components\net\lwip-2.0.2\src\include;..\..\components\net\lwip-2.0.2\src\include\ipv4;..\..\components\net\lwip-2.0.2\src\arch\include;..\..\components\net\lwip-2.0.2\src\include\netif;..\..\components\net\lwip-2.0.2\src\include\posix</IncludePath>
             </VariousControls>
           </Cads>
           <Aads>
@@ -442,6 +440,13 @@
               <FilePath>drivers\drv_pin.c</FilePath>
             </File>
           </Files>
+          <Files>
+            <File>
+              <FileName>drv_hp_rtc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>drivers\drv_hp_rtc.c</FilePath>
+            </File>
+          </Files>
           <Files>
             <File>
               <FileName>drv_eth.c</FileName>
@@ -1115,6 +1120,13 @@
               <FilePath>..\..\components\drivers\misc\pin.c</FilePath>
             </File>
           </Files>
+          <Files>
+            <File>
+              <FileName>rtc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\components\drivers\rtc\rtc.c</FilePath>
+            </File>
+          </Files>
           <Files>
             <File>
               <FileName>block_dev.c</FileName>

+ 4 - 2
bsp/imxrt1052-evk/rtconfig.h

@@ -121,7 +121,9 @@
 #define RT_USING_PIN
 /* RT_USING_MTD_NOR is not set */
 /* RT_USING_MTD_NAND is not set */
-/* RT_USING_RTC is not set */
+#define RT_USING_RTC
+/* RT_USING_SOFT_RTC is not set */
+/* RTC_SYNC_USING_NTP is not set */
 #define RT_USING_SDIO
 /* RT_USING_SPI is not set */
 /* RT_USING_WDT is not set */
@@ -277,7 +279,7 @@
 /* PKG_USING_HELLO is not set */
 /* PKG_USING_MULTIBUTTON is not set */
 #define SOC_IMXRT1052
-#define RT_USING_UART
 #define RT_USING_UART1
+#define RT_USING_HP_RTC
 
 #endif