summaryrefslogtreecommitdiff
path: root/components/finsh/shell.c
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2013-07-05 21:02:47 +0800
committerBernard Xiong <[email protected]>2013-07-05 21:02:47 +0800
commitb0c1f8a79b272c1ab61be637d1f2a84561c1bbc0 (patch)
tree690e9181418e89231a4744ac26642906d7446831 /components/finsh/shell.c
parentca71f33303e00a0e5792113c529776f937bc3f53 (diff)
Add device checking when set_device.
Diffstat (limited to 'components/finsh/shell.c')
-rw-r--r--components/finsh/shell.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index 7ace0c34fc..ba5d0e4d77 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -116,7 +116,16 @@ void finsh_set_device(const char* device_name)
RT_ASSERT(shell != RT_NULL);
dev = rt_device_find(device_name);
- if (dev != RT_NULL && rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) == RT_EOK)
+ if (dev == RT_NULL)
+ {
+ rt_kprintf("finsh: can not find device: %s\n", device_name);
+ return;
+ }
+
+ /* check whether it's a same device */
+ if (dev == shell->device) return;
+ /* open this device and set the new device in finsh shell */
+ if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) == RT_EOK)
{
if (shell->device != RT_NULL)
{
@@ -127,10 +136,6 @@ void finsh_set_device(const char* device_name)
shell->device = dev;
rt_device_set_rx_indicate(dev, finsh_rx_ind);
}
- else
- {
- rt_kprintf("finsh: can not find device:%s\n", device_name);
- }
}
/**