Skip to content

Commit fe0c272

Browse files
committed
Update example
1 parent 5e2406f commit fe0c272

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

examples/Wasm_Blink/Wasm_Blink.ino

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
#define LED_BUILTIN 13
1414
#endif
1515

16+
#define WASM_STACK_SLOTS 1024
17+
#define NATIVE_STACK_SIZE 32768
18+
1619
/*
1720
* WebAssembly app
1821
*
1922
* This is essentially a simple "Blink" sketch, compiled to WebAssembly
2023
* The file was generated from ./wasm_apps/cpp
21-
* You can also find examples for Rust, TinyGO
24+
* You can also find examples for Rust, AssemblyScript, TinyGo
2225
*/
2326

2427
unsigned char app_wasm[] = {
@@ -122,7 +125,7 @@ m3ApiRawFunction(m3_dummy)
122125
m3ApiSuccess();
123126
}
124127

125-
M3Result m3_LinkArduino (IM3Runtime runtime)
128+
M3Result LinkArduino (IM3Runtime runtime)
126129
{
127130
IM3Module module = runtime->modules;
128131
const char* arduino = "arduino";
@@ -150,31 +153,31 @@ void wasm_task(void*)
150153
M3Result result = m3Err_none;
151154

152155
IM3Environment env = m3_NewEnvironment ();
153-
if (!env) FATAL("m3_NewEnvironment", "failed");
156+
if (!env) FATAL("NewEnvironment", "failed");
154157

155-
IM3Runtime runtime = m3_NewRuntime (env, 1024, NULL);
156-
if (!runtime) FATAL("m3_NewRuntime", "failed");
158+
IM3Runtime runtime = m3_NewRuntime (env, WASM_STACK_SLOTS, NULL);
159+
if (!runtime) FATAL("NewRuntime", "failed");
157160

158161
IM3Module module;
159162
result = m3_ParseModule (env, &module, app_wasm, app_wasm_len-1);
160-
if (result) FATAL("m3_ParseModule", result);
163+
if (result) FATAL("ParseModule", result);
161164

162165
result = m3_LoadModule (runtime, module);
163-
if (result) FATAL("m3_LoadModule", result);
166+
if (result) FATAL("LoadModule", result);
164167

165-
result = m3_LinkArduino (runtime);
166-
if (result) FATAL("m3_LinkArduino", result);
168+
result = LinkArduino (runtime);
169+
if (result) FATAL("LinkArduino", result);
167170

168171
IM3Function f;
169172
result = m3_FindFunction (&f, runtime, "_start");
170-
if (result) FATAL("m3_FindFunction", result);
173+
if (result) FATAL("FindFunction", result);
171174

172175
Serial.println("Running WebAssembly...\n");
173176

174177
const char* i_argv[1] = { NULL };
175178
result = m3_CallWithArgs (f, 0, i_argv);
176179

177-
if (result) FATAL("m3_CallWithArgs", result);
180+
if (result) FATAL("CallWithArgs", result);
178181

179182
// Should not arrive here
180183
}
@@ -188,7 +191,7 @@ void setup()
188191

189192
#ifdef ESP32
190193
// On ESP32, we can launch in a separate thread
191-
xTaskCreate(&wasm_task, "wasm3", 32768, NULL, 5, NULL);
194+
xTaskCreate(&wasm_task, "wasm3", NATIVE_STACK_SIZE, NULL, 5, NULL);
192195
#else
193196
wasm_task(NULL);
194197
#endif

0 commit comments

Comments
 (0)