├── .gitignore
├── README.md
├── examples
├── CC26X2R1
│ ├── .ccsproject
│ ├── .cproject
│ ├── .launches
│ │ └── CC26X2R1.launch
│ ├── .project
│ ├── .settings
│ │ ├── org.eclipse.cdt.codan.core.prefs
│ │ ├── org.eclipse.cdt.debug.core.prefs
│ │ └── org.eclipse.core.resources.prefs
│ ├── CC26X2R1.syscfg
│ ├── README.html
│ ├── README.md
│ ├── cc13x2_cc26x2_tirtos7.cmd
│ ├── luaProject
│ │ ├── Scripts
│ │ │ ├── convertToHeader.bat
│ │ │ ├── helperScript.h
│ │ │ ├── helperScript.lua
│ │ │ ├── script1.h
│ │ │ ├── script1.lua
│ │ │ ├── script2.h
│ │ │ └── script2.lua
│ │ ├── luaInterface.c
│ │ ├── luaInterface.h
│ │ ├── luaProjectConfig.h
│ │ ├── printFreeHeap.c
│ │ └── printFreeHeap.h
│ ├── main.c
│ ├── overview.rov.json
│ ├── targetConfigs
│ │ ├── CC2652R1F.ccxml
│ │ └── readme.txt
│ └── threads.c
├── RX64M
│ ├── .HardwareDebuglinker
│ ├── .Releaselinker
│ ├── .cproject
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ ├── CodeGenerator
│ │ │ └── cgprojectDatas.datas
│ │ ├── CoverageSetting.xml
│ │ ├── DebugVirtualConsoleSetting.xml
│ │ ├── Dependency_Scan_Preferences.prefs
│ │ ├── IORegisterSetting.xml
│ │ ├── Project_Generation_Prefrences.prefs
│ │ ├── com.renesas.cdt.managedbuild.renesas.ccrx.prefs
│ │ ├── com.renesas.hardwaredebug.rx.e1.PerfAnalysisSettings.xml
│ │ ├── e2studio_project.prefs
│ │ ├── fitsettings.xml
│ │ └── org.eclipse.cdt.codan.core.prefs
│ ├── RX64M.rcpc
│ ├── custom.bat
│ ├── makefile.init
│ └── src
│ │ ├── dbsct.c
│ │ ├── interrupt_handlers.c
│ │ ├── iodefine.h
│ │ ├── luaProject
│ │ ├── Scripts
│ │ │ ├── convertToHeader.bat
│ │ │ ├── helperScript.h
│ │ │ ├── helperScript.lua
│ │ │ ├── script1.h
│ │ │ ├── script1.lua
│ │ │ ├── script2.h
│ │ │ └── script2.lua
│ │ ├── luaInterface.c
│ │ ├── luaInterface.h
│ │ ├── luaProjectConfig.h
│ │ ├── printFreeHeap.c
│ │ └── printFreeHeap.h
│ │ ├── main.cpp
│ │ ├── r_init_clock.c
│ │ ├── r_init_clock.h
│ │ ├── r_init_stop_module.c
│ │ ├── r_init_stop_module.h
│ │ ├── reset_program.c
│ │ ├── sbrk.c
│ │ ├── sbrk.h
│ │ ├── stacksct.h
│ │ ├── typedefine.h
│ │ ├── uart
│ │ ├── trace_uart.c
│ │ └── trace_uart.h
│ │ ├── vect.h
│ │ └── vector_table.c
└── STM32L552
│ ├── .cproject
│ ├── .project
│ ├── .settings
│ ├── com.st.stm32cube.ide.mcu.sfrview.prefs
│ └── language.settings.xml
│ ├── Application
│ ├── Include
│ │ ├── app_global.h
│ │ └── app_ringBuffer.h
│ ├── Main
│ │ └── app_main.c
│ └── RingBuffer
│ │ └── app_ringBuffer.c
│ ├── Drivers
│ ├── CMSIS
│ │ ├── Device
│ │ │ └── ST
│ │ │ │ └── STM32L5xx
│ │ │ │ ├── Include
│ │ │ │ ├── stm32l552xx.h
│ │ │ │ ├── stm32l5xx.h
│ │ │ │ └── system_stm32l5xx.h
│ │ │ │ └── License.md
│ │ ├── Include
│ │ │ ├── cmsis_armcc.h
│ │ │ ├── cmsis_armclang.h
│ │ │ ├── cmsis_armclang_ltm.h
│ │ │ ├── cmsis_compiler.h
│ │ │ ├── cmsis_gcc.h
│ │ │ ├── cmsis_iccarm.h
│ │ │ ├── cmsis_version.h
│ │ │ ├── core_armv81mml.h
│ │ │ ├── core_armv8mbl.h
│ │ │ ├── core_armv8mml.h
│ │ │ ├── core_cm0.h
│ │ │ ├── core_cm0plus.h
│ │ │ ├── core_cm1.h
│ │ │ ├── core_cm23.h
│ │ │ ├── core_cm3.h
│ │ │ ├── core_cm33.h
│ │ │ ├── core_cm35p.h
│ │ │ ├── core_cm4.h
│ │ │ ├── core_cm7.h
│ │ │ ├── core_sc000.h
│ │ │ ├── core_sc300.h
│ │ │ ├── mpu_armv7.h
│ │ │ ├── mpu_armv8.h
│ │ │ └── tz_context.h
│ │ └── LICENSE.txt
│ ├── Include
│ │ ├── drv_cacheApi.h
│ │ ├── drv_canApi.h
│ │ ├── drv_clockApi.h
│ │ ├── drv_uartApi.h
│ │ ├── stm32l5xx_hal_conf.h
│ │ └── stm32l5xx_it.h
│ ├── STM32L5xx_HAL_Driver
│ │ ├── Inc
│ │ │ ├── Legacy
│ │ │ │ └── stm32_hal_legacy.h
│ │ │ ├── stm32l5xx_hal.h
│ │ │ ├── stm32l5xx_hal_adc.h
│ │ │ ├── stm32l5xx_hal_adc_ex.h
│ │ │ ├── stm32l5xx_hal_cortex.h
│ │ │ ├── stm32l5xx_hal_def.h
│ │ │ ├── stm32l5xx_hal_dma.h
│ │ │ ├── stm32l5xx_hal_dma_ex.h
│ │ │ ├── stm32l5xx_hal_exti.h
│ │ │ ├── stm32l5xx_hal_fdcan.h
│ │ │ ├── stm32l5xx_hal_flash.h
│ │ │ ├── stm32l5xx_hal_flash_ex.h
│ │ │ ├── stm32l5xx_hal_flash_ramfunc.h
│ │ │ ├── stm32l5xx_hal_gpio.h
│ │ │ ├── stm32l5xx_hal_gpio_ex.h
│ │ │ ├── stm32l5xx_hal_i2c.h
│ │ │ ├── stm32l5xx_hal_i2c_ex.h
│ │ │ ├── stm32l5xx_hal_icache.h
│ │ │ ├── stm32l5xx_hal_pwr.h
│ │ │ ├── stm32l5xx_hal_pwr_ex.h
│ │ │ ├── stm32l5xx_hal_rcc.h
│ │ │ ├── stm32l5xx_hal_rcc_ex.h
│ │ │ ├── stm32l5xx_hal_rtc.h
│ │ │ ├── stm32l5xx_hal_rtc_ex.h
│ │ │ ├── stm32l5xx_hal_tim.h
│ │ │ ├── stm32l5xx_hal_tim_ex.h
│ │ │ ├── stm32l5xx_hal_uart.h
│ │ │ ├── stm32l5xx_hal_uart_ex.h
│ │ │ ├── stm32l5xx_ll_adc.h
│ │ │ ├── stm32l5xx_ll_bus.h
│ │ │ ├── stm32l5xx_ll_cortex.h
│ │ │ ├── stm32l5xx_ll_crs.h
│ │ │ ├── stm32l5xx_ll_dma.h
│ │ │ ├── stm32l5xx_ll_dmamux.h
│ │ │ ├── stm32l5xx_ll_exti.h
│ │ │ ├── stm32l5xx_ll_gpio.h
│ │ │ ├── stm32l5xx_ll_lpuart.h
│ │ │ ├── stm32l5xx_ll_pwr.h
│ │ │ ├── stm32l5xx_ll_rcc.h
│ │ │ ├── stm32l5xx_ll_rtc.h
│ │ │ ├── stm32l5xx_ll_system.h
│ │ │ ├── stm32l5xx_ll_ucpd.h
│ │ │ ├── stm32l5xx_ll_usart.h
│ │ │ └── stm32l5xx_ll_utils.h
│ │ ├── License.md
│ │ └── Src
│ │ │ ├── stm32l5xx_hal.c
│ │ │ ├── stm32l5xx_hal_adc.c
│ │ │ ├── stm32l5xx_hal_adc_ex.c
│ │ │ ├── stm32l5xx_hal_cortex.c
│ │ │ ├── stm32l5xx_hal_dma.c
│ │ │ ├── stm32l5xx_hal_dma_ex.c
│ │ │ ├── stm32l5xx_hal_exti.c
│ │ │ ├── stm32l5xx_hal_fdcan.c
│ │ │ ├── stm32l5xx_hal_flash.c
│ │ │ ├── stm32l5xx_hal_flash_ex.c
│ │ │ ├── stm32l5xx_hal_flash_ramfunc.c
│ │ │ ├── stm32l5xx_hal_gpio.c
│ │ │ ├── stm32l5xx_hal_i2c.c
│ │ │ ├── stm32l5xx_hal_i2c_ex.c
│ │ │ ├── stm32l5xx_hal_icache.c
│ │ │ ├── stm32l5xx_hal_pwr.c
│ │ │ ├── stm32l5xx_hal_pwr_ex.c
│ │ │ ├── stm32l5xx_hal_rcc.c
│ │ │ ├── stm32l5xx_hal_rcc_ex.c
│ │ │ ├── stm32l5xx_hal_rtc.c
│ │ │ ├── stm32l5xx_hal_rtc_ex.c
│ │ │ ├── stm32l5xx_hal_tim.c
│ │ │ ├── stm32l5xx_hal_tim_ex.c
│ │ │ ├── stm32l5xx_hal_uart.c
│ │ │ ├── stm32l5xx_hal_uart_ex.c
│ │ │ ├── stm32l5xx_ll_dma.c
│ │ │ ├── stm32l5xx_ll_exti.c
│ │ │ ├── stm32l5xx_ll_gpio.c
│ │ │ ├── stm32l5xx_ll_ucpd.c
│ │ │ └── stm32l5xx_ll_utils.c
│ ├── drv_cache.c
│ ├── drv_clock.c
│ ├── drv_uart.c
│ ├── startup_stm32l552zetxq.s
│ ├── stm32l5xx_it.c
│ └── system_stm32l5xx.c
│ ├── STM32L552ZETXQ_FLASH.ld
│ ├── STM32L552ZETXQ_RAM.ld
│ ├── eclipseStyle.xml
│ └── luaProject
│ ├── Scripts
│ ├── convertToHeader.bat
│ ├── helperScript.h
│ ├── helperScript.lua
│ ├── script1.h
│ ├── script1.lua
│ ├── script2.h
│ └── script2.lua
│ ├── luaInterface.c
│ ├── luaInterface.h
│ ├── luaProjectConfig.h
│ ├── printFreeHeap.c
│ └── printFreeHeap.h
├── licence
├── lua
├── helper
│ ├── convertToHeader.lua
│ ├── luaHeap.c
│ ├── luaHeap.h
│ ├── luaHelper.c
│ └── luaHelper.h
├── lapi.c
├── lapi.h
├── lauxlib.c
├── lauxlib.h
├── lbaselib.c
├── lcode.c
├── lcode.h
├── lctype.c
├── lctype.h
├── ldebug.c
├── ldebug.h
├── ldo.c
├── ldo.h
├── ldump.c
├── lfunc.c
├── lfunc.h
├── lgc.c
├── lgc.h
├── linit.c
├── ljumptab.h
├── llex.c
├── llex.h
├── llimits.h
├── lmathlib.c
├── lmem.c
├── lmem.h
├── lobject.c
├── lobject.h
├── lopcodes.c
├── lopcodes.h
├── lparser.c
├── lparser.h
├── lprefix.h
├── lstate.c
├── lstate.h
├── lstring.c
├── lstring.h
├── lstrlib.c
├── ltable.c
├── ltable.h
├── ltablib.c
├── ltm.c
├── ltm.h
├── lua.h
├── luaconf.h
├── lualib.h
├── lundump.c
├── lundump.h
├── lvm.c
├── lvm.h
├── lzio.c
└── lzio.h
└── release_notes.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | ### C objects and libs
2 | *.slo
3 | *.lo
4 | *.o
5 | *.a
6 | *.la
7 | *.lai
8 | *.so
9 | *.dll
10 | *.dylib
11 | examples/MSP430F6747A_FreeRTOS/.settings/
12 | examples/MSP430F6747A_FreeRTOS/targetConfigs/
13 | examples/MSP430F6747A_FreeRTOS/Debug/
14 | examples/MSP430F6747A_FreeRTOS/Release/
15 | examples/RX64M_embOS_Trial_V424/Debug/
16 | examples/RX64M_embOS_Trial_V424/Release/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # embLua
2 | The aim of embLua (includes the complete Lua 5.4.7 core) is to provide C/C++ developers the possibility to extend their microcontroller/embedded device with scripting functionality.
3 | The main focus of embLua is the fast/easy integration in custom projects and new platforms. Therefore only a subset of Lua modules and global functions are available:
4 | - table module
5 | - string module
6 | - global functions: assert, collectgarbage, error, getmetatable, ipairs, load, next, pairs, pcall, print, warn, rawequal, rawlen, rawget, rawset, select, setmetatable, tonumber, tostring, type, type
7 |
8 | Note: The math module is only included if the define LUA_WITH_MATH is defined in luaProjectConfig.h.
9 |
10 | ## embLua requirements
11 | To run scripts which do something 'meaningful' embLua needs:
12 | - TI CC2642R1: 2k stack, 20k Heap, 160k ROM (-O0), 100k ROM (-Oz)
13 | - STM32L552: 2k stack, 20k Heap, 210k ROM (-O0), 120k ROM (-Os)
14 | - Renesas RX64M: 3k stack, 20k Heap, 135k ROM (no optimizations), 95k ROM (max. optimizations)
15 | - C-Library
16 |
17 | ## Integrating embLua
18 | To integrate embLua in a custom project:
19 | - copy the source files embLua/lua into your project
20 | - create the embLua config file luaInterface.h (an example can be found under embLua/examples/STM32L552/luaProject)
21 |
22 |
23 | ### luaProjectConfig.h
24 | This file is used to configure embLua (an example can be found under embLua/examples/STM32L552/luaProject).
25 |
26 | #### Memory management
27 | embLua uses its own heap implementation. To configure this heap following defines are used:
28 |
29 | - LUA_HEAP_SIZE: The size of the heap used by Lua.
30 | - LUA_MEM_ENTER_CRITICAL_SECTION and LUA_MEM_LEAVE_CRITICAL_SECTION: These defines are used to protect the heap calls if several Lua instances in different threads are created.
31 |
32 | #### Other configuration options
33 | - LUA_DECIMAL_POINT: The "radix character" (decimal point) used by Lua is per default '.'. With this define this character can be changed.
34 | - LUA_WITH_MATH: If the math module shall be included then this define must be set.
35 |
36 | #### Needed functions
37 | - void luaAbort(void): This function is called by Lua if it cannot handle an occurred error.
38 | - lua_writestring(string,length), lua_writeline, lua_writestringerror(string,length): These function are called by lua to print texts.
39 |
40 | ## Embedding lua scripts
41 | To execute a Lua script the function dostring (embLua/lua/helper/luaHelper.c) can be used. This function can execute scipts wich resides in the RAM or in the ROM.
42 |
43 | ### Compiling a Lua script into ROM
44 | For this purpose embLua/lua/convertToHeader.lua can be used. This script converts all Lua scripts in a given directory (sript argument) into header files. To run these scripts the header files must be included and dofile with the name of these header files must be called (an example can be found in embLua/examples/STM32L552/main.c).
45 |
46 | Under embLua/examples/STM32L552/luaProject/Scripts a batch file can be found (convertToHeader.bat) which shows the usage of convertToHeader.lua.
47 |
48 | ## Extending embLua
49 | To extend embLua with custom module/functions the define LUA_INTERFACE_LIBS can be used. An example can be found under embLua/examples/STM32L552/luaProject/luaInterface.h
50 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/.ccsproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/.launches/CC26X2R1.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/.settings/org.eclipse.cdt.codan.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | inEditor=false
3 | onBuild=false
4 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/.settings/org.eclipse.cdt.debug.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker
3 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//Debug/helper/subdir_rules.mk=UTF-8
3 | encoding//Debug/helper/subdir_vars.mk=UTF-8
4 | encoding//Debug/lua/helper/subdir_rules.mk=UTF-8
5 | encoding//Debug/lua/helper/subdir_vars.mk=UTF-8
6 | encoding//Debug/lua/subdir_rules.mk=UTF-8
7 | encoding//Debug/lua/subdir_vars.mk=UTF-8
8 | encoding//Debug/luaProject/subdir_rules.mk=UTF-8
9 | encoding//Debug/luaProject/subdir_vars.mk=UTF-8
10 | encoding//Debug/makefile=UTF-8
11 | encoding//Debug/objects.mk=UTF-8
12 | encoding//Debug/sources.mk=UTF-8
13 | encoding//Debug/subdir_rules.mk=UTF-8
14 | encoding//Debug/subdir_vars.mk=UTF-8
15 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/CC26X2R1.syscfg:
--------------------------------------------------------------------------------
1 | /**
2 | * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
3 | * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
4 | * @cliArgs --board "/ti/boards/CC26X2R1_LAUNCHXL" --rtos "tirtos7" --product "simplelink_cc13xx_cc26xx_sdk@6.40.00.13"
5 | * @versions {"tool":"1.15.0+2826"}
6 | */
7 |
8 | /**
9 | * Import the modules used in this configuration.
10 | */
11 | const GPIO = scripting.addModule("/ti/drivers/GPIO");
12 | const GPIO1 = GPIO.addInstance();
13 | const Power = scripting.addModule("/ti/drivers/Power");
14 | const UART2 = scripting.addModule("/ti/drivers/UART2", {}, false);
15 | const UART21 = UART2.addInstance();
16 | const Settings = scripting.addModule("/ti/posix/tirtos/Settings");
17 | const BIOS = scripting.addModule("/ti/sysbios/BIOS");
18 | const Event = scripting.addModule("/ti/sysbios/knl/Event");
19 | const Idle = scripting.addModule("/ti/sysbios/knl/Idle", {}, false);
20 | const Idle2 = Idle.addInstance();
21 | const Mailbox = scripting.addModule("/ti/sysbios/knl/Mailbox");
22 | const Error = scripting.addModule("/ti/sysbios/runtime/Error");
23 | const SysCallback = scripting.addModule("/ti/sysbios/runtime/SysCallback");
24 | const Timestamp = scripting.addModule("/ti/sysbios/runtime/Timestamp");
25 |
26 | /**
27 | * Write custom configuration values to the imported modules.
28 | */
29 | GPIO1.$hardware = system.deviceData.board.components.LED_RED;
30 | GPIO1.$name = "CONFIG_GPIO_LED_0";
31 |
32 | const CCFG = scripting.addModule("/ti/devices/CCFG", {}, false);
33 | CCFG.ccfgTemplate.$name = "ti_devices_CCFG_CCFGCC26XXTemplate0";
34 |
35 | UART21.$name = "CONFIG_UART2_0";
36 | UART21.$hardware = system.deviceData.board.components.XDS110UART;
37 |
38 | BIOS.assertsEnabled = false;
39 | BIOS.heapBaseAddr = "__primary_heap_start__";
40 | BIOS.heapEndAddr = "__primary_heap_end__";
41 |
42 | const Hwi = scripting.addModule("/ti/sysbios/family/arm/m3/Hwi", {}, false);
43 | Hwi.enableException = false;
44 |
45 | const Clock = scripting.addModule("/ti/sysbios/knl/Clock", {}, false);
46 | Clock.tickPeriod = 10;
47 |
48 | const Timer = scripting.addModule("/ti/sysbios/family/arm/cc26xx/Timer", {}, false);
49 |
50 | Idle2.$name = "powerIdle";
51 | Idle2.idleFxn = "Power_idleFunc";
52 |
53 | const Semaphore = scripting.addModule("/ti/sysbios/knl/Semaphore", {}, false);
54 | Semaphore.supportsPriority = false;
55 |
56 | const Swi = scripting.addModule("/ti/sysbios/knl/Swi", {}, false);
57 | Swi.numPriorities = 6;
58 |
59 | const Task = scripting.addModule("/ti/sysbios/knl/Task", {}, false);
60 | Task.checkStackFlag = false;
61 | Task.defaultStackSize = 512;
62 | Task.idleTaskStackSize = 512;
63 | Task.numPriorities = 6;
64 |
65 | Error.policy = "Error_SPIN";
66 | Error.printDetails = false;
67 |
68 | const System = scripting.addModule("/ti/sysbios/runtime/System", {}, false);
69 | System.abortFxn = "System_abortSpin";
70 | System.exitFxn = "System_exitSpin";
71 | System.extendedFormats = "%f";
72 | System.supportModule = "SysCallback";
73 |
74 | /**
75 | * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future
76 | * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to
77 | * re-solve from scratch.
78 | */
79 | GPIO1.gpioPin.$suggestSolution = "boosterpack.39";
80 | UART21.uart.$suggestSolution = "UART0";
81 | UART21.uart.txPin.$suggestSolution = "boosterpack.4";
82 | UART21.uart.rxPin.$suggestSolution = "boosterpack.3";
83 | Timer.rtc.$suggestSolution = "RTC0";
84 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/README.md:
--------------------------------------------------------------------------------
1 | ## Example Summary
2 |
3 | This example is intended to be a starting point for new development where
4 | a fuller set of kernel features and debug capabilities are enabled.
5 |
6 | ## Peripherals & Pin Assignments
7 |
8 | When this project is built, the SysConfig tool will generate the TI-Driver
9 | configurations into the __ti_drivers_config.c__ and __ti_drivers_config.h__
10 | files. Information on pins and resources used is present in both generated
11 | files. Additionally, the System Configuration file (\*.syscfg) present in the
12 | project may be opened with SysConfig's graphical user interface to determine
13 | pins and resources used.
14 |
15 | * `CONFIG_GPIO_LED_0`
16 |
17 | ## BoosterPacks, Board Resources & Jumper Settings
18 |
19 | For board specific jumper settings, resources and BoosterPack modifications,
20 | refer to the __Board.html__ file.
21 |
22 | > If you're using an IDE such as Code Composer Studio (CCS) or IAR, please
23 | refer to Board.html in your project directory for resources used and
24 | board-specific jumper settings.
25 |
26 | The Board.html can also be found in your SDK installation:
27 |
28 | /source/ti/boards/
29 |
30 | ## Example Usage
31 |
32 | * The example lights `CONFIG_GPIO_LED_0` as part of the initialization in the
33 | `mainThread()`. This thread then toggles the LED at a 1 second rate.
34 |
35 | ## Application Design Details
36 |
37 | FreeRTOS:
38 |
39 | * Please view the `FreeRTOSConfig.h` header file for example configuration
40 | information.
41 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/Scripts/convertToHeader.bat:
--------------------------------------------------------------------------------
1 | %~dp0\..\..\..\..\..\lua\helper\lua-5.2.4_Win32_bin\lua52.exe %~dp0\..\..\..\..\..\lua\helper\convertToHeader.lua ./
2 |
3 | pause
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/Scripts/helperScript.h:
--------------------------------------------------------------------------------
1 | static const char* helperScript="local helperScriptCounter = 0\n\
2 | function includedScript ()\n\
3 | print(\"print from helperScript: \" .. tostring(helperScriptCounter) .. \"\\n\")\n\
4 | helperScriptCounter = helperScriptCounter+1\n\
5 | end";
6 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/Scripts/helperScript.lua:
--------------------------------------------------------------------------------
1 | local helperScriptCounter = 0
2 | function includedScript ()
3 | print("print from helperScript: " .. tostring(helperScriptCounter) .. "\n")
4 | helperScriptCounter = helperScriptCounter+1
5 | end
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/Scripts/script1.h:
--------------------------------------------------------------------------------
1 | static const char* script1="function script1Function ()\n\
2 | print('\\nscript1: ' .. tostring(uc.counter()) ..'\\n')\n\
3 | includedScript()\n\
4 | local example = 'an example string'\n\
5 | for el in string.gmatch(example, '%S+') do\n\
6 | print(el .. ' ')\n\
7 | end\n\
8 | print('\\n')\n\
9 | local result1, result2 = uc.func1('Testmessage')\n\
10 | print('result1: '.. tostring(result1) .. ' result2: '.. tostring(result2) .. '\\n')\n\
11 | local array = {0,1,2,3,4}\n\
12 | local resultTable = uc.func2(array)\n\
13 | print('test print:', 'string', 3, '\\n')\n\
14 | print('resultTable1: '.. tostring(resultTable[0]) .. ' resultTable2: '.. tostring(resultTable[1]) .. '\\n')\n\
15 | print('heap usage before collect: ' .. tostring(collectgarbage('count')*1024) .. '\\n')\n\
16 | collectgarbage('collect')\n\
17 | print('heap usage after collect: ' .. tostring(collectgarbage('count')*1024) .. '\\n')\n\
18 | error({code=121})\n\
19 | end\n\
20 | for loopCounter=0,2 do\n\
21 | local status, err = pcall(script1Function)\n\
22 | print(err.code .. '\\n')\n\
23 | end";
24 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/Scripts/script1.lua:
--------------------------------------------------------------------------------
1 | function script1Function ()
2 | print('\nscript1: ' .. tostring(uc.counter()) ..'\n')
3 |
4 | --Call a function from an other script (helperScript.lua).
5 | includedScript()
6 |
7 | --Split a string and print the result.
8 | local example = 'an example string'
9 | for el in string.gmatch(example, '%S+') do
10 | print(el .. ' ')
11 | end
12 | print('\n')
13 | --[[ test muli line comment:
14 | line 2
15 | line 3
16 | --]]
17 |
18 | --Call C-function func1 and print the result.
19 | local result1, result2 = uc.func1('Testmessage')
20 | print('result1: '.. tostring(result1) .. ' result2: '.. tostring(result2) .. '\n')
21 |
22 | --Call C-function func2 and print the result.
23 | local array = {0,1,2,3,4}
24 | local resultTable = uc.func2(array)
25 | print('test print:', 'string', 3, '\n')
26 | print('resultTable1: '.. tostring(resultTable[0]) .. ' resultTable2: '.. tostring(resultTable[1]) .. '\n')
27 |
28 | --Print the heap usage, collect garbage and then print the heap usage again.
29 | print('heap usage before collect: ' .. tostring(collectgarbage('count')*1024) .. '\n')
30 | collectgarbage('collect')
31 | print('heap usage after collect: ' .. tostring(collectgarbage('count')*1024) .. '\n')
32 | error({code=121})
33 | end
34 |
35 | for loopCounter=0,2 do
36 | local status, err = pcall(script1Function)
37 | print(err.code .. '\\n')
38 | end
39 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/Scripts/script2.h:
--------------------------------------------------------------------------------
1 | static const char* script2="print('\\nscript2: ' .. tostring(uc.counter()) ..'\\n')\n\
2 | includedScript()\n\
3 | print('heap usage: ' .. tostring(collectgarbage('count')*1024) .. '\\n')";
4 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/Scripts/script2.lua:
--------------------------------------------------------------------------------
1 | print('\nscript2: ' .. tostring(uc.counter()) ..'\n')
2 |
3 | --Call a function from an other script (helperScript.lua).
4 | includedScript()
5 |
6 | --Print the heap usage.
7 | print('heap usage: ' .. tostring(collectgarbage('count')*1024) .. '\n')
8 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/luaInterface.c:
--------------------------------------------------------------------------------
1 |
2 | #include "luaInterface.h"
3 |
4 | #include "../../../lua/lua.h"
5 | #include "../../../lua/lauxlib.h"
6 | #include "../../../lua/lualib.h"
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | //This function is called by Lua if it cannot handle an occured error.
13 | void luaAbort(void)
14 | {
15 | lua_writestringerror("luaAbort", sizeof("luaAbort"));
16 | while(1){}
17 | }
18 |
19 |
20 | int func1(lua_State *L)
21 | {
22 | size_t size;
23 | const char *message = luaL_checklstring(L, 1, &size);
24 |
25 | const char* msg = "C func1:";
26 | lua_writestring(msg, strlen(msg));
27 | lua_writestring(message, size);
28 | lua_writeline();
29 |
30 | //Cleanup the stack.
31 | int n = lua_gettop(L);
32 | lua_pop(L, n);
33 |
34 |
35 | //Create the result.
36 | lua_pushinteger(L, 1);
37 | lua_pushinteger(L, 2);
38 |
39 | return 2;//2 results
40 | }
41 |
42 | int func2(lua_State *L)
43 | {
44 | luaL_checktype(L, 1, LUA_TTABLE);
45 |
46 | lua_settop(L, 1);
47 |
48 |
49 | const char* msg = "C func2:";
50 | lua_writestring(msg, strlen(msg));
51 |
52 |
53 | lua_gettable(L, 1);
54 |
55 | //Add dummy value for the last lua_pop.
56 | lua_pushnil(L);
57 |
58 | while(lua_next(L, -2))
59 | {
60 | lua_Integer b = (int)lua_tonumber(L, -1);
61 | char value = 48 + b;
62 | lua_writestring(" ", 1);
63 | lua_writestring(&value, 1);
64 | lua_pop(L, 1);
65 | }
66 |
67 | lua_writeline();
68 |
69 | //Cleanup the stack.
70 | int n = lua_gettop(L);
71 | lua_pop(L, n);
72 |
73 |
74 | //Create the result.
75 | lua_newtable(L);
76 | lua_pushinteger(L, 5);
77 | lua_rawseti(L, -2, 0);
78 | lua_pushinteger(L, 9);
79 | lua_rawseti(L, -2, 1);
80 |
81 | return 1;
82 | }
83 |
84 | int counterFunction(lua_State *L)
85 | {
86 | static uint32_t counter = 0;
87 |
88 | counter++;
89 | lua_pushinteger(L, counter);
90 | return 1;
91 | }
92 |
93 |
94 | static const luaL_Reg uC_funcs[] = {
95 | {"func1", func1},
96 | {"func2", func2},
97 | {"counter", counterFunction},
98 | {NULL, NULL}
99 | };
100 |
101 |
102 | LUAMOD_API int luaopen_uc (lua_State *L) {
103 | luaL_newlib(L, uC_funcs);
104 | return 1;
105 | }
106 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/luaInterface.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef LUAINTERFACE_H_
4 | #define LUAINTERFACE_H_
5 |
6 | #include "lua.h"
7 |
8 | //
9 | #define LUA_INTERFACE_LIBS {"uc", luaopen_uc}
10 |
11 |
12 | LUAMOD_API int (luaopen_uc) (lua_State *L);
13 |
14 |
15 |
16 | #endif /* LUAINTERFACE_H_ */
17 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/luaProjectConfig.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef LUAPROJECTCONFIG_H_
3 | #define LUAPROJECTCONFIG_H_
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include "helper/luaHeap.h"
10 | #include
11 |
12 |
13 | //This function is called by Lua if it cannot handle an occurred error.
14 | void luaAbort(void);
15 |
16 | //If the math module shall be included then this define must be defined.
17 | //define LUA_WITH_MATH
18 |
19 | //The size of the heap used by Lua.
20 | #define LUA_HEAP_SIZE (40000)
21 |
22 | //These defines are used to protect the memory management calls if several Lua instances in different threads are created.
23 | extern sem_t memorySema;
24 | #define LUA_MEM_ENTER_CRITICAL_SECTION() sem_wait(&memorySema);
25 | #define LUA_MEM_LEAVE_CRITICAL_SECTION() sem_post(&memorySema);
26 |
27 |
28 | //Function for printing text from lua.
29 | extern uint32_t uart_send(const void *buffer, uint32_t size);
30 | #define lua_writestring(string,length) uart_send((uint8_t*) string, length);
31 | #define lua_writeline() lua_writestring("\n", 1);
32 | #define lua_writestringerror(string,length) lua_writestring(string, length);
33 |
34 |
35 | #endif /* LUAPROJECTCONFIG_H_ */
36 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/printFreeHeap.c:
--------------------------------------------------------------------------------
1 |
2 | #include "printFreeHeap.h"
3 |
4 | #include "../../../lua/lua.h"
5 | #include "../../../lua/lauxlib.h"
6 | #include "../../../lua/lualib.h"
7 | #include "../../../lua/helper/luaHeap.h"
8 | #include "../../../lua/luaconf.h"
9 | #include "luaInterface.h"
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | void printFreeHeap(char* message)
16 | {
17 | char buffer[16];
18 | size_t size = luaGetFreeHeapSize();
19 |
20 | snprintf(buffer, 16, "%i", size);
21 | lua_writestring(message, strlen(message));
22 | lua_writestring(buffer, strlen(buffer));
23 | lua_writeline();
24 | }
25 |
26 | void printMinimumFreeHeap()
27 | {
28 | char buffer[16];
29 | size_t size = luaGetMinimumEverFreeHeapSize();
30 |
31 | snprintf(buffer, 16, "%i", size);
32 | lua_writestring("minimum free heap: ", sizeof("minimum free heap: ") - 1);
33 | lua_writestring(buffer, strlen(buffer));
34 | lua_writeline();
35 | }
36 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/luaProject/printFreeHeap.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef LUAPROJECT_PRINTFREEHEAP_H_
4 | #define LUAPROJECT_PRINTFREEHEAP_H_
5 |
6 |
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 |
12 | void printFreeHeap(char* message);
13 | void printMinimumFreeHeap();
14 |
15 | #ifdef __cplusplus
16 | }
17 | #endif
18 |
19 |
20 |
21 | #endif /* LUAPROJECT_PRINTFREEHEAP_H_ */
22 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2020, Texas Instruments Incorporated
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of Texas Instruments Incorporated nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 |
29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 | */
33 |
34 | /*
35 | * ======== main_tirtos.c ========
36 | */
37 | #include
38 |
39 | /* POSIX Header files */
40 | #include
41 |
42 | /* RTOS header files */
43 | #include
44 |
45 | #include
46 |
47 | #include
48 | #include
49 |
50 | /* Driver configuration */
51 | #include "ti_drivers_config.h"
52 |
53 | extern void createThread1(void);
54 | extern void createThread2(void);
55 |
56 |
57 | sem_t memorySema;
58 | sem_t uart_txSema;
59 | UART2_Handle g_uartHandle;
60 |
61 |
62 | void app_uartReadCallback(UART2_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status)
63 | {
64 | (void)handle;
65 | (void)buf;
66 | (void)count;
67 | (void)userArg;
68 | (void)status;
69 |
70 | }
71 |
72 | void initializeUart(void)
73 | {
74 | UART2_Params uartParams;
75 |
76 | sem_init(&uart_txSema, 0, 0);
77 | sem_post(&uart_txSema);
78 |
79 | UART2_Params_init(&uartParams);
80 | uartParams.baudRate = 115200;
81 | uartParams.readMode = UART2_Mode_CALLBACK;
82 | uartParams.readCallback = app_uartReadCallback;
83 | g_uartHandle = UART2_open(CONFIG_UART2_0, &uartParams);
84 | }
85 |
86 | uint32_t uart_send(const void *buffer, uint32_t size)
87 | {
88 | uint32_t bytesWritten = 0;
89 |
90 | sem_wait(&uart_txSema);
91 |
92 | do
93 | {
94 | UART2_write(g_uartHandle, buffer, size, &bytesWritten);
95 |
96 | }while(bytesWritten < size);
97 | sem_post(&uart_txSema);
98 |
99 | return bytesWritten;
100 |
101 | }
102 |
103 | int main(void)
104 | {
105 | Board_init();
106 |
107 | initializeUart();
108 |
109 | sem_init(&memorySema, 0, 0);
110 | sem_post(&memorySema);
111 |
112 | createThread1();
113 | createThread2();
114 |
115 | BIOS_start();
116 |
117 | return (0);
118 | }
119 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/targetConfigs/CC2652R1F.ccxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/examples/CC26X2R1/targetConfigs/readme.txt:
--------------------------------------------------------------------------------
1 | The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based
2 | on the device and connection settings specified in your project on the Properties > General page.
3 |
4 | Please note that in automatic target-configuration management, changes to the project's device and/or
5 | connection settings will either modify an existing or generate a new target-configuration file. Thus,
6 | if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively,
7 | you may create your own target-configuration file for this project and manage it manually. You can
8 | always switch back to automatic target-configuration management by checking the "Manage the project's
9 | target-configuration automatically" checkbox on the project's Properties > General page.
--------------------------------------------------------------------------------
/examples/RX64M/.HardwareDebuglinker:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/examples/RX64M/.Releaselinker:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/examples/RX64M/.gitignore:
--------------------------------------------------------------------------------
1 | /Release
2 | /HardwareDebug
3 | /HardwareDebug
4 |
--------------------------------------------------------------------------------
/examples/RX64M/.settings/CodeGenerator/cgprojectDatas.datas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szieke/embLua/000a7dea186d0e5653b7636442ee896dde3273a1/examples/RX64M/.settings/CodeGenerator/cgprojectDatas.datas
--------------------------------------------------------------------------------
/examples/RX64M/.settings/CoverageSetting.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1.0
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/examples/RX64M/.settings/DebugVirtualConsoleSetting.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | true
6 |
7 | false
8 |
9 | 0
10 | true
11 | false
12 |
13 |
14 |
--------------------------------------------------------------------------------
/examples/RX64M/.settings/Dependency_Scan_Preferences.prefs:
--------------------------------------------------------------------------------
1 | Build\ project\ excluding\ the\ dependencies=false
2 | DependecyMode=ScanBuildDep
3 | Re-generate\ and\ use\ dependencies\ during\ project\ build=true
4 | Use\ existing\ dependencies\ during\ project\ build=false
5 | eclipse.preferences.version=1
6 |
--------------------------------------------------------------------------------
/examples/RX64M/.settings/IORegisterSetting.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/examples/RX64M/.settings/Project_Generation_Prefrences.prefs:
--------------------------------------------------------------------------------
1 | com.renesas.cdt.renesas.Assembler.option.userDefine=-nologo;;;
2 | com.renesas.cdt.renesas.Compiler.option.C=com.renesas.cdt.renesas.Compiler.option.C89
3 | com.renesas.cdt.renesas.Compiler.option.UserDef=-nologo;
4 | com.renesas.cdt.renesas.Compiler.option.defines=__RX\=1;
5 | com.renesas.cdt.renesas.Compiler.option.deviceShortName=R5F564MLCxFC
6 | com.renesas.cdt.renesas.Compiler.option.incFileDirectories="${TCINSTALL}/include";
7 | com.renesas.cdt.renesas.Configurator.option.cfgPath=""
8 | com.renesas.cdt.renesas.Configurator.option.rtosName=None
9 | com.renesas.cdt.renesas.Configurator.option.rtosPath=""
10 | com.renesas.cdt.renesas.Configurator.option.rtosVersion=None
11 | com.renesas.cdt.renesas.Linker.option.rom=D\=R;D_1\=R_1;D_2\=R_2;
12 | com.renesas.cdt.renesas.Linker.option.typeOfOutputFileOption=Stype via absolute
13 | com.renesas.cdt.renesas.StandardLibrary.option.complexC99=false
14 | com.renesas.cdt.renesas.StandardLibrary.option.ctypec89=false
15 | com.renesas.cdt.renesas.StandardLibrary.option.fenvC99=false
16 | com.renesas.cdt.renesas.StandardLibrary.option.inttypesC99=false
17 | com.renesas.cdt.renesas.StandardLibrary.option.libConfiguration=C(C89)
18 | com.renesas.cdt.renesas.StandardLibrary.option.mathc89=false
19 | com.renesas.cdt.renesas.StandardLibrary.option.mathfc89=false
20 | com.renesas.cdt.renesas.StandardLibrary.option.mode=com.renesas.cdt.renesas.StandardLibrary.option.buildOnlyWhenOptionsChanged
21 | com.renesas.cdt.renesas.StandardLibrary.option.runtime=true
22 | com.renesas.cdt.renesas.StandardLibrary.option.rxccomplexCPP=false
23 | com.renesas.cdt.renesas.StandardLibrary.option.rxciosCPP=false
24 | com.renesas.cdt.renesas.StandardLibrary.option.rxcnewCPP=true
25 | com.renesas.cdt.renesas.StandardLibrary.option.rxcstringCPP=false
26 | com.renesas.cdt.renesas.StandardLibrary.option.stdargc89=false
27 | com.renesas.cdt.renesas.StandardLibrary.option.stdioc89=true
28 | com.renesas.cdt.renesas.StandardLibrary.option.stdlibc89=true
29 | com.renesas.cdt.renesas.StandardLibrary.option.stringc89=true
30 | com.renesas.cdt.renesas.StandardLibrary.option.wcharC99=false
31 | com.renesas.cdt.renesas.StandardLibrary.option.wctypeC99=false
32 | com.renesas.cdt.rxc.HardwareDebug.Assembler.option.endian=Little-endian data
33 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.RAM=None
34 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.ROM=None
35 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.address=00000000
36 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.addressRegister=None
37 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.allocLowerBit=Lower bit
38 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.cpuType=RX600
39 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.denormalized=false
40 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.endian=Little-endian data
41 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.enumSize=false
42 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.packStructures=false
43 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.patchCode=None
44 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.precisionDouble=Single precision
45 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.registerFastInterrupt=None
46 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.replaceFromIntWithShort=false
47 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.roundTo=Nearest
48 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.saveacc=false
49 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.signBitField=unsigned
50 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.signChar=unsigned
51 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.useDynamic=false
52 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.useTry=false
53 | com.renesas.cdt.rxc.HardwareDebug.Compiler.option.widthDivergence=24 bit
54 | com.renesas.cdt.rxc.HardwareDebug.StandardLibrary.option.endian=Little-endian data
55 | com.renesas.cdt.rxc.Release.Assembler.option.endian=Little-endian data
56 | com.renesas.cdt.rxc.Release.Compiler.option.RAM=None
57 | com.renesas.cdt.rxc.Release.Compiler.option.ROM=None
58 | com.renesas.cdt.rxc.Release.Compiler.option.address=00000000
59 | com.renesas.cdt.rxc.Release.Compiler.option.addressRegister=None
60 | com.renesas.cdt.rxc.Release.Compiler.option.allocLowerBit=Lower bit
61 | com.renesas.cdt.rxc.Release.Compiler.option.cpuType=RX600
62 | com.renesas.cdt.rxc.Release.Compiler.option.denormalized=false
63 | com.renesas.cdt.rxc.Release.Compiler.option.endian=Little-endian data
64 | com.renesas.cdt.rxc.Release.Compiler.option.enumSize=false
65 | com.renesas.cdt.rxc.Release.Compiler.option.packStructures=false
66 | com.renesas.cdt.rxc.Release.Compiler.option.patchCode=None
67 | com.renesas.cdt.rxc.Release.Compiler.option.precisionDouble=Single precision
68 | com.renesas.cdt.rxc.Release.Compiler.option.registerFastInterrupt=None
69 | com.renesas.cdt.rxc.Release.Compiler.option.replaceFromIntWithShort=false
70 | com.renesas.cdt.rxc.Release.Compiler.option.roundTo=Nearest
71 | com.renesas.cdt.rxc.Release.Compiler.option.saveacc=false
72 | com.renesas.cdt.rxc.Release.Compiler.option.signBitField=unsigned
73 | com.renesas.cdt.rxc.Release.Compiler.option.signChar=unsigned
74 | com.renesas.cdt.rxc.Release.Compiler.option.useDynamic=false
75 | com.renesas.cdt.rxc.Release.Compiler.option.useTry=false
76 | com.renesas.cdt.rxc.Release.Compiler.option.widthDivergence=24 bit
77 | com.renesas.cdt.rxc.Release.StandardLibrary.option.endian=Little-endian data
78 | eclipse.preferences.version=1
79 |
--------------------------------------------------------------------------------
/examples/RX64M/.settings/com.renesas.cdt.managedbuild.renesas.ccrx.prefs:
--------------------------------------------------------------------------------
1 | com.renesas.cdt.managedbuild.renesas.ccrx.common.option.checkRtos=unusedRtos
2 | com.renesas.cdt.managedbuild.renesas.ccrx.rtosConfig.option.cfgFilePath=../src/${ProjName}.cfg
3 | com.renesas.cdt.managedbuild.renesas.ccrx.rtosConfig.option.output=${workspace_loc\:/${ProjName}}\\cfg_output
4 | com.renesas.cdt.managedbuild.renesas.ccrx.rtosConfig.option.rtosId=
5 | com.renesas.cdt.managedbuild.renesas.ccrx.rtosConfig.option.rtosName=None
6 | com.renesas.cdt.managedbuild.renesas.ccrx.rtosConfig.option.rtosPath=
7 | com.renesas.cdt.managedbuild.renesas.ccrx.rtosConfig.option.rtosVersion=
8 | eclipse.preferences.version=1
9 |
--------------------------------------------------------------------------------
/examples/RX64M/.settings/com.renesas.hardwaredebug.rx.e1.PerfAnalysisSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1.1
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/examples/RX64M/.settings/e2studio_project.prefs:
--------------------------------------------------------------------------------
1 | #
2 | #Thu Sep 05 08:42:16 CEST 2024
3 | activeConfiguration=com.renesas.cdt.managedbuild.renesas.ccrx.hardwaredebug.configuration.1937371311
4 |
--------------------------------------------------------------------------------
/examples/RX64M/.settings/fitsettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | false
4 |
5 |
--------------------------------------------------------------------------------
/examples/RX64M/custom.bat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szieke/embLua/000a7dea186d0e5653b7636442ee896dde3273a1/examples/RX64M/custom.bat
--------------------------------------------------------------------------------
/examples/RX64M/makefile.init:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Automatically-generated file. Do not edit!
3 | ################################################################################
4 |
5 | export INC_RX=D:\Sartorius\Sartocheck\src\au\trunk\tools\toolchain\include
6 | export RXC_LIB=D:\Sartorius\Sartocheck\src\au\trunk\tools\toolchain\bin
7 | export BIN_RX=D:\Sartorius\Sartocheck\src\au\trunk\tools\toolchain\bin
8 | PATH := $(PATH):D:\Sartorius\Sartocheck\src\au\trunk\tools\toolchain\bin
--------------------------------------------------------------------------------
/examples/RX64M/src/dbsct.c:
--------------------------------------------------------------------------------
1 | /***************************************************************/
2 | /* */
3 | /* PROJECT NAME : r01an1918_rx64m */
4 | /* FILE : dbsct.c */
5 | /* DESCRIPTION : Setting of B and R sections */
6 | /* CPU SERIES : RX600 */
7 | /* CPU TYPE : RX64M */
8 | /* */
9 | /* This file is generated by e2 studio. */
10 | /* */
11 | /***************************************************************/
12 |
13 |
14 |
15 |
16 | /************************************************************************
17 | *
18 | * Device : RX
19 | *
20 | * File Name : dbsct.c
21 | *
22 | * Abstract : Setting of B,R Section.
23 | *
24 | * History : 1.00 (2009-08-07)
25 | * : 1.10 (2013-02-13)
26 | *
27 | * NOTE : THIS IS A TYPICAL EXAMPLE.
28 | *
29 | * Copyright (C) 2009 Renesas Electronics Corporation.
30 | * and Renesas Solutions Corporation. All rights reserved.
31 | *
32 | ************************************************************************/
33 |
34 | #include "typedefine.h"
35 |
36 | #pragma unpack
37 |
38 | #pragma section C C$DSEC
39 | extern const struct {
40 | _UBYTE *rom_s; /* Start address of the initialized data section in ROM */
41 | _UBYTE *rom_e; /* End address of the initialized data section in ROM */
42 | _UBYTE *ram_s; /* Start address of the initialized data section in RAM */
43 | } _DTBL[] = {
44 | { __sectop("D"), __secend("D"), __sectop("R") },
45 | { __sectop("D_2"), __secend("D_2"), __sectop("R_2") },
46 | { __sectop("D_1"), __secend("D_1"), __sectop("R_1") }
47 | };
48 | #pragma section C C$BSEC
49 | extern const struct {
50 | _UBYTE *b_s; /* Start address of non-initialized data section */
51 | _UBYTE *b_e; /* End address of non-initialized data section */
52 | } _BTBL[] = {
53 | { __sectop("B"), __secend("B") },
54 | { __sectop("B_2"), __secend("B_2") },
55 | { __sectop("B_1"), __secend("B_1") }
56 | };
57 |
58 | #pragma section
59 |
60 | /*
61 | ** CTBL prevents excessive output of L1100 messages when linking.
62 | ** Even if CTBL is deleted, the operation of the program does not change.
63 | */
64 | _UBYTE * const _CTBL[] = {
65 | __sectop("C_1"), __sectop("C_2"), __sectop("C"),
66 | __sectop("W_1"), __sectop("W_2"), __sectop("W"),
67 | __sectop("L"), __sectop("SU"),
68 | __sectop("C$DSEC"), __sectop("C$BSEC"),
69 | __sectop("C$INIT"), __sectop("C$VTBL"), __sectop("C$VECT"),
70 | };
71 |
72 | #pragma packoption
73 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/Scripts/convertToHeader.bat:
--------------------------------------------------------------------------------
1 | %~dp0\..\..\..\..\..\lua\helper\lua-5.2.4_Win32_bin\lua52.exe %~dp0\..\..\..\..\..\lua\helper\convertToHeader.lua ./
2 |
3 | pause
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/Scripts/helperScript.h:
--------------------------------------------------------------------------------
1 | static const char* helperScript="local helperScriptCounter = 0\n\
2 | function includedScript ()\n\
3 | print(\"print from helperScript: \" .. tostring(helperScriptCounter) .. \"\\n\")\n\
4 | helperScriptCounter = helperScriptCounter+1\n\
5 | end";
6 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/Scripts/helperScript.lua:
--------------------------------------------------------------------------------
1 | local helperScriptCounter = 0
2 | function includedScript ()
3 | print("print from helperScript: " .. tostring(helperScriptCounter) .. "\n")
4 | helperScriptCounter = helperScriptCounter+1
5 | end
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/Scripts/script1.h:
--------------------------------------------------------------------------------
1 | static const char* script1="function script1Function ()\n\
2 | print('\\nscript1: ' .. tostring(uc.counter()) ..'\\n')\n\
3 | includedScript()\n\
4 | local example = 'an example string'\n\
5 | for el in string.gmatch(example, '%S+') do\n\
6 | print(el .. ' ')\n\
7 | end\n\
8 | print('\\n')\n\
9 | local result1, result2 = uc.func1('Testmessage')\n\
10 | print('result1: '.. tostring(result1) .. ' result2: '.. tostring(result2) .. '\\n')\n\
11 | local array = {0,1,2,3,4}\n\
12 | local resultTable = uc.func2(array)\n\
13 | print('test print:', 'string', 3, '\\n')\n\
14 | print('resultTable1: '.. tostring(resultTable[0]) .. ' resultTable2: '.. tostring(resultTable[1]) .. '\\n')\n\
15 | print('heap usage before collect: ' .. tostring(collectgarbage('count')*1024) .. '\\n')\n\
16 | collectgarbage('collect')\n\
17 | print('heap usage after collect: ' .. tostring(collectgarbage('count')*1024) .. '\\n')\n\
18 | error({code=121})\n\
19 | end\n\
20 | for loopCounter=0,2 do\n\
21 | local status, err = pcall(script1Function)\n\
22 | print(err.code .. '\\n')\n\
23 | end";
24 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/Scripts/script1.lua:
--------------------------------------------------------------------------------
1 | function script1Function ()
2 | print('\nscript1: ' .. tostring(uc.counter()) ..'\n')
3 |
4 | --Call a function from an other script (helperScript.lua).
5 | includedScript()
6 |
7 | --Split a string and print the result.
8 | local example = 'an example string'
9 | for el in string.gmatch(example, '%S+') do
10 | print(el .. ' ')
11 | end
12 | print('\n')
13 | --[[ test muli line comment:
14 | line 2
15 | line 3
16 | --]]
17 |
18 | --Call C-function func1 and print the result.
19 | local result1, result2 = uc.func1('Testmessage')
20 | print('result1: '.. tostring(result1) .. ' result2: '.. tostring(result2) .. '\n')
21 |
22 | --Call C-function func2 and print the result.
23 | local array = {0,1,2,3,4}
24 | local resultTable = uc.func2(array)
25 | print('test print:', 'string', 3, '\n')
26 | print('resultTable1: '.. tostring(resultTable[0]) .. ' resultTable2: '.. tostring(resultTable[1]) .. '\n')
27 |
28 | --Print the heap usage, collect garbage and then print the heap usage again.
29 | print('heap usage before collect: ' .. tostring(collectgarbage('count')*1024) .. '\n')
30 | collectgarbage('collect')
31 | print('heap usage after collect: ' .. tostring(collectgarbage('count')*1024) .. '\n')
32 | end
33 |
34 | for loopCounter=0,2 do
35 | print(pcall(script1Function), '\n')
36 | end
37 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/Scripts/script2.h:
--------------------------------------------------------------------------------
1 | static const char* script2="print('\\nscript2: ' .. tostring(uc.counter()) ..'\\n')\n\
2 | includedScript()\n\
3 | print('heap usage: ' .. tostring(collectgarbage('count')*1024) .. '\\n')";
4 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/Scripts/script2.lua:
--------------------------------------------------------------------------------
1 | print('\nscript2: ' .. tostring(uc.counter()) ..'\n')
2 |
3 | --Call a function from an other script (helperScript.lua).
4 | includedScript()
5 |
6 | --Print the heap usage.
7 | print('heap usage: ' .. tostring(collectgarbage('count')*1024) .. '\n')
8 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/luaInterface.c:
--------------------------------------------------------------------------------
1 |
2 | #include "luaInterface.h"
3 |
4 | #include "../../../lua/lua.h"
5 | #include "../../../lua/lauxlib.h"
6 | #include "../../../lua/lualib.h"
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | //This function is called by Lua cannot handle an occured error.
13 | void luaAbort(void)
14 | {
15 | lua_writestringerror("luaAbort", sizeof("luaAbort"));
16 | while(1){}
17 | }
18 |
19 |
20 | int func1(lua_State *L)
21 | {
22 | size_t size;
23 | const char *message = luaL_checklstring(L, 1, &size);
24 |
25 | const char* msg = "C func1:";
26 | lua_writestring(msg, strlen(msg));
27 | lua_writestring(message, size);
28 | lua_writeline();
29 |
30 | //Cleanup the stack.
31 | int n = lua_gettop(L);
32 | lua_pop(L, n);
33 |
34 |
35 | //Create the result.
36 | lua_pushinteger(L, 1);
37 | lua_pushinteger(L, 2);
38 |
39 | return 2;//2 results
40 | }
41 |
42 | int func2(lua_State *L)
43 | {
44 | luaL_checktype(L, 1, LUA_TTABLE);
45 |
46 | lua_settop(L, 1);
47 |
48 |
49 | const char* msg = "C func2:";
50 | lua_writestring(msg, strlen(msg));
51 |
52 |
53 | lua_gettable(L, 1);
54 |
55 | //Add dummy value for the last lua_pop.
56 | lua_pushnil(L);
57 |
58 | while(lua_next(L, -2))
59 | {
60 | lua_Integer b = (int)lua_tonumber(L, -1);
61 | char value = 48 + b;
62 | lua_writestring(" ", 1);
63 | lua_writestring(&value, 1);
64 | lua_pop(L, 1);
65 | }
66 |
67 | lua_writeline();
68 |
69 | //Cleanup the stack.
70 | int n = lua_gettop(L);
71 | lua_pop(L, n);
72 |
73 |
74 | //Create the result.
75 | lua_newtable(L);
76 | lua_pushinteger(L, 5);
77 | lua_rawseti(L, -2, 0);
78 | lua_pushinteger(L, 9);
79 | lua_rawseti(L, -2, 1);
80 |
81 | return 1;
82 | }
83 |
84 | int counterFunction(lua_State *L)
85 | {
86 | static uint32_t counter = 0;
87 |
88 | counter++;
89 | lua_pushinteger(L, counter);
90 | return 1;
91 | }
92 |
93 |
94 | static const luaL_Reg uC_funcs[] = {
95 | {"func1", func1},
96 | {"func2", func2},
97 | {"counter", counterFunction},
98 | {NULL, NULL}
99 | };
100 |
101 |
102 | LUAMOD_API int luaopen_uc (lua_State *L) {
103 | luaL_newlib(L, uC_funcs);
104 | return 1;
105 | }
106 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/luaInterface.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef LUAINTERFACE_H_
4 | #define LUAINTERFACE_H_
5 |
6 | #include "lua.h"
7 |
8 | //
9 | #define LUA_INTERFACE_LIBS {"uc", luaopen_uc}
10 |
11 |
12 | LUAMOD_API int (luaopen_uc) (lua_State *L);
13 |
14 |
15 |
16 | #endif /* LUAINTERFACE_H_ */
17 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/luaProjectConfig.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef LUAPROJECTCONFIG_H_
3 | #define LUAPROJECTCONFIG_H_
4 |
5 | #include
6 | #include
7 | #include
8 | #include "helper/luaHeap.h"
9 | #include "trace_uart.h"
10 |
11 |
12 | //This function is called by Lua if it cannot handle an occurred error.
13 | void luaAbort(void);
14 |
15 | //If the math module shall be included then this define must be defined.
16 | //define LUA_WITH_MATH
17 |
18 | //The size of the heap used by Lua.
19 | #define LUA_HEAP_SIZE (20000)
20 |
21 | //These defines are used to protect the memory management calls if several Lua instances in different threads are created.
22 | #define LUA_MEM_ENTER_CRITICAL_SECTION()
23 | #define LUA_MEM_LEAVE_CRITICAL_SECTION()
24 |
25 | //Function for printing text from lua.
26 | #define lua_writestring(string,length) trace_write((uint8_t*) string, length, TRUE);
27 | #define lua_writeline() lua_writestring("\n", 1);
28 | #define lua_writestringerror(string,length) lua_writestring(string, length);
29 |
30 |
31 | #endif /* LUAPROJECTCONFIG_H_ */
32 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/printFreeHeap.c:
--------------------------------------------------------------------------------
1 |
2 | #include "printFreeHeap.h"
3 |
4 | #include "../../../lua/lua.h"
5 | #include "../../../lua/lauxlib.h"
6 | #include "../../../lua/lualib.h"
7 | #include "../../../lua/helper/luaHeap.h"
8 | #include "../../../lua/luaconf.h"
9 | #include "luaInterface.h"
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | void printFreeHeap(char* message)
16 | {
17 | char buffer[16];
18 | size_t size = luaGetFreeHeapSize();
19 |
20 | snprintf(buffer, 16, "%i", size);
21 | lua_writestring(message, strlen(message));
22 | lua_writestring(buffer, strlen(buffer));
23 | lua_writeline();
24 | }
25 |
26 | void printMinimumFreeHeap()
27 | {
28 | char buffer[16];
29 | size_t size = luaGetMinimumEverFreeHeapSize();
30 |
31 | snprintf(buffer, 16, "%i", size);
32 | lua_writestring("minimum free heap: ", sizeof("minimum free heap: ") - 1);
33 | lua_writestring(buffer, strlen(buffer));
34 | lua_writeline();
35 | }
36 |
--------------------------------------------------------------------------------
/examples/RX64M/src/luaProject/printFreeHeap.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef LUAPROJECT_PRINTFREEHEAP_H_
4 | #define LUAPROJECT_PRINTFREEHEAP_H_
5 |
6 |
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 |
12 | void printFreeHeap(char* message);
13 | void printMinimumFreeHeap();
14 |
15 | #ifdef __cplusplus
16 | }
17 | #endif
18 |
19 |
20 |
21 | #endif /* LUAPROJECT_PRINTFREEHEAP_H_ */
22 |
--------------------------------------------------------------------------------
/examples/RX64M/src/main.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include "iodefine.h"
5 | #include "r_init_clock.h"
6 | #include "r_init_stop_module.h"
7 |
8 | #include "trace_uart.h"
9 |
10 | #define lua_c
11 |
12 | #include "lprefix.h"
13 | #include
14 |
15 | #include "lua.h"
16 | #include "lauxlib.h"
17 | #include "lualib.h"
18 |
19 | #include "luaHelper.h"
20 |
21 | #include "script1.h"
22 | #include "script2.h"
23 | #include "helperScript.h"
24 | #include "printFreeHeap.h"
25 |
26 | void main(void);
27 |
28 | #ifdef __cplusplus
29 | extern "C"
30 | {
31 | void abort(void);
32 | }
33 | #endif
34 |
35 | void main(void)
36 | {
37 | char* mesg;
38 | /* ---- Disable maskable interrupts ---- */
39 | clrpsw_i();
40 |
41 | /* ---- Stopping the peripherals which start operations ---- */
42 | R_INIT_StopModule();
43 |
44 | /* ---- Initialization of the clock ---- */
45 | R_INIT_Clock();
46 |
47 | trace_initializeUart();
48 |
49 | setpsw_i();
50 |
51 | mesg = "Start\n";
52 | lua_writestring(mesg, strlen(mesg));
53 |
54 | //Create the lua state.
55 | lua_State *L = luaL_newstate();
56 | if (L == NULL)
57 | {
58 | mesg = "cannot create state: not enough memory";
59 | lua_writestring(mesg, strlen(mesg));
60 | while (1);
61 | }
62 | else
63 | {
64 | //Open the standard libraries.
65 | luaL_openlibs(L);
66 |
67 | //Load the helper script.
68 | if (dostring(L, helperScript, "helperScript") != LUA_OK)
69 | {
70 | while (1);
71 | }
72 |
73 | while (1)
74 | {
75 | //Execute script 1.
76 | if (dostring(L, script1, "script1") != LUA_OK)
77 | {
78 | while (1);
79 | }
80 |
81 | //Collect garbage.
82 | lua_gc(L, LUA_GCCOLLECT, 0);
83 |
84 | lua_writeline();
85 |
86 | //Execute script 2.
87 | if (dostring(L, script2, "script2") != LUA_OK)
88 | {
89 | while (1);
90 | }
91 |
92 | lua_writeline();
93 | printMinimumFreeHeap();
94 |
95 | mesg = "\n****************************************************************************\n";
96 | lua_writestring(mesg, strlen(mesg));
97 |
98 | }//while (1)
99 | }
100 | }
101 |
102 | #ifdef __cplusplus
103 | void abort(void)
104 | {
105 | lua_writestring("\nabort\n", sizeof("\nabort\n") - 1);
106 | }
107 | #endif
108 |
109 | /* End of File */
110 |
111 |
--------------------------------------------------------------------------------
/examples/RX64M/src/r_init_stop_module.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * DISCLAIMER
3 | * This software is supplied by Renesas Electronics Corporation and is only
4 | * intended for use with Renesas products. No other uses are authorized. This
5 | * software is owned by Renesas Electronics Corporation and is protected under
6 | * all applicable laws, including copyright laws.
7 | * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
8 | * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
9 | * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
10 | * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
11 | * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
12 | * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
13 | * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
14 | * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
15 | * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
16 | * Renesas reserves the right, without notice, to make changes to this software
17 | * and to discontinue the availability of this software. By using this software,
18 | * you agree to the additional terms and conditions found by accessing the
19 | * following link:
20 | * http://www.renesas.com/disclaimer
21 | *
22 | * Copyright (C) 2017 Renesas Electronics Corporation. All rights reserved.
23 | *******************************************************************************/
24 | /*******************************************************************************
25 | * System Name : RX64M initialization example
26 | * File Name : r_init_stop_module.c
27 | * Version : Ver 1.00
28 | * Device : R5F564MLDxFC(RX64M Group)
29 | * Abstract : Program example of RX64M initialization
30 | * Tool-Chain : e2 studio Version 5.4.0.015
31 | * : C/C++ Compiler Package for RX Family (V.2.06.00)
32 | * OS : not use
33 | * H/W Platform : Renesas Starter Kit for RX64M
34 | * Description : Configure the setting to enter module-stop state.
35 | * Limitation : none
36 | *******************************************************************************/
37 | /*******************************************************************************
38 | * History : DD.MM.YYYY Version Description
39 | * : 31.05.2017 1.00 First Release
40 | *******************************************************************************/
41 |
42 | /*******************************************************************************
43 | Includes , "Project Includes"
44 | *******************************************************************************/
45 | #include "iodefine.h"
46 | #include "r_init_stop_module.h"
47 |
48 |
49 | /*******************************************************************************
50 | * Outline : Stopping the peripherals which start operations after a reset
51 | * Header : r_init_stop_module.h
52 | * Function Name: R_INIT_StopModule
53 | * Description : Configure the setting to enter module-stop state.
54 | * Arguments : none
55 | * Return Value : none
56 | *******************************************************************************/
57 | void R_INIT_StopModule (void)
58 | {
59 |
60 | /* ---- Enable write protection ---- */
61 | /* PRCR - Protect Register
62 | b15:b8 PRKEY - PRC Key Code - A5h
63 | (The write value should be A5h to permission writing PRCi bit)
64 | b7:b4 Reserved - The write value should be 0.
65 | b3 PRC3 - Protect Bit 3 - Write disabled
66 | b2 Reserved - The write value should be 0.
67 | b1 PRC1 - Protect Bit 1 - Write enabled
68 | b0 PRC0 - Protect Bit 0 - Write disabled */
69 | SYSTEM.PRCR.WORD = 0xA502;
70 |
71 | /* ---- Set transition to module-stop state ---- */
72 | #if MSTP_STATE_EXDMAC == MODULE_STOP_ENABLE
73 | MSTP(EXDMAC0) = 1; /* EXDMAC trans to module-stop state */
74 | #endif
75 |
76 | #if MSTP_STATE_DMACDTC == MODULE_STOP_ENABLE
77 | MSTP(DTC) = 1; /* DMAC/DTC trans to module-stop state */
78 | #endif
79 |
80 | #if MSTP_STATE_STBYRAM == MODULE_STOP_ENABLE
81 | MSTP(STBYRAM) = 1; /* STBYRAM trans to module-stop state */
82 | #endif
83 |
84 | #if MSTP_STATE_ECCRAM == MODULE_STOP_ENABLE
85 | MSTP(ECCRAM) = 1; /* ECCRAM trans to module-stop state */
86 | #endif
87 |
88 | #if MSTP_STATE_RAM0 == MODULE_STOP_ENABLE
89 | MSTP(RAM0) = 1; /* RAM0 trans to module-stop state */
90 | #endif
91 |
92 | /* ---- Disable write protection ---- */
93 | /* PRCR - Protect Register
94 | b15:b8 PRKEY - PRC Key Code - A5h
95 | (The write value should be A5h to permission writing PRCi bit)
96 | b1 PRC1 - Protect Bit 1 - Write disabled */
97 | SYSTEM.PRCR.WORD = 0xA500;
98 |
99 | }
100 |
101 | /* End of File */
102 |
103 |
--------------------------------------------------------------------------------
/examples/RX64M/src/r_init_stop_module.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * DISCLAIMER
3 | * This software is supplied by Renesas Electronics Corporation and is only
4 | * intended for use with Renesas products. No other uses are authorized. This
5 | * software is owned by Renesas Electronics Corporation and is protected under
6 | * all applicable laws, including copyright laws.
7 | * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
8 | * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
9 | * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
10 | * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
11 | * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
12 | * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
13 | * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
14 | * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
15 | * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
16 | * Renesas reserves the right, without notice, to make changes to this software
17 | * and to discontinue the availability of this software. By using this software,
18 | * you agree to the additional terms and conditions found by accessing the
19 | * following link:
20 | * http://www.renesas.com/disclaimer
21 | *
22 | * Copyright (C) 2017 Renesas Electronics Corporation. All rights reserved.
23 | *******************************************************************************/
24 | /*******************************************************************************
25 | * System Name : RX64M initialization example
26 | * File Name : r_init_stop_module.c
27 | * Version : Ver 1.00
28 | * Device : R5F564MLDxFC(RX64M Group)
29 | * Abstract : Program example of RX64M initialization
30 | * Tool-Chain : e2 studio Version 5.4.0.015
31 | * : C/C++ Compiler Package for RX Family (V.2.06.00)
32 | * OS : not use
33 | * H/W Platform : Renesas Starter Kit for RX64M
34 | * Description : Configure the setting to enter module-stop state.
35 | * Limitation : none
36 | *******************************************************************************/
37 | /*******************************************************************************
38 | * History : DD.MM.YYYY Version Description
39 | * : 31.05.2017 1.00 First Release
40 | *******************************************************************************/
41 |
42 | /* Guards against multiple inclusion */
43 | #ifndef R_INIT_STOP_MODULE_H
44 | #define R_INIT_STOP_MODULE_H
45 |
46 | #ifdef __cplusplus
47 | extern "C"
48 | {
49 | #endif
50 |
51 | /*******************************************************************************
52 | Macro definitions
53 | *******************************************************************************/
54 | #define MODULE_STOP_ENABLE (1)
55 | #define MODULE_STOP_DISABLE (0)
56 |
57 | #define MSTP_STATE_EXDMAC (MODULE_STOP_DISABLE) /* EXDMAC module-stop state */
58 | #define MSTP_STATE_DMACDTC (MODULE_STOP_DISABLE) /* DMAC/DTC module-stop state */
59 | #define MSTP_STATE_STBYRAM (MODULE_STOP_DISABLE) /* STBYRAM module-stop state */
60 | #define MSTP_STATE_ECCRAM (MODULE_STOP_DISABLE) /* ECCRAM module-stop-state */
61 | #define MSTP_STATE_RAM0 (MODULE_STOP_DISABLE) /* RAM0 module-stop state */
62 |
63 | /*******************************************************************************
64 | Exported global variables and functions (to be accessed by other files)
65 | *******************************************************************************/
66 | void R_INIT_StopModule(void);
67 |
68 | #ifdef __cplusplus
69 | }
70 | #endif
71 |
72 | #endif /* R_INIT_STOP_MODULE_H */
73 |
74 | /* End of File */
75 |
76 |
--------------------------------------------------------------------------------
/examples/RX64M/src/reset_program.c:
--------------------------------------------------------------------------------
1 | /***************************************************************/
2 | /* */
3 | /* PROJECT NAME : r01an1918_rx64m */
4 | /* FILE : reset_program.c */
5 | /* DESCRIPTION : Reset program */
6 | /* CPU SERIES : RX600 */
7 | /* CPU TYPE : RX64M */
8 | /* */
9 | /* This file is generated by e2 studio. */
10 | /* */
11 | /***************************************************************/
12 |
13 |
14 |
15 |
16 | /*********************************************************************
17 | *
18 | * Device : RX/RX600
19 | *
20 | * File Name : resetprg.c
21 | *
22 | * Abstract : Reset Program.
23 | *
24 | * History : 1.00 (2009-08-07)
25 | * : 1.10 (2011-02-21)
26 | * : 1.11 (2011-06-20)
27 | * : 1.12 (2014-02-20)
28 | * : 1.20 (2014-10-22)
29 | *
30 | * NOTE : THIS IS A TYPICAL EXAMPLE.
31 | *
32 | * Copyright (C) 2009 (2014) Renesas Electronics Corporation.
33 | * and Renesas Solutions Corp.
34 | *
35 | *********************************************************************/
36 |
37 | #include
38 | #include <_h_c_lib.h>
39 | //#include // Remove the comment when you use errno
40 | //#include // Remove the comment when you use rand()
41 | #include "typedefine.h" // Define Types
42 | #include "stacksct.h" // Stack Sizes (Interrupt and User)
43 |
44 | #ifdef __cplusplus
45 | extern "C" {
46 | #endif
47 | void PowerON_Reset_PC(void);
48 | void main(void);
49 | #ifdef __cplusplus
50 | }
51 | #endif
52 |
53 | //#ifdef __cplusplus // Use SIM I/O
54 | //extern "C" {
55 | //#endif
56 | //extern void _INIT_IOLIB(void);
57 | //extern void _CLOSEALL(void);
58 | //#ifdef __cplusplus
59 | //}
60 | //#endif
61 |
62 | #define PSW_init 0x00010000 // PSW bit pattern
63 | #define FPSW_init 0x00000000 // FPSW bit base pattern
64 |
65 | //extern void srand(_UINT); // Remove the comment when you use rand()
66 | //extern _SBYTE *_s1ptr; // Remove the comment when you use strtok()
67 |
68 | //#ifdef __cplusplus // Use Hardware Setup
69 | //extern "C" {
70 | //#endif
71 | //extern void HardwareSetup(void);
72 | //#ifdef __cplusplus
73 | //}
74 | //#endif
75 |
76 | //#ifdef __cplusplus // Remove the comment when you use global class object
77 | //extern "C" { // Sections C$INIT and C$END will be generated
78 | //#endif
79 | //extern void _CALL_INIT(void);
80 | //extern void _CALL_END(void);
81 | //#ifdef __cplusplus
82 | //}
83 | //#endif
84 |
85 | #pragma section ResetPRG // output PowerON_Reset to PResetPRG section
86 |
87 | #pragma entry PowerON_Reset_PC
88 |
89 | void PowerON_Reset_PC(void)
90 | {
91 | #ifdef __RXV2
92 | set_extb(__sectop("EXCEPTVECT"));
93 | #endif
94 | set_intb(__sectop("C$VECT"));
95 |
96 | #ifdef __FPU
97 | #ifdef __ROZ // Initialize FPSW
98 | #define _ROUND 0x00000001 // Let FPSW RMbits=01 (round to zero)
99 | #else
100 | #define _ROUND 0x00000000 // Let FPSW RMbits=00 (round to nearest)
101 | #endif
102 | #ifdef __DOFF
103 | #define _DENOM 0x00000100 // Let FPSW DNbit=1 (denormal as zero)
104 | #else
105 | #define _DENOM 0x00000000 // Let FPSW DNbit=0 (denormal as is)
106 | #endif
107 | set_fpsw(FPSW_init | _ROUND | _DENOM);
108 | #endif
109 |
110 | _INITSCT();
111 |
112 | // _INIT_IOLIB(); // Use SIM I/O
113 |
114 | // errno=0; // Remove the comment when you use errno
115 | // srand((_UINT)1); // Remove the comment when you use rand()
116 | // _s1ptr=NULL; // Remove the comment when you use strtok()
117 |
118 | // HardwareSetup(); // Use Hardware Setup
119 | nop();
120 |
121 | // _CALL_INIT(); // Remove the comment when you use global class object
122 |
123 | set_psw(PSW_init); // Set Ubit & Ibit for PSW
124 | // chg_pmusr(); // Remove the comment when you need to change PSW PMbit (SuperVisor->User)
125 |
126 | main();
127 |
128 | // _CLOSEALL(); // Use SIM I/O
129 |
130 | // _CALL_END(); // Remove the comment when you use global class object
131 |
132 | brk();
133 | }
134 |
135 |
--------------------------------------------------------------------------------
/examples/RX64M/src/sbrk.c:
--------------------------------------------------------------------------------
1 | /***************************************************************/
2 | /* */
3 | /* PROJECT NAME : r01an1918_rx64m */
4 | /* FILE : sbrk.c */
5 | /* DESCRIPTION : Program of sbrk */
6 | /* CPU SERIES : RX600 */
7 | /* CPU TYPE : RX64M */
8 | /* */
9 | /* This file is generated by e2 studio. */
10 | /* */
11 | /***************************************************************/
12 |
13 |
14 |
15 |
16 | /*********************************************************************
17 | *
18 | * Device : RX
19 | *
20 | * File Name : sbrk.c
21 | *
22 | * Abstract : Program of sbrk.
23 | *
24 | * History : 1.00 (2009-08-07)
25 | *
26 | * NOTE : THIS IS A TYPICAL EXAMPLE.
27 | *
28 | * Copyright (C) 2009 Renesas Electronics Corporation.
29 | * and Renesas Solutions Corporation. All rights reserved.
30 | *
31 | *********************************************************************/
32 |
33 | #include
34 | #include
35 | #include "typedefine.h"
36 | #include "sbrk.h"
37 |
38 | _SBYTE *sbrk(size_t size);
39 |
40 | //const size_t _sbrk_size= /* Specifies the minimum unit of */
41 | /* the defined heap area */
42 |
43 | extern _SBYTE *_s1ptr;
44 |
45 | union HEAP_TYPE {
46 | _SDWORD dummy ; /* Dummy for 4-byte boundary */
47 | _SBYTE heap[HEAPSIZE]; /* Declaration of the area managed by sbrk */
48 | };
49 |
50 | static union HEAP_TYPE heap_area ;
51 |
52 | /* End address allocated by sbrk */
53 | static _SBYTE *brk=(_SBYTE *)&heap_area;
54 |
55 | /**************************************************************************/
56 | /* sbrk:Memory area allocation */
57 | /* Return value:Start address of allocated area (Pass) */
58 | /* -1 (Failure) */
59 | /**************************************************************************/
60 | _SBYTE *sbrk(size_t size) /* Assigned area size */
61 | {
62 | _SBYTE *p;
63 |
64 | if(brk+size > heap_area.heap+HEAPSIZE){ /* Empty area size */
65 | p = (_SBYTE *)-1;
66 | }
67 | else {
68 | p = brk; /* Area assignment */
69 | brk += size; /* End address update */
70 | }
71 | return p;
72 | }
73 |
74 |
--------------------------------------------------------------------------------
/examples/RX64M/src/sbrk.h:
--------------------------------------------------------------------------------
1 | /***************************************************************/
2 | /* */
3 | /* PROJECT NAME : r01an1918_rx64m */
4 | /* FILE : sbrk.h */
5 | /* DESCRIPTION : Header file of sbrk file */
6 | /* CPU SERIES : RX600 */
7 | /* CPU TYPE : RX64M */
8 | /* */
9 | /* This file is generated by e2 studio. */
10 | /* */
11 | /***************************************************************/
12 |
13 | /* size of area managed by sbrk */
14 | #define HEAPSIZE 0x1000
15 |
--------------------------------------------------------------------------------
/examples/RX64M/src/stacksct.h:
--------------------------------------------------------------------------------
1 | /***************************************************************/
2 | /* */
3 | /* PROJECT NAME : r01an1918_rx64m */
4 | /* FILE : stacksct.h */
5 | /* DESCRIPTION : Setting of Stack area */
6 | /* CPU SERIES : RX600 */
7 | /* CPU TYPE : RX64M */
8 | /* */
9 | /* This file is generated by e2 studio. */
10 | /* */
11 | /***************************************************************/
12 | #pragma stacksize su=0xC00
13 | #pragma stacksize si=0xC00
14 |
--------------------------------------------------------------------------------
/examples/RX64M/src/typedefine.h:
--------------------------------------------------------------------------------
1 | /***************************************************************/
2 | /* */
3 | /* PROJECT NAME : r01an1918_rx64m */
4 | /* FILE : typedefine.h */
5 | /* DESCRIPTION : Aliases of Integer Type */
6 | /* CPU SERIES : RX600 */
7 | /* CPU TYPE : RX64M */
8 | /* */
9 | /* This file is generated by e2 studio. */
10 | /* */
11 | /***************************************************************/
12 |
13 |
14 |
15 |
16 | /*********************************************************************
17 | *
18 | * Device : RX
19 | *
20 | * File Name : typedefine.h
21 | *
22 | * Abstract : Aliases of Integer Type.
23 | *
24 | * History : 1.00 (2009-08-07)
25 | *
26 | * NOTE : THIS IS A TYPICAL EXAMPLE.
27 | *
28 | * Copyright (C) 2009 Renesas Electronics Corporation.
29 | * and Renesas Solutions Corporation. All rights reserved.
30 | *
31 | *********************************************************************/
32 |
33 | typedef signed char _SBYTE;
34 | typedef unsigned char _UBYTE;
35 | typedef signed short _SWORD;
36 | typedef unsigned short _UWORD;
37 | typedef signed int _SINT;
38 | typedef unsigned int _UINT;
39 | typedef signed long _SDWORD;
40 | typedef unsigned long _UDWORD;
41 | typedef signed long long _SQWORD;
42 | typedef unsigned long long _UQWORD;
43 |
--------------------------------------------------------------------------------
/examples/RX64M/src/uart/trace_uart.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef _UART_API_H_
3 | #define _UART_API_H_
4 |
5 |
6 | #include "stdint.h"
7 |
8 | #ifdef __cplusplus
9 | extern "C"
10 | {
11 | #endif
12 |
13 | #define TRACE_TRANSMIT_BUFFER_SIZE 1024
14 | #define TRACE_RECEIVE_BUFFER_SIZE 1024
15 |
16 | #ifndef bool_t
17 | typedef unsigned char bool_t;
18 | #endif
19 |
20 | #ifndef TRUE
21 | #define TRUE 1
22 | #endif
23 |
24 | #ifndef FALSE
25 | #define FALSE 0
26 | #endif
27 |
28 | #define TRACE_RECEIVE_EVENT 0x10000000
29 |
30 | void trace_initializeUart();
31 |
32 | uint32_t trace_write(const uint8_t buffer[], const uint32_t bufferSize, bool_t waitUntilAllBytesAreInBuffer);
33 |
34 |
35 | uint32_t trace_peak(void);
36 |
37 | uint32_t trace_read(uint8_t buffer[], const uint32_t bufferSize);
38 |
39 | #ifdef __cplusplus
40 | }
41 | #endif
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/examples/RX64M/src/vector_table.c:
--------------------------------------------------------------------------------
1 | /***************************************************************/
2 | /* */
3 | /* PROJECT NAME : r01an1918_rx64m */
4 | /* FILE : vector_table.c */
5 | /* DESCRIPTION : Vector Table */
6 | /* CPU SERIES : RX600 */
7 | /* CPU TYPE : RX64M */
8 | /* */
9 | /* This file is generated by e2 studio. */
10 | /* */
11 | /***************************************************************/
12 |
13 | /************************************************************************
14 | *
15 | * Device : RX/RX600/RX64M
16 | *
17 | * File Name : vecttbl.c
18 | *
19 | * Abstract : Initialize of Vector Table.
20 | *
21 | * History : 0.10 (2013-05-30) [Hardware Manual Revision : 0.40]
22 | * : 0.50 (2014-01-22) [Hardware Manual Revision : 0.50]
23 | * : 0.80 (2014-02-20) [Hardware Manual Revision : 0.80]
24 | * : 1.00 (2014-10-20) [Hardware Manual Revision : 1.00]
25 | *
26 | * NOTE : THIS IS A TYPICAL EXAMPLE.
27 | *
28 | * Copyright (C) 2013(2014) Renesas Electronics Corporation.
29 | *
30 | ************************************************************************/
31 |
32 | #include "vect.h"
33 |
34 | #pragma section C EXCEPTVECT
35 | void (*const Except_Vectors[])(void) = {
36 | //;0xffffff80 Reserved
37 | Dummy,
38 | //;0xffffff84 Reserved
39 | Dummy,
40 | //;0xffffff88 Reserved
41 | Dummy,
42 | //;0xffffff8c Reserved
43 | Dummy,
44 | //;0xffffff90 Reserved
45 | Dummy,
46 | //;0xffffff94 Reserved
47 | Dummy,
48 | //;0xffffff98 Reserved
49 | Dummy,
50 | //;0xffffff9c Reserved
51 | Dummy,
52 | //;0xffffffa0 Reserved
53 | Dummy,
54 | //;0xffffffa4 Reserved
55 | Dummy,
56 | //;0xffffffa8 Reserved
57 | Dummy,
58 | //;0xffffffac Reserved
59 | Dummy,
60 | //;0xffffffb0 Reserved
61 | Dummy,
62 | //;0xffffffb4 Reserved
63 | Dummy,
64 | //;0xffffffb8 Reserved
65 | Dummy,
66 | //;0xffffffbc Reserved
67 | Dummy,
68 | //;0xffffffc0 Reserved
69 | Dummy,
70 | //;0xffffffc4 Reserved
71 | Dummy,
72 | //;0xffffffc8 Reserved
73 | Dummy,
74 | //;0xffffffcc Reserved
75 | Dummy,
76 | //;0xffffffd0 Exception(Supervisor Instruction)
77 | Excep_SuperVisorInst,
78 | //;0xffffffd4 Exception(Access Instruction)
79 | Excep_AccessInst,
80 | //;0xffffffd8 Reserved
81 | Dummy,
82 | //;0xffffffdc Exception(Undefined Instruction)
83 | Excep_UndefinedInst,
84 | //;0xffffffe0 Reserved
85 | Dummy,
86 | //;0xffffffe4 Exception(Floating Point)
87 | Excep_FloatingPoint,
88 | //;0xffffffe8 Reserved
89 | Dummy,
90 | //;0xffffffec Reserved
91 | Dummy,
92 | //;0xfffffff0 Reserved
93 | Dummy,
94 | //;0xfffffff4 Reserved
95 | Dummy,
96 | //;0xfffffff8 NMI
97 | NonMaskableInterrupt,
98 | };
99 |
100 | #pragma section C RESETVECT
101 | void (*const Reset_Vectors[])(void) = {
102 | //;<>
103 | //;Power On Reset PC
104 | /*(void*)*/ PowerON_Reset_PC
105 | //;<>
106 | };
107 |
108 |
109 | #pragma address __SPCCreg=0x00120040 // SPCC register
110 | const unsigned long __SPCCreg = 0xffffffff;
111 |
112 | #pragma address __TMEFreg=0x00120048 // TMEF register
113 | const unsigned long __TMEFreg = 0xffffffff;
114 |
115 | #pragma address __OSISreg=0x00120050 // OSIC register (ID codes)
116 | const unsigned long __OSISreg[4] = {
117 | 0xffffffff,
118 | 0xffffffff,
119 | 0xffffffff,
120 | 0xffffffff,
121 | };
122 |
123 | #pragma address __TMINFreg=0x00120060 // TMINF register
124 | const unsigned long __TMINFreg = 0xffffffff;
125 |
126 | #pragma address __MDEreg=0x00120064 // MDE register (Single Chip Mode)
127 | #ifdef __BIG
128 | const unsigned long __MDEreg = 0xfffffff8; // big
129 | #else
130 | const unsigned long __MDEreg = 0xffffffff; // little
131 | #endif
132 |
133 | #pragma address __OFS0reg=0x00120068 // OFS0 register
134 | const unsigned long __OFS0reg = 0xffffffff;
135 |
136 | #pragma address __OFS1reg=0x0012006c // OFS1 register
137 | const unsigned long __OFS1reg = 0xffffffff;
138 |
--------------------------------------------------------------------------------
/examples/STM32L552/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | uC
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | com.st.stm32cube.ide.mcu.MCUProjectNature
23 | org.eclipse.cdt.core.cnature
24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature
25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature
26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature
27 | com.st.stm32cube.ide.mcu.MCUNonSecureProjectNature
28 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature
29 | com.st.stm32cube.ide.mcu.MCURootProjectNature
30 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
31 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
32 |
33 |
34 |
35 | lua
36 | 2
37 | PARENT-2-PROJECT_LOC/lua
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/examples/STM32L552/.settings/com.st.stm32cube.ide.mcu.sfrview.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | sfrviewstate={"fFavorites"\:{"fLists"\:{}},"fProperties"\:{"fNodeProperties"\:{}}}
3 |
--------------------------------------------------------------------------------
/examples/STM32L552/.settings/language.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/examples/STM32L552/Application/Include/app_global.h:
--------------------------------------------------------------------------------
1 | #ifndef __GLOBAL_H
2 | #define __GLOBAL_H
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include "stdint.h"
9 | #include "luaProjectConfig.h"
10 |
11 | #define UC_UID_ADDRESS 0x0BFA0590
12 |
13 | typedef unsigned char bool_t;
14 |
15 | /*! \brief Current major SW version of the SW. */
16 | #define RLS_SW_VERSION_MAJOR ((uint8_t)1U)
17 |
18 | /*! \brief Current minor SW version of the SW */
19 | #define RLS_SW_VERSION_MINOR ((uint8_t)2U)
20 |
21 | #ifndef NULL
22 | /*! \brief NULL */
23 | #define NULL ((void*)0)
24 | #endif
25 |
26 | #ifndef FALSE
27 | /*! \brief FALSE */
28 | #define FALSE ((bool_t)0U)
29 | #endif
30 |
31 | #ifndef TRUE
32 | /*! \brief TRUE */
33 | #define TRUE (((bool_t)!FALSE))
34 | #endif
35 |
36 | #ifndef STATIC
37 | #define STATIC static
38 | #endif /* ifndef STATIC */
39 |
40 | #ifndef CONST
41 | #define CONST const
42 | #endif /* ifndef CONST */
43 |
44 | typedef enum
45 | {
46 | FAULT_ERROR_CACHE_INIT_1 = 0x00000000,
47 | FAULT_ERROR_CACHE_INIT_2 = 0x00000001,
48 |
49 | FAULT_ERROR_UART_GET_DATA = 0x80000000,
50 | FAULT_ERROR_UART_INIT_1 = 0x80000001,
51 | FAULT_ERROR_UART_INIT_2 = 0x80000002,
52 | FAULT_ERROR_UART_INIT_3 = 0x80000003,
53 |
54 | FAULT_ERROR_CLOCK_INIT_1 = 0x80000100,
55 | FAULT_ERROR_CLOCK_INIT_2 = 0x80000101,
56 | FAULT_ERROR_CLOCK_INIT_3 = 0x80000102,
57 |
58 | FAULT_ERROR_CAN_INIT_1 = 0x80000205,
59 | FAULT_ERROR_CAN_INIT_2 = 0x80000206,
60 | FAULT_ERROR_CAN_INIT_3 = 0x80000206,
61 | FAULT_ERROR_CAN_INVALID_SIZE_1 = 0x80000206,
62 |
63 | }fault_error_t;
64 |
65 | /**
66 | * Reports an error.
67 | *
68 | * @param error The error.
69 | */
70 | void fault_reportError(fault_error_t error);
71 |
72 |
73 | #endif /* __GLOBAL_H */
74 |
--------------------------------------------------------------------------------
/examples/STM32L552/Application/Include/app_ringBuffer.h:
--------------------------------------------------------------------------------
1 | #ifndef RING_BUFFER_H
2 | #define RING_BUFFER_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | #ifdef __cplusplus
9 | extern "C" {
10 | #endif
11 |
12 | /**
13 | * The ring buffer structure.
14 | */
15 | typedef struct
16 | {
17 | unsigned char *buffer;
18 | size_t length;
19 | size_t count;
20 | size_t head;
21 | size_t tail;
22 | size_t maxCount;
23 | } ringBuf_Object, *ringBuf_Handle;
24 |
25 | /**
26 | * Initialize the circular buffer.
27 | *
28 | * @param object Pointer to the ring buffer object.
29 | * @param bufPtr Pointer to data buffer to be used for the circular buffer.
30 | * The buffer is NOT stored in ringBuf_Object.
31 | * @param bufSize The size of bufPtr in number of unsigned chars.
32 | */
33 | void ringBuf_construct(ringBuf_Handle object, unsigned char *bufPtr, size_t bufSize);
34 |
35 | /**
36 | * Clears all the data from the buffer.
37 | *
38 | * @param object Pointer to the ring buffer object.
39 | */
40 | void ringBuf_clear(ringBuf_Handle object);
41 |
42 | /**
43 | * Get the number of unsigned chars currently stored on the circular
44 | * buffer.
45 | *
46 | * @param object Pointer to the ring buffer object.
47 | * @return Number of unsigned chars on the circular buffer.
48 | */
49 | size_t ringBuf_getCount(ringBuf_Handle object);
50 |
51 | /**
52 | * A high-water mark indicating the largest number of unsigned chars
53 | * stored on the circular buffer since it was constructed.
54 | *
55 | * @param object Pointer to the ring buffer object.
56 | * @return Get the largest number of unsigned chars that were at one
57 | * point in the circular buffer.
58 | */
59 | size_t ringBuf_getMaxCount(ringBuf_Handle object);
60 |
61 | /**
62 | * Pointer to a function that disables an ISR during the access on the buffer.
63 | */
64 | typedef void (*ringBuf_disableCommunicationIsr)(void);
65 |
66 | /**
67 | * Pointer to a function that enables the ISR that was disabled in a ring buffer function.
68 | */
69 | typedef void (*ringBuf_enableCommunicationIsr)(void);
70 |
71 | /**
72 | * Get one or more unsigned chars from the end of the circular buffer and
73 | * remove them.
74 | *
75 | * @param object Pointer to the ring buffer object.
76 | * @param data Pointer to an unsigned char to be filled with the data from
77 | * the front of the circular buffer.
78 | * @param n The number of unsigned chars to try and remove.
79 | * @param disableIsr Pointer to a function that disables an ISR during the access on the buffer. Can be NULL.
80 | * @param denableIsr Pointer to a function that enables the ISR that is disabled with disableIsr. Can be NULL.
81 | * @return Number of unsigned chars successfully removed from the buffer
82 | * and copied into data. May be 0 or less than n.
83 | */
84 | size_t ringBuf_getData(ringBuf_Handle object, unsigned char *data, size_t n, ringBuf_disableCommunicationIsr disableIsr,
85 | ringBuf_enableCommunicationIsr enableIs);
86 |
87 | /**
88 | * Function to determine if the circular buffer is full or not.
89 | *
90 | * @param object Pointer to the ring buffer object.
91 | * @return True if circular buffer is full, else FALSE.
92 | */
93 | bool ringBuf_isFull(ringBuf_Handle object);
94 |
95 | /*
96 | * Put one or more unsigned chars into the end of the circular buffer.
97 | *
98 | * @param object The ring buffer object.
99 | * @param data The unsigned chars to be placed at the end of the circular
100 | * buffer.
101 | * @param n The number of unsigned chars to try and remove.
102 | * @param disableIsr Pointer to a function that disables an ISR during the access on the buffer. Can be NULL.
103 | * @param denableIsr Pointer to a function that enables the ISR that is disabled with disableIsr. Can be NULL.
104 | * @return Number of unsigned chars placed into the buffer. May be 0 or
105 | * less than n.
106 | */
107 | size_t ringBuf_putData(ringBuf_Handle object, unsigned char *data, size_t nr, ringBuf_disableCommunicationIsr disableIsr,
108 | ringBuf_enableCommunicationIsr enableIs);
109 |
110 | /**
111 | * Return the number of unsigned characters that the buffer has space for.
112 | * This function should normally be called from a context where HWI is
113 | * disabled. For efficiency, it is incumbent on the caller to ensure mutual
114 | * exclusion with the proper HWI lock.
115 | *
116 | * @param object Pointer to the ring buffer object.
117 | * @return Number of unsigned chars that the buffer has space for.
118 | */
119 | static inline size_t ringBuf_space(ringBuf_Handle object)
120 | {
121 | return (object->length - object->count);
122 | }
123 |
124 | #ifdef __cplusplus
125 | }
126 | #endif
127 |
128 | #endif /* RING_BUFFER_H */
129 |
--------------------------------------------------------------------------------
/examples/STM32L552/Application/Main/app_main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "drv_uartApi.h"
3 | #include "drv_canApi.h"
4 | #include "drv_clockApi.h"
5 | #include "drv_cacheApi.h"
6 | #include "app_global.h"
7 |
8 | #include "stm32l5xx_hal.h"
9 | #include "string.h"
10 |
11 | #define lua_c
12 |
13 | #include "lprefix.h"
14 |
15 | #include "lua.h"
16 | #include "lauxlib.h"
17 | #include "lualib.h"
18 |
19 | #include "helper/luaHelper.h"
20 |
21 | #include "script1.h"
22 | #include "script2.h"
23 | #include "helperScript.h"
24 | #include "printFreeHeap.h"
25 |
26 | extern uint32_t cmdIf_getTimeDiffFromNow(uint32_t startTime);
27 |
28 | int main(void)
29 | {
30 |
31 | char* mesg;
32 | HAL_Init();
33 |
34 | drv_clockInit();
35 | drv_cacheInit();
36 | drv_uartInit();
37 |
38 | mesg = "Start\n";
39 | lua_writestring(mesg, strlen(mesg));
40 |
41 | //Create the lua state.
42 | lua_State *L = luaL_newstate();
43 | if (L == NULL)
44 | {
45 | mesg = "cannot create state: not enough memory";
46 | lua_writestring(mesg, strlen(mesg));
47 | while (1);
48 | }
49 | else
50 | {
51 | //Open the standard libraries.
52 | luaL_openlibs(L);
53 |
54 | //Load the helper script.
55 | if (dostring(L, helperScript, "helperScript") != LUA_OK)
56 | {
57 | while (1);
58 | }
59 |
60 | while (1)
61 | {
62 | //Execute script 1.
63 | if (dostring(L, script1, "script1") != LUA_OK)
64 | {
65 | while (1);
66 | }
67 |
68 | //Collect garbage.
69 | lua_gc(L, LUA_GCCOLLECT, 0);
70 |
71 | lua_writeline();
72 |
73 | //Execute script 2.
74 | if (dostring(L, script2, "script2") != LUA_OK)
75 | {
76 | while (1);
77 | }
78 |
79 | lua_writeline();
80 | printMinimumFreeHeap();
81 |
82 | mesg = "\n****************************************************************************\n";
83 | lua_writestring(mesg, strlen(mesg));
84 |
85 | }//while (1)
86 | }
87 |
88 | }
89 |
90 | /*************************************************************************/
91 |
92 | void fault_reportError(fault_error_t error)
93 | {
94 | char buffer[16];
95 | lua_writestringerror("\n\nfatal error: ", sizeof("\n\nfatal error: ") - 1);
96 | snprintf(buffer, 16, "%x", error);
97 | lua_writestringerror(buffer, strlen(buffer))
98 | lua_writestringerror("\n\n", sizeof("\n\n") - 1);
99 | }
100 |
101 |
--------------------------------------------------------------------------------
/examples/STM32L552/Application/RingBuffer/app_ringBuffer.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /*************************************************************************/
4 |
5 | void ringBuf_construct(ringBuf_Handle object, unsigned char *bufPtr, size_t bufSize)
6 | {
7 | object->buffer = bufPtr;
8 | object->length = bufSize;
9 | object->count = 0;
10 | object->head = bufSize - 1;
11 | object->tail = 0;
12 | object->maxCount = 0;
13 | }
14 |
15 | /*************************************************************************/
16 |
17 | size_t ringBuf_getCount(ringBuf_Handle object)
18 | {
19 | return object->count;
20 | }
21 |
22 | /*************************************************************************/
23 |
24 | size_t ringBuf_getMaxCount(ringBuf_Handle object)
25 | {
26 | return object->maxCount;
27 | }
28 |
29 | /*************************************************************************/
30 |
31 | size_t ringBuf_getData(ringBuf_Handle object, unsigned char *data, size_t n, ringBuf_disableCommunicationIsr disableIsr,
32 | ringBuf_enableCommunicationIsr enableIsr)
33 | {
34 | size_t removed = 0;
35 |
36 | if (disableIsr)
37 | {
38 | disableIsr();
39 | }
40 |
41 | if (n > object->count)
42 | {
43 | n = object->count;
44 | }
45 | while (n)
46 | {
47 | if (disableIsr)
48 | {
49 | disableIsr();
50 | }
51 | *data++ = object->buffer[object->tail++];
52 | object->tail %= object->length;
53 | object->count--;
54 |
55 | if (enableIsr)
56 | {
57 | enableIsr();
58 | }
59 |
60 | n--;
61 | removed++;
62 | }
63 |
64 | if (enableIsr)
65 | {
66 | enableIsr();
67 | }
68 |
69 | return removed;
70 | }
71 |
72 | /*************************************************************************/
73 |
74 | void ringBuf_clear(ringBuf_Handle object)
75 | {
76 | size_t maxCount;
77 |
78 | maxCount = object->maxCount;
79 | ringBuf_construct(object, object->buffer, object->length);
80 | object->maxCount = maxCount;
81 | }
82 |
83 | /*************************************************************************/
84 |
85 | bool ringBuf_isFull(ringBuf_Handle object)
86 | {
87 | return (object->count == object->length);
88 | }
89 |
90 | /*************************************************************************/
91 |
92 | size_t ringBuf_putData(ringBuf_Handle object, unsigned char *data, size_t n, ringBuf_disableCommunicationIsr disableIsr,
93 | ringBuf_enableCommunicationIsr enableIsr)
94 | {
95 | size_t next;
96 | size_t added = 0;
97 |
98 | if (disableIsr)
99 | {
100 | disableIsr();
101 | }
102 |
103 | if (n > ringBuf_space(object))
104 | {
105 | n = ringBuf_space(object);
106 | }
107 | while (n != 0)
108 | {
109 | if (disableIsr)
110 | {
111 | disableIsr();
112 | }
113 |
114 | next = (object->head + 1) % object->length;
115 | object->buffer[next] = *data++;
116 | object->head = next;
117 | object->count++;
118 |
119 | if (enableIsr)
120 | {
121 | enableIsr();
122 | }
123 |
124 | n--;
125 | added++;
126 | }
127 | if (object->maxCount < object->count)
128 | {
129 | object->maxCount = object->count;
130 | }
131 |
132 | if (enableIsr)
133 | {
134 | enableIsr();
135 | }
136 |
137 | return added;
138 | }
139 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/CMSIS/Device/ST/STM32L5xx/Include/stm32l5xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szieke/embLua/000a7dea186d0e5653b7636442ee896dde3273a1/examples/STM32L552/Drivers/CMSIS/Device/ST/STM32L5xx/Include/stm32l5xx.h
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/CMSIS/Device/ST/STM32L5xx/Include/system_stm32l5xx.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file system_stm32l5xx.h
4 | * @author MCD Application Team
5 | * @brief CMSIS Cortex-M33 Device System Source File for STM32L5xx devices.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2019 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under Apache License, Version 2.0,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/Apache-2.0
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /** @addtogroup CMSIS
21 | * @{
22 | */
23 |
24 | /** @addtogroup STM32L5xx_system
25 | * @{
26 | */
27 |
28 | #ifndef SYSTEM_STM32L5XX_H
29 | #define SYSTEM_STM32L5XX_H
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | /** @addtogroup STM32L5xx_System_Includes
36 | * @{
37 | */
38 | #include
39 | /**
40 | * @}
41 | */
42 |
43 | /** @addtogroup STM32L5xx_System_Exported_Variables
44 | * @{
45 | */
46 | /* The SystemCoreClock variable is updated in three ways:
47 | 1) by calling CMSIS function SystemCoreClockUpdate()
48 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq()
49 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
50 | Note: If you use this function to configure the system clock; then there
51 | is no need to call the 2 first functions listed above, since SystemCoreClock
52 | variable is updated automatically.
53 | */
54 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
55 |
56 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */
57 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */
58 | extern const uint32_t MSIRangeTable[16]; /*!< MSI ranges table values */
59 |
60 | /**
61 | * @}
62 | */
63 |
64 | /** @addtogroup STM32L5xx_System_Exported_Functions
65 | * @{
66 | */
67 |
68 | /**
69 | \brief Setup the microcontroller system.
70 |
71 | Initialize the System and update the SystemCoreClock variable.
72 | */
73 | extern void SystemInit (void);
74 |
75 |
76 | /**
77 | \brief Update SystemCoreClock variable.
78 |
79 | Updates the SystemCoreClock with current core Clock retrieved from cpu registers.
80 | */
81 | extern void SystemCoreClockUpdate (void);
82 |
83 |
84 | /**
85 | \brief Update SystemCoreClock variable from secure application and return its value
86 | when security is implemented in the system (Non-secure callable function).
87 |
88 | Returns the SystemCoreClock value with current core Clock retrieved from cpu registers.
89 | */
90 | extern uint32_t SECURE_SystemCoreClockUpdate(void);
91 |
92 | /**
93 | * @}
94 | */
95 |
96 | #ifdef __cplusplus
97 | }
98 | #endif
99 |
100 | #endif /* SYSTEM_STM32L5XX_H */
101 |
102 | /**
103 | * @}
104 | */
105 |
106 | /**
107 | * @}
108 | */
109 |
110 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
111 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/CMSIS/Include/cmsis_version.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************//**
2 | * @file cmsis_version.h
3 | * @brief CMSIS Core(M) Version definitions
4 | * @version V5.0.3
5 | * @date 24. June 2019
6 | ******************************************************************************/
7 | /*
8 | * Copyright (c) 2009-2019 ARM Limited. All rights reserved.
9 | *
10 | * SPDX-License-Identifier: Apache-2.0
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the License); you may
13 | * not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | #if defined ( __ICCARM__ )
26 | #pragma system_include /* treat file as system include file for MISRA check */
27 | #elif defined (__clang__)
28 | #pragma clang system_header /* treat file as system include file */
29 | #endif
30 |
31 | #ifndef __CMSIS_VERSION_H
32 | #define __CMSIS_VERSION_H
33 |
34 | /* CMSIS Version definitions */
35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */
36 | #define __CM_CMSIS_VERSION_SUB ( 3U) /*!< [15:0] CMSIS Core(M) sub version */
37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \
38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */
39 | #endif
40 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/CMSIS/Include/tz_context.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @file tz_context.h
3 | * @brief Context Management for Armv8-M TrustZone
4 | * @version V1.0.1
5 | * @date 10. January 2018
6 | ******************************************************************************/
7 | /*
8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved.
9 | *
10 | * SPDX-License-Identifier: Apache-2.0
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the License); you may
13 | * not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | #if defined ( __ICCARM__ )
26 | #pragma system_include /* treat file as system include file for MISRA check */
27 | #elif defined (__clang__)
28 | #pragma clang system_header /* treat file as system include file */
29 | #endif
30 |
31 | #ifndef TZ_CONTEXT_H
32 | #define TZ_CONTEXT_H
33 |
34 | #include
35 |
36 | #ifndef TZ_MODULEID_T
37 | #define TZ_MODULEID_T
38 | /// \details Data type that identifies secure software modules called by a process.
39 | typedef uint32_t TZ_ModuleId_t;
40 | #endif
41 |
42 | /// \details TZ Memory ID identifies an allocated memory slot.
43 | typedef uint32_t TZ_MemoryId_t;
44 |
45 | /// Initialize secure context memory system
46 | /// \return execution status (1: success, 0: error)
47 | uint32_t TZ_InitContextSystem_S (void);
48 |
49 | /// Allocate context memory for calling secure software modules in TrustZone
50 | /// \param[in] module identifies software modules called from non-secure mode
51 | /// \return value != 0 id TrustZone memory slot identifier
52 | /// \return value 0 no memory available or internal error
53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module);
54 |
55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S
56 | /// \param[in] id TrustZone memory slot identifier
57 | /// \return execution status (1: success, 0: error)
58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id);
59 |
60 | /// Load secure context (called on RTOS thread context switch)
61 | /// \param[in] id TrustZone memory slot identifier
62 | /// \return execution status (1: success, 0: error)
63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id);
64 |
65 | /// Store secure context (called on RTOS thread context switch)
66 | /// \param[in] id TrustZone memory slot identifier
67 | /// \return execution status (1: success, 0: error)
68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id);
69 |
70 | #endif // TZ_CONTEXT_H
71 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/Include/drv_cacheApi.h:
--------------------------------------------------------------------------------
1 | /*!
2 | * \file drv_cacheApi.h
3 | * \brief Contains the API declarations of the cache driver.
4 | * \author Stefan Zieker
5 | */
6 |
7 | #ifndef INCLUDE_DRV_CACHEAPI_H_
8 | #define INCLUDE_DRV_CACHEAPI_H_
9 |
10 | /**
11 | * Initializes the cache.
12 | */
13 | void drv_cacheInit(void);
14 |
15 |
16 | #endif /* INCLUDE_DRV_CACHEAPI_H_ */
17 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/Include/drv_canApi.h:
--------------------------------------------------------------------------------
1 | /*!
2 | * \file drv_canApi.h
3 | * \brief Contains the API declarations of the CAN driver.
4 | * \author Stefan Zieker
5 | */
6 |
7 | #ifndef INCLUDE_DRV_CANAPI_H_
8 | #define INCLUDE_DRV_CANAPI_H_
9 |
10 | #include "app_global.h"
11 |
12 | /**
13 | * Initializes the CAN module.
14 | */
15 | void drv_canInit(void);
16 |
17 | /**
18 | * Receives a CAN message (from the receive fifos).
19 | *
20 | * @param canId The CAN ID of the message.
21 | * @param buffer [out] The buffer for the data of the message.
22 | * @param numberOfReceivedBytes [out] The number of received bytes.
23 | * @param timeout The timeout for receiving a message (ms).
24 | * @param traceReceivedData TRUE if the received data shall be traced.
25 | */
26 | bool_t drv_canReceiveMessage(uint32_t* canId, uint8_t *buffer, uint32_t* numberOfReceivedBytes, uint32_t timeout, bool_t traceReceivedData);
27 |
28 | /**
29 | * Sends a CAN message.
30 | *
31 | * @param canId The CAN ID of the message.
32 | * @param data The data of the CAN message.
33 | * @param length The data length.
34 | * @param flushRxQueue TRUE if all received CAN messages shall be flushed before the message is sent.
35 | */
36 | bool_t drv_canSendMessage(uint32_t canId, uint8_t *data, uint32_t length, bool_t flushRxQueue);
37 |
38 | /**
39 | * Flushes all received CAN message.
40 | */
41 | void drv_canFlushRx();
42 |
43 | #endif /* INCLUDE_DRV_CANAPI_H_ */
44 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/Include/drv_clockApi.h:
--------------------------------------------------------------------------------
1 | /*!
2 | * \file drv_clockApi.h
3 | * \brief Contains the API declarations of the clock driver.
4 | * \author Stefan Zieker
5 | */
6 |
7 | #ifndef INCLUDE_DRV_CLOCKAPI_H_
8 | #define INCLUDE_DRV_CLOCKAPI_H_
9 |
10 | /**
11 | * Initializes the clocks
12 | */
13 | void drv_clockInit(void);
14 |
15 | #endif /* INCLUDE_DRV_CLOCKAPI_H_ */
16 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/Include/drv_uartApi.h:
--------------------------------------------------------------------------------
1 | /*!
2 | * \file drv_uartApi.h
3 | * \brief Contains the API declarations of the UART driver.
4 | * \author Stefan Zieker
5 | */
6 |
7 | #ifndef INCLUDE_DRV_UARTAPI_H_
8 | #define INCLUDE_DRV_UARTAPI_H_
9 |
10 | #include
11 |
12 | /**
13 | * Initializes the UART.
14 | */
15 | void drv_uartInit(void);
16 |
17 | /**
18 | * Sends data with the UART.
19 | *
20 | * @param buffer The data buffer.
21 | * @param size The size of the data buffer.
22 | */
23 | uint32_t drv_uartSendData(uint8_t *buffer, uint32_t size);
24 |
25 | /**
26 | * Reads received data.
27 | *
28 | * @param buffer [out] The data buffer.
29 | * @param size The size of the data buffer.
30 | */
31 | uint32_t drv_uartGetData(uint8_t *buffer, uint32_t size);
32 |
33 | #endif /* INCLUDE_DRV_UARTAPI_H_ */
34 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/Include/stm32l5xx_it.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file stm32l5xx_it.h
5 | * @brief This file contains the headers of the interrupt handlers.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * Copyright (c) 2023 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software is licensed under terms that can be found in the LICENSE file
13 | * in the root directory of this software component.
14 | * If no LICENSE file comes with this software, it is provided AS-IS.
15 | *
16 | ******************************************************************************
17 | */
18 | /* USER CODE END Header */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef __STM32L5xx_IT_H
22 | #define __STM32L5xx_IT_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Private includes ----------------------------------------------------------*/
29 | /* USER CODE BEGIN Includes */
30 |
31 | /* USER CODE END Includes */
32 |
33 | /* Exported types ------------------------------------------------------------*/
34 | /* USER CODE BEGIN ET */
35 |
36 | /* USER CODE END ET */
37 |
38 | /* Exported constants --------------------------------------------------------*/
39 | /* USER CODE BEGIN EC */
40 |
41 | /* USER CODE END EC */
42 |
43 | /* Exported macro ------------------------------------------------------------*/
44 | /* USER CODE BEGIN EM */
45 |
46 | /* USER CODE END EM */
47 |
48 | /* Exported functions prototypes ---------------------------------------------*/
49 | void NMI_Handler(void);
50 | void HardFault_Handler(void);
51 | void MemManage_Handler(void);
52 | void BusFault_Handler(void);
53 | void UsageFault_Handler(void);
54 | void SVC_Handler(void);
55 | void DebugMon_Handler(void);
56 | void PendSV_Handler(void);
57 | void SysTick_Handler(void);
58 | /* USER CODE BEGIN EFP */
59 |
60 | /* USER CODE END EFP */
61 |
62 | #ifdef __cplusplus
63 | }
64 | #endif
65 |
66 | #endif /* __STM32L5xx_IT_H */
67 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/STM32L5xx_HAL_Driver/Inc/stm32l5xx_hal_flash_ramfunc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32l5xx_hal_flash_ramfunc.h
4 | * @author MCD Application Team
5 | * @brief Header file of FLASH RAMFUNC driver.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2019 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /* Define to prevent recursive inclusion -------------------------------------*/
21 | #ifndef STM32L5xx_HAL_FLASH_RAMFUNC_H
22 | #define STM32L5xx_HAL_FLASH_RAMFUNC_H
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "stm32l5xx_hal_def.h"
30 |
31 | /** @addtogroup STM32L5xx_HAL_Driver
32 | * @{
33 | */
34 |
35 | /** @addtogroup FLASH_RAMFUNC
36 | * @{
37 | */
38 |
39 | /* Exported types ------------------------------------------------------------*/
40 | /* Exported macro ------------------------------------------------------------*/
41 | /* Exported functions --------------------------------------------------------*/
42 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions
43 | * @{
44 | */
45 |
46 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1
47 | * @{
48 | */
49 | /* Peripheral Control functions ************************************************/
50 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableRunPowerDown(void);
51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableRunPowerDown(void);
52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig);
53 | /**
54 | * @}
55 | */
56 |
57 | /**
58 | * @}
59 | */
60 |
61 | /**
62 | * @}
63 | */
64 |
65 | /**
66 | * @}
67 | */
68 |
69 | #ifdef __cplusplus
70 | }
71 | #endif
72 |
73 | #endif /* STM32L5xx_HAL_FLASH_RAMFUNC_H */
74 |
75 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
76 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/STM32L5xx_HAL_Driver/License.md:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2019 STMicroelectronics
2 |
3 | This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this software except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause).
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/STM32L5xx_HAL_Driver/Src/stm32l5xx_ll_ucpd.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32l5xx_ll_ucpd.c
4 | * @author MCD Application Team
5 | * @brief UCPD LL module driver.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2019 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 | #if defined(USE_FULL_LL_DRIVER)
20 |
21 | /* Includes ------------------------------------------------------------------*/
22 | #include "stm32l5xx_ll_ucpd.h"
23 | #include "stm32l5xx_ll_bus.h"
24 | #include "stm32l5xx_ll_rcc.h"
25 |
26 | #ifdef USE_FULL_ASSERT
27 | #include "stm32_assert.h"
28 | #else
29 | #define assert_param(expr) ((void)0U)
30 | #endif
31 |
32 | /** @addtogroup STM32L5xx_LL_Driver
33 | * @{
34 | */
35 | #if defined (UCPD1)
36 | /** @addtogroup UCPD_LL
37 | * @{
38 | */
39 |
40 | /* Private types -------------------------------------------------------------*/
41 | /* Private variables ---------------------------------------------------------*/
42 |
43 | /* Private constants ---------------------------------------------------------*/
44 | /** @defgroup UCPD_LL_Private_Constants UCPD Private Constants
45 | * @{
46 | */
47 |
48 | /**
49 | * @}
50 | */
51 |
52 | /* Private macros ------------------------------------------------------------*/
53 | /** @defgroup UCPD_LL_Private_Macros UCPD Private Macros
54 | * @{
55 | */
56 |
57 |
58 | /**
59 | * @}
60 | */
61 |
62 | /* Private function prototypes -----------------------------------------------*/
63 |
64 | /* Exported functions --------------------------------------------------------*/
65 | /** @addtogroup UCPD_LL_Exported_Functions
66 | * @{
67 | */
68 |
69 | /** @addtogroup UCPD_LL_EF_Init
70 | * @{
71 | */
72 |
73 | /**
74 | * @brief De-initialize the UCPD registers to their default reset values.
75 | * @param UCPDx ucpd Instance
76 | * @retval An ErrorStatus enumeration value:
77 | * - SUCCESS: ucpd registers are de-initialized
78 | * - ERROR: ucpd registers are not de-initialized
79 | */
80 | ErrorStatus LL_UCPD_DeInit(UCPD_TypeDef *UCPDx)
81 | {
82 | ErrorStatus status = ERROR;
83 |
84 | /* Check the parameters */
85 | assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
86 |
87 | LL_UCPD_Disable(UCPDx);
88 |
89 | if (UCPD1 == UCPDx)
90 | {
91 | /* Force reset of ucpd clock */
92 | LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_UCPD1);
93 |
94 | /* Release reset of ucpd clock */
95 | LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_UCPD1);
96 |
97 | /* Disable ucpd clock */
98 | LL_APB1_GRP2_DisableClock(LL_APB1_GRP2_PERIPH_UCPD1);
99 |
100 | status = SUCCESS;
101 | }
102 |
103 | return status;
104 | }
105 |
106 | /**
107 | * @brief Initialize the ucpd registers according to the specified parameters in UCPD_InitStruct.
108 | * @note As some bits in ucpd configuration registers can only be written when the ucpd is disabled (ucpd_CR1_SPE bit =0),
109 | * UCPD peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
110 | * @param UCPDx UCPD Instance
111 | * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure that contains
112 | * the configuration information for the UCPD peripheral.
113 | * @retval An ErrorStatus enumeration value. (Return always SUCCESS)
114 | */
115 | ErrorStatus LL_UCPD_Init(UCPD_TypeDef *UCPDx, LL_UCPD_InitTypeDef *UCPD_InitStruct)
116 | {
117 | /* Check the ucpd Instance UCPDx*/
118 | assert_param(IS_UCPD_ALL_INSTANCE(UCPDx));
119 |
120 | if(UCPD1 == UCPDx)
121 | {
122 | LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_UCPD1);
123 | }
124 |
125 |
126 | LL_UCPD_Disable(UCPDx);
127 |
128 | /*---------------------------- UCPDx CFG1 Configuration ------------------------*/
129 | MODIFY_REG(UCPDx->CFG1,
130 | UCPD_CFG1_PSC_UCPDCLK | UCPD_CFG1_TRANSWIN | UCPD_CFG1_IFRGAP | UCPD_CFG1_HBITCLKDIV,
131 | UCPD_InitStruct->psc_ucpdclk | (UCPD_InitStruct->transwin << UCPD_CFG1_TRANSWIN_Pos) |
132 | (UCPD_InitStruct->IfrGap << UCPD_CFG1_IFRGAP_Pos) | UCPD_InitStruct->HbitClockDiv);
133 |
134 | return SUCCESS;
135 | }
136 |
137 | /**
138 | * @brief Set each @ref LL_UCPD_InitTypeDef field to default value.
139 | * @param UCPD_InitStruct pointer to a @ref LL_UCPD_InitTypeDef structure
140 | * whose fields will be set to default values.
141 | * @retval None
142 | */
143 | void LL_UCPD_StructInit(LL_UCPD_InitTypeDef *UCPD_InitStruct)
144 | {
145 | /* Set UCPD_InitStruct fields to default values */
146 | UCPD_InitStruct->psc_ucpdclk = LL_UCPD_PSC_DIV2;
147 | UCPD_InitStruct->transwin = 0x7; /* Divide by 8 */
148 | UCPD_InitStruct->IfrGap = 0x10; /* Divide by 17 */
149 | UCPD_InitStruct->HbitClockDiv = 0x0D; /* Divide by 14 to produce HBITCLK */
150 | }
151 |
152 | /**
153 | * @}
154 | */
155 |
156 | /**
157 | * @}
158 | */
159 |
160 | /**
161 | * @}
162 | */
163 | #endif /* defined (UCPD1) */
164 | /**
165 | * @}
166 | */
167 |
168 | #endif /* USE_FULL_LL_DRIVER */
169 |
170 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
171 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/drv_cache.c:
--------------------------------------------------------------------------------
1 | /*!
2 | * \file drv_cacheApi.c
3 | * \brief Contains the cache driver.
4 | * \author Stefan Zieker
5 | */
6 |
7 | #include
8 |
9 | #include "stm32l5xx_hal.h"
10 |
11 | /****************************************************************************************/
12 |
13 | void drv_cacheInit(void)
14 | {
15 | if (HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY) != HAL_OK)
16 | {
17 | fault_reportError(FAULT_ERROR_CACHE_INIT_1);
18 | }
19 | if (HAL_ICACHE_Enable() != HAL_OK)
20 | {
21 | fault_reportError(FAULT_ERROR_CACHE_INIT_2);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/STM32L552/Drivers/drv_clock.c:
--------------------------------------------------------------------------------
1 | /*!
2 | * \file drv_clockApi.c
3 | * \brief Contains the clock driver.
4 | * \author Stefan Zieker
5 | */
6 |
7 | #include "stm32l5xx_hal.h"
8 | #include "app_global.h"
9 |
10 | /*************************************************************************/
11 |
12 | void drv_clockInit(void)
13 | {
14 | RCC_OscInitTypeDef RCC_OscInitStruct = {0};
15 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
16 |
17 | __HAL_RCC_SYSCFG_CLK_ENABLE();
18 | __HAL_RCC_PWR_CLK_ENABLE();
19 |
20 | /** Configure the main internal regulator output voltage
21 | */
22 | if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE0) != HAL_OK)
23 | {
24 | fault_reportError(FAULT_ERROR_CLOCK_INIT_1);
25 | }
26 |
27 | /** Configure LSE Drive Capability
28 | */
29 | HAL_PWR_EnableBkUpAccess();
30 | __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
31 |
32 | /** Initializes the RCC Oscillators according to the specified parameters
33 | * in the RCC_OscInitTypeDef structure.
34 | */
35 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
36 | RCC_OscInitStruct.LSEState = RCC_LSE_ON;
37 | RCC_OscInitStruct.MSIState = RCC_MSI_ON;
38 | RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
39 | RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
40 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
41 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
42 | RCC_OscInitStruct.PLL.PLLM = 1;
43 | RCC_OscInitStruct.PLL.PLLN = 55;
44 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
45 | RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
46 | RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
47 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
48 | {
49 | fault_reportError(FAULT_ERROR_CLOCK_INIT_2);
50 | }
51 |
52 | /** Initializes the CPU, AHB and APB buses clocks
53 | */
54 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
55 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
56 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
57 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
58 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
59 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
60 |
61 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
62 | {
63 | fault_reportError(FAULT_ERROR_CLOCK_INIT_3);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/examples/STM32L552/STM32L552ZETXQ_FLASH.ld:
--------------------------------------------------------------------------------
1 | /*
2 | ******************************************************************************
3 | **
4 | ** File : LinkerScript.ld
5 | **
6 | ** Author : STM32CubeIDE
7 | **
8 | ** Abstract : Linker script for STM32L552xE Device from STM32L5 series
9 | ** 512Kbytes FLASH
10 | ** 256Kbytes RAM
11 | **
12 | ** Set heap size, stack size and stack location according
13 | ** to application requirements.
14 | **
15 | ** Set memory bank area and size if external memory is used.
16 | **
17 | ** Target : STMicroelectronics STM32
18 | **
19 | ** Distribution: The file is distributed as is without any warranty
20 | ** of any kind.
21 | **
22 | *****************************************************************************
23 | ** @attention
24 | **
25 | ** Copyright (c) 2023 STMicroelectronics.
26 | ** All rights reserved.
27 | **
28 | ** This software is licensed under terms that can be found in the LICENSE file
29 | ** in the root directory of this software component.
30 | ** If no LICENSE file comes with this software, it is provided AS-IS.
31 | **
32 | *****************************************************************************
33 | */
34 |
35 | /* Entry Point */
36 | ENTRY(Reset_Handler)
37 |
38 | /* Highest address of the user mode stack */
39 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
40 |
41 | _Min_Heap_Size = 0; /* required amount of heap */
42 | _Min_Stack_Size = 0x400; /* required amount of stack */
43 |
44 | /* Memories definition */
45 | MEMORY
46 | {
47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
48 | RAM2 (xrw) : ORIGIN = 0x20030000, LENGTH = 64K
49 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
50 | }
51 |
52 | /* Sections */
53 | SECTIONS
54 | {
55 | /* The startup code into "FLASH" Rom type memory */
56 | .isr_vector :
57 | {
58 | . = ALIGN(4);
59 | KEEP(*(.isr_vector)) /* Startup code */
60 | . = ALIGN(4);
61 | } >FLASH
62 |
63 | /* The program code and other data into "FLASH" Rom type memory */
64 | .text :
65 | {
66 | . = ALIGN(4);
67 | *(.text) /* .text sections (code) */
68 | *(.text*) /* .text* sections (code) */
69 | *(.glue_7) /* glue arm to thumb code */
70 | *(.glue_7t) /* glue thumb to arm code */
71 | *(.eh_frame)
72 |
73 | KEEP (*(.init))
74 | KEEP (*(.fini))
75 |
76 | . = ALIGN(4);
77 | _etext = .; /* define a global symbols at end of code */
78 | } >FLASH
79 |
80 | /* Constant data into "FLASH" Rom type memory */
81 | .rodata :
82 | {
83 | . = ALIGN(4);
84 | *(.rodata) /* .rodata sections (constants, strings, etc.) */
85 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
86 | . = ALIGN(4);
87 | } >FLASH
88 |
89 | .ARM.extab : {
90 | . = ALIGN(4);
91 | *(.ARM.extab* .gnu.linkonce.armextab.*)
92 | . = ALIGN(4);
93 | } >FLASH
94 |
95 | .ARM : {
96 | . = ALIGN(4);
97 | __exidx_start = .;
98 | *(.ARM.exidx*)
99 | __exidx_end = .;
100 | . = ALIGN(4);
101 | } >FLASH
102 |
103 | .preinit_array :
104 | {
105 | . = ALIGN(4);
106 | PROVIDE_HIDDEN (__preinit_array_start = .);
107 | KEEP (*(.preinit_array*))
108 | PROVIDE_HIDDEN (__preinit_array_end = .);
109 | . = ALIGN(4);
110 | } >FLASH
111 |
112 | .init_array :
113 | {
114 | . = ALIGN(4);
115 | PROVIDE_HIDDEN (__init_array_start = .);
116 | KEEP (*(SORT(.init_array.*)))
117 | KEEP (*(.init_array*))
118 | PROVIDE_HIDDEN (__init_array_end = .);
119 | . = ALIGN(4);
120 | } >FLASH
121 |
122 | .fini_array :
123 | {
124 | . = ALIGN(4);
125 | PROVIDE_HIDDEN (__fini_array_start = .);
126 | KEEP (*(SORT(.fini_array.*)))
127 | KEEP (*(.fini_array*))
128 | PROVIDE_HIDDEN (__fini_array_end = .);
129 | . = ALIGN(4);
130 | } >FLASH
131 |
132 | /* Used by the startup to initialize data */
133 | _sidata = LOADADDR(.data);
134 |
135 | /* Initialized data sections into "RAM" Ram type memory */
136 | .data :
137 | {
138 | . = ALIGN(4);
139 | _sdata = .; /* create a global symbol at data start */
140 | *(.data) /* .data sections */
141 | *(.data*) /* .data* sections */
142 | *(.RamFunc) /* .RamFunc sections */
143 | *(.RamFunc*) /* .RamFunc* sections */
144 |
145 | . = ALIGN(4);
146 | _edata = .; /* define a global symbol at data end */
147 |
148 | } >RAM AT> FLASH
149 |
150 | /* Uninitialized data section into "RAM" Ram type memory */
151 | . = ALIGN(4);
152 | .bss :
153 | {
154 | /* This is used by the startup in order to initialize the .bss section */
155 | _sbss = .; /* define a global symbol at bss start */
156 | __bss_start__ = _sbss;
157 | *(.bss)
158 | *(.bss*)
159 | *(COMMON)
160 |
161 | . = ALIGN(4);
162 | _ebss = .; /* define a global symbol at bss end */
163 | __bss_end__ = _ebss;
164 | } >RAM
165 |
166 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
167 | ._user_heap_stack :
168 | {
169 | . = ALIGN(8);
170 | PROVIDE ( end = . );
171 | PROVIDE ( _end = . );
172 | . = . + _Min_Heap_Size;
173 | . = . + _Min_Stack_Size;
174 | . = ALIGN(8);
175 | } >RAM
176 |
177 | /* Remove information from the compiler libraries */
178 | /DISCARD/ :
179 | {
180 | libc.a ( * )
181 | libm.a ( * )
182 | libgcc.a ( * )
183 | }
184 |
185 | .ARM.attributes 0 : { *(.ARM.attributes) }
186 | }
187 |
--------------------------------------------------------------------------------
/examples/STM32L552/STM32L552ZETXQ_RAM.ld:
--------------------------------------------------------------------------------
1 | /*
2 | ******************************************************************************
3 | **
4 | ** File : LinkerScript.ld (debug in RAM dedicated)
5 | **
6 | ** Author : STM32CubeIDE
7 | **
8 | ** Abstract : Linker script for STM32L5x2xx Device from STM32L5 series
9 | ** 256Kbytes RAM
10 | **
11 | ** Set heap size, stack size and stack location according
12 | ** to application requirements.
13 | **
14 | ** Set memory bank area and size if external memory is used.
15 | **
16 | ** Target : STMicroelectronics STM32
17 | **
18 | ** Distribution: The file is distributed as is without any warranty
19 | ** of any kind.
20 | **
21 | *****************************************************************************
22 | ** @attention
23 | **
24 | ** Copyright (c) 2023 STMicroelectronics.
25 | ** All rights reserved.
26 | **
27 | ** This software is licensed under terms that can be found in the LICENSE file
28 | ** in the root directory of this software component.
29 | ** If no LICENSE file comes with this software, it is provided AS-IS.
30 | **
31 | *****************************************************************************
32 | */
33 |
34 | /* Entry Point */
35 | ENTRY(Reset_Handler)
36 |
37 | /* Highest address of the user mode stack */
38 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
39 |
40 | _Min_Heap_Size = 0x200; /* required amount of heap */
41 | _Min_Stack_Size = 0x400; /* required amount of stack */
42 |
43 | /* Memories definition */
44 | MEMORY
45 | {
46 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K
47 | RAM2 (xrw) : ORIGIN = 0x20030000, LENGTH = 64K
48 | }
49 |
50 | /* Sections */
51 | SECTIONS
52 | {
53 | /* The startup code into "RAM" Ram type memory */
54 | .isr_vector :
55 | {
56 | . = ALIGN(4);
57 | KEEP(*(.isr_vector)) /* Startup code */
58 | . = ALIGN(4);
59 | } >RAM
60 |
61 | /* The program code and other data into "RAM" Ram type memory */
62 | .text :
63 | {
64 | . = ALIGN(4);
65 | *(.text) /* .text sections (code) */
66 | *(.text*) /* .text* sections (code) */
67 | *(.glue_7) /* glue arm to thumb code */
68 | *(.glue_7t) /* glue thumb to arm code */
69 | *(.eh_frame)
70 | *(.RamFunc) /* .RamFunc sections */
71 | *(.RamFunc*) /* .RamFunc* sections */
72 |
73 | KEEP (*(.init))
74 | KEEP (*(.fini))
75 |
76 | . = ALIGN(4);
77 | _etext = .; /* define a global symbols at end of code */
78 | } >RAM
79 |
80 | /* Constant data into "RAM" Ram type memory */
81 | .rodata :
82 | {
83 | . = ALIGN(4);
84 | *(.rodata) /* .rodata sections (constants, strings, etc.) */
85 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
86 | . = ALIGN(4);
87 | } >RAM
88 |
89 | .ARM.extab : {
90 | . = ALIGN(4);
91 | *(.ARM.extab* .gnu.linkonce.armextab.*)
92 | . = ALIGN(4);
93 | } >RAM
94 |
95 | .ARM : {
96 | . = ALIGN(4);
97 | __exidx_start = .;
98 | *(.ARM.exidx*)
99 | __exidx_end = .;
100 | . = ALIGN(4);
101 | } >RAM
102 |
103 | .preinit_array :
104 | {
105 | . = ALIGN(4);
106 | PROVIDE_HIDDEN (__preinit_array_start = .);
107 | KEEP (*(.preinit_array*))
108 | PROVIDE_HIDDEN (__preinit_array_end = .);
109 | . = ALIGN(4);
110 | } >RAM
111 |
112 | .init_array :
113 | {
114 | . = ALIGN(4);
115 | PROVIDE_HIDDEN (__init_array_start = .);
116 | KEEP (*(SORT(.init_array.*)))
117 | KEEP (*(.init_array*))
118 | PROVIDE_HIDDEN (__init_array_end = .);
119 | . = ALIGN(4);
120 | } >RAM
121 |
122 | .fini_array :
123 | {
124 | . = ALIGN(4);
125 | PROVIDE_HIDDEN (__fini_array_start = .);
126 | KEEP (*(SORT(.fini_array.*)))
127 | KEEP (*(.fini_array*))
128 | PROVIDE_HIDDEN (__fini_array_end = .);
129 | . = ALIGN(4);
130 | } >RAM
131 |
132 | /* Used by the startup to initialize data */
133 | _sidata = LOADADDR(.data);
134 |
135 | /* Initialized data sections into "RAM" Ram type memory */
136 | .data :
137 | {
138 | . = ALIGN(4);
139 | _sdata = .; /* create a global symbol at data start */
140 | *(.data) /* .data sections */
141 | *(.data*) /* .data* sections */
142 |
143 | . = ALIGN(4);
144 | _edata = .; /* define a global symbol at data end */
145 |
146 | } >RAM
147 |
148 | /* Uninitialized data section into "RAM" Ram type memory */
149 | . = ALIGN(4);
150 | .bss :
151 | {
152 | /* This is used by the startup in order to initialize the .bss section */
153 | _sbss = .; /* define a global symbol at bss start */
154 | __bss_start__ = _sbss;
155 | *(.bss)
156 | *(.bss*)
157 | *(COMMON)
158 |
159 | . = ALIGN(4);
160 | _ebss = .; /* define a global symbol at bss end */
161 | __bss_end__ = _ebss;
162 | } >RAM
163 |
164 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
165 | ._user_heap_stack :
166 | {
167 | . = ALIGN(8);
168 | PROVIDE ( end = . );
169 | PROVIDE ( _end = . );
170 | . = . + _Min_Heap_Size;
171 | . = . + _Min_Stack_Size;
172 | . = ALIGN(8);
173 | } >RAM
174 |
175 | /* Remove information from the compiler libraries */
176 | /DISCARD/ :
177 | {
178 | libc.a ( * )
179 | libm.a ( * )
180 | libgcc.a ( * )
181 | }
182 |
183 | .ARM.attributes 0 : { *(.ARM.attributes) }
184 | }
185 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/Scripts/convertToHeader.bat:
--------------------------------------------------------------------------------
1 | %~dp0\..\..\..\..\..\lua\helper\lua-5.2.4_Win32_bin\lua52.exe %~dp0\..\..\..\..\..\lua\helper\convertToHeader.lua ./
2 |
3 | pause
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/Scripts/helperScript.h:
--------------------------------------------------------------------------------
1 | static const char* helperScript="local helperScriptCounter = 0\n\
2 | function includedScript ()\n\
3 | print(\"print from helperScript: \" .. tostring(helperScriptCounter) .. \"\\n\")\n\
4 | helperScriptCounter = helperScriptCounter+1\n\
5 | end";
6 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/Scripts/helperScript.lua:
--------------------------------------------------------------------------------
1 | local helperScriptCounter = 0
2 | function includedScript ()
3 | print("print from helperScript: " .. tostring(helperScriptCounter) .. "\n")
4 | helperScriptCounter = helperScriptCounter+1
5 | end
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/Scripts/script1.h:
--------------------------------------------------------------------------------
1 | static const char* script1="function script1Function ()\n\
2 | print('\\nscript1: ' .. tostring(uc.counter()) ..'\\n')\n\
3 | includedScript()\n\
4 | local example = 'an example string'\n\
5 | for el in string.gmatch(example, '%S+') do\n\
6 | print(el .. ' ')\n\
7 | end\n\
8 | print('\\n')\n\
9 | local result1, result2 = uc.func1('Testmessage')\n\
10 | print('result1: '.. tostring(result1) .. ' result2: '.. tostring(result2) .. '\\n')\n\
11 | local array = {0,1,2,3,4}\n\
12 | local resultTable = uc.func2(array)\n\
13 | print('test print:', 'string', 3, '\\n')\n\
14 | print('resultTable1: '.. tostring(resultTable[0]) .. ' resultTable2: '.. tostring(resultTable[1]) .. '\\n')\n\
15 | print('heap usage before collect: ' .. tostring(collectgarbage('count')*1024) .. '\\n')\n\
16 | collectgarbage('collect')\n\
17 | print('heap usage after collect: ' .. tostring(collectgarbage('count')*1024) .. '\\n')\n\
18 | error({code=121})\n\
19 | end\n\
20 | for loopCounter=0,2 do\n\
21 | local status, err = pcall(script1Function)\n\
22 | print(err.code .. '\\n')\n\
23 | end";
24 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/Scripts/script1.lua:
--------------------------------------------------------------------------------
1 | function script1Function ()
2 | print('\nscript1: ' .. tostring(uc.counter()) ..'\n')
3 |
4 | --Call a function from an other script (helperScript.lua).
5 | includedScript()
6 |
7 | --Split a string and print the result.
8 | local example = 'an example string'
9 | for el in string.gmatch(example, '%S+') do
10 | print(el .. ' ')
11 | end
12 | print('\n')
13 | --[[ test muli line comment:
14 | line 2
15 | line 3
16 | --]]
17 |
18 | --Call C-function func1 and print the result.
19 | local result1, result2 = uc.func1('Testmessage')
20 | print('result1: '.. tostring(result1) .. ' result2: '.. tostring(result2) .. '\n')
21 |
22 | --Call C-function func2 and print the result.
23 | local array = {0,1,2,3,4}
24 | local resultTable = uc.func2(array)
25 | print('test print:', 'string', 3, '\n')
26 | print('resultTable1: '.. tostring(resultTable[0]) .. ' resultTable2: '.. tostring(resultTable[1]) .. '\n')
27 |
28 | --Print the heap usage, collect garbage and then print the heap usage again.
29 | print('heap usage before collect: ' .. tostring(collectgarbage('count')*1024) .. '\n')
30 | collectgarbage('collect')
31 | print('heap usage after collect: ' .. tostring(collectgarbage('count')*1024) .. '\n')
32 | error({code=121})
33 | end
34 |
35 | for loopCounter=0,2 do
36 | local status, err = pcall(script1Function)
37 | print(err.code .. '\\n')
38 | end
39 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/Scripts/script2.h:
--------------------------------------------------------------------------------
1 | static const char* script2="print('\\nscript2: ' .. tostring(uc.counter()) ..'\\n')\n\
2 | includedScript()\n\
3 | print('heap usage: ' .. tostring(collectgarbage('count')*1024) .. '\\n')";
4 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/Scripts/script2.lua:
--------------------------------------------------------------------------------
1 | print('\nscript2: ' .. tostring(uc.counter()) ..'\n')
2 |
3 | --Call a function from an other script (helperScript.lua).
4 | includedScript()
5 |
6 | --Print the heap usage.
7 | print('heap usage: ' .. tostring(collectgarbage('count')*1024) .. '\n')
8 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/luaInterface.c:
--------------------------------------------------------------------------------
1 |
2 | #include "luaInterface.h"
3 |
4 | #include "lua.h"
5 | #include "lauxlib.h"
6 | #include "lualib.h"
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | //This function is called by Lua if it cannot handle an occured error.
13 | void luaAbort(void)
14 | {
15 | lua_writestringerror("luaAbort", sizeof("luaAbort"));
16 | while(1){}
17 | }
18 |
19 |
20 | int func1(lua_State *L)
21 | {
22 | size_t size;
23 | const char *message = luaL_checklstring(L, 1, &size);
24 |
25 | const char* msg = "C func1:";
26 | lua_writestring(msg, strlen(msg));
27 | lua_writestring(message, size);
28 | lua_writeline();
29 |
30 | //Cleanup the stack.
31 | int n = lua_gettop(L);
32 | lua_pop(L, n);
33 |
34 |
35 | //Create the result.
36 | lua_pushinteger(L, 1);
37 | lua_pushinteger(L, 2);
38 |
39 | return 2;//2 results
40 | }
41 |
42 | int func2(lua_State *L)
43 | {
44 | luaL_checktype(L, 1, LUA_TTABLE);
45 |
46 | lua_settop(L, 1);
47 |
48 |
49 | const char* msg = "C func2:";
50 | lua_writestring(msg, strlen(msg));
51 |
52 |
53 | lua_gettable(L, 1);
54 |
55 | //Add dummy value for the last lua_pop.
56 | lua_pushnil(L);
57 |
58 | while(lua_next(L, -2))
59 | {
60 | lua_Integer b = (int)lua_tonumber(L, -1);
61 | char value = 48 + b;
62 | lua_writestring(" ", 1);
63 | lua_writestring(&value, 1);
64 | lua_pop(L, 1);
65 | }
66 |
67 | lua_writeline();
68 |
69 | //Cleanup the stack.
70 | int n = lua_gettop(L);
71 | lua_pop(L, n);
72 |
73 |
74 | //Create the result.
75 | lua_newtable(L);
76 | lua_pushinteger(L, 5);
77 | lua_rawseti(L, -2, 0);
78 | lua_pushinteger(L, 9);
79 | lua_rawseti(L, -2, 1);
80 |
81 | return 1;
82 | }
83 |
84 | int counterFunction(lua_State *L)
85 | {
86 | static uint32_t counter = 0;
87 |
88 | counter++;
89 | lua_pushinteger(L, counter);
90 | return 1;
91 | }
92 |
93 |
94 | static const luaL_Reg uC_funcs[] = {
95 | {"func1", func1},
96 | {"func2", func2},
97 | {"counter", counterFunction},
98 | {NULL, NULL}
99 | };
100 |
101 |
102 | LUAMOD_API int luaopen_uc (lua_State *L) {
103 | luaL_newlib(L, uC_funcs);
104 | return 1;
105 | }
106 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/luaInterface.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef LUAINTERFACE_H_
4 | #define LUAINTERFACE_H_
5 |
6 | #include "lua.h"
7 |
8 | //
9 | #define LUA_INTERFACE_LIBS {"uc", luaopen_uc}
10 |
11 |
12 | LUAMOD_API int (luaopen_uc) (lua_State *L);
13 |
14 |
15 |
16 | #endif /* LUAINTERFACE_H_ */
17 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/luaProjectConfig.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef LUAPROJECTCONFIG_H_
3 | #define LUAPROJECTCONFIG_H_
4 |
5 | #include
6 | #include
7 | #include
8 | #include "helper/luaHeap.h"
9 | #include "drv_uartApi.h"
10 |
11 |
12 | //This function is called by Lua if it cannot handle an occurred error.
13 | void luaAbort(void);
14 |
15 | //If the math module shall be included then this define must be defined.
16 | //define LUA_WITH_MATH
17 |
18 | //The size of the heap used by Lua.
19 | #define LUA_HEAP_SIZE (20000)
20 |
21 | //These defines are used to protect the memory management calls if several Lua instances in different threads are created.
22 | #define LUA_MEM_ENTER_CRITICAL_SECTION()
23 | #define LUA_MEM_LEAVE_CRITICAL_SECTION()
24 |
25 | //Function for printing text from lua.
26 | #define lua_writestring(string,length) drv_uartSendData((uint8_t*) string, length);
27 | #define lua_writeline() lua_writestring("\n", 1);
28 | #define lua_writestringerror(string,length) lua_writestring(string, length);
29 |
30 |
31 | #endif /* LUAPROJECTCONFIG_H_ */
32 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/printFreeHeap.c:
--------------------------------------------------------------------------------
1 |
2 | #include "printFreeHeap.h"
3 |
4 | #include "../../../lua/lua.h"
5 | #include "../../../lua/lauxlib.h"
6 | #include "../../../lua/lualib.h"
7 | #include "../../../lua/helper/luaHeap.h"
8 | #include "../../../lua/luaconf.h"
9 | #include "luaInterface.h"
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | void printFreeHeap(char* message)
16 | {
17 | char buffer[16];
18 | size_t size = luaGetFreeHeapSize();
19 |
20 | snprintf(buffer, 16, "%i", size);
21 | lua_writestring(message, strlen(message));
22 | lua_writestring(buffer, strlen(buffer));
23 | lua_writeline();
24 | }
25 |
26 | void printMinimumFreeHeap()
27 | {
28 | char buffer[16];
29 | size_t size = luaGetMinimumEverFreeHeapSize();
30 |
31 | snprintf(buffer, 16, "%i", size);
32 | lua_writestring("minimum free heap: ", sizeof("minimum free heap: ") - 1);
33 | lua_writestring(buffer, strlen(buffer));
34 | lua_writeline();
35 | }
36 |
--------------------------------------------------------------------------------
/examples/STM32L552/luaProject/printFreeHeap.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef LUAPROJECT_PRINTFREEHEAP_H_
4 | #define LUAPROJECT_PRINTFREEHEAP_H_
5 |
6 |
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 |
12 | void printFreeHeap(char* message);
13 | void printMinimumFreeHeap();
14 |
15 | #ifdef __cplusplus
16 | }
17 | #endif
18 |
19 |
20 |
21 | #endif /* LUAPROJECT_PRINTFREEHEAP_H_ */
22 |
--------------------------------------------------------------------------------
/licence:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Copyright (C) 2018 Stefan Zieker
3 | *
4 | * embLua is based on Lua 5.3.4 and has the same licence (below).
5 | *
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining
8 | * a copy of this software and associated documentation files (the
9 | * "Software"), to deal in the Software without restriction, including
10 | * without limitation the rights to use, copy, modify, merge, publish,
11 | * distribute, sublicense, and/or sell copies of the Software, and to
12 | * permit persons to whom the Software is furnished to do so, subject to
13 | * the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 | ******************************************************************************/
--------------------------------------------------------------------------------
/lua/helper/convertToHeader.lua:
--------------------------------------------------------------------------------
1 |
2 | --Rurns the file name from a file path
3 | function GetFileName(filePath)
4 | return filePath:match("^.+/(.+)$")
5 | end
6 |
7 | --Returns the file extension from a file name
8 | function GetFileExtension(fileName)
9 | return fileName:match("^.+(%..+)$")
10 | end
11 |
12 | --Returns all files in a directory.
13 | function dirLookup(dir)
14 | local result = {}
15 | local p = io.popen('find "'..dir..'" -type f') --Open directory look for files, save data in p. By giving '-type f' as parameter, it returns all files.
16 | for file in p:lines() do --Loop through all files
17 | table.insert(result, file)
18 | end
19 | return result
20 | end
21 |
22 | --Converts a lua script file into a C header file.
23 | function convertFile(fileName)
24 | local f = assert(io.open(fileName, "r"))
25 | local content = f:read("*all")
26 | f:close()
27 |
28 | --Create the name of the header file.
29 | local newFileName = string.sub(fileName, 0, string.len(fileName) - 4);
30 |
31 | local newContent = 'static const char* ' .. GetFileName(newFileName) .. '="'
32 | newFileName = newFileName .. '.h'
33 |
34 | --Remove all multi line comments (--[[ --]])
35 | content = string.gsub(content, '[^"\']%-%-%[%[(.-)%-%-%]%]', '')
36 |
37 | --Remove all single line comments (--)
38 | local tmpString = content
39 | repeat
40 | content = tmpString
41 | tmpString = string.gsub(content, '[\r\n][ \t]-%-%-(.-)[\r\n]', '\n')
42 | until(tmpString == content)
43 |
44 | content = string.gsub(content, '\\', '\\\\')
45 | content = string.gsub(content, '"', '\\"')
46 |
47 | --Split the file into single lines.
48 | for line in string.gmatch(content, "[^\r\n]+") do
49 | newContent = newContent .. line .. '\\n\\\n'
50 | end
51 | newContent = string.sub(newContent, 0, string.len(newContent) - 4) .. '";'
52 |
53 | --Remove all empty lines.
54 | newContent = string.gsub(newContent, '[\t ]+\\n\\', '\\n\\')
55 | newContent = string.gsub(newContent, '[\r\n]\\n\\[\r\n]', '\n')
56 | newContent = string.gsub(newContent, '\\n\\[\r\n]\\n\\', '\\n\\')
57 |
58 |
59 |
60 | newContent = newContent .. "\n"
61 |
62 | --Write the header file.
63 | local headerFile = assert(io.open(newFileName, "w"))
64 | headerFile:write(newContent)
65 | headerFile:close()
66 | end
67 |
68 |
69 | local scriptFolder = arg[1]
70 |
71 | --Get all files.
72 | local files = dirLookup(scriptFolder)
73 |
74 | --Convert all lua files.
75 | for i, file in ipairs(files) do
76 | if GetFileExtension(file) == ".lua" then
77 | print ("processing file: " .. file)
78 | convertFile(file)
79 | end
80 | end
--------------------------------------------------------------------------------
/lua/helper/luaHeap.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef LUA_HELPER_LUAHEAP_H_
4 | #define LUA_HELPER_LUAHEAP_H_
5 |
6 | /**
7 | * Allocates memory.
8 | *
9 | * @param xWantedSize The size to allocate.
10 | */
11 | void *luaMallocFunction( size_t xWantedSize );
12 |
13 | /**
14 | * Releases a memory block.
15 | *
16 | * @param pv Pointer to the memory block.
17 | */
18 | void luaFreeFunction( void *pv );
19 |
20 | /**
21 | * Returns the remaining space on the heap.
22 | */
23 | size_t luaGetFreeHeapSize( void );
24 |
25 | /**
26 | * Returns min. remaining space on the heap.
27 | */
28 | size_t luaGetMinimumEverFreeHeapSize(void);
29 |
30 | #endif /* LUA_HELPER_LUAHEAP_H_ */
31 |
--------------------------------------------------------------------------------
/lua/helper/luaHelper.c:
--------------------------------------------------------------------------------
1 |
2 | #include "../lua.h"
3 | #include "../lauxlib.h"
4 | #include "../lualib.h"
5 |
6 | #include
7 |
8 | /*
9 | ** Check whether 'status' is not OK and, if so, prints the error
10 | ** message on the top of the stack. It assumes that the error object
11 | ** is a string, as it was either generated by Lua or by 'msghandler'.
12 | */
13 | static int report (lua_State *L, int status) {
14 | if (status != LUA_OK) {
15 | const char *msg = lua_tostring(L, -1);
16 | lua_writestring(msg, strlen(msg));
17 | lua_writeline();
18 | lua_pop(L, 1); /* remove message */
19 | }
20 | return status;
21 | }
22 |
23 |
24 | /**
25 | * Executes a lua script.
26 | *
27 | * @param L The lua state.
28 | * @param s The script.
29 | * @param name The name of the script.
30 | * @return LUA_OK on success.
31 | */
32 | int dostring (lua_State *L, const char *s, const char *name)
33 | {
34 | int status = luaL_loadbuffer(L, s, strlen(s), name);
35 |
36 | if (status == LUA_OK)
37 | {
38 | status = lua_pcall(L, 0, 0, 0);
39 | }
40 | return report(L, status);
41 | }
42 |
43 |
44 |
--------------------------------------------------------------------------------
/lua/helper/luaHelper.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef LUAHELPER_H_
4 | #define LUAHELPER_H_
5 |
6 |
7 | #include "lua.h"
8 |
9 | #ifdef __cplusplus
10 | extern "C" {
11 | #endif
12 |
13 | /**
14 | * Executes a lua script.
15 | *
16 | * @param L The lua state.
17 | * @param s The script.
18 | * @param name The name of the script.
19 | * @return LUA_OK on success.
20 | */
21 | int dostring (lua_State *L, const char *s, const char *name);
22 |
23 | #ifdef __cplusplus
24 | }
25 | #endif
26 | #endif /* LUAHELPER_H_ */
27 |
--------------------------------------------------------------------------------
/lua/lapi.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lapi.h $
3 | ** Auxiliary functions from Lua API
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lapi_h
8 | #define lapi_h
9 |
10 |
11 | #include "llimits.h"
12 | #include "lstate.h"
13 |
14 |
15 | /* Increments 'L->top.p', checking for stack overflows */
16 | #define api_incr_top(L) {L->top.p++; \
17 | api_check(L, L->top.p <= L->ci->top.p, \
18 | "stack overflow");}
19 |
20 |
21 | /*
22 | ** If a call returns too many multiple returns, the callee may not have
23 | ** stack space to accommodate all results. In this case, this macro
24 | ** increases its stack space ('L->ci->top.p').
25 | */
26 | #define adjustresults(L,nres) \
27 | { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
28 | L->ci->top.p = L->top.p; }
29 |
30 |
31 | /* Ensure the stack has at least 'n' elements */
32 | #define api_checknelems(L,n) \
33 | api_check(L, (n) < (L->top.p - L->ci->func.p), \
34 | "not enough elements in the stack")
35 |
36 |
37 | /*
38 | ** To reduce the overhead of returning from C functions, the presence of
39 | ** to-be-closed variables in these functions is coded in the CallInfo's
40 | ** field 'nresults', in a way that functions with no to-be-closed variables
41 | ** with zero, one, or "all" wanted results have no overhead. Functions
42 | ** with other number of wanted results, as well as functions with
43 | ** variables to be closed, have an extra check.
44 | */
45 |
46 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET)
47 |
48 | /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
49 | #define codeNresults(n) (-(n) - 3)
50 | #define decodeNresults(n) (-(n) - 3)
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/lua/lcode.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lcode.h $
3 | ** Code generator for Lua
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lcode_h
8 | #define lcode_h
9 |
10 | #include "llex.h"
11 | #include "lobject.h"
12 | #include "lopcodes.h"
13 | #include "lparser.h"
14 |
15 |
16 | /*
17 | ** Marks the end of a patch list. It is an invalid value both as an absolute
18 | ** address, and as a list link (would link an element to itself).
19 | */
20 | #define NO_JUMP (-1)
21 |
22 |
23 | /*
24 | ** grep "ORDER OPR" if you change these enums (ORDER OP)
25 | */
26 | typedef enum BinOpr {
27 | /* arithmetic operators */
28 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,
29 | OPR_DIV, OPR_IDIV,
30 | /* bitwise operators */
31 | OPR_BAND, OPR_BOR, OPR_BXOR,
32 | OPR_SHL, OPR_SHR,
33 | /* string operator */
34 | OPR_CONCAT,
35 | /* comparison operators */
36 | OPR_EQ, OPR_LT, OPR_LE,
37 | OPR_NE, OPR_GT, OPR_GE,
38 | /* logical operators */
39 | OPR_AND, OPR_OR,
40 | OPR_NOBINOPR
41 | } BinOpr;
42 |
43 |
44 | /* true if operation is foldable (that is, it is arithmetic or bitwise) */
45 | #define foldbinop(op) ((op) <= OPR_SHR)
46 |
47 |
48 | #define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0)
49 |
50 |
51 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
52 |
53 |
54 | /* get (pointer to) instruction of given 'expdesc' */
55 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info])
56 |
57 |
58 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
59 |
60 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
61 |
62 | LUAI_FUNC int luaK_code (FuncState *fs, Instruction i);
63 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
64 | LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A,
65 | int B, int C, int k);
66 | LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);
67 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
68 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
69 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
70 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
71 | LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n);
72 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
73 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
74 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);
75 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
76 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
77 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
78 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
79 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
80 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
81 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
82 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
83 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
84 | LUAI_FUNC int luaK_jump (FuncState *fs);
85 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);
86 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
87 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
88 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
89 | LUAI_FUNC int luaK_getlabel (FuncState *fs);
90 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);
91 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
92 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,
93 | expdesc *v2, int line);
94 | LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
95 | int ra, int asize, int hsize);
96 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
97 | LUAI_FUNC void luaK_finish (FuncState *fs);
98 | LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg);
99 |
100 |
101 | #endif
102 |
--------------------------------------------------------------------------------
/lua/lctype.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lctype.c $
3 | ** 'ctype' functions for Lua
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #define lctype_c
8 | #define LUA_CORE
9 |
10 | #include "lprefix.h"
11 |
12 |
13 | #include "lctype.h"
14 |
15 | #if !LUA_USE_CTYPE /* { */
16 |
17 | #include
18 |
19 |
20 | #if defined (LUA_UCID) /* accept UniCode IDentifiers? */
21 | /* consider all non-ascii codepoints to be alphabetic */
22 | #define NONA 0x01
23 | #else
24 | #define NONA 0x00 /* default */
25 | #endif
26 |
27 |
28 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {
29 | 0x00, /* EOZ */
30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */
31 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */
33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */
35 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
36 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */
37 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
38 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */
39 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
40 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */
41 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05,
42 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */
43 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
44 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */
45 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
46 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 8. */
47 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
48 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 9. */
49 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
50 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* a. */
51 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
52 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* b. */
53 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
54 | 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, /* c. */
55 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
56 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* d. */
57 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
58 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* e. */
59 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
60 | NONA, NONA, NONA, NONA, NONA, 0x00, 0x00, 0x00, /* f. */
61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
62 | };
63 |
64 | #endif /* } */
65 |
--------------------------------------------------------------------------------
/lua/lctype.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lctype.h $
3 | ** 'ctype' functions for Lua
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lctype_h
8 | #define lctype_h
9 |
10 | #include "lua.h"
11 |
12 |
13 | /*
14 | ** WARNING: the functions defined here do not necessarily correspond
15 | ** to the similar functions in the standard C ctype.h. They are
16 | ** optimized for the specific needs of Lua.
17 | */
18 |
19 | #if !defined(LUA_USE_CTYPE)
20 |
21 | #if 'A' == 65 && '0' == 48
22 | /* ASCII case: can use its own tables; faster and fixed */
23 | #define LUA_USE_CTYPE 0
24 | #else
25 | /* must use standard C ctype */
26 | #define LUA_USE_CTYPE 1
27 | #endif
28 |
29 | #endif
30 |
31 |
32 | #if !LUA_USE_CTYPE /* { */
33 |
34 | #include
35 |
36 | #include "llimits.h"
37 |
38 |
39 | #define ALPHABIT 0
40 | #define DIGITBIT 1
41 | #define PRINTBIT 2
42 | #define SPACEBIT 3
43 | #define XDIGITBIT 4
44 |
45 |
46 | #define MASK(B) (1 << (B))
47 |
48 |
49 | /*
50 | ** add 1 to char to allow index -1 (EOZ)
51 | */
52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p))
53 |
54 | /*
55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_'
56 | */
57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT))
58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT)))
59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT))
60 | #define lisspace(c) testprop(c, MASK(SPACEBIT))
61 | #define lisprint(c) testprop(c, MASK(PRINTBIT))
62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
63 |
64 |
65 | /*
66 | ** In ASCII, this 'ltolower' is correct for alphabetic characters and
67 | ** for '.'. That is enough for Lua needs. ('check_exp' ensures that
68 | ** the character either is an upper-case letter or is unchanged by
69 | ** the transformation, which holds for lower-case letters and '.'.)
70 | */
71 | #define ltolower(c) \
72 | check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \
73 | (c) | ('A' ^ 'a'))
74 |
75 |
76 | /* one entry for each character and for -1 (EOZ) */
77 | LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];)
78 |
79 |
80 | #else /* }{ */
81 |
82 | /*
83 | ** use standard C ctypes
84 | */
85 |
86 | #include
87 |
88 |
89 | #define lislalpha(c) (isalpha(c) || (c) == '_')
90 | #define lislalnum(c) (isalnum(c) || (c) == '_')
91 | #define lisdigit(c) (isdigit(c))
92 | #define lisspace(c) (isspace(c))
93 | #define lisprint(c) (isprint(c))
94 | #define lisxdigit(c) (isxdigit(c))
95 |
96 | #define ltolower(c) (tolower(c))
97 |
98 | #endif /* } */
99 |
100 | #endif
101 |
102 |
--------------------------------------------------------------------------------
/lua/ldebug.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ldebug.h $
3 | ** Auxiliary functions from Debug Interface module
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ldebug_h
8 | #define ldebug_h
9 |
10 |
11 | #include "lstate.h"
12 |
13 |
14 | #define pcRel(pc, p) (cast_int((pc) - (p)->code) - 1)
15 |
16 |
17 | /* Active Lua function (given call info) */
18 | #define ci_func(ci) (clLvalue(s2v((ci)->func.p)))
19 |
20 |
21 | #define resethookcount(L) (L->hookcount = L->basehookcount)
22 |
23 | /*
24 | ** mark for entries in 'lineinfo' array that has absolute information in
25 | ** 'abslineinfo' array
26 | */
27 | #define ABSLINEINFO (-0x80)
28 |
29 |
30 | /*
31 | ** MAXimum number of successive Instructions WiTHout ABSolute line
32 | ** information. (A power of two allows fast divisions.)
33 | */
34 | #if !defined(MAXIWTHABS)
35 | #define MAXIWTHABS 128
36 | #endif
37 |
38 |
39 | LUAI_FUNC int luaG_getfuncline (const Proto *f, int pc);
40 | LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n,
41 | StkId *pos);
42 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o,
43 | const char *opname);
44 | LUAI_FUNC l_noret luaG_callerror (lua_State *L, const TValue *o);
45 | LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o,
46 | const char *what);
47 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1,
48 | const TValue *p2);
49 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1,
50 | const TValue *p2,
51 | const char *msg);
52 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1,
53 | const TValue *p2);
54 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,
55 | const TValue *p2);
56 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);
57 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,
58 | TString *src, int line);
59 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L);
60 | LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc);
61 | LUAI_FUNC int luaG_tracecall (lua_State *L);
62 |
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/lua/ldo.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ldo.h $
3 | ** Stack and Call structure of Lua
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ldo_h
8 | #define ldo_h
9 |
10 |
11 | #include "llimits.h"
12 | #include "lobject.h"
13 | #include "lstate.h"
14 | #include "lzio.h"
15 |
16 |
17 | /*
18 | ** Macro to check stack size and grow stack if needed. Parameters
19 | ** 'pre'/'pos' allow the macro to preserve a pointer into the
20 | ** stack across reallocations, doing the work only when needed.
21 | ** It also allows the running of one GC step when the stack is
22 | ** reallocated.
23 | ** 'condmovestack' is used in heavy tests to force a stack reallocation
24 | ** at every check.
25 | */
26 | #define luaD_checkstackaux(L,n,pre,pos) \
27 | if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \
28 | { pre; luaD_growstack(L, n, 1); pos; } \
29 | else { condmovestack(L,pre,pos); }
30 |
31 | /* In general, 'pre'/'pos' are empty (nothing to save) */
32 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0)
33 |
34 |
35 |
36 | #define savestack(L,pt) (cast_charp(pt) - cast_charp(L->stack.p))
37 | #define restorestack(L,n) cast(StkId, cast_charp(L->stack.p) + (n))
38 |
39 |
40 | /* macro to check stack size, preserving 'p' */
41 | #define checkstackp(L,n,p) \
42 | luaD_checkstackaux(L, n, \
43 | ptrdiff_t t__ = savestack(L, p), /* save 'p' */ \
44 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
45 |
46 |
47 | /* macro to check stack size and GC, preserving 'p' */
48 | #define checkstackGCp(L,n,p) \
49 | luaD_checkstackaux(L, n, \
50 | ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
51 | luaC_checkGC(L), /* stack grow uses memory */ \
52 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
53 |
54 |
55 | /* macro to check stack size and GC */
56 | #define checkstackGC(L,fsize) \
57 | luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
58 |
59 |
60 | /* type of protected functions, to be ran by 'runprotected' */
61 | typedef void (*Pfunc) (lua_State *L, void *ud);
62 |
63 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
64 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
65 | const char *mode);
66 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
67 | int fTransfer, int nTransfer);
68 | LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
69 | LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
70 | int narg1, int delta);
71 | LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
72 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
73 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
74 | LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status);
75 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
76 | ptrdiff_t oldtop, ptrdiff_t ef);
77 | LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres);
78 | LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);
79 | LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);
80 | LUAI_FUNC void luaD_shrinkstack (lua_State *L);
81 | LUAI_FUNC void luaD_inctop (lua_State *L);
82 |
83 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
84 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
85 |
86 | #endif
87 |
88 |
--------------------------------------------------------------------------------
/lua/ldump.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ldump.c $
3 | ** save precompiled Lua chunks
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #define ldump_c
8 | #define LUA_CORE
9 |
10 | #include "lprefix.h"
11 |
12 |
13 | #include
14 | #include
15 |
16 | #include "lua.h"
17 |
18 | #include "lobject.h"
19 | #include "lstate.h"
20 | #include "lundump.h"
21 |
22 |
23 | typedef struct {
24 | lua_State *L;
25 | lua_Writer writer;
26 | void *data;
27 | int strip;
28 | int status;
29 | } DumpState;
30 |
31 |
32 | /*
33 | ** All high-level dumps go through dumpVector; you can change it to
34 | ** change the endianness of the result
35 | */
36 | #define dumpVector(D,v,n) dumpBlock(D,v,(n)*sizeof((v)[0]))
37 |
38 | #define dumpLiteral(D, s) dumpBlock(D,s,sizeof(s) - sizeof(char))
39 |
40 |
41 | static void dumpBlock (DumpState *D, const void *b, size_t size) {
42 | if (D->status == 0 && size > 0) {
43 | lua_unlock(D->L);
44 | D->status = (*D->writer)(D->L, b, size, D->data);
45 | lua_lock(D->L);
46 | }
47 | }
48 |
49 |
50 | #define dumpVar(D,x) dumpVector(D,&x,1)
51 |
52 |
53 | static void dumpByte (DumpState *D, int y) {
54 | lu_byte x = (lu_byte)y;
55 | dumpVar(D, x);
56 | }
57 |
58 |
59 | /*
60 | ** 'dumpSize' buffer size: each byte can store up to 7 bits. (The "+6"
61 | ** rounds up the division.)
62 | */
63 | #define DIBS ((sizeof(size_t) * CHAR_BIT + 6) / 7)
64 |
65 | static void dumpSize (DumpState *D, size_t x) {
66 | lu_byte buff[DIBS];
67 | int n = 0;
68 | do {
69 | buff[DIBS - (++n)] = x & 0x7f; /* fill buffer in reverse order */
70 | x >>= 7;
71 | } while (x != 0);
72 | buff[DIBS - 1] |= 0x80; /* mark last byte */
73 | dumpVector(D, buff + DIBS - n, n);
74 | }
75 |
76 |
77 | static void dumpInt (DumpState *D, int x) {
78 | dumpSize(D, x);
79 | }
80 |
81 |
82 | static void dumpNumber (DumpState *D, lua_Number x) {
83 | dumpVar(D, x);
84 | }
85 |
86 |
87 | static void dumpInteger (DumpState *D, lua_Integer x) {
88 | dumpVar(D, x);
89 | }
90 |
91 |
92 | static void dumpString (DumpState *D, const TString *s) {
93 | if (s == NULL)
94 | dumpSize(D, 0);
95 | else {
96 | size_t size = tsslen(s);
97 | const char *str = getstr(s);
98 | dumpSize(D, size + 1);
99 | dumpVector(D, str, size);
100 | }
101 | }
102 |
103 |
104 | static void dumpCode (DumpState *D, const Proto *f) {
105 | dumpInt(D, f->sizecode);
106 | dumpVector(D, f->code, f->sizecode);
107 | }
108 |
109 |
110 | static void dumpFunction(DumpState *D, const Proto *f, TString *psource);
111 |
112 | static void dumpConstants (DumpState *D, const Proto *f) {
113 | int i;
114 | int n = f->sizek;
115 | dumpInt(D, n);
116 | for (i = 0; i < n; i++) {
117 | const TValue *o = &f->k[i];
118 | int tt = ttypetag(o);
119 | dumpByte(D, tt);
120 | switch (tt) {
121 | case LUA_VNUMFLT:
122 | dumpNumber(D, fltvalue(o));
123 | break;
124 | case LUA_VNUMINT:
125 | dumpInteger(D, ivalue(o));
126 | break;
127 | case LUA_VSHRSTR:
128 | case LUA_VLNGSTR:
129 | dumpString(D, tsvalue(o));
130 | break;
131 | default:
132 | lua_assert(tt == LUA_VNIL || tt == LUA_VFALSE || tt == LUA_VTRUE);
133 | }
134 | }
135 | }
136 |
137 |
138 | static void dumpProtos (DumpState *D, const Proto *f) {
139 | int i;
140 | int n = f->sizep;
141 | dumpInt(D, n);
142 | for (i = 0; i < n; i++)
143 | dumpFunction(D, f->p[i], f->source);
144 | }
145 |
146 |
147 | static void dumpUpvalues (DumpState *D, const Proto *f) {
148 | int i, n = f->sizeupvalues;
149 | dumpInt(D, n);
150 | for (i = 0; i < n; i++) {
151 | dumpByte(D, f->upvalues[i].instack);
152 | dumpByte(D, f->upvalues[i].idx);
153 | dumpByte(D, f->upvalues[i].kind);
154 | }
155 | }
156 |
157 |
158 | static void dumpDebug (DumpState *D, const Proto *f) {
159 | int i, n;
160 | n = (D->strip) ? 0 : f->sizelineinfo;
161 | dumpInt(D, n);
162 | dumpVector(D, f->lineinfo, n);
163 | n = (D->strip) ? 0 : f->sizeabslineinfo;
164 | dumpInt(D, n);
165 | for (i = 0; i < n; i++) {
166 | dumpInt(D, f->abslineinfo[i].pc);
167 | dumpInt(D, f->abslineinfo[i].line);
168 | }
169 | n = (D->strip) ? 0 : f->sizelocvars;
170 | dumpInt(D, n);
171 | for (i = 0; i < n; i++) {
172 | dumpString(D, f->locvars[i].varname);
173 | dumpInt(D, f->locvars[i].startpc);
174 | dumpInt(D, f->locvars[i].endpc);
175 | }
176 | n = (D->strip) ? 0 : f->sizeupvalues;
177 | dumpInt(D, n);
178 | for (i = 0; i < n; i++)
179 | dumpString(D, f->upvalues[i].name);
180 | }
181 |
182 |
183 | static void dumpFunction (DumpState *D, const Proto *f, TString *psource) {
184 | if (D->strip || f->source == psource)
185 | dumpString(D, NULL); /* no debug info or same source as its parent */
186 | else
187 | dumpString(D, f->source);
188 | dumpInt(D, f->linedefined);
189 | dumpInt(D, f->lastlinedefined);
190 | dumpByte(D, f->numparams);
191 | dumpByte(D, f->is_vararg);
192 | dumpByte(D, f->maxstacksize);
193 | dumpCode(D, f);
194 | dumpConstants(D, f);
195 | dumpUpvalues(D, f);
196 | dumpProtos(D, f);
197 | dumpDebug(D, f);
198 | }
199 |
200 |
201 | static void dumpHeader (DumpState *D) {
202 | dumpLiteral(D, LUA_SIGNATURE);
203 | dumpByte(D, LUAC_VERSION);
204 | dumpByte(D, LUAC_FORMAT);
205 | dumpLiteral(D, LUAC_DATA);
206 | dumpByte(D, sizeof(Instruction));
207 | dumpByte(D, sizeof(lua_Integer));
208 | dumpByte(D, sizeof(lua_Number));
209 | dumpInteger(D, LUAC_INT);
210 | dumpNumber(D, LUAC_NUM);
211 | }
212 |
213 |
214 | /*
215 | ** dump Lua function as precompiled chunk
216 | */
217 | int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,
218 | int strip) {
219 | DumpState D;
220 | D.L = L;
221 | D.writer = w;
222 | D.data = data;
223 | D.strip = strip;
224 | D.status = 0;
225 | dumpHeader(&D);
226 | dumpByte(&D, f->sizeupvalues);
227 | dumpFunction(&D, f, NULL);
228 | return D.status;
229 | }
230 |
231 |
--------------------------------------------------------------------------------
/lua/lfunc.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lfunc.h $
3 | ** Auxiliary functions to manipulate prototypes and closures
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lfunc_h
8 | #define lfunc_h
9 |
10 |
11 | #include "lobject.h"
12 |
13 |
14 | #define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \
15 | cast_int(sizeof(TValue)) * (n))
16 |
17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \
18 | cast_int(sizeof(TValue *)) * (n))
19 |
20 |
21 | /* test whether thread is in 'twups' list */
22 | #define isintwups(L) (L->twups != L)
23 |
24 |
25 | /*
26 | ** maximum number of upvalues in a closure (both C and Lua). (Value
27 | ** must fit in a VM register.)
28 | */
29 | #define MAXUPVAL 255
30 |
31 |
32 | #define upisopen(up) ((up)->v.p != &(up)->u.value)
33 |
34 |
35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v.p))
36 |
37 |
38 | /*
39 | ** maximum number of misses before giving up the cache of closures
40 | ** in prototypes
41 | */
42 | #define MAXMISS 10
43 |
44 |
45 |
46 | /* special status to close upvalues preserving the top of the stack */
47 | #define CLOSEKTOP (-1)
48 |
49 |
50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L);
51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals);
52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals);
53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
59 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
60 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
61 | int pc);
62 |
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/lua/linit.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: linit.c $
3 | ** Initialization of libraries for lua.c and other clients
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #define linit_c
9 | #define LUA_LIB
10 |
11 | /*
12 | ** If you embed Lua in your program and need to open the standard
13 | ** libraries, call luaL_openlibs in your program. If you need a
14 | ** different set of libraries, copy this file to your project and edit
15 | ** it to suit your needs.
16 | **
17 | ** You can also *preload* libraries, so that a later 'require' can
18 | ** open the library, which is already linked to the application.
19 | ** For that, do the following code:
20 | **
21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
22 | ** lua_pushcfunction(L, luaopen_modname);
23 | ** lua_setfield(L, -2, modname);
24 | ** lua_pop(L, 1); // remove PRELOAD table
25 | */
26 |
27 | #include "lprefix.h"
28 |
29 |
30 | #include
31 |
32 | #include "lua.h"
33 |
34 | #include "lualib.h"
35 | #include "lauxlib.h"
36 |
37 | #include "luaInterface.h"
38 |
39 |
40 | /*
41 | ** these libs are loaded by lua.c and are readily available to any Lua
42 | ** program
43 | */
44 | static const luaL_Reg loadedlibs[] = {
45 | {LUA_GNAME, luaopen_base},
46 | {LUA_TABLIBNAME, luaopen_table},
47 | {LUA_STRLIBNAME, luaopen_string},
48 | #ifdef LUA_WITH_MATH
49 | {LUA_MATHLIBNAME, luaopen_math},
50 | #endif
51 | #ifdef LUA_INTERFACE_LIBS
52 | LUA_INTERFACE_LIBS,
53 | #endif
54 | {NULL, NULL}
55 | };
56 |
57 |
58 | LUALIB_API void luaL_openlibs (lua_State *L) {
59 | const luaL_Reg *lib;
60 | /* "require" functions from 'loadedlibs' and set results to global table */
61 | for (lib = loadedlibs; lib->func; lib++) {
62 | luaL_requiref(L, lib->name, lib->func, 1);
63 | lua_pop(L, 1); /* remove lib */
64 | }
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/lua/ljumptab.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ljumptab.h $
3 | ** Jump Table for the Lua interpreter
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #undef vmdispatch
9 | #undef vmcase
10 | #undef vmbreak
11 |
12 | #define vmdispatch(x) goto *disptab[x];
13 |
14 | #define vmcase(l) L_##l:
15 |
16 | #define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i));
17 |
18 |
19 | static const void *const disptab[NUM_OPCODES] = {
20 |
21 | #if 0
22 | ** you can update the following list with this command:
23 | **
24 | ** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h
25 | **
26 | #endif
27 |
28 | &&L_OP_MOVE,
29 | &&L_OP_LOADI,
30 | &&L_OP_LOADF,
31 | &&L_OP_LOADK,
32 | &&L_OP_LOADKX,
33 | &&L_OP_LOADFALSE,
34 | &&L_OP_LFALSESKIP,
35 | &&L_OP_LOADTRUE,
36 | &&L_OP_LOADNIL,
37 | &&L_OP_GETUPVAL,
38 | &&L_OP_SETUPVAL,
39 | &&L_OP_GETTABUP,
40 | &&L_OP_GETTABLE,
41 | &&L_OP_GETI,
42 | &&L_OP_GETFIELD,
43 | &&L_OP_SETTABUP,
44 | &&L_OP_SETTABLE,
45 | &&L_OP_SETI,
46 | &&L_OP_SETFIELD,
47 | &&L_OP_NEWTABLE,
48 | &&L_OP_SELF,
49 | &&L_OP_ADDI,
50 | &&L_OP_ADDK,
51 | &&L_OP_SUBK,
52 | &&L_OP_MULK,
53 | &&L_OP_MODK,
54 | &&L_OP_POWK,
55 | &&L_OP_DIVK,
56 | &&L_OP_IDIVK,
57 | &&L_OP_BANDK,
58 | &&L_OP_BORK,
59 | &&L_OP_BXORK,
60 | &&L_OP_SHRI,
61 | &&L_OP_SHLI,
62 | &&L_OP_ADD,
63 | &&L_OP_SUB,
64 | &&L_OP_MUL,
65 | &&L_OP_MOD,
66 | &&L_OP_POW,
67 | &&L_OP_DIV,
68 | &&L_OP_IDIV,
69 | &&L_OP_BAND,
70 | &&L_OP_BOR,
71 | &&L_OP_BXOR,
72 | &&L_OP_SHL,
73 | &&L_OP_SHR,
74 | &&L_OP_MMBIN,
75 | &&L_OP_MMBINI,
76 | &&L_OP_MMBINK,
77 | &&L_OP_UNM,
78 | &&L_OP_BNOT,
79 | &&L_OP_NOT,
80 | &&L_OP_LEN,
81 | &&L_OP_CONCAT,
82 | &&L_OP_CLOSE,
83 | &&L_OP_TBC,
84 | &&L_OP_JMP,
85 | &&L_OP_EQ,
86 | &&L_OP_LT,
87 | &&L_OP_LE,
88 | &&L_OP_EQK,
89 | &&L_OP_EQI,
90 | &&L_OP_LTI,
91 | &&L_OP_LEI,
92 | &&L_OP_GTI,
93 | &&L_OP_GEI,
94 | &&L_OP_TEST,
95 | &&L_OP_TESTSET,
96 | &&L_OP_CALL,
97 | &&L_OP_TAILCALL,
98 | &&L_OP_RETURN,
99 | &&L_OP_RETURN0,
100 | &&L_OP_RETURN1,
101 | &&L_OP_FORLOOP,
102 | &&L_OP_FORPREP,
103 | &&L_OP_TFORPREP,
104 | &&L_OP_TFORCALL,
105 | &&L_OP_TFORLOOP,
106 | &&L_OP_SETLIST,
107 | &&L_OP_CLOSURE,
108 | &&L_OP_VARARG,
109 | &&L_OP_VARARGPREP,
110 | &&L_OP_EXTRAARG
111 |
112 | };
113 |
--------------------------------------------------------------------------------
/lua/llex.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: llex.h $
3 | ** Lexical Analyzer
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef llex_h
8 | #define llex_h
9 |
10 | #include
11 |
12 | #include "lobject.h"
13 | #include "lzio.h"
14 |
15 |
16 | /*
17 | ** Single-char tokens (terminal symbols) are represented by their own
18 | ** numeric code. Other tokens start at the following value.
19 | */
20 | #define FIRST_RESERVED (UCHAR_MAX + 1)
21 |
22 |
23 | #if !defined(LUA_ENV)
24 | #define LUA_ENV "_ENV"
25 | #endif
26 |
27 |
28 | /*
29 | * WARNING: if you change the order of this enumeration,
30 | * grep "ORDER RESERVED"
31 | */
32 | enum RESERVED {
33 | /* terminal symbols denoted by reserved words */
34 | TK_AND = FIRST_RESERVED, TK_BREAK,
35 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
36 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
37 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
38 | /* other terminal symbols */
39 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,
40 | TK_SHL, TK_SHR,
41 | TK_DBCOLON, TK_EOS,
42 | TK_FLT, TK_INT, TK_NAME, TK_STRING
43 | };
44 |
45 | /* number of reserved words */
46 | #define NUM_RESERVED (cast_int(TK_WHILE-FIRST_RESERVED + 1))
47 |
48 |
49 | typedef union {
50 | lua_Number r;
51 | lua_Integer i;
52 | TString *ts;
53 | } SemInfo; /* semantics information */
54 |
55 |
56 | typedef struct Token {
57 | int token;
58 | SemInfo seminfo;
59 | } Token;
60 |
61 |
62 | /* state of the lexer plus state of the parser when shared by all
63 | functions */
64 | typedef struct LexState {
65 | int current; /* current character (charint) */
66 | int linenumber; /* input line counter */
67 | int lastline; /* line of last token 'consumed' */
68 | Token t; /* current token */
69 | Token lookahead; /* look ahead token */
70 | struct FuncState *fs; /* current function (parser) */
71 | struct lua_State *L;
72 | ZIO *z; /* input stream */
73 | Mbuffer *buff; /* buffer for tokens */
74 | Table *h; /* to avoid collection/reuse strings */
75 | struct Dyndata *dyd; /* dynamic structures used by the parser */
76 | TString *source; /* current source name */
77 | TString *envn; /* environment variable name */
78 | } LexState;
79 |
80 |
81 | LUAI_FUNC void luaX_init (lua_State *L);
82 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
83 | TString *source, int firstchar);
84 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
85 | LUAI_FUNC void luaX_next (LexState *ls);
86 | LUAI_FUNC int luaX_lookahead (LexState *ls);
87 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s);
88 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
89 |
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/lua/lmem.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lmem.h $
3 | ** Interface to Memory Manager
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lmem_h
8 | #define lmem_h
9 |
10 |
11 | #include
12 |
13 | #include "llimits.h"
14 | #include "lua.h"
15 |
16 |
17 | #define luaM_error(L) luaD_throw(L, LUA_ERRMEM)
18 |
19 |
20 | /*
21 | ** This macro tests whether it is safe to multiply 'n' by the size of
22 | ** type 't' without overflows. Because 'e' is always constant, it avoids
23 | ** the runtime division MAX_SIZET/(e).
24 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof'
25 | ** comparison avoids a runtime comparison when overflow cannot occur.
26 | ** The compiler should be able to optimize the real test by itself, but
27 | ** when it does it, it may give a warning about "comparison is always
28 | ** false due to limited range of data type"; the +1 tricks the compiler,
29 | ** avoiding this warning but also this optimization.)
30 | */
31 | #define luaM_testsize(n,e) \
32 | (sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e))
33 |
34 | #define luaM_checksize(L,n,e) \
35 | (luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0))
36 |
37 |
38 | /*
39 | ** Computes the minimum between 'n' and 'MAX_SIZET/sizeof(t)', so that
40 | ** the result is not larger than 'n' and cannot overflow a 'size_t'
41 | ** when multiplied by the size of type 't'. (Assumes that 'n' is an
42 | ** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.)
43 | */
44 | #define luaM_limitN(n,t) \
45 | ((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \
46 | cast_uint((MAX_SIZET/sizeof(t))))
47 |
48 |
49 | /*
50 | ** Arrays of chars do not need any test
51 | */
52 | #define luaM_reallocvchar(L,b,on,n) \
53 | cast_charp(luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))
54 |
55 | #define luaM_freemem(L, b, s) luaM_free_(L, (b), (s))
56 | #define luaM_free(L, b) luaM_free_(L, (b), sizeof(*(b)))
57 | #define luaM_freearray(L, b, n) luaM_free_(L, (b), (n)*sizeof(*(b)))
58 |
59 | #define luaM_new(L,t) cast(t*, luaM_malloc_(L, sizeof(t), 0))
60 | #define luaM_newvector(L,n,t) cast(t*, luaM_malloc_(L, (n)*sizeof(t), 0))
61 | #define luaM_newvectorchecked(L,n,t) \
62 | (luaM_checksize(L,n,sizeof(t)), luaM_newvector(L,n,t))
63 |
64 | #define luaM_newobject(L,tag,s) luaM_malloc_(L, (s), tag)
65 |
66 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \
67 | ((v)=cast(t *, luaM_growaux_(L,v,nelems,&(size),sizeof(t), \
68 | luaM_limitN(limit,t),e)))
69 |
70 | #define luaM_reallocvector(L, v,oldn,n,t) \
71 | (cast(t *, luaM_realloc_(L, v, cast_sizet(oldn) * sizeof(t), \
72 | cast_sizet(n) * sizeof(t))))
73 |
74 | #define luaM_shrinkvector(L,v,size,fs,t) \
75 | ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t))))
76 |
77 | LUAI_FUNC l_noret luaM_toobig (lua_State *L);
78 |
79 | /* not to be called directly */
80 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
81 | size_t size);
82 | LUAI_FUNC void *luaM_saferealloc_ (lua_State *L, void *block, size_t oldsize,
83 | size_t size);
84 | LUAI_FUNC void luaM_free_ (lua_State *L, void *block, size_t osize);
85 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int nelems,
86 | int *size, int size_elem, int limit,
87 | const char *what);
88 | LUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem,
89 | int final_n, int size_elem);
90 | LUAI_FUNC void *luaM_malloc_ (lua_State *L, size_t size, int tag);
91 |
92 | #endif
93 |
94 |
--------------------------------------------------------------------------------
/lua/lopcodes.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lopcodes.c $
3 | ** Opcodes for Lua virtual machine
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #define lopcodes_c
8 | #define LUA_CORE
9 |
10 | #include "lprefix.h"
11 |
12 |
13 | #include "lopcodes.h"
14 |
15 |
16 | /* ORDER OP */
17 |
18 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
19 | /* MM OT IT T A mode opcode */
20 | opmode(0, 0, 0, 0, 1, iABC) /* OP_MOVE */
21 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADI */
22 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADF */
23 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */
24 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */
25 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */
26 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */
27 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */
28 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */
29 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */
30 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETUPVAL */
31 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABUP */
32 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABLE */
33 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETI */
34 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETFIELD */
35 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABUP */
36 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABLE */
37 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETI */
38 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETFIELD */
39 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NEWTABLE */
40 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SELF */
41 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDI */
42 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDK */
43 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */
44 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */
45 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODK */
46 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWK */
47 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVK */
48 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVK */
49 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BANDK */
50 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BORK */
51 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXORK */
52 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHRI */
53 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHLI */
54 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADD */
55 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUB */
56 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MUL */
57 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MOD */
58 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POW */
59 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIV */
60 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIV */
61 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BAND */
62 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BOR */
63 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXOR */
64 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHL */
65 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHR */
66 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBIN */
67 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINI*/
68 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINK*/
69 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_UNM */
70 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BNOT */
71 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NOT */
72 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LEN */
73 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_CONCAT */
74 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_CLOSE */
75 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TBC */
76 | ,opmode(0, 0, 0, 0, 0, isJ) /* OP_JMP */
77 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQ */
78 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LT */
79 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LE */
80 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQK */
81 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQI */
82 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LTI */
83 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LEI */
84 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GTI */
85 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GEI */
86 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_TEST */
87 | ,opmode(0, 0, 0, 1, 1, iABC) /* OP_TESTSET */
88 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_CALL */
89 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_TAILCALL */
90 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_RETURN */
91 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN0 */
92 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN1 */
93 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORLOOP */
94 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORPREP */
95 | ,opmode(0, 0, 0, 0, 0, iABx) /* OP_TFORPREP */
96 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TFORCALL */
97 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_TFORLOOP */
98 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_SETLIST */
99 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_CLOSURE */
100 | ,opmode(0, 1, 0, 0, 1, iABC) /* OP_VARARG */
101 | ,opmode(0, 0, 1, 0, 1, iABC) /* OP_VARARGPREP */
102 | ,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */
103 | };
104 |
105 |
--------------------------------------------------------------------------------
/lua/lprefix.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lprefix.h $
3 | ** Definitions for Lua code that must come before any other header file
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lprefix_h
8 | #define lprefix_h
9 |
10 |
11 | /*
12 | ** Allows POSIX/XSI stuff
13 | */
14 | #if !defined(LUA_USE_C89) /* { */
15 |
16 | #if !defined(_XOPEN_SOURCE)
17 | #define _XOPEN_SOURCE 600
18 | #elif _XOPEN_SOURCE == 0
19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */
20 | #endif
21 |
22 | /*
23 | ** Allows manipulation of large files in gcc and some other compilers
24 | */
25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS)
26 | #define _LARGEFILE_SOURCE 1
27 | #define _FILE_OFFSET_BITS 64
28 | #endif
29 |
30 | #endif /* } */
31 |
32 |
33 | /*
34 | ** Windows stuff
35 | */
36 | #if defined(_WIN32) /* { */
37 |
38 | #if !defined(_CRT_SECURE_NO_WARNINGS)
39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */
40 | #endif
41 |
42 | #endif /* } */
43 |
44 | #endif
45 |
46 |
--------------------------------------------------------------------------------
/lua/lstring.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lstring.h $
3 | ** String table (keep all strings handled by Lua)
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lstring_h
8 | #define lstring_h
9 |
10 | #include "lgc.h"
11 | #include "lobject.h"
12 | #include "lstate.h"
13 |
14 |
15 | /*
16 | ** Memory-allocation error message must be preallocated (it cannot
17 | ** be created after memory is exhausted)
18 | */
19 | #define MEMERRMSG "not enough memory"
20 |
21 |
22 | /*
23 | ** Size of a TString: Size of the header plus space for the string
24 | ** itself (including final '\0').
25 | */
26 | #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char))
27 |
28 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
29 | (sizeof(s)/sizeof(char))-1))
30 |
31 |
32 | /*
33 | ** test whether a string is a reserved word
34 | */
35 | #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0)
36 |
37 |
38 | /*
39 | ** equality for short strings, which are always internalized
40 | */
41 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b))
42 |
43 |
44 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
45 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts);
46 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);
47 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
48 | LUAI_FUNC void luaS_clearcache (global_State *g);
49 | LUAI_FUNC void luaS_init (lua_State *L);
50 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts);
51 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue);
52 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
53 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str);
54 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l);
55 |
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/lua/ltable.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ltable.h $
3 | ** Lua tables (hash)
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ltable_h
8 | #define ltable_h
9 |
10 | #include "lobject.h"
11 |
12 |
13 | #define gnode(t,i) (&(t)->node[i])
14 | #define gval(n) (&(n)->i_val)
15 | #define gnext(n) ((n)->u.next)
16 |
17 |
18 | /*
19 | ** Clear all bits of fast-access metamethods, which means that the table
20 | ** may have any of these metamethods. (First access that fails after the
21 | ** clearing will set the bit again.)
22 | */
23 | #define invalidateTMcache(t) ((t)->flags &= ~maskflags)
24 |
25 |
26 | /* true when 't' is using 'dummynode' as its hash part */
27 | #define isdummy(t) ((t)->lastfree == NULL)
28 |
29 |
30 | /* allocated size for hash nodes */
31 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t))
32 |
33 |
34 | /* returns the Node, given the value of a table entry */
35 | #define nodefromval(v) cast(Node *, (v))
36 |
37 |
38 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
39 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
40 | TValue *value);
41 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key);
42 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
43 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key);
44 | LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key,
45 | TValue *value);
46 | LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key,
47 | const TValue *slot, TValue *value);
48 | LUAI_FUNC Table *luaH_new (lua_State *L);
49 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
50 | unsigned int nhsize);
51 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize);
52 | LUAI_FUNC void luaH_free (lua_State *L, Table *t);
53 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key);
54 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t);
55 | LUAI_FUNC unsigned int luaH_realasize (const Table *t);
56 |
57 |
58 | #if defined(LUA_DEBUG)
59 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key);
60 | #endif
61 |
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/lua/ltm.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ltm.h $
3 | ** Tag methods
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ltm_h
8 | #define ltm_h
9 |
10 |
11 | #include "lobject.h"
12 |
13 |
14 | /*
15 | * WARNING: if you change the order of this enumeration,
16 | * grep "ORDER TM" and "ORDER OP"
17 | */
18 | typedef enum {
19 | TM_INDEX,
20 | TM_NEWINDEX,
21 | TM_GC,
22 | TM_MODE,
23 | TM_LEN,
24 | TM_EQ, /* last tag method with fast access */
25 | TM_ADD,
26 | TM_SUB,
27 | TM_MUL,
28 | TM_MOD,
29 | TM_POW,
30 | TM_DIV,
31 | TM_IDIV,
32 | TM_BAND,
33 | TM_BOR,
34 | TM_BXOR,
35 | TM_SHL,
36 | TM_SHR,
37 | TM_UNM,
38 | TM_BNOT,
39 | TM_LT,
40 | TM_LE,
41 | TM_CONCAT,
42 | TM_CALL,
43 | TM_CLOSE,
44 | TM_N /* number of elements in the enum */
45 | } TMS;
46 |
47 |
48 | /*
49 | ** Mask with 1 in all fast-access methods. A 1 in any of these bits
50 | ** in the flag of a (meta)table means the metatable does not have the
51 | ** corresponding metamethod field. (Bit 7 of the flag is used for
52 | ** 'isrealasize'.)
53 | */
54 | #define maskflags (~(~0u << (TM_EQ + 1)))
55 |
56 |
57 | /*
58 | ** Test whether there is no tagmethod.
59 | ** (Because tagmethods use raw accesses, the result may be an "empty" nil.)
60 | */
61 | #define notm(tm) ttisnil(tm)
62 |
63 |
64 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \
65 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e]))
66 |
67 | #define fasttm(l,et,e) gfasttm(G(l), et, e)
68 |
69 | #define ttypename(x) luaT_typenames_[(x) + 1]
70 |
71 | LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];)
72 |
73 |
74 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);
75 |
76 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);
77 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o,
78 | TMS event);
79 | LUAI_FUNC void luaT_init (lua_State *L);
80 |
81 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
82 | const TValue *p2, const TValue *p3);
83 | LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f,
84 | const TValue *p1, const TValue *p2, StkId p3);
85 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
86 | StkId res, TMS event);
87 | LUAI_FUNC void luaT_tryconcatTM (lua_State *L);
88 | LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1,
89 | const TValue *p2, int inv, StkId res, TMS event);
90 | LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2,
91 | int inv, StkId res, TMS event);
92 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,
93 | const TValue *p2, TMS event);
94 | LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,
95 | int inv, int isfloat, TMS event);
96 |
97 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams,
98 | struct CallInfo *ci, const Proto *p);
99 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci,
100 | StkId where, int wanted);
101 |
102 |
103 | #endif
104 |
--------------------------------------------------------------------------------
/lua/lualib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lualib.h $
3 | ** Lua standard libraries
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #ifndef lualib_h
9 | #define lualib_h
10 |
11 | #include "lua.h"
12 |
13 | #ifdef __cplusplus
14 | extern "C" {
15 | #endif
16 |
17 |
18 | /* version suffix for environment variable names */
19 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
20 |
21 |
22 | LUAMOD_API int (luaopen_base) (lua_State *L);
23 |
24 | #define LUA_COLIBNAME "coroutine"
25 | LUAMOD_API int (luaopen_coroutine) (lua_State *L);
26 |
27 | #define LUA_TABLIBNAME "table"
28 | LUAMOD_API int (luaopen_table) (lua_State *L);
29 |
30 | #define LUA_IOLIBNAME "io"
31 | LUAMOD_API int (luaopen_io) (lua_State *L);
32 |
33 | #define LUA_OSLIBNAME "os"
34 | LUAMOD_API int (luaopen_os) (lua_State *L);
35 |
36 | #define LUA_STRLIBNAME "string"
37 | LUAMOD_API int (luaopen_string) (lua_State *L);
38 |
39 | #define LUA_UTF8LIBNAME "utf8"
40 | LUAMOD_API int (luaopen_utf8) (lua_State *L);
41 |
42 | #define LUA_MATHLIBNAME "math"
43 | LUAMOD_API int (luaopen_math) (lua_State *L);
44 |
45 | #define LUA_DBLIBNAME "debug"
46 | LUAMOD_API int (luaopen_debug) (lua_State *L);
47 |
48 | #define LUA_LOADLIBNAME "package"
49 | LUAMOD_API int (luaopen_package) (lua_State *L);
50 |
51 |
52 | /* open all previous libraries */
53 | LUALIB_API void (luaL_openlibs) (lua_State *L);
54 |
55 | #ifdef __cplusplus
56 | }
57 | #endif
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/lua/lundump.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lundump.h $
3 | ** load precompiled Lua chunks
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lundump_h
8 | #define lundump_h
9 |
10 | #include "llimits.h"
11 | #include "lobject.h"
12 | #include "lzio.h"
13 |
14 |
15 | /* data to catch conversion errors */
16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n"
17 |
18 | #define LUAC_INT 0x5678
19 | #define LUAC_NUM cast_num(370.5)
20 |
21 | /*
22 | ** Encode major-minor version in one byte, one nibble for each
23 | */
24 | #define LUAC_VERSION (((LUA_VERSION_NUM / 100) * 16) + LUA_VERSION_NUM % 100)
25 |
26 | #define LUAC_FORMAT 0 /* this is the official format */
27 |
28 | /* load one chunk; from lundump.c */
29 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);
30 |
31 | /* dump one chunk; from ldump.c */
32 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w,
33 | void* data, int strip);
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/lua/lvm.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lvm.h $
3 | ** Lua virtual machine
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef lvm_h
8 | #define lvm_h
9 |
10 |
11 | #include "ldo.h"
12 | #include "lobject.h"
13 | #include "ltm.h"
14 |
15 |
16 | #if !defined(LUA_NOCVTN2S)
17 | #define cvt2str(o) ttisnumber(o)
18 | #else
19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */
20 | #endif
21 |
22 |
23 | #if !defined(LUA_NOCVTS2N)
24 | #define cvt2num(o) ttisstring(o)
25 | #else
26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */
27 | #endif
28 |
29 |
30 | /*
31 | ** You can define LUA_FLOORN2I if you want to convert floats to integers
32 | ** by flooring them (instead of raising an error if they are not
33 | ** integral values)
34 | */
35 | #if !defined(LUA_FLOORN2I)
36 | #define LUA_FLOORN2I F2Ieq
37 | #endif
38 |
39 |
40 | /*
41 | ** Rounding modes for float->integer coercion
42 | */
43 | typedef enum {
44 | F2Ieq, /* no rounding; accepts only integral values */
45 | F2Ifloor, /* takes the floor of the number */
46 | F2Iceil /* takes the ceil of the number */
47 | } F2Imod;
48 |
49 |
50 | /* convert an object to a float (including string coercion) */
51 | #define tonumber(o,n) \
52 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
53 |
54 |
55 | /* convert an object to a float (without string coercion) */
56 | #define tonumberns(o,n) \
57 | (ttisfloat(o) ? ((n) = fltvalue(o), 1) : \
58 | (ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))
59 |
60 |
61 | /* convert an object to an integer (including string coercion) */
62 | #define tointeger(o,i) \
63 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
64 | : luaV_tointeger(o,i,LUA_FLOORN2I))
65 |
66 |
67 | /* convert an object to an integer (without string coercion) */
68 | #define tointegerns(o,i) \
69 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
70 | : luaV_tointegerns(o,i,LUA_FLOORN2I))
71 |
72 |
73 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))
74 |
75 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)
76 |
77 |
78 | /*
79 | ** fast track for 'gettable': if 't' is a table and 't[k]' is present,
80 | ** return 1 with 'slot' pointing to 't[k]' (position of final result).
81 | ** Otherwise, return 0 (meaning it will have to check metamethod)
82 | ** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL
83 | ** (otherwise). 'f' is the raw get function to use.
84 | */
85 | #define luaV_fastget(L,t,k,slot,f) \
86 | (!ttistable(t) \
87 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
88 | : (slot = f(hvalue(t), k), /* else, do raw access */ \
89 | !isempty(slot))) /* result not empty? */
90 |
91 |
92 | /*
93 | ** Special case of 'luaV_fastget' for integers, inlining the fast case
94 | ** of 'luaH_getint'.
95 | */
96 | #define luaV_fastgeti(L,t,k,slot) \
97 | (!ttistable(t) \
98 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
99 | : (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \
100 | ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \
101 | !isempty(slot))) /* result not empty? */
102 |
103 |
104 | /*
105 | ** Finish a fast set operation (when fast get succeeds). In that case,
106 | ** 'slot' points to the place to put the value.
107 | */
108 | #define luaV_finishfastset(L,t,slot,v) \
109 | { setobj2t(L, cast(TValue *,slot), v); \
110 | luaC_barrierback(L, gcvalue(t), v); }
111 |
112 |
113 | /*
114 | ** Shift right is the same as shift left with a negative 'y'
115 | */
116 | #define luaV_shiftr(x,y) luaV_shiftl(x,intop(-, 0, y))
117 |
118 |
119 |
120 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);
121 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
122 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);
123 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);
124 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode);
125 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p,
126 | F2Imod mode);
127 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode);
128 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,
129 | StkId val, const TValue *slot);
130 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
131 | TValue *val, const TValue *slot);
132 | LUAI_FUNC void luaV_finishOp (lua_State *L);
133 | LUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci);
134 | LUAI_FUNC void luaV_concat (lua_State *L, int total);
135 | LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y);
136 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);
137 | LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y);
138 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);
139 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);
140 |
141 | #endif
142 |
--------------------------------------------------------------------------------
/lua/lzio.c:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lzio.c $
3 | ** Buffered streams
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #define lzio_c
8 | #define LUA_CORE
9 |
10 | #include "lprefix.h"
11 |
12 |
13 | #include
14 |
15 | #include "lua.h"
16 |
17 | #include "llimits.h"
18 | #include "lmem.h"
19 | #include "lstate.h"
20 | #include "lzio.h"
21 |
22 |
23 | int luaZ_fill (ZIO *z) {
24 | size_t size;
25 | lua_State *L = z->L;
26 | const char *buff;
27 | lua_unlock(L);
28 | buff = z->reader(L, z->data, &size);
29 | lua_lock(L);
30 | if (buff == NULL || size == 0)
31 | return EOZ;
32 | z->n = size - 1; /* discount char being returned */
33 | z->p = buff;
34 | return cast_uchar(*(z->p++));
35 | }
36 |
37 |
38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
39 | z->L = L;
40 | z->reader = reader;
41 | z->data = data;
42 | z->n = 0;
43 | z->p = NULL;
44 | }
45 |
46 |
47 | /* --------------------------------------------------------------- read --- */
48 | size_t luaZ_read (ZIO *z, void *b, size_t n) {
49 | while (n) {
50 | size_t m;
51 | if (z->n == 0) { /* no bytes in buffer? */
52 | if (luaZ_fill(z) == EOZ) /* try to read more */
53 | return n; /* no more input; return number of missing bytes */
54 | else {
55 | z->n++; /* luaZ_fill consumed first byte; put it back */
56 | z->p--;
57 | }
58 | }
59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
60 | memcpy(b, z->p, m);
61 | z->n -= m;
62 | z->p += m;
63 | b = (char *)b + m;
64 | n -= m;
65 | }
66 | return 0;
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/lua/lzio.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lzio.h $
3 | ** Buffered streams
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #ifndef lzio_h
9 | #define lzio_h
10 |
11 | #include "lua.h"
12 |
13 | #include "lmem.h"
14 |
15 |
16 | #define EOZ (-1) /* end of stream */
17 |
18 | typedef struct Zio ZIO;
19 |
20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
21 |
22 |
23 | typedef struct Mbuffer {
24 | char *buffer;
25 | size_t n;
26 | size_t buffsize;
27 | } Mbuffer;
28 |
29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
30 |
31 | #define luaZ_buffer(buff) ((buff)->buffer)
32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize)
33 | #define luaZ_bufflen(buff) ((buff)->n)
34 |
35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i))
36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0)
37 |
38 |
39 | #define luaZ_resizebuffer(L, buff, size) \
40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \
41 | (buff)->buffsize, size), \
42 | (buff)->buffsize = size)
43 |
44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
45 |
46 |
47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
48 | void *data);
49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */
50 |
51 |
52 |
53 | /* --------- Private Part ------------------ */
54 |
55 | struct Zio {
56 | size_t n; /* bytes still unread */
57 | const char *p; /* current position in buffer */
58 | lua_Reader reader; /* reader function */
59 | void *data; /* additional data */
60 | lua_State *L; /* Lua state (for reader) */
61 | };
62 |
63 |
64 | LUAI_FUNC int luaZ_fill (ZIO *z);
65 |
66 | #endif
67 |
--------------------------------------------------------------------------------
/release_notes.txt:
--------------------------------------------------------------------------------
1 |
2 | release 01.01, 2024-09-05
3 | - migrated to Lua 5.4.7
4 |
5 | release 01.00, 2018-01-22
6 | - initial release
--------------------------------------------------------------------------------