Skip to content

Commit 794028a

Browse files
authored
1. fix error while building project with RT-Thread Studio. (#497)
2. add macro to enable/disable export native method of rt-thread.
1 parent 8ec03a5 commit 794028a

3 files changed

Lines changed: 65 additions & 7 deletions

File tree

build-scripts/SConscript_config

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,23 @@ if rtconfig.ARCH == 'arm':
3232
if re.match('^cortex-m.*', rtconfig.CPU):
3333
print('[WAMR] using thumbv4t')
3434
CPPDEFINES += ['BUILD_TARGET_THUMB']
35-
CPPDEFINES += [r'BUILD_TARGET=\"thumbv4t\"']
35+
CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_THUMB']
3636
elif re.match('^cortex-a.*', rtconfig.CPU):
3737
print('[WAMR] using armv7')
3838
CPPDEFINES += ['BUILD_TARGET_ARM']
39-
CPPDEFINES += [r'BUILD_TARGET=\"armv7\"']
39+
CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV7']
4040
elif re.match('^cortex-r.*', rtconfig.CPU):
4141
print('[WAMR] using armv7')
4242
CPPDEFINES += ['BUILD_TARGET_ARM']
43-
CPPDEFINES += [r'BUILD_TARGET=\"armv7\"']
43+
CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV7']
4444
elif rtconfig.CPU == 'armv6':
4545
print('[WAMR] using armv6')
4646
CPPDEFINES += ['BUILD_TARGET_ARM']
47-
CPPDEFINES += [r'BUILD_TARGET=\"armv6\"']
47+
CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV6']
4848
elif re.match('^arm9*', rtconfig.CPU):
4949
print('[WAMR] using armv4')
5050
CPPDEFINES += ['BUILD_TARGET_ARM']
51-
CPPDEFINES += [r'BUILD_TARGET=\"armv4\"']
52-
51+
CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV4']
5352
else:
5453
print("[WAMR] unknown arch", rtconfig.ARCH)
5554

core/shared/platform/rt-thread/platform_internal.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
#include <stdint.h>
1717
#include <ctype.h>
1818

19+
#if defined(WASM_ENABLE_AOT)
20+
#if defined(RTT_WAMR_BUILD_TARGET_THUMB)
21+
#define BUILD_TARGET "thumbv4t"
22+
#elif defined(RTT_WAMR_BUILD_TARGET_ARMV7)
23+
#define BUILD_TARGET "armv7"
24+
#elif defined(RTT_WAMR_BUILD_TARGET_ARMV6)
25+
#define BUILD_TARGET "armv6"
26+
#elif defined(RTT_WAMR_BUILD_TARGET_ARMV4)
27+
#define BUILD_TARGET "armv4"
28+
#else
29+
#error "unsupported aot platform."
30+
#endif
31+
#endif /* WASM_ENABLE_AOT */
32+
1933
typedef rt_thread_t korp_tid;
2034
typedef struct rt_mutex korp_mutex;
2135
typedef struct rt_thread korp_cond;

product-mini/platforms/rt-thread/rtt_wamr_entry.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include <dfs_fs.h>
1313
#include <dfs_posix.h>
1414

15+
#ifdef WAMR_ENABLE_RTT_EXPORT
16+
17+
#ifdef WAMR_RTT_EXPORT_VPRINTF
1518
static int wasm_vprintf(wasm_exec_env_t env, const char* fmt, va_list va)
1619
{
1720
return vprintf(fmt, va);
@@ -27,6 +30,9 @@ static int wasm_vsnprintf(wasm_exec_env_t env, char *buf, int n, const char *fmt
2730
return vsnprintf(buf, n, fmt, va);
2831
}
2932

33+
#endif /* WAMR_RTT_EXPORT_VPRINTF */
34+
35+
#ifdef WAMR_RTT_EXPORT_DEVICE_OPS
3036
static rt_device_t wasm_rt_device_find(wasm_exec_env_t env, const char *name)
3137
{
3238
return rt_device_find(name);
@@ -57,7 +63,11 @@ static rt_err_t wasm_rt_device_control(wasm_exec_env_t env, rt_device_t dev, in
5763
return rt_device_control(dev, cmd, arg);
5864
}
5965

66+
#endif /* WAMR_RTT_EXPORT_DEVICE_OPS */
67+
6068
static NativeSymbol native_export_symbols[] = {
69+
70+
#ifdef WAMR_RTT_EXPORT_VPRINTF
6171
{
6272
"vprintf",
6373
wasm_vprintf,
@@ -73,6 +83,9 @@ static NativeSymbol native_export_symbols[] = {
7383
wasm_vsnprintf,
7484
"($i$*)i"
7585
},
86+
#endif /* WAMR_RTT_EXPORT_VPRINTF */
87+
88+
#ifdef WAMR_RTT_EXPORT_DEVICE_OPS
7689
{
7790
"rt_device_find",
7891
wasm_rt_device_find,
@@ -102,9 +115,39 @@ static NativeSymbol native_export_symbols[] = {
102115
"rt_device_control",
103116
wasm_rt_device_control,
104117
"(ii*)i"
105-
}
118+
},
119+
#ifdef WAMR_RTT_EXPORT_DEVICE_OPS_CPP
120+
{
121+
"_Z15rt_device_closeP9rt_device",
122+
wasm_rt_device_close,
123+
"(i)i"
124+
},
125+
{
126+
"_Z14rt_device_readP9rt_devicejPvj",
127+
wasm_rt_device_read,
128+
"(ii*~)i"
129+
},
130+
{
131+
"_Z15rt_device_writeP9rt_devicejPKvj",
132+
wasm_rt_device_write,
133+
"(ii*~)i"
134+
},
135+
{
136+
"_Z14rt_device_openP9rt_devicet",
137+
wasm_rt_device_open,
138+
"(ii)i"
139+
},
140+
{
141+
"_Z14rt_device_findPKc",
142+
wasm_rt_device_find,
143+
"($)i"
144+
},
145+
#endif /* WAMR_RTT_EXPORT_DEVICE_OPS_CPP */
146+
#endif /* WAMR_RTT_EXPORT_DEVICE_OPS */
106147
};
107148

149+
#endif /* WAMR_ENABLE_RTT_EXPORT */
150+
108151
/**
109152
* run WASM module instance.
110153
* @param module_inst instance of wasm module
@@ -236,9 +279,11 @@ int iwasm(int argc, char **argv)
236279
init_args.mem_alloc_option.allocator.malloc_func = os_malloc;
237280
init_args.mem_alloc_option.allocator.realloc_func = os_realloc;
238281
init_args.mem_alloc_option.allocator.free_func = os_free;
282+
#ifdef WAMR_ENABLE_RTT_EXPORT
239283
init_args.native_symbols = native_export_symbols;
240284
init_args.n_native_symbols = sizeof(native_export_symbols) / sizeof(NativeSymbol);
241285
init_args.native_module_name = "env";
286+
#endif /* WAMR_ENABLE_RTT_EXPORT */
242287

243288
#ifdef WAMR_ENABLE_IWASM_PARAMS
244289
#if defined(RT_USING_HEAP) && defined(RT_USING_MEMHEAP_AS_HEAP)

0 commit comments

Comments
 (0)