|
@@ -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);
|
|
|
|
- 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);
|
|
va_end(args);
|
|
}
|
|
}
|