Browse Source

add module feature

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@614 bbd45198-f89e-11dd-88c7-29a3b14d5316
qiuyiuestc 15 years ago
parent
commit
cbfb87fac1

+ 4 - 1
bsp/mini2440/SConstruct

@@ -42,7 +42,10 @@ if rtconfig.RT_USING_RTGUI:
 	objs = objs + SConscript(RTT_ROOT + '/rtgui/SConscript', variant_dir='build/rtgui', duplicate=0)
 	objs = objs + SConscript(RTT_ROOT + '/rtgui/SConscript', variant_dir='build/rtgui', duplicate=0)
 	objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0)
 	objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0)
 
 
-src_bsp = ['application.c', 'startup.c', 'board.c', 'rtc_calendar.c' ]
+if rtconfig.RT_USING_MODBUS:
+	objs = objs + SConscript(RTT_ROOT + '/net/freemodbus/SConscript', variant_dir='build/net/freemodbus', duplicate=0)	
+
+src_bsp = ['application.c', 'startup.c', 'board.c', 'rtc_calendar.c', 'info.c', 'today.c', 'picture.c', 'osc.c', 'device_info.c', 'run_module.c']
 src_drv = ['console.c', 'led.c']
 src_drv = ['console.c', 'led.c']
 
 
 if rtconfig.RT_USING_DFS:
 if rtconfig.RT_USING_DFS:

+ 6 - 0
bsp/mini2440/mini2440_ram.ld

@@ -22,6 +22,12 @@ SECTIONS
 		KEEP(*(VSymTab))
 		KEEP(*(VSymTab))
 		__vsymtab_end = .;
 		__vsymtab_end = .;
 		. = ALIGN(4);	
 		. = ALIGN(4);	
+
+		/* section information for modules */
+		. = ALIGN(4);
+		__rtmsymtab_start = .;
+		KEEP(*(RTMSymTab))
+		__rtmsymtab_end = .;
 	}
 	}
 
 
 	. = ALIGN(4);
 	. = ALIGN(4);

+ 172 - 0
bsp/mini2440/network.xpm

@@ -0,0 +1,172 @@
+/* XPM */
+static char * network_xpm[] = {
+"24 24 145 2",
+"  	c None",
+". 	c #6C6E6A",
+"+ 	c #676965",
+"@ 	c #6B6D6A",
+"# 	c #C6C8C4",
+"$ 	c #F0F1F0",
+"% 	c #F1F1F0",
+"& 	c #C8CAC6",
+"* 	c #646662",
+"= 	c #446795",
+"- 	c #27508B",
+"; 	c #2A538D",
+"> 	c #2E558F",
+", 	c #315890",
+"' 	c #355B92",
+") 	c #385E94",
+"! 	c #3C6196",
+"~ 	c #5C7BA2",
+"{ 	c #F2F3F2",
+"] 	c #626460",
+"^ 	c #F2F2F2",
+"/ 	c #3E6297",
+"( 	c #86ACD5",
+"_ 	c #88AED6",
+": 	c #8BB0D7",
+"< 	c #8DB1D7",
+"[ 	c #8CB1D7",
+"} 	c #8CB0D6",
+"| 	c #8DAED6",
+"1 	c #5B7AA7",
+"2 	c #F4F4F4",
+"3 	c #61635F",
+"4 	c #30578F",
+"5 	c #88ADD6",
+"6 	c #8EB1D7",
+"7 	c #92B3D8",
+"8 	c #96B6D8",
+"9 	c #92B2D6",
+"0 	c #8CADD3",
+"a 	c #84A7CF",
+"b 	c #5F615D",
+"c 	c #204A87",
+"d 	c #6694C7",
+"e 	c #6391C5",
+"f 	c #618FC3",
+"g 	c #5E8CC1",
+"h 	c #5B8ABF",
+"i 	c #5887BD",
+"j 	c #5684BB",
+"k 	c #5D5F5B",
+"l 	c #5D8CC0",
+"m 	c #5A89BE",
+"n 	c #5886BD",
+"o 	c #5584BB",
+"p 	c #5281B9",
+"q 	c #4F7FB7",
+"r 	c #4D7CB5",
+"s 	c #5C5E5A",
+"t 	c #5482BA",
+"u 	c #5180B8",
+"v 	c #4F7EB6",
+"w 	c #4C7BB4",
+"x 	c #4979B2",
+"y 	c #4676B1",
+"z 	c #4373AF",
+"A 	c #5A5C58",
+"B 	c #406492",
+"C 	c #31527F",
+"D 	c #656D70",
+"E 	c #5E605B",
+"F 	c #C3C4C1",
+"G 	c #80827F",
+"H 	c #C8CAC7",
+"I 	c #545651",
+"J 	c #5E605C",
+"K 	c #6A6E68",
+"L 	c #72756F",
+"M 	c #7B7E79",
+"N 	c #848781",
+"O 	c #8D908A",
+"P 	c #969993",
+"Q 	c #9FA29C",
+"R 	c #416593",
+"S 	c #244E89",
+"T 	c #29518C",
+"U 	c #2D558E",
+"V 	c #325991",
+"W 	c #375C93",
+"X 	c #3B6096",
+"Y 	c #5D7BA3",
+"Z 	c #555753",
+"` 	c #D0D2CE",
+" .	c #BBBEB7",
+"..	c #BABDB6",
+"+.	c #F2F2F1",
+"@.	c #345A92",
+"#.	c #81A8D3",
+"$.	c #83ABD4",
+"%.	c #8AAFD6",
+"&.	c #8FB3D8",
+"*.	c #92B4DA",
+"=.	c #5978A6",
+"-.	c #D2D4D1",
+";.	c #2C548E",
+">.	c #85ACD5",
+",.	c #92B5DA",
+"'.	c #98B9DB",
+").	c #95B6DA",
+"!.	c #90B2D7",
+"~.	c #88ACD3",
+"{.	c #464644",
+"].	c #719ECE",
+"^.	c #6E9BCC",
+"/.	c #6A98C9",
+"(.	c #6794C7",
+"_.	c #608EC2",
+":.	c #5C8BC0",
+"<.	c #757773",
+"[.	c #DADAD9",
+"}.	c #6391C4",
+"|.	c #5F8DC2",
+"1.	c #5C8ABF",
+"2.	c #5181B8",
+"3.	c #7F817C",
+"4.	c #ECECEA",
+"5.	c #5B89BF",
+"6.	c #5483BA",
+"7.	c #4D7DB6",
+"8.	c #4A7AB3",
+"9.	c #4776B1",
+"0.	c #80827D",
+"a.	c #EEEEEC",
+"b.	c #3F6392",
+"c.	c #82847F",
+"d.	c #848680",
+"e.	c #7F817D",
+"f.	c #7D7F7B",
+"g.	c #666863",
+"h.	c #A8ACA5",
+"i.	c #B1B3AC",
+"j.	c #E1E1DE",
+"k.	c #EDEDEB",
+"l.	c #E0E0DE",
+"m.	c #565854",
+"n.	c #767874",
+"                                                ",
+"    . + + + + + + + + + .                       ",
+"  @ # $ % % % % % % % $ & @                     ",
+"  * $ = - ; > , ' ) ! ~ { *                     ",
+"  ] ^ / ( _ : < [ } | 1 2 ]                     ",
+"  3 % 4 5 6 7 8 9 0 a ) % 3                     ",
+"  b % c d e f g h i j c % b                     ",
+"  k % c l m n o p q r c % k                     ",
+"  s % c t u v w x y z c % s                     ",
+"  A $ B c c c c c c C D + + + + + + + + + .     ",
+"  E F $ % % % % % % G # $ % % % % % % % $ H @   ",
+"  I J K L M N O P Q * $ R c S T U V W X Y { *   ",
+"  Z `  .............] +.@.#.$.( %.[ &.*.=.2 ]   ",
+"  Z -.+.+.+.+.+.+.+.3 % ;.>.: ,.'.).!.~.W % 3   ",
+"  {.Z Z Z Z Z Z Z Z b % c ].^./.(.e _.:.c % b   ",
+"      <.[.<.        k % c d }.|.1.i o 2.c % k   ",
+"      3.4.3.        s % c 5.i 6.u 7.8.9.c % s   ",
+"      0.a.0.        A $ B c c c c c c c b.$ A   ",
+"      c...c.        E F $ % % % % % % % $ F E   ",
+"      0.a.0.d.0.e.f.g.J K L M N O P Q h.i.J I   ",
+"      0.j.a...a.k.l.m.`  ............... .` Z   ",
+"        0.0.c.0.3.n.Z -.+.+.+.+.+.+.+.+.+.-.Z   ",
+"                    {.Z Z Z Z Z Z Z Z Z Z Z {.  ",
+"                                                "};

