Modified macro of RTC_ENABLE and RTC_DISABLE

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@403 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
gary.li.wenchao.4 2010-02-11 02:53:43 +00:00
parent 2fdf112063
commit 66b8805283
2 changed files with 17 additions and 10 deletions

View File

@ -26,7 +26,7 @@ void rt_hw_rtc_get(struct rtc_time *ti)
rt_uint8_t sec, min, hour, mday, wday, mon, year; rt_uint8_t sec, min, hour, mday, wday, mon, year;
/* enable access to RTC registers */ /* enable access to RTC registers */
RTCCON |= RTC_ENABLE; RTC_ENABLE();
/* read RTC registers */ /* read RTC registers */
do do
@ -38,10 +38,10 @@ void rt_hw_rtc_get(struct rtc_time *ti)
wday = BCDDAY; wday = BCDDAY;
mon = BCDMON; mon = BCDMON;
year = BCDYEAR; year = BCDYEAR;
} while (sec != BCDSEC); } while (sec != BCDSEC);
/* disable access to RTC registers */ /* disable access to RTC registers */
RTCCON &= ~0x01; RTC_DISABLE();
ti->tm_sec = BCD2BIN(sec & 0x7F); ti->tm_sec = BCD2BIN(sec & 0x7F);
ti->tm_min = BCD2BIN(min & 0x7F); ti->tm_min = BCD2BIN(min & 0x7F);
@ -70,7 +70,7 @@ void rt_hw_rtc_set(struct rtc_time *ti)
sec = BIN2BCD(ti->tm_sec); sec = BIN2BCD(ti->tm_sec);
/* enable access to RTC registers */ /* enable access to RTC registers */
RTCCON |= 0x01; RTC_ENABLE();
/* write RTC registers */ /* write RTC registers */
BCDSEC = sec; BCDSEC = sec;
@ -82,7 +82,7 @@ void rt_hw_rtc_set(struct rtc_time *ti)
BCDYEAR = year; BCDYEAR = year;
/* disable access to RTC registers */ /* disable access to RTC registers */
RTCCON &= ~0x01; RTC_DISABLE();
} }
/** /**
@ -97,6 +97,13 @@ void rt_hw_rtc_reset (void)
static struct rt_device rtc; static struct rt_device rtc;
static rt_err_t rt_rtc_open(rt_device_t dev, rt_uint16_t oflag) static rt_err_t rt_rtc_open(rt_device_t dev, rt_uint16_t oflag)
{ {
RTC_ENABLE();
return RT_EOK;
}
static rt_err_t rt_rtc_close(rt_device_t dev)
{
RTC_DISABLE();
return RT_EOK; return RT_EOK;
} }
@ -134,7 +141,7 @@ void rt_hw_rtc_init(void)
/* register rtc device */ /* register rtc device */
rtc.init = RT_NULL; rtc.init = RT_NULL;
rtc.open = rt_rtc_open; rtc.open = rt_rtc_open;
rtc.close = RT_NULL; rtc.close = rt_rtc_close;
rtc.read = rt_rtc_read; rtc.read = rt_rtc_read;
rtc.write = RT_NULL; rtc.write = RT_NULL;
rtc.control = rt_rtc_control; rtc.control = rt_rtc_control;
@ -170,7 +177,7 @@ time_t time(time_t* t)
#include <finsh.h> #include <finsh.h>
void set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day) void set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
{ {
struct tm ti; struct rtc_time ti;
rt_device_t device; rt_device_t device;
device = rt_device_find("rtc"); device = rt_device_find("rtc");
@ -187,7 +194,7 @@ FINSH_FUNCTION_EXPORT(set_date, set date(year, month, day))
void set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second) void set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
{ {
struct tm ti; struct rtc_time ti;
rt_device_t device; rt_device_t device;
device = rt_device_find("rtc"); device = rt_device_find("rtc");

View File

@ -8,8 +8,8 @@
#define RTC_DEBUG #define RTC_DEBUG
#define RTC_ENABLE 0x01 #define RTC_ENABLE() (RTCCON |= 0x01) //RTC read and write enable
#define RTC_DISABLE 0x02 #define RTC_DISABLE() (RTCCON &= ~0x01) //RTC read and write disable
#define BCD2BIN(n) (((((n) >> 4) & 0x0F) * 10) + ((n) & 0x0F)) #define BCD2BIN(n) (((((n) >> 4) & 0x0F) * 10) + ((n) & 0x0F))
#define BIN2BCD(n) ((((n) / 10) << 4) | ((n) % 10)) #define BIN2BCD(n) ((((n) / 10) << 4) | ((n) % 10))