@@ -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,21 @@ static void _console_release(void)
319
311
*/
320
312
static void _kputs (const char * str , long len )
321
313
{
322
- RT_UNUSED ( len );
314
+ rt_device_t console_device = rt_console_get_device ( );
323
315
324
316
CONSOLE_TAKE ;
325
317
326
318
#ifdef RT_USING_DEVICE
327
- if (_console_device == RT_NULL )
319
+ if (console_device == RT_NULL )
328
320
{
329
321
rt_hw_console_output (str );
330
322
}
331
323
else
332
324
{
333
- rt_device_write (_console_device , 0 , str , len );
325
+ rt_device_write (console_device , 0 , str , len );
334
326
}
335
327
#else
328
+ RT_UNUSED (len );
336
329
rt_hw_console_output (str );
337
330
#endif /* RT_USING_DEVICE */
338
331
0 commit comments