* @brief This function will close a device. * * @param dev is the pointer of device driver structure. * * @return the result, RT_EOK on successfully. */
| 290 | * @return the result, RT_EOK on successfully. |
| 291 | */ |
| 292 | rt_err_t rt_device_close(rt_device_t dev) |
| 293 | { |
| 294 | rt_err_t result = RT_EOK; |
| 295 | |
| 296 | /* parameter check */ |
| 297 | RT_ASSERT(dev != RT_NULL); |
| 298 | RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device); |
| 299 | |
| 300 | if (dev->ref_count == 0) |
| 301 | return -RT_ERROR; |
| 302 | |
| 303 | dev->ref_count--; |
| 304 | |
| 305 | if (dev->ref_count != 0) |
| 306 | return RT_EOK; |
| 307 | |
| 308 | /* call device_close interface */ |
| 309 | if (device_close != RT_NULL) |
| 310 | { |
| 311 | result = device_close(dev); |
| 312 | } |
| 313 | |
| 314 | /* set open flag */ |
| 315 | if (result == RT_EOK || result == -RT_ENOSYS) |
| 316 | dev->open_flag = RT_DEVICE_OFLAG_CLOSE; |
| 317 | |
| 318 | return result; |
| 319 | } |
| 320 | RTM_EXPORT(rt_device_close); |
| 321 | |
| 322 | /** |