* @brief This function registers a device driver with a specified name. * * @param dev is the pointer of device driver structure. * * @param name is the device driver's name. * * @param flags is the capabilities flag of device. * * @return the error code, RT_EOK on initialization successfully. */
| 65 | * @return the error code, RT_EOK on initialization successfully. |
| 66 | */ |
| 67 | rt_err_t rt_device_register(rt_device_t dev, |
| 68 | const char *name, |
| 69 | rt_uint16_t flags) |
| 70 | { |
| 71 | if (dev == RT_NULL) |
| 72 | return -RT_ERROR; |
| 73 | |
| 74 | if (rt_device_find(name) != RT_NULL) |
| 75 | return -RT_ERROR; |
| 76 | |
| 77 | rt_object_init(&(dev->parent), RT_Object_Class_Device, name); |
| 78 | dev->flag = flags; |
| 79 | dev->ref_count = 0; |
| 80 | dev->open_flag = 0; |
| 81 | |
| 82 | #ifdef RT_USING_POSIX_DEVIO |
| 83 | dev->fops = RT_NULL; |
| 84 | rt_wqueue_init(&(dev->wait_queue)); |
| 85 | #endif /* RT_USING_POSIX_DEVIO */ |
| 86 | |
| 87 | #if defined (RT_USING_DFS_V2) && defined (RT_USING_DFS_DEVFS) |
| 88 | dfs_devfs_device_add(dev); |
| 89 | #endif /* RT_USING_DFS_V2 */ |
| 90 | |
| 91 | return RT_EOK; |
| 92 | } |
| 93 | RTM_EXPORT(rt_device_register); |
| 94 | |
| 95 | /** |