summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author陈豪 <[email protected]>2014-08-06 22:55:49 +0800
committer陈豪 <[email protected]>2014-08-06 22:55:49 +0800
commit5fc32bf12ef4356ecbd46cfa21079cddb522b5c7 (patch)
tree8f77e59c1bcec59c3c5efd0fe022f3dc0a0c901e /src
parent0c8335d5ab046ce9fe36c4e01d5d40e4ba152b49 (diff)
parenta8fadf15b1828569e7684049d983cc6cb7fda2c9 (diff)
Merge pull request #1 from RT-Thread/master
sync
Diffstat (limited to 'src')
-rw-r--r--src/device.c51
-rw-r--r--src/kservice.c14
-rw-r--r--src/module.c4
-rw-r--r--src/object.c65
-rw-r--r--src/timer.c29
5 files changed, 96 insertions, 67 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);
diff --git a/src/kservice.c b/src/kservice.c
index 0f06806087..cb0064f38b 100644
--- a/src/kservice.c
+++ b/src/kservice.c
@@ -1081,19 +1081,7 @@ rt_device_t rt_console_set_device(const char *name)
RTM_EXPORT(rt_console_set_device);
#endif
-#if defined(__GNUC__) || defined(__ADSPBLACKFIN__)
-void rt_hw_console_output(const char *str) __attribute__((weak));
-void rt_hw_console_output(const char *str)
-#elif defined(__CC_ARM)
-__weak void rt_hw_console_output(const char *str)
-#elif defined(__IAR_SYSTEMS_ICC__)
- #if __VER__ > 540
- __weak
- #endif
-void rt_hw_console_output(const char *str)
-#else
-void rt_hw_console_output(const char *str)
-#endif
+WEAK void rt_hw_console_output(const char *str)
{
/* empty console output */
}
diff --git a/src/module.c b/src/module.c
index 0603159b91..5d5d02c580 100644
--- a/src/module.c
+++ b/src/module.c
@@ -1120,8 +1120,8 @@ rt_module_t rt_module_open(const char *path)
* This function will do a excutable program with main function and parameters.
*
* @param path the full path of application module
- * @cmd_line the command line of program
- * @size the size of command line of program
+ * @param cmd_line the command line of program
+ * @param size the size of command line of program
*
* @return the module object
*/
diff --git a/src/object.c b/src/object.c
index ed3173a0f5..32dc0f2384 100644
--- a/src/object.c
+++ b/src/object.c
@@ -403,22 +403,77 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
{
struct rt_object *object;
struct rt_list_node *node;
- struct rt_object_information *information;
- extern volatile rt_uint8_t rt_interrupt_nest;
+ struct rt_object_information *information = RT_NULL;
/* parameter check */
if ((name == RT_NULL) || (type > RT_Object_Class_Unknown))
return RT_NULL;
/* which is invoke in interrupt status */
- if (rt_interrupt_nest != 0)
- RT_ASSERT(0);
+ RT_DEBUG_NOT_IN_INTERRUPT;
+
+#ifdef RT_USING_MODULE
+ /* check whether to find a object inside a module. */
+ {
+ const char *name_ptr;
+ int module_name_length;
+
+ name_ptr = name;
+ while ((*name_ptr != '\0') && (*name_ptr != '/'))
+ name_ptr ++;
+
+ if (*name_ptr == '/')
+ {
+ struct rt_module* module = RT_NULL;
+
+ /* get the name length of module */
+ module_name_length = name_ptr - name;
+
+ /* enter critical */
+ rt_enter_critical();
+
+ /* find module */
+ information = &rt_object_container[RT_Object_Class_Module];
+ for (node = information->object_list.next;
+ node != &(information->object_list);
+ node = node->next)
+ {
+ object = rt_list_entry(node, struct rt_object, list);
+ if ((rt_strncmp(object->name, name, module_name_length) == 0) &&
+ module_name_length == RT_NAME_MAX || object->name[module_name_length] == '\0')
+ {
+ /* get module */
+ module = (struct rt_module*)object;
+ break;
+ }
+ }
+ rt_exit_critical();
+
+ /* there is no this module inside the system */
+ if (module == RT_NULL) return RT_NULL;
+
+ /* get the object pool of module */
+ information = &(module->module_object[type]);
+
+ /* get object name */
+ while ((*name_ptr == '/') && (*name_ptr != '\0')) name_ptr ++;
+ if (*name_ptr == '\0')
+ {
+ if (type == RT_Object_Class_Module) return object;
+ return RT_NULL;
+ }
+
+ /* point to the object name */
+ name = name_ptr;
+ }
+ }
+#endif
/* enter critical */
rt_enter_critical();
/* try to find object */
- information = &rt_object_container[type];
+ if (information == RT_NULL) information = &rt_object_container[type];
for (node = information->object_list.next;
node != &(information->object_list);
node = node->next)
diff --git a/src/timer.c b/src/timer.c
index ac8a148d8d..f71e40fcd6 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -28,6 +28,8 @@
* 2010-05-12 Bernard fix the timer check bug.
* 2010-11-02 Charlie re-implement tick overflow issue
* 2012-12-15 Bernard fix the next timeout issue in soft timer
+ * 2014-07-12 Bernard does not lock scheduler when invoking soft-timer
+ * timeout function.
*/
#include <rtthread.h>
@@ -128,6 +130,7 @@ rt_inline void _rt_timer_remove(rt_timer_t timer)
}
}
+#if RT_DEBUG_TIMER
static int rt_timer_count_height(struct rt_timer *timer)
{
int i, cnt = 0;
@@ -155,6 +158,7 @@ void rt_timer_dump(rt_list_t timer_heads[])
}
rt_kprintf("\n");
}
+#endif
/**
* @addtogroup Clock
@@ -298,8 +302,14 @@ rt_err_t rt_timer_start(rt_timer_t timer)
/* timer check */
RT_ASSERT(timer != RT_NULL);
- if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
- return -RT_ERROR;
+
+ /* stop timer firstly */
+ level = rt_hw_interrupt_disable();
+ /* remove timer from list */
+ _rt_timer_remove(timer);
+ /* change status of timer */
+ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
+ rt_hw_interrupt_enable(level);
RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(timer->parent)));
@@ -560,6 +570,9 @@ void rt_soft_timer_check(void)
current_tick = rt_tick_get();
+ /* lock scheduler */
+ rt_enter_critical();
+
for (n = rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1].next;
n != &(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1]);)
{
@@ -579,6 +592,8 @@ void rt_soft_timer_check(void)
/* remove timer from timer list firstly */
_rt_timer_remove(t);
+ /* not lock scheduler when performing timeout function */
+ rt_exit_critical();
/* call timeout function */
t->timeout_func(t->parameter);
@@ -587,6 +602,9 @@ void rt_soft_timer_check(void)
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));
+ /* lock scheduler */
+ rt_enter_critical();
+
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
{
@@ -603,6 +621,9 @@ void rt_soft_timer_check(void)
else break; /* not check anymore */
}
+ /* unlock scheduler */
+ rt_exit_critical();
+
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n"));
}
@@ -636,12 +657,8 @@ static void rt_thread_timer_entry(void *parameter)
}
}
- /* lock scheduler */
- rt_enter_critical();
/* check software timer */
rt_soft_timer_check();
- /* unlock scheduler */
- rt_exit_critical();
}
}
#endif