@@ -187,23 +187,15 @@ RTM_EXPORT(rt_console_get_device);
187187 */
188188rt_device_t rt_console_set_device (const char * name )
189189{
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 );
191192
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 )
202194 {
203- if (_console_device != RT_NULL )
195+ if (old_device != RT_NULL )
204196 {
205197 /* close old console device */
206- rt_device_close (_console_device );
198+ rt_device_close (old_device );
207199 }
208200
209201 /* set new console device */
@@ -319,20 +311,21 @@ static void _console_release(void)
319311 */
320312static void _kputs (const char * str , long len )
321313{
322- RT_UNUSED ( len );
314+ rt_device_t console_device = rt_console_get_device ( );
323315
324316 CONSOLE_TAKE ;
325317
326318#ifdef RT_USING_DEVICE
327- if (_console_device == RT_NULL )
319+ if (console_device == RT_NULL )
328320 {
329321 rt_hw_console_output (str );
330322 }
331323 else
332324 {
333- rt_device_write (_console_device , 0 , str , len );
325+ rt_device_write (console_device , 0 , str , len );
334326 }
335327#else
328+ RT_UNUSED (len );
336329 rt_hw_console_output (str );
337330#endif /* RT_USING_DEVICE */
338331
0 commit comments