+ 98 - 0
bsp/mini2440/network_disconnect.xpm

@@ -0,0 +1,98 @@
+/* XPM */
+static char * network_disconnect_xpm[] = {
+"24 24 71 1",
+" 	c None",
+".	c #191918",
+"+	c #181817",
+"@	c #808080",
+"#	c #EDEDED",
+"$	c #6B6B6A",
+"%	c #161615",
+"&	c #D8D8D8",
+"*	c #484848",
+"=	c #A4A4A4",
+"-	c #E6E6E6",
+";	c #F3F3F3",
+">	c #F5F5F6",
+",	c #C0C0C5",
+"'	c #F3F3F4",
+")	c #F0F0F0",
+"!	c #B7B4C3",
+"~	c #B7B5C4",
+"{	c #F5F5F5",
+"]	c #A19DB2",
+"^	c #EEEEEE",
+"/	c #B6B4C3",
+"(	c #B7B5C3",
+"_	c #B3B1C1",
+":	c #B5B3C1",
+"<	c #EAEAEB",
+"[	c #EFEFEF",
+"}	c #A19EB2",
+"|	c #A09CB1",
+"1	c #928FA2",
+"2	c #676571",
+"3	c #D3D3D3",
+"4	c #2A2A2A",
+"5	c #090909",
+"6	c #8B8B8B",
+"7	c #0F0F0E",
+"8	c #2A2A29",
+"9	c #70706F",
+"0	c #898988",
+"a	c #A8A8A8",
+"b	c #0E0E0D",
+"c	c #D1D1D1",
+"d	c #ECECEC",
+"e	c #EBEBEB",
+"f	c #D9D9D9",
+"g	c #C1C1C1",
+"h	c #B7B7B7",
+"i	c #BCBCBC",
+"j	c #141413",
+"k	c #7F7F7E",
+"l	c #B6B6B5",
+"m	c #C8C8C7",
+"n	c #C0C0C0",
+"o	c #949494",
+"p	c #E5E5E5",
+"q	c #5D5D5C",
+"r	c #242423",
+"s	c #9A9A99",
+"t	c #C8C8C8",
+"u	c #C5C5C5",
+"v	c #E8E8E8",
+"w	c #BABABA",
+"x	c #DEDEDE",
+"y	c #D5D5D5",
+"z	c #C2C2C2",
+"A	c #B3B3B3",
+"B	c #909090",
+"C	c #B6B6B6",
+"D	c #C4C4C4",
+"E	c #1F1F1D",
+"F	c #000000",
+"                        ",
+"   .........+           ",
+" +@#########$%          ",
+" .#&*******=-.          ",
+" .;*>,,>,,'*).          ",
+" .)*!~~~>{]*).          ",
+" .^*/(_:<<]*[.          ",
+" .^*}}|}<<]*^.          ",
+" .#*]]]]]12.........+   ",
+" .;3*****4@#########$%  ",
+" 56######.#&*******=-.  ",
+" 7890aaaa.;*>,,>,,'*).  ",
+" b;)cdeee.)*!~~~>{]*).  ",
+" bfghiiii.^*/(_:<<]*[.  ",
+" j........^*}}|}<<]*^.  ",
+"  klk    .#*]]]]]]]*#.  ",
+"  kmk    .;3*******n#.  ",
+"  k3k    56#########o.  ",
+"  kpk    7890aaaa09q.r  ",
+"  kpskkkkb;)cdeeetuuv.  ",
+"  kwxyzABbfghiiiiCcyD.  ",
+"   kkkkkkE...........F  ",
+"                        ",
+"                        "};

+ 131 - 0
bsp/mini2440/osc.c

