diff --git a/Makefile b/Makefile index 764ee281d..5b8dd5252 100644 --- a/Makefile +++ b/Makefile @@ -41,25 +41,29 @@ # dwarf4=1 - use DWARF v4 format for debug information # -export TARGET_MODES = debug debug_release release +export TARGET_DEBUG_MODES = debug debug_release +export TARGET_RELEASE_MODES = release export TARGET_PC_SYSTEMS = linux -export TARGET_MCU_SYSTEMS = $(addprefix stm32f,4) # now only stm32f4 is supported, to add, for example, to stm32f3, change to $(addprefix stm32f,3 4) +export TARGET_MCU_SYSTEMS = $(addprefix stm32f,3 4) export TARGET_PC_MODS = musl sanitize valgrind \ musl-valgrind export TARGET_MCU_MODS = -export TARGET_SYSTEMS = $(TARGET_PC_SYSTEMS) \ - $(TARGET_MCU_SYSTEMS) \ - $(foreach __MOD,$(TARGET_PC_MODS),$(foreach __SYSTEM,$(TARGET_PC_SYSTEMS),$(__SYSTEM)-$(__MOD))) \ - $(foreach __MOD,$(TARGET_MCU_MODS),$(foreach __SYSTEM,$(TARGET_MCU_SYSTEMS),$(__SYSTEM)-$(__MOD))) +export TARGET_PC_SYSTEMS_MODS = $(TARGET_PC_SYSTEMS) \ + $(foreach __MOD,$(TARGET_PC_MODS),$(foreach __SYSTEM,$(TARGET_PC_SYSTEMS),$(__SYSTEM)-$(__MOD))) +export TARGET_MCU_SYSTEMS_MODS = $(TARGET_MCU_SYSTEMS) \ + $(foreach __MOD,$(TARGET_MCU_MODS),$(foreach __SYSTEM,$(TARGET_MCU_SYSTEMS),$(__SYSTEM)-$(__MOD))) # Target list -export JERRY_TARGETS = $(foreach __MODE,$(TARGET_MODES),$(foreach __SYSTEM,$(TARGET_SYSTEMS),$(__MODE).$(__SYSTEM))) +export JERRY_TARGETS = $(foreach __MODE,$(TARGET_DEBUG_MODES),$(foreach __SYSTEM,$(TARGET_PC_SYSTEMS_MODS),$(__MODE).$(__SYSTEM))) \ + $(foreach __MODE,$(TARGET_RELEASE_MODES),$(foreach __SYSTEM,$(TARGET_PC_SYSTEMS_MODS),$(__MODE).$(__SYSTEM))) \ + $(foreach __MODE,$(TARGET_RELEASE_MODES),$(foreach __SYSTEM,$(TARGET_MCU_SYSTEMS_MODS),$(__MODE).$(__SYSTEM))) + export TESTS_TARGET = unittests export CHECK_TARGETS = $(foreach __TARGET,$(JERRY_TARGETS),$(__TARGET).check) -export FLASH_TARGETS = $(foreach __TARGET,$(foreach __MODE,$(TARGET_MODES),$(foreach __SYSTEM,$(TARGET_MCU_SYSTEMS),$(__MODE).$(__SYSTEM))),$(__TARGET).flash) +export FLASH_TARGETS = $(foreach __TARGET,$(foreach __MODE,$(TARGET_RELEASE_MODES),$(foreach __SYSTEM,$(TARGET_MCU_SYSTEMS_MODS),$(__MODE).$(__SYSTEM))),$(__TARGET).flash) export OUT_DIR = ./out export UNITTESTS_SRC_DIR = ./tests/unit diff --git a/Makefile.mk b/Makefile.mk index 371f0d473..38e1ce556 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -16,6 +16,7 @@ STRIP = strip MAIN_MODULE_SRC = ./src/main.c +LNK_SCRIPT_STM32F3 = ./third-party/stm32f3.ld LNK_SCRIPT_STM32F4 = ./third-party/stm32f4.ld # Parsing target @@ -234,11 +235,6 @@ ifeq ($(TARGET_CPU),cortexm4) CFLAGS_COMMON += $(CFLAGS_CORTEXM4) endif -# System-specific common -ifeq ($(TARGET_SYSTEM),stm32f4) - LDFLAGS += -nostartfiles -T$(LNK_SCRIPT_STM32F4) -endif - ifeq ($(OPTION_MCU),enable) CC := $(CROSS_COMPILE)$(CC) LD := $(CROSS_COMPILE)$(LD) @@ -345,6 +341,7 @@ ifeq ($(OPTION_MCU),disable) else CFLAGS_COMMON += -ffunction-sections -fdata-sections -nostdlib DEFINES_JERRY += -D__TARGET_MCU + LDFLAGS += -Wl,--gc-sections endif ifeq ($(OPTION_COLOR),enable) @@ -377,6 +374,8 @@ INCLUDES_THIRDPARTY = -I third-party/valgrind/ CFLAGS_THIRDPARTY = ifeq ($(TARGET_SYSTEM),stm32f4) + DEFINES_JERRY += -D__TARGET_MCU_STM32F4 + LDFLAGS += -nostartfiles -T$(LNK_SCRIPT_STM32F4) SOURCES_THIRDPARTY += \ ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c \ ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s \ @@ -389,9 +388,23 @@ ifeq ($(TARGET_SYSTEM),stm32f4) -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/inc \ -I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include \ -I third-party/STM32F4-Discovery_FW_V1.1.0/ +else + ifeq ($(TARGET_SYSTEM),stm32f3) + DEFINES_JERRY += -D__TARGET_MCU_STM32F3 + LDFLAGS += -nostartfiles -T$(LNK_SCRIPT_STM32F3) + SOURCES_THIRDPARTY += \ + ./third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Device/ST/STM32F30x/Source/Templates/system_stm32f30x.c \ + ./third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Device/ST/STM32F30x/Source/Templates/gcc_ride7/startup_stm32f30x.s \ + ./third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/STM32F30x_StdPeriph_Driver/src/stm32f30x_tim.c \ + ./third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/STM32F30x_StdPeriph_Driver/src/stm32f30x_gpio.c \ + ./third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/STM32F30x_StdPeriph_Driver/src/stm32f30x_rcc.c -#-I third-party/STM32F4-Discovery_FW_V1.1.0/Project/Demonstration \ - + INCLUDES_THIRDPARTY += \ + -I ./third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Device/ST/STM32F30x/Include/ \ + -I ./third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/STM32F30x_StdPeriph_Driver/inc \ + -I ./third-party/STM32F3-Discovery_FW_V1.1.0/Libraries/CMSIS/Include/ \ + -I ./third-party/STM32F3-Discovery_FW_V1.1.0 + endif endif # Unit tests diff --git a/demo-applications/loop_demo.js b/demo-applications/loop_demo.js index 162de8f0e..189f93198 100644 --- a/demo-applications/loop_demo.js +++ b/demo-applications/loop_demo.js @@ -12,6 +12,25 @@ // See the License for the specific language governing permissions and // limitations under the License. +var led_green = 0; +var led_orange = 1; +var led_red = 2; +var led_blue = 3; + +function LEDSet(led_group, on) +{ + if (on) + { + LEDOn (led_group); + LEDOn (led_group + 4); + } + else + { + LEDOff (led_group); + LEDOff (led_group + 4); + } +} + var tmp, a, b = 1, c = 2, d, e = 3, g = 4; var count = 1000; @@ -27,99 +46,99 @@ while (1) { for (var j = 0; j < numOfIterations; j += 1) { - LEDOn(12); - LEDOn(13); - LEDOn(14); - LEDOn(15); + LEDSet(led_green, true); + LEDSet(led_orange, true); + LEDSet(led_red, true); + LEDSet(led_blue, true); wait(waitTime * 2); - LEDOff(12); - LEDOff(13); - LEDOff(14); - LEDOff(15); + LEDSet(led_green, false); + LEDSet(led_orange, false); + LEDSet(led_red, false); + LEDSet(led_blue, false); wait(waitTime * 2); } for (var j = 0; j < numOfIterations; j += 1) { - LEDOn(12); + LEDSet(led_green, true); wait(waitTime); - LEDOff(12); + LEDSet(led_green, false); wait(waitTime); - LEDOn(13); + LEDSet(led_orange, true); wait(waitTime); - LEDOff(13); + LEDSet(led_orange, false); wait(waitTime); - LEDOn(14); + LEDSet(led_red, true); wait(waitTime); - LEDOff(14); + LEDSet(led_red, false); wait(waitTime); - LEDOn(15); + LEDSet(led_blue, true); wait(waitTime); - LEDOff(15); + LEDSet(led_blue, false); wait(waitTime); } for (var j = 0; j < numOfIterations; j += 1) { - LEDOn(12); + LEDSet(led_green, true); wait(waitTime); - LEDOff(12); - LEDOn(13); + LEDSet(led_green, false); + LEDSet(led_orange, true); wait(waitTime); - LEDOff(13); - LEDOn(14); + LEDSet(led_orange, false); + LEDSet(led_red, true); wait(waitTime); - LEDOff(14); - LEDOn(15); + LEDSet(led_red, false); + LEDSet(led_blue, true); wait(waitTime); - LEDOff(15); + LEDSet(led_blue, false); } for (var j = 0; j < numOfIterations; j += 1) { - LEDOn(12); + LEDSet(led_green, true); wait(waitTime / 2); - LEDOff(12); - LEDOn(13); + LEDSet(led_green, false); + LEDSet(led_orange, true); wait(waitTime / 2); - LEDOff(13); - LEDOn(14); + LEDSet(led_orange, false); + LEDSet(led_red, true); wait(waitTime / 2); - LEDOff(14); - LEDOn(15); + LEDSet(led_red, false); + LEDSet(led_blue, true); wait(waitTime / 2); - LEDOff(15); + LEDSet(led_blue, false); } for (var j = 0; j < numOfIterations; j += 1) { - LEDOn(12); + LEDSet(led_green, true); wait(waitTime / 3); - LEDOff(12); - LEDOn(13); + LEDSet(led_green, false); + LEDSet(led_orange, true); wait(waitTime / 3); - LEDOff(13); - LEDOn(14); + LEDSet(led_orange, false); + LEDSet(led_red, true); wait(waitTime / 3); - LEDOff(14); - LEDOn(15); + LEDSet(led_red, false); + LEDSet(led_blue, true); wait(waitTime / 3); - LEDOff(15); + LEDSet(led_blue, false); } for (var j = 0; j < numOfIterations; j += 1) { - LEDOn(12); + LEDSet(led_green, true); wait(waitTime / 6); - LEDOff(12); - LEDOn(13); + LEDSet(led_green, false); + LEDSet(led_orange, true); wait(waitTime / 6); - LEDOff(13); - LEDOn(14); + LEDSet(led_orange, false); + LEDSet(led_red, true); wait(waitTime / 6); - LEDOff(14); - LEDOn(15); + LEDSet(led_red, false); + LEDSet(led_blue, true); wait(waitTime / 6); - LEDOff(15); + LEDSet(led_blue, false); } } diff --git a/src/config.h b/src/config.h index 111d91597..42ee08218 100644 --- a/src/config.h +++ b/src/config.h @@ -55,7 +55,13 @@ /** * Size of heap */ -#define CONFIG_MEM_HEAP_AREA_SIZE (64 * 1024) +#ifdef __TARGET_HOST +# define CONFIG_MEM_HEAP_AREA_SIZE (64 * 1024) +#elif defined (__TARGET_MCU) +# define CONFIG_MEM_HEAP_AREA_SIZE (8 * 1024) +#else /* !__TARGET_HOST && !__TARGET_MCU */ +# error "!__TARGET_HOST && !__TARGET_MCU" +#endif /* !__TARGET_HOST && !__TARGET_MCU */ /** * Log2 of maximum possible offset in the heap diff --git a/src/generated.h b/src/generated.h index 1cd66087c..1f37c709e 100644 --- a/src/generated.h +++ b/src/generated.h @@ -17,6 +17,235 @@ static char generated_source [] = { + 'v', + 'a', + 'r', + ' ', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ' ', + '=', + ' ', + '0', + ';', + 'v', + 'a', + 'r', + ' ', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ' ', + '=', + ' ', + '1', + ';', + 'v', + 'a', + 'r', + ' ', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ' ', + '=', + ' ', + '2', + ';', + 'v', + 'a', + 'r', + ' ', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ' ', + '=', + ' ', + '3', + ';', + ' ', + 'f', + 'u', + 'n', + 'c', + 't', + 'i', + 'o', + 'n', + ' ', + 'L', + 'E', + 'D', + 'S', + 'e', + 't', + '(', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'o', + 'u', + 'p', + ',', + ' ', + 'o', + 'n', + ')', + '{', + ' ', + ' ', + 'i', + 'f', + ' ', + '(', + 'o', + 'n', + ')', + ' ', + ' ', + '{', + ' ', + ' ', + ' ', + ' ', + 'L', + 'E', + 'D', + 'O', + 'n', + ' ', + '(', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'o', + 'u', + 'p', + ')', + ';', + ' ', + ' ', + ' ', + ' ', + 'L', + 'E', + 'D', + 'O', + 'n', + ' ', + '(', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'o', + 'u', + 'p', + ' ', + '+', + ' ', + '4', + ')', + ';', + ' ', + ' ', + '}', + ' ', + ' ', + 'e', + 'l', + 's', + 'e', + ' ', + ' ', + '{', + ' ', + ' ', + ' ', + ' ', + 'L', + 'E', + 'D', + 'O', + 'f', + 'f', + ' ', + '(', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'o', + 'u', + 'p', + ')', + ';', + ' ', + ' ', + ' ', + ' ', + 'L', + 'E', + 'D', + 'O', + 'f', + 'f', + ' ', + '(', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'o', + 'u', + 'p', + ' ', + '+', + ' ', + '4', + ')', + ';', + ' ', + ' ', + '}', + '}', + ' ', 'v', 'a', 'r', @@ -229,11 +458,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -243,11 +486,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -257,11 +515,23 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -271,11 +541,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -308,12 +591,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -323,12 +620,27 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -338,12 +650,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -353,12 +677,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -444,11 +781,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', + 'S', + 'e', + 't', + '(', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', 'n', - '(', - '1', - '2', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -477,45 +828,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', - '(', - '1', - '2', - ')', - ';', - ' ', - ' ', - ' ', - ' ', - 'w', - 'a', - 'i', - 't', - '(', - 'w', - 'a', - 'i', - 't', - 'T', - 'i', - 'm', + 'S', + 'e', + 't', + '(', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', 'e', - ')', - ';', - ' ', - ' ', - ' ', - ' ', - 'L', - 'E', - 'D', - 'O', 'n', - '(', - '1', - '3', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -544,45 +876,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', - '(', - '1', - '3', - ')', - ';', - ' ', - ' ', - ' ', - ' ', - 'w', - 'a', - 'i', - 't', - '(', - 'w', - 'a', - 'i', - 't', - 'T', - 'i', - 'm', + 'S', 'e', - ')', - ';', - ' ', - ' ', - ' ', - ' ', - 'L', - 'E', - 'D', - 'O', + 't', + '(', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', 'n', - '(', - '1', - '4', + 'g', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -611,45 +924,27 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', - '(', - '1', - '4', - ')', - ';', - ' ', - ' ', - ' ', - ' ', - 'w', - 'a', - 'i', - 't', - '(', - 'w', - 'a', - 'i', - 't', - 'T', - 'i', - 'm', + 'S', 'e', - ')', - ';', - ' ', - ' ', - ' ', - ' ', - 'L', - 'E', - 'D', - 'O', + 't', + '(', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', 'n', - '(', - '1', - '5', + 'g', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -678,12 +973,162 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 't', + 'r', + 'u', + 'e', + ')', + ';', + ' ', + ' ', + ' ', + ' ', + 'w', + 'a', + 'i', + 't', + '(', + 'w', + 'a', + 'i', + 't', + 'T', + 'i', + 'm', + 'e', + ')', + ';', + ' ', + ' ', + ' ', + ' ', + 'L', + 'E', + 'D', + 'S', + 'e', + 't', + '(', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', + ')', + ';', + ' ', + ' ', + ' ', + ' ', + 'w', + 'a', + 'i', + 't', + '(', + 'w', + 'a', + 'i', + 't', + 'T', + 'i', + 'm', + 'e', + ')', + ';', + ' ', + ' ', + ' ', + ' ', + 'L', + 'E', + 'D', + 'S', + 'e', + 't', + '(', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', + ')', + ';', + ' ', + ' ', + ' ', + ' ', + 'w', + 'a', + 'i', + 't', + '(', + 'w', + 'a', + 'i', + 't', + 'T', + 'i', + 'm', + 'e', + ')', + ';', + ' ', + ' ', + ' ', + ' ', + 'L', + 'E', + 'D', + 'S', + 'e', + 't', + '(', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -765,11 +1210,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -798,12 +1257,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -813,11 +1286,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -846,12 +1334,27 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -861,11 +1364,23 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -894,12 +1409,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -909,11 +1436,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -942,12 +1482,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1010,11 +1563,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1047,12 +1614,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1062,11 +1643,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1099,12 +1695,27 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1114,11 +1725,23 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1151,12 +1774,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1166,11 +1801,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1203,12 +1851,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1271,11 +1932,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1308,12 +1983,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1323,11 +2012,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1360,12 +2064,27 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1375,11 +2094,23 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1412,12 +2143,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1427,11 +2170,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1464,12 +2220,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1532,11 +2301,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1569,12 +2352,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '2', + 'l', + 'e', + 'd', + '_', + 'g', + 'r', + 'e', + 'e', + 'n', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1584,11 +2381,26 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1621,12 +2433,27 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '3', + 'l', + 'e', + 'd', + '_', + 'o', + 'r', + 'a', + 'n', + 'g', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1636,11 +2463,23 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1673,12 +2512,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '4', + 'l', + 'e', + 'd', + '_', + 'r', + 'e', + 'd', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', @@ -1688,11 +2539,24 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'n', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 't', + 'r', + 'u', + 'e', ')', ';', ' ', @@ -1725,12 +2589,25 @@ static char generated_source [] = 'L', 'E', 'D', - 'O', - 'f', - 'f', + 'S', + 'e', + 't', '(', - '1', - '5', + 'l', + 'e', + 'd', + '_', + 'b', + 'l', + 'u', + 'e', + ',', + ' ', + 'f', + 'a', + 'l', + 's', + 'e', ')', ';', ' ', diff --git a/src/globals.h b/src/globals.h index ce2dc2f8f..49a6266de 100644 --- a/src/globals.h +++ b/src/globals.h @@ -116,7 +116,7 @@ extern void __noreturn jerry_unimplemented (const char *comment, const char *fil * Mark for unreachable points and unimplemented cases */ extern void jerry_ref_unused_variables (int unused_variables_follow, ...); -#ifndef JERRY_NDEBUG +#if !defined (JERRY_NDEBUG) && defined (__TARGET_HOST) #define JERRY_UNREACHABLE() \ do \ { \ @@ -138,7 +138,7 @@ extern void jerry_ref_unused_variables (int unused_variables_follow, ...); jerry_ref_unused_variables (0, __VA_ARGS__); \ } \ } while (0) -#else /* !JERRY_NDEBUG */ +#else /* !JERRY_NDEBUG && __TARGET_HOST */ #define JERRY_UNREACHABLE() \ do \ { \ @@ -160,7 +160,7 @@ extern void jerry_ref_unused_variables (int unused_variables_follow, ...); jerry_ref_unused_variables (0, __VA_ARGS__); \ } \ } while (0) -#endif /* JERRY_NDEBUG */ +#endif /* JERRY_NDEBUG || !TARGET_HOST */ /** * Conditions' likeliness, unlikeliness. */ diff --git a/src/libperipherals/actuators.c b/src/libperipherals/actuators.c index 648dbc95a..0317394f6 100644 --- a/src/libperipherals/actuators.c +++ b/src/libperipherals/actuators.c @@ -13,88 +13,218 @@ * limitations under the License. */ -#ifdef __TARGET_MCU -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#include "stm32f4xx_conf.h" -#include "stm32f4xx.h" -#pragma GCC diagnostic pop -#endif - #include "actuators.h" #include "common-io.h" #include "jerry-libc.h" -void -led_toggle (uint32_t led_id) -{ #ifdef __TARGET_HOST +/** + * Host stub for LEDToggle operation + */ +void +led_toggle (uint32_t led_id) /**< index of LED */ +{ __printf ("led_toggle: %d\n", led_id); -#endif - - -#ifdef __TARGET_MCU - GPIOD->ODR ^= (uint16_t) (1 << led_id); -#endif } +/** + * Host stub for LEDOn operation + */ void -led_on (uint32_t led_id) +led_on (uint32_t led_id) /**< index of LED */ { -#ifdef __TARGET_HOST __printf ("led_on: %d\n", led_id); -#endif - - -#ifdef __TARGET_MCU - GPIO_WriteBit (GPIOD, (uint16_t) (1 << led_id), Bit_SET); -#endif } +/** + * Host stub for LEDOff operation + */ void -led_off (uint32_t led_id) +led_off (uint32_t led_id) /**< index of LED */ { -#ifdef __TARGET_HOST __printf ("led_off: %d\n", led_id); -#endif - -#ifdef __TARGET_MCU - GPIO_WriteBit (GPIOD, (uint16_t) (1 << led_id), Bit_RESET); -#endif } +/** + * Host stub for LEDOnce operation + */ void -led_blink_once (uint32_t led_id) +led_blink_once (uint32_t led_id) /**< index of LED */ { -#ifdef __TARGET_HOST __printf ("led_blink_once: %d\n", led_id); -#endif - -#ifdef __TARGET_MCU - uint32_t dot = 300000; - - GPIOD->BSRRL = (uint16_t) (1 << led_id); - wait_ms (dot); - GPIOD->BSRRH = (uint16_t) (1 << led_id); -#endif } +#else /* !__TARGET_HOST */ +#ifndef __TARGET_MCU +# error "!__TARGET_HOST && !__TARGET_MCU" +#endif /* !__TARGET_MCU */ -#ifdef __TARGET_MCU +#include "mcu-headers.h" -void -initialize_leds () +#ifdef __TARGET_MCU_STM32F4 +/** + * Number of LEDs on the board + */ +#define LED_NUMBER 4 + +/** + * LEDs' GPIO pins + */ +static const uint16_t led_pins [LED_NUMBER] = { + GPIO_Pin_12, /* LD4: Green */ + GPIO_Pin_13, /* LD3: Orange */ + GPIO_Pin_14, /* LD5: Red */ + GPIO_Pin_15 /* LD6: Blue */ +}; + +/** + * LEDs' GPIO ports + */ +static GPIO_TypeDef* leds_port = GPIOD; + +/** + * Initialize LEDs on the board + */ +void +initialize_leds (void) +{ + GPIO_InitTypeDef gpio_init_structure; + RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOD, ENABLE); - GPIO_InitTypeDef gpioStructure; - gpioStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; - gpioStructure.GPIO_Mode = GPIO_Mode_OUT; - gpioStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_Init (GPIOD, &gpioStructure); + uint16_t led_pins_mask = 0; + for (uint32_t led_index = 0; + led_index < LED_NUMBER; + led_index++) + { + led_pins_mask |= led_pins[led_index]; + } - GPIO_WriteBit (GPIOD, - GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15, - Bit_RESET); -} -#endif + gpio_init_structure.GPIO_Pin = led_pins_mask; + gpio_init_structure.GPIO_Mode = GPIO_Mode_OUT; + gpio_init_structure.GPIO_Speed = GPIO_Speed_100MHz; + GPIO_Init (leds_port, &gpio_init_structure); + + for (uint32_t led_index = 0; + led_index < LED_NUMBER; + led_index++) + { + led_off (led_index); + } +} /* initialize_leds */ + +#else /* !__TARGET_MCU_STM32F4 */ + +# ifndef __TARGET_MCU_STM32F3 +# error "!__TARGET_MCU_STM32F4 && !__TARGET_MCU_STM32F3" +# endif /* !__TARGET_MCU_STM32F3 */ + +/** + * Number of LEDs on the board + */ +#define LED_NUMBER 8 + +/** + * LEDs' GPIO pins + */ +static const uint16_t led_pins [LED_NUMBER] = +{ + GPIO_Pin_15, /* LD6 - Green */ + GPIO_Pin_14, /* LD8 - Orange */ + GPIO_Pin_13, /* LD10 - Red */ + GPIO_Pin_12, /* LD9 - Blue */ + GPIO_Pin_11, /* LD7 - Green */ + GPIO_Pin_10, /* LD5 - Orange */ + GPIO_Pin_9, /* LD3 - Red */ + GPIO_Pin_8 /* LD4 - Blue */ +}; + +/** + * LEDs' GPIO ports + */ +static GPIO_TypeDef* leds_port = GPIOE; + +/** + * Initialize LEDs on the board + */ +void +initialize_leds (void) +{ + GPIO_InitTypeDef gpio_init_structure; + + RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOE, ENABLE); + + uint16_t led_pins_mask = 0; + for (uint32_t led_index = 0; + led_index < LED_NUMBER; + led_index++) + { + led_pins_mask |= led_pins[led_index]; + } + + gpio_init_structure.GPIO_Pin = led_pins_mask; + gpio_init_structure.GPIO_Mode = GPIO_Mode_OUT; + gpio_init_structure.GPIO_OType = GPIO_OType_PP; + gpio_init_structure.GPIO_PuPd = GPIO_PuPd_UP; + gpio_init_structure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init (leds_port, &gpio_init_structure); + + for (uint32_t led_index = 0; + led_index < LED_NUMBER; + led_index++) + { + led_off (led_index); + } +} /* initialize_leds */ +#endif /* !__TARGET_MCU_STM32F4 && __TARGET_MCU_STM32F3 */ + +/** + * Toggle specified LED + */ +void +led_toggle (uint32_t led_id) /**< index of LED */ +{ + if (led_id < LED_NUMBER) + { + leds_port->ODR ^= led_pins [led_id]; + } +} /* led_toggle */ + +/** + * Turn specified LED on + */ +void +led_on (uint32_t led_id) /**< index of LED */ +{ + if (led_id < LED_NUMBER) + { + GPIO_WriteBit (leds_port, led_pins[led_id], Bit_SET); + } +} /* led_on */ + +/** + * Turn specified LED off + */ +void +led_off (uint32_t led_id) /**< index of LED */ +{ + if (led_id < LED_NUMBER) + { + GPIO_WriteBit (leds_port, led_pins[led_id], Bit_RESET); + } +} /* led_off */ + +/** + * Blink once with specified LED + */ +void +led_blink_once (uint32_t led_id) /**< index of LED */ +{ + uint32_t dot = 300; + + led_on (led_id); + wait_ms (dot); + led_off (led_id); +} /* led_blink_once */ + +#endif /* !__TARGET_HOST && __TARGET_MCU */ diff --git a/src/libperipherals/common-io.c b/src/libperipherals/common-io.c index 64652c9ff..f11f6910c 100644 --- a/src/libperipherals/common-io.c +++ b/src/libperipherals/common-io.c @@ -13,23 +13,11 @@ * limitations under the License. */ +#include "actuators.h" #include "common-io.h" #include "jerry-libc.h" -#ifdef __TARGET_MCU -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#include "stm32f4xx_conf.h" -#include "stm32f4xx.h" -#pragma GCC diagnostic pop - -// STM32 F4 -#define LED_GREEN 12 -#define LED_ORANGE 13 -#define LED_RED 14 -#define LED_BLUE 15 -#endif +#include "mcu-headers.h" int digital_read (uint32_t arg1 __unused, uint32_t arg2 __unused) @@ -55,62 +43,17 @@ analog_write (uint32_t arg1 __unused, uint32_t arg2 __unused) JERRY_UNIMPLEMENTED (); } +#ifdef __TARGET_HOST void wait_ms (uint32_t time_ms) { -#ifdef __TARGET_HOST - // 1 millisecond = 1,000,000 Nanoseconds -#define NANO_SECOND_MULTIPLIER 1000000 __printf ("wait_ms: %d\n", time_ms); -#endif - -#ifdef __TARGET_MCU - while (time_ms --) - { - wait_1ms (); - } -#endif } +#else /* !__TARGET_HOST */ -#ifdef __TARGET_MCU - -void -initialize_timer () -{ - RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM2, ENABLE); - - TIM_TimeBaseInitTypeDef timerInitStructure; - timerInitStructure.TIM_Prescaler = 40000; - timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up; - timerInitStructure.TIM_Period = 500; - timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; - timerInitStructure.TIM_RepetitionCounter = 0; - TIM_TimeBaseInit (TIM2, &timerInitStructure); - TIM_Cmd (TIM2, ENABLE); -} - -void -fake_exit (void) -{ - uint32_t pin = LED_ORANGE; - volatile GPIO_TypeDef* gpio = GPIOD; - volatile int index; - - int dot = 600000; - int dash = dot * 3; - - while (1) - { - gpio->BSRRL = (uint16_t) (1 << pin); - for ( index = 0; index < dot; index ++) - { - }; - gpio->BSRRH = (uint16_t) (1 << pin); - for (index = 0; index < dash; index ++) - { - }; - } -} +#ifndef __TARGET_MCU +# error "!__TARGET_HOST && !__TARGET_MCU" +#endif /* !__TARGET_MCU */ static __IO uint32_t sys_tick_counter; @@ -163,4 +106,49 @@ wait_1ms (void) { } } -#endif + +void +wait_ms (uint32_t time_ms) +{ + while (time_ms --) + { + wait_1ms (); + } +} + +void +fake_exit (void) +{ + uint32_t pin = LED_ORANGE; + volatile int index; + + int dot = 600000; + int dash = dot * 3; + + while (1) + { + led_on (pin); + for ( index = 0; index < dot; index ++) + { + }; + led_off (pin); + for (index = 0; index < dash; index ++) + { + }; + } +} +void +initialize_timer () +{ + RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM2, ENABLE); + + TIM_TimeBaseInitTypeDef timerInitStructure; + timerInitStructure.TIM_Prescaler = 40000; + timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up; + timerInitStructure.TIM_Period = 500; + timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; + timerInitStructure.TIM_RepetitionCounter = 0; + TIM_TimeBaseInit (TIM2, &timerInitStructure); + TIM_Cmd (TIM2, ENABLE); +} +#endif /* !__TARGET_HOST && __TARGET_MCU */ diff --git a/src/libperipherals/mcu-headers.h b/src/libperipherals/mcu-headers.h new file mode 100644 index 000000000..28b7ce92b --- /dev/null +++ b/src/libperipherals/mcu-headers.h @@ -0,0 +1,45 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MCU_HEADERS_H +#define MCU_HEADERS_H + +#ifdef __TARGET_MCU +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#pragma GCC diagnostic ignored "-Wsign-conversion" +# ifdef __TARGET_MCU_STM32F4 +# include "stm32f4xx_conf.h" +# include "stm32f4xx.h" + +# define LED_GREEN 0 +# define LED_ORANGE 1 +# define LED_RED 2 +# define LED_BLUE 3 +# elif defined (__TARGET_MCU_STM32F3) +# include "stm32f30x_conf.h" +# include "stm32f30x.h" + +# define LED_GREEN 0 +# define LED_ORANGE 1 +# define LED_RED 2 +# define LED_BLUE 3 +# else /* !__TARGET_MCU_STM32F4 && !__TARGET_MCU_STM32F3 */ +# error "!__TARGET_MCU_STM32F4 && !__TARGET_MCU_STM32F3" +# endif /* !__TARGET_MCU_STM32F4 && !__TARGET_MCU_STM32F3 */ +#pragma GCC diagnostic pop +#endif /* __TARGET_MCU */ + +#endif /* !MCU_HEADERS_H */ diff --git a/src/libruntime/target/stm32f3/abi.S b/src/libruntime/target/stm32f3/abi.S new file mode 100644 index 000000000..8aa534116 --- /dev/null +++ b/src/libruntime/target/stm32f3/abi.S @@ -0,0 +1,103 @@ +/** + * Runtime ABI for ARM architecture + */ + +/** + * long long __aeabi_llsl(long long {r1, r0}, int {r2}) + */ +.thumb_func +.global __aeabi_llsl +__aeabi_llsl: + // if (r2 >= 64) goto 2f; + cmp r2, #64 + bhs 2f + + // if (r2 < 32) goto 1f; + cmp r2, #32 + blo 1f + + // r1 = (r0 << (r2 - 32)); + // r0 = 0; + sub r2, #32 + mov r1, r0 + lsl r1, r2 + mov r0, #0 + + bx lr + + 1: + // r1 <<= r2; + lsl r1, r2 + + // r2 = 32 - r2; + rsb r2, r2, #32 + + // r1 |= (r0 >> r2); + mov r3, r0 + lsr r3, r2 + orr r1, r3 + + // r2 = 32 - r2; + rsb r2, r2, #32 + + // r0 <<= r2; + lsl r0, r2 + + bx lr + + 2: + // r1 = 0; + // r0 = 0; + mov r1, #0 + mov r0, #0 + + bx lr + + +/** + * long long __aeabi_llsr(long long {r1, r0}, int {r2}) + */ +.thumb_func +.global __aeabi_llsr +__aeabi_llsr: + // if (r2 >= 64) goto 2f; + cmp r2, #64 + bhs 2f + + // if (r2 < 32) goto 1f; + cmp r2, #32 + blo 1f + + // r0 = (r1 >> (r2 - 32)); + // r1 = 0 + sub r2, #32 + mov r0, r1 + lsr r0, r2 + mov r1, #0 + + bx lr + + 1: + // r0 >>= r2 + lsr r0, r2 + + // r0 |= r1 << (32 - r2) + mov r3, r1 + rsb r2, r2, #32 + lsl r3, r3, r2 + orr r0, r3 + rsb r2, r2, #32 + + // r1 >>= r2 + lsr r1, r2 + + bx lr + + 2: + // r1 = 0; + // r0 = 0; + mov r1, #0 + mov r0, #0 + + bx lr + diff --git a/src/libruntime/target/stm32f3/jerry-assert.c b/src/libruntime/target/stm32f3/jerry-assert.c new file mode 100644 index 000000000..a986cda97 --- /dev/null +++ b/src/libruntime/target/stm32f3/jerry-assert.c @@ -0,0 +1,55 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "globals.h" +#include "jerry-libc.h" + +/** + * Handle failed assertion + */ +void __noreturn +jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */ + const char *file __unused, /**< file name */ + const char *function __unused, /**< function name */ + const uint32_t line __unused) /** line */ +{ + __exit (-ERR_FAILED_INTERNAL_ASSERTION); +} /* jerry_assert_fail */ + +/** + * Handle execution of control path that should be unreachable + */ +void __noreturn +jerry_unreachable (const char *comment __unused, /**< comment to unreachable mark if exists, + NULL - otherwise */ + const char *file __unused, /**< file name */ + const char *function __unused, /**< function name */ + const uint32_t line __unused) /**< line */ +{ + __exit (-ERR_FAILED_INTERNAL_ASSERTION); +} /* jerry_unreachable */ + +/** + * Handle unimplemented case execution + */ +void __noreturn +jerry_unimplemented (const char *comment __unused, /**< comment to unimplemented mark if exists, + NULL - otherwise */ + const char *file __unused, /**< file name */ + const char *function __unused, /**< function name */ + const uint32_t line __unused) /**< line */ +{ + __exit (-ERR_UNIMPLEMENTED_CASE); +} /* jerry_unimplemented */ diff --git a/src/libruntime/target/stm32f3/jerry-libc.c b/src/libruntime/target/stm32f3/jerry-libc.c new file mode 100644 index 000000000..cb8ca0391 --- /dev/null +++ b/src/libruntime/target/stm32f3/jerry-libc.c @@ -0,0 +1,59 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Jerry libc platform-specific functions stm32f4 implementation + */ + +#include "jerry-libc.h" + +#include + +extern void __noreturn exit (int status); + +/** Output of character. Writes the character c, cast to an unsigned char, to stdout. */ +int +__putchar (int c) +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(c); +} /* __putchar */ + +/** exit - cause normal process termination */ +void __noreturn +__exit (int status __unused) +{ + /** + * TODO: Blink LEDs? status -> binary -> LEDs? + */ + + while (true) + { + } +} /* __exit */ + +/** + * fwrite + * + * @return number of bytes written + */ +size_t +__fwrite (const void *ptr, /**< data to write */ + size_t size, /**< size of elements to write */ + size_t nmemb, /**< number of elements */ + _FILE *stream) /**< stream pointer */ +{ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS(ptr, size, nmemb, stream); +} /* __fwrite */ +