summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorqiuyiuestc <[email protected]>2010-11-21 23:12:42 +0000
committerqiuyiuestc <[email protected]>2010-11-21 23:12:42 +0000
commit5f838f86aabed563975deb7cf01c04b96e1df0c8 (patch)
tree69e887cf0f79b565cbc6dc1cb8993a3fe0e7c889 /components
parent03951e4e38690ee0505c628156d9546142cb148c (diff)
add libdl and extension examples
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1080 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components')
-rw-r--r--components/module/SConstruct6
-rw-r--r--components/module/extapp/SConscript34
-rw-r--r--components/module/extapp/extapp.c35
-rw-r--r--components/module/extension/SConscript34
-rw-r--r--components/module/extension/extension.c33
5 files changed, 140 insertions, 2 deletions
diff --git a/components/module/SConstruct b/components/module/SConstruct
index ad16baf103..f7fdfd948a 100644
--- a/components/module/SConstruct
+++ b/components/module/SConstruct
@@ -32,5 +32,7 @@ Export('rtconfig')
Export('projects')
Export('TARGET')
-SConscript(RTT_ROOT + '/components/module/tetris/SConscript', variant_dir='build/tetris', duplicate=0)
-SConscript(RTT_ROOT + '/components/module/basicapp/SConscript', variant_dir='build/basicapp', duplicate=0)
+SConscript(RTT_ROOT + '/components/module/tetris/SConscript', duplicate=0)
+SConscript(RTT_ROOT + '/components/module/basicapp/SConscript', duplicate=0)
+SConscript(RTT_ROOT + '/components/module/extension/SConscript', duplicate=0)
+SConscript(RTT_ROOT + '/components/module/extapp/SConscript', duplicate=0) \ No newline at end of file
diff --git a/components/module/extapp/SConscript b/components/module/extapp/SConscript
new file mode 100644
index 0000000000..c3af53aba2
--- /dev/null
+++ b/components/module/extapp/SConscript
@@ -0,0 +1,34 @@
+Import('env')
+Import('projects')
+Import('RTT_ROOT')
+Import('rtconfig')
+Import('TARGET')
+
+RTMLINKER = RTT_ROOT + '/tools/rtmlinker.exe '
+
+# group definitions
+group = {}
+group['name'] = 'examples'
+group['src'] = Glob('*.c')
+group['CCFLAGS'] = ''
+group['CPPPATH'] = [RTT_ROOT + '/include', RTT_ROOT + '/components/module', RTT_ROOT + '/components/libdl']
+group['CPPDEFINES'] = ''
+
+target = 'extapp.so'
+POST_ACTION = RTMLINKER + '-l ' + TARGET + ' -o extapp.mo ' + '$TARGET'
+
+# add group to project list
+projects.append(group)
+
+src_local = Glob('extapp.c')
+
+env.Append(CCFLAGS = group['CCFLAGS'])
+env.Append(CPPPATH = group['CPPPATH'])
+env.Append(CPPDEFINES = group['CPPDEFINES'])
+module_env = env.Clone(CPPDEFINE = 'RT_MODULE')
+module_env = env.Clone(CCFLAGS = ' -mcpu=arm920t -O0 -fPIC')
+module_env.Replace(LINK = 'arm-none-eabi-ld')
+module_env.Replace(LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e rt_application_entry -nostdlib -s')
+module_env.Program(target, src_local)
+module_env.AddPostAction(target, POST_ACTION)
+
diff --git a/components/module/extapp/extapp.c b/components/module/extapp/extapp.c
new file mode 100644
index 0000000000..c638e9773c
--- /dev/null
+++ b/components/module/extapp/extapp.c
@@ -0,0 +1,35 @@
+#include <rtthread.h>
+#include <dlfcn.h>
+
+typedef void (*func)(void);
+
+int rt_application_entry(void)
+{
+ func f1, f2, f3, f4, f5;
+
+ void* handle = dlopen("/mo/ext.so", RTLD_NOW);
+ if(handle != RT_NULL)
+ {
+ f1= (func)dlsym(handle, "function1");
+ f2= (func)dlsym(handle, "function2");
+ f3= (func)dlsym(handle, "function3");
+ f4= (func)dlsym(handle, "function4");
+ f5= (func)dlsym(handle, "function5");
+
+ if(f1 != RT_NULL) f1();
+ else rt_kprintf("dlsym function1 failed.\n");
+ if(f2 != RT_NULL) f2();
+ else rt_kprintf("dlsym function2 failed.\n");
+ if(f3 != RT_NULL) f3();
+ else rt_kprintf("dlsym function3 failed.\n");
+ if(f4 != RT_NULL) f4();
+ else rt_kprintf("dlsym function4 failed.\n");
+ if(f5 != RT_NULL) f5();
+ else rt_kprintf("dlsym function5 failed.\n");
+ }
+
+ dlclose(handle);
+
+ return 0;
+}
+
diff --git a/components/module/extension/SConscript b/components/module/extension/SConscript
new file mode 100644
index 0000000000..98e126776f
--- /dev/null
+++ b/components/module/extension/SConscript
@@ -0,0 +1,34 @@
+Import('env')
+Import('projects')
+Import('RTT_ROOT')
+Import('rtconfig')
+Import('TARGET')
+
+RTMLINKER = RTT_ROOT + '/tools/rtmlinker.exe '
+
+# group definitions
+group = {}
+group['name'] = 'examples'
+group['src'] = Glob('*.c')
+group['CCFLAGS'] = ''
+group['CPPPATH'] = [RTT_ROOT + '/include', RTT_ROOT + '/components/module']
+group['CPPDEFINES'] = ''
+
+target = 'extension.so'
+POST_ACTION = RTMLINKER + '-l ' + TARGET + ' -o extension.mo ' + '$TARGET'
+
+# add group to project list
+projects.append(group)
+
+src_local = Glob('extension.c')
+
+env.Append(CCFLAGS = group['CCFLAGS'])
+env.Append(CPPPATH = group['CPPPATH'])
+env.Append(CPPDEFINES = group['CPPDEFINES'])
+module_env = env.Clone(CPPDEFINE = 'RT_MODULE')
+module_env = env.Clone(CCFLAGS = ' -mcpu=arm920t -O0 -fPIC')
+module_env.Replace(LINK = 'arm-none-eabi-ld')
+module_env.Replace(LINKFLAGS = '-z max-page-size=0x4 -e 0 -shared -fPIC -nostdlib -s')
+module_env.Program(target, src_local)
+module_env.AddPostAction(target, POST_ACTION)
+
diff --git a/components/module/extension/extension.c b/components/module/extension/extension.c
new file mode 100644
index 0000000000..e5dd094c54
--- /dev/null
+++ b/components/module/extension/extension.c
@@ -0,0 +1,33 @@
+#include <rtthread.h>
+#include <rtm.h>
+
+void function1(void)
+{
+ rt_kprintf("Hello RT-Thread function1\n");
+}
+
+void function2(void)
+{
+ rt_kprintf("Hello RT-Thread function2\n");
+}
+
+void function3(void)
+{
+ rt_kprintf("Hello RT-Thread function3\n");
+}
+
+void function4(void)
+{
+ rt_kprintf("Hello RT-Thread function4\n");
+}
+
+void function5(void)
+{
+ rt_kprintf("Hello RT-Thread function5\n");
+}
+
+RTM_EXPORT(function1)
+RTM_EXPORT(function2)
+RTM_EXPORT(function3)
+RTM_EXPORT(function4)
+RTM_EXPORT(function5) \ No newline at end of file