summaryrefslogtreecommitdiff
path: root/components/module/extapp
diff options
context:
space:
mode:
Diffstat (limited to 'components/module/extapp')
-rw-r--r--components/module/extapp/SConscript34
-rw-r--r--components/module/extapp/extapp.c35
2 files changed, 69 insertions, 0 deletions
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;
+}
+