2022-01-20 21:50:38 +08:00
|
|
|
#include "BaseObj.h"
|
2022-01-20 18:16:08 +08:00
|
|
|
#include "PikaVM.h"
|
|
|
|
|
|
|
|
extern PikaObj* __pikaMain;
|
|
|
|
void PikaStdTask_Task___init__(PikaObj* self) {
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(self,
|
|
|
|
"calls.__init__()\n"
|
|
|
|
"is_period = 0\n");
|
|
|
|
obj_setPtr(__pikaMain, "__calls", obj_getPtr(self, "calls"));
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
2022-01-20 21:50:38 +08:00
|
|
|
|
2022-01-20 18:16:08 +08:00
|
|
|
void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
|
|
|
obj_setArg(self, "fun_todo", fun_todo);
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(self,
|
|
|
|
"calls.append('always')\n"
|
|
|
|
"calls.append(fun_todo)\n");
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
2022-01-20 21:50:38 +08:00
|
|
|
|
2022-01-20 22:24:08 +08:00
|
|
|
void PikaStdTask_Task_call_when(PikaObj* self, Arg* fun_todo, Arg* fun_when) {
|
|
|
|
obj_setArg(self, "fun_todo", fun_todo);
|
|
|
|
obj_setArg(self, "fun_when", fun_when);
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(self,
|
|
|
|
"calls.append('when')\n"
|
|
|
|
"calls.append(fun_when)\n"
|
|
|
|
"calls.append(fun_todo)\n");
|
2022-01-23 21:50:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdTask_Task_call_period_ms(PikaObj* self,
|
|
|
|
Arg* fun_todo,
|
|
|
|
int period_ms) {
|
|
|
|
obj_setArg(self, "fun_todo", fun_todo);
|
|
|
|
obj_setInt(self, "period_ms", period_ms);
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(self,
|
|
|
|
"calls.append('period_ms')\n"
|
|
|
|
"calls.append(period_ms)\n"
|
|
|
|
"calls.append(fun_todo)\n"
|
2022-01-24 19:08:33 +08:00
|
|
|
"calls.append(0)\n"
|
2022-01-24 18:50:20 +08:00
|
|
|
"is_period = 1\n");
|
2022-01-20 22:24:08 +08:00
|
|
|
}
|
2022-01-20 18:16:08 +08:00
|
|
|
|
|
|
|
void PikaStdTask_Task_run_once(PikaObj* self) {
|
2022-01-23 21:50:05 +08:00
|
|
|
/* transfer the tick to pikaMain */
|
|
|
|
obj_setInt(__pikaMain, "__tick", obj_getInt(self, "tick"));
|
2022-01-24 20:03:44 +08:00
|
|
|
/* Python
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(__pikaMain,
|
|
|
|
"len = __calls.len()\n"
|
|
|
|
"mode = 'none'\n"
|
|
|
|
"info_index = 0\n"
|
|
|
|
"for i in range(0, len):\n"
|
|
|
|
" if len == 0:\n"
|
|
|
|
" break\n"
|
|
|
|
" if info_index == 0:\n"
|
|
|
|
" mode = __calls[i]\n"
|
|
|
|
" info_index = 1\n"
|
|
|
|
" elif info_index == 1:\n"
|
|
|
|
" if mode == 'always':\n"
|
|
|
|
" todo = __calls[i]\n"
|
|
|
|
" todo()\n"
|
|
|
|
" info_index = 0\n"
|
|
|
|
" elif mode == 'when':\n"
|
|
|
|
" when = __calls[i]\n"
|
|
|
|
" info_index = 2\n"
|
2022-01-24 19:08:33 +08:00
|
|
|
" elif mode == 'period_ms':\n"
|
|
|
|
" period_ms = __calls[i]\n"
|
|
|
|
" info_index = 2\n"
|
2022-01-24 18:50:20 +08:00
|
|
|
" elif info_index == 2:\n"
|
|
|
|
" if mode == 'when':\n"
|
|
|
|
" if when():\n"
|
|
|
|
" todo = __calls[i]\n"
|
|
|
|
" todo()\n"
|
2022-01-24 19:08:33 +08:00
|
|
|
" info_index = 0\n"
|
|
|
|
" elif mode == 'period_ms':\n"
|
|
|
|
" todo = __calls[i]\n"
|
|
|
|
" info_index = 3\n"
|
|
|
|
" elif info_index == 3:\n"
|
|
|
|
" if mode == 'period_ms':\n"
|
|
|
|
" if __tick > __calls[i]:\n"
|
|
|
|
" todo()\n"
|
|
|
|
" __calls[i] = __tick + period_ms\n"
|
|
|
|
" info_index = 0\n"
|
2022-01-24 18:50:20 +08:00
|
|
|
"\n");
|
2022-01-23 21:50:05 +08:00
|
|
|
*/
|
2022-03-17 16:47:03 +08:00
|
|
|
const uint8_t bytes[] = {
|
|
|
|
0x08, 0x02, /* instruct array size */
|
|
|
|
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x0d, 0x00, 0x00, 0x83, 0x11, 0x00,
|
|
|
|
0x00, 0x04, 0x16, 0x00, 0x00, 0x85, 0x1b, 0x00, 0x00, 0x04, 0x1d, 0x00,
|
|
|
|
0x20, 0x85, 0x1b, 0x00, 0x20, 0x01, 0x0d, 0x00, 0x10, 0x02, 0x28, 0x00,
|
|
|
|
0x00, 0x02, 0x2e, 0x00, 0x00, 0x04, 0x33, 0x00, 0x00, 0x01, 0x37, 0x00,
|
|
|
|
0x00, 0x01, 0x3b, 0x00, 0x00, 0x01, 0x3f, 0x00, 0x00, 0x04, 0x43, 0x00,
|
|
|
|
0x00, 0x04, 0x4a, 0x00, 0x00, 0x04, 0x51, 0x00, 0x00, 0x82, 0x58, 0x00,
|
|
|
|
0x00, 0x04, 0x65, 0x00, 0x00, 0x0d, 0x65, 0x00, 0x00, 0x07, 0x67, 0x00,
|
|
|
|
0x11, 0x81, 0x0d, 0x00, 0x11, 0x05, 0x1b, 0x00, 0x01, 0x08, 0x69, 0x00,
|
|
|
|
0x01, 0x07, 0x6c, 0x00, 0x02, 0x8e, 0x6c, 0x00, 0x11, 0x81, 0x1d, 0x00,
|
|
|
|
0x11, 0x05, 0x1b, 0x00, 0x01, 0x08, 0x69, 0x00, 0x01, 0x07, 0x6c, 0x00,
|
|
|
|
0x12, 0x81, 0x6e, 0x00, 0x12, 0x01, 0x65, 0x00, 0x02, 0x02, 0x76, 0x00,
|
|
|
|
0x02, 0x04, 0x16, 0x00, 0x02, 0x85, 0x6c, 0x00, 0x02, 0x04, 0x1d, 0x00,
|
|
|
|
0x01, 0x8b, 0x6c, 0x00, 0x11, 0x01, 0x1d, 0x00, 0x11, 0x05, 0x6c, 0x00,
|
|
|
|
0x01, 0x08, 0x69, 0x00, 0x01, 0x07, 0x6c, 0x00, 0x12, 0x81, 0x16, 0x00,
|
|
|
|
0x12, 0x03, 0x7e, 0x00, 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00,
|
|
|
|
0x13, 0x81, 0x6e, 0x00, 0x13, 0x01, 0x65, 0x00, 0x03, 0x02, 0x76, 0x00,
|
|
|
|
0x03, 0x04, 0x85, 0x00, 0x03, 0x82, 0x85, 0x00, 0x03, 0x85, 0x1b, 0x00,
|
|
|
|
0x03, 0x04, 0x1d, 0x00, 0x02, 0x8b, 0x6c, 0x00, 0x12, 0x01, 0x16, 0x00,
|
|
|
|
0x12, 0x03, 0x8a, 0x00, 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00,
|
|
|
|
0x13, 0x81, 0x6e, 0x00, 0x13, 0x01, 0x65, 0x00, 0x03, 0x02, 0x76, 0x00,
|
|
|
|
0x03, 0x04, 0x8a, 0x00, 0x03, 0x85, 0x67, 0x00, 0x03, 0x04, 0x1d, 0x00,
|
|
|
|
0x02, 0x8b, 0x6c, 0x00, 0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x8f, 0x00,
|
|
|
|
0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00, 0x13, 0x81, 0x6e, 0x00,
|
|
|
|
0x13, 0x01, 0x65, 0x00, 0x03, 0x02, 0x76, 0x00, 0x03, 0x04, 0x8f, 0x00,
|
|
|
|
0x03, 0x85, 0x67, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x6c, 0x00,
|
|
|
|
0x11, 0x01, 0x1d, 0x00, 0x11, 0x05, 0x67, 0x00, 0x01, 0x08, 0x69, 0x00,
|
|
|
|
0x01, 0x07, 0x6c, 0x00, 0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x8a, 0x00,
|
|
|
|
0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00, 0x03, 0x82, 0x8a, 0x00,
|
|
|
|
0x03, 0x07, 0x6c, 0x00, 0x14, 0x81, 0x6e, 0x00, 0x14, 0x01, 0x65, 0x00,
|
|
|
|
0x04, 0x02, 0x76, 0x00, 0x04, 0x04, 0x85, 0x00, 0x04, 0x82, 0x85, 0x00,
|
|
|
|
0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x02, 0x8b, 0x6c, 0x00,
|
|
|
|
0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x8f, 0x00, 0x02, 0x08, 0x69, 0x00,
|
|
|
|
0x02, 0x07, 0x6c, 0x00, 0x13, 0x81, 0x6e, 0x00, 0x13, 0x01, 0x65, 0x00,
|
|
|
|
0x03, 0x02, 0x76, 0x00, 0x03, 0x04, 0x85, 0x00, 0x03, 0x85, 0x99, 0x00,
|
|
|
|
0x03, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x6c, 0x00, 0x11, 0x01, 0x1d, 0x00,
|
|
|
|
0x11, 0x05, 0x99, 0x00, 0x01, 0x08, 0x69, 0x00, 0x01, 0x07, 0x6c, 0x00,
|
|
|
|
0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x8f, 0x00, 0x02, 0x08, 0x69, 0x00,
|
|
|
|
0x02, 0x07, 0x6c, 0x00, 0x13, 0x81, 0x9b, 0x00, 0x23, 0x01, 0x6e, 0x00,
|
|
|
|
0x23, 0x01, 0x65, 0x00, 0x13, 0x02, 0x76, 0x00, 0x03, 0x08, 0xa2, 0x00,
|
|
|
|
0x03, 0x07, 0x6c, 0x00, 0x04, 0x82, 0x85, 0x00, 0x14, 0x81, 0x6e, 0x00,
|
|
|
|
0x14, 0x01, 0x65, 0x00, 0x24, 0x01, 0x9b, 0x00, 0x24, 0x01, 0x8f, 0x00,
|
|
|
|
0x14, 0x08, 0xa4, 0x00, 0x14, 0x03, 0x6e, 0x00, 0x04, 0x02, 0xa6, 0x00,
|
|
|
|
0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x00, 0x86, 0xae, 0x00,
|
|
|
|
0x00, 0x8c, 0x33, 0x00, /* instruct array */
|
|
|
|
0xb1, 0x00, /* const pool size */
|
|
|
|
0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x2e, 0x6c, 0x65, 0x6e,
|
|
|
|
0x00, 0x6c, 0x65, 0x6e, 0x00, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x6d, 0x6f,
|
|
|
|
0x64, 0x65, 0x00, 0x30, 0x00, 0x69, 0x6e, 0x66, 0x6f, 0x5f, 0x69, 0x6e,
|
|
|
|
0x64, 0x65, 0x78, 0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x69, 0x74,
|
|
|
|
0x65, 0x72, 0x00, 0x5f, 0x6c, 0x30, 0x00, 0x5f, 0x72, 0x31, 0x00, 0x5f,
|
|
|
|
0x72, 0x32, 0x00, 0x5f, 0x72, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61,
|
|
|
|
0x31, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61, 0x32, 0x00, 0x5f, 0x6c, 0x30,
|
|
|
|
0x2e, 0x61, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e, 0x65,
|
|
|
|
0x78, 0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00, 0x32, 0x00, 0x3d, 0x3d, 0x00,
|
|
|
|
0x31, 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x00, 0x5f, 0x5f,
|
|
|
|
0x67, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x61, 0x6c, 0x77, 0x61, 0x79, 0x73,
|
|
|
|
0x00, 0x74, 0x6f, 0x64, 0x6f, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x00, 0x70,
|
|
|
|
0x65, 0x72, 0x69, 0x6f, 0x64, 0x5f, 0x6d, 0x73, 0x00, 0x33, 0x00, 0x5f,
|
|
|
|
0x5f, 0x74, 0x69, 0x63, 0x6b, 0x00, 0x3e, 0x00, 0x2b, 0x00, 0x5f, 0x5f,
|
|
|
|
0x73, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const pool */
|
|
|
|
};
|
|
|
|
pikaVM_runByteCode(__pikaMain, (uint8_t*)bytes);
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
|
|
|
|
2022-01-24 19:34:43 +08:00
|
|
|
void __Task_update_tick(PikaObj* self) {
|
2022-01-24 21:01:18 +08:00
|
|
|
if (obj_getInt(self, "is_perod")) {
|
|
|
|
pikaVM_runAsm(self, "B0\n0 RUN platformGetTick\n");
|
|
|
|
}
|
2022-01-24 19:34:43 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 09:27:53 +08:00
|
|
|
void PikaStdTask_Task_run_forever(PikaObj* self) {
|
2022-01-20 21:50:38 +08:00
|
|
|
while (1) {
|
2022-01-24 19:34:43 +08:00
|
|
|
__Task_update_tick(self);
|
|
|
|
PikaStdTask_Task_run_once(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdTask_Task_run_until_ms(PikaObj* self, int until_ms) {
|
|
|
|
while (1) {
|
|
|
|
__Task_update_tick(self);
|
2022-01-20 18:16:08 +08:00
|
|
|
PikaStdTask_Task_run_once(self);
|
2022-01-24 19:34:43 +08:00
|
|
|
if (obj_getInt(self, "tick") > until_ms) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
|
|
|
}
|
2022-01-23 21:50:05 +08:00
|
|
|
|
|
|
|
void PikaStdTask_Task_platformGetTick(PikaObj* self) {
|
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|