diff options
| author | 陈豪 <[email protected]> | 2014-08-06 22:55:49 +0800 |
|---|---|---|
| committer | 陈豪 <[email protected]> | 2014-08-06 22:55:49 +0800 |
| commit | 5fc32bf12ef4356ecbd46cfa21079cddb522b5c7 (patch) | |
| tree | 8f77e59c1bcec59c3c5efd0fe022f3dc0a0c901e /src/device.c | |
| parent | 0c8335d5ab046ce9fe36c4e01d5d40e4ba152b49 (diff) | |
| parent | a8fadf15b1828569e7684049d983cc6cb7fda2c9 (diff) | |
Merge pull request #1 from RT-Thread/master
sync
Diffstat (limited to 'src/device.c')
| -rw-r--r-- | src/device.c | 51 |
1 files changed, 10 insertions, 41 deletions
diff --git a/src/device.c b/src/device.c index 75b88bf6eb..835a517ce3 100644 --- a/src/device.c +++ b/src/device.c @@ -79,45 +79,12 @@ RTM_EXPORT(rt_device_unregister); * This function initializes all registered device driver * * @return the error code, RT_EOK on successfully. + * + * @deprecated since 1.2.x, this function is not needed because the initialization + * of a device is performed when applicaiton opens it. */ rt_err_t rt_device_init_all(void) { - struct rt_device *device; - struct rt_list_node *node; - struct rt_object_information *information; - register rt_err_t result; - - extern struct rt_object_information rt_object_container[]; - - information = &rt_object_container[RT_Object_Class_Device]; - - /* for each device */ - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) - { - rt_err_t (*init)(rt_device_t dev); - device = (struct rt_device *)rt_list_entry(node, - struct rt_object, - list); - - /* get device init handler */ - init = device->init; - if (init != RT_NULL && !(device->flag & RT_DEVICE_FLAG_ACTIVATED)) - { - result = init(device); - if (result != RT_EOK) - { - rt_kprintf("To initialize device:%s failed. The error code is %d\n", - device->parent.name, result); - } - else - { - device->flag |= RT_DEVICE_FLAG_ACTIVATED; - } - } - } - return RT_EOK; } @@ -239,11 +206,6 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag) return -RT_EBUSY; } - dev->ref_count++; - /* don't let bad things happen silently. If you are bitten by this assert, - * please set the ref_count to a bigger type. */ - RT_ASSERT(dev->ref_count != 0); - /* call device open interface */ if (dev->open != RT_NULL) { @@ -252,8 +214,15 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag) /* set open flag */ if (result == RT_EOK || result == -RT_ENOSYS) + { dev->open_flag = oflag | RT_DEVICE_OFLAG_OPEN; + dev->ref_count++; + /* don't let bad things happen silently. If you are bitten by this assert, + * please set the ref_count to a bigger type. */ + RT_ASSERT(dev->ref_count != 0); + } + return result; } RTM_EXPORT(rt_device_open); |
