update rtc driver
add webserver support git-svn-id: https://rt-thread.googlecode.com/svn/trunk@295 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
25220a4a32
commit
6c267dc5cd
@ -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/lwip/SConscript', variant_dir='build/net/lwip', duplicate=0)
|
||||||
objs = objs + SConscript(RTT_ROOT + '/net/apps/SConscript', variant_dir='build/net/apps', 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:
|
if rtconfig.RT_USING_RTGUI:
|
||||||
objs = objs + SConscript(RTT_ROOT + '/rtgui/SConscript', variant_dir='build/rtgui', duplicate=0)
|
objs = objs + SConscript(RTT_ROOT + '/rtgui/SConscript', variant_dir='build/rtgui', duplicate=0)
|
||||||
|
|
||||||
|
@ -90,14 +90,14 @@
|
|||||||
|
|
||||||
/* SECTION: Device filesystem support */
|
/* SECTION: Device filesystem support */
|
||||||
/* using DFS support */
|
/* using DFS support */
|
||||||
/* #define RT_USING_DFS */
|
#define RT_USING_DFS
|
||||||
#define RT_USING_DFS_EFSL
|
#define RT_USING_DFS_EFSL
|
||||||
#define RT_USING_DFS_YAFFS2
|
#define RT_USING_DFS_YAFFS2
|
||||||
|
|
||||||
#define RT_USING_WORKDIR
|
#define RT_USING_WORKDIR
|
||||||
|
|
||||||
/* the max number of mounted filesystem */
|
/* the max number of mounted filesystem */
|
||||||
#define DFS_FILESYSTEMS_MAX 2
|
#define DFS_FILESYSTEMS_MAX 2
|
||||||
/* the max number of opened files */
|
/* the max number of opened files */
|
||||||
#define DFS_FD_MAX 16
|
#define DFS_FD_MAX 16
|
||||||
/* the max number of cached sector */
|
/* the max number of cached sector */
|
||||||
@ -127,7 +127,10 @@
|
|||||||
#define RT_LWIP_TCP_PCB_NUM 5
|
#define RT_LWIP_TCP_PCB_NUM 5
|
||||||
|
|
||||||
/* TCP sender buffer space */
|
/* 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 */
|
/* Enable SNMP protocol */
|
||||||
/* #define RT_LWIP_SNMP */
|
/* #define RT_LWIP_SNMP */
|
||||||
|
@ -11,6 +11,7 @@ RT_USING_DFS_YAFFS2 = False
|
|||||||
|
|
||||||
# lwip options
|
# lwip options
|
||||||
RT_USING_LWIP = True
|
RT_USING_LWIP = True
|
||||||
|
RT_USING_WEBSERVER = False
|
||||||
|
|
||||||
# rtgui options
|
# rtgui options
|
||||||
RT_USING_RTGUI = True
|
RT_USING_RTGUI = True
|
||||||
@ -77,6 +78,9 @@ elif PLATFORM == 'armcc':
|
|||||||
|
|
||||||
EXEC_PATH += '/arm/bin40/'
|
EXEC_PATH += '/arm/bin40/'
|
||||||
|
|
||||||
|
if RT_USING_WEBSERVER:
|
||||||
|
CFLAGS += ' -DWEBS -DUEMF -DRTT -D__NO_FCNTL=1'
|
||||||
|
|
||||||
if BUILD == 'debug':
|
if BUILD == 'debug':
|
||||||
CFLAGS += ' -g -O0'
|
CFLAGS += ' -g -O0'
|
||||||
AFLAGS += ' -g'
|
AFLAGS += ' -g'
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
extern void rt_hw_interrupt_init(void);
|
extern void rt_hw_interrupt_init(void);
|
||||||
extern void rt_hw_board_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_serial_init(void);
|
||||||
extern void rt_system_timer_init(void);
|
extern void rt_system_timer_init(void);
|
||||||
extern void rt_system_scheduler_init(void);
|
extern void rt_system_scheduler_init(void);
|
||||||
@ -102,6 +103,9 @@ void rtthread_startup(void)
|
|||||||
rt_hw_sdcard_init();
|
rt_hw_sdcard_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* rtc init */
|
||||||
|
rt_hw_rtc_init();
|
||||||
|
|
||||||
/*init all registed devices */
|
/*init all registed devices */
|
||||||
rt_device_init_all();
|
rt_device_init_all();
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,10 +17,10 @@ RT_USING_RTGUI = False
|
|||||||
# toolchains options
|
# toolchains options
|
||||||
ARCH='arm'
|
ARCH='arm'
|
||||||
CPU='stm32'
|
CPU='stm32'
|
||||||
#PLATFORM = 'gcc'
|
PLATFORM = 'gcc'
|
||||||
#EXEC_PATH = 'd:/codesourcery/bin'
|
EXEC_PATH = 'E:/Program Files/CodeSourcery/Sourcery G++ Lite/bin'
|
||||||
PLATFORM = 'armcc'
|
#PLATFORM = 'armcc'
|
||||||
EXEC_PATH = 'C:/Keil'
|
#EXEC_PATH = 'C:/Keil'
|
||||||
#PLATFORM = 'iar'
|
#PLATFORM = 'iar'
|
||||||
#EXEC_PATH = 'E:/Program Files/IAR Systems/Embedded Workbench 5.4/'
|
#EXEC_PATH = 'E:/Program Files/IAR Systems/Embedded Workbench 5.4/'
|
||||||
BUILD = 'debug'
|
BUILD = 'debug'
|
||||||
|
@ -62,15 +62,15 @@ typedef unsigned int size_t;
|
|||||||
#define strlen rt_strlen
|
#define strlen rt_strlen
|
||||||
#define strncpy rt_strncpy
|
#define strncpy rt_strncpy
|
||||||
#define strncmp rt_strncmp
|
#define strncmp rt_strncmp
|
||||||
#else
|
|
||||||
#include <string.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int strcmp (const char *s1, const char *s2);
|
int strcmp (const char *s1, const char *s2);
|
||||||
char *strdup(const char *s);
|
char *strdup(const char *s);
|
||||||
|
|
||||||
int isalpha( int ch );
|
int isalpha( int ch );
|
||||||
int atoi(const char* s);
|
int atoi(const char* s);
|
||||||
|
#else
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FINSH_VERSION_MAJOR 0
|
#define FINSH_VERSION_MAJOR 0
|
||||||
|
@ -12,133 +12,78 @@
|
|||||||
* 2009-04-26 yi.qiu first version
|
* 2009-04-26 yi.qiu first version
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rtc.h"
|
#include <rtthread.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <s3c24x0.h>
|
||||||
|
|
||||||
/**
|
#define BCD2BIN(n) (((((n) >> 4) & 0x0F) * 10) + ((n) & 0x0F))
|
||||||
* This function access to rtc
|
#define BIN2BCD(n) ((((n) / 10) << 4) | ((n) % 10))
|
||||||
*/
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function get rtc time
|
* 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 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 */
|
/* enable access to RTC registers */
|
||||||
rt_hw_rtc_access(RTC_ENABLE);
|
RTCCON |= 0x01;
|
||||||
|
|
||||||
/* read RTC registers */
|
/* read RTC registers */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
sec = BCDSEC;
|
sec = BCDSEC;
|
||||||
min = BCDMIN;
|
min = BCDMIN;
|
||||||
hour = BCDHOUR;
|
hour = BCDHOUR;
|
||||||
mday = BCDDATE;
|
mday = BCDDATE;
|
||||||
wday = BCDDAY;
|
wday = BCDDAY;
|
||||||
mon = BCDMON;
|
mon = BCDMON;
|
||||||
year = BCDYEAR;
|
year = BCDYEAR;
|
||||||
} while (sec != BCDSEC);
|
} 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 */
|
/* disable access to RTC registers */
|
||||||
rt_hw_rtc_access(RTC_DISABLE);
|
RTCCON &= ~0x01;
|
||||||
|
|
||||||
#ifdef RTC_DEBUG
|
ti->tm_sec = BCD2BIN(sec & 0x7F);
|
||||||
rt_kprintf ( "Get RTC year: %02x mon/cent: %02x mday: %02x wday: %02x "
|
ti->tm_min = BCD2BIN(min & 0x7F);
|
||||||
"hr: %02x min: %02x sec: %02x\n",
|
ti->tm_hour = BCD2BIN(hour & 0x3F);
|
||||||
year, mon, mday, wday,
|
ti->tm_mday = BCD2BIN(mday & 0x3F);
|
||||||
hour, min, sec);
|
ti->tm_mon = BCD2BIN(mon & 0x1F);
|
||||||
rt_kprintf ( "Alarms: %02x: year: %02x month: %02x date: %02x hour: %02x min: %02x sec: %02x\n",
|
ti->tm_year = BCD2BIN(year);
|
||||||
a_armed,
|
ti->tm_wday = BCD2BIN(wday & 0x07);
|
||||||
a_year, a_mon, a_date,
|
ti->tm_yday = 0;
|
||||||
a_hour, a_min, a_sec);
|
ti->tm_isdst = 0;
|
||||||
#endif
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function set rtc time
|
* 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;
|
rt_uint8_t sec, min, hour, mday, wday, mon, year;
|
||||||
|
|
||||||
#ifdef RTC_DEBUG
|
year = BIN2BCD(ti->tm_year);
|
||||||
rt_kprintf ( "Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
|
mon = BIN2BCD(ti->tm_mon);
|
||||||
tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
|
wday = BIN2BCD(ti->tm_wday);
|
||||||
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
|
mday = BIN2BCD(ti->tm_mday);
|
||||||
#endif
|
hour = BIN2BCD(ti->tm_hour);
|
||||||
year = BIN2BCD(tmp->tm_year % 100);
|
min = BIN2BCD(ti->tm_min);
|
||||||
mon = BIN2BCD(tmp->tm_mon);
|
sec = BIN2BCD(ti->tm_sec);
|
||||||
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);
|
|
||||||
|
|
||||||
/* enable access to RTC registers */
|
/* enable access to RTC registers */
|
||||||
rt_hw_rtc_access(RTC_ENABLE);
|
RTCCON |= 0x01;
|
||||||
|
|
||||||
/* write RTC registers */
|
/* write RTC registers */
|
||||||
BCDSEC = sec;
|
BCDSEC = sec;
|
||||||
BCDMIN = min;
|
BCDMIN = min;
|
||||||
BCDHOUR = hour;
|
BCDHOUR = hour;
|
||||||
BCDDATE = mday;
|
BCDDATE = mday;
|
||||||
BCDDAY = wday;
|
BCDDAY = wday;
|
||||||
BCDMON = mon;
|
BCDMON = mon;
|
||||||
BCDYEAR = year;
|
BCDYEAR = year;
|
||||||
|
|
||||||
/* disable access to RTC registers */
|
/* 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);
|
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
|
||||||
|
|
||||||
|
@ -189,7 +189,11 @@
|
|||||||
#define TCP_SNDLOWAT (TCP_SND_BUF/2)
|
#define TCP_SNDLOWAT (TCP_SND_BUF/2)
|
||||||
|
|
||||||
/* TCP receive window. */
|
/* 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. */
|
/* Maximum number of retransmissions of data segments. */
|
||||||
#define TCP_MAXRTX 12
|
#define TCP_MAXRTX 12
|
||||||
|
Loading…
x
Reference in New Issue
Block a user