void lua_setup() { VM_THREAD_HANDLE handle; L = lua_open(); lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(L); /* open libraries */ luaopen_audio(L); luaopen_gsm(L); luaopen_timer(L); luaopen_gpio(L); luaopen_screen(L); luaopen_i2c(L); luaopen_tcp(L); luaopen_https(L); luaopen_bluetooth(L); luaopen_button(L); lua_register(L, "msleep", msleep_c); lua_gc(L, LUA_GCRESTART, 0); luaL_dofile(L, "init.lua"); handle = vm_thread_create(shell_thread, L, 0); vm_thread_change_priority(handle, 245); }
/* * \brief Main entry point of Arduino application */ extern "C" void vm_main( void ) { VM_THREAD_HANDLE handle; /* Alloc DMA memory for SPI read and write, for SPI must be use non-cache memory, so we need use vm_malloc_dma to alloc memory, but in arduino thread we cannot invoke this interface directly, so use here to prepare memory, you can see its usage in SPI.transfer in SPI.cpp */ spi_w_data = (unsigned char*)vm_malloc_dma(2); spi_r_data = (unsigned char*)vm_malloc_dma(2); /* Same reason like above, this is used for transferring large of data, like screen buffer, you can see its usage in SPI.write in SPI.cpp */ spi_data_memory = (unsigned char*)vm_malloc_dma(64*1024); memset(spi_data_memory,0, 64*1024); /* only prepare something for rand, please don't delete this , otherwise arduino cannot use these two interface */ srand(0) ; rand(); /* Register system event callback */ vm_pmng_register_system_event_callback(__handle_sysevt); /* Register voice call event callback */ vm_gsm_tel_call_reg_listener(__call_listener_func); /* Create arduino thread, and change its priority, please don't change the code, or it will effort system stable */ handle = vm_thread_create(__arduino_thread, NULL, 0); vm_thread_change_priority(handle, 245); }
/* * \brief Main entry point of Arduino application */ void vm_main( void ) { VM_THREAD_HANDLE handle; spi_w_data = (unsigned char*)vm_malloc_nc(2); spi_r_data = (unsigned char*)vm_malloc_nc(2); srand(0); rand(); spi_data_memory = (unsigned char*)vm_malloc_nc(64*1024); memset(spi_data_memory,0, 64*1024); vm_reg_sysevt_callback(__handle_sysevt); vm_call_reg_listener(__call_listener_func); handle = vm_thread_create(__arduino_thread, NULL, 0); vm_thread_change_priority(handle, 245); }
void lua_setup() { VM_THREAD_HANDLE handle; L = lua_open(); lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(L); /* open libraries */ luaopen_audio(L); luaopen_gsm(L); luaopen_timer(L); luaopen_gpio(L); luaopen_screen(L); luaopen_i2c(L); luaopen_tcp(L); luaopen_https(L); lua_register(L, "msleep", msleep_c); lua_gc(L, LUA_GCRESTART, 0); luaL_dofile(L, "init.lua"); if (0) { const char *script = "audio.play('nokia.mp3')"; int error; error = luaL_loadbuffer(L, script, strlen(script), "line") || lua_pcall(L, 0, 0, 0); if (error) { fprintf(stderr, "%s", lua_tostring(L, -1)); lua_pop(L, 1); /* pop error message from the stack */ } } handle = vm_thread_create(shell_thread, L, 0); vm_thread_change_priority(handle, 245); }