summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqiuyiuestc <[email protected]>2010-01-10 15:15:27 +0000
committerqiuyiuestc <[email protected]>2010-01-10 15:15:27 +0000
commit6c267dc5cdfd26ea3520326ddc418eccdd840892 (patch)
tree2ccc2a4816e2e8a2a0c501d2b83267b587e22813
parent25220a4a32ae3dca57f7a30690ec5b53ae301d73 (diff)
update rtc driver
add webserver support git-svn-id: https://rt-thread.googlecode.com/svn/trunk@295 bbd45198-f89e-11dd-88c7-29a3b14d5316
-rw-r--r--bsp/mini2440/SConstruct3
-rw-r--r--bsp/mini2440/rtconfig.h9
-rw-r--r--bsp/mini2440/rtconfig.py4
-rw-r--r--bsp/mini2440/startup.c4
-rw-r--r--bsp/stm3210/rtconfig.py8
-rw-r--r--finsh/finsh.h6
-rw-r--r--libcpu/arm/s3c24x0/rtc.c256
-rw-r--r--net/lwip/src/lwipopts.h6
8 files changed, 189 insertions, 107 deletions
diff --git a/bsp/mini2440/SConstruct b/bsp/mini2440/SConstruct
index 783a9f8a28..9100d80aca 100644
--- a/bsp/mini2440/SConstruct
+++ b/bsp/mini2440/SConstruct
@@ -35,6 +35,9 @@ if rtconfig.RT_USING_LWIP:
objs = objs + SConscript(RTT_ROOT + '/net/lwip/SConscript', variant_dir='build/net/lwip', duplicate=0)
objs = objs + SConscript(RTT_ROOT + '/net/apps/SConscript', variant_dir='build/net/apps', duplicate=0)
+if rtconfig.RT_USING_WEBSERVER:
+ objs = objs + SConscript(RTT_ROOT + '/net/webserver/SConscript', variant_dir='build/net/webserver', duplicate=0)
+
if rtconfig.RT_USING_RTGUI:
objs = objs + SConscript(RTT_ROOT + '/rtgui/SConscript', variant_dir='build/rtgui', duplicate=0)
diff --git a/bsp/mini2440/rtconfig.h b/bsp/mini2440/rtconfig.h
index 116852d2b3..1f6a77cbb9 100644
--- a/bsp/mini2440/rtconfig.h
+++ b/bsp/mini2440/rtconfig.h
@@ -90,14 +90,14 @@
/* SECTION: Device filesystem support */
/* using DFS support */
-/* #define RT_USING_DFS */
+#define RT_USING_DFS
#define RT_USING_DFS_EFSL
#define RT_USING_DFS_YAFFS2
#define RT_USING_WORKDIR
/* the max number of mounted filesystem */
-#define DFS_FILESYSTEMS_MAX 2
+#define DFS_FILESYSTEMS_MAX 2
/* the max number of opened files */
#define DFS_FD_MAX 16
/* the max number of cached sector */
@@ -127,7 +127,10 @@
#define RT_LWIP_TCP_PCB_NUM 5
/* TCP sender buffer space */
-#define RT_LWIP_TCP_SND_BUF 10240
+#define RT_LWIP_TCP_SND_BUF 1024*10
+
+/* TCP receive window. */
+#define RT_LWIP_TCP_WND 1024
/* Enable SNMP protocol */
/* #define RT_LWIP_SNMP */
diff --git a/bsp/mini2440/rtconfig.py b/bsp/mini2440/rtconfig.py
index 39fcbedbdb..6cc74ea8da 100644
--- a/bsp/mini2440/rtconfig.py
+++ b/bsp/mini2440/rtconfig.py
@@ -11,6 +11,7 @@ RT_USING_DFS_YAFFS2 = False
# lwip options
RT_USING_LWIP = True
+RT_USING_WEBSERVER = False
# rtgui options
RT_USING_RTGUI = True
@@ -77,6 +78,9 @@ elif PLATFORM == 'armcc':
EXEC_PATH += '/arm/bin40/'
+ if RT_USING_WEBSERVER:
+ CFLAGS += ' -DWEBS -DUEMF -DRTT -D__NO_FCNTL=1'
+
if BUILD == 'debug':
CFLAGS += ' -g -O0'
AFLAGS += ' -g'
diff --git a/bsp/mini2440/startup.c b/bsp/mini2440/startup.c
index 0caeb12aa7..852e5f56b6 100644
--- a/bsp/mini2440/startup.c
+++ b/bsp/mini2440/startup.c
@@ -25,6 +25,7 @@
extern void rt_hw_interrupt_init(void);
extern void rt_hw_board_init(void);
+extern void rt_hw_rtc_init(void);
extern void rt_serial_init(void);
extern void rt_system_timer_init(void);
extern void rt_system_scheduler_init(void);
@@ -102,6 +103,9 @@ void rtthread_startup(void)
rt_hw_sdcard_init();
#endif
+ /* rtc init */
+ rt_hw_rtc_init();
+
/*init all registed devices */
rt_device_init_all();
#endif
diff --git a/bsp/stm3210/rtconfig.py b/bsp/stm3210/rtconfig.py
index 725a814400..5e76672df7 100644
--- a/bsp/stm3210/rtconfig.py
+++ b/bsp/stm3210/rtconfig.py
@@ -17,10 +17,10 @@ RT_USING_RTGUI = False
# toolchains options
ARCH='arm'
CPU='stm32'
-#PLATFORM = 'gcc'
-#EXEC_PATH = 'd:/codesourcery/bin'
-PLATFORM = 'armcc'
-EXEC_PATH = 'C:/Keil'
+PLATFORM = 'gcc'
+EXEC_PATH = 'E:/Program Files/CodeSourcery/Sourcery G++ Lite/bin'
+#PLATFORM = 'armcc'
+#EXEC_PATH = 'C:/Keil'
#PLATFORM = 'iar'
#EXEC_PATH = 'E:/Program Files/IAR Systems/Embedded Workbench 5.4/'
BUILD = 'debug'
diff --git a/finsh/finsh.h b/finsh/finsh.h
index 1eb0310239..d97254bf9a 100644
--- a/finsh/finsh.h
+++ b/finsh/finsh.h
@@ -62,15 +62,15 @@ typedef unsigned int size_t;
#define strlen rt_strlen
#define strncpy rt_strncpy
#define strncmp rt_strncmp
-#else
-#include <string.h>
-#endif
int strcmp (const char *s1, const char *s2);
char *strdup(const char *s);
int isalpha( int ch );
int atoi(const char* s);
+#else
+#include <string.h>
+#endif
#endif
#define FINSH_VERSION_MAJOR 0
diff --git a/libcpu/arm/s3c24x0/rtc.c b/libcpu/arm/s3c24x0/rtc.c
index b49292ce7c..a9b8d3bac2 100644
--- a/libcpu/arm/s3c24x0/rtc.c
+++ b/libcpu/arm/s3c24x0/rtc.c
@@ -12,133 +12,78 @@
* 2009-04-26 yi.qiu first version
*/
-#include "rtc.h"
+#include <rtthread.h>
+#include <time.h>
+#include <s3c24x0.h>
-/**
- * This function access to rtc
- */
-rt_inline void rt_hw_rtc_access(int a)
-{
- switch (a)
- {
- case RTC_ENABLE:
- RTCCON |= 0x01;
- break;
-
- case RTC_DISABLE:
- RTCCON &= ~0x01;
- break;
- }
-}
-
-rt_inline rt_uint32_t BCD2BIN(rt_uint8_t n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-rt_inline rt_uint8_t BIN2BCD(rt_uint32_t n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
+#define BCD2BIN(n) (((((n) >> 4) & 0x0F) * 10) + ((n) & 0x0F))
+#define BIN2BCD(n) ((((n) / 10) << 4) | ((n) % 10))
/**
* This function get rtc time
*/
-void rt_hw_rtc_get (struct rtc_time *tmp)
+void rt_hw_rtc_get(struct tm *ti)
{
rt_uint8_t sec, min, hour, mday, wday, mon, year;
- rt_uint8_t a_sec,a_min, a_hour, a_date, a_mon, a_year, a_armed;
/* enable access to RTC registers */
- rt_hw_rtc_access(RTC_ENABLE);
+ RTCCON |= 0x01;
/* read RTC registers */
do
{
- sec = BCDSEC;
- min = BCDMIN;
- hour = BCDHOUR;
- mday = BCDDATE;
- wday = BCDDAY;
- mon = BCDMON;
- year = BCDYEAR;
+ sec = BCDSEC;
+ min = BCDMIN;
+ hour = BCDHOUR;
+ mday = BCDDATE;
+ wday = BCDDAY;
+ mon = BCDMON;
+ year = BCDYEAR;
} while (sec != BCDSEC);
- /* read ALARM registers */
- a_sec = ALMSEC;
- a_min = ALMMIN;
- a_hour = ALMHOUR;
- a_date = ALMDATE;
- a_mon = ALMMON;
- a_year = ALMYEAR;
- a_armed = RTCALM;
-
/* disable access to RTC registers */
- rt_hw_rtc_access(RTC_DISABLE);
-
-#ifdef RTC_DEBUG
- rt_kprintf ( "Get RTC year: %02x mon/cent: %02x mday: %02x wday: %02x "
- "hr: %02x min: %02x sec: %02x\n",
- year, mon, mday, wday,
- hour, min, sec);
- rt_kprintf ( "Alarms: %02x: year: %02x month: %02x date: %02x hour: %02x min: %02x sec: %02x\n",
- a_armed,
- a_year, a_mon, a_date,
- a_hour, a_min, a_sec);
-#endif
+ RTCCON &= ~0x01;
- tmp->tm_sec = BCD2BIN(sec & 0x7F);
- tmp->tm_min = BCD2BIN(min & 0x7F);
- tmp->tm_hour = BCD2BIN(hour & 0x3F);
- tmp->tm_mday = BCD2BIN(mday & 0x3F);
- tmp->tm_mon = BCD2BIN(mon & 0x1F);
- tmp->tm_year = BCD2BIN(year);
- tmp->tm_wday = BCD2BIN(wday & 0x07);
- if(tmp->tm_year < 70) tmp->tm_year += 2000;
- else tmp->tm_year += 1900;
- tmp->tm_yday = 0;
- tmp->tm_isdst = 0;
-#ifdef RTC_DEBUG
- rt_kprintf ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
- tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
-#endif
+ ti->tm_sec = BCD2BIN(sec & 0x7F);
+ ti->tm_min = BCD2BIN(min & 0x7F);
+ ti->tm_hour = BCD2BIN(hour & 0x3F);
+ ti->tm_mday = BCD2BIN(mday & 0x3F);
+ ti->tm_mon = BCD2BIN(mon & 0x1F);
+ ti->tm_year = BCD2BIN(year);
+ ti->tm_wday = BCD2BIN(wday & 0x07);
+ ti->tm_yday = 0;
+ ti->tm_isdst = 0;
}
/**
* This function set rtc time
*/
-void rt_hw_rtc_set (struct rtc_time *tmp)
+void rt_hw_rtc_set(struct tm *ti)
{
rt_uint8_t sec, min, hour, mday, wday, mon, year;
-#ifdef RTC_DEBUG
- rt_kprintf ( "Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
- tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
- tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
-#endif
- year = BIN2BCD(tmp->tm_year % 100);
- mon = BIN2BCD(tmp->tm_mon);
- wday = BIN2BCD(tmp->tm_wday);
- mday = BIN2BCD(tmp->tm_mday);
- hour = BIN2BCD(tmp->tm_hour);
- min = BIN2BCD(tmp->tm_min);
- sec = BIN2BCD(tmp->tm_sec);
+ year = BIN2BCD(ti->tm_year);
+ mon = BIN2BCD(ti->tm_mon);
+ wday = BIN2BCD(ti->tm_wday);
+ mday = BIN2BCD(ti->tm_mday);
+ hour = BIN2BCD(ti->tm_hour);
+ min = BIN2BCD(ti->tm_min);
+ sec = BIN2BCD(ti->tm_sec);
/* enable access to RTC registers */
- rt_hw_rtc_access(RTC_ENABLE);
+ RTCCON |= 0x01;
/* write RTC registers */
- BCDSEC = sec;
- BCDMIN = min;
- BCDHOUR = hour;
- BCDDATE = mday;
- BCDDAY = wday;
- BCDMON = mon;
- BCDYEAR = year;
+ BCDSEC = sec;
+ BCDMIN = min;
+ BCDHOUR = hour;
+ BCDDATE = mday;
+ BCDDAY = wday;
+ BCDMON = mon;
+ BCDYEAR = year;
/* disable access to RTC registers */
- rt_hw_rtc_access(RTC_DISABLE);
+ RTCCON &= ~0x01;
}
/**
@@ -150,3 +95,122 @@ void rt_hw_rtc_reset (void)
RTCCON &= ~(0x08|0x01);
}
+static struct rt_device rtc;
+static rt_err_t rt_rtc_open(rt_device_t dev, rt_uint16_t oflag)
+{
+ return RT_EOK;
+}
+
+static rt_size_t rt_rtc_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
+{
+ return 0;
+}
+
+static rt_err_t rt_rtc_control(rt_device_t dev, rt_uint8_t cmd, void *args)
+{
+ struct tm* ti;
+ RT_ASSERT(dev != RT_NULL);
+
+ ti = (struct tm*)args;
+ switch (cmd)
+ {
+ case RT_DEVICE_CTRL_RTC_GET_TIME:
+ /* read device */
+ rt_hw_rtc_get(ti);
+ break;
+
+ case RT_DEVICE_CTRL_RTC_SET_TIME:
+ /* write device */
+ rt_hw_rtc_set(ti);
+ break;
+ }
+
+ return RT_EOK;
+}
+
+void rt_hw_rtc_init(void)
+{
+ rtc.type = RT_Device_Class_RTC;
+
+ /* register rtc device */
+ rtc.init = RT_NULL;
+ rtc.open = rt_rtc_open;
+ rtc.close = RT_NULL;
+ rtc.read = rt_rtc_read;
+ rtc.write = RT_NULL;
+ rtc.control = rt_rtc_control;
+
+ /* no private */
+ rtc.private = RT_NULL;
+
+ rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);
+
+ return;
+}
+
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+time_t time(time_t* t)
+{
+ rt_device_t device;
+ struct tm ti;
+ time_t time;
+
+ device = rt_device_find("rtc");
+ if (device != RT_NULL)
+ {
+ rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &ti);
+ if (t != RT_NULL)
+ {
+ time = mktime(&ti);
+ *t = time;
+ }
+ }
+
+ return time;
+}
+
+void set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
+{
+ struct tm ti;
+ rt_device_t device;
+
+ device = rt_device_find("rtc");
+ if (device != RT_NULL)
+ {
+ rt_rtc_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &ti);
+ ti.tm_year = year - 1900;
+ ti.tm_mon = month - 1;
+ ti.tm_mday = day;
+ rt_rtc_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &ti);
+ }
+}
+FINSH_FUNCTION_EXPORT(set_date, set date)
+
+void set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
+{
+ struct tm ti;
+ rt_device_t device;
+
+ device = rt_device_find("rtc");
+ if (device != RT_NULL)
+ {
+ rt_rtc_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &ti);
+ ti.tm_hour = hour;
+ ti.tm_min = minute;
+ ti.tm_sec = second;
+ rt_rtc_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &ti);
+ }
+}
+FINSH_FUNCTION_EXPORT(set_time, set second)
+
+void list_date()
+{
+ time_t now;
+
+ time(&now);
+ rt_kprintf("%s\n", ctime(&now));
+}
+FINSH_FUNCTION_EXPORT(list_date, set date)
+#endif
+
diff --git a/net/lwip/src/lwipopts.h b/net/lwip/src/lwipopts.h
index f002adc214..f5cc7a2e56 100644
--- a/net/lwip/src/lwipopts.h
+++ b/net/lwip/src/lwipopts.h
@@ -189,7 +189,11 @@
#define TCP_SNDLOWAT (TCP_SND_BUF/2)
/* TCP receive window. */
-#define TCP_WND 1500
+#ifdef RT_LWIP_TCP_WND
+#define TCP_WND RT_LWIP_TCP_WND
+#else
+#define TCP_WND 1500
+#endif
/* Maximum number of retransmissions of data segments. */
#define TCP_MAXRTX 12