diff --git a/targets/esp8266/Makefile b/targets/esp8266/Makefile index f034f1f63..a87fb4346 100644 --- a/targets/esp8266/Makefile +++ b/targets/esp8266/Makefile @@ -40,8 +40,16 @@ SPECIAL_MKTARGETS=$(APP_MKTARGETS) SUBDIRS= user endif # } PDIR +# path to the JERRYSCRIPT directory +JERRYDIR ?= $(CURDIR)/../../.. + LDDIR = $(SDK_PATH)/ld +############################################################# +# JerryScript requires a modified linker script with specified alignments +# so we use it instead of the original one from SDK. +JERRY_LD_FILE = $(CURDIR)/ld/eagle.app.v6.ld + CCFLAGS += -Os #CCFLAGS += -O0 @@ -52,7 +60,7 @@ TARGET_LDFLAGS = \ --text-section-literals ifeq ($(FLAVOR),debug) - TARGET_LDFLAGS += -O0 + TARGET_LDFLAGS += -O0 -g endif ifeq ($(FLAVOR),release) @@ -60,45 +68,53 @@ ifeq ($(FLAVOR),release) endif COMPONENTS_eagle.app.v6 = \ - user/libuser.a \ - + user/libuser.a LINKFLAGS_eagle.app.v6 = \ -L$(SDK_PATH)/lib \ -Wl,--gc-sections \ -Wl,-Map,output.map \ -nostdlib \ - -T$(LD_FILE) \ + -T$(JERRY_LD_FILE) \ -Wl,--no-check-sections \ -u call_user_start \ -Wl,-static \ -Wl,--start-group \ - -lminic \ + -lcirom \ + -lcrypto \ + -lespconn \ + -lespnow \ + -lfreertos \ -lgcc \ -lhal \ + -ljson \ + -llwip \ + -ldriver \ + -lmain \ + -lmesh \ + -lmirom \ + -lnet80211 \ + -lnopoll \ -lphy \ -lpp \ - -lnet80211 \ + -lpwm \ + -lsmartconfig \ + -lspiffs \ + -lssl \ -lwpa \ - -lmain \ - -lfreertos \ - -llwip \ + -lwps \ -L./libs \ - -ljerrycore \ - -ljerryentry \ - -ljerrylibm \ + -ljerry-core \ + -ljerry-libm \ $(DEP_LIBS_eagle.app.v6) \ - ./libs/lib_a-setjmp.o \ -Wl,--end-group - DEPENDS_eagle.app.v6 = \ - $(LD_FILE) \ + $(JERRY_LD_FILE) \ $(LDDIR)/eagle.rom.addr.v6.ld \ - ./source/jerry-targetjs.h \ - ./libs/libjerrylibm.a \ - ./libs/libjerrycore.a \ - ./libs/libjerryentry.a + ./include/jerry-targetjs.h \ + ./libs/libjerry-core.a \ + ./libs/libjerry-libm.a ############################################################# @@ -138,6 +154,7 @@ DDEFINES += \ # Required for each makefile to inherit from the parent # +INCLUDES := -I $(JERRYDIR)/jerry-core/include INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)source sinclude $(SDK_PATH)/Makefile diff --git a/targets/esp8266/Makefile.esp8266 b/targets/esp8266/Makefile.esp8266 index 2ac0213e9..5bc854db3 100644 --- a/targets/esp8266/Makefile.esp8266 +++ b/targets/esp8266/Makefile.esp8266 @@ -12,17 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -# use TAB-8 - CURDIR = `pwd` -ESP_SDK_PATH ?= $(SDK_PATH) -ESP_INC = $(ESP_SDK_PATH)/extra_include -ESP_INC2 = $(ESP_SDK_PATH)/include -ESP_LIB = $(ESP_SDK_PATH)/lib -TYPE = release -INTERM = build/obj-esp8266 -OUTPUT = build/bin/$(TYPE).esp8266 -SRCPATH = targets/esp8266/source +ESP_LIB = $(SDK_PATH)/lib +BUILD_DIR = build/obj-esp8266 COPYTARGET = targets/esp8266/libs USBDEVICE ?= /dev/ttyUSB0 JERRYHEAP ?= 20 @@ -31,76 +23,50 @@ ESPTOOL ?= /opt/Espressif/esptool-py/esptool.py # compile flags ESP_CFLAGS := -D__TARGET_ESP8266 -D__attr_always_inline___= -MFORCE32 = `xtensa-lx106-elf-gcc --help=target | grep mforce-l32` +MFORCE32 = $(shell xtensa-lx106-elf-gcc --help=target | grep mforce-l32) ifneq ($(MFORCE32),) # Your compiler supports the -mforce-l32 flag which means that # constants can be placed in ROM to free additional RAM ESP_CFLAGS += -DJERRY_CONST_DATA="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))" + ESP_CFLAGS += -mforce-l32 endif ESP_CFLAGS += -Wl,-EL -fno-inline-functions ESP_CFLAGS += -ffunction-sections -fdata-sections ESP_CFLAGS += -mlongcalls -mtext-section-literals -mno-serialize-volatile -ifneq ($(MFORCE32),) - ESP_CFLAGS += -mforce-l32 -endif - -# include path -ESP_LIBS_INC :=$(CURDIR)/targets/esp8266/include -ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2) -ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/espressif -ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/freertos -ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/json -ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/lwip -ESP_LIBS_INC :=$(ESP_LIBS_INC);$(ESP_INC2)/ssl - -# jerry related source files -JERRY_BUILD_FILES := $(SRCPATH)/jerry_extapi.c -JERRY_BUILD_FILES := $(JERRY_BUILD_FILES);$(SRCPATH)/jerry_run.c - .PHONY: jerry js2c mkbin check-env flash clean - all: check-env jerry js2c mkbin - jerry: - mkdir -p $(INTERM) - mkdir -p $(OUTPUT) + mkdir -p $(BUILD_DIR) mkdir -p $(COPYTARGET) - cmake -B$(INTERM) -H./ \ + cmake -B$(BUILD_DIR) -H./ \ -DENABLE_LTO=OFF \ - -DENABLE_VALGRIND=OFF \ - -DCMAKE_TOOLCHAIN_FILE=build/configs/toolchain_external.cmake \ + -DFEATURE_VALGRIND=OFF \ + -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain_external.cmake \ -DEXTERNAL_CMAKE_SYSTEM_PROCESSOR=xtensia-lx106 \ -DEXTERNAL_CMAKE_C_COMPILER=xtensa-lx106-elf-gcc \ -DEXTERNAL_CMAKE_C_COMPILER_ID=GNU \ - -DEXTERNAL_BUILD_ENTRY_FILE="$(JERRY_BUILD_FILES)" \ + -DJERRY_LIBC=OFF \ + -DJERRY_LIBM=ON \ + -DJERRY_CMDLINE=OFF \ + -DENABLE_ALL_IN_ONE=ON \ -DEXTERNAL_COMPILE_FLAGS="$(ESP_CFLAGS)" \ - -DEXTERNAL_LIBC_INTERFACE="$(ESP_INC)" \ - -DEXTERNAL_LIBS_INTERFACE="$(ESP_LIBS_INC)" \ - -DEXTERNAL_MEM_HEAP_SIZE_KB=$(JERRYHEAP) - - make -C $(INTERM) $(TYPE).external - cp `cat $(INTERM)/$(TYPE).external/list` $(OUTPUT)/. - cp $(OUTPUT)/lib$(TYPE).jerry-core.a $(COPYTARGET)/libjerrycore.a - cp $(OUTPUT)/lib$(TYPE).jerry-libm.lib.a $(COPYTARGET)/libjerrylibm.a - cp $(INTERM)/lib$(TYPE).external-entry.a $(OUTPUT)/. - cp $(OUTPUT)/lib$(TYPE).external-entry.a $(COPYTARGET)/libjerryentry.a + -DMEM_HEAP_SIZE_KB=$(JERRYHEAP) + make -C$(BUILD_DIR) jerry-core jerry-libm + cp $(BUILD_DIR)/lib/libjerry-core.a $(COPYTARGET)/ + cp $(BUILD_DIR)/lib/libjerry-libm.a $(COPYTARGET)/ js2c: - cd targets/esp8266; ../../tools/js2c.py - + tools/js2c.py --dest targets/esp8266/include --js-source targets/esp8266/js mkbin: - cd targets/esp8266; \ - make clean; \ - BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=3 make; \ - BOOT=new APP=2 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=3 make - + make -Ctargets/esp8266 clean + make -Ctargets/esp8266 BOOT=new APP=0 SPI_SPEED=40 SPI_MODE=DIO SPI_SIZE_MAP=4 check-env: ifndef SDK_PATH @@ -110,16 +76,14 @@ ifndef BIN_PATH $(error BIN_PATH is undefined for ESP8266) endif - flash: $(ESPTOOL) --port $(USBDEVICE) write_flash \ - 0x00000 $(SDK_PATH)/bin/"boot_v1.4(b1).bin" \ - 0x01000 $(BIN_PATH)/upgrade/user1.2048.new.3.bin \ - 0x81000 $(BIN_PATH)/upgrade/user2.2048.new.3.bin \ - 0x1FC000 $(SDK_PATH)/bin/esp_init_data_default.bin \ - 0x1FE000 $(SDK_PATH)/bin/blank.bin + 0x00000 $(BIN_PATH)/eagle.flash.bin \ + 0x20000 $(BIN_PATH)/eagle.irom0text.bin \ + 0x3FC000 $(SDK_PATH)/bin/esp_init_data_default.bin +erase_flash: + $(ESPTOOL) --port $(USBDEVICE) erase_flash clean: - rm -rf $(INTERM) - rm -rf $(OUTPUT) + rm -rf $(BUILD_DIR) diff --git a/targets/esp8266/docs/ESP-PATCHFORJERRYSCRIPT.md b/targets/esp8266/docs/ESP-PATCHFORJERRYSCRIPT.md deleted file mode 100644 index bc6bb74ab..000000000 --- a/targets/esp8266/docs/ESP-PATCHFORJERRYSCRIPT.md +++ /dev/null @@ -1,75 +0,0 @@ -#### Apply patch to ESP8266 SDK - -As `iram` is quite small to fit all the codes but linker tries to put it there. -To force JerryScript codes to be placed at the `irom` section, -need to change the order and tell the linker as below; - -``` -diff --git a/ld/eagle.app.v6.common.ld b/ld/eagle.app.v6.common.ld -index caf8e32..dadaceb 100644 ---- a/ld/eagle.app.v6.common.ld -+++ b/ld/eagle.app.v6.common.ld -@@ -151,6 +151,21 @@ SECTIONS - } >dram0_0_seg :dram0_0_bss_phdr - /* __stack = 0x3ffc8000; */ - -+ .irom0.text : ALIGN(4) -+ { -+ _irom0_text_start = ABSOLUTE(.); -+ *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text) -+ *(.literal.* .text.*) -+ _irom0_text_end = ABSOLUTE(.); -+ -+ _jerry_text_start = ABSOLUTE(.); -+ *\libjerryentry.a:*(.text*) -+ *\libjerrycore.a:*(.text*) -+ *\libjerrylibm.a:*(.text*) -+ _jerry_text_end = ABSOLUTE(.); -+ -+ } >irom0_0_seg :irom0_0_phdr -+ - .text : ALIGN(4) - { - _stext = .; -@@ -199,13 +214,6 @@ SECTIONS - _lit4_end = ABSOLUTE(.); - } >iram1_0_seg :iram1_0_phdr - -- .irom0.text : ALIGN(4) -- { -- _irom0_text_start = ABSOLUTE(.); -- *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text) -- *(.literal.* .text.*) -- _irom0_text_end = ABSOLUTE(.); -- } >irom0_0_seg :irom0_0_phdr - } - - /* get ROM code address */ -diff --git a/ld/eagle.app.v6.ld b/ld/eagle.app.v6.ld -index 3e7ec1b..4a9ab5b 100644 ---- a/ld/eagle.app.v6.ld -+++ b/ld/eagle.app.v6.ld -@@ -26,7 +26,7 @@ MEMORY - dport0_0_seg : org = 0x3FF00000, len = 0x10 - dram0_0_seg : org = 0x3FFE8000, len = 0x14000 - iram1_0_seg : org = 0x40100000, len = 0x8000 -- irom0_0_seg : org = 0x40240000, len = 0x3C000 -+ irom0_0_seg : org = 0x40240000, len = 0xB0000 - } - - INCLUDE "../ld/eagle.app.v6.common.ld" -``` - -Second file is to modify `irom` size so that it can hold all the codes and data. -This can be done by giving another `SPI_SIZE_MAP`. -For now, I'll use this manual modification. - - -#### Need to get setjmp / longjmp - -Extract and copy from the SDK. - -``` -cd ~/harmony/jerryscript/targets/esp8266/libs -ar -xv $SDK_PATH/lib/libcirom.a lib_a-setjmp.o -``` diff --git a/targets/esp8266/docs/ESP-PREREQUISITES.md b/targets/esp8266/docs/ESP-PREREQUISITES.md index 7d1a915b8..339950890 100644 --- a/targets/esp8266/docs/ESP-PREREQUISITES.md +++ b/targets/esp8266/docs/ESP-PREREQUISITES.md @@ -18,22 +18,24 @@ I've slightly changed the step to use SDK from Espressif official SDK ##### Toolchain: -dependencies for x86 +dependencies ``` sudo apt-get install git autoconf build-essential gperf \ - bison flex texinfo libtool libncurses5-dev wget \ - gawk libc6-dev-i386 python-serial libexpat-dev + bison flex texinfo libtool libtool-bin libncurses5-dev wget \ + gawk python-serial libexpat-dev sudo mkdir /opt/Espressif sudo chown $USER /opt/Espressif/ + ``` -dependencies for x64 +dependency specific to x86: ``` -sudo apt-get install git autoconf build-essential gperf \ - bison flex texinfo libtool libncurses5-dev wget \ - gawk libc6-dev-amd64 python-serial libexpat-dev -sudo mkdir /opt/Espressif -sudo chown $USER /opt/Espressif/ +sudo apt-get install libc6-dev-i386 +``` + +dependency specific to x64: +``` +sudo apt-get install libc6-dev-amd64 ``` crosstool-NG @@ -56,14 +58,10 @@ PATH=$PWD/builds/xtensa-lx106-elf/bin:$PATH cd /opt/Esprissif git clone https://github.com/espressif/ESP8266_RTOS_SDK.git ESP8266_RTOS_SDK.git ln -s ESP8266_RTOS_SDK.git ESP8266_SDK -cd ESP8266_SDK -git checkout -b jerry a2b413ad2996450fe2f173b6afab243f6e1249aa +git checkout -b jerry 2fab9e23d779cdd6e5900b8ba2b588e30d9b08c4 ``` -We use SDK 1.2.0 version which has stdlib.h and others. Latest 1.3.0 version, -as of writing this document, doesn't have it. -(If anyone knows how to use latest version, please add an issue or send a PR.) - +This verison is tested and works properly. set two environment variables such as in .profile ``` @@ -126,7 +124,7 @@ make BOOT=new APP=0 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=2 ``` sudo /opt/Espressif/esptool-py/esptool.py \ --port /dev/ttyUSB0 write_flash \ - 0x00000 $SDK_PATH/bin/"boot_v1.4(b1).bin" \ + 0x00000 $SDK_PATH/bin/"boot_v1.7.bin" \ 0x01000 $BIN_PATH/upgrade/user1.2048.new.5.bin \ 0x101000 $BIN_PATH/upgrade/user2.2048.new.5.bin \ 0x3FE000 $SDK_PATH/bin/blank.bin \ @@ -146,5 +144,3 @@ sudo /opt/Espressif/esptool-py/esptool.py \ * disconnect GPIO0 so that it is floating * connect GPIO2 with serial of 470 Ohm + LED and to GND * power On - -LED should blink on and off every second diff --git a/targets/esp8266/gen_misc.sh b/targets/esp8266/gen_misc.sh deleted file mode 100644 index 9e8a86312..000000000 --- a/targets/esp8266/gen_misc.sh +++ /dev/null @@ -1,165 +0,0 @@ -#!/bin/bash - -echo "gen_misc.sh version 20150826" -echo "" - -if [ $SDK_PATH ]; then - echo "SDK_PATH:" - echo "$SDK_PATH" - echo "" -else - echo "ERROR: Please export SDK_PATH firstly, exit!!!" - exit -fi - -if [ $BIN_PATH ]; then - echo "BIN_PATH:" - echo "$BIN_PATH" - echo "" -else - echo "ERROR: Please export BIN_PATH firstly, exit!!!" - exit -fi - -echo "Please check SDK_PATH & BIN_PATH, enter (Y/y) to continue:" -read input - -if [[ $input != Y ]] && [[ $input != y ]]; then - exit -fi - -echo "" - -echo "Please follow below steps(1-5) to generate specific bin(s):" -echo "STEP 1: use boot_v1.2+ by default" -boot=new - -echo "boot mode: $boot" -echo "" - -echo "STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin)" -echo "enter (0/1/2, default 0):" -read input - -if [ -z "$input" ]; then - if [ $boot != none ]; then - boot=none - echo "ignore boot" - fi - app=0 - echo "generate bin: eagle.flash.bin+eagle.irom0text.bin" -elif [ $input == 1 ]; then - if [ $boot == none ]; then - app=0 - echo "choose no boot before" - echo "generate bin: eagle.flash.bin+eagle.irom0text.bin" - else - app=1 - echo "generate bin: user1.bin" - fi -elif [ $input == 2 ]; then - if [ $boot == none ]; then - app=0 - echo "choose no boot before" - echo "generate bin: eagle.flash.bin+eagle.irom0text.bin" - else - app=2 - echo "generate bin: user2.bin" - fi -else - if [ $boot != none ]; then - boot=none - echo "ignore boot" - fi - app=0 - echo "generate bin: eagle.flash.bin+eagle.irom0text.bin" -fi - -echo "" - -echo "STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz)" -echo "enter (0/1/2/3, default 2):" -read input - -if [ -z "$input" ]; then - spi_speed=40 -elif [ $input == 0 ]; then - spi_speed=20 -elif [ $input == 1 ]; then - spi_speed=26.7 -elif [ $input == 3 ]; then - spi_speed=80 -else - spi_speed=40 -fi - -echo "spi speed: $spi_speed MHz" -echo "" - -echo "STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT)" -echo "enter (0/1/2/3, default 0):" -read input - -if [ -z "$input" ]; then - spi_mode=QIO -elif [ $input == 1 ]; then - spi_mode=QOUT -elif [ $input == 2 ]; then - spi_mode=DIO -elif [ $input == 3 ]; then - spi_mode=DOUT -else - spi_mode=QIO -fi - -echo "spi mode: $spi_mode" -echo "" - -echo "STEP 5: choose spi size and map" -echo " 0= 512KB( 256KB+ 256KB)" -echo " 2=1024KB( 512KB+ 512KB)" -echo " 3=2048KB( 512KB+ 512KB)" -echo " 4=4096KB( 512KB+ 512KB)" -echo " 5=2048KB(1024KB+1024KB)" -echo " 6=4096KB(1024KB+1024KB)" -echo "enter (0/2/3/4/5/6, default 0):" -read input - -if [ -z "$input" ]; then - spi_size_map=0 - echo "spi size: 512KB" - echo "spi ota map: 256KB + 256KB" -elif [ $input == 2 ]; then - spi_size_map=2 - echo "spi size: 1024KB" - echo "spi ota map: 512KB + 512KB" -elif [ $input == 3 ]; then - spi_size_map=3 - echo "spi size: 2048KB" - echo "spi ota map: 512KB + 512KB" -elif [ $input == 4 ]; then - spi_size_map=4 - echo "spi size: 4096KB" - echo "spi ota map: 512KB + 512KB" -elif [ $input == 5 ]; then - spi_size_map=5 - echo "spi size: 2048KB" - echo "spi ota map: 1024KB + 1024KB" -elif [ $input == 6 ]; then - spi_size_map=6 - echo "spi size: 4096KB" - echo "spi ota map: 1024KB + 1024KB" -else - spi_size_map=0 - echo "spi size: 512KB" - echo "spi ota map: 256KB + 256KB" -fi - -echo "" - -echo "start..." -echo "" - -make clean - -make BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map diff --git a/targets/esp8266/include/esp8266_gpio.h b/targets/esp8266/include/esp8266_gpio.h deleted file mode 100644 index 6c323637a..000000000 --- a/targets/esp8266/include/esp8266_gpio.h +++ /dev/null @@ -1,151 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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. - */ - -/* - * Copyright (C) 2014 -2016 Espressif System - * - */ - -#ifndef __ESP82666_GPIO_H__ -#define __ESP82666_GPIO_H__ - -#define GPIO_Pin_0 (BIT(0)) /* Pin 0 selected */ -#define GPIO_Pin_1 (BIT(1)) /* Pin 1 selected */ -#define GPIO_Pin_2 (BIT(2)) /* Pin 2 selected */ -#define GPIO_Pin_3 (BIT(3)) /* Pin 3 selected */ -#define GPIO_Pin_4 (BIT(4)) /* Pin 4 selected */ -#define GPIO_Pin_5 (BIT(5)) /* Pin 5 selected */ -#define GPIO_Pin_6 (BIT(6)) /* Pin 6 selected */ -#define GPIO_Pin_7 (BIT(7)) /* Pin 7 selected */ -#define GPIO_Pin_8 (BIT(8)) /* Pin 8 selected */ -#define GPIO_Pin_9 (BIT(9)) /* Pin 9 selected */ -#define GPIO_Pin_10 (BIT(10)) /* Pin 10 selected */ -#define GPIO_Pin_11 (BIT(11)) /* Pin 11 selected */ -#define GPIO_Pin_12 (BIT(12)) /* Pin 12 selected */ -#define GPIO_Pin_13 (BIT(13)) /* Pin 13 selected */ -#define GPIO_Pin_14 (BIT(14)) /* Pin 14 selected */ -#define GPIO_Pin_15 (BIT(15)) /* Pin 15 selected */ -#define GPIO_Pin_All (0xFFFF) /* All pins selected */ - -#define GPIO_PIN_REG_0 PERIPHS_IO_MUX_GPIO0_U -#define GPIO_PIN_REG_1 PERIPHS_IO_MUX_U0TXD_U -#define GPIO_PIN_REG_2 PERIPHS_IO_MUX_GPIO2_U -#define GPIO_PIN_REG_3 PERIPHS_IO_MUX_U0RXD_U -#define GPIO_PIN_REG_4 PERIPHS_IO_MUX_GPIO4_U -#define GPIO_PIN_REG_5 PERIPHS_IO_MUX_GPIO5_U -#define GPIO_PIN_REG_6 PERIPHS_IO_MUX_SD_CLK_U -#define GPIO_PIN_REG_7 PERIPHS_IO_MUX_SD_DATA0_U -#define GPIO_PIN_REG_8 PERIPHS_IO_MUX_SD_DATA1_U -#define GPIO_PIN_REG_9 PERIPHS_IO_MUX_SD_DATA2_U -#define GPIO_PIN_REG_10 PERIPHS_IO_MUX_SD_DATA3_U -#define GPIO_PIN_REG_11 PERIPHS_IO_MUX_SD_CMD_U -#define GPIO_PIN_REG_12 PERIPHS_IO_MUX_MTDI_U -#define GPIO_PIN_REG_13 PERIPHS_IO_MUX_MTCK_U -#define GPIO_PIN_REG_14 PERIPHS_IO_MUX_MTMS_U -#define GPIO_PIN_REG_15 PERIPHS_IO_MUX_MTDO_U - -#define GPIO_PIN_REG(i) \ - (i==0) ? GPIO_PIN_REG_0: \ - (i==1) ? GPIO_PIN_REG_1: \ - (i==2) ? GPIO_PIN_REG_2: \ - (i==3) ? GPIO_PIN_REG_3: \ - (i==4) ? GPIO_PIN_REG_4: \ - (i==5) ? GPIO_PIN_REG_5: \ - (i==6) ? GPIO_PIN_REG_6: \ - (i==7) ? GPIO_PIN_REG_7: \ - (i==8) ? GPIO_PIN_REG_8: \ - (i==9) ? GPIO_PIN_REG_9: \ - (i==10)? GPIO_PIN_REG_10: \ - (i==11)? GPIO_PIN_REG_11: \ - (i==12)? GPIO_PIN_REG_12: \ - (i==13)? GPIO_PIN_REG_13: \ - (i==14)? GPIO_PIN_REG_14: \ - GPIO_PIN_REG_15 - -#define GPIO_PIN_ADDR(i) (GPIO_PIN0_ADDRESS + i*4) - -#define GPIO_ID_IS_PIN_REGISTER(reg_id) ((reg_id >= GPIO_ID_PIN0) && (reg_id <= GPIO_ID_PIN(GPIO_PIN_COUNT-1))) - -#define GPIO_REGID_TO_PINIDX(reg_id) ((reg_id) - GPIO_ID_PIN0) - -typedef enum -{ - GPIO_PIN_INTR_DISABLE = 0, - GPIO_PIN_INTR_POSEDGE = 1, - GPIO_PIN_INTR_NEGEDGE = 2, - GPIO_PIN_INTR_ANYEGDE = 3, - GPIO_PIN_INTR_LOLEVEL = 4, - GPIO_PIN_INTR_HILEVEL = 5 -} GPIO_INT_TYPE; - -typedef enum -{ - GPIO_Mode_Input = 0x0, - GPIO_Mode_Out_OD, - GPIO_Mode_Output , - GPIO_Mode_Sigma_Delta -} GPIOMode_TypeDef; - -typedef enum -{ - GPIO_PullUp_DIS = 0x0, - GPIO_PullUp_EN = 0x1 -} GPIO_Pullup_IF; - -typedef struct -{ - uint16 GPIO_Pin; - GPIOMode_TypeDef GPIO_Mode; - GPIO_Pullup_IF GPIO_Pullup; - GPIO_INT_TYPE GPIO_IntrType; -} GPIO_ConfigTypeDef; - -#define GPIO_OUTPUT_SET(gpio_no, bit_value) gpio_output_conf (bit_value<> gpio_no)&BIT0) - - -#ifdef __cplusplus -extern "C" { -#endif - - -void gpio16_output_conf (void); -void gpio16_output_set (uint8 value); -void gpio16_input_conf (void); -uint8 gpio16_input_get (void); - -void gpio_output_conf (uint32 set_mask, uint32 clear_mask, uint32 enable_mask, uint32 disable_mask); -void gpio_intr_handler_register (void *fn); -void gpio_pin_wakeup_enable (uint32 i, GPIO_INT_TYPE intr_state); -void gpio_pin_wakeup_disable (); -void gpio_pin_intr_state_set (uint32 i, GPIO_INT_TYPE intr_state); -uint32 gpio_input_get (void); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/targets/esp8266/include/esp8266_uart.h b/targets/esp8266/include/esp8266_uart.h deleted file mode 100644 index 333fe0dcc..000000000 --- a/targets/esp8266/include/esp8266_uart.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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. - */ - -/* - * Copyright (C) 2014 -2016 Espressif System - * - */ - -#ifndef __ESP8266_UART_H__ -#define __ESP8266_UART_H__ - -typedef enum { - UART0 = 0x0, - UART1 = 0x1, -} UART_Port; - -typedef enum { - BIT_RATE_300 = 300, - BIT_RATE_600 = 600, - BIT_RATE_1200 = 1200, - BIT_RATE_2400 = 2400, - BIT_RATE_4800 = 4800, - BIT_RATE_9600 = 9600, - BIT_RATE_19200 = 19200, - BIT_RATE_38400 = 38400, - BIT_RATE_57600 = 57600, - BIT_RATE_74880 = 74880, - BIT_RATE_115200 = 115200, - BIT_RATE_230400 = 230400, - BIT_RATE_460800 = 460800, - BIT_RATE_921600 = 921600, - BIT_RATE_1843200 = 1843200, - BIT_RATE_3686400 = 3686400, -} UART_BautRate; - -#endif diff --git a/targets/esp8266/include/jerry_run.h b/targets/esp8266/include/jerry_run.h index 984a3c011..51a6e987e 100644 --- a/targets/esp8266/include/jerry_run.h +++ b/targets/esp8266/include/jerry_run.h @@ -21,7 +21,7 @@ extern "C" { #endif -int js_entry (const char *source_p, const size_t source_size); +void js_entry (void); int js_eval (const char *source_p, const size_t source_size); int js_loop (uint32_t ticknow); void js_exit (void); diff --git a/targets/esp8266/include/native_esp8266.h b/targets/esp8266/include/native_esp8266.h deleted file mode 100644 index e57665e85..000000000 --- a/targets/esp8266/include/native_esp8266.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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 __NATIVE_ESP8266_H__ -#define __NATIVE_ESP8266_H__ - -#ifdef __cplusplus -extern "C" { -#endif - - -void native_gpio_dir (int, int); -void native_gpio_set (int, int); -int native_gpio_get (int); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/targets/esp8266/ld/eagle.app.v6.ld b/targets/esp8266/ld/eagle.app.v6.ld new file mode 100644 index 000000000..a25f5cc93 --- /dev/null +++ b/targets/esp8266/ld/eagle.app.v6.ld @@ -0,0 +1,32 @@ +/* eagle.flash.bin @ 0x00000 */ +/* eagle.irom0text.bin @ 0x20000 */ + +/* Flash Map, support 512KB/1MB/2MB/4MB SPI Flash */ +/* |......|..............................|..........................|.....|....| */ +/* ^ ^ ^ ^ ^ */ +/* |_flash.bin start(0x00000) |_irom0text.bin start(0x20000) | */ +/* |_flash.bin end |_irom0text.bin end */ +/* |_system param area(0x7b000) */ + +/* NOTICE: */ +/* 1. You can change irom0 org, but MUST make sure irom0text.bin start not overlap flash.bin end. */ +/* 2. You can change irom0 len, but MUST make sure irom0text.bin end not overlap system param area. */ +/* 3. Space between flash.bin end and irom0text.bin start can be used as user param area. */ +/* 4. Space between irom0text.bin end and system param area can be used as user param area. */ +/* 5. Make sure irom0text.bin end < 0x100000 */ +/* 6. system param area: */ +/* 1>. 512KB--->0x07b000 */ +/* 2>. 1MB----->0x0fb000 */ +/* 3>. 2MB----->0x1fb000 */ +/* 4>. 4MB----->0x3fb000 */ +/* 7. Don't change any other seg. */ + +MEMORY +{ + dport0_0_seg : org = 0x3FF00000, len = 0x10 + dram0_0_seg : org = 0x3FFE8000, len = 0x18000 + iram1_0_seg : org = 0x40100000, len = 0x8000 + irom0_0_seg : org = 0x40220000, len = 0x6C000 +} + +INCLUDE ../ld/eagle.app.v6.common.ld diff --git a/targets/esp8266/readme.md b/targets/esp8266/readme.md index 42a2ce77f..10a18c6e8 100644 --- a/targets/esp8266/readme.md +++ b/targets/esp8266/readme.md @@ -1,6 +1,6 @@ ### About -Files in this folder (embedding/esp8266) are copied from +Files in this folder (targets/esp8266) are copied from `examples/project_template` of `esp_iot_rtos_sdk` and modified for JerryScript. You can view online from [this](https://github.com/espressif/esp_iot_rtos_sdk/tree/master/examples/project_template) page. @@ -13,38 +13,18 @@ You can view online from Follow [this](./docs/ESP-PREREQUISITES.md) page to setup build environment -#### 2. Patch ESP-SDK for JerryScript - -Follow [this](./docs/ESP-PATCHFORJERRYSCRIPT.md) page to patch for JerryScript building. -Below is a summary after SDK patch is applied. - -#### 3. Building JerryScript +#### 2. Building JerryScript ``` -cd ~/harmony/jerryscript -# clean build -make -f ./targets/esp8266/Makefile.esp8266 clean -# or just normal build +# assume you are in jerryscript folder make -f ./targets/esp8266/Makefile.esp8266 ``` Output files should be placed at $BIN_PATH -#### 4. Flashing for ESP8266 ESP-01 board (WiFi Module) - -Steps are for `ESP8266 ESP-01(WiFi)` board. Others may vary. -Refer http://www.esp8266.com/wiki/doku.php?id=esp8266-module-family page. - -##### 4.1 GPIO0 and GPIO2 - -Before flashing you need to follow the steps. - -1. Power off ESP8266 -2. Connect GPIO0 to GND and GPIO2 to VCC -3. Power on ESP8266 -4. Flash - -##### 4.2 Flashing +#### 3. Flashing for ESP8266 12E +Follow +[this](http://www.kloppenborg.net/images/blog/esp8266/esp8266-esp12e-specs.pdf) page to get details about this board. ``` make -f ./targets/esp8266/Makefile.esp8266 flash @@ -56,26 +36,36 @@ Default USB device is `/dev/ttyUSB0`. If you have different one, give with `USBD USBDEVICE=/dev/ttyUSB1 make -f ./targets/esp8266/Makefile.esp8266 flash ``` +### 4. Running -### 5. Running +* power off +* connect GPIO2 with serial of 470 Ohm + LED and to GND +* power On -1. Power off -2. Disonnect(float) both GPIO0 and GPIO2 -3. Power on +LED should blink on and off every second -Sample program here works with LED and a SW with below connection. -* Connect GPIO2 to a LED > 4K resistor > GND -* Connect GPIO0 between VCC > 4K resistor and GND +#### 5. Cleaning + +To clean the build result: + +``` +make -f ./targets/esp8266/Makefile.esp8266 clean +``` + +To clean the board's flash memory: +``` +make -f ./targets/esp8266/Makefile.esp8266 erase_flash +``` -If GPIO0 is High then LED is turned on longer. If L vice versa. ### 6. Optimizing initial RAM usage (ESP8266 specific) The existing open source gcc compiler with Xtensa support stores const(ants) in -the same limited RAM where our code needs to run. +the same limited RAM where our code needs to run. -It is possible to force the compiler to 1)store a constant into ROM and also 2) read it from there thus saving 1.1) RAM. -It will require two things though: -1. To add the attribute JERRY_CONST_DATA to your constant. For example +It is possible to force the compiler to store a constant into ROM and also read it from there thus saving RAM. +The only requirement is to add `JERRY_CONST_DATA` attribute to your constant. + +For example: ```C static const lit_magic_size_t lit_magic_string_sizes[] = @@ -87,27 +77,12 @@ can be modified to static const lit_magic_size_t lit_magic_string_sizes[] JERRY_CONST_DATA = ``` -That is already done to some constants in jerry-core. +That is already done to some constants in jerry-core. E.g.: -1.1) Below is a short list: - - -Bytes | Name --------- | --------- -928 | magic_strings$2428 -610 | vm_decode_table -424 | unicode_letter_interv_sps -235 | cbc_flags -232 | lit_magic_string_sizes -212 | unicode_letter_interv_len -196 | unicode_non_letter_ident_ -112 | unicode_letter_chars - -Which frees 2949 bytes in RAM. - -2. To compile your code with compiler that supports the `-mforce-l32` parameter. You can check if your compiler is -supporting that parameter by calling: -```bash -xtensa-lx106-elf-gcc --help=target | grep mforce-l32 -``` -If the command above does not provide a result then you will need to upgrade your compiler. \ No newline at end of file +- vm_decode_table +- ecma_property_hashmap_steps +- lit_magic_string_sizes +- unicode_letter_interv_sps +- unicode_letter_interv_len +- unicode_non_letter_ident_ +- unicode_letter_chars diff --git a/targets/esp8266/user/Makefile b/targets/esp8266/user/Makefile index 31e4bbfc9..76aea6937 100644 --- a/targets/esp8266/user/Makefile +++ b/targets/esp8266/user/Makefile @@ -37,7 +37,8 @@ endif # Required for each makefile to inherit from the parent # -INCLUDES := $(INCLUDES) -I $(PDIR)include -INCLUDES += -I ./ -I ../include -I../../../ -sinclude $(PDIR)Makefile +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I ./ +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile diff --git a/targets/esp8266/source/jerry_extapi.c b/targets/esp8266/user/jerry_extapi.c similarity index 65% rename from targets/esp8266/source/jerry_extapi.c rename to targets/esp8266/user/jerry_extapi.c index ffc950483..91643a7ce 100644 --- a/targets/esp8266/source/jerry_extapi.c +++ b/targets/esp8266/user/jerry_extapi.c @@ -16,32 +16,24 @@ #include #include -#include "jerry-core/include/jerryscript.h" +#include "c_types.h" +#include "gpio.h" + +#include "jerryscript.h" #include "jerry_extapi.h" -#include "native_esp8266.h" - - - -#ifndef MIN -#define MIN(A,B) ((A)<(B)?(A):(B)) -#endif - - -#define __UNSED__ __attribute__((unused)) +#define __UNUSED__ __attribute__((unused)) #define DELCARE_HANDLER(NAME) \ static jerry_value_t \ -NAME ## _handler (const jerry_value_t function_obj_val __UNSED__, \ - const jerry_value_t this_val __UNSED__, \ +NAME ## _handler (const jerry_value_t function_obj_val __UNUSED__, \ + const jerry_value_t this_val __UNUSED__, \ const jerry_value_t args_p[], \ const jerry_length_t args_cnt) #define REGISTER_HANDLER(NAME) \ register_native_function ( # NAME, NAME ## _handler) -/*---------------------------------------------------------------------------*/ - DELCARE_HANDLER(assert) { if (args_cnt == 1 && jerry_value_is_boolean (args_p[0]) @@ -53,21 +45,18 @@ DELCARE_HANDLER(assert) { printf ("Script assertion failed\n"); exit (JERRY_STANDALONE_EXIT_CODE_FAIL); return jerry_create_boolean (false); -} +} /* assert */ DELCARE_HANDLER(print) { - jerry_length_t cc; - if (args_cnt) { - printf(">> print(%d) :", (int) args_cnt); - for (cc=0; cc #include +#include -#include "jerry-core/include/jerryscript-port.h" -int ets_putc (int); +#include "esp_common.h" + +#include "jerryscript-port.h" /** * Provide log message implementation for the engine. @@ -32,50 +34,49 @@ jerry_port_log (jerry_log_level_t level, /**< log level */ va_list args; va_start (args, format); - /* TODO, uncomment when vprint link is ok */ - /* vprintf (stderr, format, args); */ + vfprintf (stderr, format, args); va_end (args); } /* jerry_port_log */ - -/** exit - cause normal process termination */ -void exit (int status) +/** + * Provide fatal message implementation for the engine. + */ +void +jerry_port_fatal (jerry_fatal_code_t code) { - while (true) - { - } -} /* exit */ - -/** abort - cause abnormal process termination */ -void abort (void) -{ - while (true) - { - } -} /* abort */ + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Jerry Fatal Error!\n"); + while (true); +} /* jerry_port_fatal */ /** - * fwrite + * Implementation of jerry_port_get_current_time. * - * @return number of bytes written + * @return current timer's counter value in milliseconds */ -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 */ +double +jerry_port_get_current_time (void) { - return size * nmemb; -} /* fwrite */ + struct timeval tv; + + if (gettimeofday (&tv, NULL) != 0) + { + return 0; + } + + return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0; +} /* jerry_port_get_current_time */ /** - * This function can get the time as well as a timezone. + * Dummy function to get the time zone. * - * @return 0 if success, -1 otherwise + * @return true */ -int -gettimeofday (void *tp, /**< struct timeval */ - void *tzp) /**< struct timezone */ +bool +jerry_port_get_time_zone (jerry_time_zone_t *tz_p) { - return -1; -} /* gettimeofday */ + /* We live in UTC. */ + tz_p->offset = 0; + tz_p->daylight_saving_time = 0; + + return true; +} /* jerry_port_get_time_zone */ diff --git a/targets/esp8266/source/jerry_run.c b/targets/esp8266/user/jerry_run.c similarity index 53% rename from targets/esp8266/source/jerry_run.c rename to targets/esp8266/user/jerry_run.c index a15850b75..108e5488f 100644 --- a/targets/esp8266/source/jerry_run.c +++ b/targets/esp8266/user/jerry_run.c @@ -16,68 +16,42 @@ #include #include -#include "jerry-core/include/jerryscript.h" #include "jerry_extapi.h" #include "jerry_run.h" +#include "jerryscript.h" +#include "jerryscript-port.h" static const char* fn_sys_loop_name = "sysloop"; -jerry_value_t parsed_res; - -/*---------------------------------------------------------------------------*/ - -int js_entry (const char *source_p, const size_t source_size) +void js_entry () { - const jerry_char_t *jerry_src = (const jerry_char_t *) source_p; - int ret_code = 0; /* JERRY_COMPLETION_CODE_OK */ - jerry_init_flag_t flags = JERRY_INIT_EMPTY; - - jerry_init (flags); + srand ((unsigned) jerry_port_get_current_time ()); + jerry_init (JERRY_INIT_EMPTY); js_register_functions (); - - parsed_res = jerry_parse ((jerry_char_t *) jerry_src, source_size, false); - - if (jerry_value_has_error_flag (parsed_res)) - { - printf ("Error: jerry_parse failed\r\n"); - ret_code = JERRY_ERROR_SYNTAX; - } - - return ret_code; } int js_eval (const char *source_p, const size_t source_size) { - int status = 0; - jerry_value_t res; - - res = jerry_eval ((jerry_char_t *) source_p, - source_size, - false); + jerry_value_t res = jerry_eval ((jerry_char_t *) source_p, + source_size, + false); if (jerry_value_has_error_flag (res)) { - status = -1; + jerry_release_value (res); + return -1; } jerry_release_value (res); - return status; + return 0; } int js_loop (uint32_t ticknow) { - jerry_value_t global_obj_val; - jerry_value_t sysloop_func; - jerry_value_t val_args[1]; - uint16_t val_argv; - jerry_value_t res; - jerry_value_t prop_name_val; - int ret_code = 0; - - global_obj_val = jerry_get_global_object (); - prop_name_val = jerry_create_string ((const jerry_char_t *) fn_sys_loop_name); - sysloop_func = jerry_get_property (global_obj_val, prop_name_val); + jerry_value_t global_obj_val = jerry_get_global_object (); + jerry_value_t prop_name_val = jerry_create_string ((const jerry_char_t *) fn_sys_loop_name); + jerry_value_t sysloop_func = jerry_get_property (global_obj_val, prop_name_val); jerry_release_value (prop_name_val); if (jerry_value_has_error_flag (sysloop_func)) { @@ -94,23 +68,29 @@ int js_loop (uint32_t ticknow) return -2; } - val_argv = 1; - val_args[0] = jerry_create_number (ticknow); + jerry_value_t val_args[] = { jerry_create_number (ticknow) }; + uint16_t val_argv = sizeof (val_args) / sizeof (jerry_value_t); - res = jerry_call_function (sysloop_func, - global_obj_val, - val_args, - val_argv); + jerry_value_t res = jerry_call_function (sysloop_func, + global_obj_val, + val_args, + val_argv); - if (jerry_value_has_error_flag (res)) { - ret_code = -3; + for (uint16_t i = 0; i < val_argv; i++) { + jerry_release_value (val_args[i]); } - jerry_release_value (res); jerry_release_value (sysloop_func); jerry_release_value (global_obj_val); - return ret_code; + if (jerry_value_has_error_flag (res)) { + jerry_release_value (res); + return -3; + } + + jerry_release_value (res); + + return 0; } void js_exit (void) diff --git a/targets/esp8266/user/native_esp8266.c b/targets/esp8266/user/native_esp8266.c deleted file mode 100644 index 87f564d6a..000000000 --- a/targets/esp8266/user/native_esp8266.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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. - */ - -/****************************************************************************** - * Copyright 2013-2014 Espressif Systems (Wuxi) - * - * FileName: user_main.c - * - * Description: entry file of user application - * - * Modification history: - * 2014/12/1, v1.0 create this file. -*******************************************************************************/ - -#include "esp_common.h" - -#include "user_config.h" -#include "esp8266_gpio.h" - - -void native_gpio_dir(int port, int value) { - if (value) { - GPIO_AS_OUTPUT(1 << port); - } - else { - GPIO_AS_INPUT(1 << port); - } -} - - -void native_gpio_set(int port, int value) { - GPIO_OUTPUT_SET(port, value); -} - - -int native_gpio_get(int port) { - return GPIO_INPUT_GET(port); -} diff --git a/targets/esp8266/user/user_gpio.c b/targets/esp8266/user/user_gpio.c deleted file mode 100644 index 36ef70272..000000000 --- a/targets/esp8266/user/user_gpio.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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. - */ - -/* - * Copyright (C) 2014 -2016 Espressif System - * - */ - -#include "esp_common.h" - -#include "esp8266_gpio.h" - - -//----------------------------------------------------------------------------- - -void gpio_output_conf(uint32 set_mask, uint32 clear_mask, uint32 enable_mask, - uint32 disable_mask) { - GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, set_mask); - GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, clear_mask); - GPIO_REG_WRITE(GPIO_ENABLE_W1TS_ADDRESS, enable_mask); - GPIO_REG_WRITE(GPIO_ENABLE_W1TC_ADDRESS, disable_mask); -} - - -uint32 gpio_input_get(void) { - return GPIO_REG_READ(GPIO_IN_ADDRESS); -} diff --git a/targets/esp8266/user/user_main.c b/targets/esp8266/user/user_main.c index 82ecd976a..739ab3c56 100644 --- a/targets/esp8266/user/user_main.c +++ b/targets/esp8266/user/user_main.c @@ -25,64 +25,47 @@ *******************************************************************************/ #include "esp_common.h" - #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "uart.h" #include "user_config.h" -#include "esp8266_uart.h" +#include "jerry_run.h" +#include "jerry-targetjs.h" - -//----------------------------------------------------------------------------- - -void show_free_mem(int idx) { +static void show_free_mem(int idx) { size_t res = xPortGetFreeHeapSize(); printf("dbg free memory(%d): %d\r\n", idx, res); } - -//----------------------------------------------------------------------------- - -#include "jerry-targetjs.h" - - static int jerry_task_init(void) { - int retcode; - int src; - DECLARE_JS_CODES; - /* run main.js */ + js_entry(); + + /* run js files */ show_free_mem(2); - retcode = js_entry(js_codes[0].source, js_codes[0].length); - if (retcode != 0) { - printf("js_entry failed code(%d) [%s]\r\n", retcode, js_codes[0].name); - return -1; - } - /* run rest of the js files */ - show_free_mem(3); - for (src=1; js_codes[src].source; src++) { - retcode = js_eval(js_codes[src].source, js_codes[src].length); + for (int src = 0; js_codes[src].source; src++) { + int retcode = js_eval(js_codes[src].source, js_codes[src].length); if (retcode != 0) { printf("js_eval failed code(%d) [%s]\r\n", retcode, js_codes[src].name); return -2; } } - show_free_mem(4); + show_free_mem(3); return 0; } - -void jerry_task(void *pvParameters) { - const portTickType xDelay = 100 / portTICK_RATE_MS; - uint32_t ticknow = 0; - +static void jerry_task(void *pvParameters) { if (jerry_task_init() == 0) { + const portTickType xDelay = 100 / portTICK_RATE_MS; + uint32_t ticknow = 0; + for (;;) { vTaskDelay(xDelay); js_loop(ticknow); if (!ticknow) { - show_free_mem(5); + show_free_mem(4); } ticknow++; } @@ -90,15 +73,12 @@ void jerry_task(void *pvParameters) { js_exit(); } - -//----------------------------------------------------------------------------- - /* * This is entry point for user code */ void ICACHE_FLASH_ATTR user_init(void) { - uart_div_modify(UART0, UART_CLK_FREQ / (BIT_RATE_115200)); + UART_SetBaudrate(UART0, BIT_RATE_115200); show_free_mem(0); wifi_softap_dhcps_stop(); @@ -109,3 +89,52 @@ void ICACHE_FLASH_ATTR user_init(void) xTaskCreate(jerry_task, "jerry", JERRY_STACK_SIZE, NULL, 2, NULL); } + +/* + * FunctionName : user_rf_cal_sector_set + * Description : SDK just reserved 4 sectors, used for rf init data and Parameters. + * We add this function to force users to set rf cal sector, since + * we don't know which sector is free in user's application. + * sector map for last several sectors : ABCCC + * A : rf cal + * B : rf init data + * C : sdk parameters + * Parameters : none + * Returns : rf cal sector + */ +uint32 user_rf_cal_sector_set(void) +{ + flash_size_map size_map = system_get_flash_size_map(); + uint32 rf_cal_sec = 0; + + switch (size_map) { + case FLASH_SIZE_4M_MAP_256_256: + rf_cal_sec = 128 - 5; + break; + + case FLASH_SIZE_8M_MAP_512_512: + rf_cal_sec = 256 - 5; + break; + + case FLASH_SIZE_16M_MAP_512_512: + case FLASH_SIZE_16M_MAP_1024_1024: + rf_cal_sec = 512 - 5; + break; + + case FLASH_SIZE_32M_MAP_512_512: + case FLASH_SIZE_32M_MAP_1024_1024: + rf_cal_sec = 1024 - 5; + break; + case FLASH_SIZE_64M_MAP_1024_1024: + rf_cal_sec = 2048 - 5; + break; + case FLASH_SIZE_128M_MAP_1024_1024: + rf_cal_sec = 4096 - 5; + break; + default: + rf_cal_sec = 0; + break; + } + + return rf_cal_sec; +}