[device] Avoid repeated calls device_open interface. (#7476)
This commit is contained in:
parent
a5211c70b6
commit
8a1260c56a
|
@ -233,7 +233,10 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
|
|||
return -RT_EBUSY;
|
||||
}
|
||||
|
||||
/* call device_open interface */
|
||||
/* device is not opened or opened by other oflag, call device_open interface */
|
||||
if (!(dev->open_flag & RT_DEVICE_OFLAG_OPEN) ||
|
||||
((dev->open_flag & RT_DEVICE_OFLAG_MASK) | (oflag & RT_DEVICE_OFLAG_MASK)))
|
||||
{
|
||||
if (device_open != RT_NULL)
|
||||
{
|
||||
result = device_open(dev, oflag);
|
||||
|
@ -243,6 +246,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
|
|||
/* set open flag */
|
||||
dev->open_flag = (oflag & RT_DEVICE_OFLAG_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
/* set open flag */
|
||||
if (result == RT_EOK || result == -RT_ENOSYS)
|
||||
|
|
Loading…
Reference in New Issue