| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- #include "luat_base.h"
- #include "luat_msgbus.h"
- #include "luat_fs.h"
- #include <stdlib.h>
- LUAMOD_API int luaopen_win32( lua_State *L );
- int luaopen_lfs(lua_State * L);
- int luaopen_rs232_core(lua_State * L);
- static const luaL_Reg loadedlibs[] = {
- {"_G", luaopen_base}, // _G
- {LUA_LOADLIBNAME, luaopen_package}, // require
- {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
- {LUA_TABLIBNAME, luaopen_table}, // table库,操作table类型的数据结构
- {LUA_IOLIBNAME, luaopen_io}, // io库,操作文件
- {LUA_OSLIBNAME, luaopen_os}, // os库,已精简
- {LUA_STRLIBNAME, luaopen_string}, // string库,字符串操作
- {LUA_MATHLIBNAME, luaopen_math}, // math 数值计算
- // {LUA_UTF8LIBNAME, luaopen_utf8},
- {LUA_DBLIBNAME, luaopen_debug}, // debug库,已精简
- #if defined(LUA_COMPAT_BITLIB)
- {LUA_BITLIBNAME, luaopen_bit32}, // 不太可能启用
- #endif
- {"rtos", luaopen_rtos}, // rtos底层库, 核心功能是队列和定时器
- {"log", luaopen_log}, // 日志库
- {"timer", luaopen_timer}, // 延时库
- {"pack", luaopen_pack}, // pack.pack/pack.unpack
- {"json", luaopen_cjson}, // json
- {"win32", luaopen_win32}, // windows 32 tools
- {"zbuff", luaopen_zbuff}, //
- {"mqttcore", luaopen_mqttcore}, //
- {"libcoap", luaopen_libcoap}, //
- #ifdef LUA_USE_WINDOWS
- {"lfs", luaopen_lfs}, //
- {"rs232.core", luaopen_rs232_core},
- #endif
- {"crypto", luaopen_crypto},
- {NULL, NULL}
- };
- // 按不同的rtconfig加载不同的库函数
- void luat_openlibs(lua_State *L) {
- // 初始化队列服务
- luat_msgbus_init();
- //print_list_mem("done>luat_msgbus_init");
- // 加载系统库
- const luaL_Reg *lib;
- /* "require" functions from 'loadedlibs' and set results to global table */
- for (lib = loadedlibs; lib->func; lib++) {
- luaL_requiref(L, lib->name, lib->func, 1);
- lua_pop(L, 1); /* remove lib */
- //extern void print_list_mem(const char* name);
- //print_list_mem(lib->name);
- }
- }
- void luat_os_reboot(int code) {
- exit(code);
- }
- const char* luat_os_bsp(void) {
- #ifdef LUA_USE_WINDOWS
- return "win32";
- #else
- return "posix";
- #endif
- }
- extern const struct luat_vfs_filesystem vfs_fs_posix;
- extern const struct luat_vfs_filesystem vfs_fs_luadb;
- #ifdef LUAT_USE_VFS_INLINE_LIB
- extern const char luadb_inline[];
- #endif
- int luat_fs_init(void) {
- #ifdef LUAT_USE_FS_VFS
- // vfs进行必要的初始化
- luat_vfs_init(NULL);
- // 注册vfs for posix 实现
- luat_vfs_reg(&vfs_fs_posix);
- luat_vfs_reg(&vfs_fs_luadb);
- luat_fs_conf_t conf = {
- .busname = "",
- .type = "posix",
- .filesystem = "posix",
- .mount_point = "", // window环境下, 需要支持任意路径的读取,不能强制要求必须是/
- };
- luat_fs_mount(&conf);
- #ifdef LUAT_USE_VFS_INLINE_LIB
- luat_fs_conf_t conf2 = {
- .busname = (char*)luadb_inline,
- .type = "luadb",
- .filesystem = "luadb",
- .mount_point = "/luadb/",
- };
- luat_fs_mount(&conf2);
- #endif
- return 0;
- #else
- return 0;
- #endif
- }
- void vConfigureTimerForRunTimeStats( void ) {}
- /** 设备进入待机模式 */
- void luat_os_standy(int timeout) {
- return; // nop
- }
- //--------------------------------------------------------------------------------
- // for freertos
- #include "FreeRTOS.h"
- #include "task.h"
- /* When configSUPPORT_STATIC_ALLOCATION is set to 1 the application writer can
- use a callback function to optionally provide the memory required by the idle
- and timer tasks. This is the stack that will be used by the timer task. It is
- declared here, as a global, so it can be checked by a test that is implemented
- in a different file. */
- StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
- /* Notes if the trace is running or not. */
- static BaseType_t xTraceRunning = pdTRUE;
- void vApplicationIdleHook( void )
- {
- #ifdef LUA_USE_WINDOWS
- Sleep(1);
- #else
- usleep(1000);
- #endif
- }
- void vAssertCalled( unsigned long ulLine, const char * const pcFileName ) {
- printf( "ASSERT! Line %d, file %s\r\n", ulLine, pcFileName );
- exit(255);
- }
- void vApplicationDaemonTaskStartupHook( void )
- {
- /* This function will be called once only, when the daemon task starts to
- execute (sometimes called the timer task). This is useful if the
- application includes initialisation code that would benefit from executing
- after the scheduler has been started. */
- }
- void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
- {
- ( void ) pcTaskName;
- ( void ) pxTask;
- /* Run time stack overflow checking is performed if
- configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
- function is called if a stack overflow is detected. This function is
- provided as an example only as stack overflow checking does not function
- when running the FreeRTOS Windows port. */
- vAssertCalled( __LINE__, __FILE__ );
- }
- /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
- implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
- used by the Idle task. */
- void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
- {
- /* If the buffers to be provided to the Idle task are declared inside this
- function then they must be declared static - otherwise they will be allocated on
- the stack and so not exists after this function exits. */
- static StaticTask_t xIdleTaskTCB;
- static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
- /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
- state will be stored. */
- *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
- /* Pass out the array that will be used as the Idle task's stack. */
- *ppxIdleTaskStackBuffer = uxIdleTaskStack;
- /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
- Note that, as the array is necessarily of type StackType_t,
- configMINIMAL_STACK_SIZE is specified in words, not bytes. */
- *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
- }
- /*-----------------------------------------------------------*/
- /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
- application must provide an implementation of vApplicationGetTimerTaskMemory()
- to provide the memory that is used by the Timer service task. */
- void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
- {
- /* If the buffers to be provided to the Timer task are declared inside this
- function then they must be declared static - otherwise they will be allocated on
- the stack and so not exists after this function exits. */
- static StaticTask_t xTimerTaskTCB;
- /* Pass out a pointer to the StaticTask_t structure in which the Timer
- task's state will be stored. */
- *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
- /* Pass out the array that will be used as the Timer task's stack. */
- *ppxTimerTaskStackBuffer = uxTimerTaskStack;
- /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
- Note that, as the array is necessarily of type StackType_t,
- configMINIMAL_STACK_SIZE is specified in words, not bytes. */
- *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
- }
- /*-----------------------------------------------------------*/
- void vApplicationMallocFailedHook( void )
- {
- /* vApplicationMallocFailedHook() will only be called if
- configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
- function that will get called if a call to pvPortMalloc() fails.
- pvPortMalloc() is called internally by the kernel whenever a task, queue,
- timer or semaphore is created. It is also called by various parts of the
- demo application. If heap_1.c, heap_2.c or heap_4.c is being used, then the
- size of the heap available to pvPortMalloc() is defined by
- configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
- API function can be used to query the size of free heap space that remains
- (although it does not provide information on how the remaining heap might be
- fragmented). See http://www.freertos.org/a00111.html for more
- information. */
- vAssertCalled( __LINE__, __FILE__ );
- }
- /*-----------------------------------------------------------*/
|