summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
authorbernard.xiong <[email protected]>2010-03-08 23:09:40 +0000
committerbernard.xiong <[email protected]>2010-03-08 23:09:40 +0000
commit5e82a9a02205e053c281ac19b93ed896d2c88a5c (patch)
tree1a997e0963d20943864f278983881d7871f22ee0 /src/device.c
parent1c9c3bf175bf949014f3815c4eeb99d17c967c5f (diff)
remove rt_passed_second in clock; init device driver when driver has been opened if it is not in activate status; change interrupt nest count to rt_uint8_t; add rt_console_set_device function in kservice.c (rt_kprintf function can use device right now)
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@464 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/device.c b/src/device.c
index 818f4e0445..6f709e38c0 100644
--- a/src/device.c
+++ b/src/device.c
@@ -81,12 +81,12 @@ rt_err_t rt_device_init_all()
result = init(device);
if (result != RT_EOK)
{
- rt_kprintf("To initialize device:%s failed. The error code is %d\n",
+ rt_kprintf("To initialize device:%s failed. The error code is %d\n",
device->parent.name, result);
- }
- else
- {
- device->flag |= RT_DEVICE_FLAG_ACTIVATED;
+ }
+ else
+ {
+ device->flag |= RT_DEVICE_FLAG_ACTIVATED;
}
}
}
@@ -124,6 +124,22 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
result = RT_EOK;
+ /* if device is not initialized, initialize it. */
+ if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
+ {
+ result = dev->init(dev);
+ if (result != RT_EOK)
+ {
+ rt_kprintf("To initialize device:%s failed. The error code is %d\n",
+ dev->parent.name, result);
+ return result;
+ }
+ else
+ {
+ dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
+ }
+ }
+
/* device is a standalone device and opened */
if ((dev->flag & RT_DEVICE_FLAG_STANDALONE) &&
(dev->open_flag & RT_DEVICE_OFLAG_OPEN))