提交 5e82a9a0 编写于 作者: B bernard.xiong

remove rt_passed_second in clock; init device driver when driver has been...

remove rt_passed_second in clock; init device driver when driver has been opened if it is not in activate status; change interrupt nest count to rt_uint8_t; add rt_console_set_device function in kservice.c (rt_kprintf function can use device right now)

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@464 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 1c9c3bf1
......@@ -11,13 +11,13 @@
* Date Author Notes
* 2006-03-12 Bernard first version
* 2006-05-27 Bernard add support for same priority thread schedule
* 2006-08-10 Bernard remove the last rt_schedule in rt_tick_increase
* 2006-08-10 Bernard remove the last rt_schedule in rt_tick_increase
* 2010-03-08 Bernard remove rt_passed_second
*/
#include <rtthread.h>
static rt_tick_t rt_tick;
static rt_time_t rt_passed_second;
extern void rt_timer_check(void);
......@@ -29,7 +29,6 @@ extern void rt_timer_check(void);
void rt_system_tick_init()
{
rt_tick = 0;
rt_passed_second = 0;
}
/**
......@@ -60,11 +59,6 @@ void rt_tick_increase()
/* increase the global tick */
++ rt_tick;
if (rt_tick % RT_TICK_PER_SECOND == 0)
{
++rt_passed_second;
}
/* check timer */
rt_timer_check();
......
......@@ -81,12 +81,12 @@ rt_err_t rt_device_init_all()
result = init(device);
if (result != RT_EOK)
{
rt_kprintf("To initialize device:%s failed. The error code is %d\n",
rt_kprintf("To initialize device:%s failed. The error code is %d\n",
device->parent.name, result);
}
else
{
device->flag |= RT_DEVICE_FLAG_ACTIVATED;
}
else
{
device->flag |= RT_DEVICE_FLAG_ACTIVATED;
}
}
}
......@@ -124,6 +124,22 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
result = RT_EOK;
/* if device is not initialized, initialize it. */
if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
{
result = dev->init(dev);
if (result != RT_EOK)
{
rt_kprintf("To initialize device:%s failed. The error code is %d\n",
dev->parent.name, result);
return result;
}
else
{
dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
}
}
/* device is a standalone device and opened */
if ((dev->flag & RT_DEVICE_FLAG_STANDALONE) &&
(dev->open_flag & RT_DEVICE_OFLAG_OPEN))
......
......@@ -24,7 +24,7 @@
/*@{*/
volatile rt_uint32_t rt_interrupt_nest;
volatile rt_uint8_t rt_interrupt_nest;
/**
* This function will be invoked by BSP, when enter interrupt service routine
......
......@@ -351,7 +351,7 @@ char *rt_strlcpy(char *dest, const char *src, rt_ubase_t n)
while(n--)
*tmp++ = *s++;
*tmp = '\0';
return dest;
}
......@@ -427,8 +427,6 @@ void rt_show_version()
rt_kprintf(" 2006 - 2009 Copyright by rt-thread team\n");
}
static char rt_log_buf[RT_CONSOLEBUF_SIZE]; /* Message log buffer */
/* private function */
#define isdigit(c) ((unsigned)((c) - '0') < 10)
......@@ -904,7 +902,52 @@ rt_int32_t rt_sprintf(char *buf ,const char *format,...)
return n;
}
static rt_device_t _console_device = RT_NULL;
/**
* This function will set console to a device.
* After set a device to console, all output of rt_kprintf will be
* written to this device.
*
* @param device the new console device
*
* @return the old console device
*/
rt_device_t rt_console_set_device(const char* name)
{
rt_device_t new, old;
/* save old device */
old = _console_device;
/* find new console device */
new = rt_device_find(name);
if (new != RT_NULL)
{
if (_console_device != RT_NULL)
{
/* close old console device */
rt_device_close(_console_device);
}
/* set new console device */
_console_device = new;
rt_device_open(_console_device, RT_DEVICE_OFLAG_RDWR);
}
return old;
}
#if defined(__GNUC__)
void rt_hw_console_output(const char* str) __attribute__((weak))
#elif defined(__CC_ARM)
__weak void rt_hw_console_output(const char* str)
#elif defined(__ICCARM__)
__weak void rt_hw_console_output(const char* str)
#endif
{
/* empty console output */
}
/**
* This function will print a formatted string on system console
......@@ -914,10 +957,20 @@ rt_int32_t rt_sprintf(char *buf ,const char *format,...)
void rt_kprintf(const char *fmt, ...)
{
va_list args;
rt_size_t length;
static char rt_log_buf[RT_CONSOLEBUF_SIZE];
va_start(args, fmt);
vsnprintf(rt_log_buf, sizeof(rt_log_buf), fmt, args);
rt_hw_console_output(rt_log_buf);
length = vsnprintf(rt_log_buf, sizeof(rt_log_buf), fmt, args);
if (_console_device == RT_NULL)
{
rt_hw_console_output(rt_log_buf);
}
else
{
rt_device_write(_console_device, 0, rt_log_buf, length);
}
va_end(args);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册