Browse Source

update rtc driver.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1808 bbd45198-f89e-11dd-88c7-29a3b14d5316
wuyangyong 13 years ago
parent
commit
88f891066d
2 changed files with 32 additions and 9 deletions
  1. 18 6
      bsp/stm32f10x/rtc.c
  2. 14 3
      bsp/stm32f20x/rtc.c

+ 18 - 6
bsp/stm32f10x/rtc.c

@@ -9,11 +9,13 @@
  *
  * Change Logs:
  * Date           Author       Notes
- * 2009-01-05     Bernard      the first version
+ * 2009-01-05     Bernard      the first version.
+ * 2011-11-26     aozima       implementation time.
  */
 
 #include <rtthread.h>
 #include <stm32f10x.h>
+#include "rtc.h"
 
 static struct rt_device rtc;
 static rt_err_t rt_rtc_open(rt_device_t dev, rt_uint16_t oflag)
@@ -154,16 +156,23 @@ void rt_hw_rtc_init(void)
 
     rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);
 
+#ifdef RT_USING_FINSH
+	list_date();
+#endif
+
     return;
 }
 
-#ifdef RT_USING_FINSH
-#include <finsh.h>
 #include <time.h>
+#if defined (__IAR_SYSTEMS_ICC__) &&  (__VER__) >= 6020000   /* for IAR 6.2 later Compiler */
+#pragma module_name = "?time"
+time_t (__time32)(time_t *t)                                 /* Only supports 32-bit timestamp */
+#else
 time_t time(time_t* t)
+#endif
 {
     rt_device_t device;
-    time_t time;
+    time_t time=0;
 
     device = rt_device_find("rtc");
     if (device != RT_NULL)
@@ -175,6 +184,9 @@ time_t time(time_t* t)
     return time;
 }
 
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+
 void set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
 {
     time_t now;
@@ -189,7 +201,7 @@ void set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
     if (ti != RT_NULL)
     {
         ti->tm_year = year - 1900;
-        ti->tm_mon 	= month - 1; /* ti->tm_mon 	= month; */
+        ti->tm_mon 	= month - 1; /* ti->tm_mon 	= month; 0~11 */
         ti->tm_mday = day;
     }
 
@@ -230,7 +242,7 @@ void set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
 }
 FINSH_FUNCTION_EXPORT(set_time, set time. e.g: set_time(23,59,59))
 
-void list_date()
+void list_date(void)
 {
     time_t now;
 

+ 14 - 3
bsp/stm32f20x/rtc.c

@@ -10,6 +10,7 @@
  * Change Logs:
  * Date           Author       Notes
  * 2009-01-05     Bernard      the first version
+ * 2011-11-26     aozima       implementation time.
  */
 
 #include <rtthread.h>
@@ -249,16 +250,23 @@ void rt_hw_rtc_init(void)
 
     rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);
 
+#ifdef RT_USING_FINSH
+	list_date();
+#endif
+
     return;
 }
 
-#ifdef RT_USING_FINSH
-#include <finsh.h>
 #include <time.h>
+#if defined (__IAR_SYSTEMS_ICC__) &&  (__VER__) >= 6020000   /* for IAR 6.2 later Compiler */
+#pragma module_name = "?time"
+time_t (__time32)(time_t *t)                                 /* Only supports 32-bit timestamp */
+#else
 time_t time(time_t* t)
+#endif
 {
     rt_device_t device;
-    time_t time;
+    time_t time=0;
 
     device = rt_device_find("rtc");
     if (device != RT_NULL)
@@ -270,6 +278,9 @@ time_t time(time_t* t)
     return time;
 }
 
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+
 void set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
 {
     time_t now;