@@ -187,23 +187,15 @@ RTM_EXPORT(rt_console_get_device);
187
187
*/
188
188
rt_device_t rt_console_set_device (const char * name )
189
189
{
190
- rt_device_t new_device , old_device ;
190
+ rt_device_t old_device = _console_device ;
191
+ rt_device_t new_device = rt_device_find (name );
191
192
192
- /* save old device */
193
- old_device = _console_device ;
194
-
195
- /* find new console device */
196
- new_device = rt_device_find (name );
197
-
198
- /* check whether it's a same device */
199
- if (new_device == old_device ) return RT_NULL ;
200
-
201
- if (new_device != RT_NULL )
193
+ if (new_device != RT_NULL && new_device != old_device )
202
194
{
203
- if (_console_device != RT_NULL )
195
+ if (old_device != RT_NULL )
204
196
{
205
197
/* close old console device */
206
- rt_device_close (_console_device );
198
+ rt_device_close (old_device );
207
199
}
208
200
209
201
/* set new console device */
@@ -319,20 +311,23 @@ static void _console_release(void)
319
311
*/
320
312
static void _kputs (const char * str , long len )
321
313
{
322
- RT_UNUSED (len );
314
+ #ifdef RT_USING_DEVICE
315
+ rt_device_t console_device = rt_console_get_device ();
316
+ #endif /* RT_USING_DEVICE */
323
317
324
318
CONSOLE_TAKE ;
325
319
326
320
#ifdef RT_USING_DEVICE
327
- if (_console_device == RT_NULL )
321
+ if (console_device == RT_NULL )
328
322
{
329
323
rt_hw_console_output (str );
330
324
}
331
325
else
332
326
{
333
- rt_device_write (_console_device , 0 , str , len );
327
+ rt_device_write (console_device , 0 , str , len );
334
328
}
335
329
#else
330
+ RT_UNUSED (len );
336
331
rt_hw_console_output (str );
337
332
#endif /* RT_USING_DEVICE */
338
333
0 commit comments