mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-22 15:08:52 +08:00
[kservice] optimize console_device
This commit is contained in:
parent
ebe05a91df
commit
6cad23bc31
@ -187,23 +187,15 @@ RTM_EXPORT(rt_console_get_device);
|
||||
*/
|
||||
rt_device_t rt_console_set_device(const char *name)
|
||||
{
|
||||
rt_device_t new_device, old_device;
|
||||
rt_device_t old_device = _console_device;
|
||||
rt_device_t new_device = rt_device_find(name);
|
||||
|
||||
/* save old device */
|
||||
old_device = _console_device;
|
||||
|
||||
/* find new console device */
|
||||
new_device = rt_device_find(name);
|
||||
|
||||
/* check whether it's a same device */
|
||||
if (new_device == old_device) return RT_NULL;
|
||||
|
||||
if (new_device != RT_NULL)
|
||||
if (new_device != RT_NULL && new_device != old_device)
|
||||
{
|
||||
if (_console_device != RT_NULL)
|
||||
if (old_device != RT_NULL)
|
||||
{
|
||||
/* close old console device */
|
||||
rt_device_close(_console_device);
|
||||
rt_device_close(old_device);
|
||||
}
|
||||
|
||||
/* set new console device */
|
||||
@ -319,20 +311,23 @@ static void _console_release(void)
|
||||
*/
|
||||
static void _kputs(const char *str, long len)
|
||||
{
|
||||
RT_UNUSED(len);
|
||||
#ifdef RT_USING_DEVICE
|
||||
rt_device_t console_device = rt_console_get_device();
|
||||
#endif /* RT_USING_DEVICE */
|
||||
|
||||
CONSOLE_TAKE;
|
||||
|
||||
#ifdef RT_USING_DEVICE
|
||||
if (_console_device == RT_NULL)
|
||||
if (console_device == RT_NULL)
|
||||
{
|
||||
rt_hw_console_output(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_device_write(_console_device, 0, str, len);
|
||||
rt_device_write(console_device, 0, str, len);
|
||||
}
|
||||
#else
|
||||
RT_UNUSED(len);
|
||||
rt_hw_console_output(str);
|
||||
#endif /* RT_USING_DEVICE */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user