diff --git a/src/clock.c b/src/clock.c index 0b91dbcfc6..4f785dd5b9 100644 --- a/src/clock.c +++ b/src/clock.c @@ -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 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(); diff --git a/src/device.c b/src/device.c index 818f4e0445..6f709e38c0 100644 --- a/src/device.c +++ b/src/device.c @@ -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)) diff --git a/src/irq.c b/src/irq.c index 3edde2f7bf..4effde32a0 100644 --- a/src/irq.c +++ b/src/irq.c @@ -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 diff --git a/src/kservice.c b/src/kservice.c index 243d00cdfc..9d97323950 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -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); }