Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add js intepreter #353

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 139 additions & 10 deletions board/TencentOS_Tiny_CH32V307_EVB/.cproject

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.openocd.launchConfigurationType">
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doContinue" value="true" />
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doDebugInRam" value="false" />
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doFirstReset" value="true" />
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true" />
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false" />
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doSecondReset" value="true" />
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbCLient" value="true" />
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbServer" value="true" />
<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.enableSemihosting" value="false" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.firstResetType" value="init" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off&#xD;&#xA;set architecture riscv:rv32&#xD;&#xA;set remotetimeout unlimited" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherOptions" value="" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerConnectionAddress" value="" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerExecutable" value="${eclipse_home}toolchain/OpenOCD/bin/openocd.exe" />
<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerLog" value="" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerOther" value="-f &quot;${eclipse_home}toolchain/OpenOCD/bin/wch-riscv.cfg&quot;" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTclPortNumber" value="6666" />
<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherInitCommands" value="" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherRunCommands" value="" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.secondResetType" value="halt" />
<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.svdPath" value="${eclipse_home}template/wizard/WCH/RISC-V/CH32V307/NoneOS/CH32V307xx.svd" />
<launchConfiguration type="com.mounriver.debug.gdbjtag.openocd.launchConfigurationType">
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doContinue" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doDebugInRam" value="false" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doFirstReset" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doSecondReset" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doStartGdbCLient" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doStartGdbServer" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.enableSemihosting" value="false" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.firstResetType" value="init" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off&#xD;&#xA;set architecture riscv:rv32&#xD;&#xA;set remotetimeout unlimited" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbClientOtherOptions" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerConnectionAddress" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerExecutable" value="${eclipse_home}toolchain/OpenOCD/bin/openocd.exe" />
<intAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerLog" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerOther" value="-f &quot;${eclipse_home}toolchain/OpenOCD/bin/wch-riscv.cfg&quot;" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerTclPortNumber" value="6666" />
<intAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.otherInitCommands" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.otherRunCommands" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.secondResetType" value="halt" />
<stringAttribute key="com.mounriver.debug.gdbjtag.svdPath" value="${eclipse_home}template/wizard/WCH/RISC-V/CH32V307/NoneOS/CH32V307xx.svd" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value="" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value="" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost" />
Expand Down
2 changes: 1 addition & 1 deletion board/TencentOS_Tiny_CH32V307_EVB/User/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int main(void)
LCD_ShowString(0,0,"Welcome to TencentOS",WHITE,BLACK,16,0);

tos_knl_init();
tos_task_create(&application_task, "application_task", application_entry, NULL, 4, application_task_stk, APPLICATION_TASK_STK_SIZE, 0);
tos_task_create(&application_task, "application_task", application_entry, NULL, 5, application_task_stk, APPLICATION_TASK_STK_SIZE, 0);
tos_knl_start();

printf("should not run at here!\r\n");
Expand Down
24 changes: 24 additions & 0 deletions board/TencentOS_Tiny_CH32V307_EVB/examples/hello_world.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "tos_k.h"
#include "tos_js.h"

#define TASK1_STK_SIZE 1024
k_task_t task1;
Expand All @@ -9,6 +10,10 @@ uint8_t task1_stk[TASK1_STK_SIZE];
k_task_t task2;
uint8_t task2_stk[TASK2_STK_SIZE];

#define TASK3_STK_SIZE 4096
k_task_t task3;
uint8_t task3_stk[TASK3_STK_SIZE];

void task1_entry(void *arg)
{
while (1) {
Expand All @@ -25,10 +30,29 @@ void task2_entry(void *arg)
}
}

char js_mem[6000];
void task3_entry(void *arg) {
printf("JS Beegin Running!\r\n");
struct js *js = tos_js_vm_create(js_mem, sizeof(js_mem));
js_run(js,
"let a = 1;"
"LCD_ShowString(0, 20, 'Greet from JS!');"
"let b = 1, c = 1, tmp = 1;"
"for (let i = 1; i <= 10; i++) {"
" a *= 2;"
" print('res:', a, 'c-fib:', fib(i), 'js-fib:', c);"
" tmp = b + c;"
" b = c;"
" c = tmp;"
" sleep(1000);"
"}"
);
}

void application_entry(void *arg)
{
tos_task_create(&task1, "task1", task1_entry, NULL, 3, task1_stk, TASK1_STK_SIZE, 0); // Create task1
tos_task_create(&task2, "task2", task2_entry, NULL, 3, task2_stk, TASK2_STK_SIZE, 0);// Create task2
tos_task_create(&task3, "task3", task3_entry, NULL, 4, task3_stk, TASK3_STK_SIZE, 0);// Create task3
}

Loading