1. fix error while building project with RT-Thread Studio. (#497)

2. add macro to enable/disable export native method of rt-thread.
This commit is contained in:
alvkeke 2021-01-14 18:47:52 +08:00 committed by GitHub
parent 8ec03a5165
commit 794028a968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 7 deletions

View File

@ -32,24 +32,23 @@ if rtconfig.ARCH == 'arm':
if re.match('^cortex-m.*', rtconfig.CPU): if re.match('^cortex-m.*', rtconfig.CPU):
print('[WAMR] using thumbv4t') print('[WAMR] using thumbv4t')
CPPDEFINES += ['BUILD_TARGET_THUMB'] CPPDEFINES += ['BUILD_TARGET_THUMB']
CPPDEFINES += [r'BUILD_TARGET=\"thumbv4t\"'] CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_THUMB']
elif re.match('^cortex-a.*', rtconfig.CPU): elif re.match('^cortex-a.*', rtconfig.CPU):
print('[WAMR] using armv7') print('[WAMR] using armv7')
CPPDEFINES += ['BUILD_TARGET_ARM'] CPPDEFINES += ['BUILD_TARGET_ARM']
CPPDEFINES += [r'BUILD_TARGET=\"armv7\"'] CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV7']
elif re.match('^cortex-r.*', rtconfig.CPU): elif re.match('^cortex-r.*', rtconfig.CPU):
print('[WAMR] using armv7') print('[WAMR] using armv7')
CPPDEFINES += ['BUILD_TARGET_ARM'] CPPDEFINES += ['BUILD_TARGET_ARM']
CPPDEFINES += [r'BUILD_TARGET=\"armv7\"'] CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV7']
elif rtconfig.CPU == 'armv6': elif rtconfig.CPU == 'armv6':
print('[WAMR] using armv6') print('[WAMR] using armv6')
CPPDEFINES += ['BUILD_TARGET_ARM'] CPPDEFINES += ['BUILD_TARGET_ARM']
CPPDEFINES += [r'BUILD_TARGET=\"armv6\"'] CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV6']
elif re.match('^arm9*', rtconfig.CPU): elif re.match('^arm9*', rtconfig.CPU):
print('[WAMR] using armv4') print('[WAMR] using armv4')
CPPDEFINES += ['BUILD_TARGET_ARM'] CPPDEFINES += ['BUILD_TARGET_ARM']
CPPDEFINES += [r'BUILD_TARGET=\"armv4\"'] CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV4']
else: else:
print("[WAMR] unknown arch", rtconfig.ARCH) print("[WAMR] unknown arch", rtconfig.ARCH)

View File

@ -16,6 +16,20 @@
#include <stdint.h> #include <stdint.h>
#include <ctype.h> #include <ctype.h>
#if defined(WASM_ENABLE_AOT)
#if defined(RTT_WAMR_BUILD_TARGET_THUMB)
#define BUILD_TARGET "thumbv4t"
#elif defined(RTT_WAMR_BUILD_TARGET_ARMV7)
#define BUILD_TARGET "armv7"
#elif defined(RTT_WAMR_BUILD_TARGET_ARMV6)
#define BUILD_TARGET "armv6"
#elif defined(RTT_WAMR_BUILD_TARGET_ARMV4)
#define BUILD_TARGET "armv4"
#else
#error "unsupported aot platform."
#endif
#endif /* WASM_ENABLE_AOT */
typedef rt_thread_t korp_tid; typedef rt_thread_t korp_tid;
typedef struct rt_mutex korp_mutex; typedef struct rt_mutex korp_mutex;
typedef struct rt_thread korp_cond; typedef struct rt_thread korp_cond;

View File

@ -12,6 +12,9 @@
#include <dfs_fs.h> #include <dfs_fs.h>
#include <dfs_posix.h> #include <dfs_posix.h>
#ifdef WAMR_ENABLE_RTT_EXPORT
#ifdef WAMR_RTT_EXPORT_VPRINTF
static int wasm_vprintf(wasm_exec_env_t env, const char* fmt, va_list va) static int wasm_vprintf(wasm_exec_env_t env, const char* fmt, va_list va)
{ {
return vprintf(fmt, va); return vprintf(fmt, va);
@ -27,6 +30,9 @@ static int wasm_vsnprintf(wasm_exec_env_t env, char *buf, int n, const char *fmt
return vsnprintf(buf, n, fmt, va); return vsnprintf(buf, n, fmt, va);
} }
#endif /* WAMR_RTT_EXPORT_VPRINTF */
#ifdef WAMR_RTT_EXPORT_DEVICE_OPS
static rt_device_t wasm_rt_device_find(wasm_exec_env_t env, const char *name) static rt_device_t wasm_rt_device_find(wasm_exec_env_t env, const char *name)
{ {
return rt_device_find(name); 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
return rt_device_control(dev, cmd, arg); return rt_device_control(dev, cmd, arg);
} }
#endif /* WAMR_RTT_EXPORT_DEVICE_OPS */
static NativeSymbol native_export_symbols[] = { static NativeSymbol native_export_symbols[] = {
#ifdef WAMR_RTT_EXPORT_VPRINTF
{ {
"vprintf", "vprintf",
wasm_vprintf, wasm_vprintf,
@ -73,6 +83,9 @@ static NativeSymbol native_export_symbols[] = {
wasm_vsnprintf, wasm_vsnprintf,
"($i$*)i" "($i$*)i"
}, },
#endif /* WAMR_RTT_EXPORT_VPRINTF */
#ifdef WAMR_RTT_EXPORT_DEVICE_OPS
{ {
"rt_device_find", "rt_device_find",
wasm_rt_device_find, wasm_rt_device_find,
@ -102,9 +115,39 @@ static NativeSymbol native_export_symbols[] = {
"rt_device_control", "rt_device_control",
wasm_rt_device_control, wasm_rt_device_control,
"(ii*)i" "(ii*)i"
} },
#ifdef WAMR_RTT_EXPORT_DEVICE_OPS_CPP
{
"_Z15rt_device_closeP9rt_device",
wasm_rt_device_close,
"(i)i"
},
{
"_Z14rt_device_readP9rt_devicejPvj",
wasm_rt_device_read,
"(ii*~)i"
},
{
"_Z15rt_device_writeP9rt_devicejPKvj",
wasm_rt_device_write,
"(ii*~)i"
},
{
"_Z14rt_device_openP9rt_devicet",
wasm_rt_device_open,
"(ii)i"
},
{
"_Z14rt_device_findPKc",
wasm_rt_device_find,
"($)i"
},
#endif /* WAMR_RTT_EXPORT_DEVICE_OPS_CPP */
#endif /* WAMR_RTT_EXPORT_DEVICE_OPS */
}; };
#endif /* WAMR_ENABLE_RTT_EXPORT */
/** /**
* run WASM module instance. * run WASM module instance.
* @param module_inst instance of wasm module * @param module_inst instance of wasm module
@ -236,9 +279,11 @@ int iwasm(int argc, char **argv)
init_args.mem_alloc_option.allocator.malloc_func = os_malloc; init_args.mem_alloc_option.allocator.malloc_func = os_malloc;
init_args.mem_alloc_option.allocator.realloc_func = os_realloc; init_args.mem_alloc_option.allocator.realloc_func = os_realloc;
init_args.mem_alloc_option.allocator.free_func = os_free; init_args.mem_alloc_option.allocator.free_func = os_free;
#ifdef WAMR_ENABLE_RTT_EXPORT
init_args.native_symbols = native_export_symbols; init_args.native_symbols = native_export_symbols;
init_args.n_native_symbols = sizeof(native_export_symbols) / sizeof(NativeSymbol); init_args.n_native_symbols = sizeof(native_export_symbols) / sizeof(NativeSymbol);
init_args.native_module_name = "env"; init_args.native_module_name = "env";
#endif /* WAMR_ENABLE_RTT_EXPORT */
#ifdef WAMR_ENABLE_IWASM_PARAMS #ifdef WAMR_ENABLE_IWASM_PARAMS
#if defined(RT_USING_HEAP) && defined(RT_USING_MEMHEAP_AS_HEAP) #if defined(RT_USING_HEAP) && defined(RT_USING_MEMHEAP_AS_HEAP)