@@ -0,0 +1,131 @@
+#include <rtgui/rtgui.h>
+#include <rtgui/image.h>
+#include <rtgui/rtgui_system.h>
+
+#include <rtgui/widgets/view.h>
+#include <rtgui/widgets/workbench.h>
+
+#define POINT_LENGTH    320
+static rt_uint8_t points[POINT_LENGTH];
+static rt_uint8_t old_point, fudu = 1;
+static rt_uint16_t current_point = 0;
+
+static rtgui_view_t  *osc_view = RT_NULL;
+static rtgui_timer_t *osc_timer;
+
+#include <math.h>
+
+void osc_timeout(struct rtgui_timer* timer, void* parameter)
+{
+    struct rtgui_dc* dc;
+    rtgui_color_t saved;
+	const double PI=3.141592653589793238462643383279;
+
+    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(osc_view));
+    if (dc == RT_NULL) return ;
+
+    saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(osc_view));
+    RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(osc_view)) =
+        RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(osc_view));
+	if (current_point != 0)
+		rtgui_dc_draw_line(dc, current_point - 1, old_point, current_point, points[current_point]);
+	else
+		rtgui_dc_draw_point(dc, current_point, points[current_point]);
+
+    RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(osc_view)) = saved;
+
+	old_point = points[current_point];
+	points[current_point] = 100 * sin((current_point * 4 * fudu) * PI / POINT_LENGTH) + 100;
+	if (current_point != 0)
+		rtgui_dc_draw_line(dc, current_point - 1, points[current_point - 1], current_point, points[current_point]);
+	else
+		rtgui_dc_draw_point(dc, current_point, points[current_point]);
+
+	current_point ++; 
+	if (current_point == POINT_LENGTH)
+	{
+		current_point = 0;
+		fudu ++;
+		if (fudu == 4) fudu = 1;
+	}
+
+    rtgui_dc_end_drawing(dc);
+}
+
+static rt_bool_t osc_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
+{
+    switch (event->type)
+    {
+    case RTGUI_EVENT_PAINT:
+    {
+		struct rtgui_dc* dc;
+		struct rtgui_rect rect;
+		int index;
+
+		dc = rtgui_dc_begin_drawing(widget);
+		if (dc == RT_NULL) return RT_FALSE;
+		rtgui_widget_get_rect(widget, &rect);
+
+		rtgui_dc_fill_rect(dc, &rect);
+		for (index = 0; index < 320; index ++)
+			rtgui_dc_draw_point(dc, index, points[index]);
+		rtgui_dc_end_drawing(dc);
+
+		return RT_FALSE;
+    }
+
+    case RTGUI_EVENT_KBD:
+    {
+		struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
+		if ((ekbd->type == RTGUI_KEYDOWN) && (ekbd->key == RTGUIK_RETURN))
+		{
+            rtgui_workbench_t* workbench;
+
+			/* stop timer */
+			rtgui_timer_destory(osc_timer);
+			/* clean points */
+			rt_memset(points, 0xff, sizeof(points));
+			current_point = 0;
+
+            /* close this view */
+            workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(osc_view)->parent);
+            rtgui_workbench_remove_view(workbench, osc_view);
+            rtgui_view_destroy(osc_view);
+
+            osc_view = RT_NULL;
+			fudu = 0;
+			return RT_FALSE;
+		}
+    }
+    }
+
+    return rtgui_view_event_handler(widget, event);
+}
+
+rtgui_view_t *osc_view_create(struct rtgui_workbench* workbench)
+{
+    if (osc_view != RT_NULL)
+    {
+        rtgui_view_show(osc_view, RT_FALSE);
+    }
+	else
+	{
+	    /* create picture view */
+	    osc_view = rtgui_view_create("Oscilloscope");
+		rtgui_widget_set_event_handler(RTGUI_WIDGET(osc_view),
+	        osc_view_event_handler);
+
+		rtgui_workbench_add_view(workbench, osc_view);
+		/* this view can be focused */
+		RTGUI_WIDGET(osc_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+
+		rt_memset(points, 0xff, sizeof(points));
+
+		osc_timer = rtgui_timer_create(8,
+            RT_TIMER_FLAG_PERIODIC,
+            osc_timeout, RT_NULL);
+        rtgui_timer_start(osc_timer);
+	}
+
+	return osc_view;
+}

BIN
bsp/mini2440/osc.o


+ 300 - 0
bsp/mini2440/picture.c

@@ -0,0 +1,300 @@
+#include <rtgui/rtgui.h>
+#include <rtgui/image.h>
+#include <rtgui/rtgui_system.h>
+
+#include <rtgui/widgets/view.h>
+#include <rtgui/widgets/workbench.h>
+#include <dfs_posix.h>
+#include <string.h>
+
+enum picture_view_mode
+{
+	VIEW_SINGLE_MODE,
+	VIEW_DIR_MODE,
+	VIEW_FN_LIST_MODE
+};
+
+static rtgui_view_t* picture_view = RT_NULL;
+static enum picture_view_mode view_mode = VIEW_SINGLE_MODE;
+
+/* current picture file name */
+static char current_fn[32] = {0};
+static const char** picture_fn_list;
+static rt_uint8_t picture_fn_list_size, picture_fn_list_current;
+
+static void picture_show_prev()
+{
+	DIR* dir;
+	struct dirent* entry;
+	rt_bool_t is_last;
+	char fn[32];
+
+	fn[0] = '\0';
+	is_last = RT_FALSE;
+
+	dir = opendir("/");
+	if (dir == RT_NULL)
+	{
+		rt_kprintf("open directory failed\n");
+		return;
+	}
+
+	do
+	{
+		entry = readdir(dir);
+		if (entry != RT_NULL)
+		{
+			if (strstr(entry->d_name, ".hdc") != RT_NULL ||
+				strstr(entry->d_name, ".HDC") != RT_NULL)
+			{
+				/* it's a HDC image */
+				if ((strcmp(entry->d_name, current_fn) == 0) &&
+					is_last != RT_TRUE)
+				{
+					if (fn[0] == '\0')
+					{
+						/* it should be the last image */
+						is_last = RT_TRUE;
+					}
+					else
+					{
+						/* display image */
+						strcpy(current_fn, fn);
+						rtgui_widget_update(RTGUI_WIDGET(picture_view));
+						closedir(dir);
+						return;
+					}
+				}
+				strcpy(fn, entry->d_name);
+			}
+		}
+	} while(entry != RT_NULL);
+
+	/* close directory */
+	closedir(dir);
+
+	if ((is_last == RT_TRUE) && fn[0] != '\0')
+	{
+		strcpy(current_fn, fn);
+		rtgui_widget_update(RTGUI_WIDGET(picture_view));
+	}
+}
+
+static void picture_show_next()
+{
+	DIR* dir;
+	struct dirent* entry;
+	rt_bool_t found, has_image;
+
+	found = RT_FALSE; has_image = RT_FALSE;
+
+__restart:
+	dir = opendir("/");
+	if (dir == RT_NULL)
+	{
+		rt_kprintf("open directory failed\n");
+		return;
+	}
+
+	do
+	{
+		entry = readdir(dir);
+		if (entry != RT_NULL)
+		{
+			if (strstr(entry->d_name, ".hdc") != RT_NULL ||
+				strstr(entry->d_name, ".HDC") != RT_NULL)
+			{
+				/* this directory includes image */
+				has_image = RT_TRUE;
+
+				if (found == RT_TRUE || current_fn[0] == '\0')
+				{
+					strcpy(current_fn, entry->d_name);
+					rtgui_widget_update(RTGUI_WIDGET(picture_view));
+
+					closedir(dir);
+					return;
+				}
+
+				/* it's a HDC image */
+				if (strcmp(entry->d_name, current_fn) == 0)
+					found = RT_TRUE;
+			}
+		}
+	} while(entry != RT_NULL);
+
+	/* close directory */
+	closedir(dir);
+
+	if (has_image != RT_TRUE) return;
+	current_fn[0] = '\0';
+	goto __restart;
+}
+
+static rt_bool_t picture_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
+{
+	if (event->type == RTGUI_EVENT_PAINT)
+	{
+		struct rtgui_dc* dc;
+		struct rtgui_rect rect;
+		struct rtgui_image* image;
+		char fn[32];
+
+		dc = rtgui_dc_begin_drawing(widget);
+		if (dc == RT_NULL) return RT_FALSE;
+		rtgui_widget_get_rect(widget, &rect);
+
+		/* open image */
+		rt_sprintf(fn, "/%s", current_fn);
+		image = rtgui_image_create_from_file("hdc",
+			fn, RT_FALSE);
+		if (image != RT_NULL)
+		{
+			/* blit image */
+			rtgui_image_blit(image, dc, &rect);
+			/* destroy image */
+			rtgui_image_destroy(image);
+		}
+		else
+		{
+			rtgui_dc_fill_rect(dc, &rect);
+			rtgui_dc_draw_text(dc, "ûÓÐÎļþ±»´ò¿ª", &rect);
+		}
+		rtgui_dc_end_drawing(dc);
+
+		return RT_FALSE;
+	}
+	else if (event->type == RTGUI_EVENT_KBD)
+	{
+		struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
+		if (ekbd->type == RTGUI_KEYDOWN)
+		{
+			switch (ekbd->key)
+			{
+			case RTGUIK_UP:
+				if (view_mode == VIEW_DIR_MODE) picture_show_next();
+				else if (view_mode == VIEW_FN_LIST_MODE)
+				{
+					picture_fn_list_current ++;
+					if (picture_fn_list_current == picture_fn_list_size)
+					{
+						picture_fn_list_current = 0;
+					}
+					strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
+					rtgui_widget_update(RTGUI_WIDGET(picture_view));
+				}
+				break;
+			case RTGUIK_DOWN:
+				if (view_mode == VIEW_DIR_MODE) picture_show_prev();
+				else if (view_mode == VIEW_FN_LIST_MODE)
+				{
+					if (picture_fn_list_current == 0)
+					{
+						picture_fn_list_current = picture_fn_list_size - 1;
+					}
+					else picture_fn_list_current --;
+
+					strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
+					rtgui_widget_update(RTGUI_WIDGET(picture_view));
+				}
+				break;
+			case RTGUIK_RETURN:
+			{
+				rtgui_view_t* view;
+				rtgui_workbench_t* workbench;
+				
+				/* close this view */
+				current_fn[0] = '\0';
+				
+				/* remove view in workbench */
+				view = RTGUI_VIEW(widget);
+				workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
+				rtgui_workbench_remove_view(workbench, view);
+				rtgui_view_destroy(view);
+				
+				picture_view = RT_NULL;
+			}
+				break;
+			}
+		}
+		return RT_FALSE;
+	}
+
+	return rtgui_view_event_handler(widget, event);
+}
+
+rtgui_view_t *picture_view_create(struct rtgui_workbench* workbench)
+{
+    if (picture_view != RT_NULL)
+    {
+        rtgui_view_show(picture_view, RT_FALSE);
+    }
+	else
+	{
+	    /* create picture view */
+	    picture_view = rtgui_view_create("Picture Presentation");
+		rtgui_widget_set_event_handler(RTGUI_WIDGET(picture_view),
+	        picture_view_event_handler);
+	
+		rtgui_workbench_add_view(workbench, picture_view);
+		/* this view can be focused */
+		RTGUI_WIDGET(picture_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+	}
+
+	return picture_view;
+}
+
+rtgui_view_t *picture_view_create_view_file(struct rtgui_workbench* workbench,
+	const char* filename)
+{
+    if (picture_view != RT_NULL)
+    {
+        rtgui_view_show(picture_view, RT_FALSE);
+    }
+	else
+	{
+		strcpy(current_fn, filename);
+
+	    /* create picture view */
+	    picture_view = rtgui_view_create("Picture Presentation");
+		rtgui_widget_set_event_handler(RTGUI_WIDGET(picture_view),
+	        picture_view_event_handler);
+	
+		rtgui_workbench_add_view(workbench, picture_view);
+		/* this view can be focused */
+		RTGUI_WIDGET(picture_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+		
+		view_mode = VIEW_SINGLE_MODE;
+	}
+
+	return picture_view;
+}
+
+rtgui_view_t *picture_view_create_view_list(struct rtgui_workbench* workbench,
+	const char* list[], rt_uint8_t size)
+{
+    if (picture_view != RT_NULL)
+    {
+        rtgui_view_show(picture_view, RT_FALSE);
+    }
+	else
+	{
+		picture_fn_list = list;
+		picture_fn_list_size = size; 
+		picture_fn_list_current = 0;
+		strcpy(current_fn, picture_fn_list[picture_fn_list_current]);
+
+	    /* create picture view */
+	    picture_view = rtgui_view_create("Picture Presentation");
+		rtgui_widget_set_event_handler(RTGUI_WIDGET(picture_view),
+	        picture_view_event_handler);
+
+		rtgui_workbench_add_view(workbench, picture_view);
+		/* this view can be focused */
+		RTGUI_WIDGET(picture_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+
+		view_mode = VIEW_FN_LIST_MODE;
+	}
+
+	return picture_view;
+}

+ 8 - 0
bsp/mini2440/picture.h

@@ -0,0 +1,8 @@
+#ifndef __PICTURE_H__
+#define __PICTURE_H__
+
+rtgui_view_t *picture_view_create(struct rtgui_workbench* workbench);
+rtgui_view_t *picture_view_create_view_file(struct rtgui_workbench* workbench, const char* fn);
+rtgui_view_t *picture_view_create_view_list(struct rtgui_workbench* workbench, const char* list[], rt_uint8_t size);
+
+#endif

+ 8 - 2
bsp/mini2440/rtconfig.h

@@ -63,6 +63,9 @@
 /* Using Device System */
 /* Using Device System */
 #define RT_USING_DEVICE
 #define RT_USING_DEVICE
 
 
+/* Using Module System */
+#define RT_USING_MODULE
+
 /* SECTION: Console options */
 /* SECTION: Console options */
 /* the buffer size of console */
 /* the buffer size of console */
 #define RT_CONSOLEBUF_SIZE	128
 #define RT_CONSOLEBUF_SIZE	128
@@ -84,7 +87,7 @@
 /* SECTION: Device filesystem support */
 /* SECTION: Device filesystem support */
 /* using DFS support */
 /* using DFS support */
 #define RT_USING_DFS
 #define RT_USING_DFS
-#define RT_USING_DFS_ELMFATFS
+#define RT_USING_DFS_ELMFAT
 /* #define RT_USING_DFS_YAFFS2 */
 /* #define RT_USING_DFS_YAFFS2 */
 
 
 /* #define DFS_USING_WORKDIR */
 /* #define DFS_USING_WORKDIR */
@@ -96,6 +99,9 @@
 /* the max number of cached sector 		*/
 /* the max number of cached sector 		*/
 #define DFS_CACHE_MAX_NUM   		4
 #define DFS_CACHE_MAX_NUM   		4
 
 
+/* Enable freemodbus protocal stack*/
+/* #define RT_USING_MODBUS */
+
 /* SECTION: lwip, a lighwight TCP/IP protocol stack */
 /* SECTION: lwip, a lighwight TCP/IP protocol stack */
 /* Using lighweight TCP/IP protocol stack */
 /* Using lighweight TCP/IP protocol stack */
 #define RT_USING_LWIP
 #define RT_USING_LWIP
@@ -158,7 +164,7 @@
 #define RT_LWIP_TCPTHREAD_PRIORITY	128
 #define RT_LWIP_TCPTHREAD_PRIORITY	128
 
 
 /* mail box size of tcpip thread to wait for */
 /* mail box size of tcpip thread to wait for */
-#define RT_LWIP_TCPTHREAD_MBOX_SIZE	8
+#define RT_LWIP_TCPTHREAD_MBOX_SIZE	32
 
 
 /* thread stack size of tcpip thread */
 /* thread stack size of tcpip thread */
 #define RT_LWIP_TCPTHREAD_STACKSIZE	4096
 #define RT_LWIP_TCPTHREAD_STACKSIZE	4096

+ 41 - 0
bsp/mini2440/run_module.c

@@ -0,0 +1,41 @@
+/*
+ * File      : module.c
+ * This file is part of RT-Thread RTOS
+ * 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
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date           Author		Notes
+ * 2010-04-12      yi.qiu	first version
+ */
+
+#include <rtthread.h>
+#include <dfs_posix.h>
+
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+static char buffer[4096];
+
+void run_module(const char* filename)
+{
+	int fd, length;
+	struct dfs_stat s;
+
+	fd = open(filename, O_RDONLY, 0);
+	length = read(fd, buffer, 4096);
+	if (length == 0)
+	{
+		rt_kprintf("check: read file failed\n");
+		close(fd);
+		return;
+	}
+
+	rt_module_load(buffer, filename);
+}
+
+FINSH_FUNCTION_EXPORT(run_module, run module from file);
+#endif
+

+ 5 - 0
bsp/mini2440/startup.c

@@ -139,6 +139,11 @@ void rtthread_startup(void)
 	rt_device_init_all();
 	rt_device_init_all();
 #endif
 #endif
 
 
+#ifdef RT_USING_MODULE
+	/* init module system */
+	rt_system_module_init();
+#endif
+
 	/* init application */
 	/* init application */
 	rt_application_init();
 	rt_application_init();
 
 

+ 213 - 0
bsp/mini2440/today.c

@@ -0,0 +1,213 @@
+#include <rtgui/rtgui.h>
+#include <rtgui/image.h>
+#include <rtgui/rtgui_system.h>
+
+#include <rtgui/widgets/view.h>
+#include <rtgui/widgets/list_view.h>
+#include <rtgui/widgets/workbench.h>
+#include <rtgui/widgets/filelist_view.h>
+#include <string.h>
+
+#include "picture.h"
+
+static rtgui_image_t *background = RT_NULL;
+rtgui_image_t *selected_image = RT_NULL;
+
+static struct rtgui_view* function_view;
+static struct rtgui_view* home_view;
+static struct rtgui_workbench* workbench;
+
+const char *introduction_list[] = 
+{
+	"/rtt/01.hdc", 
+	"/rtt/02.hdc", 
+	"/rtt/03.hdc", 
+	"/rtt/04.hdc", 
+	"/rtt/05.hdc", 
+	"/rtt/06.hdc", 
+	"/rtt/07.hdc", 
+	"/rtt/08.hdc", 
+};
+
+void function_introduction(void* parameter)
+{
+	rtgui_view_t *view;
+
+	view = picture_view_create_view_list(workbench, introduction_list, 
+		sizeof(introduction_list)/sizeof(char*));
+	if (view != RT_NULL)
+	{
+	    rtgui_view_show(view, RT_FALSE);
+	}
+
+	return;
+}
+
+void function_filelist(void* parameter)
+{
+	rtgui_rect_t rect;
+	rtgui_view_t *view;
+
+	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
+	view = (rtgui_view_t*)rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
+	if (view != RT_NULL)
+	{
+	    rtgui_view_show(view, RT_FALSE);
+	}
+
+	return;
+}
+
+void function_osc(void* parameter)
+{
+	rtgui_view_t *view;
+	extern rtgui_view_t *osc_view_create(rtgui_workbench_t *workbench);
+
+	view = osc_view_create(workbench);
+	if (view != RT_NULL)
+	{
+	    rtgui_view_show(view, RT_FALSE);
+	}
+
+	return;
+}
+
+void function_device(void* parameter)
+{
+	rtgui_view_t *view;
+	extern rtgui_view_t *device_view_create(rtgui_workbench_t *workbench);
+
+	view = device_view_create(workbench);
+	if (view != RT_NULL)
+	{
+	    rtgui_view_show(view, RT_FALSE);
+	}
+
+	return;
+}
+
+void function_action(void* parameter)
+{
+	rt_kprintf("item action!\n");
+	return;
+}
+
+struct rtgui_list_item function_list[] =
+{
+	{"RT-Thread介绍", RT_NULL, function_introduction, RT_NULL},
+	{"文件浏览", RT_NULL, function_filelist, RT_NULL},
+	{"波形演示", RT_NULL, function_osc, RT_NULL},
+	{"设备信息", RT_NULL, function_device, RT_NULL},
+};
+
+static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
+{
+	if (event->type == RTGUI_EVENT_PAINT)
+	{
+		struct rtgui_dc* dc;
+		struct rtgui_rect rect;
+
+		dc = rtgui_dc_begin_drawing(widget);
+		if (dc == RT_NULL) return RT_FALSE;
+		rtgui_widget_get_rect(widget, &rect);
+
+		/* draw background */
+		background = rtgui_image_create_from_file("hdc", 
+			"/resource/bg.hdc", RT_FALSE);
+		if (background != RT_NULL)
+		{
+			rtgui_image_blit(background, dc, &rect);
+			rtgui_image_destroy(background);
+			
+			background = RT_NULL;
+		}
+		else
+		{
+			rtgui_dc_fill_rect(dc, &rect);
+		}
+		rtgui_dc_end_drawing(dc);
+
+		return RT_FALSE;
+	}
+	else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
+	{
+		struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
+        	if (emouse->button == RTGUI_MOUSE_BUTTON_UP | RTGUI_MOUSE_BUTTON_LEFT)
+        	{
+			rtgui_view_show(function_view, RT_FALSE);
+		}
+		return RT_FALSE;
+	}
+
+	return rtgui_view_event_handler(widget, event);
+}
+
+rt_bool_t today_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *event)
+{			
+    if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
+    {
+        struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
+        //if (emouse->button == RTGUI_MOUSE_BUTTON_UP | RTGUI_MOUSE_BUTTON_LEFT)
+	if(0)
+		{
+            /* active home view */
+            if (workbench->current_view != home_view)
+            {
+                rtgui_view_show(home_view, RT_FALSE);
+                return RT_FALSE;
+            }
+        }
+    }
+
+    return rtgui_workbench_event_handler(widget, event);
+}
+
+static void today_entry(void* parameter)
+{
+	rt_mq_t mq;
+	rtgui_rect_t rect;
+
+	mq = rt_mq_create("qToday", 256, 4, RT_IPC_FLAG_FIFO);
+	rtgui_thread_register(rt_thread_self(), mq);
+
+	selected_image = rtgui_image_create_from_file("hdc",
+		"/resource/select.hdc", RT_FALSE);
+
+	workbench = rtgui_workbench_create("main", "workbench");
+	if (workbench == RT_NULL) return;
+	rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), today_workbench_event_handler);
+
+    /* add home view */
+	home_view = rtgui_view_create("Home");
+	rtgui_widget_set_event_handler(RTGUI_WIDGET(home_view), home_view_event_handler);
+
+	rtgui_workbench_add_view(workbench, home_view);
+	/* this view can be focused */
+	RTGUI_WIDGET(home_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+	/* set widget focus */
+	rtgui_widget_focus(RTGUI_WIDGET(home_view));
+
+	rtgui_view_show(home_view, RT_FALSE);
+
+    /* add function view */
+	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
+	function_view = (struct rtgui_view*)rtgui_list_view_create(function_list,
+		sizeof(function_list)/sizeof(struct rtgui_list_item), &rect);
+	rtgui_workbench_add_view(workbench, function_view);
+
+	rtgui_workbench_event_loop(workbench);
+
+	rtgui_thread_deregister(rt_thread_self());
+	rt_mq_delete(mq);
+}
+
+void today_init()
+{
+    rt_thread_t tid;
+
+    tid = rt_thread_create("today",
+        today_entry, RT_NULL,
+        2048, 25, 10);
+
+    if (tid != RT_NULL) rt_thread_startup(tid);
+}

+ 7 - 6
bsp/mini2440/touch.c

@@ -95,7 +95,7 @@ void report_touch_input(int updown)
 	}
 	}
 
 
 	/* rt_kprintf("touch %s: ts.x: %d, ts.y: %d, count:%d\n", updown? "down" : "up",
 	/* rt_kprintf("touch %s: ts.x: %d, ts.y: %d, count:%d\n", updown? "down" : "up",
-		xp, yp, ts.count); */
+		xp, yp, ts.count);  */
 
 
 	emouse.button |= RTGUI_MOUSE_BUTTON_LEFT;
 	emouse.button |= RTGUI_MOUSE_BUTTON_LEFT;
 
 
