* @brief This function will set a device as console device. * After set a device to console, all output of rt_kprintf will be * redirected to this new device. * * @param name is the name of new console device. * * @return the old console device handler on successful, or RT_NULL on failure. */
| 186 | * @return the old console device handler on successful, or RT_NULL on failure. |
| 187 | */ |
| 188 | rt_device_t rt_console_set_device(const char *name) |
| 189 | { |
| 190 | rt_device_t old_device = _console_device; |
| 191 | rt_device_t new_device = rt_device_find(name); |
| 192 | |
| 193 | if (new_device != RT_NULL && new_device != old_device) |
| 194 | { |
| 195 | if (old_device != RT_NULL) |
| 196 | { |
| 197 | /* close old console device */ |
| 198 | rt_device_close(old_device); |
| 199 | } |
| 200 | |
| 201 | /* set new console device */ |
| 202 | rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM); |
| 203 | _console_device = new_device; |
| 204 | } |
| 205 | |
| 206 | return old_device; |
| 207 | } |
| 208 | RTM_EXPORT(rt_console_set_device); |
| 209 | #endif /* RT_USING_DEVICE */ |
| 210 |