Bläddra i källkod

remove rt_object_find function.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@690 bbd45198-f89e-11dd-88c7-29a3b14d5316
bernard.xiong 15 år sedan
förälder
incheckning
fca4e1a719
4 ändrade filer med 99 tillägg och 40 borttagningar
  1. 1 1
      include/rtthread.h
  2. 65 2
      src/device.c
  3. 0 29
      src/object.c
  4. 33 8
      src/thread.c

+ 1 - 1
include/rtthread.h

@@ -40,7 +40,6 @@ void rt_object_init(struct rt_object* object, enum rt_object_class_type type, co
 void rt_object_detach(rt_object_t object);
 rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name);
 void rt_object_delete(rt_object_t object);
-rt_object_t rt_object_find(enum rt_object_class_type type, const char* name);
 rt_err_t rt_object_is_systemobject(rt_object_t object);
 
 #ifdef RT_USING_HOOK
@@ -285,6 +284,7 @@ rt_err_t rt_device_init_all(void);
 rt_err_t rt_device_set_rx_indicate(rt_device_t dev, rt_err_t (*rx_ind )(rt_device_t dev, rt_size_t size));
 rt_err_t rt_device_set_tx_complete(rt_device_t dev, rt_err_t (*tx_done)(rt_device_t dev, void *buffer));
 
+rt_err_t  rt_device_init (rt_device_t dev);
 rt_err_t  rt_device_open (rt_device_t dev, rt_uint16_t oflag);
 rt_err_t  rt_device_close(rt_device_t dev);
 rt_size_t rt_device_read (rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size);

+ 65 - 2
src/device.c

@@ -10,6 +10,7 @@
  * Change Logs:
  * Date           Author       Notes
  * 2007-01-21     Bernard      the first version
+ * 2010-05-04     Bernard      add rt_device_init implementation
  */
 
 #include <rtthread.h>
@@ -103,9 +104,71 @@ rt_err_t rt_device_init_all()
  */
 rt_device_t rt_device_find(const char* name)
 {
+	struct rt_object* object;
+	struct rt_list_node* node;
+	struct rt_object_information *information;
+
+	extern struct rt_object_information rt_object_container[];
+
+	/* enter critical */
+	if (rt_thread_self() != RT_NULL)
+		rt_enter_critical();
+
 	/* try to find device object */
-	return (struct rt_device*) rt_object_find (RT_Object_Class_Device,
-		name);
+	information = &rt_object_container[RT_Object_Class_Device];
+	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, RT_NAME_MAX) == 0)
+		{
+			/* leave critical */
+			if (rt_thread_self() != RT_NULL)
+				rt_exit_critical();
+
+			return (rt_device_t)object;
+		}
+	}
+
+	/* leave critical */
+	if (rt_thread_self() != RT_NULL)
+		rt_exit_critical();
+
+	/* not found */
+	return RT_NULL;
+}
+
+/**
+ * This function will initialize the speicial device
+ *
+ * @param dev the pointer of device driver structure
+ * 
+ * @return the result
+ */
+rt_err_t rt_device_init(rt_device_t dev)
+{
+	rt_err_t result;
+	rt_err_t (*init)(rt_device_t dev);
+	
+	RT_ASSERT(dev != RT_NULL);
+
+	/* get device init handler */
+	init = dev->init;
+	if (init != RT_NULL && !(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
+	{
+		result = init(dev);
+		if (result != RT_EOK)
+		{
+			rt_kprintf("To initialize device:%s failed. The error code is %d\n",
+				dev->parent.name, result);
+		}
+		else
+		{
+			dev->flag |= RT_DEVICE_FLAG_ACTIVATED;
+		}
+	}
+	else result = -RT_ENOSYS;
+	
+	return result;
 }
 
 /**

+ 0 - 29
src/object.c

@@ -334,35 +334,6 @@ void rt_object_delete(rt_object_t object)
 }
 #endif
 
-/**
- * This fucntion will find the object id by specified object name
- *
- * @param type the type of object
- * @param name the specified object name
- *
- * @return object id for successful
- */
-rt_object_t rt_object_find(enum rt_object_class_type type, const char* name)
-{
-	struct rt_object_information *information;
-	struct rt_object* object;
-	struct rt_list_node* node;
-
-	information = &rt_object_container[type];
-
-	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, RT_NAME_MAX) == 0)
-		{
-			return object;
-		}
-	}
-
-	/* not found */
-	return RT_NULL;
-}
-
 /**
  * This function will judge the object is system object or not.
  * Normally, the system object is a static object and the type

+ 33 - 8
src/thread.c

@@ -1,7 +1,7 @@
 /*
  * File      : thread.c
  * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
+ * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -19,7 +19,7 @@
  * 2006-09-03     Bernard      implement rt_thread_detach
  * 2008-02-16     Bernard      fix the rt_thread_timeout bug
  * 2010-03-21     Bernard      change the errno of rt_thread_delay/sleep to RT_EOK.
- * 2010-04-11     yi.qiu          add module feature
+ * 2010-04-11     Yi.Qiu       add module feature
  */
 
 #include <rtthread.h>
@@ -49,8 +49,7 @@ static rt_err_t _rt_thread_init(struct rt_thread* thread,
 	void* stack_start, rt_uint32_t stack_size,
 	rt_uint8_t priority, rt_uint32_t tick)
 {
-	/* set thread id and init thread list */
-	thread->tid = thread;
+	/* init thread list */
 	rt_list_init(&(thread->tlist));
 
 	thread->entry = (void*)entry;
@@ -82,7 +81,7 @@ static rt_err_t _rt_thread_init(struct rt_thread* thread,
 
 #ifdef RT_USING_MODULE
 	/* init module parent */
-	thread->module_parent = 
+	thread->module_parent =
 		(rt_current_module != RT_NULL) ? rt_current_module : RT_NULL;
 #endif
 
@@ -626,11 +625,37 @@ void rt_thread_timeout(void* parameter)
  */
 rt_thread_t rt_thread_find(char* name)
 {
-	struct rt_thread* thread;
+	struct rt_object_information *information;
+	struct rt_object* object;
+	struct rt_list_node* node;
 
-	thread = (struct rt_thread*)rt_object_find(RT_Object_Class_Thread, name);
+	extern struct rt_object_information rt_object_container[];
 
-	return thread;
+	/* enter critical */
+	if (rt_thread_self() != RT_NULL)
+		rt_enter_critical();
+
+	/* try to find device object */
+	information = &rt_object_container[RT_Object_Class_Thread];
+	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, RT_NAME_MAX) == 0)
+		{
+			/* leave critical */
+			if (rt_thread_self() != RT_NULL)
+				rt_exit_critical();
+
+			return (rt_thread_t)object;
+		}
+	}
+
+	/* leave critical */
+	if (rt_thread_self() != RT_NULL)
+		rt_exit_critical();
+
+	/* not found */
+	return RT_NULL;
 }
 
 /*@}*/