@@ -122,7 +122,7 @@ static void touch_timer_fire(void)
 	ADCCON |= S3C2410_ADCCON_ENABLE_START;
 	ADCCON |= S3C2410_ADCCON_ENABLE_START;
 }
 }
 
 
-void s3c2410_adc_stylus_action()
+void s3c2410_adc_stylus_action(void)
 {
 {
 	rt_uint32_t data0;
 	rt_uint32_t data0;
 	rt_uint32_t data1;
 	rt_uint32_t data1;
@@ -148,7 +148,7 @@ void s3c2410_adc_stylus_action()
 	}
 	}
 }
 }
 
 
-void s3c2410_intc_stylus_updown()
+void s3c2410_intc_stylus_updown(void)
 {
 {
 	rt_uint32_t data0;
 	rt_uint32_t data0;
 	rt_uint32_t data1;
 	rt_uint32_t data1;
@@ -186,13 +186,13 @@ void s3c2410_intc_stylus_updown()
 
 
 void rt_touch_handler(int irqno)
 void rt_touch_handler(int irqno)
 {
 {
-	if (SUBSRCPND & (1 << 10))
+	if (SUBSRCPND & BIT_SUB_ADC)
 	{
 	{
 		/* INT_SUB_ADC */
 		/* INT_SUB_ADC */
 		s3c2410_adc_stylus_action();
 		s3c2410_adc_stylus_action();
 	}
 	}
 
 
-	if (SUBSRCPND & (1 << 9))
+	if (SUBSRCPND & BIT_SUB_TC)
 	{
 	{
 		/* INT_SUB_TC */
 		/* INT_SUB_TC */
 		s3c2410_intc_stylus_updown();
 		s3c2410_intc_stylus_updown();
@@ -202,7 +202,7 @@ void rt_touch_handler(int irqno)
 	INTPND |= (rt_uint32_t)(1 << INTADC);
 	INTPND |= (rt_uint32_t)(1 << INTADC);
 }
 }
 
 
-void rt_hw_touch_init()
+void rt_hw_touch_init(void)
 {
 {
 	/* init touch screen structure */
 	/* init touch screen structure */
 	rt_memset(&ts, 0, sizeof(struct s3c2410ts));
 	rt_memset(&ts, 0, sizeof(struct s3c2410ts));
@@ -233,3 +233,4 @@ void rt_hw_touch_init()
 
 
 	first_down_report = 1;
 	first_down_report = 1;
 }
 }
+

+ 18 - 2
components/hello/hello.c

@@ -1,6 +1,22 @@
 #include <rtthread.h>
 #include <rtthread.h>
 
 
-void hello()
+static int a = 0;
+int b = 1000000;
+
+void function(int count1, int count2)
 {
 {
-    rt_kprintf("Hello RT-Thread\n");
+	rt_kprintf("Hello RT-Thread %d %d\n", count1, count2);
+}
+
+int rtm_main(void)
+{
+	int i;
+	for(i=0; i<1000; i++) 
+	{	
+		a++;
+		b--;
+		function(a, b);
+	}
+
+	return 0;
 }
 }

+ 3 - 0
components/hello/mk.bat

@@ -0,0 +1,3 @@
+set PATH="E:\Program Files\CodeSourcery\Sourcery G++ Lite\bin";%PATH%
+arm-none-eabi-gcc -c hello.c -o hello.o -DRT_MODULE "-I..\..\include" "-I..\..\bsp\mini2440"
+arm-none-eabi-gcc -o hello.mo -r -d -e rtm_main -nostdlib hello.o

+ 3 - 0
components/thread/mk.bat

@@ -0,0 +1,3 @@
+set PATH="E:\Program Files\CodeSourcery\Sourcery G++ Lite\bin";%PATH%
+arm-none-eabi-gcc -c module_thread_dynamic.c -o module_thread_dynamic.o -DRT_MODULE "-I..\..\include" "-I..\..\bsp\mini2440"
+arm-none-eabi-gcc -o dynamic.mo -r -d -e rtm_main -nostdlib module_thread_dynamic.o

+ 4 - 2
components/thread/module_thread_dynamic.c

@@ -1,5 +1,9 @@
 #include <rtthread.h>
 #include <rtthread.h>
 
 
+#define THREAD_PRIORITY		25
+#define THREAD_STACK_SIZE	512
+#define THREAD_TIMESLICE	5
+
 static void thread_entry(void* parameter)
 static void thread_entry(void* parameter)
 {
 {
 	rt_kprintf("thread dynamicly created ok\n");
 	rt_kprintf("thread dynamicly created ok\n");
@@ -16,8 +20,6 @@ int rtm_main()
 		THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
 		THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
 	if (tid != RT_NULL)
 	if (tid != RT_NULL)
 		rt_thread_startup(tid);
 		rt_thread_startup(tid);
-	else
-		tc_stat(TC_STAT_END | TC_STAT_FAILED);
 
 
 	return 0;
 	return 0;
 }
 }

+ 22 - 0
finsh/cmd.c

@@ -336,6 +336,28 @@ int list_device()
 FINSH_FUNCTION_EXPORT(list_device, list device in system)
 FINSH_FUNCTION_EXPORT(list_device, list device in system)
 #endif
 #endif
 
 
+#ifdef RT_USING_MODULE
+int list_module()
+{
+	struct rt_module *module;
+	struct rt_list_node *list, *node;
+
+	list = &rt_object_container[RT_Object_Class_Module].object_list;
+
+	rt_kprintf("module    entry      stack size\n");
+	rt_kprintf("-------- ---------- ----------\n");
+	for (node = list->next; node != list; node = node->next)
+	{
+		module = (struct rt_device*)(rt_list_entry(node, struct rt_object, list));
+		rt_kprintf("%-8s 0x%08x 0x%08x \n", module->parent.name, (rt_uint32_t)module->module_entry,
+			module->stack_size);
+	}
+
+	return 0;
+}
+FINSH_FUNCTION_EXPORT(list_module, list module in system)
+#endif
+
 int list()
 int list()
 {
 {
 	struct finsh_syscall_item* syscall_item;
 	struct finsh_syscall_item* syscall_item;

+ 0 - 5
src/kservice.c

@@ -977,9 +977,4 @@ char *strdup(const char *s) __attribute__((weak, alias("rt_strdup")));
 #endif
 #endif
 #endif
 #endif
 
 
-#ifdef RT_USING_MODULE
-#include <rtm.h>
-/* some buildin kernel symbol */
-RTM_EXPORT(rt_kprintf)
-#endif
 /*@}*/
 /*@}*/

+ 21 - 11
src/module.c

@@ -19,6 +19,19 @@
 #include "module.h"
 #include "module.h"
 #include "kservice.h"
 #include "kservice.h"
 
 
+/* #define RT_MODULE_DEBUG */
+
+#define elf_module 	((Elf32_Ehdr *)module_ptr)
+#define shdr		((Elf32_Shdr *)((rt_uint8_t *)module_ptr + elf_module->e_shoff))
+
+#define IS_PROG(s)		(s.sh_type == SHT_PROGBITS)
+#define IS_NOPROG(s)	(s.sh_type == SHT_NOBITS)
+#define IS_REL(s)		(s.sh_type == SHT_REL)
+#define IS_RELA(s)		(s.sh_type == SHT_RELA)
+#define IS_ALLOC(s)		(s.sh_flags == SHF_ALLOC)
+#define IS_AX(s)		((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_EXECINSTR))
+#define IS_AW(s)		((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_WRITE))
+
 #ifdef RT_USING_MODULE
 #ifdef RT_USING_MODULE
 rt_list_t rt_module_symbol_list;
 rt_list_t rt_module_symbol_list;
 struct rt_module* rt_current_module;
 struct rt_module* rt_current_module;
@@ -55,17 +68,6 @@ rt_uint32_t rt_module_symbol_find(const rt_uint8_t* sym_str)
 	return 0;
 	return 0;
 }
 }
 
 
-#define elf_module 	((Elf32_Ehdr *)module_ptr)
-#define shdr		((Elf32_Shdr *)((rt_uint8_t *)module_ptr + elf_module->e_shoff))
-
-#define IS_PROG(s)		(s.sh_type == SHT_PROGBITS)
-#define IS_NOPROG(s)	(s.sh_type == SHT_NOBITS)
-#define IS_REL(s)		(s.sh_type == SHT_REL)
-#define IS_RELA(s)		(s.sh_type == SHT_RELA)
-#define IS_ALLOC(s)		(s.sh_flags == SHF_ALLOC)
-#define IS_AX(s)		((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_EXECINSTR))
-#define IS_AW(s)		((s.sh_flags & SHF_ALLOC) && (s.sh_flags & SHF_WRITE))
-
 int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf32_Addr sym_val, rt_uint32_t module_addr)
 int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf32_Addr sym_val, rt_uint32_t module_addr)
 {
 {
 	Elf32_Addr *where, tmp;
 	Elf32_Addr *where, tmp;
@@ -79,7 +81,9 @@ int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf32_Addr
 
 
 	case R_ARM_ABS32:
 	case R_ARM_ABS32:
 		*where += (Elf32_Addr)sym_val;
 		*where += (Elf32_Addr)sym_val;
+#ifdef RT_MODULE_DEBUG
 		rt_kprintf("R_ARM_ABS32: %x -> %x\n", where, *where);
 		rt_kprintf("R_ARM_ABS32: %x -> %x\n", where, *where);
+#endif
 		break;
 		break;
 
 
 	case R_ARM_PC24:
 	case R_ARM_PC24:
@@ -92,7 +96,9 @@ int rt_module_arm_relocate(struct rt_module* module, Elf32_Rel *rel, Elf32_Addr
 		tmp = sym_val - (Elf32_Addr)where + (addend << 2);
 		tmp = sym_val - (Elf32_Addr)where + (addend << 2);
 		tmp >>= 2;
 		tmp >>= 2;
 		*where = (*where & 0xff000000) | (tmp & 0x00ffffff);
 		*where = (*where & 0xff000000) | (tmp & 0x00ffffff);
+#ifdef RT_MODULE_DEBUG
 		rt_kprintf("R_ARM_PC24: %x -> %x\n", where, *where);
 		rt_kprintf("R_ARM_PC24: %x -> %x\n", where, *where);
+#endif
 		break;
 		break;
 
 
 	default:
 	default:
@@ -275,7 +281,9 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name)
 			for (i = 0; i < nr_reloc; i ++)
 			for (i = 0; i < nr_reloc; i ++)
 			{
 			{
 				Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
 				Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
+#ifdef RT_MODULE_DEBUG
 				rt_kprintf("relocate symbol: %s\n", strtab + sym->st_name);
 				rt_kprintf("relocate symbol: %s\n", strtab + sym->st_name);
+#endif
 				if (sym->st_shndx != STN_UNDEF)
 				if (sym->st_shndx != STN_UNDEF)
 				{				
 				{				
 					if(ELF_ST_TYPE(sym->st_info) == STT_SECTION)
 					if(ELF_ST_TYPE(sym->st_info) == STT_SECTION)
@@ -310,7 +318,9 @@ struct rt_module* rt_module_load(void* module_ptr, const rt_uint8_t* name)
 				}
 				}
 				else
 				else
 				{
 				{
+#ifdef RT_MODULE_DEBUG
 					rt_kprintf("unresolved relocate symbol: %s\n", strtab + sym->st_name);
 					rt_kprintf("unresolved relocate symbol: %s\n", strtab + sym->st_name);
+#endif
 					/* need to resolve symbol in kernel symbol table */
 					/* need to resolve symbol in kernel symbol table */
 					Elf32_Addr addr = rt_module_symbol_find(strtab + sym->st_name);
 					Elf32_Addr addr = rt_module_symbol_find(strtab + sym->st_name);
 					if (addr != (Elf32_Addr)RT_NULL)
 					if (addr != (Elf32_Addr)RT_NULL)

+ 10 - 0
src/object.c

@@ -21,6 +21,10 @@
 
 
 #include "kservice.h"
 #include "kservice.h"
 
 
+#ifdef RT_USING_MODULE
+extern struct rt_module* rt_current_module;
+#endif
+
 #define _OBJ_CONTAINER_LIST_INIT(c) 	\
 #define _OBJ_CONTAINER_LIST_INIT(c) 	\
 	{&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)}
 	{&(rt_object_container[c].object_list), &(rt_object_container[c].object_list)}
 struct rt_object_information rt_object_container[RT_Object_Class_Unknown] =
 struct rt_object_information rt_object_container[RT_Object_Class_Unknown] =
@@ -249,8 +253,14 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
 	register rt_base_t temp;
 	register rt_base_t temp;
 	struct rt_object_information* information;
 	struct rt_object_information* information;
 
 
+#ifdef RT_USING_MODULE
+	/* get module object information */
+	information = (rt_current_module != RT_NULL) ? 
+		&rt_current_module->module_object[type] : &rt_object_container[type];
+#else
 	/* get object information */
 	/* get object information */
 	information = &rt_object_container[type];
 	information = &rt_object_container[type];
+#endif
 
 
 	object = (struct rt_object*)rt_malloc(information->object_size);
 	object = (struct rt_object*)rt_malloc(information->object_size);
 	if (object == RT_NULL)
 	if (object == RT_NULL)

+ 36 - 0
src/rtm.c

@@ -0,0 +1,36 @@
+/*
+ * File      : module.c
+ * This file is part of RT-Thread RTOS
+ * 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
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date           Author		Notes
+ * 2010-04-12      yi.qiu	first version
+ */
+
+#include <rtthread.h> 
+#include <rtm.h>
+
+/* some buildin kernel symbol */
+
+/* thread symbol */
+RTM_EXPORT(rt_thread_init)
+RTM_EXPORT(rt_thread_detach)
+RTM_EXPORT(rt_thread_create)
+RTM_EXPORT(rt_thread_self)
+RTM_EXPORT(rt_thread_find)
+RTM_EXPORT(rt_thread_startup)
+RTM_EXPORT(rt_thread_delete)
+RTM_EXPORT(rt_thread_yield)
+RTM_EXPORT(rt_thread_delay)
+RTM_EXPORT(rt_thread_control)
+RTM_EXPORT(rt_thread_suspend)
+RTM_EXPORT(rt_thread_resume)
+RTM_EXPORT(rt_thread_timeout)
+
+/* kservice symbol */
+RTM_EXPORT(rt_kprintf)

+ 8 - 0
src/scheduler.c

@@ -35,6 +35,9 @@ rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
 struct rt_thread* rt_current_thread;
 struct rt_thread* rt_current_thread;
 
 
 rt_uint8_t rt_current_priority;
 rt_uint8_t rt_current_priority;
+#ifdef RT_USING_MODULE
+extern struct rt_module* rt_current_module;
+#endif
 
 
 #if RT_THREAD_PRIORITY_MAX > 32
 #if RT_THREAD_PRIORITY_MAX > 32
 /* maximun priority level, 256 */
 /* maximun priority level, 256 */
@@ -260,6 +263,11 @@ void rt_schedule()
             from_thread = rt_current_thread;
             from_thread = rt_current_thread;
             rt_current_thread = to_thread;
             rt_current_thread = to_thread;
 
 
+#ifdef RT_USING_MODULE
+            if(rt_current_thread->module_parent != RT_NULL)	
+                rt_current_module = rt_current_thread->module_parent;
+#endif
+
 #ifdef RT_USING_HOOK
 #ifdef RT_USING_HOOK
             if (rt_scheduler_hook != RT_NULL) rt_scheduler_hook(from_thread, to_thread);
             if (rt_scheduler_hook != RT_NULL) rt_scheduler_hook(from_thread, to_thread);
 #endif
 #endif

+ 10 - 22
src/thread.c

@@ -32,6 +32,10 @@ extern rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
 extern struct rt_thread* rt_current_thread;
 extern struct rt_thread* rt_current_thread;
 extern rt_uint8_t rt_current_priority;
 extern rt_uint8_t rt_current_priority;
 
 
+#ifdef RT_USING_MODULE
+extern struct rt_module* rt_current_module;
+#endif
+
 #ifdef RT_USING_HEAP
 #ifdef RT_USING_HEAP
 extern rt_list_t rt_thread_defunct;
 extern rt_list_t rt_thread_defunct;
 #endif
 #endif
@@ -78,7 +82,8 @@ static rt_err_t _rt_thread_init(struct rt_thread* thread,
 
 
 #ifdef RT_USING_MODULE
 #ifdef RT_USING_MODULE
 	/* init module parent */
 	/* init module parent */
-	thread->module_parent = RT_NULL;
+	thread->module_parent = 
+		(rt_current_module != RT_NULL) ? rt_current_module : RT_NULL;
 #endif
 #endif
 
 
 	/* init user data */
 	/* init user data */
@@ -228,12 +233,12 @@ rt_err_t rt_thread_startup (rt_thread_t thread)
 static void rt_thread_exit()
 static void rt_thread_exit()
 {
 {
 	struct rt_thread* thread;
 	struct rt_thread* thread;
-    register rt_base_t temp;
+	register rt_base_t temp;
 
 
-    /* disable interrupt */
-    temp = rt_hw_interrupt_disable();
+	/* disable interrupt */
+	temp = rt_hw_interrupt_disable();
 
 
-    /* get current thread */
+	/* get current thread */
 	thread = rt_current_thread;
 	thread = rt_current_thread;
 
 
 	/* remove from schedule */
 	/* remove from schedule */
@@ -628,21 +633,4 @@ rt_thread_t rt_thread_find(char* name)
 	return thread;
 	return thread;
 }
 }
 
 
-#ifdef RT_USING_MODULE
-#include <rtm.h>
-/* some buildin kernel symbol */
-RTM_EXPORT(rt_thread_init)
-RTM_EXPORT(rt_thread_detach)
-RTM_EXPORT(rt_thread_create)
-RTM_EXPORT(rt_thread_self)
-RTM_EXPORT(rt_thread_find)
-RTM_EXPORT(rt_thread_startup)
-RTM_EXPORT(rt_thread_delete)
-RTM_EXPORT(rt_thread_yield)
-RTM_EXPORT(rt_thread_delay)
-RTM_EXPORT(rt_thread_control)
-RTM_EXPORT(rt_thread_suspend)
-RTM_EXPORT(rt_thread_resume)
-RTM_EXPORT(rt_thread_timeout)
-#endif
 /*@}*/
 /*@}*/