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
This commit is contained in:
bernard.xiong 2010-03-08 23:09:40 +00:00
parent 1c9c3bf175
commit 5e82a9a022
4 changed files with 82 additions and 19 deletions

View File

@ -11,13 +11,13 @@
* Date Author Notes * Date Author Notes
* 2006-03-12 Bernard first version * 2006-03-12 Bernard first version
* 2006-05-27 Bernard add support for same priority thread schedule * 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> #include <rtthread.h>
static rt_tick_t rt_tick; static rt_tick_t rt_tick;
static rt_time_t rt_passed_second;
extern void rt_timer_check(void); extern void rt_timer_check(void);
@ -29,7 +29,6 @@ extern void rt_timer_check(void);
void rt_system_tick_init() void rt_system_tick_init()
{ {
rt_tick = 0; rt_tick = 0;
rt_passed_second = 0;
} }
/** /**
@ -60,11 +59,6 @@ void rt_tick_increase()
/* increase the global tick */ /* increase the global tick */
++ rt_tick; ++ rt_tick;
if (rt_tick % RT_TICK_PER_SECOND == 0)
{
++rt_passed_second;
}
/* check timer */ /* check timer */
rt_timer_check(); rt_timer_check();

View File

@ -81,12 +81,12 @@ rt_err_t rt_device_init_all()
result = init(device); result = init(device);
if (result != RT_EOK) 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); device->parent.name, result);
} }
else else
{ {
device->flag |= RT_DEVICE_FLAG_ACTIVATED; 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; 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 */ /* device is a standalone device and opened */
if ((dev->flag & RT_DEVICE_FLAG_STANDALONE) && if ((dev->flag & RT_DEVICE_FLAG_STANDALONE) &&
(dev->open_flag & RT_DEVICE_OFLAG_OPEN)) (dev->open_flag & RT_DEVICE_OFLAG_OPEN))

View File

@ -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 * This function will be invoked by BSP, when enter interrupt service routine

View File

@ -351,7 +351,7 @@ char *rt_strlcpy(char *dest, const char *src, rt_ubase_t n)
while(n--) while(n--)
*tmp++ = *s++; *tmp++ = *s++;
*tmp = '\0'; *tmp = '\0';
return dest; return dest;
} }
@ -427,8 +427,6 @@ void rt_show_version()
rt_kprintf(" 2006 - 2009 Copyright by rt-thread team\n"); rt_kprintf(" 2006 - 2009 Copyright by rt-thread team\n");
} }
static char rt_log_buf[RT_CONSOLEBUF_SIZE]; /* Message log buffer */
/* private function */ /* private function */
#define isdigit(c) ((unsigned)((c) - '0') < 10) #define isdigit(c) ((unsigned)((c) - '0') < 10)
@ -904,7 +902,52 @@ rt_int32_t rt_sprintf(char *buf ,const char *format,...)
return n; 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 * 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, ...) void rt_kprintf(const char *fmt, ...)
{ {
va_list args; va_list args;
rt_size_t length;
static char rt_log_buf[RT_CONSOLEBUF_SIZE];
va_start(args, fmt); va_start(args, fmt);
vsnprintf(rt_log_buf, sizeof(rt_log_buf), fmt, args); length = vsnprintf(rt_log_buf, sizeof(rt_log_buf), fmt, args);
rt_hw_console_output(rt_log_buf); 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); va_end(args);
} }