diff --git a/Makefile b/Makefile index 3340b12..0a4682b 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ FW_BASE = firmware XTENSA_TOOLS_ROOT ?= /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin # base directory of the ESP8266 SDK package, absolute -SDK_BASE ?= /opt/Espressif/ESP8266_SDK +SDK_BASE ?= $(CURDIR)/esp_iot_sdk_v1.3.0 #Esptool.py path and port ESPTOOL ?= esptool.py diff --git a/README.md b/README.md index 54807a2..057c0b0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ # ESP8266 packet injection/sniffer example -**Warning!** This example runs with a particular SDK build -which was available around September 2015. You can download it [here](https://www.dropbox.com/s/lkjwiyk81ky7wfu/esp_iot_sdk_v1.3.0_15_08_08.zip?dl=0). +**Warning!** This example runs with a particular SDK build that is now integrated into this project. +Future versions of the esp_iot_sdk removed the ability to send wifi control frames with `wifi_send_pkt_freedom`. This example project utilizes sniffer capabilities of -ESP8266 to perform deauth attack. Minimum SDK -requirement is 1.4.0. The communication between the +ESP8266 to perform deauth attack. The communication between the victim and access point (AP) is traced by `wifi_set_promiscuous_rx_cb` while packet injection is performed by `wifi_send_pkt_freedom`. To use the example adjust the Makefile and change MAC diff --git a/esp_iot_sdk_v1.3.0/Makefile b/esp_iot_sdk_v1.3.0/Makefile new file mode 100644 index 0000000..928f74f --- /dev/null +++ b/esp_iot_sdk_v1.3.0/Makefile @@ -0,0 +1,378 @@ +# copyright (c) 2010 Espressif System +# +ifndef PDIR + +endif + +ifeq ($(COMPILE), gcc) + AR = xtensa-lx106-elf-ar + CC = xtensa-lx106-elf-gcc + NM = xtensa-lx106-elf-nm + CPP = xtensa-lx106-elf-cpp + OBJCOPY = xtensa-lx106-elf-objcopy + OBJDUMP = xtensa-lx106-elf-objdump +else + AR = xt-ar + CC = xt-xcc + NM = xt-nm + CPP = xt-cpp + OBJCOPY = xt-objcopy + OBJDUMP = xt-objdump +endif + +BOOT?=none +APP?=0 +SPI_SPEED?=40 +SPI_MODE?=QIO +SPI_SIZE_MAP?=0 + +ifeq ($(BOOT), new) + boot = new +else + ifeq ($(BOOT), old) + boot = old + else + boot = none + endif +endif + +ifeq ($(APP), 1) + app = 1 +else + ifeq ($(APP), 2) + app = 2 + else + app = 0 + endif +endif + +ifeq ($(SPI_SPEED), 26.7) + freqdiv = 1 +else + ifeq ($(SPI_SPEED), 20) + freqdiv = 2 + else + ifeq ($(SPI_SPEED), 80) + freqdiv = 15 + else + freqdiv = 0 + endif + endif +endif + + +ifeq ($(SPI_MODE), QOUT) + mode = 1 +else + ifeq ($(SPI_MODE), DIO) + mode = 2 + else + ifeq ($(SPI_MODE), DOUT) + mode = 3 + else + mode = 0 + endif + endif +endif + +addr = 0x01000 + +ifeq ($(SPI_SIZE_MAP), 1) + size_map = 1 + flash = 256 +else + ifeq ($(SPI_SIZE_MAP), 2) + size_map = 2 + flash = 1024 + ifeq ($(app), 2) + addr = 0x81000 + endif + else + ifeq ($(SPI_SIZE_MAP), 3) + size_map = 3 + flash = 2048 + ifeq ($(app), 2) + addr = 0x81000 + endif + else + ifeq ($(SPI_SIZE_MAP), 4) + size_map = 4 + flash = 4096 + ifeq ($(app), 2) + addr = 0x81000 + endif + else + ifeq ($(SPI_SIZE_MAP), 5) + size_map = 5 + flash = 2048 + ifeq ($(app), 2) + addr = 0x101000 + endif + else + ifeq ($(SPI_SIZE_MAP), 6) + size_map = 6 + flash = 4096 + ifeq ($(app), 2) + addr = 0x101000 + endif + else + size_map = 0 + flash = 512 + ifeq ($(app), 2) + addr = 0x41000 + endif + endif + endif + endif + endif + endif +endif + +LD_FILE = $(LDDIR)/eagle.app.v6.ld + +ifneq ($(boot), none) +ifneq ($(app),0) + ifeq ($(size_map), 6) + LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).2048.ld + else + ifeq ($(size_map), 5) + LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).2048.ld + else + ifeq ($(size_map), 4) + LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).1024.app$(app).ld + else + ifeq ($(size_map), 3) + LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).1024.app$(app).ld + else + ifeq ($(size_map), 2) + LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).1024.app$(app).ld + else + ifeq ($(size_map), 0) + LD_FILE = $(LDDIR)/eagle.app.v6.$(boot).512.app$(app).ld + endif + endif + endif + endif + endif + endif + BIN_NAME = user$(app).$(flash).$(boot).$(size_map) +endif +else + app = 0 +endif + +CSRCS ?= $(wildcard *.c) +ASRCs ?= $(wildcard *.s) +ASRCS ?= $(wildcard *.S) +SUBDIRS ?= $(patsubst %/,%,$(dir $(wildcard */Makefile))) + +ODIR := .output +OBJODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/obj + +OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \ + $(ASRCs:%.s=$(OBJODIR)/%.o) \ + $(ASRCS:%.S=$(OBJODIR)/%.o) + +DEPS := $(CSRCS:%.c=$(OBJODIR)/%.d) \ + $(ASRCs:%.s=$(OBJODIR)/%.d) \ + $(ASRCS:%.S=$(OBJODIR)/%.d) + +LIBODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/lib +OLIBS := $(GEN_LIBS:%=$(LIBODIR)/%) + +IMAGEODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/image +OIMAGES := $(GEN_IMAGES:%=$(IMAGEODIR)/%) + +BINODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/bin +OBINS := $(GEN_BINS:%=$(BINODIR)/%) + +CCFLAGS += \ + -g \ + -Wpointer-arith \ + -Wundef \ + -Werror \ + -Wl,-EL \ + -fno-inline-functions \ + -nostdlib \ + -mlongcalls \ + -mtext-section-literals \ + -ffunction-sections \ + -fdata-sections +# -Wall + +CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(INCLUDES) +DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(INCLUDES) + + +############################################################# +# Functions +# + +define ShortcutRule +$(1): .subdirs $(2)/$(1) +endef + +define MakeLibrary +DEP_LIBS_$(1) = $$(foreach lib,$$(filter %.a,$$(COMPONENTS_$(1))),$$(dir $$(lib))$$(LIBODIR)/$$(notdir $$(lib))) +DEP_OBJS_$(1) = $$(foreach obj,$$(filter %.o,$$(COMPONENTS_$(1))),$$(dir $$(obj))$$(OBJODIR)/$$(notdir $$(obj))) +$$(LIBODIR)/$(1).a: $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1)) $$(DEPENDS_$(1)) + @mkdir -p $$(LIBODIR) + $$(if $$(filter %.a,$$?),mkdir -p $$(EXTRACT_DIR)_$(1)) + $$(if $$(filter %.a,$$?),cd $$(EXTRACT_DIR)_$(1); $$(foreach lib,$$(filter %.a,$$?),$$(AR) xo $$(UP_EXTRACT_DIR)/$$(lib);)) + $$(AR) ru $$@ $$(filter %.o,$$?) $$(if $$(filter %.a,$$?),$$(EXTRACT_DIR)_$(1)/*.o) + $$(if $$(filter %.a,$$?),$$(RM) -r $$(EXTRACT_DIR)_$(1)) +endef + +define MakeImage +DEP_LIBS_$(1) = $$(foreach lib,$$(filter %.a,$$(COMPONENTS_$(1))),$$(dir $$(lib))$$(LIBODIR)/$$(notdir $$(lib))) +DEP_OBJS_$(1) = $$(foreach obj,$$(filter %.o,$$(COMPONENTS_$(1))),$$(dir $$(obj))$$(OBJODIR)/$$(notdir $$(obj))) +$$(IMAGEODIR)/$(1).out: $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1)) $$(DEPENDS_$(1)) + @mkdir -p $$(IMAGEODIR) + $$(CC) $$(LDFLAGS) $$(if $$(LINKFLAGS_$(1)),$$(LINKFLAGS_$(1)),$$(LINKFLAGS_DEFAULT) $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1))) -o $$@ +endef + +$(BINODIR)/%.bin: $(IMAGEODIR)/%.out + @mkdir -p $(BINODIR) + +ifeq ($(APP), 0) + @$(RM) -r ../bin/eagle.S ../bin/eagle.dump + @$(OBJDUMP) -x -s $< > ../bin/eagle.dump + @$(OBJDUMP) -S $< > ../bin/eagle.S +else + @$(RM) -r ../bin/upgrade/$(BIN_NAME).S ../bin/upgrade/$(BIN_NAME).dump + @$(OBJDUMP) -x -s $< > ../bin/upgrade/$(BIN_NAME).dump + @$(OBJDUMP) -S $< > ../bin/upgrade/$(BIN_NAME).S +endif + + @$(OBJCOPY) --only-section .text -O binary $< eagle.app.v6.text.bin + @$(OBJCOPY) --only-section .data -O binary $< eagle.app.v6.data.bin + @$(OBJCOPY) --only-section .rodata -O binary $< eagle.app.v6.rodata.bin + @$(OBJCOPY) --only-section .irom0.text -O binary $< eagle.app.v6.irom0text.bin + + @echo "" + @echo "!!!" + +ifeq ($(app), 0) + @python ../tools/gen_appbin.py $< 0 $(mode) $(freqdiv) $(size_map) + @mv eagle.app.flash.bin ../bin/eagle.flash.bin + @mv eagle.app.v6.irom0text.bin ../bin/eagle.irom0text.bin + @rm eagle.app.v6.* + @echo "No boot needed." + @echo "Generate eagle.flash.bin and eagle.irom0text.bin successully in folder bin." + @echo "eagle.flash.bin-------->0x00000" + @echo "eagle.irom0text.bin---->0x40000" +else + ifneq ($(boot), new) + @python ../tools/gen_appbin.py $< 1 $(mode) $(freqdiv) $(size_map) + @echo "Support boot_v1.1 and +" + else + @python ../tools/gen_appbin.py $< 2 $(mode) $(freqdiv) $(size_map) + + ifeq ($(size_map), 6) + @echo "Support boot_v1.4 and +" + else + ifeq ($(size_map), 5) + @echo "Support boot_v1.4 and +" + else + @echo "Support boot_v1.2 and +" + endif + endif + endif + + @mv eagle.app.flash.bin ../bin/upgrade/$(BIN_NAME).bin + @rm eagle.app.v6.* + @echo "Generate $(BIN_NAME).bin successully in folder bin/upgrade." + @echo "boot.bin------------>0x00000" + @echo "$(BIN_NAME).bin--->$(addr)" +endif + + @echo "!!!" + +############################################################# +# Rules base +# Should be done in top-level makefile only +# + +all: .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS) + +clean: + $(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;) + $(RM) -r $(ODIR)/$(TARGET)/$(FLAVOR) + +clobber: $(SPECIAL_CLOBBER) + $(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clobber;) + $(RM) -r $(ODIR) + +.subdirs: + @set -e; $(foreach d, $(SUBDIRS), $(MAKE) -C $(d);) + +#.subdirs: +# $(foreach d, $(SUBDIRS), $(MAKE) -C $(d)) + +ifneq ($(MAKECMDGOALS),clean) +ifneq ($(MAKECMDGOALS),clobber) +ifdef DEPS +sinclude $(DEPS) +endif +endif +endif + +$(OBJODIR)/%.o: %.c + @mkdir -p $(OBJODIR); + $(CC) $(if $(findstring $<,$(DSRCS)),$(DFLAGS),$(CFLAGS)) $(COPTS_$(*F)) -o $@ -c $< + +$(OBJODIR)/%.d: %.c + @mkdir -p $(OBJODIR); + @echo DEPEND: $(CC) -M $(CFLAGS) $< + @set -e; rm -f $@; \ + $(CC) -M $(CFLAGS) $< > $@.$$$$; \ + sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +$(OBJODIR)/%.o: %.s + @mkdir -p $(OBJODIR); + $(CC) $(CFLAGS) -o $@ -c $< + +$(OBJODIR)/%.d: %.s + @mkdir -p $(OBJODIR); \ + set -e; rm -f $@; \ + $(CC) -M $(CFLAGS) $< > $@.$$$$; \ + sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +$(OBJODIR)/%.o: %.S + @mkdir -p $(OBJODIR); + $(CC) $(CFLAGS) -D__ASSEMBLER__ -o $@ -c $< + +$(OBJODIR)/%.d: %.S + @mkdir -p $(OBJODIR); \ + set -e; rm -f $@; \ + $(CC) -M $(CFLAGS) $< > $@.$$$$; \ + sed 's,\($*\.o\)[ :]*,$(OBJODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +$(foreach lib,$(GEN_LIBS),$(eval $(call ShortcutRule,$(lib),$(LIBODIR)))) + +$(foreach image,$(GEN_IMAGES),$(eval $(call ShortcutRule,$(image),$(IMAGEODIR)))) + +$(foreach bin,$(GEN_BINS),$(eval $(call ShortcutRule,$(bin),$(BINODIR)))) + +$(foreach lib,$(GEN_LIBS),$(eval $(call MakeLibrary,$(basename $(lib))))) + +$(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image))))) + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)include/$(TARGET) +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile diff --git a/esp_iot_sdk_v1.3.0/app/gen_misc.bat b/esp_iot_sdk_v1.3.0/app/gen_misc.bat new file mode 100644 index 0000000..8856e66 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/app/gen_misc.bat @@ -0,0 +1,147 @@ +@echo off + +echo gen_misc.bat version 20150511 +echo . + +echo Please follow below steps(1-5) to generate specific bin(s): +echo STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none) +set input=default +set /p input=enter(0/1/2, default 2): + +if %input% equ 0 ( + set boot=old +) else ( +if %input% equ 1 ( + set boot=new +) else ( + set boot=none +) +) + +echo boot mode: %boot% +echo. + +echo STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin) +set input=default +set /p input=enter (0/1/2, default 0): + +if %input% equ 1 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=1 + echo generate bin: user1.bin + ) +) else ( +if %input% equ 2 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=2 + echo generate bin: user2.bin + ) +) else ( + if %boot% neq none ( + set boot=none + echo ignore boot + ) + set app=0 + echo generate bin: eagle.flash.bin+eagle.irom0text.bin +)) + +echo. + +echo STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz) +set input=default +set /p input=enter (0/1/2/3, default 2): + +if %input% equ 0 ( + set spi_speed=20 +) else ( +if %input% equ 1 ( + set spi_speed=26.7 +) else ( +if %input% equ 3 ( + set spi_speed=80 +) else ( + set spi_speed=40 +))) + +echo spi speed: %spi_speed% MHz +echo. + +echo STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT) +set input=default +set /p input=enter (0/1/2/3, default 0): + +if %input% equ 1 ( + set spi_mode=QOUT +) else ( +if %input% equ 2 ( + set spi_mode=DIO +) else ( +if %input% equ 3 ( + set spi_mode=DOUT +) else ( + set spi_mode=QIO +))) + +echo spi mode: %spi_mode% +echo. + +echo STEP 5: choose flash 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) +set input=default +set /p input=enter (0/1/2/3/4/5/6, default 0): + +if %input% equ 2 ( + set spi_size_map=2 + echo spi size: 1024KB + echo spi ota map: 512KB + 512KB +) else ( + if %input% equ 3 ( + set spi_size_map=3 + echo spi size: 2048KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 4 ( + set spi_size_map=4 + echo spi size: 4096KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 5 ( + set spi_size_map=5 + echo spi size: 2048KB + echo spi ota map: 1024KB + 1024KB + ) else ( + if %input% equ 6 ( + set spi_size_map=6 + echo spi size: 4096KB + echo spi ota map: 1024KB + 1024KB + ) else ( + set spi_size_map=0 + echo spi size: 512KB + echo spi ota map: 256KB + 256KB + ) + ) + ) + ) +) + +touch user/user_main.c + +echo. +echo start... +echo. + +make BOOT=%boot% APP=%app% SPI_SPEED=%spi_speed% SPI_MODE=%spi_mode% SPI_SIZE=%spi_size_map% + diff --git a/esp_iot_sdk_v1.3.0/app/gen_misc.sh b/esp_iot_sdk_v1.3.0/app/gen_misc.sh new file mode 100644 index 0000000..1612cd9 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/app/gen_misc.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +echo "gen_misc.sh version 20150511" +echo "" + +echo "Please follow below steps(1-5) to generate specific bin(s):" +echo "STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none)" +echo "enter(0/1/2, default 2):" +read input + +if [ -z "$input" ]; then + boot=none +elif [ $input == 0 ]; then + boot=old +elif [ $input == 1 ]; then + boot=new +else + boot=none +fi + +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 "" + +touch user/user_main.c + +echo "" +echo "start..." +echo "" + +make COMPILE=gcc BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map diff --git a/esp_iot_sdk_v1.3.0/bin/at/eagle.flash.bin b/esp_iot_sdk_v1.3.0/bin/at/eagle.flash.bin new file mode 100644 index 0000000..2ad3d65 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/bin/at/eagle.flash.bin differ diff --git a/esp_iot_sdk_v1.3.0/bin/at/eagle.irom0text.bin b/esp_iot_sdk_v1.3.0/bin/at/eagle.irom0text.bin new file mode 100644 index 0000000..8316abe Binary files /dev/null and b/esp_iot_sdk_v1.3.0/bin/at/eagle.irom0text.bin differ diff --git a/esp_iot_sdk_v1.3.0/bin/at/readme.txt b/esp_iot_sdk_v1.3.0/bin/at/readme.txt new file mode 100644 index 0000000..841c367 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/bin/at/readme.txt @@ -0,0 +1,39 @@ +download: +boot_v1.2+.bin 0x00000 +user1.1024.new.2.bin 0x01000 +blank.bin 0x7e000 & 0xfe000 + +or + +eagle.flash.bin 0x00000 +eagle.irom0text.bin 0x40000 +blank.bin 0x7e000 & 0xfe000 + +*NOTICE*: +1.If you use Esp Flash Download Tool, please MAKE SURE to choose FLASH SIZE to 8Mbit. +2.UPDATE is not supported in non-boot mode + +Update steps +1.Make sure TE(terminal equipment) is in sta or sta+ap mode +ex. AT+CWMODE=3 + OK + + AT+RST + +2.Make sure TE got ip address +ex. AT+CWJAP="ssid","12345678" + OK + + AT+CIFSR + 192.168.1.134 + +3.Let's update +ex. AT+CIUPDATE + +CIPUPDATE:1 found server + +CIPUPDATE:2 connect server + +CIPUPDATE:3 got edition + +CIPUPDATE:4 start start + + OK + +note. If there are mistakes in the updating, then break update and print ERROR. \ No newline at end of file diff --git a/esp_iot_sdk_v1.3.0/bin/at/user1.1024.new.2.bin b/esp_iot_sdk_v1.3.0/bin/at/user1.1024.new.2.bin new file mode 100644 index 0000000..632c12b Binary files /dev/null and b/esp_iot_sdk_v1.3.0/bin/at/user1.1024.new.2.bin differ diff --git a/esp_iot_sdk_v1.3.0/bin/at/user2.1024.new.2.bin b/esp_iot_sdk_v1.3.0/bin/at/user2.1024.new.2.bin new file mode 100644 index 0000000..6a8ecba Binary files /dev/null and b/esp_iot_sdk_v1.3.0/bin/at/user2.1024.new.2.bin differ diff --git a/esp_iot_sdk_v1.3.0/bin/blank.bin b/esp_iot_sdk_v1.3.0/bin/blank.bin new file mode 100644 index 0000000..7de9e36 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/bin/blank.bin @@ -0,0 +1 @@ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ \ No newline at end of file diff --git a/esp_iot_sdk_v1.3.0/bin/boot_v1.2.bin b/esp_iot_sdk_v1.3.0/bin/boot_v1.2.bin new file mode 100644 index 0000000..78e1254 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/bin/boot_v1.2.bin differ diff --git a/esp_iot_sdk_v1.3.0/bin/boot_v1.4(b1).bin b/esp_iot_sdk_v1.3.0/bin/boot_v1.4(b1).bin new file mode 100644 index 0000000..7692abd Binary files /dev/null and b/esp_iot_sdk_v1.3.0/bin/boot_v1.4(b1).bin differ diff --git a/esp_iot_sdk_v1.3.0/bin/esp_init_data_default.bin b/esp_iot_sdk_v1.3.0/bin/esp_init_data_default.bin new file mode 100644 index 0000000..73d7453 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/bin/esp_init_data_default.bin differ diff --git a/esp_iot_sdk_v1.3.0/document/CN/2A-ESP8266__IOT_SDK_User_Manual__CN_v1.3.0.pdf b/esp_iot_sdk_v1.3.0/document/CN/2A-ESP8266__IOT_SDK_User_Manual__CN_v1.3.0.pdf new file mode 100644 index 0000000..fe7f5f8 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/CN/2A-ESP8266__IOT_SDK_User_Manual__CN_v1.3.0.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/CN/2B-ESP8266__SDK__IOT_Demo__CN_v0.6.pdf b/esp_iot_sdk_v1.3.0/document/CN/2B-ESP8266__SDK__IOT_Demo__CN_v0.6.pdf new file mode 100644 index 0000000..2d0b064 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/CN/2B-ESP8266__SDK__IOT_Demo__CN_v0.6.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/CN/2C-ESP8266__SDK__Programming Guide__CN_v1.3.0.pdf b/esp_iot_sdk_v1.3.0/document/CN/2C-ESP8266__SDK__Programming Guide__CN_v1.3.0.pdf new file mode 100644 index 0000000..33ec346 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/CN/2C-ESP8266__SDK__Programming Guide__CN_v1.3.0.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/CN/4A-ESP8266__AT Instruction Set__CN_v0.40.pdf b/esp_iot_sdk_v1.3.0/document/CN/4A-ESP8266__AT Instruction Set__CN_v0.40.pdf new file mode 100644 index 0000000..7f4e7f0 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/CN/4A-ESP8266__AT Instruction Set__CN_v0.40.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/CN/4B-ESP8266__AT Command Examples__CN_v0.6.pdf b/esp_iot_sdk_v1.3.0/document/CN/4B-ESP8266__AT Command Examples__CN_v0.6.pdf new file mode 100644 index 0000000..929a148 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/CN/4B-ESP8266__AT Command Examples__CN_v0.6.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/CN/5A-ESP8266__SDK__SSL_User_Manual__CN_v1.1.pdf b/esp_iot_sdk_v1.3.0/document/CN/5A-ESP8266__SDK__SSL_User_Manual__CN_v1.1.pdf new file mode 100644 index 0000000..79fed55 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/CN/5A-ESP8266__SDK__SSL_User_Manual__CN_v1.1.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/EN/2A-ESP8266__IOT_SDK_User_Manual__EN_v1.3.0.pdf b/esp_iot_sdk_v1.3.0/document/EN/2A-ESP8266__IOT_SDK_User_Manual__EN_v1.3.0.pdf new file mode 100644 index 0000000..3bbf9b3 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/EN/2A-ESP8266__IOT_SDK_User_Manual__EN_v1.3.0.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/EN/2B-ESP8266__SDK__IOT_Demo__EN_v0.6.pdf b/esp_iot_sdk_v1.3.0/document/EN/2B-ESP8266__SDK__IOT_Demo__EN_v0.6.pdf new file mode 100644 index 0000000..9dddd7a Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/EN/2B-ESP8266__SDK__IOT_Demo__EN_v0.6.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/EN/2C-ESP8266__SDK__Programming Guide__EN_v1.3.0.pdf b/esp_iot_sdk_v1.3.0/document/EN/2C-ESP8266__SDK__Programming Guide__EN_v1.3.0.pdf new file mode 100644 index 0000000..de6bd2e Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/EN/2C-ESP8266__SDK__Programming Guide__EN_v1.3.0.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/EN/4A-ESP8266__AT Instruction Set__EN_v0.40.pdf b/esp_iot_sdk_v1.3.0/document/EN/4A-ESP8266__AT Instruction Set__EN_v0.40.pdf new file mode 100644 index 0000000..3479b77 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/EN/4A-ESP8266__AT Instruction Set__EN_v0.40.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/EN/4B-ESP8266__AT Command Examples__EN_v0.6.pdf b/esp_iot_sdk_v1.3.0/document/EN/4B-ESP8266__AT Command Examples__EN_v0.6.pdf new file mode 100644 index 0000000..1fbffec Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/EN/4B-ESP8266__AT Command Examples__EN_v0.6.pdf differ diff --git a/esp_iot_sdk_v1.3.0/document/EN/5A-ESP8266__SDK__SSL_User_Manual__EN_v1.1.pdf b/esp_iot_sdk_v1.3.0/document/EN/5A-ESP8266__SDK__SSL_User_Manual__EN_v1.1.pdf new file mode 100644 index 0000000..aef8c45 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/document/EN/5A-ESP8266__SDK__SSL_User_Manual__EN_v1.1.pdf differ diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/Makefile b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/Makefile new file mode 100644 index 0000000..758796e --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/Makefile @@ -0,0 +1,125 @@ +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of object file images to be generated () +# GEN_BINS - list of binaries to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +TARGET = eagle +#FLAVOR = release +FLAVOR = debug + +#EXTRA_CCFLAGS += -u + +ifndef PDIR # { +GEN_IMAGES= eagle.app.v6.out +GEN_BINS= eagle.app.v6.bin +SPECIAL_MKTARGETS=$(APP_MKTARGETS) +SUBDIRS= \ + user \ + driver + +endif # } PDIR + +APPDIR = . +LDDIR = ../ld + +CCFLAGS += -Os + +TARGET_LDFLAGS = \ + -nostdlib \ + -Wl,-EL \ + --longcalls \ + --text-section-literals + +ifeq ($(FLAVOR),debug) + TARGET_LDFLAGS += -g -O2 +endif + +ifeq ($(FLAVOR),release) + TARGET_LDFLAGS += -g -O0 +endif + +COMPONENTS_eagle.app.v6 = \ + user/libuser.a \ + driver/libdriver.a + +LINKFLAGS_eagle.app.v6 = \ + -L../lib \ + -nostdlib \ + -T$(LD_FILE) \ + -Wl,--no-check-sections \ + -u call_user_start \ + -Wl,-static \ + -Wl,--start-group \ + -lc \ + -lgcc \ + -lhal \ + -lphy \ + -lpp \ + -lnet80211 \ + -llwip \ + -lwpa \ + -lmain \ + -ljson \ + -lupgrade\ + -lssl \ + -lpwm \ + -lsmartconfig \ + $(DEP_LIBS_eagle.app.v6) \ + -Wl,--end-group + +DEPENDS_eagle.app.v6 = \ + $(LD_FILE) \ + $(LDDIR)/eagle.rom.addr.v6.ld + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# + +#UNIVERSAL_TARGET_DEFINES = \ + +# Other potential configuration flags include: +# -DTXRX_TXBUF_DEBUG +# -DTXRX_RXBUF_DEBUG +# -DWLAN_CONFIG_CCX +CONFIGURATION_DEFINES = -DICACHE_FLASH + +DEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + +DDEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + +.PHONY: FORCE +FORCE: + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/driver/Makefile b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/driver/Makefile new file mode 100644 index 0000000..ffdb4d0 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/driver/Makefile @@ -0,0 +1,44 @@ + +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of images to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +ifndef PDIR +GEN_LIBS = libdriver.a +endif + + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# +#DEFINES += + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I ./ +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/driver/i2c_master.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/driver/i2c_master.c new file mode 100644 index 0000000..b12e3e5 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/driver/i2c_master.c @@ -0,0 +1,316 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: i2c_master.c + * + * Description: i2c master API + * + * Modification history: + * 2014/3/12, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "osapi.h" +#include "gpio.h" + +#include "driver/i2c_master.h" + +LOCAL uint8 m_nLastSDA; +LOCAL uint8 m_nLastSCL; + +/****************************************************************************** + * FunctionName : i2c_master_setDC + * Description : Internal used function - + * set i2c SDA and SCL bit value for half clk cycle + * Parameters : uint8 SDA + * uint8 SCL + * Returns : NONE +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +i2c_master_setDC(uint8 SDA, uint8 SCL) +{ + SDA &= 0x01; + SCL &= 0x01; + m_nLastSDA = SDA; + m_nLastSCL = SCL; + + if ((0 == SDA) && (0 == SCL)) { + I2C_MASTER_SDA_LOW_SCL_LOW(); + } else if ((0 == SDA) && (1 == SCL)) { + I2C_MASTER_SDA_LOW_SCL_HIGH(); + } else if ((1 == SDA) && (0 == SCL)) { + I2C_MASTER_SDA_HIGH_SCL_LOW(); + } else { + I2C_MASTER_SDA_HIGH_SCL_HIGH(); + } +} + +/****************************************************************************** + * FunctionName : i2c_master_getDC + * Description : Internal used function - + * get i2c SDA bit value + * Parameters : NONE + * Returns : uint8 - SDA bit value +*******************************************************************************/ +LOCAL uint8 ICACHE_FLASH_ATTR +i2c_master_getDC(void) +{ + uint8 sda_out; + sda_out = GPIO_INPUT_GET(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)); + return sda_out; +} + +/****************************************************************************** + * FunctionName : i2c_master_init + * Description : initilize I2C bus to enable i2c operations + * Parameters : NONE + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_init(void) +{ + uint8 i; + + i2c_master_setDC(1, 0); + i2c_master_wait(5); + + // when SCL = 0, toggle SDA to clear up + i2c_master_setDC(0, 0) ; + i2c_master_wait(5); + i2c_master_setDC(1, 0) ; + i2c_master_wait(5); + + // set data_cnt to max value + for (i = 0; i < 28; i++) { + i2c_master_setDC(1, 0); + i2c_master_wait(5); // sda 1, scl 0 + i2c_master_setDC(1, 1); + i2c_master_wait(5); // sda 1, scl 1 + } + + // reset all + i2c_master_stop(); + return; +} + +/****************************************************************************** + * FunctionName : i2c_master_gpio_init + * Description : config SDA and SCL gpio to open-drain output mode, + * mux and gpio num defined in i2c_master.h + * Parameters : NONE + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_gpio_init(void) +{ + ETS_GPIO_INTR_DISABLE() ; +// ETS_INTR_LOCK(); + + PIN_FUNC_SELECT(I2C_MASTER_SDA_MUX, I2C_MASTER_SDA_FUNC); + PIN_FUNC_SELECT(I2C_MASTER_SCL_MUX, I2C_MASTER_SCL_FUNC); + + GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain; + GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SDA_GPIO)); + GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain; + GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SCL_GPIO)); + + I2C_MASTER_SDA_HIGH_SCL_HIGH(); + + ETS_GPIO_INTR_ENABLE() ; +// ETS_INTR_UNLOCK(); + + i2c_master_init(); +} + +/****************************************************************************** + * FunctionName : i2c_master_start + * Description : set i2c to send state + * Parameters : NONE + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_start(void) +{ + i2c_master_setDC(1, m_nLastSCL); + i2c_master_wait(5); + i2c_master_setDC(1, 1); + i2c_master_wait(5); // sda 1, scl 1 + i2c_master_setDC(0, 1); + i2c_master_wait(5); // sda 0, scl 1 +} + +/****************************************************************************** + * FunctionName : i2c_master_stop + * Description : set i2c to stop sending state + * Parameters : NONE + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_stop(void) +{ + i2c_master_wait(5); + + i2c_master_setDC(0, m_nLastSCL); + i2c_master_wait(5); // sda 0 + i2c_master_setDC(0, 1); + i2c_master_wait(5); // sda 0, scl 1 + i2c_master_setDC(1, 1); + i2c_master_wait(5); // sda 1, scl 1 +} + +/****************************************************************************** + * FunctionName : i2c_master_setAck + * Description : set ack to i2c bus as level value + * Parameters : uint8 level - 0 or 1 + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_setAck(uint8 level) +{ + i2c_master_setDC(m_nLastSDA, 0); + i2c_master_wait(5); + i2c_master_setDC(level, 0); + i2c_master_wait(5); // sda level, scl 0 + i2c_master_setDC(level, 1); + i2c_master_wait(8); // sda level, scl 1 + i2c_master_setDC(level, 0); + i2c_master_wait(5); // sda level, scl 0 + i2c_master_setDC(1, 0); + i2c_master_wait(5); +} + +/****************************************************************************** + * FunctionName : i2c_master_getAck + * Description : confirm if peer send ack + * Parameters : NONE + * Returns : uint8 - ack value, 0 or 1 +*******************************************************************************/ +uint8 ICACHE_FLASH_ATTR +i2c_master_getAck(void) +{ + uint8 retVal; + i2c_master_setDC(m_nLastSDA, 0); + i2c_master_wait(5); + i2c_master_setDC(1, 0); + i2c_master_wait(5); + i2c_master_setDC(1, 1); + i2c_master_wait(5); + + retVal = i2c_master_getDC(); + i2c_master_wait(5); + i2c_master_setDC(1, 0); + i2c_master_wait(5); + + return retVal; +} + +/****************************************************************************** +* FunctionName : i2c_master_checkAck +* Description : get dev response +* Parameters : NONE +* Returns : true : get ack ; false : get nack +*******************************************************************************/ +bool ICACHE_FLASH_ATTR +i2c_master_checkAck(void) +{ + if(i2c_master_getAck()){ + return FALSE; + }else{ + return TRUE; + } +} + +/****************************************************************************** +* FunctionName : i2c_master_send_ack +* Description : response ack +* Parameters : NONE +* Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_send_ack(void) +{ + i2c_master_setAck(0x0); +} +/****************************************************************************** +* FunctionName : i2c_master_send_nack +* Description : response nack +* Parameters : NONE +* Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_send_nack(void) +{ + i2c_master_setAck(0x1); +} + +/****************************************************************************** + * FunctionName : i2c_master_readByte + * Description : read Byte from i2c bus + * Parameters : NONE + * Returns : uint8 - readed value +*******************************************************************************/ +uint8 ICACHE_FLASH_ATTR +i2c_master_readByte(void) +{ + uint8 retVal = 0; + uint8 k, i; + + i2c_master_wait(5); + i2c_master_setDC(m_nLastSDA, 0); + i2c_master_wait(5); // sda 1, scl 0 + + for (i = 0; i < 8; i++) { + i2c_master_wait(5); + i2c_master_setDC(1, 0); + i2c_master_wait(5); // sda 1, scl 0 + i2c_master_setDC(1, 1); + i2c_master_wait(5); // sda 1, scl 1 + + k = i2c_master_getDC(); + i2c_master_wait(5); + + if (i == 7) { + i2c_master_wait(3); //// + } + + k <<= (7 - i); + retVal |= k; + } + + i2c_master_setDC(1, 0); + i2c_master_wait(5); // sda 1, scl 0 + + return retVal; +} + +/****************************************************************************** + * FunctionName : i2c_master_writeByte + * Description : write wrdata value(one byte) into i2c + * Parameters : uint8 wrdata - write value + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_writeByte(uint8 wrdata) +{ + uint8 dat; + sint8 i; + + i2c_master_wait(5); + + i2c_master_setDC(m_nLastSDA, 0); + i2c_master_wait(5); + + for (i = 7; i >= 0; i--) { + dat = wrdata >> i; + i2c_master_setDC(dat, 0); + i2c_master_wait(5); + i2c_master_setDC(dat, 1); + i2c_master_wait(5); + + if (i == 0) { + i2c_master_wait(3); //// + } + + i2c_master_setDC(dat, 0); + i2c_master_wait(5); + } +} diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/driver/key.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/driver/key.c new file mode 100644 index 0000000..1b2d0df --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/driver/key.c @@ -0,0 +1,162 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: key.c + * + * Description: key driver, now can use different gpio and install different function + * + * Modification history: + * 2014/5/1, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "os_type.h" +#include "osapi.h" +#include "mem.h" +#include "gpio.h" +#include "user_interface.h" + +#include "driver/key.h" + +LOCAL void key_intr_handler(struct keys_param *keys); + +/****************************************************************************** + * FunctionName : key_init_single + * Description : init single key's gpio and register function + * Parameters : uint8 gpio_id - which gpio to use + * uint32 gpio_name - gpio mux name + * uint32 gpio_func - gpio function + * key_function long_press - long press function, needed to install + * key_function short_press - short press function, needed to install + * Returns : single_key_param - single key parameter, needed by key init +*******************************************************************************/ +struct single_key_param *ICACHE_FLASH_ATTR +key_init_single(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func, key_function long_press, key_function short_press) +{ + struct single_key_param *single_key = (struct single_key_param *)os_zalloc(sizeof(struct single_key_param)); + + single_key->gpio_id = gpio_id; + single_key->gpio_name = gpio_name; + single_key->gpio_func = gpio_func; + single_key->long_press = long_press; + single_key->short_press = short_press; + + return single_key; +} + +/****************************************************************************** + * FunctionName : key_init + * Description : init keys + * Parameters : key_param *keys - keys parameter, which inited by key_init_single + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +key_init(struct keys_param *keys) +{ + uint8 i; + + ETS_GPIO_INTR_ATTACH(key_intr_handler, keys); + + ETS_GPIO_INTR_DISABLE(); + + for (i = 0; i < keys->key_num; i++) { + keys->single_key[i]->key_level = 1; + + PIN_FUNC_SELECT(keys->single_key[i]->gpio_name, keys->single_key[i]->gpio_func); + + gpio_output_set(0, 0, 0, GPIO_ID_PIN(keys->single_key[i]->gpio_id)); + + gpio_register_set(GPIO_PIN_ADDR(keys->single_key[i]->gpio_id), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) + | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) + | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)); + + //clear gpio14 status + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(keys->single_key[i]->gpio_id)); + + //enable interrupt + gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_NEGEDGE); + } + + ETS_GPIO_INTR_ENABLE(); +} + +/****************************************************************************** + * FunctionName : key_5s_cb + * Description : long press 5s timer callback + * Parameters : single_key_param *single_key - single key parameter + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +key_5s_cb(struct single_key_param *single_key) +{ + os_timer_disarm(&single_key->key_5s); + + // low, then restart + if (0 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { + if (single_key->long_press) { + single_key->long_press(); + } + } +} + +/****************************************************************************** + * FunctionName : key_50ms_cb + * Description : 50ms timer callback to check it's a real key push + * Parameters : single_key_param *single_key - single key parameter + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +key_50ms_cb(struct single_key_param *single_key) +{ + os_timer_disarm(&single_key->key_50ms); + + // high, then key is up + if (1 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { + os_timer_disarm(&single_key->key_5s); + single_key->key_level = 1; + gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_NEGEDGE); + + if (single_key->short_press) { + single_key->short_press(); + } + } else { + gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_POSEDGE); + } +} + +/****************************************************************************** + * FunctionName : key_intr_handler + * Description : key interrupt handler + * Parameters : key_param *keys - keys parameter, which inited by key_init_single + * Returns : none +*******************************************************************************/ +LOCAL void +key_intr_handler(struct keys_param *keys) +{ + uint8 i; + uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); + + for (i = 0; i < keys->key_num; i++) { + if (gpio_status & BIT(keys->single_key[i]->gpio_id)) { + //disable interrupt + gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_DISABLE); + + //clear interrupt status + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(keys->single_key[i]->gpio_id)); + + if (keys->single_key[i]->key_level == 1) { + // 5s, restart & enter softap mode + os_timer_disarm(&keys->single_key[i]->key_5s); + os_timer_setfn(&keys->single_key[i]->key_5s, (os_timer_func_t *)key_5s_cb, keys->single_key[i]); + os_timer_arm(&keys->single_key[i]->key_5s, 5000, 0); + keys->single_key[i]->key_level = 0; + gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_POSEDGE); + } else { + // 50ms, check if this is a real key up + os_timer_disarm(&keys->single_key[i]->key_50ms); + os_timer_setfn(&keys->single_key[i]->key_50ms, (os_timer_func_t *)key_50ms_cb, keys->single_key[i]); + os_timer_arm(&keys->single_key[i]->key_50ms, 50, 0); + } + } + } +} + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/gen_misc.bat b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/gen_misc.bat new file mode 100644 index 0000000..8856e66 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/gen_misc.bat @@ -0,0 +1,147 @@ +@echo off + +echo gen_misc.bat version 20150511 +echo . + +echo Please follow below steps(1-5) to generate specific bin(s): +echo STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none) +set input=default +set /p input=enter(0/1/2, default 2): + +if %input% equ 0 ( + set boot=old +) else ( +if %input% equ 1 ( + set boot=new +) else ( + set boot=none +) +) + +echo boot mode: %boot% +echo. + +echo STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin) +set input=default +set /p input=enter (0/1/2, default 0): + +if %input% equ 1 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=1 + echo generate bin: user1.bin + ) +) else ( +if %input% equ 2 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=2 + echo generate bin: user2.bin + ) +) else ( + if %boot% neq none ( + set boot=none + echo ignore boot + ) + set app=0 + echo generate bin: eagle.flash.bin+eagle.irom0text.bin +)) + +echo. + +echo STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz) +set input=default +set /p input=enter (0/1/2/3, default 2): + +if %input% equ 0 ( + set spi_speed=20 +) else ( +if %input% equ 1 ( + set spi_speed=26.7 +) else ( +if %input% equ 3 ( + set spi_speed=80 +) else ( + set spi_speed=40 +))) + +echo spi speed: %spi_speed% MHz +echo. + +echo STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT) +set input=default +set /p input=enter (0/1/2/3, default 0): + +if %input% equ 1 ( + set spi_mode=QOUT +) else ( +if %input% equ 2 ( + set spi_mode=DIO +) else ( +if %input% equ 3 ( + set spi_mode=DOUT +) else ( + set spi_mode=QIO +))) + +echo spi mode: %spi_mode% +echo. + +echo STEP 5: choose flash 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) +set input=default +set /p input=enter (0/1/2/3/4/5/6, default 0): + +if %input% equ 2 ( + set spi_size_map=2 + echo spi size: 1024KB + echo spi ota map: 512KB + 512KB +) else ( + if %input% equ 3 ( + set spi_size_map=3 + echo spi size: 2048KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 4 ( + set spi_size_map=4 + echo spi size: 4096KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 5 ( + set spi_size_map=5 + echo spi size: 2048KB + echo spi ota map: 1024KB + 1024KB + ) else ( + if %input% equ 6 ( + set spi_size_map=6 + echo spi size: 4096KB + echo spi ota map: 1024KB + 1024KB + ) else ( + set spi_size_map=0 + echo spi size: 512KB + echo spi ota map: 256KB + 256KB + ) + ) + ) + ) +) + +touch user/user_main.c + +echo. +echo start... +echo. + +make BOOT=%boot% APP=%app% SPI_SPEED=%spi_speed% SPI_MODE=%spi_mode% SPI_SIZE=%spi_size_map% + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/gen_misc.sh b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/gen_misc.sh new file mode 100644 index 0000000..1612cd9 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/gen_misc.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +echo "gen_misc.sh version 20150511" +echo "" + +echo "Please follow below steps(1-5) to generate specific bin(s):" +echo "STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none)" +echo "enter(0/1/2, default 2):" +read input + +if [ -z "$input" ]; then + boot=none +elif [ $input == 0 ]; then + boot=old +elif [ $input == 1 ]; then + boot=new +else + boot=none +fi + +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 "" + +touch user/user_main.c + +echo "" +echo "start..." +echo "" + +make COMPILE=gcc BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/driver/i2c_master.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/driver/i2c_master.h new file mode 100644 index 0000000..7455add --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/driver/i2c_master.h @@ -0,0 +1,57 @@ +#ifndef __I2C_MASTER_H__ +#define __I2C_MASTER_H__ + +#define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U +#define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_MTMS_U +#define I2C_MASTER_SDA_GPIO 2 +#define I2C_MASTER_SCL_GPIO 14 +#define I2C_MASTER_SDA_FUNC FUNC_GPIO2 +#define I2C_MASTER_SCL_FUNC FUNC_GPIO14 + +//#define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U +//#define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_GPIO0_U +//#define I2C_MASTER_SDA_GPIO 2 +//#define I2C_MASTER_SCL_GPIO 0 +//#define I2C_MASTER_SDA_FUNC FUNC_GPIO2 +//#define I2C_MASTER_SCL_FUNC FUNC_GPIO0 + +#if 0 +#define I2C_MASTER_GPIO_SET(pin) \ + gpio_output_set(1<L<@i&Nxe!" +#endif + +#if SENSOR_DEVICE +#define SENSOR_DEEP_SLEEP + +#if HUMITURE_SUB_DEVICE +#define SENSOR_DEEP_SLEEP_TIME 30000000 +#elif FLAMMABLE_GAS_SUB_DEVICE +#define SENSOR_DEEP_SLEEP_TIME 60000000 +#endif +#endif + +#if LIGHT_DEVICE +#define USE_US_TIMER +#endif + +#if PLUG_DEVICE || LIGHT_DEVICE +#define BEACON_TIMEOUT 150000000 +#define BEACON_TIME 50000 +#endif + +#define AP_CACHE 1 + +#if AP_CACHE +#define AP_CACHE_NUMBER 5 +#endif + +#elif LEWEI_PLATFORM +#endif + +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_devicefind.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_devicefind.h new file mode 100644 index 0000000..d88ce8c --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_devicefind.h @@ -0,0 +1,6 @@ +#ifndef __USER_DEVICEFIND_H__ +#define __USER_DEVICEFIND_H__ + +void user_devicefind_init(void); + +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_esp_platform.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_esp_platform.h new file mode 100644 index 0000000..fdfbb66 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_esp_platform.h @@ -0,0 +1,33 @@ +#ifndef __USER_DEVICE_H__ +#define __USER_DEVICE_H__ + +/* NOTICE---this is for 512KB spi flash. + * you can change to other sector if you use other size spi flash. */ +#define ESP_PARAM_START_SEC 0x3D + +#define packet_size (2 * 1024) + +#define token_size 41 + +struct esp_platform_saved_param { + uint8 devkey[40]; + uint8 token[40]; + uint8 activeflag; + uint8 pad[3]; +}; + +enum { + DEVICE_CONNECTING = 40, + DEVICE_ACTIVE_DONE, + DEVICE_ACTIVE_FAIL, + DEVICE_CONNECT_SERVER_FAIL +}; + +struct dhcp_client_info { + ip_addr_t ip_addr; + ip_addr_t netmask; + ip_addr_t gw; + uint8 flag; + uint8 pad[3]; +}; +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_esp_platform_timer.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_esp_platform_timer.h new file mode 100644 index 0000000..7a319bd --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_esp_platform_timer.h @@ -0,0 +1,6 @@ +#ifndef __USER_DEVICEFIND_H__ +#define __USER_DEVICEFIND_H__ + +void user_platform_timer_start(char* pbuffer, struct espconn *pespconn); + +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_iot_version.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_iot_version.h new file mode 100644 index 0000000..7c86586 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_iot_version.h @@ -0,0 +1,43 @@ +#ifndef __USER_IOT_VERSION_H__ +#define __USER_IOT_VERSION_H__ + +#include "user_config.h" + +#define IOT_VERSION_MAJOR 1U +#define IOT_VERSION_MINOR 0U +#define IOT_VERSION_REVISION 5U + +#define VERSION_NUM (IOT_VERSION_MAJOR * 1000 + IOT_VERSION_MINOR * 100 + IOT_VERSION_REVISION) + +//#define VERSION_TYPE "b" +#define VERSION_TYPE "v" + +#if LIGHT_DEVICE +#define device_type 45772 +#elif PLUG_DEVICE +#define device_type 23701 +#elif SENSOR_DEVICE +#define device_type 12335 +#endif + + +#define ONLINE_UPGRADE 0 +#define LOCAL_UPGRADE 0 +#define ALL_UPGRADE 1 +#define NONE_UPGRADE 0 + +#if ONLINE_UPGRADE +#define UPGRADE_FALG "O" +#elif LOCAL_UPGRADE +#define UPGRADE_FALG "l" +#elif ALL_UPGRADE +#define UPGRADE_FALG "a" +#elif NONE_UPGRADE +#define UPGRADE_FALG "n" +#endif + +#define IOT_VERSION + + +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_json.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_json.h new file mode 100644 index 0000000..e8aa936 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_json.h @@ -0,0 +1,17 @@ +#ifndef __USER_JSON_H__ +#define __USER_JSON_H__ + +#include "json/jsonparse.h" +#include "json/jsontree.h" + +#define jsonSize 2*1024 + +void json_parse(struct jsontree_context *json, char *ptrJSONMessage); + +void json_ws_send(struct jsontree_value *tree, const char *path, char *pbuf); + +int json_putchar(int c); + +struct jsontree_value *find_json_path(struct jsontree_context *json, const char *path); + +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_light.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_light.h new file mode 100644 index 0000000..2c628a9 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_light.h @@ -0,0 +1,64 @@ +#ifndef __USER_LIGHT_H__ +#define __USER_LIGHT_H__ +/*pwm.h: function and macro definition of PWM API , driver level */ +/*user_light.h: user interface for light API, user level*/ +/*user_light_adj: API for color changing and lighting effects, user level*/ + + +#include "pwm.h" + + +/* NOTICE !!! ---this is for 512KB spi flash.*/ +/* You can change to other sector if you use other size spi flash. */ +/* Refer to the documentation about OTA support and flash mapping*/ +#define PRIV_PARAM_START_SEC 0x3C +#define PRIV_PARAM_SAVE 0 + + + +/*Define the channel number of PWM*/ +/*In this demo, we can set 3 for 3 PWM channels: RED, GREEN, BLUE*/ +/*Or , we can choose 5 channels : RED,GREEN,BLUE,COLD-WHITE,WARM-WHITE*/ +#define PWM_CHANNEL 5 // 5:5channel ; 3:3channel + +#define LIGHT_RED 0 +#define LIGHT_GREEN 1 +#define LIGHT_BLUE 2 +#define LIGHT_COLD_WHITE 3 +#define LIGHT_WARM_WHITE 4 + + +/*Definition of GPIO PIN params, for GPIO initialization*/ +#define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_MTDI_U +#define PWM_0_OUT_IO_NUM 12 +#define PWM_0_OUT_IO_FUNC FUNC_GPIO12 + +#define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTDO_U +#define PWM_1_OUT_IO_NUM 15 +#define PWM_1_OUT_IO_FUNC FUNC_GPIO15 + +#define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U +#define PWM_2_OUT_IO_NUM 13 +#define PWM_2_OUT_IO_FUNC FUNC_GPIO13 + +#define PWM_3_OUT_IO_MUX PERIPHS_IO_MUX_MTMS_U +#define PWM_3_OUT_IO_NUM 14 +#define PWM_3_OUT_IO_FUNC FUNC_GPIO14 + +#define PWM_4_OUT_IO_MUX PERIPHS_IO_MUX_GPIO5_U +#define PWM_4_OUT_IO_NUM 5 +#define PWM_4_OUT_IO_FUNC FUNC_GPIO5 + +struct light_saved_param { + uint32 pwm_period; + uint32 pwm_duty[PWM_CHANNEL]; +}; + +void user_light_init(void); +uint32 user_light_get_duty(uint8 channel); +void user_light_set_duty(uint32 duty, uint8 channel); +uint32 user_light_get_period(void); +void user_light_set_period(uint32 period); + +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_light_adj.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_light_adj.h new file mode 100644 index 0000000..4997aec --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_light_adj.h @@ -0,0 +1,33 @@ +#ifndef __USER_LIGHT_ADJ_H__ +#define __USER_LIGHT_ADJ_H__ +/*pwm.h: function and macro definition of PWM API , driver level */ +/*user_light.h: user interface for light setting, user level*/ +/*user_light_adj: API for color changing and lighting effects, user level*/ + + + + +/*save RGB params to flash when calling light_set_aim*/ +#define SAVE_LIGHT_PARAM 0 //set to 0: do not save color params + +/*check current consumption and limit the total current for LED driver IC*/ +/*NOTE: YOU SHOULD REPLACE WIHT THE LIMIT CURRENT OF YOUR OWN APPLICATION*/ +#define LIGHT_CURRENT_LIMIT 0 //set to 0: do not limit total current +#if LIGHT_CURRENT_LIMIT +#define LIGHT_TOTAL_CURRENT_MAX (450*1000) //450000/1000 MA AT MOST +#define LIGHT_CURRENT_MARGIN (80*1000) //80000/1000 MA CURRENT RAISES WHILE TEMPERATURE INCREASING +#define LIGHT_CURRENT_MARGIN_L2 (110*1000) //110000/1000 MA +#define LIGHT_CURRENT_MARGIN_L3 (140*1000) //140000/1000 MA +#endif + + +/*set target duty for PWM channels, change each channel duty gradually */ +void light_set_aim(uint32 r,uint32 g,uint32 b,uint32 cw,uint32 ww,uint32 period);//'white' channel is not used in default demo +void light_set_aim_r(uint32 r); +void light_set_aim_g(uint32 g); +void light_set_aim_b(uint32 b); +void light_set_aim_cw(uint32 cw); +void light_set_aim_ww(uint32 ww); + +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_plug.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_plug.h new file mode 100644 index 0000000..4e626a7 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_plug.h @@ -0,0 +1,43 @@ +#ifndef __USER_ESPSWITCH_H__ +#define __USER_ESPSWITCH_H__ + +#include "driver/key.h" + +/* NOTICE---this is for 512KB spi flash. + * you can change to other sector if you use other size spi flash. */ +#define PRIV_PARAM_START_SEC 0x3C + +#define PRIV_PARAM_SAVE 0 + +#define PLUG_KEY_NUM 1 + +#define PLUG_KEY_0_IO_MUX PERIPHS_IO_MUX_MTCK_U +#define PLUG_KEY_0_IO_NUM 13 +#define PLUG_KEY_0_IO_FUNC FUNC_GPIO13 + +#define PLUG_WIFI_LED_IO_MUX PERIPHS_IO_MUX_GPIO0_U +#define PLUG_WIFI_LED_IO_NUM 0 +#define PLUG_WIFI_LED_IO_FUNC FUNC_GPIO0 + +#define PLUG_LINK_LED_IO_MUX PERIPHS_IO_MUX_MTDI_U +#define PLUG_LINK_LED_IO_NUM 12 +#define PLUG_LINK_LED_IO_FUNC FUNC_GPIO12 + +#define PLUG_RELAY_LED_IO_MUX PERIPHS_IO_MUX_MTDO_U +#define PLUG_RELAY_LED_IO_NUM 15 +#define PLUG_RELAY_LED_IO_FUNC FUNC_GPIO15 + +#define PLUG_STATUS_OUTPUT(pin, on) GPIO_OUTPUT_SET(pin, on) + +struct plug_saved_param { + uint8_t status; + uint8_t pad[3]; +}; + +void user_plug_init(void); +uint8 user_plug_get_status(void); +void user_plug_set_status(bool status); + + +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_sensor.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_sensor.h new file mode 100644 index 0000000..940564d --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_sensor.h @@ -0,0 +1,32 @@ +#ifndef __USER_SENSOR_H__ +#define __USER_SENSOR_H__ + +#include "user_config.h" +#include "driver/key.h" + +#define SENSOR_KEY_NUM 1 + +#define SENSOR_KEY_IO_MUX PERIPHS_IO_MUX_MTCK_U +#define SENSOR_KEY_IO_NUM 13 +#define SENSOR_KEY_IO_FUNC FUNC_GPIO13 + +#define SENSOR_WIFI_LED_IO_MUX PERIPHS_IO_MUX_GPIO0_U +#define SENSOR_WIFI_LED_IO_NUM 0 +#define SENSOR_WIFI_LED_IO_FUNC FUNC_GPIO0 + +#define SENSOR_LINK_LED_IO_MUX PERIPHS_IO_MUX_MTDI_U +#define SENSOR_LINK_LED_IO_NUM 12 +#define SENSOR_LINK_LED_IO_FUNC FUNC_GPIO12 + +#define SENSOR_UNUSED_LED_IO_MUX PERIPHS_IO_MUX_MTDO_U +#define SENSOR_UNUSED_LED_IO_NUM 15 +#define SENSOR_UNUSED_LED_IO_FUNC FUNC_GPIO15 + +#if HUMITURE_SUB_DEVICE +bool user_mvh3004_read_th(uint8 *data); +void user_mvh3004_init(void); +#endif + +void user_sensor_init(uint8 active); + +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_webserver.h b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_webserver.h new file mode 100644 index 0000000..3db88fa --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/include/user_webserver.h @@ -0,0 +1,45 @@ +#ifndef __USER_WEBSERVER_H__ +#define __USER_WEBSERVER_H__ + +#define SERVER_PORT 80 +#define SERVER_SSL_PORT 443 + +#define URLSize 10 + +typedef enum Result_Resp { + RespFail = 0, + RespSuc, +} Result_Resp; + +typedef enum ProtocolType { + GET = 0, + POST, +} ProtocolType; + +typedef enum _ParmType { + SWITCH_STATUS = 0, + INFOMATION, + WIFI, + SCAN, + REBOOT, + DEEP_SLEEP, + LIGHT_STATUS, + CONNECT_STATUS, + USER_BIN +} ParmType; + +typedef struct URL_Frame { + enum ProtocolType Type; + char pSelect[URLSize]; + char pCommand[URLSize]; + char pFilename[URLSize]; +} URL_Frame; + +typedef struct _rst_parm { + ParmType parmtype; + struct espconn *pespconn; +} rst_parm; + +void user_webserver_init(uint32 port); + +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/Makefile b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/Makefile new file mode 100644 index 0000000..5795e20 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/Makefile @@ -0,0 +1,45 @@ + +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of images to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +ifndef PDIR +GEN_LIBS = libuser.a +endif + + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# +#DEFINES += + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I ./ +INCLUDES += -I ../../include/ets +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_devicefind.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_devicefind.c new file mode 100644 index 0000000..8987978 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_devicefind.c @@ -0,0 +1,112 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_devicefind.c + * + * Description: Find your hardware's information while working any mode. + * + * Modification history: + * 2014/3/12, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "os_type.h" +#include "osapi.h" +#include "mem.h" +#include "user_interface.h" + +#include "espconn.h" +#include "user_json.h" +#include "user_devicefind.h" + +const char *device_find_request = "Are You Espressif IOT Smart Device?"; +#if PLUG_DEVICE +const char *device_find_response_ok = "I'm Plug."; +#elif LIGHT_DEVICE +const char *device_find_response_ok = "I'm Light."; +#elif SENSOR_DEVICE +#if HUMITURE_SUB_DEVICE +const char *device_find_response_ok = "I'm Humiture."; +#elif FLAMMABLE_GAS_SUB_DEVICE +const char *device_find_response_ok = "I'm Flammable Gas."; +#endif +#endif + +/*---------------------------------------------------------------------------*/ +LOCAL struct espconn ptrespconn; + +/****************************************************************************** + * FunctionName : user_devicefind_recv + * Description : Processing the received data from the host + * Parameters : arg -- Additional argument to pass to the callback function + * pusrdata -- The received data (or NULL when the connection has been closed!) + * length -- The length of received data + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_devicefind_recv(void *arg, char *pusrdata, unsigned short length) +{ + char DeviceBuffer[40] = {0}; + char Device_mac_buffer[60] = {0}; + char hwaddr[6]; + + struct ip_info ipconfig; + + if (wifi_get_opmode() != STATION_MODE) { + wifi_get_ip_info(SOFTAP_IF, &ipconfig); + wifi_get_macaddr(SOFTAP_IF, hwaddr); + + if (!ip_addr_netcmp((struct ip_addr *)ptrespconn.proto.udp->remote_ip, &ipconfig.ip, &ipconfig.netmask)) { + wifi_get_ip_info(STATION_IF, &ipconfig); + wifi_get_macaddr(STATION_IF, hwaddr); + } + } else { + wifi_get_ip_info(STATION_IF, &ipconfig); + wifi_get_macaddr(STATION_IF, hwaddr); + } + + if (pusrdata == NULL) { + return; + } + + if (length == os_strlen(device_find_request) && + os_strncmp(pusrdata, device_find_request, os_strlen(device_find_request)) == 0) { + os_sprintf(DeviceBuffer, "%s" MACSTR " " IPSTR, device_find_response_ok, + MAC2STR(hwaddr), IP2STR(&ipconfig.ip)); + + os_printf("%s\n", DeviceBuffer); + length = os_strlen(DeviceBuffer); + espconn_sent(&ptrespconn, DeviceBuffer, length); + } else if (length == (os_strlen(device_find_request) + 18)) { + os_sprintf(Device_mac_buffer, "%s " MACSTR , device_find_request, MAC2STR(hwaddr)); + os_printf("%s", Device_mac_buffer); + + if (os_strncmp(Device_mac_buffer, pusrdata, os_strlen(device_find_request) + 18) == 0) { + //os_printf("%s\n", Device_mac_buffer); + length = os_strlen(DeviceBuffer); + os_sprintf(DeviceBuffer, "%s" MACSTR " " IPSTR, device_find_response_ok, + MAC2STR(hwaddr), IP2STR(&ipconfig.ip)); + + os_printf("%s\n", DeviceBuffer); + length = os_strlen(DeviceBuffer); + espconn_sent(&ptrespconn, DeviceBuffer, length); + } else { + return; + } + } +} + +/****************************************************************************** + * FunctionName : user_devicefind_init + * Description : the espconn struct parame init + * Parameters : none + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_devicefind_init(void) +{ + ptrespconn.type = ESPCONN_UDP; + ptrespconn.proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp)); + ptrespconn.proto.udp->local_port = 1025; + espconn_regist_recvcb(&ptrespconn, user_devicefind_recv); + espconn_create(&ptrespconn); +} diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_esp_platform.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_esp_platform.c new file mode 100644 index 0000000..17f9572 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_esp_platform.c @@ -0,0 +1,1383 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_esp_platform.c + * + * Description: The client mode configration. + * Check your hardware connection with the host while use this mode. + * + * Modification history: + * 2014/5/09, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "os_type.h" +#include "mem.h" +#include "osapi.h" +#include "user_interface.h" + +#include "espconn.h" +#include "user_esp_platform.h" +#include "user_iot_version.h" +#include "upgrade.h" + +#if ESP_PLATFORM + +#define ESP_DEBUG + +#ifdef ESP_DEBUG +#define ESP_DBG os_printf +#else +#define ESP_DBG +#endif + +#define ACTIVE_FRAME "{\"nonce\": %d,\"path\": \"/v1/device/activate/\", \"method\": \"POST\", \"body\": {\"encrypt_method\": \"PLAIN\", \"token\": \"%s\", \"bssid\": \""MACSTR"\",\"rom_version\":\"%s\"}, \"meta\": {\"Authorization\": \"token %s\"}}\n" + +#if PLUG_DEVICE +#include "user_plug.h" + +#define RESPONSE_FRAME "{\"status\": 200, \"datapoint\": {\"x\": %d}, \"nonce\": %d, \"deliver_to_device\": true}\n" +#define FIRST_FRAME "{\"nonce\": %d, \"path\": \"/v1/device/identify\", \"method\": \"GET\",\"meta\": {\"Authorization\": \"token %s\"}}\n" + +#elif LIGHT_DEVICE +#include "user_light.h" + +#define RESPONSE_FRAME "{\"status\": 200,\"nonce\": %d, \"datapoint\": {\"x\": %d,\"y\": %d,\"z\": %d,\"k\": %d,\"l\": %d},\"deliver_to_device\":true}\n" +#define FIRST_FRAME "{\"nonce\": %d, \"path\": \"/v1/device/identify\", \"method\": \"GET\",\"meta\": {\"Authorization\": \"token %s\"}}\n" + +#elif SENSOR_DEVICE +#include "user_sensor.h" + +#if HUMITURE_SUB_DEVICE +#define UPLOAD_FRAME "{\"nonce\": %d, \"path\": \"/v1/datastreams/tem_hum/datapoint/\", \"method\": \"POST\", \ +\"body\": {\"datapoint\": {\"x\": %s%d.%02d,\"y\": %d.%02d}}, \"meta\": {\"Authorization\": \"token %s\"}}\n" +#elif FLAMMABLE_GAS_SUB_DEVICE +#define UPLOAD_FRAME "{\"nonce\": %d, \"path\": \"/v1/datastreams/flammable_gas/datapoint/\", \"method\": \"POST\", \ +\"body\": {\"datapoint\": {\"x\": %d.%03d}}, \"meta\": {\"Authorization\": \"token %s\"}}\n" +#endif + +LOCAL uint32 count = 0; +#endif + +#define UPGRADE_FRAME "{\"path\": \"/v1/messages/\", \"method\": \"POST\", \"meta\": {\"Authorization\": \"token %s\"},\ +\"get\":{\"action\":\"%s\"},\"body\":{\"pre_rom_version\":\"%s\",\"rom_version\":\"%s\"}}\n" + +#if PLUG_DEVICE || LIGHT_DEVICE +#define BEACON_FRAME "{\"path\": \"/v1/ping/\", \"method\": \"POST\",\"meta\": {\"Authorization\": \"token %s\"}}\n" +#define RPC_RESPONSE_FRAME "{\"status\": 200, \"nonce\": %d, \"deliver_to_device\": true}\n" +#define TIMER_FRAME "{\"body\": {}, \"get\":{\"is_humanize_format_simple\":\"true\"},\"meta\": {\"Authorization\": \"Token %s\"},\"path\": \"/v1/device/timers/\",\"post\":{},\"method\": \"GET\"}\n" +#define pheadbuffer "Connection: keep-alive\r\n\ +Cache-Control: no-cache\r\n\ +User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 \r\n\ +Accept: */*\r\n\ +Authorization: token %s\r\n\ +Accept-Encoding: gzip,deflate,sdch\r\n\ +Accept-Language: zh-CN,zh;q=0.8\r\n\r\n" + +LOCAL uint8 ping_status; +LOCAL os_timer_t beacon_timer; +#endif + +#ifdef USE_DNS +ip_addr_t esp_server_ip; +#endif + +LOCAL struct espconn user_conn; +LOCAL struct _esp_tcp user_tcp; +LOCAL os_timer_t client_timer; + struct esp_platform_saved_param esp_param; +LOCAL uint8 device_status; +LOCAL uint8 device_recon_count = 0; +LOCAL uint32 active_nonce = 0; +LOCAL uint8 iot_version[20] = {0}; +struct rst_info rtc_info; +void user_esp_platform_check_ip(uint8 reset_flag); + +/****************************************************************************** + * FunctionName : user_esp_platform_get_token + * Description : get the espressif's device token + * Parameters : token -- the parame point which write the flash + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_esp_platform_get_token(uint8_t *token) +{ + if (token == NULL) { + return; + } + + os_memcpy(token, esp_param.token, sizeof(esp_param.token)); +} + +/****************************************************************************** + * FunctionName : user_esp_platform_set_token + * Description : save the token for the espressif's device + * Parameters : token -- the parame point which write the flash + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_esp_platform_set_token(uint8_t *token) +{ + if (token == NULL) { + return; + } + + esp_param.activeflag = 0; + os_memcpy(esp_param.token, token, os_strlen(token)); + + system_param_save_with_protect(ESP_PARAM_START_SEC, &esp_param, sizeof(esp_param)); +} + +/****************************************************************************** + * FunctionName : user_esp_platform_set_active + * Description : set active flag + * Parameters : activeflag -- 0 or 1 + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_esp_platform_set_active(uint8 activeflag) +{ + esp_param.activeflag = activeflag; + + system_param_save_with_protect(ESP_PARAM_START_SEC, &esp_param, sizeof(esp_param)); +} + +void ICACHE_FLASH_ATTR +user_esp_platform_set_connect_status(uint8 status) +{ + device_status = status; +} + +/****************************************************************************** + * FunctionName : user_esp_platform_get_connect_status + * Description : get each connection step's status + * Parameters : none + * Returns : status +*******************************************************************************/ +uint8 ICACHE_FLASH_ATTR +user_esp_platform_get_connect_status(void) +{ + uint8 status = wifi_station_get_connect_status(); + + if (status == STATION_GOT_IP) { + status = (device_status == 0) ? DEVICE_CONNECTING : device_status; + } + + ESP_DBG("status %d\n", status); + return status; +} + +/****************************************************************************** + * FunctionName : user_esp_platform_parse_nonce + * Description : parse the device nonce + * Parameters : pbuffer -- the recivce data point + * Returns : the nonce +*******************************************************************************/ +int ICACHE_FLASH_ATTR +user_esp_platform_parse_nonce(char *pbuffer) +{ + char *pstr = NULL; + char *pparse = NULL; + char noncestr[11] = {0}; + int nonce = 0; + pstr = (char *)os_strstr(pbuffer, "\"nonce\": "); + + if (pstr != NULL) { + pstr += 9; + pparse = (char *)os_strstr(pstr, ","); + + if (pparse != NULL) { + os_memcpy(noncestr, pstr, pparse - pstr); + } else { + pparse = (char *)os_strstr(pstr, "}"); + + if (pparse != NULL) { + os_memcpy(noncestr, pstr, pparse - pstr); + } else { + pparse = (char *)os_strstr(pstr, "]"); + + if (pparse != NULL) { + os_memcpy(noncestr, pstr, pparse - pstr); + } else { + return 0; + } + } + } + + nonce = atoi(noncestr); + } + + return nonce; +} + +/****************************************************************************** + * FunctionName : user_esp_platform_get_info + * Description : get and update the espressif's device status + * Parameters : pespconn -- the espconn used to connect with host + * pbuffer -- prossing the data point + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_esp_platform_get_info(struct espconn *pconn, uint8 *pbuffer) +{ + char *pbuf = NULL; + int nonce = 0; + + pbuf = (char *)os_zalloc(packet_size); + + nonce = user_esp_platform_parse_nonce(pbuffer); + + if (pbuf != NULL) { +#if PLUG_DEVICE + os_sprintf(pbuf, RESPONSE_FRAME, user_plug_get_status(), nonce); +#elif LIGHT_DEVICE + uint32 white_val; + white_val = (PWM_CHANNEL>LIGHT_COLD_WHITE?user_light_get_duty(LIGHT_COLD_WHITE):0); + os_sprintf(pbuf, RESPONSE_FRAME, nonce, user_light_get_period(), + user_light_get_duty(LIGHT_RED), user_light_get_duty(LIGHT_GREEN), + user_light_get_duty(LIGHT_BLUE),white_val );//50); +#endif + + ESP_DBG("%s\n", pbuf); +#ifdef CLIENT_SSL_ENABLE + espconn_secure_sent(pconn, pbuf, os_strlen(pbuf)); +#else + espconn_sent(pconn, pbuf, os_strlen(pbuf)); +#endif + os_free(pbuf); + pbuf = NULL; + } +} + +/****************************************************************************** + * FunctionName : user_esp_platform_set_info + * Description : prossing the data and controling the espressif's device + * Parameters : pespconn -- the espconn used to connect with host + * pbuffer -- prossing the data point + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_esp_platform_set_info(struct espconn *pconn, uint8 *pbuffer) +{ +#if PLUG_DEVICE + char *pstr = NULL; + pstr = (char *)os_strstr(pbuffer, "plug-status"); + + if (pstr != NULL) { + pstr = (char *)os_strstr(pbuffer, "body"); + + if (pstr != NULL) { + + if (os_strncmp(pstr + 27, "1", 1) == 0) { + user_plug_set_status(0x01); + } else if (os_strncmp(pstr + 27, "0", 1) == 0) { + user_plug_set_status(0x00); + } + } + } + +#elif LIGHT_DEVICE + char *pstr = NULL; + char *pdata = NULL; + char *pbuf = NULL; + char recvbuf[10]; + uint16 length = 0; + uint32 data = 0; + static uint32 rr,gg,bb,cw,ww,period; + ww=0; + cw=0; + extern uint8 light_sleep_flg; + pstr = (char *)os_strstr(pbuffer, "\"path\": \"/v1/datastreams/light/datapoint/\""); + + if (pstr != NULL) { + pstr = (char *)os_strstr(pbuffer, "{\"datapoint\": "); + + if (pstr != NULL) { + pbuf = (char *)os_strstr(pbuffer, "}}"); + length = pbuf - pstr; + length += 2; + pdata = (char *)os_zalloc(length + 1); + os_memcpy(pdata, pstr, length); + + pstr = (char *)os_strchr(pdata, 'x'); + + if (pstr != NULL) { + pstr += 4; + pbuf = (char *)os_strchr(pstr, ','); + + if (pbuf != NULL) { + length = pbuf - pstr; + os_memset(recvbuf, 0, 10); + os_memcpy(recvbuf, pstr, length); + data = atoi(recvbuf); + period = data; + //user_light_set_period(data); + } + } + + pstr = (char *)os_strchr(pdata, 'y'); + + if (pstr != NULL) { + pstr += 4; + pbuf = (char *)os_strchr(pstr, ','); + + if (pbuf != NULL) { + length = pbuf - pstr; + os_memset(recvbuf, 0, 10); + os_memcpy(recvbuf, pstr, length); + data = atoi(recvbuf); + rr=data; + os_printf("r: %d\r\n",rr); + //user_light_set_duty(data, 0); + } + } + + pstr = (char *)os_strchr(pdata, 'z'); + + if (pstr != NULL) { + pstr += 4; + pbuf = (char *)os_strchr(pstr, ','); + + if (pbuf != NULL) { + length = pbuf - pstr; + os_memset(recvbuf, 0, 10); + os_memcpy(recvbuf, pstr, length); + data = atoi(recvbuf); + gg=data; + os_printf("g: %d\r\n",gg); + //user_light_set_duty(data, 1); + } + } + + pstr = (char *)os_strchr(pdata, 'k'); + + if (pstr != NULL) { + pstr += 4;; + pbuf = (char *)os_strchr(pstr, ','); + + if (pbuf != NULL) { + length = pbuf - pstr; + os_memset(recvbuf, 0, 10); + os_memcpy(recvbuf, pstr, length); + data = atoi(recvbuf); + bb=data; + os_printf("b: %d\r\n",bb); + //user_light_set_duty(data, 2); + } + } + + pstr = (char *)os_strchr(pdata, 'l'); + + if (pstr != NULL) { + pstr += 4;; + pbuf = (char *)os_strchr(pstr, ','); + + if (pbuf != NULL) { + length = pbuf - pstr; + os_memset(recvbuf, 0, 10); + os_memcpy(recvbuf, pstr, length); + data = atoi(recvbuf); + cw=data; + ww=data; + os_printf("cw: %d\r\n",cw); + os_printf("ww:%d\r\n",ww); //chg + //user_light_set_duty(data, 2); + } + } + + os_free(pdata); + } + } + + if((rr|gg|bb|cw|ww) == 0){ + if(light_sleep_flg==0){ + + } + + }else{ + if(light_sleep_flg==1){ + os_printf("modem sleep en\r\n"); + wifi_set_sleep_type(MODEM_SLEEP_T); + light_sleep_flg =0; + } + } + + light_set_aim(rr,gg,bb,cw,ww,period); + //user_light_restart(); + +#endif + + user_esp_platform_get_info(pconn, pbuffer); +} + +/****************************************************************************** + * FunctionName : user_esp_platform_reconnect + * Description : reconnect with host after get ip + * Parameters : pespconn -- the espconn used to reconnect with host + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_reconnect(struct espconn *pespconn) +{ + ESP_DBG("user_esp_platform_reconnect\n"); + + user_esp_platform_check_ip(0); +} + +/****************************************************************************** + * FunctionName : user_esp_platform_discon_cb + * Description : disconnect successfully with the host + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_discon_cb(void *arg) +{ + struct espconn *pespconn = arg; + struct ip_info ipconfig; + struct dhcp_client_info dhcp_info; + ESP_DBG("user_esp_platform_discon_cb\n"); + +#if (PLUG_DEVICE || LIGHT_DEVICE) + os_timer_disarm(&beacon_timer); +#endif + + if (pespconn == NULL) { + return; + } + + pespconn->proto.tcp->local_port = espconn_port(); + +#if (PLUG_DEVICE || SENSOR_DEVICE) + user_link_led_output(1); +#endif + +#if SENSOR_DEVICE +#ifdef SENSOR_DEEP_SLEEP + + if (wifi_get_opmode() == STATION_MODE) { + /***add by tzx for saving ip_info to avoid dhcp_client start****/ + wifi_get_ip_info(STATION_IF, &ipconfig); + + dhcp_info.ip_addr = ipconfig.ip; + dhcp_info.netmask = ipconfig.netmask; + dhcp_info.gw = ipconfig.gw ; + dhcp_info.flag = 0x01; + os_printf("dhcp_info.ip_addr = %d\n",dhcp_info.ip_addr); + system_rtc_mem_write(64,&dhcp_info,sizeof(struct dhcp_client_info)); + user_sensor_deep_sleep_enter(); + } else { + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_reconnect, pespconn); + os_timer_arm(&client_timer, SENSOR_DEEP_SLEEP_TIME / 1000, 0); + } + +#else + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_reconnect, pespconn); + os_timer_arm(&client_timer, 1000, 0); +#endif +#else + user_esp_platform_reconnect(pespconn); +#endif +} + +/****************************************************************************** + * FunctionName : user_esp_platform_discon + * Description : A new incoming connection has been disconnected. + * Parameters : espconn -- the espconn used to disconnect with host + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_discon(struct espconn *pespconn) +{ + ESP_DBG("user_esp_platform_discon\n"); + +#if (PLUG_DEVICE || SENSOR_DEVICE) + user_link_led_output(1); +#endif + +#ifdef CLIENT_SSL_ENABLE + espconn_secure_disconnect(pespconn); +#else + espconn_disconnect(pespconn); +#endif +} + +/****************************************************************************** + * FunctionName : user_esp_platform_sent_cb + * Description : Data has been sent successfully and acknowledged by the remote host. + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_sent_cb(void *arg) +{ + struct espconn *pespconn = arg; + + ESP_DBG("user_esp_platform_sent_cb\n"); +} + +/****************************************************************************** + * FunctionName : user_esp_platform_sent + * Description : Processing the application data and sending it to the host + * Parameters : pespconn -- the espconn used to connetion with the host + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_sent(struct espconn *pespconn) +{ + uint8 devkey[token_size] = {0}; + uint32 nonce; + char *pbuf = (char *)os_zalloc(packet_size); + + os_memcpy(devkey, esp_param.devkey, 40); + + if (esp_param.activeflag == 0xFF) { + esp_param.activeflag = 0; + } + + if (pbuf != NULL) { + if (esp_param.activeflag == 0) { + uint8 token[token_size] = {0}; + uint8 bssid[6]; + active_nonce = os_random() && 0x7FFFFFFF; + + os_memcpy(token, esp_param.token, 40); + + wifi_get_macaddr(STATION_IF, bssid); + + os_sprintf(pbuf, ACTIVE_FRAME, active_nonce, token, MAC2STR(bssid),iot_version, devkey); + } + +#if SENSOR_DEVICE +#if HUMITURE_SUB_DEVICE + else { +#if 0 + uint16 tp, rh; + uint8 data[4]; + + if (user_mvh3004_read_th(data)) { + rh = data[0] << 8 | data[1]; + tp = data[2] << 8 | data[3]; + } + +#else + uint16 tp, rh; + uint8 *data; + uint32 tp_t, rh_t; + data = (uint8 *)user_mvh3004_get_poweron_th(); + + rh = data[0] << 8 | data[1]; + tp = data[2] << 8 | data[3]; +#endif + tp_t = (tp >> 2) * 165 * 100 / (16384 - 1); + rh_t = (rh & 0x3fff) * 100 * 100 / (16384 - 1); + + if (tp_t >= 4000) { + os_sprintf(pbuf, UPLOAD_FRAME, count, "", tp_t / 100 - 40, tp_t % 100, rh_t / 100, rh_t % 100, devkey); + } else { + tp_t = 4000 - tp_t; + os_sprintf(pbuf, UPLOAD_FRAME, count, "-", tp_t / 100, tp_t % 100, rh_t / 100, rh_t % 100, devkey); + } + } + +#elif FLAMMABLE_GAS_SUB_DEVICE + else { + uint32 adc_value = system_adc_read(); + + os_sprintf(pbuf, UPLOAD_FRAME, count, adc_value / 1024, adc_value * 1000 / 1024, devkey); + } + +#endif +#else + else { + nonce = os_random() && 0x7FFFFFFF; + os_sprintf(pbuf, FIRST_FRAME, nonce , devkey); + } + +#endif + ESP_DBG("%s\n", pbuf); + +#ifdef CLIENT_SSL_ENABLE + espconn_secure_sent(pespconn, pbuf, os_strlen(pbuf)); +#else + espconn_sent(pespconn, pbuf, os_strlen(pbuf)); +#endif + + os_free(pbuf); + } +} + +#if PLUG_DEVICE || LIGHT_DEVICE +/****************************************************************************** + * FunctionName : user_esp_platform_sent_beacon + * Description : sent beacon frame for connection with the host is activate + * Parameters : pespconn -- the espconn used to connetion with the host + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_sent_beacon(struct espconn *pespconn) +{ + if (pespconn == NULL) { + return; + } + + if (pespconn->state == ESPCONN_CONNECT) { + if (esp_param.activeflag == 0) { + ESP_DBG("please check device is activated.\n"); + user_esp_platform_sent(pespconn); + } else { + uint8 devkey[token_size] = {0}; + os_memcpy(devkey, esp_param.devkey, 40); + + ESP_DBG("user_esp_platform_sent_beacon %u\n", system_get_time()); + + if (ping_status == 0) { + ESP_DBG("user_esp_platform_sent_beacon sent fail!\n"); + user_esp_platform_discon(pespconn); + } else { + char *pbuf = (char *)os_zalloc(packet_size); + + if (pbuf != NULL) { + os_sprintf(pbuf, BEACON_FRAME, devkey); + +#ifdef CLIENT_SSL_ENABLE + espconn_secure_sent(pespconn, pbuf, os_strlen(pbuf)); +#else + espconn_sent(pespconn, pbuf, os_strlen(pbuf)); +#endif + + ping_status = 0; + os_timer_arm(&beacon_timer, BEACON_TIME, 0); + os_free(pbuf); + } + } + } + } else { + ESP_DBG("user_esp_platform_sent_beacon sent fail!\n"); + user_esp_platform_discon(pespconn); + } +} + +/****************************************************************************** + * FunctionName : user_platform_rpc_set_rsp + * Description : response the message to server to show setting info is received + * Parameters : pespconn -- the espconn used to connetion with the host + * nonce -- mark the message received from server + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_platform_rpc_set_rsp(struct espconn *pespconn, int nonce) +{ + char *pbuf = (char *)os_zalloc(packet_size); + + if (pespconn == NULL) { + return; + } + + os_sprintf(pbuf, RPC_RESPONSE_FRAME, nonce); + ESP_DBG("%s\n", pbuf); +#ifdef CLIENT_SSL_ENABLE + espconn_secure_sent(pespconn, pbuf, os_strlen(pbuf)); +#else + espconn_sent(pespconn, pbuf, os_strlen(pbuf)); +#endif + os_free(pbuf); +} + +/****************************************************************************** + * FunctionName : user_platform_timer_get + * Description : get the timers from server + * Parameters : pespconn -- the espconn used to connetion with the host + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_platform_timer_get(struct espconn *pespconn) +{ + uint8 devkey[token_size] = {0}; + char *pbuf = (char *)os_zalloc(packet_size); + os_memcpy(devkey, esp_param.devkey, 40); + + if (pespconn == NULL) { + return; + } + + os_sprintf(pbuf, TIMER_FRAME, devkey); + ESP_DBG("%s\n", pbuf); +#ifdef CLIENT_SSL_ENABLE + espconn_secure_sent(pespconn, pbuf, os_strlen(pbuf)); +#else + espconn_sent(pespconn, pbuf, os_strlen(pbuf)); +#endif + os_free(pbuf); +} + +/****************************************************************************** + * FunctionName : user_esp_platform_upgrade_cb + * Description : Processing the downloaded data from the server + * Parameters : pespconn -- the espconn used to connetion with the host + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_upgrade_rsp(void *arg) +{ + struct upgrade_server_info *server = arg; + struct espconn *pespconn = server->pespconn; + uint8 devkey[41] = {0}; + uint8 *pbuf = NULL; + char *action = NULL; + + os_memcpy(devkey, esp_param.devkey, 40); + pbuf = (char *)os_zalloc(packet_size); + + if (server->upgrade_flag == true) { + ESP_DBG("user_esp_platform_upgarde_successfully\n"); + action = "device_upgrade_success"; + os_sprintf(pbuf, UPGRADE_FRAME, devkey, action, server->pre_version, server->upgrade_version); + ESP_DBG("%s\n",pbuf); + +#ifdef CLIENT_SSL_ENABLE + espconn_secure_sent(pespconn, pbuf, os_strlen(pbuf)); +#else + espconn_sent(pespconn, pbuf, os_strlen(pbuf)); +#endif + + if (pbuf != NULL) { + os_free(pbuf); + pbuf = NULL; + } + } else { + ESP_DBG("user_esp_platform_upgrade_failed\n"); + action = "device_upgrade_failed"; + os_sprintf(pbuf, UPGRADE_FRAME, devkey, action,server->pre_version, server->upgrade_version); + ESP_DBG("%s\n",pbuf); + +#ifdef CLIENT_SSL_ENABLE + espconn_secure_sent(pespconn, pbuf, os_strlen(pbuf)); +#else + espconn_sent(pespconn, pbuf, os_strlen(pbuf)); +#endif + + if (pbuf != NULL) { + os_free(pbuf); + pbuf = NULL; + } + } + + os_free(server->url); + server->url = NULL; + os_free(server); + server = NULL; +} + +/****************************************************************************** + * FunctionName : user_esp_platform_upgrade_begin + * Description : Processing the received data from the server + * Parameters : pespconn -- the espconn used to connetion with the host + * server -- upgrade param + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_upgrade_begin(struct espconn *pespconn, struct upgrade_server_info *server) +{ + uint8 user_bin[9] = {0}; + uint8 devkey[41] = {0}; + + server->pespconn = pespconn; + + os_memcpy(devkey, esp_param.devkey, 40); + os_memcpy(server->ip, pespconn->proto.tcp->remote_ip, 4); + +#ifdef UPGRADE_SSL_ENABLE + server->port = 443; +#else + server->port = 80; +#endif + + server->check_cb = user_esp_platform_upgrade_rsp; + server->check_times = 120000; + + if (server->url == NULL) { + server->url = (uint8 *)os_zalloc(512); + } + + if (system_upgrade_userbin_check() == UPGRADE_FW_BIN1) { + os_memcpy(user_bin, "user2.bin", 10); + } else if (system_upgrade_userbin_check() == UPGRADE_FW_BIN2) { + os_memcpy(user_bin, "user1.bin", 10); + } + + os_sprintf(server->url, "GET /v1/device/rom/?action=download_rom&version=%s&filename=%s HTTP/1.0\r\nHost: "IPSTR":%d\r\n"pheadbuffer"", + server->upgrade_version, user_bin, IP2STR(server->ip), + server->port, devkey); + ESP_DBG("%s\n",server->url); + +#ifdef UPGRADE_SSL_ENABLE + + if (system_upgrade_start_ssl(server) == false) { +#else + + if (system_upgrade_start(server) == false) { +#endif + ESP_DBG("upgrade is already started\n"); + } +} +#endif + +/****************************************************************************** + * FunctionName : user_esp_platform_recv_cb + * Description : Processing the received data from the server + * Parameters : arg -- Additional argument to pass to the callback function + * pusrdata -- The received data (or NULL when the connection has been closed!) + * length -- The length of received data + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_recv_cb(void *arg, char *pusrdata, unsigned short length) +{ + char *pstr = NULL; + LOCAL char pbuffer[1024 * 2] = {0}; + struct espconn *pespconn = arg; + + ESP_DBG("user_esp_platform_recv_cb %s\n", pusrdata); + +#if (PLUG_DEVICE || LIGHT_DEVICE) + os_timer_disarm(&beacon_timer); +#endif + + if (length == 1460) { + os_memcpy(pbuffer, pusrdata, length); + } else { + struct espconn *pespconn = (struct espconn *)arg; + + os_memcpy(pbuffer + os_strlen(pbuffer), pusrdata, length); + + if ((pstr = (char *)os_strstr(pbuffer, "\"activate_status\": ")) != NULL && + user_esp_platform_parse_nonce(pbuffer) == active_nonce) { + if (os_strncmp(pstr + 19, "1", 1) == 0) { + ESP_DBG("device activates successful.\n"); + + device_status = DEVICE_ACTIVE_DONE; + esp_param.activeflag = 1; + system_param_save_with_protect(ESP_PARAM_START_SEC, &esp_param, sizeof(esp_param)); + user_esp_platform_sent(pespconn); + if(LIGHT_DEVICE){ + system_restart(); + } + } else { + ESP_DBG("device activates failed.\n"); + device_status = DEVICE_ACTIVE_FAIL; + } + } + +#if (PLUG_DEVICE || LIGHT_DEVICE) + else if ((pstr = (char *)os_strstr(pbuffer, "\"action\": \"sys_upgrade\"")) != NULL) { + if ((pstr = (char *)os_strstr(pbuffer, "\"version\":")) != NULL) { + struct upgrade_server_info *server = NULL; + int nonce = user_esp_platform_parse_nonce(pbuffer); + user_platform_rpc_set_rsp(pespconn, nonce); + + server = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info)); + os_memcpy(server->upgrade_version, pstr + 12, 16); + server->upgrade_version[15] = '\0'; + os_sprintf(server->pre_version,"%s%d.%d.%dt%d(%s)",VERSION_TYPE,IOT_VERSION_MAJOR,\ + IOT_VERSION_MINOR,IOT_VERSION_REVISION,device_type,UPGRADE_FALG); + user_esp_platform_upgrade_begin(pespconn, server); + } + } else if ((pstr = (char *)os_strstr(pbuffer, "\"action\": \"sys_reboot\"")) != NULL) { + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)system_upgrade_reboot, NULL); + os_timer_arm(&client_timer, 1000, 0); + } else if ((pstr = (char *)os_strstr(pbuffer, "/v1/device/timers/")) != NULL) { + int nonce = user_esp_platform_parse_nonce(pbuffer); + user_platform_rpc_set_rsp(pespconn, nonce); + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_platform_timer_get, pespconn); + os_timer_arm(&client_timer, 2000, 0); + } else if ((pstr = (char *)os_strstr(pbuffer, "\"method\": ")) != NULL) { + if (os_strncmp(pstr + 11, "GET", 3) == 0) { + user_esp_platform_get_info(pespconn, pbuffer); + } else if (os_strncmp(pstr + 11, "POST", 4) == 0) { + user_esp_platform_set_info(pespconn, pbuffer); + } + } else if ((pstr = (char *)os_strstr(pbuffer, "ping success")) != NULL) { + ESP_DBG("ping success\n"); + ping_status = 1; + } else if ((pstr = (char *)os_strstr(pbuffer, "send message success")) != NULL) { + } else if ((pstr = (char *)os_strstr(pbuffer, "timers")) != NULL) { + user_platform_timer_start(pusrdata , pespconn); + } + +#elif SENSOR_DEVICE + else if ((pstr = (char *)os_strstr(pbuffer, "\"status\":")) != NULL) { + if (os_strncmp(pstr + 10, "200", 3) != 0) { + ESP_DBG("message upload failed.\n"); + } else { + count++; + ESP_DBG("message upload sucessful.\n"); + } + + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_discon, pespconn); + os_timer_arm(&client_timer, 10, 0); + } + +#endif + else if ((pstr = (char *)os_strstr(pbuffer, "device")) != NULL) { +#if PLUG_DEVICE || LIGHT_DEVICE + user_platform_timer_get(pespconn); +#elif SENSOR_DEVICE + +#endif + } + + os_memset(pbuffer, 0, sizeof(pbuffer)); + } + +#if (PLUG_DEVICE || LIGHT_DEVICE) + os_timer_arm(&beacon_timer, BEACON_TIME, 0); +#endif +} + +#if AP_CACHE +/****************************************************************************** + * FunctionName : user_esp_platform_ap_change + * Description : add the user interface for changing to next ap ID. + * Parameters : + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_ap_change(void) +{ + uint8 current_id; + uint8 i = 0; + ESP_DBG("user_esp_platform_ap_is_changing\n"); + + current_id = wifi_station_get_current_ap_id(); + ESP_DBG("current ap id =%d\n", current_id); + + if (current_id == AP_CACHE_NUMBER - 1) { + i = 0; + } else { + i = current_id + 1; + } + while (wifi_station_ap_change(i) != true) { + i++; + if (i == AP_CACHE_NUMBER - 1) { + i = 0; + } + } + + /* just need to re-check ip while change AP */ + device_recon_count = 0; + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL); + os_timer_arm(&client_timer, 100, 0); +} +#endif + +LOCAL bool ICACHE_FLASH_ATTR +user_esp_platform_reset_mode(void) +{ + if (wifi_get_opmode() == STATION_MODE) { + wifi_set_opmode(STATIONAP_MODE); + } + +#if AP_CACHE + /* delay 5s to change AP */ + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_ap_change, NULL); + os_timer_arm(&client_timer, 5000, 0); + + return true; +#endif + + return false; +} + +/****************************************************************************** + * FunctionName : user_esp_platform_recon_cb + * Description : The connection had an error and is already deallocated. + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_recon_cb(void *arg, sint8 err) +{ + struct espconn *pespconn = (struct espconn *)arg; + + ESP_DBG("user_esp_platform_recon_cb\n"); + +#if (PLUG_DEVICE || LIGHT_DEVICE) + os_timer_disarm(&beacon_timer); +#endif + +#if (PLUG_DEVICE || SENSOR_DEVICE) + user_link_led_output(1); +#endif + + if (++device_recon_count == 5) { + device_status = DEVICE_CONNECT_SERVER_FAIL; + + if (user_esp_platform_reset_mode()) { + return; + } + } + +#if SENSOR_DEVICE +#ifdef SENSOR_DEEP_SLEEP + + if (wifi_get_opmode() == STATION_MODE) { + user_esp_platform_reset_mode(); + + //user_sensor_deep_sleep_enter(); + } else { + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_reconnect, pespconn); + os_timer_arm(&client_timer, 1000, 0); + } + +#else + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_reconnect, pespconn); + os_timer_arm(&client_timer, 1000, 0); +#endif +#else + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_reconnect, pespconn); + os_timer_arm(&client_timer, 1000, 0); +#endif +} + +/****************************************************************************** + * FunctionName : user_esp_platform_connect_cb + * Description : A new incoming connection has been connected. + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_connect_cb(void *arg) +{ + struct espconn *pespconn = arg; + + ESP_DBG("user_esp_platform_connect_cb\n"); + if (wifi_get_opmode() == STATIONAP_MODE ) { + wifi_set_opmode(STATION_MODE); + } + +#if (PLUG_DEVICE || SENSOR_DEVICE) + user_link_led_timer_done(); +#endif + device_recon_count = 0; + espconn_regist_recvcb(pespconn, user_esp_platform_recv_cb); + espconn_regist_sentcb(pespconn, user_esp_platform_sent_cb); + user_esp_platform_sent(pespconn); +} + +/****************************************************************************** + * FunctionName : user_esp_platform_connect + * Description : The function given as the connect with the host + * Parameters : espconn -- the espconn used to connect the connection + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_connect(struct espconn *pespconn) +{ + ESP_DBG("user_esp_platform_connect\n"); + +#ifdef CLIENT_SSL_ENABLE + espconn_secure_connect(pespconn); +#else + espconn_connect(pespconn); +#endif +} + +#ifdef USE_DNS +/****************************************************************************** + * FunctionName : user_esp_platform_dns_found + * Description : dns found callback + * Parameters : name -- pointer to the name that was looked up. + * ipaddr -- pointer to an ip_addr_t containing the IP address of + * the hostname, or NULL if the name could not be found (or on any + * other error). + * callback_arg -- a user-specified callback argument passed to + * dns_gethostbyname + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) +{ + struct espconn *pespconn = (struct espconn *)arg; + + if (ipaddr == NULL) { + ESP_DBG("user_esp_platform_dns_found NULL\n"); + + if (++device_recon_count == 5) { + device_status = DEVICE_CONNECT_SERVER_FAIL; + + user_esp_platform_reset_mode(); + } + + return; + } + + ESP_DBG("user_esp_platform_dns_found %d.%d.%d.%d\n", + *((uint8 *)&ipaddr->addr), *((uint8 *)&ipaddr->addr + 1), + *((uint8 *)&ipaddr->addr + 2), *((uint8 *)&ipaddr->addr + 3)); + + if (esp_server_ip.addr == 0 && ipaddr->addr != 0) { + os_timer_disarm(&client_timer); + esp_server_ip.addr = ipaddr->addr; + os_memcpy(pespconn->proto.tcp->remote_ip, &ipaddr->addr, 4); + + pespconn->proto.tcp->local_port = espconn_port(); + +#ifdef CLIENT_SSL_ENABLE + pespconn->proto.tcp->remote_port = 8443; +#else + pespconn->proto.tcp->remote_port = 8000; +#endif + +#if (PLUG_DEVICE || LIGHT_DEVICE) + ping_status = 1; +#endif + + espconn_regist_connectcb(pespconn, user_esp_platform_connect_cb); + espconn_regist_disconcb(pespconn, user_esp_platform_discon_cb); + espconn_regist_reconcb(pespconn, user_esp_platform_recon_cb); + user_esp_platform_connect(pespconn); + } +} + +/****************************************************************************** + * FunctionName : user_esp_platform_dns_check_cb + * Description : 1s time callback to check dns found + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_dns_check_cb(void *arg) +{ + struct espconn *pespconn = arg; + + ESP_DBG("user_esp_platform_dns_check_cb\n"); + + espconn_gethostbyname(pespconn, ESP_DOMAIN, &esp_server_ip, user_esp_platform_dns_found); + + os_timer_arm(&client_timer, 1000, 0); +} + +LOCAL void ICACHE_FLASH_ATTR +user_esp_platform_start_dns(struct espconn *pespconn) +{ + esp_server_ip.addr = 0; + espconn_gethostbyname(pespconn, ESP_DOMAIN, &esp_server_ip, user_esp_platform_dns_found); + + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_dns_check_cb, pespconn); + os_timer_arm(&client_timer, 1000, 0); +} +#endif + + +#if LIGHT_DEVICE +void user_mdns_conf() +{ + +struct ip_info ipconfig; +wifi_get_ip_info(STATION_IF, &ipconfig); + +struct mdns_info *info = (struct mdns_info *)os_zalloc(sizeof(struct mdns_info)); +info->host_name = "espressif_light_demo"; +info->ipAddr= ipconfig.ip.addr; //sation ip +info->server_name = "espLight"; +info->server_port = 80; +info->txt_data[0] = "version = 1.0.1"; +espconn_mdns_init(info); + + +} +#endif + +/****************************************************************************** + * FunctionName : user_esp_platform_check_ip + * Description : espconn struct parame init when get ip addr + * Parameters : none + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_esp_platform_check_ip(uint8 reset_flag) +{ + struct ip_info ipconfig; + + os_timer_disarm(&client_timer); + + wifi_get_ip_info(STATION_IF, &ipconfig); + + if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) { +#if (PLUG_DEVICE || SENSOR_DEVICE) + user_link_led_timer_init(); +#endif + +//*************************** +#if LIGHT_DEVICE + user_mdns_conf(); +#endif +//*************************** + user_conn.proto.tcp = &user_tcp; + user_conn.type = ESPCONN_TCP; + user_conn.state = ESPCONN_NONE; + + device_status = DEVICE_CONNECTING; + + if (reset_flag) { + device_recon_count = 0; + } + +#if (PLUG_DEVICE || LIGHT_DEVICE) + os_timer_disarm(&beacon_timer); + os_timer_setfn(&beacon_timer, (os_timer_func_t *)user_esp_platform_sent_beacon, &user_conn); +#endif + +#ifdef USE_DNS + user_esp_platform_start_dns(&user_conn); +#else + const char esp_server_ip[4] = {114, 215, 177, 97}; + + os_memcpy(user_conn.proto.tcp->remote_ip, esp_server_ip, 4); + user_conn.proto.tcp->local_port = espconn_port(); + +#ifdef CLIENT_SSL_ENABLE + user_conn.proto.tcp->remote_port = 8443; +#else + user_conn.proto.tcp->remote_port = 8000; +#endif + + espconn_regist_connectcb(&user_conn, user_esp_platform_connect_cb); + espconn_regist_reconcb(&user_conn, user_esp_platform_recon_cb); + user_esp_platform_connect(&user_conn); +#endif + } else { + /* if there are wrong while connecting to some AP, then reset mode */ + if ((wifi_station_get_connect_status() == STATION_WRONG_PASSWORD || + wifi_station_get_connect_status() == STATION_NO_AP_FOUND || + wifi_station_get_connect_status() == STATION_CONNECT_FAIL)) { + user_esp_platform_reset_mode(); + } else { + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL); + os_timer_arm(&client_timer, 100, 0); + } + } +} + +/****************************************************************************** + * FunctionName : user_esp_platform_init + * Description : device parame init based on espressif platform + * Parameters : none + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_esp_platform_init(void) +{ + + os_sprintf(iot_version,"%s%d.%d.%dt%d(%s)",VERSION_TYPE,IOT_VERSION_MAJOR,\ + IOT_VERSION_MINOR,IOT_VERSION_REVISION,device_type,UPGRADE_FALG); + os_printf("IOT VERSION = %s\n",iot_version); + + system_param_load(ESP_PARAM_START_SEC, 0, &esp_param, sizeof(esp_param)); + + struct rst_info *rtc_info = system_get_rst_info(); + + os_printf("reset reason: %x\n", rtc_info->reason); + + if (rtc_info->reason == REASON_WDT_RST || + rtc_info->reason == REASON_EXCEPTION_RST || + rtc_info->reason == REASON_SOFT_WDT_RST) { + if (rtc_info->reason == REASON_EXCEPTION_RST) { + os_printf("Fatal exception (%d):\n", rtc_info->exccause); + } + os_printf("epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\n", + rtc_info->epc1, rtc_info->epc2, rtc_info->epc3, rtc_info->excvaddr, rtc_info->depc); + } + + /***add by tzx for saving ip_info to avoid dhcp_client start****/ + struct dhcp_client_info dhcp_info; + struct ip_info sta_info; + system_rtc_mem_read(64,&dhcp_info,sizeof(struct dhcp_client_info)); + if(dhcp_info.flag == 0x01 ) { + if (true == wifi_station_dhcpc_status()) + { + wifi_station_dhcpc_stop(); + } + sta_info.ip = dhcp_info.ip_addr; + sta_info.gw = dhcp_info.gw; + sta_info.netmask = dhcp_info.netmask; + if ( true != wifi_set_ip_info(STATION_IF,&sta_info)) { + os_printf("set default ip wrong\n"); + } + } + os_memset(&dhcp_info,0,sizeof(struct dhcp_client_info)); + system_rtc_mem_write(64,&dhcp_info,sizeof(struct rst_info)); + + +#if AP_CACHE + wifi_station_ap_number_set(AP_CACHE_NUMBER); +#endif + +#if 0 + { + char sofap_mac[6] = {0x16, 0x34, 0x56, 0x78, 0x90, 0xab}; + char sta_mac[6] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab}; + struct ip_info info; + + wifi_set_macaddr(SOFTAP_IF, sofap_mac); + wifi_set_macaddr(STATION_IF, sta_mac); + + IP4_ADDR(&info.ip, 192, 168, 3, 200); + IP4_ADDR(&info.gw, 192, 168, 3, 1); + IP4_ADDR(&info.netmask, 255, 255, 255, 0); + wifi_set_ip_info(STATION_IF, &info); + + IP4_ADDR(&info.ip, 10, 10, 10, 1); + IP4_ADDR(&info.gw, 10, 10, 10, 1); + IP4_ADDR(&info.netmask, 255, 255, 255, 0); + wifi_set_ip_info(SOFTAP_IF, &info); + } +#endif + + if (esp_param.activeflag != 1) { +#ifdef SOFTAP_ENCRYPT + struct softap_config config; + char password[33]; + char macaddr[6]; + + wifi_softap_get_config(&config); + wifi_get_macaddr(SOFTAP_IF, macaddr); + + os_memset(config.password, 0, sizeof(config.password)); + os_sprintf(password, MACSTR "_%s", MAC2STR(macaddr), PASSWORD); + os_memcpy(config.password, password, os_strlen(password)); + config.authmode = AUTH_WPA_WPA2_PSK; + + wifi_softap_set_config(&config); +#endif + + wifi_set_opmode(STATIONAP_MODE); + } + +#if PLUG_DEVICE + user_plug_init(); +#elif LIGHT_DEVICE + user_light_init(); +#elif SENSOR_DEVICE + user_sensor_init(esp_param.activeflag); +#endif + + if (wifi_get_opmode() != SOFTAP_MODE) { + os_timer_disarm(&client_timer); + os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_check_ip, 1); + os_timer_arm(&client_timer, 100, 0); + } +} + +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_esp_platform_timer.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_esp_platform_timer.c new file mode 100644 index 0000000..945145d --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_esp_platform_timer.c @@ -0,0 +1,344 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: esp_platform_user_timer.c + * + * Description: + * + * Modification history: + * 2014/5/09, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "os_type.h" +#include "mem.h" +#include "osapi.h" +#include "user_interface.h" + +#include "espconn.h" +#include "user_esp_platform.h" + +#define ESP_DEBUG + +#ifdef ESP_DEBUG +#define ESP_DBG os_printf +#else +#define ESP_DBG +#endif + +LOCAL os_timer_t device_timer; +uint32 min_wait_second; +char timestamp_str[11]; +int timestamp = 0; +char *timer_splits[20] = {NULL}; + +struct esp_platform_wait_timer_param { + uint8 wait_time_param[11]; + uint8 wait_action[15]; + int wait_time_second; +}; + +struct wait_param { + uint8 action[20][15]; + uint16 action_number; + uint16 count; + uint32 min_time_backup; +}; + +void esp_platform_timer_action(struct esp_platform_wait_timer_param *timer_wait_param, uint16 count); + +/****************************************************************************** + * FunctionName : split + * Description : split string p1 according to sting p2 and save the splits + * Parameters : p1 , p2 ,splits[] + * Returns : the number of splits +*******************************************************************************/ +uint16 ICACHE_FLASH_ATTR +split(char *p1, char *p2, char *splits[]) +{ + int i = 0; + int j = 0; + + while (i != -1) { + int start = i; + int end = indexof(p1, p2, start); + + if (end == -1) { + end = os_strlen(p1); + } + + char *p = (char *) os_zalloc(100); + os_memcpy(p, p1 + start, end - start); + p[end - start] = '\0'; + splits[j] = p; + j++; + i = end + 1; + + if (i > os_strlen(p1)) { + break; + } + } + + return j; +} + +/****************************************************************************** + * FunctionName : indexof + * Description : calculate the offset of p2 relate to start of p1 + * Parameters : p1,p1,start + * Returns : the offset of p2 relate to the start +*******************************************************************************/ +int ICACHE_FLASH_ATTR +indexof(char *p1, char *p2, int start) +{ + char *find = (char *)os_strstr(p1 + start, p2); + + if (find != NULL) { + return (find - p1); + } + + return -1; +} + +/****************************************************************************** + * FunctionName : esp_platform_find_min_time + * Description : find the minimum wait second in timer list + * Parameters : timer_wait_param -- param of timer action and wait time param + * count -- The number of timers given by server + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +esp_platform_find_min_time(struct esp_platform_wait_timer_param *timer_wait_param , uint16 count) +{ + uint16 i = 0; + min_wait_second = 0xFFFFFFF; + + for (i = 0; i < count ; i++) { + if (timer_wait_param[i].wait_time_second < min_wait_second && timer_wait_param[i].wait_time_second >= 0) { + min_wait_second = timer_wait_param[i].wait_time_second; + } + } +} + +/****************************************************************************** + * FunctionName : user_platform_timer_first_start + * Description : calculate the wait time of each timer + * Parameters : count -- The number of timers given by server + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_platform_timer_first_start(uint16 count) +{ + int i = 0; + struct esp_platform_wait_timer_param timer_wait_param[100] = {0}; + + ESP_DBG("current timestamp= %ds\n", timestamp); + + timestamp = timestamp + min_wait_second; + + for (i = 0 ; i < count ; i++) { + char *str = timer_splits[i]; + + if (indexof(str, "f", 0) == 0) { + char *fixed_wait[2]; + + ESP_DBG("timer is fixed mode\n"); + + split(str, "=", fixed_wait); + os_memcpy(timer_wait_param[i].wait_time_param, fixed_wait[0] + 1, os_strlen(fixed_wait[0]) - 1); + os_memcpy(timer_wait_param[i].wait_action, fixed_wait[1], os_strlen(fixed_wait[1])); + timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - timestamp; + os_free(fixed_wait[0]); + os_free(fixed_wait[1]); + } + + else if (indexof(str, "l", 0) == 0) { + char *loop_wait[2]; + + ESP_DBG("timer is loop mode\n"); + + split(str, "=", loop_wait); + os_memcpy(timer_wait_param[i].wait_time_param, loop_wait[0] + 1, os_strlen(loop_wait[0]) - 1); + os_memcpy(timer_wait_param[i].wait_action, loop_wait[1], os_strlen(loop_wait[1])); + timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - (timestamp % atoi(timer_wait_param[i].wait_time_param)); + os_free(loop_wait[0]); + os_free(loop_wait[1]); + } else if (indexof(str, "w", 0) == 0) { + char *week_wait[2]; + int monday_wait_time = 0; + + ESP_DBG("timer is weekend mode\n"); + + split(str, "=", week_wait); + os_memcpy(timer_wait_param[i].wait_time_param, week_wait[0] + 1, os_strlen(week_wait[0]) - 1); + os_memcpy(timer_wait_param[i].wait_action, week_wait[1], os_strlen(week_wait[1])); + monday_wait_time = (timestamp - 1388937600) % (7 * 24 * 3600); + + ESP_DBG("monday_wait_time == %d", monday_wait_time); + + if (atoi(timer_wait_param[i].wait_time_param) > monday_wait_time) { + timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - monday_wait_time; + } else { + timer_wait_param[i].wait_time_second = 7 * 24 * 3600 - monday_wait_time + atoi(timer_wait_param[i].wait_time_param); + } + + os_free(week_wait[0]); + os_free(week_wait[1]); + } + } + + esp_platform_find_min_time(timer_wait_param, count); + if(min_wait_second == 0) { + return; + } + + esp_platform_timer_action(timer_wait_param, count); +} + +/****************************************************************************** + * FunctionName : user_esp_platform_device_action + * Description : Execute the actions of minimum wait time + * Parameters : pwait_action -- point the list of actions which need execute + * + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_esp_platform_device_action(struct wait_param *pwait_action) +{ + uint8 i = 0; + uint16 count = pwait_action->count; + uint16 action_number = pwait_action->action_number; + + ESP_DBG("there is %d action at the same time\n", pwait_action->action_number); + +#if PLUG_DEVICE + for (i = 0; i < action_number && pwait_action->action[i][0] != '0'; i++) { + ESP_DBG("%s\n",pwait_action->action[i]); + + if (os_strcmp(pwait_action->action[i], "on_switch", 9) == 0) { + user_plug_set_status(0x01); + } else if (os_strcmp(pwait_action->action[i], "off_switch", 10) == 0) { + user_plug_set_status(0x00); + } else if (os_strcmp(pwait_action->action[i], "on_off_switch", 13) == 0) { + if (user_plug_get_status() == 0) { + user_plug_set_status(0x01); + } else { + user_plug_set_status(0x00); + } + } else { + return; + } + } + user_platform_timer_first_start(count); +#endif +} + +/****************************************************************************** + * FunctionName : user_platform_timer_start + * Description : Processing the message about timer from the server + * Parameters : timer_wait_param -- The received data from the server + * count -- the espconn used to connetion with the host + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_esp_platform_wait_time_overflow_check(struct wait_param *pwait_action) +{ + ESP_DBG("min_wait_second = %d", min_wait_second); + + if (pwait_action->min_time_backup >= 3600) { + os_timer_disarm(&device_timer); + os_timer_setfn(&device_timer, (os_timer_func_t *)user_esp_platform_wait_time_overflow_check, pwait_action); + os_timer_arm(&device_timer, 3600000, 0); + ESP_DBG("min_wait_second is extended\n"); + } else { + os_timer_disarm(&device_timer); + os_timer_setfn(&device_timer, (os_timer_func_t *)user_esp_platform_device_action, pwait_action); + os_timer_arm(&device_timer, pwait_action->min_time_backup * 1000, 0); + ESP_DBG("min_wait_second is = %dms\n", pwait_action->min_time_backup * 1000); + } + + pwait_action->min_time_backup -= 3600; +} + +/****************************************************************************** + * FunctionName : user_platform_timer_start + * Description : Processing the message about timer from the server + * Parameters : timer_wait_param -- The received data from the server + * count -- the espconn used to connetion with the host + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +esp_platform_timer_action(struct esp_platform_wait_timer_param *timer_wait_param, uint16 count) +{ + uint16 i = 0; + uint16 action_number; + struct wait_param pwait_action = {0}; + + pwait_action.count = count; + action_number = 0; + + for (i = 0; i < count ; i++) { + if (timer_wait_param[i].wait_time_second == min_wait_second) { + os_memcpy(pwait_action.action[action_number], timer_wait_param[i].wait_action, os_strlen(timer_wait_param[i].wait_action)); + ESP_DBG("*****%s*****\n", timer_wait_param[i].wait_action); + action_number++; + } + } + + pwait_action.action_number = action_number; + pwait_action.min_time_backup = min_wait_second; + user_esp_platform_wait_time_overflow_check(&pwait_action); +} + +/****************************************************************************** + * FunctionName : user_platform_timer_start + * Description : Processing the message about timer from the server + * Parameters : pbuffer -- The received data from the server + + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_platform_timer_start(char *pbuffer) +{ + int str_begin = 0; + int str_end = 0; + uint8 i = 0; + char *pstr_start = NULL; + char *pstr_end = NULL; + struct esp_platform_wait_timer_param timer_wait_param[20]; + char *pstr = NULL; + + min_wait_second = 0; + + if ((pstr = (char *)os_strstr(pbuffer, "\"timestamp\":")) != NULL) { + pstr_start = pstr + 13; + pstr_end = (char *)os_strstr(pstr_start, ","); + + if (pstr != NULL) { + os_memcpy(timestamp_str, pstr_start, pstr_end - pstr_start); + timestamp = atoi(timestamp_str); + } + } + + for (i = 0 ; i < 20 ; i++) { + if (timer_splits[i] != NULL) { + os_free(timer_splits[i]); + timer_splits[i] = NULL; + } + } + + if ((pstr_start = (char *)os_strstr(pbuffer, "\"timers\": \"")) != NULL) { + str_begin = 11; + str_end = indexof(pstr_start, "\"", str_begin); + + if (str_begin == str_end) { + os_timer_disarm(&device_timer); + return; + } + + char *split_buffer = (char *)os_zalloc(str_end - str_begin + 1); + os_memcpy(split_buffer, pstr_start + str_begin, str_end - str_begin); + uint16 count = split(split_buffer , ";" , timer_splits); + os_free(split_buffer); + user_platform_timer_first_start(count); + } +} diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_json.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_json.c new file mode 100644 index 0000000..e5b1e4e --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_json.c @@ -0,0 +1,164 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_json.c + * + * Description: JSON format set up and parse. + * Check your hardware transmation while use this data format. + * + * Modification history: + * 2014/5/09, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "osapi.h" +#include "os_type.h" +#include "mem.h" + +#include "user_json.h" + +LOCAL char *json_buf; +LOCAL int pos; +LOCAL int size; + +/****************************************************************************** + * FunctionName : find_json_path + * Description : find the JSON format tree's path + * Parameters : json -- A pointer to a JSON set up + * path -- A pointer to the JSON format tree's path + * Returns : A pointer to the JSON format tree +*******************************************************************************/ +struct jsontree_value *ICACHE_FLASH_ATTR +find_json_path(struct jsontree_context *json, const char *path) +{ + struct jsontree_value *v; + const char *start; + const char *end; + int len; + + v = json->values[0]; + start = path; + + do { + end = (const char *)os_strstr(start, "/"); + + if (end == start) { + break; + } + + if (end != NULL) { + len = end - start; + end++; + } else { + len = os_strlen(start); + } + + if (v->type != JSON_TYPE_OBJECT) { + v = NULL; + } else { + struct jsontree_object *o; + int i; + + o = (struct jsontree_object *)v; + v = NULL; + + for (i = 0; i < o->count; i++) { + if (os_strncmp(start, o->pairs[i].name, len) == 0) { + v = o->pairs[i].value; + json->index[json->depth] = i; + json->depth++; + json->values[json->depth] = v; + json->index[json->depth] = 0; + break; + } + } + } + + start = end; + } while (end != NULL && *end != '\0' && v != NULL); + + json->callback_state = 0; + return v; +} + +/****************************************************************************** + * FunctionName : json_putchar + * Description : write the value to the JSON format tree + * Parameters : c -- the value which write the JSON format tree + * Returns : result +*******************************************************************************/ +int ICACHE_FLASH_ATTR +json_putchar(int c) +{ + if (json_buf != NULL && pos <= size) { + json_buf[pos++] = c; + return c; + } + + return 0; +} + +/****************************************************************************** + * FunctionName : json_ws_send + * Description : set up the JSON format tree for string + * Parameters : tree -- A pointer to the JSON format tree + * path -- A pointer to the JSON format tree's path + * pbuf -- A pointer for the data sent + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +json_ws_send(struct jsontree_value *tree, const char *path, char *pbuf) +{ + struct jsontree_context json; + /* maxsize = 128 bytes */ + json_buf = (char *)os_malloc(jsonSize); + + /* reset state and set max-size */ + /* NOTE: packet will be truncated at 512 bytes */ + pos = 0; + size = jsonSize; + + json.values[0] = (struct jsontree_value *)tree; + jsontree_reset(&json); + find_json_path(&json, path); + json.path = json.depth; + json.putchar = json_putchar; + + while (jsontree_print_next(&json) && json.path <= json.depth); + + json_buf[pos] = 0; + os_memcpy(pbuf, json_buf, pos); + os_free(json_buf); +} + +/****************************************************************************** + * FunctionName : json_parse + * Description : parse the data as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * ptrJSONMessage -- A pointer to the data + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +json_parse(struct jsontree_context *json, char *ptrJSONMessage) +{ + /* Set value */ + struct jsontree_value *v; + struct jsontree_callback *c; + struct jsontree_callback *c_bak = NULL; + + while ((v = jsontree_find_next(json, JSON_TYPE_CALLBACK)) != NULL) { + c = (struct jsontree_callback *)v; + + if (c == c_bak) { + continue; + } + + c_bak = c; + + if (c->set != NULL) { + struct jsonparse_state js; + + jsonparse_setup(&js, ptrJSONMessage, os_strlen(ptrJSONMessage)); + c->set(json, &js); + } + } +} diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_light.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_light.c new file mode 100644 index 0000000..416dc77 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_light.c @@ -0,0 +1,141 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_light.c + * + * Description: light demo's function realization + * + * Modification history: + * 2014/5/1, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "osapi.h" +#include "os_type.h" +#include "mem.h" +#include "user_interface.h" + +#include "user_light.h" +#include "pwm.h" + +#if LIGHT_DEVICE + +struct light_saved_param light_param; + +/****************************************************************************** + * FunctionName : user_light_get_duty + * Description : get duty of each channel + * Parameters : uint8 channel : LIGHT_RED/LIGHT_GREEN/LIGHT_BLUE + * Returns : NONE +*******************************************************************************/ +uint32 ICACHE_FLASH_ATTR +user_light_get_duty(uint8 channel) +{ + return light_param.pwm_duty[channel]; +} + +/****************************************************************************** + * FunctionName : user_light_set_duty + * Description : set each channel's duty params + * Parameters : uint8 duty : 0 ~ PWM_DEPTH + * uint8 channel : LIGHT_RED/LIGHT_GREEN/LIGHT_BLUE + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_light_set_duty(uint32 duty, uint8 channel) +{ + if (duty != light_param.pwm_duty[channel]) { + pwm_set_duty(duty, channel); + + light_param.pwm_duty[channel] = pwm_get_duty(channel); + } +} + +/****************************************************************************** + * FunctionName : user_light_get_period + * Description : get pwm period + * Parameters : NONE + * Returns : uint32 : pwm period +*******************************************************************************/ +uint32 ICACHE_FLASH_ATTR +user_light_get_period(void) +{ + return light_param.pwm_period; +} + +/****************************************************************************** + * FunctionName : user_light_set_duty + * Description : set pwm frequency + * Parameters : uint16 freq : 100hz typically + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_light_set_period(uint32 period) +{ + if (period != light_param.pwm_period) { + pwm_set_period(period); + + light_param.pwm_period = pwm_get_period(); + } +} + +void ICACHE_FLASH_ATTR +user_light_restart(void) +{ + spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE); + spi_flash_write((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE, + (uint32 *)&light_param, sizeof(struct light_saved_param)); + + pwm_start(); +} + +/****************************************************************************** + * FunctionName : user_light_init + * Description : light demo init, mainy init pwm + * Parameters : none + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_light_init(void) +{ + spi_flash_read((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE, + (uint32 *)&light_param, sizeof(struct light_saved_param)); + if(light_param.pwm_period>10000 || light_param.pwm_period <1000){ + light_param.pwm_period = 1000; + } + + uint32 io_info[][3] = { {PWM_0_OUT_IO_MUX,PWM_0_OUT_IO_FUNC,PWM_0_OUT_IO_NUM}, + {PWM_1_OUT_IO_MUX,PWM_1_OUT_IO_FUNC,PWM_1_OUT_IO_NUM}, + {PWM_2_OUT_IO_MUX,PWM_2_OUT_IO_FUNC,PWM_2_OUT_IO_NUM}, + {PWM_3_OUT_IO_MUX,PWM_3_OUT_IO_FUNC,PWM_3_OUT_IO_NUM}, + {PWM_4_OUT_IO_MUX,PWM_4_OUT_IO_FUNC,PWM_4_OUT_IO_NUM}, + }; + + uint32 pwm_duty_init[PWM_CHANNEL] = {0}; + + /*PIN FUNCTION INIT FOR PWM OUTPUT*/ + pwm_init(light_param.pwm_period, pwm_duty_init ,PWM_CHANNEL,io_info); + + os_printf("LIGHT PARAM: R: %d \r\n",light_param.pwm_duty[LIGHT_RED]); + os_printf("LIGHT PARAM: G: %d \r\n",light_param.pwm_duty[LIGHT_GREEN]); + os_printf("LIGHT PARAM: B: %d \r\n",light_param.pwm_duty[LIGHT_BLUE]); + if(PWM_CHANNEL>LIGHT_COLD_WHITE){ + os_printf("LIGHT PARAM: CW: %d \r\n",light_param.pwm_duty[LIGHT_COLD_WHITE]); + os_printf("LIGHT PARAM: WW: %d \r\n",light_param.pwm_duty[LIGHT_WARM_WHITE]); + } + os_printf("LIGHT PARAM: P: %d \r\n",light_param.pwm_period); + + uint32 light_init_target[8]={0}; + os_memcpy(light_init_target,light_param.pwm_duty,sizeof(light_param.pwm_duty)); + + light_set_aim( + light_init_target[LIGHT_RED], + light_init_target[LIGHT_GREEN], + light_init_target[LIGHT_BLUE], + light_init_target[LIGHT_COLD_WHITE], + light_init_target[LIGHT_WARM_WHITE], + light_param.pwm_period); + set_pwm_debug_en(0);//disable debug print in pwm driver + os_printf("PWM version : %08x \r\n",get_pwm_version()); +} +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_light_adj.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_light_adj.c new file mode 100644 index 0000000..519451a --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_light_adj.c @@ -0,0 +1,334 @@ + +#include "ets_sys.h" +#include "osapi.h" +#include "os_type.h" +#include "mem.h" +#include "user_interface.h" + +#include "user_light.h" +#include "user_light_adj.h" +#include "pwm.h" + +#define ABS_MINUS(x,y) (x LIGHT_EVT_QNUM ){ + TotalUsedLightEvtNum--; + } + else{ + tmp = &(LightEvtArr[CurFreeLightEvtIdx]); + CurFreeLightEvtIdx++; + if( CurFreeLightEvtIdx > (LIGHT_EVT_QNUM-1) ) + CurFreeLightEvtIdx = 0; + } + os_printf("malloc:%u\n",TotalUsedLightEvtNum); + return tmp; +} + +static void ICACHE_FLASH_ATTR LightEvtFree(void) +{ + TotalUsedLightEvtNum--; +os_printf("free:%u\n",TotalUsedLightEvtNum); +} +//------------------------------------------------------------------------------------ + +static void ICACHE_FLASH_ATTR light_pwm_smooth_adj_proc(void); + + +void ICACHE_FLASH_ATTR + light_save_target_duty() +{ + extern struct light_saved_param light_param; + + os_memcpy(light_param.pwm_duty,current_duty,sizeof(light_param.pwm_duty)); + light_param.pwm_period = pwm_get_period(); + +#if SAVE_LIGHT_PARAM + spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE); + spi_flash_write((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE, + (uint32 *)&light_param, sizeof(struct light_saved_param)); +#endif + +} + + +void ICACHE_FLASH_ATTR +light_set_aim_r(uint32 r) +{ + current_duty[LIGHT_RED]=r; + light_pwm_smooth_adj_proc(); +} + +void ICACHE_FLASH_ATTR +light_set_aim_g(uint32 g) +{ + current_duty[LIGHT_GREEN]=g; + light_pwm_smooth_adj_proc(); +} + +void ICACHE_FLASH_ATTR +light_set_aim_b(uint32 b) +{ + current_duty[LIGHT_BLUE]=b; + light_pwm_smooth_adj_proc(); +} + +void ICACHE_FLASH_ATTR +light_set_aim_cw(uint32 cw) +{ + current_duty[LIGHT_COLD_WHITE]=cw; + light_pwm_smooth_adj_proc(); +} + +void ICACHE_FLASH_ATTR +light_set_aim_ww(uint32 ww) +{ + current_duty[LIGHT_WARM_WHITE]=ww; + light_pwm_smooth_adj_proc(); +} + +LOCAL bool ICACHE_FLASH_ATTR + check_pwm_current_duty_diff() +{ + int i; + + for(i=0;i>4; + if( ABS_MINUS(duty_now[i],current_duty[i])<20 ) + duty_now[i] = current_duty[i]; + user_light_set_duty(duty_now[i],i); + } + + //os_printf("duty:%u,%u,%u\r\n", pwm.duty[0],pwm.duty[1],pwm.duty[2] ); + pwm_start(); + + if(check_pwm_current_duty_diff()){ + change_finish = 0; + os_timer_disarm(&timer_pwm_adj); + os_timer_setfn(&timer_pwm_adj, (os_timer_func_t *)light_dh_pwm_adj_proc, NULL); + os_timer_arm(&timer_pwm_adj, min_ms, 0); + } + else{ + os_printf("finish\n"); + change_finish = 1; + //light_save_target_duty(); + os_timer_disarm(&timer_pwm_adj); + light_pwm_smooth_adj_proc(); + } + +} + +LOCAL bool ICACHE_FLASH_ATTR + check_pwm_duty_zero() +{ + int i; + for(i=0;i0 ){ + user_light_set_period( LightEvtArr[CurEvtIdxToBeUse].period ); + + os_memcpy(current_duty,LightEvtArr[CurEvtIdxToBeUse].duty,sizeof(current_duty)); + CurEvtIdxToBeUse++; + if(CurEvtIdxToBeUse > (LIGHT_EVT_QNUM-1) ){ + CurEvtIdxToBeUse = 0; + } + LightEvtFree(); + + if(change_finish){ + light_dh_pwm_adj_proc(NULL); + } + } + + if(change_finish){ + light_save_target_duty(); + if(check_pwm_duty_zero()){ + if(light_sleep_flg==0){ + os_printf("light sleep en\r\n"); + wifi_set_sleep_type(LIGHT_SLEEP_T); + light_sleep_flg = 1; + } + } + } +} + + + +#if LIGHT_CURRENT_LIMIT +uint32 light_get_cur(uint32 duty , uint8 channel, uint32 period) +{ + uint32 duty_max_limit = (period*1000/45); + uint32 duty_mapped = duty*22727/duty_max_limit; + switch(channel){ + + case LIGHT_RED : + if(duty_mapped>=0 && duty_mapped<23000){ + return (duty_mapped*151000/22727); + } + + break; + + case LIGHT_GREEN: + if(duty_mapped>=0 && duty_mapped<23000){ + return (duty_mapped*82000/22727); + } + break; + + case LIGHT_BLUE: + if(duty_mapped>=0 && duty_mapped<23000){ + return (duty_mapped*70000/22727); + } + break; + + case LIGHT_COLD_WHITE: + case LIGHT_WARM_WHITE: + if(duty_mapped>=0 && duty_mapped<23000){ + return (duty_mapped*115000/22727); + } + break; + + default: + os_printf("CHANNEL ERROR IN GET_CUR\r\n"); + break; + + + + } + +} + +#endif + + + +void ICACHE_FLASH_ATTR +light_set_aim(uint32 r,uint32 g,uint32 b,uint32 cw,uint32 ww,uint32 period) +{ + struct pwm_param *tmp = LightEvtMalloc(); + if(tmp != NULL){ + tmp->period = (period<10000?period:10000); + uint32 duty_max_limit = (period*1000/45); + + tmp->duty[LIGHT_RED] = (rduty[LIGHT_GREEN] = (gduty[LIGHT_BLUE] = (bduty[LIGHT_COLD_WHITE] = (cwduty[LIGHT_WARM_WHITE] = (ww0 || ww>0){ + cur_r = light_get_cur(tmp->duty[LIGHT_RED] , LIGHT_RED, tmp->period); + + cur_g = light_get_cur(tmp->duty[LIGHT_GREEN] , LIGHT_GREEN, tmp->period); + cur_b = light_get_cur(tmp->duty[LIGHT_BLUE] , LIGHT_BLUE, tmp->period); + cur_rgb = (cur_r+cur_g+cur_b); + //} + uint32 cur_cw = light_get_cur( tmp->duty[LIGHT_COLD_WHITE],LIGHT_COLD_WHITE, tmp->period); + uint32 cur_ww = light_get_cur( tmp->duty[LIGHT_WARM_WHITE],LIGHT_WARM_WHITE, tmp->period); + uint32 cur_remain,cur_mar; + cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN); + cur_mar = LIGHT_CURRENT_MARGIN; + +/* + if((cur_cw < 50000) || (cur_ww < 50000)){ + cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN); + cur_mar = LIGHT_CURRENT_MARGIN; + }else if((cur_cw < 99000) || (cur_ww < 99000)){ + cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN_L2); + cur_mar = LIGHT_CURRENT_MARGIN_L2; + }else{ + cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN_L3); + cur_mar = LIGHT_CURRENT_MARGIN_L2; + } + + */ + + /* + if((LIGHT_TOTAL_CURRENT_MAX-cur_rgb)>120){ + cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN); + cur_mar = LIGHT_CURRENT_MARGIN; + }else if((LIGHT_TOTAL_CURRENT_MAX-cur_rgb)>100){ + cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN_L2); + cur_mar = LIGHT_CURRENT_MARGIN_L2; + }else{ + cur_remain = (LIGHT_TOTAL_CURRENT_MAX - cur_rgb -LIGHT_CURRENT_MARGIN_L3); + cur_mar = LIGHT_CURRENT_MARGIN_L2; + } + */ + + + + os_printf("cur_remain: %d \r\n",cur_remain); + while((cur_cw+cur_ww) > cur_remain){ + tmp->duty[LIGHT_COLD_WHITE] = tmp->duty[LIGHT_COLD_WHITE] * 9 / 10; + tmp->duty[LIGHT_WARM_WHITE] = tmp->duty[LIGHT_WARM_WHITE] * 9 / 10; + cur_cw = light_get_cur( tmp->duty[LIGHT_COLD_WHITE],LIGHT_COLD_WHITE, tmp->period); + cur_ww = light_get_cur( tmp->duty[LIGHT_WARM_WHITE],LIGHT_WARM_WHITE, tmp->period); + } + os_printf("debug : %d %d %d %d %d\r\n",cur_r/1000,cur_g/1000,cur_b/1000,cur_cw/1000,cur_ww/1000); + + os_printf("debug:total current after adj : %d + %d mA \r\n",(cur_cw+cur_ww+cur_r+cur_g+cur_b)/1000,cur_mar/1000); +#endif + + + + + os_printf("prd:%u r : %u g: %u b: %u cw: %u ww: %u \r\n",period, + tmp->duty[0],tmp->duty[1],tmp->duty[2],tmp->duty[3],tmp->duty[4]); + light_pwm_smooth_adj_proc(); + } + else{ + os_printf("light para full\n"); + } +} + + + + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_main.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_main.c new file mode 100644 index 0000000..beb8722 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_main.c @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_main.c + * + * Description: entry file of user application + * + * Modification history: + * 2014/1/1, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "osapi.h" + +#include "user_interface.h" + +#include "user_devicefind.h" +#include "user_webserver.h" + +#if ESP_PLATFORM +#include "user_esp_platform.h" +#endif + +#ifdef SERVER_SSL_ENABLE +#include "ssl/cert.h" +#include "ssl/private_key.h" +#else +#ifdef CLIENT_SSL_ENABLE +unsigned char *default_certificate; +unsigned int default_certificate_len = 0; +unsigned char *default_private_key; +unsigned int default_private_key_len = 0; +#endif +#endif + +void user_rf_pre_init(void) +{ +} + +/****************************************************************************** + * FunctionName : user_init + * Description : entry of user application, init user function here + * Parameters : none + * Returns : none +*******************************************************************************/ +void user_init(void) +{ + os_printf("SDK version:%s\n", system_get_sdk_version()); + +#if ESP_PLATFORM + /*Initialization of the peripheral drivers*/ + /*For light demo , it is user_light_init();*/ + /* Also check whether assigned ip addr by the router.If so, connect to ESP-server */ + user_esp_platform_init(); +#endif + /*Establish a udp socket to receive local device detect info.*/ + /*Listen to the port 1025, as well as udp broadcast. + /*If receive a string of device_find_request, it rely its IP address and MAC.*/ + user_devicefind_init(); + + /*Establish a TCP server for http(with JSON) POST or GET command to communicate with the device.*/ + /*You can find the command in "2B-SDK-Espressif IoT Demo.pdf" to see the details.*/ + /*the JSON command for curl is like:*/ + /*3 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000}}" http://192.168.4.1/config?command=light */ + /*5 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000,\"cwhite\":3000,\"wwhite\",3000}}" http://192.168.4.1/config?command=light */ +#ifdef SERVER_SSL_ENABLE + user_webserver_init(SERVER_SSL_PORT); +#else + user_webserver_init(SERVER_PORT); +#endif +} + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_plug.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_plug.c new file mode 100644 index 0000000..0397a4a --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_plug.c @@ -0,0 +1,159 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_plug.c + * + * Description: plug demo's function realization + * + * Modification history: + * 2014/5/1, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "osapi.h" +#include "os_type.h" +#include "mem.h" +#include "user_interface.h" + +#include "user_plug.h" + +#if PLUG_DEVICE + +LOCAL struct plug_saved_param plug_param; +LOCAL struct keys_param keys; +LOCAL struct single_key_param *single_key[PLUG_KEY_NUM]; +LOCAL os_timer_t link_led_timer; +LOCAL uint8 link_led_level = 0; + +/****************************************************************************** + * FunctionName : user_plug_get_status + * Description : get plug's status, 0x00 or 0x01 + * Parameters : none + * Returns : uint8 - plug's status +*******************************************************************************/ +uint8 ICACHE_FLASH_ATTR +user_plug_get_status(void) +{ + return plug_param.status; +} + +/****************************************************************************** + * FunctionName : user_plug_set_status + * Description : set plug's status, 0x00 or 0x01 + * Parameters : uint8 - status + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_plug_set_status(bool status) +{ + if (status != plug_param.status) { + if (status > 1) { + os_printf("error status input!\n"); + return; + } + + plug_param.status = status; + PLUG_STATUS_OUTPUT(PLUG_RELAY_LED_IO_NUM, status); + } +} + +/****************************************************************************** + * FunctionName : user_plug_short_press + * Description : key's short press function, needed to be installed + * Parameters : none + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_plug_short_press(void) +{ + user_plug_set_status((~plug_param.status) & 0x01); + + spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE); + spi_flash_write((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE, + (uint32 *)&plug_param, sizeof(struct plug_saved_param)); +} + +/****************************************************************************** + * FunctionName : user_plug_long_press + * Description : key's long press function, needed to be installed + * Parameters : none + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_plug_long_press(void) +{ + user_esp_platform_set_active(0); + system_restore(); + system_restart(); +} + +LOCAL void ICACHE_FLASH_ATTR +user_link_led_init(void) +{ + PIN_FUNC_SELECT(PLUG_LINK_LED_IO_MUX, PLUG_LINK_LED_IO_FUNC); +} + +void ICACHE_FLASH_ATTR +user_link_led_output(uint8 level) +{ + GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), level); +} + +LOCAL void ICACHE_FLASH_ATTR +user_link_led_timer_cb(void) +{ + link_led_level = (~link_led_level) & 0x01; + GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), link_led_level); +} + +void ICACHE_FLASH_ATTR +user_link_led_timer_init(void) +{ + os_timer_disarm(&link_led_timer); + os_timer_setfn(&link_led_timer, (os_timer_func_t *)user_link_led_timer_cb, NULL); + os_timer_arm(&link_led_timer, 50, 1); + link_led_level = 0; + GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), link_led_level); +} + +void ICACHE_FLASH_ATTR +user_link_led_timer_done(void) +{ + os_timer_disarm(&link_led_timer); + GPIO_OUTPUT_SET(GPIO_ID_PIN(PLUG_LINK_LED_IO_NUM), 0); +} + +/****************************************************************************** + * FunctionName : user_plug_init + * Description : init plug's key function and relay output + * Parameters : none + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_plug_init(void) +{ + user_link_led_init(); + + wifi_status_led_install(PLUG_WIFI_LED_IO_NUM, PLUG_WIFI_LED_IO_MUX, PLUG_WIFI_LED_IO_FUNC); + + single_key[0] = key_init_single(PLUG_KEY_0_IO_NUM, PLUG_KEY_0_IO_MUX, PLUG_KEY_0_IO_FUNC, + user_plug_long_press, user_plug_short_press); + + keys.key_num = PLUG_KEY_NUM; + keys.single_key = single_key; + + key_init(&keys); + + spi_flash_read((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE, + (uint32 *)&plug_param, sizeof(struct plug_saved_param)); + + PIN_FUNC_SELECT(PLUG_RELAY_LED_IO_MUX, PLUG_RELAY_LED_IO_FUNC); + + // no used SPI Flash + if (plug_param.status == 0xff) { + plug_param.status = 1; + } + + PLUG_STATUS_OUTPUT(PLUG_RELAY_LED_IO_NUM, plug_param.status); +} +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_sensor.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_sensor.c new file mode 100644 index 0000000..6019467 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_sensor.c @@ -0,0 +1,230 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_humiture.c + * + * Description: humiture demo's function realization + * + * Modification history: + * 2014/5/1, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "osapi.h" +#include "os_type.h" +#include "user_interface.h" + +#if SENSOR_DEVICE +#include "user_sensor.h" + +LOCAL struct keys_param keys; +LOCAL struct single_key_param *single_key[SENSOR_KEY_NUM]; +LOCAL os_timer_t sensor_sleep_timer; +LOCAL os_timer_t link_led_timer; +LOCAL uint8 link_led_level = 0; +LOCAL uint32 link_start_time; + +#if HUMITURE_SUB_DEVICE +#include "driver/i2c_master.h" + +#define MVH3004_Addr 0x88 + +LOCAL uint8 humiture_data[4]; + +/****************************************************************************** + * FunctionName : user_mvh3004_burst_read + * Description : burst read mvh3004's internal data + * Parameters : uint8 addr - mvh3004's address + * uint8 *pData - data point to put read data + * uint16 len - read length + * Returns : bool - true or false +*******************************************************************************/ +LOCAL bool ICACHE_FLASH_ATTR +user_mvh3004_burst_read(uint8 addr, uint8 *pData, uint16 len) +{ + uint8 ack; + uint16 i; + + i2c_master_start(); + i2c_master_writeByte(addr); + ack = i2c_master_getAck(); + + if (ack) { + os_printf("addr not ack when tx write cmd \n"); + i2c_master_stop(); + return false; + } + + i2c_master_stop(); + i2c_master_wait(40000); + + i2c_master_start(); + i2c_master_writeByte(addr + 1); + ack = i2c_master_getAck(); + + if (ack) { + os_printf("addr not ack when tx write cmd \n"); + i2c_master_stop(); + return false; + } + + for (i = 0; i < len; i++) { + pData[i] = i2c_master_readByte(); + + i2c_master_setAck((i == (len - 1)) ? 1 : 0); + } + + i2c_master_stop(); + + return true; +} + +/****************************************************************************** + * FunctionName : user_mvh3004_read_th + * Description : read mvh3004's humiture data + * Parameters : uint8 *data - where data to put + * Returns : bool - ture or false +*******************************************************************************/ +bool ICACHE_FLASH_ATTR +user_mvh3004_read_th(uint8 *data) +{ + return user_mvh3004_burst_read(MVH3004_Addr, data, 4); +} + +/****************************************************************************** + * FunctionName : user_mvh3004_init + * Description : init mvh3004, mainly i2c master gpio + * Parameters : none + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_mvh3004_init(void) +{ + i2c_master_gpio_init(); +} + +uint8 *ICACHE_FLASH_ATTR +user_mvh3004_get_poweron_th(void) +{ + return humiture_data; +} +#endif + +/****************************************************************************** + * FunctionName : user_humiture_long_press + * Description : humiture key's function, needed to be installed + * Parameters : none + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +user_sensor_long_press(void) +{ + user_esp_platform_set_active(0); + system_restore(); + system_restart(); +} + +LOCAL void ICACHE_FLASH_ATTR +user_link_led_init(void) +{ + PIN_FUNC_SELECT(SENSOR_LINK_LED_IO_MUX, SENSOR_LINK_LED_IO_FUNC); + PIN_FUNC_SELECT(SENSOR_UNUSED_LED_IO_MUX, SENSOR_UNUSED_LED_IO_FUNC); + GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_UNUSED_LED_IO_NUM), 0); +} + +void ICACHE_FLASH_ATTR +user_link_led_output(uint8 level) +{ + GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), level); +} + +LOCAL void ICACHE_FLASH_ATTR +user_link_led_timer_cb(void) +{ + link_led_level = (~link_led_level) & 0x01; + GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), link_led_level); +} + +void ICACHE_FLASH_ATTR +user_link_led_timer_init(void) +{ + link_start_time = system_get_time(); + + os_timer_disarm(&link_led_timer); + os_timer_setfn(&link_led_timer, (os_timer_func_t *)user_link_led_timer_cb, NULL); + os_timer_arm(&link_led_timer, 50, 1); + link_led_level = 0; + GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), link_led_level); +} + +void ICACHE_FLASH_ATTR +user_link_led_timer_done(void) +{ + os_timer_disarm(&link_led_timer); + GPIO_OUTPUT_SET(GPIO_ID_PIN(SENSOR_LINK_LED_IO_NUM), 0); +} + +void ICACHE_FLASH_ATTR +user_sensor_deep_sleep_enter(void) +{ + system_deep_sleep(SENSOR_DEEP_SLEEP_TIME > link_start_time \ + ? SENSOR_DEEP_SLEEP_TIME - link_start_time : 30000000); +} + +void ICACHE_FLASH_ATTR +user_sensor_deep_sleep_disable(void) +{ + os_timer_disarm(&sensor_sleep_timer); +} + +void ICACHE_FLASH_ATTR +user_sensor_deep_sleep_init(uint32 time) +{ + os_timer_disarm(&sensor_sleep_timer); + os_timer_setfn(&sensor_sleep_timer, (os_timer_func_t *)user_sensor_deep_sleep_enter, NULL); + os_timer_arm(&sensor_sleep_timer, time, 0); +} + +/****************************************************************************** + * FunctionName : user_humiture_init + * Description : init humiture function, include key and mvh3004 + * Parameters : none + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_sensor_init(uint8 active) +{ + user_link_led_init(); + + wifi_status_led_install(SENSOR_WIFI_LED_IO_NUM, SENSOR_WIFI_LED_IO_MUX, SENSOR_WIFI_LED_IO_FUNC); + + if (wifi_get_opmode() != SOFTAP_MODE) { + single_key[0] = key_init_single(SENSOR_KEY_IO_NUM, SENSOR_KEY_IO_MUX, SENSOR_KEY_IO_FUNC, + user_sensor_long_press, NULL); + + keys.key_num = SENSOR_KEY_NUM; + keys.single_key = single_key; + + key_init(&keys); + + if (GPIO_INPUT_GET(GPIO_ID_PIN(SENSOR_KEY_IO_NUM)) == 0) { + user_sensor_long_press(); + } + } + +#if HUMITURE_SUB_DEVICE + user_mvh3004_init(); + user_mvh3004_read_th(humiture_data); +#endif + +#ifdef SENSOR_DEEP_SLEEP + if (wifi_get_opmode() != STATIONAP_MODE) { + if (active == 1) { + user_sensor_deep_sleep_init(SENSOR_DEEP_SLEEP_TIME / 1000 ); + } else { + user_sensor_deep_sleep_init(SENSOR_DEEP_SLEEP_TIME / 1000 / 3 * 2); + } + } +#endif +} +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_webserver.c b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_webserver.c new file mode 100644 index 0000000..76d6f85 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/IoT_Demo/user/user_webserver.c @@ -0,0 +1,1783 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_webserver.c + * + * Description: The web server mode configration. + * Check your hardware connection with the host while use this mode. + * Modification history: + * 2014/3/12, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "os_type.h" +#include "osapi.h" +#include "mem.h" +#include "user_interface.h" + +#include "user_iot_version.h" +#include "espconn.h" +#include "user_json.h" +#include "user_webserver.h" + +#include "upgrade.h" +#if ESP_PLATFORM +#include "user_esp_platform.h" +#endif + +#if LIGHT_DEVICE +#include "user_light.h" +#endif + +LOCAL struct station_config *sta_conf; +LOCAL struct softap_config *ap_conf; + +//LOCAL struct secrty_server_info *sec_server; +//LOCAL struct upgrade_server_info *server; +//struct lewei_login_info *login_info; +LOCAL scaninfo *pscaninfo; +struct bss_info *bss; +struct bss_info *bss_temp; +struct bss_info *bss_head; + +extern u16 scannum; + +LOCAL uint32 PostCmdNeeRsp = 1; + +uint8 upgrade_lock = 0; +LOCAL os_timer_t app_upgrade_10s; +LOCAL os_timer_t upgrade_check_timer; + +/****************************************************************************** + * FunctionName : device_get + * Description : set up the device information parmer as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +device_get(struct jsontree_context *js_ctx) +{ + const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); + + if (os_strncmp(path, "manufacture", 11) == 0) { + jsontree_write_string(js_ctx, "Espressif Systems"); + } else if (os_strncmp(path, "product", 7) == 0) { +#if SENSOR_DEVICE +#if HUMITURE_SUB_DEVICE + jsontree_write_string(js_ctx, "Humiture"); +#elif FLAMMABLE_GAS_SUB_DEVICE + jsontree_write_string(js_ctx, "Flammable Gas"); +#endif +#endif +#if PLUG_DEVICE + jsontree_write_string(js_ctx, "Plug"); +#endif +#if LIGHT_DEVICE + jsontree_write_string(js_ctx, "Light"); +#endif + } + + return 0; +} + +LOCAL struct jsontree_callback device_callback = + JSONTREE_CALLBACK(device_get, NULL); +/****************************************************************************** + * FunctionName : userbin_get + * Description : get up the user bin paramer as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +userbin_get(struct jsontree_context *js_ctx) +{ + const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); + char string[32]; + + if (os_strncmp(path, "status", 8) == 0) { + os_sprintf(string, "200"); + } else if (os_strncmp(path, "user_bin", 8) == 0) { + if (system_upgrade_userbin_check() == 0x00) { + os_sprintf(string, "user1.bin"); + } else if (system_upgrade_userbin_check() == 0x01) { + os_sprintf(string, "user2.bin"); + } else{ + return 0; + } + } + + jsontree_write_string(js_ctx, string); + + return 0; +} + +LOCAL struct jsontree_callback userbin_callback = + JSONTREE_CALLBACK(userbin_get, NULL); + +JSONTREE_OBJECT(userbin_tree, + JSONTREE_PAIR("status", &userbin_callback), + JSONTREE_PAIR("user_bin", &userbin_callback)); +JSONTREE_OBJECT(userinfo_tree,JSONTREE_PAIR("user_info",&userbin_tree)); +/****************************************************************************** + * FunctionName : version_get + * Description : set up the device version paramer as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +version_get(struct jsontree_context *js_ctx) +{ + const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); + char string[32]; + + if (os_strncmp(path, "hardware", 8) == 0) { +#if SENSOR_DEVICE + os_sprintf(string, "0.3"); +#else + os_sprintf(string, "0.1"); +#endif + } else if (os_strncmp(path, "sdk_version", 11) == 0) { + os_sprintf(string, "%s", system_get_sdk_version()); + } else if (os_strncmp(path, "iot_version", 11) == 0) { + os_sprintf(string,"%s%d.%d.%dt%d(%s)",VERSION_TYPE,IOT_VERSION_MAJOR,\ + IOT_VERSION_MINOR,IOT_VERSION_REVISION,device_type,UPGRADE_FALG); + } + + jsontree_write_string(js_ctx, string); + + return 0; +} + +LOCAL struct jsontree_callback version_callback = + JSONTREE_CALLBACK(version_get, NULL); + +JSONTREE_OBJECT(device_tree, + JSONTREE_PAIR("product", &device_callback), + JSONTREE_PAIR("manufacturer", &device_callback)); +JSONTREE_OBJECT(version_tree, + JSONTREE_PAIR("hardware", &version_callback), + JSONTREE_PAIR("sdk_version", &version_callback), + JSONTREE_PAIR("iot_version", &version_callback), + ); +JSONTREE_OBJECT(info_tree, + JSONTREE_PAIR("Version", &version_tree), + JSONTREE_PAIR("Device", &device_tree)); + +JSONTREE_OBJECT(INFOTree, + JSONTREE_PAIR("info", &info_tree)); + +LOCAL int ICACHE_FLASH_ATTR +connect_status_get(struct jsontree_context *js_ctx) +{ + const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); + + if (os_strncmp(path, "status", 8) == 0) { + jsontree_write_int(js_ctx, user_esp_platform_get_connect_status()); + } + + return 0; +} + +LOCAL struct jsontree_callback connect_status_callback = + JSONTREE_CALLBACK(connect_status_get, NULL); + +JSONTREE_OBJECT(status_sub_tree, + JSONTREE_PAIR("status", &connect_status_callback)); + +JSONTREE_OBJECT(connect_status_tree, + JSONTREE_PAIR("Status", &status_sub_tree)); + +JSONTREE_OBJECT(con_status_tree, + JSONTREE_PAIR("info", &connect_status_tree)); + +#if PLUG_DEVICE +/****************************************************************************** + * FunctionName : status_get + * Description : set up the device status as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +status_get(struct jsontree_context *js_ctx) +{ + if (user_plug_get_status() == 1) { + jsontree_write_int(js_ctx, 1); + } else { + jsontree_write_int(js_ctx, 0); + } + + return 0; +} + +/****************************************************************************** + * FunctionName : status_set + * Description : parse the device status parmer as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * parser -- A pointer to a JSON parser state + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +status_set(struct jsontree_context *js_ctx, struct jsonparse_state *parser) +{ + int type; + + while ((type = jsonparse_next(parser)) != 0) { + if (type == JSON_TYPE_PAIR_NAME) { + if (jsonparse_strcmp_value(parser, "status") == 0) { + uint8 status; + jsonparse_next(parser); + jsonparse_next(parser); + status = jsonparse_get_value_as_int(parser); + user_plug_set_status(status); + } + } + } + + return 0; +} + +LOCAL struct jsontree_callback status_callback = + JSONTREE_CALLBACK(status_get, status_set); + +JSONTREE_OBJECT(status_tree, + JSONTREE_PAIR("status", &status_callback)); +JSONTREE_OBJECT(response_tree, + JSONTREE_PAIR("Response", &status_tree)); +JSONTREE_OBJECT(StatusTree, + JSONTREE_PAIR("switch", &response_tree)); +#endif + +#if LIGHT_DEVICE +LOCAL int ICACHE_FLASH_ATTR +light_status_get(struct jsontree_context *js_ctx) +{ + const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); + + if (os_strncmp(path, "red", 3) == 0) { + jsontree_write_int(js_ctx, user_light_get_duty(LIGHT_RED)); + } else if (os_strncmp(path, "green", 5) == 0) { + jsontree_write_int(js_ctx, user_light_get_duty(LIGHT_GREEN)); + } else if (os_strncmp(path, "blue", 4) == 0) { + jsontree_write_int(js_ctx, user_light_get_duty(LIGHT_BLUE)); + } else if (os_strncmp(path, "wwhite", 6) == 0) { + if(PWM_CHANNEL>LIGHT_WARM_WHITE){ + jsontree_write_int(js_ctx, user_light_get_duty(LIGHT_WARM_WHITE)); + }else{ + jsontree_write_int(js_ctx, 0); + } + } else if (os_strncmp(path, "cwhite", 6) == 0) { + if(PWM_CHANNEL>LIGHT_COLD_WHITE){ + jsontree_write_int(js_ctx, user_light_get_duty(LIGHT_COLD_WHITE)); + }else{ + jsontree_write_int(js_ctx, 0); + } + } else if (os_strncmp(path, "period", 6) == 0) { + jsontree_write_int(js_ctx, user_light_get_period()); + } + + return 0; +} + +LOCAL int ICACHE_FLASH_ATTR +light_status_set(struct jsontree_context *js_ctx, struct jsonparse_state *parser) +{ + int type; + static uint32 r,g,b,cw,ww,period; + period = 1000; + cw=0; + ww=0; + extern uint8 light_sleep_flg; + + while ((type = jsonparse_next(parser)) != 0) { + if (type == JSON_TYPE_PAIR_NAME) { + if (jsonparse_strcmp_value(parser, "red") == 0) { + uint32 status; + jsonparse_next(parser); + jsonparse_next(parser); + status = jsonparse_get_value_as_int(parser); + r=status; + os_printf("R: %d \n",status); + //user_light_set_duty(status, LIGHT_RED); + //light_set_aim_r( r); + } else if (jsonparse_strcmp_value(parser, "green") == 0) { + uint32 status; + jsonparse_next(parser); + jsonparse_next(parser); + status = jsonparse_get_value_as_int(parser); + g=status; + os_printf("G: %d \n",status); + //user_light_set_duty(status, LIGHT_GREEN); + //light_set_aim_g( g); + } else if (jsonparse_strcmp_value(parser, "blue") == 0) { + uint32 status; + jsonparse_next(parser); + jsonparse_next(parser); + status = jsonparse_get_value_as_int(parser); + b=status; + os_printf("B: %d \n",status); + //user_light_set_duty(status, LIGHT_BLUE); + //set_aim_b( b); + } else if (jsonparse_strcmp_value(parser, "cwhite") == 0) { + uint32 status; + jsonparse_next(parser); + jsonparse_next(parser); + status = jsonparse_get_value_as_int(parser); + cw=status; + os_printf("CW: %d \n",status); + //user_light_set_duty(status, LIGHT_BLUE); + //set_aim_b( b); + } else if (jsonparse_strcmp_value(parser, "wwhite") == 0) { + uint32 status; + jsonparse_next(parser); + jsonparse_next(parser); + status = jsonparse_get_value_as_int(parser); + ww=status; + os_printf("WW: %d \n",status); + //user_light_set_duty(status, LIGHT_BLUE); + //set_aim_b( b); + } else if (jsonparse_strcmp_value(parser, "period") == 0) { + uint32 status; + jsonparse_next(parser); + jsonparse_next(parser); + status = jsonparse_get_value_as_int(parser); + os_printf("PERIOD: %d \n",status); + period=status; + //user_light_set_period(status); + }else if (jsonparse_strcmp_value(parser, "response") == 0) { + uint32 status; + jsonparse_next(parser); + jsonparse_next(parser); + status = jsonparse_get_value_as_int(parser); + os_printf("rspneed: %d \n",status); + PostCmdNeeRsp = status; + + } + } + } + + if((r|g|b|ww|cw) == 0){ + if(light_sleep_flg==0){ + + } + + }else{ + if(light_sleep_flg==1){ + os_printf("modem sleep en\r\n"); + wifi_set_sleep_type(MODEM_SLEEP_T); + light_sleep_flg =0; + } + } + light_set_aim(r,g,b,cw,ww,period); + return 0; +} + +LOCAL struct jsontree_callback light_callback = + JSONTREE_CALLBACK(light_status_get, light_status_set); + +JSONTREE_OBJECT(rgb_tree, + JSONTREE_PAIR("red", &light_callback), + JSONTREE_PAIR("green", &light_callback), + JSONTREE_PAIR("blue", &light_callback), + JSONTREE_PAIR("cwhite", &light_callback), + JSONTREE_PAIR("wwhite", &light_callback), + ); +JSONTREE_OBJECT(sta_tree, + JSONTREE_PAIR("period", &light_callback), + JSONTREE_PAIR("rgb", &rgb_tree)); +JSONTREE_OBJECT(PwmTree, + JSONTREE_PAIR("light", &sta_tree)); +#endif + +/****************************************************************************** + * FunctionName : wifi_station_get + * Description : set up the station paramer as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +wifi_station_get(struct jsontree_context *js_ctx) +{ + const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); + struct ip_info ipconfig; + uint8 buf[20]; + os_bzero(buf, sizeof(buf)); + wifi_station_get_config(sta_conf); + wifi_get_ip_info(STATION_IF, &ipconfig); + + if (os_strncmp(path, "ssid", 4) == 0) { + jsontree_write_string(js_ctx, sta_conf->ssid); + } else if (os_strncmp(path, "password", 8) == 0) { + jsontree_write_string(js_ctx, sta_conf->password); + } else if (os_strncmp(path, "ip", 2) == 0) { + os_sprintf(buf, IPSTR, IP2STR(&ipconfig.ip)); + jsontree_write_string(js_ctx, buf); + } else if (os_strncmp(path, "mask", 4) == 0) { + os_sprintf(buf, IPSTR, IP2STR(&ipconfig.netmask)); + jsontree_write_string(js_ctx, buf); + } else if (os_strncmp(path, "gw", 2) == 0) { + os_sprintf(buf, IPSTR, IP2STR(&ipconfig.gw)); + jsontree_write_string(js_ctx, buf); + } + + return 0; +} + +/****************************************************************************** + * FunctionName : wifi_station_set + * Description : parse the station parmer as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * parser -- A pointer to a JSON parser state + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +wifi_station_set(struct jsontree_context *js_ctx, struct jsonparse_state *parser) +{ + int type; + uint8 station_tree; + + while ((type = jsonparse_next(parser)) != 0) { + if (type == JSON_TYPE_PAIR_NAME) { + char buffer[64]; + os_bzero(buffer, 64); + + if (jsonparse_strcmp_value(parser, "Station") == 0) { + station_tree = 1; + } else if (jsonparse_strcmp_value(parser, "Softap") == 0) { + station_tree = 0; + } + + if (station_tree) { + if (jsonparse_strcmp_value(parser, "ssid") == 0) { + jsonparse_next(parser); + jsonparse_next(parser); + jsonparse_copy_value(parser, buffer, sizeof(buffer)); + os_memcpy(sta_conf->ssid, buffer, os_strlen(buffer)); + } else if (jsonparse_strcmp_value(parser, "password") == 0) { + jsonparse_next(parser); + jsonparse_next(parser); + jsonparse_copy_value(parser, buffer, sizeof(buffer)); + os_memcpy(sta_conf->password, buffer, os_strlen(buffer)); + } + +#if ESP_PLATFORM + + else if (jsonparse_strcmp_value(parser, "token") == 0) { + jsonparse_next(parser); + jsonparse_next(parser); + jsonparse_copy_value(parser, buffer, sizeof(buffer)); + user_esp_platform_set_token(buffer); + } + +#endif + } + } + } + + return 0; +} + +LOCAL struct jsontree_callback wifi_station_callback = + JSONTREE_CALLBACK(wifi_station_get, wifi_station_set); + +JSONTREE_OBJECT(get_station_config_tree, + JSONTREE_PAIR("ssid", &wifi_station_callback), + JSONTREE_PAIR("password", &wifi_station_callback)); +JSONTREE_OBJECT(set_station_config_tree, + JSONTREE_PAIR("ssid", &wifi_station_callback), + JSONTREE_PAIR("password", &wifi_station_callback), + JSONTREE_PAIR("token", &wifi_station_callback)); + +JSONTREE_OBJECT(ip_tree, + JSONTREE_PAIR("ip", &wifi_station_callback), + JSONTREE_PAIR("mask", &wifi_station_callback), + JSONTREE_PAIR("gw", &wifi_station_callback)); +JSONTREE_OBJECT(get_station_tree, + JSONTREE_PAIR("Connect_Station", &get_station_config_tree), + JSONTREE_PAIR("Ipinfo_Station", &ip_tree)); +JSONTREE_OBJECT(set_station_tree, + JSONTREE_PAIR("Connect_Station", &set_station_config_tree)); + +//JSONTREE_OBJECT(get_wifi_station_info_tree, +// JSONTREE_PAIR("Station", &get_station_tree)); +//JSONTREE_OBJECT(set_wifi_station_info_tree, +// JSONTREE_PAIR("station", &set_station_tree)); + +/****************************************************************************** + * FunctionName : wifi_softap_get + * Description : set up the softap paramer as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +wifi_softap_get(struct jsontree_context *js_ctx) +{ + const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); + struct ip_info ipconfig; + uint8 buf[20]; + os_bzero(buf, sizeof(buf)); + wifi_softap_get_config(ap_conf); + wifi_get_ip_info(SOFTAP_IF, &ipconfig); + + if (os_strncmp(path, "ssid", 4) == 0) { + jsontree_write_string(js_ctx, ap_conf->ssid); + } else if (os_strncmp(path, "password", 8) == 0) { + jsontree_write_string(js_ctx, ap_conf->password); + } else if (os_strncmp(path, "channel", 7) == 0) { + jsontree_write_int(js_ctx, ap_conf->channel); + } else if (os_strncmp(path, "authmode", 8) == 0) { + switch (ap_conf->authmode) { + case AUTH_OPEN: + jsontree_write_string(js_ctx, "OPEN"); + break; + + case AUTH_WEP: + jsontree_write_string(js_ctx, "WEP"); + break; + + case AUTH_WPA_PSK: + jsontree_write_string(js_ctx, "WPAPSK"); + break; + + case AUTH_WPA2_PSK: + jsontree_write_string(js_ctx, "WPA2PSK"); + break; + + case AUTH_WPA_WPA2_PSK: + jsontree_write_string(js_ctx, "WPAPSK/WPA2PSK"); + break; + + default : + jsontree_write_int(js_ctx, ap_conf->authmode); + break; + } + } else if (os_strncmp(path, "ip", 2) == 0) { + os_sprintf(buf, IPSTR, IP2STR(&ipconfig.ip)); + jsontree_write_string(js_ctx, buf); + } else if (os_strncmp(path, "mask", 4) == 0) { + os_sprintf(buf, IPSTR, IP2STR(&ipconfig.netmask)); + jsontree_write_string(js_ctx, buf); + } else if (os_strncmp(path, "gw", 2) == 0) { + os_sprintf(buf, IPSTR, IP2STR(&ipconfig.gw)); + jsontree_write_string(js_ctx, buf); + } + + return 0; +} + +/****************************************************************************** + * FunctionName : wifi_softap_set + * Description : parse the softap parmer as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * parser -- A pointer to a JSON parser state + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +wifi_softap_set(struct jsontree_context *js_ctx, struct jsonparse_state *parser) +{ + int type; + uint8 softap_tree; + + while ((type = jsonparse_next(parser)) != 0) { + if (type == JSON_TYPE_PAIR_NAME) { + char buffer[64]; + os_bzero(buffer, 64); + + if (jsonparse_strcmp_value(parser, "Station") == 0) { + softap_tree = 0; + } else if (jsonparse_strcmp_value(parser, "Softap") == 0) { + softap_tree = 1; + } + + if (softap_tree) { + if (jsonparse_strcmp_value(parser, "authmode") == 0) { + jsonparse_next(parser); + jsonparse_next(parser); + jsonparse_copy_value(parser, buffer, sizeof(buffer)); + + // other mode will be supported later... + if (os_strcmp(buffer, "OPEN") == 0) { + ap_conf->authmode = AUTH_OPEN; + } else if (os_strcmp(buffer, "WPAPSK") == 0) { + ap_conf->authmode = AUTH_WPA_PSK; + os_printf("%d %s\n", ap_conf->authmode, buffer); + } else if (os_strcmp(buffer, "WPA2PSK") == 0) { + ap_conf->authmode = AUTH_WPA2_PSK; + } else if (os_strcmp(buffer, "WPAPSK/WPA2PSK") == 0) { + ap_conf->authmode = AUTH_WPA_WPA2_PSK; + } else { + ap_conf->authmode = AUTH_OPEN; + return 0; + } + } + + if (jsonparse_strcmp_value(parser, "channel") == 0) { + jsonparse_next(parser); + jsonparse_next(parser); + ap_conf->channel = jsonparse_get_value_as_int(parser); + } else if (jsonparse_strcmp_value(parser, "ssid") == 0) { + jsonparse_next(parser); + jsonparse_next(parser); + jsonparse_copy_value(parser, buffer, sizeof(buffer)); + os_memcpy(ap_conf->ssid, buffer, os_strlen(buffer)); + } else if (jsonparse_strcmp_value(parser, "password") == 0) { + jsonparse_next(parser); + jsonparse_next(parser); + jsonparse_copy_value(parser, buffer, sizeof(buffer)); + os_memcpy(ap_conf->password, buffer, os_strlen(buffer)); + } + } + } + } + + return 0; +} + +LOCAL struct jsontree_callback wifi_softap_callback = + JSONTREE_CALLBACK(wifi_softap_get, wifi_softap_set); + +JSONTREE_OBJECT(softap_config_tree, + JSONTREE_PAIR("authmode", &wifi_softap_callback), + JSONTREE_PAIR("channel", &wifi_softap_callback), + JSONTREE_PAIR("ssid", &wifi_softap_callback), + JSONTREE_PAIR("password", &wifi_softap_callback)); +JSONTREE_OBJECT(softap_ip_tree, + JSONTREE_PAIR("ip", &wifi_softap_callback), + JSONTREE_PAIR("mask", &wifi_softap_callback), + JSONTREE_PAIR("gw", &wifi_softap_callback)); +JSONTREE_OBJECT(get_softap_tree, + JSONTREE_PAIR("Connect_Softap", &softap_config_tree), + JSONTREE_PAIR("Ipinfo_Softap", &softap_ip_tree)); +JSONTREE_OBJECT(set_softap_tree, + JSONTREE_PAIR("Ipinfo_Softap", &softap_config_tree)); + +JSONTREE_OBJECT(get_wifi_tree, + JSONTREE_PAIR("Station", &get_station_tree), + JSONTREE_PAIR("Softap", &get_softap_tree)); +JSONTREE_OBJECT(set_wifi_tree, + JSONTREE_PAIR("Station", &set_station_tree), + JSONTREE_PAIR("Softap", &set_softap_tree)); + +JSONTREE_OBJECT(wifi_response_tree, + JSONTREE_PAIR("Response", &get_wifi_tree)); +JSONTREE_OBJECT(wifi_request_tree, + JSONTREE_PAIR("Request", &set_wifi_tree)); + +JSONTREE_OBJECT(wifi_info_tree, + JSONTREE_PAIR("wifi", &wifi_response_tree)); +JSONTREE_OBJECT(wifi_req_tree, + JSONTREE_PAIR("wifi", &wifi_request_tree)); + + +/****************************************************************************** + * FunctionName : scan_get + * Description : set up the scan data as a JSON format + * Parameters : js_ctx -- A pointer to a JSON set up + * Returns : result +*******************************************************************************/ +LOCAL int ICACHE_FLASH_ATTR +scan_get(struct jsontree_context *js_ctx) +{ + const char *path = jsontree_path_name(js_ctx, js_ctx->depth - 1); + // STAILQ_HEAD(, bss_info) *pbss = scanarg; +// LOCAL struct bss_info *bss; + + if (os_strncmp(path, "TotalPage", 9) == 0) { + jsontree_write_int(js_ctx, pscaninfo->totalpage); + } else if (os_strncmp(path, "PageNum", 7) == 0) { + jsontree_write_int(js_ctx, pscaninfo->pagenum); + } else if (os_strncmp(path, "bssid", 5) == 0) { + if( bss == NULL ) + bss = bss_head; + u8 buffer[32]; + //if (bss != NULL){ + os_memset(buffer, 0, sizeof(buffer)); + os_sprintf(buffer, MACSTR, MAC2STR(bss->bssid)); + jsontree_write_string(js_ctx, buffer); + //} + } else if (os_strncmp(path, "ssid", 4) == 0) { + //if (bss != NULL) + jsontree_write_string(js_ctx, bss->ssid); + } else if (os_strncmp(path, "rssi", 4) == 0) { + //if (bss != NULL) + jsontree_write_int(js_ctx, -(bss->rssi)); + } else if (os_strncmp(path, "channel", 7) == 0) { + //if (bss != NULL) + jsontree_write_int(js_ctx, bss->channel); + } else if (os_strncmp(path, "authmode", 8) == 0) { + //if (bss != NULL){ + switch (bss->authmode) { + case AUTH_OPEN: + jsontree_write_string(js_ctx, "OPEN"); + break; + + case AUTH_WEP: + jsontree_write_string(js_ctx, "WEP"); + break; + + case AUTH_WPA_PSK: + jsontree_write_string(js_ctx, "WPAPSK"); + break; + + case AUTH_WPA2_PSK: + jsontree_write_string(js_ctx, "WPA2PSK"); + break; + + case AUTH_WPA_WPA2_PSK: + jsontree_write_string(js_ctx, "WPAPSK/WPA2PSK"); + break; + + default : + jsontree_write_int(js_ctx, bss->authmode); + break; + } + + bss = STAILQ_NEXT(bss, next); +// os_free(bss); + //} + } + + return 0; +} + +LOCAL struct jsontree_callback scan_callback = + JSONTREE_CALLBACK(scan_get, NULL); + +JSONTREE_OBJECT(scaninfo_tree, + JSONTREE_PAIR("bssid", &scan_callback), + JSONTREE_PAIR("ssid", &scan_callback), + JSONTREE_PAIR("rssi", &scan_callback), + JSONTREE_PAIR("channel", &scan_callback), + JSONTREE_PAIR("authmode", &scan_callback)); +JSONTREE_ARRAY(scanrslt_tree, + JSONTREE_PAIR_ARRAY(&scaninfo_tree), + JSONTREE_PAIR_ARRAY(&scaninfo_tree), + JSONTREE_PAIR_ARRAY(&scaninfo_tree), + JSONTREE_PAIR_ARRAY(&scaninfo_tree), + JSONTREE_PAIR_ARRAY(&scaninfo_tree), + JSONTREE_PAIR_ARRAY(&scaninfo_tree), + JSONTREE_PAIR_ARRAY(&scaninfo_tree), + JSONTREE_PAIR_ARRAY(&scaninfo_tree)); + +JSONTREE_OBJECT(scantree, + JSONTREE_PAIR("TotalPage", &scan_callback), + JSONTREE_PAIR("PageNum", &scan_callback), + JSONTREE_PAIR("ScanResult", &scanrslt_tree)); +JSONTREE_OBJECT(scanres_tree, + JSONTREE_PAIR("Response", &scantree)); +JSONTREE_OBJECT(scan_tree, + JSONTREE_PAIR("scan", &scanres_tree)); + +/****************************************************************************** + * FunctionName : parse_url + * Description : parse the received data from the server + * Parameters : precv -- the received data + * purl_frame -- the result of parsing the url + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +parse_url(char *precv, URL_Frame *purl_frame) +{ + char *str = NULL; + uint8 length = 0; + char *pbuffer = NULL; + char *pbufer = NULL; + + if (purl_frame == NULL || precv == NULL) { + return; + } + + pbuffer = (char *)os_strstr(precv, "Host:"); + + if (pbuffer != NULL) { + length = pbuffer - precv; + pbufer = (char *)os_zalloc(length + 1); + pbuffer = pbufer; + os_memcpy(pbuffer, precv, length); + os_memset(purl_frame->pSelect, 0, URLSize); + os_memset(purl_frame->pCommand, 0, URLSize); + os_memset(purl_frame->pFilename, 0, URLSize); + + if (os_strncmp(pbuffer, "GET ", 4) == 0) { + purl_frame->Type = GET; + pbuffer += 4; + } else if (os_strncmp(pbuffer, "POST ", 5) == 0) { + purl_frame->Type = POST; + pbuffer += 5; + } + + pbuffer ++; + str = (char *)os_strstr(pbuffer, "?"); + + if (str != NULL) { + length = str - pbuffer; + os_memcpy(purl_frame->pSelect, pbuffer, length); + str ++; + pbuffer = (char *)os_strstr(str, "="); + + if (pbuffer != NULL) { + length = pbuffer - str; + os_memcpy(purl_frame->pCommand, str, length); + pbuffer ++; + str = (char *)os_strstr(pbuffer, "&"); + + if (str != NULL) { + length = str - pbuffer; + os_memcpy(purl_frame->pFilename, pbuffer, length); + } else { + str = (char *)os_strstr(pbuffer, " HTTP"); + + if (str != NULL) { + length = str - pbuffer; + os_memcpy(purl_frame->pFilename, pbuffer, length); + } + } + } + } + + os_free(pbufer); + } else { + return; + } +} + +LOCAL char *precvbuffer; +static uint32 dat_sumlength = 0; +LOCAL bool ICACHE_FLASH_ATTR +save_data(char *precv, uint16 length) +{ + bool flag = false; + char length_buf[10] = {0}; + char *ptemp = NULL; + char *pdata = NULL; + uint16 headlength = 0; + static uint32 totallength = 0; + + ptemp = (char *)os_strstr(precv, "\r\n\r\n"); + + if (ptemp != NULL) { + length -= ptemp - precv; + length -= 4; + totallength += length; + headlength = ptemp - precv + 4; + pdata = (char *)os_strstr(precv, "Content-Length: "); + + if (pdata != NULL) { + pdata += 16; + precvbuffer = (char *)os_strstr(pdata, "\r\n"); + + if (precvbuffer != NULL) { + os_memcpy(length_buf, pdata, precvbuffer - pdata); + dat_sumlength = atoi(length_buf); + } + } else { + if (totallength != 0x00){ + totallength = 0; + dat_sumlength = 0; + return false; + } + } + if ((dat_sumlength + headlength) >= 1024) { + precvbuffer = (char *)os_zalloc(headlength + 1); + os_memcpy(precvbuffer, precv, headlength + 1); + } else { + precvbuffer = (char *)os_zalloc(dat_sumlength + headlength + 1); + os_memcpy(precvbuffer, precv, os_strlen(precv)); + } + } else { + if (precvbuffer != NULL) { + totallength += length; + os_memcpy(precvbuffer + os_strlen(precvbuffer), precv, length); + } else { + totallength = 0; + dat_sumlength = 0; + return false; + } + } + + if (totallength == dat_sumlength) { + totallength = 0; + dat_sumlength = 0; + return true; + } else { + return false; + } +} + +LOCAL bool ICACHE_FLASH_ATTR +check_data(char *precv, uint16 length) +{ + //bool flag = true; + char length_buf[10] = {0}; + char *ptemp = NULL; + char *pdata = NULL; + char *tmp_precvbuffer; + uint16 tmp_length = length; + uint32 tmp_totallength = 0; + + ptemp = (char *)os_strstr(precv, "\r\n\r\n"); + + if (ptemp != NULL) { + tmp_length -= ptemp - precv; + tmp_length -= 4; + tmp_totallength += tmp_length; + + pdata = (char *)os_strstr(precv, "Content-Length: "); + + if (pdata != NULL){ + pdata += 16; + tmp_precvbuffer = (char *)os_strstr(pdata, "\r\n"); + + if (tmp_precvbuffer != NULL){ + os_memcpy(length_buf, pdata, tmp_precvbuffer - pdata); + dat_sumlength = atoi(length_buf); + os_printf("A_dat:%u,tot:%u,lenght:%u\n",dat_sumlength,tmp_totallength,tmp_length); + if(dat_sumlength != tmp_totallength){ + return false; + } + } + } + } + return true; +} + +LOCAL os_timer_t *restart_10ms; +LOCAL rst_parm *rstparm; + +/****************************************************************************** + * FunctionName : restart_10ms_cb + * Description : system restart or wifi reconnected after a certain time. + * Parameters : arg -- Additional argument to pass to the function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +restart_10ms_cb(void *arg) +{ + if (rstparm != NULL && rstparm->pespconn != NULL) { + switch (rstparm->parmtype) { + case WIFI: + //if (rstparm->pespconn->state == ESPCONN_CLOSE) { + if (sta_conf->ssid[0] != 0x00) { + wifi_station_set_config(sta_conf); + wifi_station_disconnect(); + wifi_station_connect(); + user_esp_platform_check_ip(1); + } + + if (ap_conf->ssid[0] != 0x00) { + wifi_softap_set_config(ap_conf); + system_restart(); + } + + os_free(ap_conf); + ap_conf = NULL; + os_free(sta_conf); + sta_conf = NULL; + os_free(rstparm); + rstparm = NULL; + os_free(restart_10ms); + restart_10ms = NULL; + //} else { + // os_timer_arm(restart_10ms, 10, 0); + //} + + break; + + case DEEP_SLEEP: + case REBOOT: + if (rstparm->pespconn->state == ESPCONN_CLOSE) { + wifi_set_opmode(STATION_MODE); + + if (rstparm->parmtype == DEEP_SLEEP) { +#if SENSOR_DEVICE + system_deep_sleep(SENSOR_DEEP_SLEEP_TIME); +#endif + } + } else { + os_timer_arm(restart_10ms, 10, 0); + } + + break; + + default: + break; + } + } +} + +/****************************************************************************** + * FunctionName : data_send + * Description : processing the data as http format and send to the client or server + * Parameters : arg -- argument to set for client or server + * responseOK -- true or false + * psend -- The send data + * Returns : +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +data_send(void *arg, bool responseOK, char *psend) +{ + uint16 length = 0; + char *pbuf = NULL; + char httphead[256]; + struct espconn *ptrespconn = arg; + os_memset(httphead, 0, 256); + + if (responseOK) { + os_sprintf(httphead, + "HTTP/1.0 200 OK\r\nContent-Length: %d\r\nServer: lwIP/1.4.0\r\n", + psend ? os_strlen(psend) : 0); + + if (psend) { + os_sprintf(httphead + os_strlen(httphead), + "Content-type: application/json\r\nExpires: Fri, 10 Apr 2008 14:00:00 GMT\r\nPragma: no-cache\r\n\r\n"); + length = os_strlen(httphead) + os_strlen(psend); + pbuf = (char *)os_zalloc(length + 1); + os_memcpy(pbuf, httphead, os_strlen(httphead)); + os_memcpy(pbuf + os_strlen(httphead), psend, os_strlen(psend)); + } else { + os_sprintf(httphead + os_strlen(httphead), "\n"); + length = os_strlen(httphead); + } + } else { + os_sprintf(httphead, "HTTP/1.0 400 BadRequest\r\n\ +Content-Length: 0\r\nServer: lwIP/1.4.0\r\n\n"); + length = os_strlen(httphead); + } + + if (psend) { +#ifdef SERVER_SSL_ENABLE + espconn_secure_sent(ptrespconn, pbuf, length); +#else + espconn_sent(ptrespconn, pbuf, length); +#endif + } else { +#ifdef SERVER_SSL_ENABLE + espconn_secure_sent(ptrespconn, httphead, length); +#else + espconn_sent(ptrespconn, httphead, length); +#endif + } + + if (pbuf) { + os_free(pbuf); + pbuf = NULL; + } +} + +/****************************************************************************** + * FunctionName : json_send + * Description : processing the data as json format and send to the client or server + * Parameters : arg -- argument to set for client or server + * ParmType -- json format type + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +json_send(void *arg, ParmType ParmType) +{ + char *pbuf = NULL; + pbuf = (char *)os_zalloc(jsonSize); + struct espconn *ptrespconn = arg; + + switch (ParmType) { +#if LIGHT_DEVICE + + case LIGHT_STATUS: + json_ws_send((struct jsontree_value *)&PwmTree, "light", pbuf); + break; +#endif + +#if PLUG_DEVICE + + case SWITCH_STATUS: + json_ws_send((struct jsontree_value *)&StatusTree, "switch", pbuf); + break; +#endif + + case INFOMATION: + json_ws_send((struct jsontree_value *)&INFOTree, "info", pbuf); + break; + + case WIFI: + json_ws_send((struct jsontree_value *)&wifi_info_tree, "wifi", pbuf); + break; + + case CONNECT_STATUS: + json_ws_send((struct jsontree_value *)&con_status_tree, "info", pbuf); + break; + + case USER_BIN: + json_ws_send((struct jsontree_value *)&userinfo_tree, "user_info", pbuf); + break; + case SCAN: { + u8 i = 0; + u8 scancount = 0; + struct bss_info *bss = NULL; +// bss = STAILQ_FIRST(pscaninfo->pbss); + bss = bss_head; + if (bss == NULL) { + os_free(pscaninfo); + pscaninfo = NULL; + os_sprintf(pbuf, "{\n\"successful\": false,\n\"data\": null\n}"); + } else { + do { + if (pscaninfo->page_sn == pscaninfo->pagenum) { + pscaninfo->page_sn = 0; + os_sprintf(pbuf, "{\n\"successful\": false,\n\"meessage\": \"repeated page\"\n}"); + break; + } + + scancount = scannum - (pscaninfo->pagenum - 1) * 8; + + if (scancount >= 8) { + pscaninfo->data_cnt += 8; + pscaninfo->page_sn = pscaninfo->pagenum; + + if (pscaninfo->data_cnt > scannum) { + pscaninfo->data_cnt -= 8; + os_sprintf(pbuf, "{\n\"successful\": false,\n\"meessage\": \"error page\"\n}"); + break; + } + + json_ws_send((struct jsontree_value *)&scan_tree, "scan", pbuf); + } else { + pscaninfo->data_cnt += scancount; + pscaninfo->page_sn = pscaninfo->pagenum; + + if (pscaninfo->data_cnt > scannum) { + pscaninfo->data_cnt -= scancount; + os_sprintf(pbuf, "{\n\"successful\": false,\n\"meessage\": \"error page\"\n}"); + break; + } + + char *ptrscanbuf = (char *)os_zalloc(jsonSize); + char *pscanbuf = ptrscanbuf; + os_sprintf(pscanbuf, ",\n\"ScanResult\": [\n"); + pscanbuf += os_strlen(pscanbuf); + + for (i = 0; i < scancount; i ++) { + JSONTREE_OBJECT(page_tree, + JSONTREE_PAIR("page", &scaninfo_tree)); + json_ws_send((struct jsontree_value *)&page_tree, "page", pscanbuf); + os_sprintf(pscanbuf + os_strlen(pscanbuf), ",\n"); + pscanbuf += os_strlen(pscanbuf); + } + + os_sprintf(pscanbuf - 2, "]\n"); + JSONTREE_OBJECT(scantree, + JSONTREE_PAIR("TotalPage", &scan_callback), + JSONTREE_PAIR("PageNum", &scan_callback)); + JSONTREE_OBJECT(scanres_tree, + JSONTREE_PAIR("Response", &scantree)); + JSONTREE_OBJECT(scan_tree, + JSONTREE_PAIR("scan", &scanres_tree)); + json_ws_send((struct jsontree_value *)&scan_tree, "scan", pbuf); + os_memcpy(pbuf + os_strlen(pbuf) - 4, ptrscanbuf, os_strlen(ptrscanbuf)); + os_sprintf(pbuf + os_strlen(pbuf), "}\n}"); + os_free(ptrscanbuf); + } + } while (0); + } + + break; + } + + default : + break; + } + + data_send(ptrespconn, true, pbuf); + os_free(pbuf); + pbuf = NULL; +} + +/****************************************************************************** + * FunctionName : response_send + * Description : processing the send result + * Parameters : arg -- argument to set for client or server + * responseOK -- true or false + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +response_send(void *arg, bool responseOK) +{ + struct espconn *ptrespconn = arg; + + data_send(ptrespconn, responseOK, NULL); +} + +/****************************************************************************** + * FunctionName : json_scan_cb + * Description : processing the scan result + * Parameters : arg -- Additional argument to pass to the callback function + * status -- scan status + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR json_scan_cb(void *arg, STATUS status) +{ + pscaninfo->pbss = arg; + + if (scannum % 8 == 0) { + pscaninfo->totalpage = scannum / 8; + } else { + pscaninfo->totalpage = scannum / 8 + 1; + } + + JSONTREE_OBJECT(totaltree, + JSONTREE_PAIR("TotalPage", &scan_callback)); + JSONTREE_OBJECT(totalres_tree, + JSONTREE_PAIR("Response", &totaltree)); + JSONTREE_OBJECT(total_tree, + JSONTREE_PAIR("total", &totalres_tree)); + + bss_temp = bss_head; + while(bss_temp !=NULL) { + bss_head = bss_temp->next.stqe_next; + os_free(bss_temp); + bss_temp = bss_head; + } + bss_head = NULL; + bss_temp = NULL; + bss = STAILQ_FIRST(pscaninfo->pbss); + while(bss != NULL) { + if(bss_temp == NULL){ + bss_temp = (struct bss_info *)os_zalloc(sizeof(struct bss_info)); + bss_head = bss_temp; + } else { + bss_temp->next.stqe_next = (struct bss_info *)os_zalloc(sizeof(struct bss_info)); + bss_temp = bss_temp->next.stqe_next; + } + if(bss_temp == NULL) { + os_printf("malloc scan info failed\n"); + break; + } else{ + os_memcpy(bss_temp->bssid,bss->bssid,sizeof(bss->bssid)); + os_memcpy(bss_temp->ssid,bss->ssid,sizeof(bss->ssid)); + bss_temp->authmode = bss->authmode; + bss_temp->rssi = bss->rssi; + bss_temp->channel = bss->channel; + } + bss = STAILQ_NEXT(bss,next); + } + char *pbuf = NULL; + pbuf = (char *)os_zalloc(jsonSize); + json_ws_send((struct jsontree_value *)&total_tree, "total", pbuf); + data_send(pscaninfo->pespconn, true, pbuf); + os_free(pbuf); +} + +void ICACHE_FLASH_ATTR +upgrade_check_func(void *arg) +{ + struct espconn *ptrespconn = arg; + os_timer_disarm(&upgrade_check_timer); + if(system_upgrade_flag_check() == UPGRADE_FLAG_START) { + response_send(ptrespconn, false); + system_upgrade_deinit(); + system_upgrade_flag_set(UPGRADE_FLAG_IDLE); + upgrade_lock = 0; + os_printf("local upgrade failed\n"); + } else if( system_upgrade_flag_check() == UPGRADE_FLAG_FINISH ) { + os_printf("local upgrade success\n"); + response_send(ptrespconn, true); + upgrade_lock = 0; + } else { + + } + + +} +/****************************************************************************** + * FunctionName : upgrade_deinit + * Description : disconnect the connection with the host + * Parameters : bin -- server number + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +LOCAL local_upgrade_deinit(void) +{ + if (system_upgrade_flag_check() != UPGRADE_FLAG_START) { + os_printf("system upgrade deinit\n"); + system_upgrade_deinit(); + } +} + + +/****************************************************************************** + * FunctionName : upgrade_download + * Description : Processing the upgrade data from the host + * Parameters : bin -- server number + * pusrdata -- The upgrade data (or NULL when the connection has been closed!) + * length -- The length of upgrade data + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +local_upgrade_download(void * arg,char *pusrdata, unsigned short length) +{ + char *ptr = NULL; + char *ptmp2 = NULL; + char lengthbuffer[32]; + static uint32 totallength = 0; + static uint32 sumlength = 0; + static uint32 erase_length = 0; + char A_buf[2] = {0xE9 ,0x03}; char B_buf[2] = {0xEA,0x04}; + struct espconn *pespconn = arg; + if (totallength == 0 && (ptr = (char *)os_strstr(pusrdata, "\r\n\r\n")) != NULL && + (ptr = (char *)os_strstr(pusrdata, "Content-Length")) != NULL) { + ptr = (char *)os_strstr(pusrdata, "Content-Length: "); + if (ptr != NULL) { + ptr += 16; + ptmp2 = (char *)os_strstr(ptr, "\r\n"); + + if (ptmp2 != NULL) { + os_memset(lengthbuffer, 0, sizeof(lengthbuffer)); + os_memcpy(lengthbuffer, ptr, ptmp2 - ptr); + sumlength = atoi(lengthbuffer); + if (sumlength == 0) { + os_timer_disarm(&upgrade_check_timer); + os_timer_setfn(&upgrade_check_timer, (os_timer_func_t *)upgrade_check_func, pespconn); + os_timer_arm(&upgrade_check_timer, 10, 0); + return; + } + } else { + os_printf("sumlength failed\n"); + } + } else { + os_printf("Content-Length: failed\n"); + } + if (sumlength != 0) { + if (sumlength >= LIMIT_ERASE_SIZE){ + system_upgrade_erase_flash(0xFFFF); + erase_length = sumlength - LIMIT_ERASE_SIZE; + } else { + system_upgrade_erase_flash(sumlength); + erase_length = 0; + } + } + ptr = (char *)os_strstr(pusrdata, "\r\n\r\n"); + length -= ptr - pusrdata; + length -= 4; + totallength += length; + os_printf("upgrade file download start.\n"); + system_upgrade(ptr + 4, length); + + } else { + totallength += length; + if (erase_length >= LIMIT_ERASE_SIZE){ + system_upgrade_erase_flash(0xFFFF); + erase_length -= LIMIT_ERASE_SIZE; + } else { + system_upgrade_erase_flash(erase_length); + erase_length = 0; + } + system_upgrade(pusrdata, length); + } + + if (totallength == sumlength) { + os_printf("upgrade file download finished.\n"); + system_upgrade_flag_set(UPGRADE_FLAG_FINISH); + totallength = 0; + sumlength = 0; + upgrade_check_func(pespconn); + os_timer_disarm(&app_upgrade_10s); + os_timer_setfn(&app_upgrade_10s, (os_timer_func_t *)local_upgrade_deinit, NULL); + os_timer_arm(&app_upgrade_10s, 10, 0); + } +} + +/****************************************************************************** + * FunctionName : webserver_recv + * Description : Processing the received data from the server + * Parameters : arg -- Additional argument to pass to the callback function + * pusrdata -- The received data (or NULL when the connection has been closed!) + * length -- The length of received data + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +webserver_recv(void *arg, char *pusrdata, unsigned short length) +{ + URL_Frame *pURL_Frame = NULL; + char *pParseBuffer = NULL; + bool parse_flag = false; + struct espconn *ptrespconn = arg; + + if(upgrade_lock == 0){ + + os_printf("len:%u\n",length); + if(check_data(pusrdata, length) == false) + { + os_printf("goto\n"); + goto _temp_exit; + } + + parse_flag = save_data(pusrdata, length); + if (parse_flag == false) { + response_send(ptrespconn, false); + } + +// os_printf(precvbuffer); + pURL_Frame = (URL_Frame *)os_zalloc(sizeof(URL_Frame)); + parse_url(precvbuffer, pURL_Frame); + + switch (pURL_Frame->Type) { + case GET: + os_printf("We have a GET request.\n"); + + if (os_strcmp(pURL_Frame->pSelect, "client") == 0 && + os_strcmp(pURL_Frame->pCommand, "command") == 0) { + if (os_strcmp(pURL_Frame->pFilename, "info") == 0) { + json_send(ptrespconn, INFOMATION); + } + + if (os_strcmp(pURL_Frame->pFilename, "status") == 0) { + json_send(ptrespconn, CONNECT_STATUS); + } else if (os_strcmp(pURL_Frame->pFilename, "scan") == 0) { + char *strstr = NULL; + strstr = (char *)os_strstr(pusrdata, "&"); + + if (strstr == NULL) { + if (pscaninfo == NULL) { + pscaninfo = (scaninfo *)os_zalloc(sizeof(scaninfo)); + } + + pscaninfo->pespconn = ptrespconn; + pscaninfo->pagenum = 0; + pscaninfo->page_sn = 0; + pscaninfo->data_cnt = 0; + wifi_station_scan(NULL, json_scan_cb); + } else { + strstr ++; + + if (os_strncmp(strstr, "page", 4) == 0) { + if (pscaninfo != NULL) { + pscaninfo->pagenum = *(strstr + 5); + pscaninfo->pagenum -= 0x30; + + if (pscaninfo->pagenum > pscaninfo->totalpage || pscaninfo->pagenum == 0) { + response_send(ptrespconn, false); + } else { + json_send(ptrespconn, SCAN); + } + } else { + response_send(ptrespconn, false); + } + } else if(os_strncmp(strstr, "finish", 6) == 0){ + bss_temp = bss_head; + while(bss_temp != NULL) { + bss_head = bss_temp->next.stqe_next; + os_free(bss_temp); + bss_temp = bss_head; + } + bss_head = NULL; + bss_temp = NULL; + response_send(ptrespconn, true); + } else { + response_send(ptrespconn, false); + } + } + } else { + response_send(ptrespconn, false); + } + } else if (os_strcmp(pURL_Frame->pSelect, "config") == 0 && + os_strcmp(pURL_Frame->pCommand, "command") == 0) { + if (os_strcmp(pURL_Frame->pFilename, "wifi") == 0) { + ap_conf = (struct softap_config *)os_zalloc(sizeof(struct softap_config)); + sta_conf = (struct station_config *)os_zalloc(sizeof(struct station_config)); + json_send(ptrespconn, WIFI); + os_free(sta_conf); + os_free(ap_conf); + sta_conf = NULL; + ap_conf = NULL; + } + +#if PLUG_DEVICE + else if (os_strcmp(pURL_Frame->pFilename, "switch") == 0) { + json_send(ptrespconn, SWITCH_STATUS); + } + +#endif + +#if LIGHT_DEVICE + else if (os_strcmp(pURL_Frame->pFilename, "light") == 0) { + json_send(ptrespconn, LIGHT_STATUS); + } + + +#endif + + else if (os_strcmp(pURL_Frame->pFilename, "reboot") == 0) { + json_send(ptrespconn, REBOOT); + } else { + response_send(ptrespconn, false); + } + } else if (os_strcmp(pURL_Frame->pSelect, "upgrade") == 0 && + os_strcmp(pURL_Frame->pCommand, "command") == 0) { + if (os_strcmp(pURL_Frame->pFilename, "getuser") == 0) { + json_send(ptrespconn , USER_BIN); + } + } else { + response_send(ptrespconn, false); + } + + break; + + case POST: + os_printf("We have a POST request.\n"); + pParseBuffer = (char *)os_strstr(precvbuffer, "\r\n\r\n"); + + if (pParseBuffer == NULL) { + break; + } + + pParseBuffer += 4; + + if (os_strcmp(pURL_Frame->pSelect, "config") == 0 && + os_strcmp(pURL_Frame->pCommand, "command") == 0) { +#if SENSOR_DEVICE + + if (os_strcmp(pURL_Frame->pFilename, "sleep") == 0) { +#else + + if (os_strcmp(pURL_Frame->pFilename, "reboot") == 0) { +#endif + + if (pParseBuffer != NULL) { + if (restart_10ms != NULL) { + os_timer_disarm(restart_10ms); + } + + if (rstparm == NULL) { + rstparm = (rst_parm *)os_zalloc(sizeof(rst_parm)); + } + + rstparm->pespconn = ptrespconn; +#if SENSOR_DEVICE + rstparm->parmtype = DEEP_SLEEP; +#else + rstparm->parmtype = REBOOT; +#endif + + if (restart_10ms == NULL) { + restart_10ms = (os_timer_t *)os_malloc(sizeof(os_timer_t)); + } + + os_timer_setfn(restart_10ms, (os_timer_func_t *)restart_10ms_cb, NULL); + os_timer_arm(restart_10ms, 10, 0); // delay 10ms, then do + + response_send(ptrespconn, true); + } else { + response_send(ptrespconn, false); + } + } else if (os_strcmp(pURL_Frame->pFilename, "wifi") == 0) { + if (pParseBuffer != NULL) { + struct jsontree_context js; + user_esp_platform_set_connect_status(DEVICE_CONNECTING); + + if (restart_10ms != NULL) { + os_timer_disarm(restart_10ms); + } + + if (ap_conf == NULL) { + ap_conf = (struct softap_config *)os_zalloc(sizeof(struct softap_config)); + } + + if (sta_conf == NULL) { + sta_conf = (struct station_config *)os_zalloc(sizeof(struct station_config)); + } + + jsontree_setup(&js, (struct jsontree_value *)&wifi_req_tree, json_putchar); + json_parse(&js, pParseBuffer); + + if (rstparm == NULL) { + rstparm = (rst_parm *)os_zalloc(sizeof(rst_parm)); + } + + rstparm->pespconn = ptrespconn; + rstparm->parmtype = WIFI; + + if (sta_conf->ssid[0] != 0x00 || ap_conf->ssid[0] != 0x00) { + ap_conf->ssid_hidden = 0; + ap_conf->max_connection = 4; + + if (restart_10ms == NULL) { + restart_10ms = (os_timer_t *)os_malloc(sizeof(os_timer_t)); + } + + os_timer_disarm(restart_10ms); + os_timer_setfn(restart_10ms, (os_timer_func_t *)restart_10ms_cb, NULL); + os_timer_arm(restart_10ms, 10, 0); // delay 10ms, then do + } else { + os_free(ap_conf); + os_free(sta_conf); + os_free(rstparm); + sta_conf = NULL; + ap_conf = NULL; + rstparm =NULL; + } + + response_send(ptrespconn, true); + } else { + response_send(ptrespconn, false); + } + } + +#if PLUG_DEVICE + else if (os_strcmp(pURL_Frame->pFilename, "switch") == 0) { + if (pParseBuffer != NULL) { + struct jsontree_context js; + jsontree_setup(&js, (struct jsontree_value *)&StatusTree, json_putchar); + json_parse(&js, pParseBuffer); + response_send(ptrespconn, true); + } else { + response_send(ptrespconn, false); + } + } + +#endif + +#if LIGHT_DEVICE + else if (os_strcmp(pURL_Frame->pFilename, "light") == 0) { + if (pParseBuffer != NULL) { + struct jsontree_context js; + + jsontree_setup(&js, (struct jsontree_value *)&PwmTree, json_putchar); + json_parse(&js, pParseBuffer); + + os_printf("rsp1:%u\n",PostCmdNeeRsp); + if(PostCmdNeeRsp == 0) + PostCmdNeeRsp = 1; + else + response_send(ptrespconn, true); + } else { + response_send(ptrespconn, false); + } + } + else if (os_strcmp(pURL_Frame->pFilename, "reset") == 0) { + response_send(ptrespconn, true); + extern struct esp_platform_saved_param esp_param; + esp_param.activeflag = 0; + system_param_save_with_protect(ESP_PARAM_START_SEC, &esp_param, sizeof(esp_param)); + + system_restore(); + system_restart(); + } + +#endif + else { + response_send(ptrespconn, false); + } + } + else if(os_strcmp(pURL_Frame->pSelect, "upgrade") == 0 && + os_strcmp(pURL_Frame->pCommand, "command") == 0){ + if (os_strcmp(pURL_Frame->pFilename, "start") == 0){ + response_send(ptrespconn, true); + os_printf("local upgrade start\n"); + upgrade_lock = 1; + system_upgrade_init(); + system_upgrade_flag_set(UPGRADE_FLAG_START); + os_timer_disarm(&upgrade_check_timer); + os_timer_setfn(&upgrade_check_timer, (os_timer_func_t *)upgrade_check_func, NULL); + os_timer_arm(&upgrade_check_timer, 120000, 0); + } else if (os_strcmp(pURL_Frame->pFilename, "reset") == 0) { + + response_send(ptrespconn, true); + os_printf("local upgrade restart\n"); + system_upgrade_reboot(); + } else { + response_send(ptrespconn, false); + } + }else { + response_send(ptrespconn, false); + } + break; + } + + if (precvbuffer != NULL){ + os_free(precvbuffer); + precvbuffer = NULL; + } + os_free(pURL_Frame); + pURL_Frame = NULL; + _temp_exit: + ; + } + else if(upgrade_lock == 1){ + local_upgrade_download(ptrespconn,pusrdata, length); + if (precvbuffer != NULL){ + os_free(precvbuffer); + precvbuffer = NULL; + } + os_free(pURL_Frame); + pURL_Frame = NULL; + } +} + +/****************************************************************************** + * FunctionName : webserver_recon + * Description : the connection has been err, reconnection + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL ICACHE_FLASH_ATTR +void webserver_recon(void *arg, sint8 err) +{ + struct espconn *pesp_conn = arg; + + os_printf("webserver's %d.%d.%d.%d:%d err %d reconnect\n", pesp_conn->proto.tcp->remote_ip[0], + pesp_conn->proto.tcp->remote_ip[1],pesp_conn->proto.tcp->remote_ip[2], + pesp_conn->proto.tcp->remote_ip[3],pesp_conn->proto.tcp->remote_port, err); +} + +/****************************************************************************** + * FunctionName : webserver_recon + * Description : the connection has been err, reconnection + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL ICACHE_FLASH_ATTR +void webserver_discon(void *arg) +{ + struct espconn *pesp_conn = arg; + + os_printf("webserver's %d.%d.%d.%d:%d disconnect\n", pesp_conn->proto.tcp->remote_ip[0], + pesp_conn->proto.tcp->remote_ip[1],pesp_conn->proto.tcp->remote_ip[2], + pesp_conn->proto.tcp->remote_ip[3],pesp_conn->proto.tcp->remote_port); +} + +/****************************************************************************** + * FunctionName : user_accept_listen + * Description : server listened a connection successfully + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +webserver_listen(void *arg) +{ + struct espconn *pesp_conn = arg; + + espconn_regist_recvcb(pesp_conn, webserver_recv); + espconn_regist_reconcb(pesp_conn, webserver_recon); + espconn_regist_disconcb(pesp_conn, webserver_discon); +} + +/****************************************************************************** + * FunctionName : user_webserver_init + * Description : parameter initialize as a server + * Parameters : port -- server port + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +user_webserver_init(uint32 port) +{ + LOCAL struct espconn esp_conn; + LOCAL esp_tcp esptcp; + + esp_conn.type = ESPCONN_TCP; + esp_conn.state = ESPCONN_NONE; + esp_conn.proto.tcp = &esptcp; + esp_conn.proto.tcp->local_port = port; + espconn_regist_connectcb(&esp_conn, webserver_listen); + +#ifdef SERVER_SSL_ENABLE + espconn_secure_accept(&esp_conn); +#else + espconn_accept(&esp_conn); +#endif +} diff --git a/esp_iot_sdk_v1.3.0/examples/at/!!!readme!!!.txt b/esp_iot_sdk_v1.3.0/examples/at/!!!readme!!!.txt new file mode 100644 index 0000000..8978e39 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/at/!!!readme!!!.txt @@ -0,0 +1,42 @@ +Notice: AT added some functions so it's larger than before, if you want to compile it, please compile it as 1024KB or larger flash in compilation STEP 5. + +1¡¢compile options + +(1) COMPILE + Possible value: gcc + Default value: + If not set, use xt-xcc by default. + +(2) BOOT + Possible value: none/old/new + none: no need boot + old: use boot_v1.1 + new: use boot_v1.2+ + Default value: none + +(3) APP + Possible value: 0/1/2 + 0: original mode, generate eagle.app.v6.flash.bin and eagle.app.v6.irom0text.bin + 1: generate user1 + 2: generate user2 + Default value: 0 + +(3) SPI_SPEED + Possible value: 20/26.7/40/80 + Default value: 40 + +(4) SPI_MODE + Possible value: QIO/QOUT/DIO/DOUT + Default value: QIO + +(4) SPI_SIZE + Possible value: 0/2/3/4/5/6 + Default value: 0 + +For example: + make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=0 + +2¡¢You can also use gen_misc to make and generate specific bin you needed. + Linux: ./gen_misc.sh + Windows: gen_misc.bat + Follow the tips and steps. \ No newline at end of file diff --git a/esp_iot_sdk_v1.3.0/examples/at/Makefile b/esp_iot_sdk_v1.3.0/examples/at/Makefile new file mode 100644 index 0000000..9071b7c --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/at/Makefile @@ -0,0 +1,145 @@ +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of object file images to be generated () +# GEN_BINS - list of binaries to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +TARGET = eagle +#FLAVOR = release +FLAVOR = debug + +#EXTRA_CCFLAGS += -u + +ifndef PDIR # { +GEN_IMAGES= eagle.app.v6.out +GEN_BINS= eagle.app.v6.bin +SPECIAL_MKTARGETS=$(APP_MKTARGETS) +SUBDIRS= \ + user +ifdef AT_OPEN_SRC +SUBDIRS += \ + at +endif +endif # } PDIR + +APPDIR = . +LDDIR = ../ld + +CCFLAGS += -Os + +TARGET_LDFLAGS = \ + -nostdlib \ + -Wl,-EL \ + --longcalls \ + --text-section-literals + +ifeq ($(FLAVOR),debug) + TARGET_LDFLAGS += -g -O2 +endif + +ifeq ($(FLAVOR),release) + TARGET_LDFLAGS += -g -O0 +endif + +COMPONENTS_eagle.app.v6 = \ + user/libuser.a + +ifdef AT_OPEN_SRC +COMPONENTS_eagle.app.v6 += \ + at/libat.a +endif + +LINKFLAGS_eagle.app.v6 = \ + -L../lib \ + -nostdlib \ + -T$(LD_FILE) \ + -Wl,--no-check-sections \ + -u call_user_start \ + -Wl,-static \ + -Wl,--start-group \ + -lc \ + -lgcc \ + -lhal \ + -lphy \ + -lpp \ + -lnet80211 \ + -llwip \ + -lwpa \ + -lmain \ + -ljson \ + -lupgrade \ + -lsmartconfig \ + $(DEP_LIBS_eagle.app.v6) + +ifndef AT_OPEN_SRC +LINKFLAGS_eagle.app.v6 += \ + -lat +endif + +LINKFLAGS_eagle.app.v6 += \ + -Wl,--end-group +DEPENDS_eagle.app.v6 = \ + $(LD_FILE) \ + $(LDDIR)/eagle.rom.addr.v6.ld + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# + +#UNIVERSAL_TARGET_DEFINES = \ + +# Other potential configuration flags include: +# -DTXRX_TXBUF_DEBUG +# -DTXRX_RXBUF_DEBUG +# -DWLAN_CONFIG_CCX +CONFIGURATION_DEFINES = -DICACHE_FLASH +ifdef AT_OPEN_SRC +CONFIGURATION_DEFINES += \ + -DAT_OPEN_SRC +endif + +ifeq ($(APP),0) +else +CONFIGURATION_DEFINES += \ + -DAT_UPGRADE_SUPPORT +endif + +DEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + +DDEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + +.PHONY: FORCE +FORCE: + diff --git a/esp_iot_sdk_v1.3.0/examples/at/gen_misc.bat b/esp_iot_sdk_v1.3.0/examples/at/gen_misc.bat new file mode 100644 index 0000000..8856e66 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/at/gen_misc.bat @@ -0,0 +1,147 @@ +@echo off + +echo gen_misc.bat version 20150511 +echo . + +echo Please follow below steps(1-5) to generate specific bin(s): +echo STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none) +set input=default +set /p input=enter(0/1/2, default 2): + +if %input% equ 0 ( + set boot=old +) else ( +if %input% equ 1 ( + set boot=new +) else ( + set boot=none +) +) + +echo boot mode: %boot% +echo. + +echo STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin) +set input=default +set /p input=enter (0/1/2, default 0): + +if %input% equ 1 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=1 + echo generate bin: user1.bin + ) +) else ( +if %input% equ 2 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=2 + echo generate bin: user2.bin + ) +) else ( + if %boot% neq none ( + set boot=none + echo ignore boot + ) + set app=0 + echo generate bin: eagle.flash.bin+eagle.irom0text.bin +)) + +echo. + +echo STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz) +set input=default +set /p input=enter (0/1/2/3, default 2): + +if %input% equ 0 ( + set spi_speed=20 +) else ( +if %input% equ 1 ( + set spi_speed=26.7 +) else ( +if %input% equ 3 ( + set spi_speed=80 +) else ( + set spi_speed=40 +))) + +echo spi speed: %spi_speed% MHz +echo. + +echo STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT) +set input=default +set /p input=enter (0/1/2/3, default 0): + +if %input% equ 1 ( + set spi_mode=QOUT +) else ( +if %input% equ 2 ( + set spi_mode=DIO +) else ( +if %input% equ 3 ( + set spi_mode=DOUT +) else ( + set spi_mode=QIO +))) + +echo spi mode: %spi_mode% +echo. + +echo STEP 5: choose flash 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) +set input=default +set /p input=enter (0/1/2/3/4/5/6, default 0): + +if %input% equ 2 ( + set spi_size_map=2 + echo spi size: 1024KB + echo spi ota map: 512KB + 512KB +) else ( + if %input% equ 3 ( + set spi_size_map=3 + echo spi size: 2048KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 4 ( + set spi_size_map=4 + echo spi size: 4096KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 5 ( + set spi_size_map=5 + echo spi size: 2048KB + echo spi ota map: 1024KB + 1024KB + ) else ( + if %input% equ 6 ( + set spi_size_map=6 + echo spi size: 4096KB + echo spi ota map: 1024KB + 1024KB + ) else ( + set spi_size_map=0 + echo spi size: 512KB + echo spi ota map: 256KB + 256KB + ) + ) + ) + ) +) + +touch user/user_main.c + +echo. +echo start... +echo. + +make BOOT=%boot% APP=%app% SPI_SPEED=%spi_speed% SPI_MODE=%spi_mode% SPI_SIZE=%spi_size_map% + diff --git a/esp_iot_sdk_v1.3.0/examples/at/gen_misc.sh b/esp_iot_sdk_v1.3.0/examples/at/gen_misc.sh new file mode 100644 index 0000000..1612cd9 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/at/gen_misc.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +echo "gen_misc.sh version 20150511" +echo "" + +echo "Please follow below steps(1-5) to generate specific bin(s):" +echo "STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none)" +echo "enter(0/1/2, default 2):" +read input + +if [ -z "$input" ]; then + boot=none +elif [ $input == 0 ]; then + boot=old +elif [ $input == 1 ]; then + boot=new +else + boot=none +fi + +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 "" + +touch user/user_main.c + +echo "" +echo "start..." +echo "" + +make COMPILE=gcc BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map diff --git a/esp_iot_sdk_v1.3.0/examples/at/include/user_config.h b/esp_iot_sdk_v1.3.0/examples/at/include/user_config.h new file mode 100644 index 0000000..d78f7d9 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/at/include/user_config.h @@ -0,0 +1,12 @@ +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +#define AT_CUSTOM_UPGRADE + +#ifdef AT_CUSTOM_UPGRADE + #ifndef AT_UPGRADE_SUPPORT + #error "upgrade is not supported when eagle.flash.bin+eagle.irom0text.bin!!!" + #endif +#endif + +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/at/user/Makefile b/esp_iot_sdk_v1.3.0/examples/at/user/Makefile new file mode 100644 index 0000000..639fe9b --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/at/user/Makefile @@ -0,0 +1,45 @@ + +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of images to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +ifndef PDIR +GEN_LIBS = libuser.a +endif + + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# +#DEFINES += + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I ./ +INCLUDES += -I ../../include/ets +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + diff --git a/esp_iot_sdk_v1.3.0/examples/at/user/at_upgrade.c b/esp_iot_sdk_v1.3.0/examples/at/user/at_upgrade.c new file mode 100644 index 0000000..299e0f3 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/at/user/at_upgrade.c @@ -0,0 +1,290 @@ +/****************************************************************************** + * Copyright 2015-2018 Espressif Systems (Wuxi) + * + * FileName: user_main.c + * + * Description: entry file of user application + * + * Modification history: + * 2015/3/06, v1.0 create this file. +*******************************************************************************/ +#include "c_types.h" +#include "user_interface.h" +#include "espconn.h" +#include "mem.h" +#include "osapi.h" +#include "upgrade.h" + +#ifdef AT_UPGRADE_SUPPORT +#ifdef AT_CUSTOM_UPGRADE + +#define UPGRADE_FRAME "{\"path\": \"/v1/messages/\", \"method\": \"POST\", \"meta\": {\"Authorization\": \"token %s\"},\ +\"get\":{\"action\":\"%s\"},\"body\":{\"pre_rom_version\":\"%s\",\"rom_version\":\"%s\"}}\n" + +#define pheadbuffer "Connection: keep-alive\r\n\ +Cache-Control: no-cache\r\n\ +User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 \r\n\ +Accept: */*\r\n\ +Accept-Encoding: gzip,deflate\r\n\ +Accept-Language: zh-CN,eb-US;q=0.8\r\n\r\n" + +/**/ + + +struct espconn *pespconn = NULL; +struct upgrade_server_info *upServer = NULL; + +static os_timer_t at_delay_check; +static struct espconn *pTcpServer = NULL; +static ip_addr_t host_ip; +/****************************************************************************** + * FunctionName : user_esp_platform_upgrade_cb + * Description : Processing the downloaded data from the server + * Parameters : pespconn -- the espconn used to connetion with the host + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +at_upDate_rsp(void *arg) +{ + struct upgrade_server_info *server = arg; + + + if(server->upgrade_flag == true) + { + os_printf("device_upgrade_success\r\n"); + at_response_ok(); + system_upgrade_reboot(); + } + else + { + os_printf("device_upgrade_failed\r\n"); + at_response_error(); + } + + os_free(server->url); + server->url = NULL; + os_free(server); + server = NULL; +} +/** + * @brief Tcp client disconnect success callback function. + * @param arg: contain the ip link information + * @retval None + */ +static void ICACHE_FLASH_ATTR +at_upDate_discon_cb(void *arg) +{ + struct espconn *pespconn = (struct espconn *)arg; + uint8_t idTemp = 0; + + if(pespconn->proto.tcp != NULL) + { + os_free(pespconn->proto.tcp); + } + if(pespconn != NULL) + { + os_free(pespconn); + } + + os_printf("disconnect\r\n"); + + if(system_upgrade_start(upServer) == false) + { + at_response_error(); + } + else + { + at_port_print("+CIPUPDATE:4\r\n"); + } +} + +/** + * @brief Udp server receive data callback function. + * @param arg: contain the ip link information + * @retval None + */ +LOCAL void ICACHE_FLASH_ATTR +at_upDate_recv(void *arg, char *pusrdata, unsigned short len) +{ + struct espconn *pespconn = (struct espconn *)arg; + char temp[32] = {0}; + uint8_t user_bin[12] = {0}; + uint8_t i = 0; + + os_timer_disarm(&at_delay_check); + at_port_print("+CIPUPDATE:3\r\n"); + + upServer = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info)); + + upServer->upgrade_version[5] = '\0'; + + upServer->pespconn = pespconn; + + os_memcpy(upServer->ip, pespconn->proto.tcp->remote_ip, 4); + + upServer->port = pespconn->proto.tcp->remote_port; + + upServer->check_cb = at_upDate_rsp; + upServer->check_times = 60000; + + if(upServer->url == NULL) + { + upServer->url = (uint8 *) os_zalloc(1024); + } + + if(system_upgrade_userbin_check() == UPGRADE_FW_BIN1) + { + os_memcpy(user_bin, "user2.bin", 10); + } + else if(system_upgrade_userbin_check() == UPGRADE_FW_BIN2) + { + os_memcpy(user_bin, "user1.bin", 10); + } + + os_sprintf(upServer->url, + "GET /%s HTTP/1.1\r\nHost: "IPSTR"\r\n"pheadbuffer"", + user_bin, IP2STR(upServer->ip)); +} + +LOCAL void ICACHE_FLASH_ATTR +at_upDate_wait(void *arg) +{ + struct espconn *pespconn = arg; + os_timer_disarm(&at_delay_check); + if(pespconn != NULL) + { + espconn_disconnect(pespconn); + } + else + { + at_response_error(); + } +} + +/****************************************************************************** + * FunctionName : user_esp_platform_sent_cb + * Description : Data has been sent successfully and acknowledged by the remote host. + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +at_upDate_sent_cb(void *arg) +{ + struct espconn *pespconn = arg; + os_timer_disarm(&at_delay_check); + os_timer_setfn(&at_delay_check, (os_timer_func_t *)at_upDate_wait, pespconn); + os_timer_arm(&at_delay_check, 5000, 0); + os_printf("at_upDate_sent_cb\r\n"); +} + +/** + * @brief Tcp client connect success callback function. + * @param arg: contain the ip link information + * @retval None + */ +static void ICACHE_FLASH_ATTR +at_upDate_connect_cb(void *arg) +{ + struct espconn *pespconn = (struct espconn *)arg; + uint8_t user_bin[9] = {0}; + char *temp = NULL; + + at_port_print("+CIPUPDATE:2\r\n"); + + + espconn_regist_disconcb(pespconn, at_upDate_discon_cb); + espconn_regist_recvcb(pespconn, at_upDate_recv);//////// + espconn_regist_sentcb(pespconn, at_upDate_sent_cb); + + temp = (uint8 *) os_zalloc(512); + + os_sprintf(temp,"GET /v1/device/rom/?is_format_simple=true HTTP/1.0\r\nHost: "IPSTR"\r\n"pheadbuffer"", + IP2STR(pespconn->proto.tcp->remote_ip)); + + espconn_sent(pespconn, temp, os_strlen(temp)); + os_free(temp); +} + +/** + * @brief Tcp client connect repeat callback function. + * @param arg: contain the ip link information + * @retval None + */ +static void ICACHE_FLASH_ATTR +at_upDate_recon_cb(void *arg, sint8 errType) +{ + struct espconn *pespconn = (struct espconn *)arg; + + at_response_error(); + if(pespconn->proto.tcp != NULL) + { + os_free(pespconn->proto.tcp); + } + os_free(pespconn); + os_printf("disconnect\r\n"); + + if(upServer != NULL) + { + os_free(upServer); + upServer = NULL; + } + at_response_error(); + +} + +/****************************************************************************** + * FunctionName : upServer_dns_found + * Description : dns found callback + * Parameters : name -- pointer to the name that was looked up. + * ipaddr -- pointer to an ip_addr_t containing the IP address of + * the hostname, or NULL if the name could not be found (or on any + * other error). + * callback_arg -- a user-specified callback argument passed to + * dns_gethostbyname + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +upServer_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) +{ + struct espconn *pespconn = (struct espconn *) arg; +// char temp[32]; + + if(ipaddr == NULL) + { + at_response_error(); + return; + } + at_port_print("+CIPUPDATE:1\r\n"); + + + if(host_ip.addr == 0 && ipaddr->addr != 0) + { + if(pespconn->type == ESPCONN_TCP) + { + os_memcpy(pespconn->proto.tcp->remote_ip, &ipaddr->addr, 4); + espconn_regist_connectcb(pespconn, at_upDate_connect_cb); + espconn_regist_reconcb(pespconn, at_upDate_recon_cb); + espconn_connect(pespconn); + } + } +} + +void ICACHE_FLASH_ATTR +at_exeCmdCiupdate(uint8_t id) +{ + pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn)); + pespconn->type = ESPCONN_TCP; + pespconn->state = ESPCONN_NONE; + pespconn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp)); + pespconn->proto.tcp->local_port = espconn_port(); + pespconn->proto.tcp->remote_port = 80; + + host_ip.addr = ipaddr_addr("192.168.10.9"); + at_port_print("+CIPUPDATE:1\r\n"); + os_memcpy(pespconn->proto.tcp->remote_ip, &host_ip.addr, 4); + espconn_regist_connectcb(pespconn, at_upDate_connect_cb); + espconn_regist_reconcb(pespconn, at_upDate_recon_cb); + espconn_connect(pespconn); +} +#endif +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/at/user/user_main.c b/esp_iot_sdk_v1.3.0/examples/at/user/user_main.c new file mode 100644 index 0000000..af42ab1 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/at/user/user_main.c @@ -0,0 +1,119 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_main.c + * + * Description: entry file of user application + * + * Modification history: + * 2015/1/23, v1.0 create this file. +*******************************************************************************/ + +#include "osapi.h" +#include "at_custom.h" +#include "user_interface.h" + +// test :AT+TEST=1,"abc"<,3> +void ICACHE_FLASH_ATTR +at_setupCmdTest(uint8_t id, char *pPara) +{ + int result = 0, err = 0, flag = 0; + uint8 buffer[32] = {0}; + pPara++; // skip '=' + + //get the first parameter + // digit + flag = at_get_next_int_dec(&pPara, &result, &err); + + // flag must be ture because there are more parameter + if (flag == FALSE) { + at_response_error(); + return; + } + + if (*pPara++ != ',') { // skip ',' + at_response_error(); + return; + } + + os_sprintf(buffer, "the first parameter:%d\r\n", result); + at_port_print(buffer); + + //get the second parameter + // string + at_data_str_copy(buffer, &pPara, 10); + at_port_print("the second parameter:"); + at_port_print(buffer); + at_port_print("\r\n"); + + if (*pPara == ',') { + pPara++; // skip ',' + result = 0; + //there is the third parameter + // digit + flag = at_get_next_int_dec(&pPara, &result, &err); + // we donot care of flag + os_sprintf(buffer, "the third parameter:%d\r\n", result); + at_port_print(buffer); + } + + if (*pPara != '\r') { + at_response_error(); + return; + } + + at_response_ok(); +} + +void ICACHE_FLASH_ATTR +at_testCmdTest(uint8_t id) +{ + uint8 buffer[32] = {0}; + + os_sprintf(buffer, "%s\r\n", "at_testCmdTest"); + at_port_print(buffer); + at_response_ok(); +} + +void ICACHE_FLASH_ATTR +at_queryCmdTest(uint8_t id) +{ + uint8 buffer[32] = {0}; + + os_sprintf(buffer, "%s\r\n", "at_queryCmdTest"); + at_port_print(buffer); + at_response_ok(); +} + +void ICACHE_FLASH_ATTR +at_exeCmdTest(uint8_t id) +{ + uint8 buffer[32] = {0}; + + os_sprintf(buffer, "%s\r\n", "at_exeCmdTest"); + at_port_print(buffer); + at_response_ok(); +} + +extern void at_exeCmdCiupdate(uint8_t id); +at_funcationType at_custom_cmd[] = { + {"+TEST", 5, at_testCmdTest, at_queryCmdTest, at_setupCmdTest, at_exeCmdTest}, +#ifdef AT_UPGRADE_SUPPORT + {"+CIUPDATE", 9, NULL, NULL, NULL, at_exeCmdCiupdate} +#endif +}; + +void user_rf_pre_init(void) +{ +} + +void user_init(void) +{ + char buf[64] = {0}; + at_customLinkMax = 5; + at_init(); + os_sprintf(buf,"compile time:%s %s",__DATE__,__TIME__); + at_set_custom_info(buf); + at_port_print("\r\nready\r\n"); + at_cmd_array_regist(&at_custom_cmd[0], sizeof(at_custom_cmd)/sizeof(at_custom_cmd[0])); +} diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/Makefile b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/Makefile new file mode 100644 index 0000000..ffdb4d0 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/Makefile @@ -0,0 +1,44 @@ + +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of images to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +ifndef PDIR +GEN_LIBS = libdriver.a +endif + + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# +#DEFINES += + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I ./ +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/gpio16.c b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/gpio16.c new file mode 100644 index 0000000..96cd059 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/gpio16.c @@ -0,0 +1,42 @@ +#include "ets_sys.h" +#include "osapi.h" +#include "driver/gpio16.h" + +void ICACHE_FLASH_ATTR +gpio16_output_conf(void) +{ + WRITE_PERI_REG(PAD_XPD_DCDC_CONF, + (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC to output rtc_gpio0 + + WRITE_PERI_REG(RTC_GPIO_CONF, + (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable + + WRITE_PERI_REG(RTC_GPIO_ENABLE, + (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); //out enable +} + +void ICACHE_FLASH_ATTR +gpio16_output_set(uint8 value) +{ + WRITE_PERI_REG(RTC_GPIO_OUT, + (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1)); +} + +void ICACHE_FLASH_ATTR +gpio16_input_conf(void) +{ + WRITE_PERI_REG(PAD_XPD_DCDC_CONF, + (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC and rtc_gpio0 connection + + WRITE_PERI_REG(RTC_GPIO_CONF, + (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable + + WRITE_PERI_REG(RTC_GPIO_ENABLE, + READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); //out disable +} + +uint8 ICACHE_FLASH_ATTR +gpio16_input_get(void) +{ + return (uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1); +} diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/hw_timer.c b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/hw_timer.c new file mode 100644 index 0000000..eeb5c89 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/hw_timer.c @@ -0,0 +1,141 @@ +/****************************************************************************** +* Copyright 2013-2014 Espressif Systems (Wuxi) +* +* FileName: hw_timer.c +* +* Description: hw_timer driver +* +* Modification history: +* 2014/5/1, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "os_type.h" +#include "osapi.h" + +#define US_TO_RTC_TIMER_TICKS(t) \ + ((t) ? \ + (((t) > 0x35A) ? \ + (((t)>>2) * ((APB_CLK_FREQ>>4)/250000) + ((t)&0x3) * ((APB_CLK_FREQ>>4)/1000000)) : \ + (((t) *(APB_CLK_FREQ>>4)) / 1000000)) : \ + 0) + +#define FRC1_ENABLE_TIMER BIT7 +#define FRC1_AUTO_LOAD BIT6 + +//TIMER PREDIVED MODE +typedef enum { + DIVDED_BY_1 = 0, //timer clock + DIVDED_BY_16 = 4, //divided by 16 + DIVDED_BY_256 = 8, //divided by 256 +} TIMER_PREDIVED_MODE; + +typedef enum { //timer interrupt mode + TM_LEVEL_INT = 1, // level interrupt + TM_EDGE_INT = 0, //edge interrupt +} TIMER_INT_MODE; + +typedef enum { + FRC1_SOURCE = 0, + NMI_SOURCE = 1, +} FRC1_TIMER_SOURCE_TYPE; + +/****************************************************************************** +* FunctionName : hw_timer_arm +* Description : set a trigger timer delay for this timer. +* Parameters : uint32 val : +in autoload mode + 50 ~ 0x7fffff; for FRC1 source. + 100 ~ 0x7fffff; for NMI source. +in non autoload mode: + 10 ~ 0x7fffff; +* Returns : NONE +*******************************************************************************/ +void hw_timer_arm(u32 val) +{ + RTC_REG_WRITE(FRC1_LOAD_ADDRESS, US_TO_RTC_TIMER_TICKS(val)); +} + +static void (* user_hw_timer_cb)(void) = NULL; +/****************************************************************************** +* FunctionName : hw_timer_set_func +* Description : set the func, when trigger timer is up. +* Parameters : void (* user_hw_timer_cb_set)(void): + timer callback function, +* Returns : NONE +*******************************************************************************/ +void hw_timer_set_func(void (* user_hw_timer_cb_set)(void)) +{ + user_hw_timer_cb = user_hw_timer_cb_set; +} + +static void hw_timer_isr_cb(void) +{ + if (user_hw_timer_cb != NULL) { + (*(user_hw_timer_cb))(); + } +} + +/****************************************************************************** +* FunctionName : hw_timer_init +* Description : initilize the hardware isr timer +* Parameters : +FRC1_TIMER_SOURCE_TYPE source_type: + FRC1_SOURCE, timer use frc1 isr as isr source. + NMI_SOURCE, timer use nmi isr as isr source. +u8 req: + 0, not autoload, + 1, autoload mode, +* Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR hw_timer_init(FRC1_TIMER_SOURCE_TYPE source_type, u8 req) +{ + if (req == 1) { + RTC_REG_WRITE(FRC1_CTRL_ADDRESS, + FRC1_AUTO_LOAD | DIVDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT); + } else { + RTC_REG_WRITE(FRC1_CTRL_ADDRESS, + DIVDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT); + } + + if (source_type == NMI_SOURCE) { + ETS_FRC_TIMER1_NMI_INTR_ATTACH(hw_timer_isr_cb); + } else { + ETS_FRC_TIMER1_INTR_ATTACH(hw_timer_isr_cb, NULL); + } + + TM1_EDGE_INT_ENABLE(); + ETS_FRC1_INTR_ENABLE(); +} + +//-------------------------------Test Code Below-------------------------------------- +#if 0 +void hw_test_timer_cb(void) +{ + static uint16 j = 0; + j++; + + if ((WDEV_NOW() - tick_now2) >= 1000000) { + static u32 idx = 1; + tick_now2 = WDEV_NOW(); + os_printf("b%u:%d\n", idx++, j); + j = 0; + } + + //hw_timer_arm(50); +} + +void ICACHE_FLASH_ATTR user_init(void) +{ + hw_timer_init(FRC1_SOURCE, 1); + hw_timer_set_func(hw_test_timer_cb); + hw_timer_arm(100); +} +#endif +/* +NOTE: +1 if use nmi source, for autoload timer , the timer setting val can't be less than 100. +2 if use nmi source, this timer has highest priority, can interrupt other isr. +3 if use frc1 source, this timer can't interrupt other isr. + +*/ + diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/i2c_master.c b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/i2c_master.c new file mode 100644 index 0000000..b12e3e5 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/i2c_master.c @@ -0,0 +1,316 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: i2c_master.c + * + * Description: i2c master API + * + * Modification history: + * 2014/3/12, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "osapi.h" +#include "gpio.h" + +#include "driver/i2c_master.h" + +LOCAL uint8 m_nLastSDA; +LOCAL uint8 m_nLastSCL; + +/****************************************************************************** + * FunctionName : i2c_master_setDC + * Description : Internal used function - + * set i2c SDA and SCL bit value for half clk cycle + * Parameters : uint8 SDA + * uint8 SCL + * Returns : NONE +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +i2c_master_setDC(uint8 SDA, uint8 SCL) +{ + SDA &= 0x01; + SCL &= 0x01; + m_nLastSDA = SDA; + m_nLastSCL = SCL; + + if ((0 == SDA) && (0 == SCL)) { + I2C_MASTER_SDA_LOW_SCL_LOW(); + } else if ((0 == SDA) && (1 == SCL)) { + I2C_MASTER_SDA_LOW_SCL_HIGH(); + } else if ((1 == SDA) && (0 == SCL)) { + I2C_MASTER_SDA_HIGH_SCL_LOW(); + } else { + I2C_MASTER_SDA_HIGH_SCL_HIGH(); + } +} + +/****************************************************************************** + * FunctionName : i2c_master_getDC + * Description : Internal used function - + * get i2c SDA bit value + * Parameters : NONE + * Returns : uint8 - SDA bit value +*******************************************************************************/ +LOCAL uint8 ICACHE_FLASH_ATTR +i2c_master_getDC(void) +{ + uint8 sda_out; + sda_out = GPIO_INPUT_GET(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)); + return sda_out; +} + +/****************************************************************************** + * FunctionName : i2c_master_init + * Description : initilize I2C bus to enable i2c operations + * Parameters : NONE + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_init(void) +{ + uint8 i; + + i2c_master_setDC(1, 0); + i2c_master_wait(5); + + // when SCL = 0, toggle SDA to clear up + i2c_master_setDC(0, 0) ; + i2c_master_wait(5); + i2c_master_setDC(1, 0) ; + i2c_master_wait(5); + + // set data_cnt to max value + for (i = 0; i < 28; i++) { + i2c_master_setDC(1, 0); + i2c_master_wait(5); // sda 1, scl 0 + i2c_master_setDC(1, 1); + i2c_master_wait(5); // sda 1, scl 1 + } + + // reset all + i2c_master_stop(); + return; +} + +/****************************************************************************** + * FunctionName : i2c_master_gpio_init + * Description : config SDA and SCL gpio to open-drain output mode, + * mux and gpio num defined in i2c_master.h + * Parameters : NONE + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_gpio_init(void) +{ + ETS_GPIO_INTR_DISABLE() ; +// ETS_INTR_LOCK(); + + PIN_FUNC_SELECT(I2C_MASTER_SDA_MUX, I2C_MASTER_SDA_FUNC); + PIN_FUNC_SELECT(I2C_MASTER_SCL_MUX, I2C_MASTER_SCL_FUNC); + + GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain; + GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SDA_GPIO)); + GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain; + GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SCL_GPIO)); + + I2C_MASTER_SDA_HIGH_SCL_HIGH(); + + ETS_GPIO_INTR_ENABLE() ; +// ETS_INTR_UNLOCK(); + + i2c_master_init(); +} + +/****************************************************************************** + * FunctionName : i2c_master_start + * Description : set i2c to send state + * Parameters : NONE + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_start(void) +{ + i2c_master_setDC(1, m_nLastSCL); + i2c_master_wait(5); + i2c_master_setDC(1, 1); + i2c_master_wait(5); // sda 1, scl 1 + i2c_master_setDC(0, 1); + i2c_master_wait(5); // sda 0, scl 1 +} + +/****************************************************************************** + * FunctionName : i2c_master_stop + * Description : set i2c to stop sending state + * Parameters : NONE + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_stop(void) +{ + i2c_master_wait(5); + + i2c_master_setDC(0, m_nLastSCL); + i2c_master_wait(5); // sda 0 + i2c_master_setDC(0, 1); + i2c_master_wait(5); // sda 0, scl 1 + i2c_master_setDC(1, 1); + i2c_master_wait(5); // sda 1, scl 1 +} + +/****************************************************************************** + * FunctionName : i2c_master_setAck + * Description : set ack to i2c bus as level value + * Parameters : uint8 level - 0 or 1 + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_setAck(uint8 level) +{ + i2c_master_setDC(m_nLastSDA, 0); + i2c_master_wait(5); + i2c_master_setDC(level, 0); + i2c_master_wait(5); // sda level, scl 0 + i2c_master_setDC(level, 1); + i2c_master_wait(8); // sda level, scl 1 + i2c_master_setDC(level, 0); + i2c_master_wait(5); // sda level, scl 0 + i2c_master_setDC(1, 0); + i2c_master_wait(5); +} + +/****************************************************************************** + * FunctionName : i2c_master_getAck + * Description : confirm if peer send ack + * Parameters : NONE + * Returns : uint8 - ack value, 0 or 1 +*******************************************************************************/ +uint8 ICACHE_FLASH_ATTR +i2c_master_getAck(void) +{ + uint8 retVal; + i2c_master_setDC(m_nLastSDA, 0); + i2c_master_wait(5); + i2c_master_setDC(1, 0); + i2c_master_wait(5); + i2c_master_setDC(1, 1); + i2c_master_wait(5); + + retVal = i2c_master_getDC(); + i2c_master_wait(5); + i2c_master_setDC(1, 0); + i2c_master_wait(5); + + return retVal; +} + +/****************************************************************************** +* FunctionName : i2c_master_checkAck +* Description : get dev response +* Parameters : NONE +* Returns : true : get ack ; false : get nack +*******************************************************************************/ +bool ICACHE_FLASH_ATTR +i2c_master_checkAck(void) +{ + if(i2c_master_getAck()){ + return FALSE; + }else{ + return TRUE; + } +} + +/****************************************************************************** +* FunctionName : i2c_master_send_ack +* Description : response ack +* Parameters : NONE +* Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_send_ack(void) +{ + i2c_master_setAck(0x0); +} +/****************************************************************************** +* FunctionName : i2c_master_send_nack +* Description : response nack +* Parameters : NONE +* Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_send_nack(void) +{ + i2c_master_setAck(0x1); +} + +/****************************************************************************** + * FunctionName : i2c_master_readByte + * Description : read Byte from i2c bus + * Parameters : NONE + * Returns : uint8 - readed value +*******************************************************************************/ +uint8 ICACHE_FLASH_ATTR +i2c_master_readByte(void) +{ + uint8 retVal = 0; + uint8 k, i; + + i2c_master_wait(5); + i2c_master_setDC(m_nLastSDA, 0); + i2c_master_wait(5); // sda 1, scl 0 + + for (i = 0; i < 8; i++) { + i2c_master_wait(5); + i2c_master_setDC(1, 0); + i2c_master_wait(5); // sda 1, scl 0 + i2c_master_setDC(1, 1); + i2c_master_wait(5); // sda 1, scl 1 + + k = i2c_master_getDC(); + i2c_master_wait(5); + + if (i == 7) { + i2c_master_wait(3); //// + } + + k <<= (7 - i); + retVal |= k; + } + + i2c_master_setDC(1, 0); + i2c_master_wait(5); // sda 1, scl 0 + + return retVal; +} + +/****************************************************************************** + * FunctionName : i2c_master_writeByte + * Description : write wrdata value(one byte) into i2c + * Parameters : uint8 wrdata - write value + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +i2c_master_writeByte(uint8 wrdata) +{ + uint8 dat; + sint8 i; + + i2c_master_wait(5); + + i2c_master_setDC(m_nLastSDA, 0); + i2c_master_wait(5); + + for (i = 7; i >= 0; i--) { + dat = wrdata >> i; + i2c_master_setDC(dat, 0); + i2c_master_wait(5); + i2c_master_setDC(dat, 1); + i2c_master_wait(5); + + if (i == 0) { + i2c_master_wait(3); //// + } + + i2c_master_setDC(dat, 0); + i2c_master_wait(5); + } +} diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/key.c b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/key.c new file mode 100644 index 0000000..1b2d0df --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/key.c @@ -0,0 +1,162 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: key.c + * + * Description: key driver, now can use different gpio and install different function + * + * Modification history: + * 2014/5/1, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "os_type.h" +#include "osapi.h" +#include "mem.h" +#include "gpio.h" +#include "user_interface.h" + +#include "driver/key.h" + +LOCAL void key_intr_handler(struct keys_param *keys); + +/****************************************************************************** + * FunctionName : key_init_single + * Description : init single key's gpio and register function + * Parameters : uint8 gpio_id - which gpio to use + * uint32 gpio_name - gpio mux name + * uint32 gpio_func - gpio function + * key_function long_press - long press function, needed to install + * key_function short_press - short press function, needed to install + * Returns : single_key_param - single key parameter, needed by key init +*******************************************************************************/ +struct single_key_param *ICACHE_FLASH_ATTR +key_init_single(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func, key_function long_press, key_function short_press) +{ + struct single_key_param *single_key = (struct single_key_param *)os_zalloc(sizeof(struct single_key_param)); + + single_key->gpio_id = gpio_id; + single_key->gpio_name = gpio_name; + single_key->gpio_func = gpio_func; + single_key->long_press = long_press; + single_key->short_press = short_press; + + return single_key; +} + +/****************************************************************************** + * FunctionName : key_init + * Description : init keys + * Parameters : key_param *keys - keys parameter, which inited by key_init_single + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +key_init(struct keys_param *keys) +{ + uint8 i; + + ETS_GPIO_INTR_ATTACH(key_intr_handler, keys); + + ETS_GPIO_INTR_DISABLE(); + + for (i = 0; i < keys->key_num; i++) { + keys->single_key[i]->key_level = 1; + + PIN_FUNC_SELECT(keys->single_key[i]->gpio_name, keys->single_key[i]->gpio_func); + + gpio_output_set(0, 0, 0, GPIO_ID_PIN(keys->single_key[i]->gpio_id)); + + gpio_register_set(GPIO_PIN_ADDR(keys->single_key[i]->gpio_id), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) + | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) + | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)); + + //clear gpio14 status + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(keys->single_key[i]->gpio_id)); + + //enable interrupt + gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_NEGEDGE); + } + + ETS_GPIO_INTR_ENABLE(); +} + +/****************************************************************************** + * FunctionName : key_5s_cb + * Description : long press 5s timer callback + * Parameters : single_key_param *single_key - single key parameter + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +key_5s_cb(struct single_key_param *single_key) +{ + os_timer_disarm(&single_key->key_5s); + + // low, then restart + if (0 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { + if (single_key->long_press) { + single_key->long_press(); + } + } +} + +/****************************************************************************** + * FunctionName : key_50ms_cb + * Description : 50ms timer callback to check it's a real key push + * Parameters : single_key_param *single_key - single key parameter + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +key_50ms_cb(struct single_key_param *single_key) +{ + os_timer_disarm(&single_key->key_50ms); + + // high, then key is up + if (1 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { + os_timer_disarm(&single_key->key_5s); + single_key->key_level = 1; + gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_NEGEDGE); + + if (single_key->short_press) { + single_key->short_press(); + } + } else { + gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_POSEDGE); + } +} + +/****************************************************************************** + * FunctionName : key_intr_handler + * Description : key interrupt handler + * Parameters : key_param *keys - keys parameter, which inited by key_init_single + * Returns : none +*******************************************************************************/ +LOCAL void +key_intr_handler(struct keys_param *keys) +{ + uint8 i; + uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); + + for (i = 0; i < keys->key_num; i++) { + if (gpio_status & BIT(keys->single_key[i]->gpio_id)) { + //disable interrupt + gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_DISABLE); + + //clear interrupt status + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(keys->single_key[i]->gpio_id)); + + if (keys->single_key[i]->key_level == 1) { + // 5s, restart & enter softap mode + os_timer_disarm(&keys->single_key[i]->key_5s); + os_timer_setfn(&keys->single_key[i]->key_5s, (os_timer_func_t *)key_5s_cb, keys->single_key[i]); + os_timer_arm(&keys->single_key[i]->key_5s, 5000, 0); + keys->single_key[i]->key_level = 0; + gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_POSEDGE); + } else { + // 50ms, check if this is a real key up + os_timer_disarm(&keys->single_key[i]->key_50ms); + os_timer_setfn(&keys->single_key[i]->key_50ms, (os_timer_func_t *)key_50ms_cb, keys->single_key[i]); + os_timer_arm(&keys->single_key[i]->key_50ms, 50, 0); + } + } + } +} + diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/spi.c b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/spi.c new file mode 100644 index 0000000..2ff5ff0 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/spi.c @@ -0,0 +1,464 @@ + +#include "driver/spi.h" +#include "driver/spi_overlap.h" + +#define CACHE_FLASH_CTRL_REG 0x3ff0000C +#define CACHE_FLUSH_START_BIT BIT0 +#define CACHE_EMPTY_FLAG_BIT BIT1 +/****************************************************************************** + * FunctionName : cache_flush + * Description : clear all the cpu cache data for stability test. +*******************************************************************************/ +void cache_flush(void) +{ + while(READ_PERI_REG(CACHE_FLASH_CTRL_REG)&CACHE_EMPTY_FLAG_BIT) { + CLEAR_PERI_REG_MASK(CACHE_FLASH_CTRL_REG, CACHE_FLUSH_START_BIT); + SET_PERI_REG_MASK(CACHE_FLASH_CTRL_REG, CACHE_FLUSH_START_BIT); + } + while(!(READ_PERI_REG(CACHE_FLASH_CTRL_REG)&CACHE_EMPTY_FLAG_BIT)); + + CLEAR_PERI_REG_MASK(CACHE_FLASH_CTRL_REG, CACHE_FLUSH_START_BIT); +} +/****************************************************************************** + * FunctionName : spi_master_init + * Description : SPI master initial function for common byte units transmission + * Parameters : uint8 spi_no - SPI module number, Only "SPI" and "HSPI" are valid +*******************************************************************************/ +void ICACHE_FLASH_ATTR + spi_master_init(uint8 spi_no) +{ + uint32 regvalue; + + if(spi_no>1) return; //handle invalid input number + + SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD|SPI_USR_COMMAND); + CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE); + + WRITE_PERI_REG(SPI_CLOCK(spi_no), + ((3&SPI_CLKCNT_N)<1) return; //handle invalid input number + + if(high_bit) bytetemp=(low_8bit>>1)|0x80; + else bytetemp=(low_8bit>>1)&0x7f; + + regvalue= ((8&SPI_USR_COMMAND_BITLEN)<1) return; //handle invalid input number + + while(READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR); + CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI|SPI_USR_MISO); + + //SPI_FLASH_USER2 bit28-31 is cmd length,cmd bit length is value(0-15)+1, + // bit15-0 is cmd value. + WRITE_PERI_REG(SPI_USER2(spi_no), + ((7&SPI_USR_COMMAND_BITLEN)<1) return; //handle invalid input number + + while(READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR); + SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI); + CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MISO|SPI_USR_ADDR|SPI_USR_DUMMY); + + //SPI_FLASH_USER2 bit28-31 is cmd length,cmd bit length is value(0-15)+1, + // bit15-0 is cmd value. + //0x70000000 is for 8bits cmd, 0x04 is eps8266 slave write cmd value + WRITE_PERI_REG(SPI_USER2(spi_no), + ((7&SPI_USR_COMMAND_BITLEN)<1) return; //handle invalid input number + + while(READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR); + + SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MISO); + CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI|SPI_USR_ADDR|SPI_USR_DUMMY); + //SPI_FLASH_USER2 bit28-31 is cmd length,cmd bit length is value(0-15)+1, + // bit15-0 is cmd value. + //0x70000000 is for 8bits cmd, 0x06 is eps8266 slave read cmd value + WRITE_PERI_REG(SPI_USER2(spi_no), + ((7&SPI_USR_COMMAND_BITLEN)<1) + return; //handle invalid input number + if(data_len<=1) data_bit_len=7; + else if(data_len>=32) data_bit_len=0xff; + else data_bit_len=(data_len<<3)-1; + + //clear bit9,bit8 of reg PERIPHS_IO_MUX + //bit9 should be cleared when HSPI clock doesn't equal CPU clock + //bit8 should be cleared when SPI clock doesn't equal CPU clock + ////WRITE_PERI_REG(PERIPHS_IO_MUX, 0x105); //clear bit9//TEST + if(spi_no==SPI){ + PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, 1);//configure io to spi mode + PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CMD_U, 1);//configure io to spi mode + PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA0_U, 1);//configure io to spi mode + PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA1_U, 1);//configure io to spi mode + }else if(spi_no==HSPI){ + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);//configure io to spi mode + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to spi mode + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to spi mode + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to spi mode + } + + //regvalue=READ_PERI_REG(SPI_FLASH_SLAVE(spi_no)); + //slave mode,slave use buffers which are register "SPI_FLASH_C0~C15", enable trans done isr + //set bit 30 bit 29 bit9,bit9 is trans done isr mask + SET_PERI_REG_MASK( SPI_SLAVE(spi_no), + SPI_SLAVE_MODE|SPI_SLV_WR_RD_BUF_EN| + SPI_SLV_WR_BUF_DONE_EN|SPI_SLV_RD_BUF_DONE_EN| + SPI_SLV_WR_STA_DONE_EN|SPI_SLV_RD_STA_DONE_EN| + SPI_TRANS_DONE_EN); + //disable general trans intr + //CLEAR_PERI_REG_MASK(SPI_SLAVE(spi_no),SPI_TRANS_DONE_EN); + + CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE);//disable flash operation mode + SET_PERI_REG_MASK(SPI_USER(spi_no),SPI_USR_MISO_HIGHPART);//SLAVE SEND DATA BUFFER IN C8-C15 + + +//////**************RUN WHEN SLAVE RECIEVE*******************/////// + //tow lines below is to configure spi timing. + SET_PERI_REG_MASK(SPI_CTRL2(spi_no),(0x2&SPI_MOSI_DELAY_NUM)<>8)&0xff; + spi_data[(idx<<2)+2] = (recv_data>>16)&0xff; + spi_data[(idx<<2)+3] = (recv_data>>24)&0xff; + idx++; + } + //add system_os_post here + GPIO_OUTPUT_SET(0, 1); + } + if(regvalue&SPI_SLV_RD_BUF_DONE){ + //it is necessary to call GPIO_OUTPUT_SET(2, 1), when new data is preped in SPI_W8-15 and needs to be sended. + GPIO_OUTPUT_SET(2, 0); + //add system_os_post here + //system_os_post(USER_TASK_PRIO_1,WR_RD,regvalue); + + } + + }else if(READ_PERI_REG(0x3ff00020)&BIT9){ //bit7 is for i2s isr, + + } +} + + +#ifdef SPI_SLAVE_DEBUG + +void ICACHE_FLASH_ATTR + set_miso_data() +{ + if(GPIO_INPUT_GET(2)==0){ + WRITE_PERI_REG(SPI_W8(HSPI),0x05040302); + WRITE_PERI_REG(SPI_W9(HSPI),0x09080706); + WRITE_PERI_REG(SPI_W10(HSPI),0x0d0c0b0a); + WRITE_PERI_REG(SPI_W11(HSPI),0x11100f0e); + + WRITE_PERI_REG(SPI_W12(HSPI),0x15141312); + WRITE_PERI_REG(SPI_W13(HSPI),0x19181716); + WRITE_PERI_REG(SPI_W14(HSPI),0x1d1c1b1a); + WRITE_PERI_REG(SPI_W15(HSPI),0x21201f1e); + GPIO_OUTPUT_SET(2, 1); + } +} + + + +void ICACHE_FLASH_ATTR + disp_spi_data() +{ + uint8 i = 0; + for(i=0;i<32;i++){ + os_printf("data %d : 0x%02x\n\r",i,spi_data[i]); + } + //os_printf("d31:0x%02x\n\r",spi_data[31]); +} + + +void ICACHE_FLASH_ATTR + spi_task(os_event_t *e) +{ + uint8 data; + switch(e->sig){ + case MOSI: + disp_spi_data(); + break; + case STATUS_R_IN_WR : + os_printf("SR ERR in WRPR,Reg:%08x \n",e->par); + break; + case STATUS_W: + os_printf("SW ERR,Reg:%08x\n",e->par); + break; + case TR_DONE_ALONE: + os_printf("TD ALO ERR,Reg:%08x\n",e->par); + break; + case WR_RD: + os_printf("WR&RD ERR,Reg:%08x\n",e->par); + break; + case DATA_ERROR: + os_printf("Data ERR,Reg:%08x\n",e->par); + break; + case STATUS_R_IN_RD : + os_printf("SR ERR in RDPR,Reg:%08x\n",e->par); + break; + default: + break; + } +} + +void ICACHE_FLASH_ATTR + spi_task_init(void) +{ + spiQueue = (os_event_t*)os_malloc(sizeof(os_event_t)*SPI_QUEUE_LEN); + system_os_task(spi_task,USER_TASK_PRIO_1,spiQueue,SPI_QUEUE_LEN); +} + +os_timer_t spi_timer_test; + +void ICACHE_FLASH_ATTR + spi_test_init() +{ + os_printf("spi init\n\r"); + spi_slave_init(HSPI); + os_printf("gpio init\n\r"); + gpio_init(); + os_printf("spi task init \n\r"); + spi_task_init(); +#ifdef SPI_MISO + os_printf("spi miso init\n\r"); + set_miso_data(); +#endif + + //os_timer_disarm(&spi_timer_test); + //os_timer_setfn(&spi_timer_test, (os_timer_func_t *)set_miso_data, NULL);//wjl + //os_timer_arm(&spi_timer_test,50,1); +} + +#endif + + diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/spi_overlap.c b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/spi_overlap.c new file mode 100644 index 0000000..b507f43 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/driver/spi_overlap.c @@ -0,0 +1,398 @@ +#include "driver/spi_overlap.h" +#include "driver/spi.h" +#include "gpio.h" + +#define SPI_FLASH_READ_MODE_MASK 0x196000 +#define WAIT_HSPI_IDLE() while(READ_PERI_REG(SPI_EXT2(HSPI))||(READ_PERI_REG(SPI_CMD(HSPI))&0xfffc0000)); +#define CONF_HSPI_CLK_DIV(div) WRITE_PERI_REG(SPI_CLOCK(HSPI), (((div<<1)+1)<<12)+(div<<6)+(div<<1)+1) +#define HSPI_FALLING_EDGE_SAMPLE() SET_PERI_REG_MASK(SPI_USER(HSPI), SPI_CK_OUT_EDGE) +#define HSPI_RISING_EDGE_SAMPLE() CLEAR_PERI_REG_MASK(SPI_USER(HSPI), SPI_CK_OUT_EDGE) +#define ACTIVE_HSPI_CS0 CLEAR_PERI_REG_MASK(SPI_PIN(HSPI), SPI_CS0_DIS);\ + SET_PERI_REG_MASK(SPI_PIN(HSPI), SPI_CS1_DIS |SPI_CS2_DIS) +#define ACTIVE_HSPI_CS1 CLEAR_PERI_REG_MASK(SPI_PIN(HSPI), SPI_CS1_DIS);\ + SET_PERI_REG_MASK(SPI_PIN(HSPI), SPI_CS0_DIS |SPI_CS2_DIS) +#define ACTIVE_HSPI_CS2 CLEAR_PERI_REG_MASK(SPI_PIN(HSPI), SPI_CS2_DIS);\ + SET_PERI_REG_MASK(SPI_PIN(HSPI), SPI_CS0_DIS |SPI_CS1_DIS) +#define ENABLE_HSPI_DEV_CS() PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2) +#define DISABLE_HSPI_DEV_CS() GPIO_OUTPUT_SET(15, 1);\ + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15) +struct hspi_device_register hspi_dev_reg; +/****************************************************************************** + * FunctionName : hspi_overlap_init + * Description : enable hspi and spi module overlap mode +*******************************************************************************/ +void ICACHE_FLASH_ATTR +hspi_overlap_init(void) +{ + //hspi overlap to spi, two spi masters on cspi + SET_PERI_REG_MASK(HOST_INF_SEL, reg_cspi_overlap); + + //set higher priority for spi than hspi + SET_PERI_REG_MASK(SPI_EXT3(SPI),0x1); + SET_PERI_REG_MASK(SPI_EXT3(HSPI),0x3); + SET_PERI_REG_MASK(SPI_USER(HSPI), BIT(5)); +} +/****************************************************************************** + * FunctionName : hspi_overlap_deinit + * Description : recover hspi and spi module from overlap mode +*******************************************************************************/ +void ICACHE_FLASH_ATTR +hspi_overlap_deinit(void) +{ + //hspi overlap to spi, two spi masters on cspi + CLEAR_PERI_REG_MASK(HOST_INF_SEL, reg_cspi_overlap); + + //set higher priority for spi than hspi + CLEAR_PERI_REG_MASK(SPI_EXT3(SPI),0x1); + CLEAR_PERI_REG_MASK(SPI_EXT3(HSPI),0x3); + CLEAR_PERI_REG_MASK(SPI_USER(HSPI), BIT(5)); +} + +/****************************************************************************** + * FunctionName : spi_reg_backup + * Description : backup SPI normal operation register value and disable CPU cache to modify some flash registers. + * Parameters : uint8 spi_no - SPI module number, Only "SPI" and "HSPI" are valid +*******************************************************************************/ +void ICACHE_FLASH_ATTR + spi_reg_backup(uint8 spi_no,uint32* backup_mem) +{ + if(spi_no>1) return; //handle invalid input number + + backup_mem[PERIPHS_IO_MUX_BACKUP] =READ_PERI_REG(PERIPHS_IO_MUX); + backup_mem[SPI_USER_BACKUP] =READ_PERI_REG(SPI_USER(spi_no)); + backup_mem[SPI_CTRL_BACKUP] =READ_PERI_REG(SPI_CTRL(spi_no)); + backup_mem[SPI_CLOCK_BACKUP] =READ_PERI_REG(SPI_CLOCK(spi_no)); + backup_mem[SPI_USER1_BACKUP] =READ_PERI_REG(SPI_USER1(spi_no)); + backup_mem[SPI_USER2_BACKUP] =READ_PERI_REG(SPI_USER2(spi_no)); + backup_mem[SPI_CMD_BACKUP] =READ_PERI_REG(SPI_CMD(spi_no)); + backup_mem[SPI_PIN_BACKUP] =READ_PERI_REG(SPI_PIN(spi_no)); + backup_mem[SPI_SLAVE_BACKUP] =READ_PERI_REG(SPI_SLAVE(spi_no)); +} +/****************************************************************************** + * FunctionName : spi_reg_recover + * Description : recover SPI normal operation register value and enable CPU cache. + * Parameters : uint8 spi_no - SPI module number, Only "SPI" and "HSPI" are valid +*******************************************************************************/ +void ICACHE_FLASH_ATTR + spi_reg_recover(uint8 spi_no,uint32* backup_mem) +{ + if(spi_no>1) return; //handle invalid input number + +// WRITE_PERI_REG(PERIPHS_IO_MUX, backup_mem[PERIPHS_IO_MUX_BACKUP]); + WRITE_PERI_REG(SPI_USER(spi_no), backup_mem[SPI_USER_BACKUP]); + WRITE_PERI_REG(SPI_CTRL(spi_no), backup_mem[SPI_CTRL_BACKUP]); + WRITE_PERI_REG(SPI_CLOCK(spi_no), backup_mem[SPI_CLOCK_BACKUP]); + WRITE_PERI_REG(SPI_USER1(spi_no), backup_mem[SPI_USER1_BACKUP]); + WRITE_PERI_REG(SPI_USER2(spi_no), backup_mem[SPI_USER2_BACKUP]); + WRITE_PERI_REG(SPI_CMD(spi_no), backup_mem[SPI_CMD_BACKUP]); + WRITE_PERI_REG(SPI_PIN(spi_no), backup_mem[SPI_PIN_BACKUP]); +// WRITE_PERI_REG(SPI_SLAVE(spi_no), backup_mem[SPI_SLAVE_BACKUP]); +} + +void ICACHE_FLASH_ATTR + hspi_master_dev_init(uint8 dev_no,uint8 clk_polar,uint8 clk_div) +{ + uint32 regtemp; + if((dev_no>3)||(clk_polar>1)||(clk_div>0x1f)) + { + os_printf("hspi_master_dev_init parameter is out of range!\n\r"); + return; + } + + WAIT_HSPI_IDLE(); + if(!hspi_dev_reg.hspi_reg_backup_flag){ + if(READ_PERI_REG(PERIPHS_IO_MUX)&BIT8){ + hspi_dev_reg.spi_io_80m=1; + SET_PERI_REG_MASK(SPI_CLOCK(HSPI),SPI_CLK_EQU_SYSCLK); + }else{ + hspi_dev_reg.spi_io_80m=0; + CLEAR_PERI_REG_MASK(SPI_CLOCK(HSPI),SPI_CLK_EQU_SYSCLK); + } + + regtemp=READ_PERI_REG(SPI_CTRL(SPI))&SPI_FLASH_READ_MODE_MASK; + CLEAR_PERI_REG_MASK(SPI_CTRL(HSPI), SPI_FLASH_READ_MODE_MASK); + SET_PERI_REG_MASK(SPI_CTRL(HSPI), regtemp); + spi_reg_backup(HSPI, hspi_dev_reg.hspi_flash_reg_backup); + + spi_master_init(HSPI); + spi_reg_backup(HSPI, hspi_dev_reg.hspi_dev_reg_backup); + + hspi_dev_reg.hspi_reg_backup_flag=1; + + // spi_reg_recover(HSPI, hspi_dev_reg.hspi_flash_reg_backup); + hspi_dev_reg.selected_dev_num=HSPI_IDLE; + } + + hspi_dev_reg.hspi_dev_conf[dev_no].active=1; + hspi_dev_reg.hspi_dev_conf[dev_no].clk_div=clk_div; + hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar=clk_polar; + + switch(dev_no){ + case HSPI_CS_DEV : + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2); + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2); + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2); + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2); + CLEAR_PERI_REG_MASK(PERIPHS_IO_MUX, BIT9); + break; + + case SPI_CS1_DEV : + PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_SPI_CS1); + if(hspi_dev_reg.spi_io_80m){ + os_printf("SPI CS1 device must work at 80Mhz"); + } + break; + + case SPI_CS2_DEV : + PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_SPI_CS2); + if(hspi_dev_reg.spi_io_80m){ + os_printf("SPI CS2 device must work at 80Mhz"); + } + break; + + default: break; + } +} + +void ICACHE_FLASH_ATTR + hspi_dev_sel(uint8 dev_no) +{ + uint32 regval; + + if(dev_no>3){ + os_printf("hspi_dev_sel parameter is out of range!\n\r"); + return; + } + + if(!hspi_dev_reg.hspi_dev_conf[dev_no].active){ + os_printf("device%d has not been initialized!\n\r",dev_no); + return; + } + + switch(hspi_dev_reg.selected_dev_num){ + case HSPI_CS_DEV: + if((dev_no==SPI_CS1_DEV)||(dev_no==SPI_CS2_DEV)){ + WAIT_HSPI_IDLE(); + DISABLE_HSPI_DEV_CS(); + hspi_overlap_init(); + + if(hspi_dev_reg.spi_io_80m) {SET_PERI_REG_MASK(SPI_CLOCK(HSPI), SPI_CLK_EQU_SYSCLK);} + else {CONF_HSPI_CLK_DIV(hspi_dev_reg.hspi_dev_conf[dev_no].clk_div);} + + if(hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar) {HSPI_FALLING_EDGE_SAMPLE();} + else {HSPI_RISING_EDGE_SAMPLE();} + + if(dev_no==SPI_CS1_DEV) {ACTIVE_HSPI_CS1;} + else {ACTIVE_HSPI_CS2;} + } + else if(dev_no==SPI_CS0_FLASH){ + WAIT_HSPI_IDLE(); + DISABLE_HSPI_DEV_CS(); + hspi_overlap_init(); + spi_reg_recover(HSPI, hspi_dev_reg.hspi_flash_reg_backup); + + if(hspi_dev_reg.spi_io_80m) {SET_PERI_REG_MASK(SPI_CLOCK(HSPI), SPI_CLK_EQU_SYSCLK);} + + HSPI_RISING_EDGE_SAMPLE(); + ACTIVE_HSPI_CS0 ; + } + break; + + case SPI_CS1_DEV: + if(dev_no==SPI_CS2_DEV){ + WAIT_HSPI_IDLE(); + if(!hspi_dev_reg.spi_io_80m) {CONF_HSPI_CLK_DIV(hspi_dev_reg.hspi_dev_conf[dev_no].clk_div);} + + if(hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar) {HSPI_FALLING_EDGE_SAMPLE();} + else {HSPI_RISING_EDGE_SAMPLE();} + ACTIVE_HSPI_CS2; + } + else if(dev_no==SPI_CS0_FLASH){ + WAIT_HSPI_IDLE(); + spi_reg_recover(HSPI, hspi_dev_reg.hspi_flash_reg_backup); + HSPI_RISING_EDGE_SAMPLE(); + ACTIVE_HSPI_CS0; + } + else if(dev_no==HSPI_CS_DEV){ + WAIT_HSPI_IDLE(); + ENABLE_HSPI_DEV_CS(); + hspi_overlap_deinit(); + CONF_HSPI_CLK_DIV(hspi_dev_reg.hspi_dev_conf[dev_no].clk_div); + + if(hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar) {HSPI_FALLING_EDGE_SAMPLE();} + else {HSPI_RISING_EDGE_SAMPLE();} + + ACTIVE_HSPI_CS0; + } + break; + + case SPI_CS2_DEV: + if(dev_no==SPI_CS1_DEV){ + WAIT_HSPI_IDLE(); + if(!hspi_dev_reg.spi_io_80m) {CONF_HSPI_CLK_DIV(hspi_dev_reg.hspi_dev_conf[dev_no].clk_div);} + + if(hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar) {HSPI_FALLING_EDGE_SAMPLE();} + else {HSPI_RISING_EDGE_SAMPLE();} + + ACTIVE_HSPI_CS1; + } + else if(dev_no==SPI_CS0_FLASH){ + WAIT_HSPI_IDLE(); + spi_reg_recover(HSPI, hspi_dev_reg.hspi_flash_reg_backup); + HSPI_RISING_EDGE_SAMPLE(); + ACTIVE_HSPI_CS0; + } + else if(dev_no==HSPI_CS_DEV){ + WAIT_HSPI_IDLE(); + ENABLE_HSPI_DEV_CS(); + hspi_overlap_deinit(); + CONF_HSPI_CLK_DIV(hspi_dev_reg.hspi_dev_conf[dev_no].clk_div); + + if(hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar) {HSPI_FALLING_EDGE_SAMPLE();} + else {HSPI_RISING_EDGE_SAMPLE();} + + ACTIVE_HSPI_CS0; + } + break; + + case SPI_CS0_FLASH: + if((dev_no==SPI_CS1_DEV)||(dev_no==SPI_CS2_DEV)){ + WAIT_HSPI_IDLE(); + spi_reg_recover(HSPI, hspi_dev_reg.hspi_dev_reg_backup); + + if(hspi_dev_reg.spi_io_80m) {SET_PERI_REG_MASK(SPI_CLOCK(HSPI), SPI_CLK_EQU_SYSCLK);} + else {CONF_HSPI_CLK_DIV(hspi_dev_reg.hspi_dev_conf[dev_no].clk_div);} + + if(hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar) {HSPI_FALLING_EDGE_SAMPLE();} + else {HSPI_RISING_EDGE_SAMPLE();} + + if(dev_no==SPI_CS1_DEV) {ACTIVE_HSPI_CS1;} + else {ACTIVE_HSPI_CS2;} + } + else if(dev_no==HSPI_CS_DEV){ + WAIT_HSPI_IDLE(); + ENABLE_HSPI_DEV_CS(); + hspi_overlap_deinit(); + spi_reg_recover(HSPI, hspi_dev_reg.hspi_dev_reg_backup); + CONF_HSPI_CLK_DIV(hspi_dev_reg.hspi_dev_conf[dev_no].clk_div); + + if(hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar) {HSPI_FALLING_EDGE_SAMPLE();} + else {HSPI_RISING_EDGE_SAMPLE();} + + ACTIVE_HSPI_CS0; + } + break; + + default: + if((dev_no==SPI_CS1_DEV)||(dev_no==SPI_CS2_DEV)){ + WAIT_HSPI_IDLE(); + DISABLE_HSPI_DEV_CS(); + hspi_overlap_init(); + spi_reg_recover(HSPI, hspi_dev_reg.hspi_dev_reg_backup); + + if(hspi_dev_reg.spi_io_80m) {SET_PERI_REG_MASK(SPI_CLOCK(HSPI), SPI_CLK_EQU_SYSCLK);} + else {CONF_HSPI_CLK_DIV(hspi_dev_reg.hspi_dev_conf[dev_no].clk_div);} + + if(hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar) {HSPI_FALLING_EDGE_SAMPLE();} + else {HSPI_RISING_EDGE_SAMPLE();} + + if(dev_no==SPI_CS1_DEV) {ACTIVE_HSPI_CS1;} + else {ACTIVE_HSPI_CS2;} + } + else if(dev_no==SPI_CS0_FLASH){ + WAIT_HSPI_IDLE(); + DISABLE_HSPI_DEV_CS(); + hspi_overlap_init(); + spi_reg_recover(HSPI, hspi_dev_reg.hspi_flash_reg_backup); + + if(hspi_dev_reg.spi_io_80m) {SET_PERI_REG_MASK(SPI_CLOCK(HSPI), SPI_CLK_EQU_SYSCLK);} + + HSPI_RISING_EDGE_SAMPLE(); + ACTIVE_HSPI_CS0 ; + } + else if(dev_no==HSPI_CS_DEV){ + WAIT_HSPI_IDLE(); + ENABLE_HSPI_DEV_CS(); + hspi_overlap_deinit(); + spi_reg_recover(HSPI, hspi_dev_reg.hspi_dev_reg_backup); + CONF_HSPI_CLK_DIV(hspi_dev_reg.hspi_dev_conf[dev_no].clk_div); + + if(hspi_dev_reg.hspi_dev_conf[dev_no].clk_polar) {HSPI_FALLING_EDGE_SAMPLE();} + else {HSPI_RISING_EDGE_SAMPLE();} + + ACTIVE_HSPI_CS0; + } + break; + } + hspi_dev_reg.selected_dev_num=dev_no; +} + +/****************************************************************************** + * FunctionName : spi_read_data + * Description : use hspi to read flash data for stability test + * Parameters : SpiFlashChip * spi-- flash parameter structure pointer + * uint32 flash_addr--flash start address + * uint32 * addr_dest--start address for preped destination memory space + * uint32 byte_length--length of the data which needs to be read from flash +*******************************************************************************/ +SpiFlashOpResult ICACHE_FLASH_ATTR +hspi_overlap_read_flash_data(SpiFlashChip * spi, uint32 flash_addr, uint32 * addr_dest, uint32 byte_length) +{ + uint32 temp_addr,reg_tmp; + sint32 temp_length; + uint8 i; + uint8 remain_word_num; + + hspi_dev_sel(SPI_CS0_FLASH); + + //address range check + if ((flash_addr+byte_length) > (spi->chip_size)) + { + return SPI_FLASH_RESULT_ERR; + } + + temp_addr = flash_addr; + temp_length = byte_length; + + while(temp_length > 0) + { + if(temp_length >= SPI_BUFF_BYTE_NUM) + { + // reg_tmp=((temp_addr&0xff)<<16)|(temp_addr&0xff00)|((temp_addr&0xff0000)>>16)|(SPI_BUFF_BYTE_NUM << SPI_FLASH_BYTES_LEN); + reg_tmp= temp_addr |(SPI_BUFF_BYTE_NUM<< SPI_FLASH_BYTES_LEN) ; + WRITE_PERI_REG(SPI_ADDR(HSPI), reg_tmp); + WRITE_PERI_REG(SPI_CMD(HSPI), SPI_FLASH_READ); + while(READ_PERI_REG(SPI_CMD(HSPI)) != 0); + + for(i=0; i<(SPI_BUFF_BYTE_NUM>>2);i++) + { + *addr_dest++ = READ_PERI_REG(SPI_W0(HSPI)+i*4); + } + temp_length = temp_length - SPI_BUFF_BYTE_NUM; + temp_addr = temp_addr + SPI_BUFF_BYTE_NUM; + } + else + { + WRITE_PERI_REG(SPI_ADDR(HSPI), temp_addr |(temp_length << SPI_FLASH_BYTES_LEN )); + WRITE_PERI_REG(SPI_CMD(HSPI), SPI_FLASH_READ); + while(READ_PERI_REG(SPI_CMD(HSPI)) != 0); + + remain_word_num = (0== (temp_length&0x3))? (temp_length>>2) : (temp_length>>2)+1; + for (i=0; i. + */ +#include "ets_sys.h" +#include "osapi.h" +#include "driver/uart.h" +#include "osapi.h" +#include "driver/uart_register.h" +#include "mem.h" +#include "os_type.h" + +// UartDev is defined and initialized in rom code. +extern UartDevice UartDev; + +LOCAL struct UartBuffer* pTxBuffer = NULL; +LOCAL struct UartBuffer* pRxBuffer = NULL; + +/*uart demo with a system task, to output what uart receives*/ +/*this is a example to process uart data from task,please change the priority to fit your application task if exists*/ +/*it might conflict with your task, if so,please arrange the priority of different task, or combine it to a different event in the same task. */ +#define uart_recvTaskPrio 0 +#define uart_recvTaskQueueLen 10 +os_event_t uart_recvTaskQueue[uart_recvTaskQueueLen]; + +#define DBG +#define DBG1 uart1_sendStr_no_wait +#define DBG2 os_printf + + +LOCAL void uart0_rx_intr_handler(void *para); + +/****************************************************************************** + * FunctionName : uart_config + * Description : Internal used function + * UART0 used for data TX/RX, RX buffer size is 0x100, interrupt enabled + * UART1 just used for debug output + * Parameters : uart_no, use UART0 or UART1 defined ahead + * Returns : NONE +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +uart_config(uint8 uart_no) +{ + if (uart_no == UART1){ + PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK); + }else{ + /* rcv_buff size if 0x100 */ + ETS_UART_INTR_ATTACH(uart0_rx_intr_handler, &(UartDev.rcv_buff)); + PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U); + PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); + #if UART_HW_RTS + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS); //HW FLOW CONTROL RTS PIN + #endif + #if UART_HW_CTS + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_U0CTS); //HW FLOW CONTROL CTS PIN + #endif + } + uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));//SET BAUDRATE + + WRITE_PERI_REG(UART_CONF0(uart_no), ((UartDev.exist_parity & UART_PARITY_EN_M) << UART_PARITY_EN_S) //SET BIT AND PARITY MODE + | ((UartDev.parity & UART_PARITY_M) <> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126) { + break; + } + } + WRITE_PERI_REG(UART_FIFO(uart) , TxChar); + return OK; +} + +/****************************************************************************** + * FunctionName : uart1_write_char + * Description : Internal used function + * Do some special deal while tx char is '\r' or '\n' + * Parameters : char c - character to tx + * Returns : NONE +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +uart1_write_char(char c) +{ + if (c == '\n'){ + uart_tx_one_char(UART1, '\r'); + uart_tx_one_char(UART1, '\n'); + }else if (c == '\r'){ + + }else{ + uart_tx_one_char(UART1, c); + } +} + +//os_printf output to fifo or to the tx buffer +LOCAL void ICACHE_FLASH_ATTR +uart0_write_char_no_wait(char c) +{ +#if UART_BUFF_EN //send to uart0 fifo but do not wait + uint8 chr; + if (c == '\n'){ + chr = '\r'; + tx_buff_enq(&chr, 1); + chr = '\n'; + tx_buff_enq(&chr, 1); + }else if (c == '\r'){ + + }else{ + tx_buff_enq(&c,1); + } +#else //send to uart tx buffer + if (c == '\n'){ + uart_tx_one_char_no_wait(UART0, '\r'); + uart_tx_one_char_no_wait(UART0, '\n'); + }else if (c == '\r'){ + + } + else{ + uart_tx_one_char_no_wait(UART0, c); + } +#endif +} + +/****************************************************************************** + * FunctionName : uart0_tx_buffer + * Description : use uart0 to transfer buffer + * Parameters : uint8 *buf - point to send buffer + * uint16 len - buffer len + * Returns : +*******************************************************************************/ +void ICACHE_FLASH_ATTR +uart0_tx_buffer(uint8 *buf, uint16 len) +{ + uint16 i; + for (i = 0; i < len; i++) + { + uart_tx_one_char(UART0, buf[i]); + } +} + +/****************************************************************************** + * FunctionName : uart0_sendStr + * Description : use uart0 to transfer buffer + * Parameters : uint8 *buf - point to send buffer + * uint16 len - buffer len + * Returns : +*******************************************************************************/ +void ICACHE_FLASH_ATTR +uart0_sendStr(const char *str) +{ + while(*str){ + uart_tx_one_char(UART0, *str++); + } +} +void at_port_print(const char *str) __attribute__((alias("uart0_sendStr"))); +/****************************************************************************** + * FunctionName : uart0_rx_intr_handler + * Description : Internal used function + * UART0 interrupt handler, add self handle code inside + * Parameters : void *para - point to ETS_UART_INTR_ATTACH's arg + * Returns : NONE +*******************************************************************************/ +LOCAL void +uart0_rx_intr_handler(void *para) +{ + /* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents + * uart1 and uart0 respectively + */ + uint8 RcvChar; + uint8 uart_no = UART0;//UartDev.buff_uart_no; + uint8 fifo_len = 0; + uint8 buf_idx = 0; + uint8 temp,cnt; + //RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para; + + /*ATTENTION:*/ + /*IN NON-OS VERSION SDK, DO NOT USE "ICACHE_FLASH_ATTR" FUNCTIONS IN THE WHOLE HANDLER PROCESS*/ + /*ALL THE FUNCTIONS CALLED IN INTERRUPT HANDLER MUST BE DECLARED IN RAM */ + /*IF NOT , POST AN EVENT AND PROCESS IN SYSTEM TASK */ + if(UART_FRM_ERR_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_FRM_ERR_INT_ST)){ + DBG1("FRM_ERR\r\n"); + WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_FRM_ERR_INT_CLR); + }else if(UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_FULL_INT_ST)){ + DBG("f"); + uart_rx_intr_disable(UART0); + WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR); + system_os_post(uart_recvTaskPrio, 0, 0); + }else if(UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_TOUT_INT_ST)){ + DBG("t"); + uart_rx_intr_disable(UART0); + WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_TOUT_INT_CLR); + system_os_post(uart_recvTaskPrio, 0, 0); + }else if(UART_TXFIFO_EMPTY_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_TXFIFO_EMPTY_INT_ST)){ + DBG("e"); + /* to output uart data from uart buffer directly in empty interrupt handler*/ + /*instead of processing in system event, in order not to wait for current task/function to quit */ + /*ATTENTION:*/ + /*IN NON-OS VERSION SDK, DO NOT USE "ICACHE_FLASH_ATTR" FUNCTIONS IN THE WHOLE HANDLER PROCESS*/ + /*ALL THE FUNCTIONS CALLED IN INTERRUPT HANDLER MUST BE DECLARED IN RAM */ + CLEAR_PERI_REG_MASK(UART_INT_ENA(UART0), UART_TXFIFO_EMPTY_INT_ENA); + #if UART_BUFF_EN + tx_start_uart_buffer(UART0); + #endif + //system_os_post(uart_recvTaskPrio, 1, 0); + WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_TXFIFO_EMPTY_INT_CLR); + + }else if(UART_RXFIFO_OVF_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_OVF_INT_ST)){ + WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_RXFIFO_OVF_INT_CLR); + DBG1("RX OVF!!\r\n"); + } + +} + +/****************************************************************************** + * FunctionName : uart_init + * Description : user interface for init uart + * Parameters : UartBautRate uart0_br - uart0 bautrate + * UartBautRate uart1_br - uart1 bautrate + * Returns : NONE +*******************************************************************************/ +#if UART_SELFTEST&UART_BUFF_EN +os_timer_t buff_timer_t; +void ICACHE_FLASH_ATTR +uart_test_rx() +{ + uint8 uart_buf[128]={0}; + uint16 len = 0; + len = rx_buff_deq(uart_buf, 128 ); + tx_buff_enq(uart_buf,len); +} +#endif + +LOCAL void ICACHE_FLASH_ATTR /////// +uart_recvTask(os_event_t *events) +{ + if(events->sig == 0){ + #if UART_BUFF_EN + Uart_rx_buff_enq(); + #else + uint8 fifo_len = (READ_PERI_REG(UART_STATUS(UART0))>>UART_RXFIFO_CNT_S)&UART_RXFIFO_CNT; + uint8 d_tmp = 0; + uint8 idx=0; + for(idx=0;idxsig == 1){ + #if UART_BUFF_EN + //already move uart buffer output to uart empty interrupt + //tx_start_uart_buffer(UART0); + #else + + #endif + } +} + +void ICACHE_FLASH_ATTR +uart_init(UartBautRate uart0_br, UartBautRate uart1_br) +{ + /*this is a example to process uart data from task,please change the priority to fit your application task if exists*/ + system_os_task(uart_recvTask, uart_recvTaskPrio, uart_recvTaskQueue, uart_recvTaskQueueLen); //demo with a task to process the uart data + + UartDev.baut_rate = uart0_br; + uart_config(UART0); + UartDev.baut_rate = uart1_br; + uart_config(UART1); + ETS_UART_INTR_ENABLE(); + + #if UART_BUFF_EN + pTxBuffer = Uart_Buf_Init(UART_TX_BUFFER_SIZE); + pRxBuffer = Uart_Buf_Init(UART_RX_BUFFER_SIZE); + #endif + + + /*option 1: use default print, output from uart0 , will wait some time if fifo is full */ + //do nothing... + + /*option 2: output from uart1,uart1 output will not wait , just for output debug info */ + /*os_printf output uart data via uart1(GPIO2)*/ + //os_install_putc1((void *)uart1_write_char); //use this one to output debug information via uart1 // + + /*option 3: output from uart0 will skip current byte if fifo is full now... */ + /*see uart0_write_char_no_wait:you can output via a buffer or output directly */ + /*os_printf output uart data via uart0 or uart buffer*/ + //os_install_putc1((void *)uart0_write_char_no_wait); //use this to print via uart0 + + #if UART_SELFTEST&UART_BUFF_EN + os_timer_disarm(&buff_timer_t); + os_timer_setfn(&buff_timer_t, uart_test_rx , NULL); //a demo to process the data in uart rx buffer + os_timer_arm(&buff_timer_t,10,1); + #endif +} + +void ICACHE_FLASH_ATTR +uart_reattach() +{ + uart_init(BIT_RATE_115200, BIT_RATE_115200); +} + +/****************************************************************************** + * FunctionName : uart_tx_one_char_no_wait + * Description : uart tx a single char without waiting for fifo + * Parameters : uint8 uart - uart port + * uint8 TxChar - char to tx + * Returns : STATUS +*******************************************************************************/ +STATUS uart_tx_one_char_no_wait(uint8 uart, uint8 TxChar) +{ + uint8 fifo_cnt = (( READ_PERI_REG(UART_STATUS(uart))>>UART_TXFIFO_CNT_S)& UART_TXFIFO_CNT); + if (fifo_cnt < 126) { + WRITE_PERI_REG(UART_FIFO(uart) , TxChar); + } + return OK; +} + +STATUS uart0_tx_one_char_no_wait(uint8 TxChar) +{ + uint8 fifo_cnt = (( READ_PERI_REG(UART_STATUS(UART0))>>UART_TXFIFO_CNT_S)& UART_TXFIFO_CNT); + if (fifo_cnt < 126) { + WRITE_PERI_REG(UART_FIFO(UART0) , TxChar); + } + return OK; +} + + +/****************************************************************************** + * FunctionName : uart1_sendStr_no_wait + * Description : uart tx a string without waiting for every char, used for print debug info which can be lost + * Parameters : const char *str - string to be sent + * Returns : NONE +*******************************************************************************/ +void uart1_sendStr_no_wait(const char *str) +{ + while(*str){ + uart_tx_one_char_no_wait(UART1, *str++); + } +} + + +#if UART_BUFF_EN +/****************************************************************************** + * FunctionName : Uart_Buf_Init + * Description : tx buffer enqueue: fill a first linked buffer + * Parameters : char *pdata - data point to be enqueue + * Returns : NONE +*******************************************************************************/ +struct UartBuffer* ICACHE_FLASH_ATTR +Uart_Buf_Init(uint32 buf_size) +{ + uint32 heap_size = system_get_free_heap_size(); + if(heap_size <=buf_size){ + DBG1("no buf for uart\n\r"); + return NULL; + }else{ + DBG("test heap size: %d\n\r",heap_size); + struct UartBuffer* pBuff = (struct UartBuffer* )os_malloc(sizeof(struct UartBuffer)); + pBuff->UartBuffSize = buf_size; + pBuff->pUartBuff = (uint8*)os_malloc(pBuff->UartBuffSize); + pBuff->pInPos = pBuff->pUartBuff; + pBuff->pOutPos = pBuff->pUartBuff; + pBuff->Space = pBuff->UartBuffSize; + pBuff->BuffState = OK; + pBuff->nextBuff = NULL; + pBuff->TcpControl = RUN; + return pBuff; + } +} + + +//copy uart buffer +LOCAL void Uart_Buf_Cpy(struct UartBuffer* pCur, char* pdata , uint16 data_len) +{ + if(data_len == 0) return ; + + uint16 tail_len = pCur->pUartBuff + pCur->UartBuffSize - pCur->pInPos ; + if(tail_len >= data_len){ //do not need to loop back the queue + os_memcpy(pCur->pInPos , pdata , data_len ); + pCur->pInPos += ( data_len ); + pCur->pInPos = (pCur->pUartBuff + (pCur->pInPos - pCur->pUartBuff) % pCur->UartBuffSize ); + pCur->Space -=data_len; + }else{ + os_memcpy(pCur->pInPos, pdata, tail_len); + pCur->pInPos += ( tail_len ); + pCur->pInPos = (pCur->pUartBuff + (pCur->pInPos - pCur->pUartBuff) % pCur->UartBuffSize ); + pCur->Space -=tail_len; + os_memcpy(pCur->pInPos, pdata+tail_len , data_len-tail_len); + pCur->pInPos += ( data_len-tail_len ); + pCur->pInPos = (pCur->pUartBuff + (pCur->pInPos - pCur->pUartBuff) % pCur->UartBuffSize ); + pCur->Space -=( data_len-tail_len); + } + +} + +/****************************************************************************** + * FunctionName : uart_buf_free + * Description : deinit of the tx buffer + * Parameters : struct UartBuffer* pTxBuff - tx buffer struct pointer + * Returns : NONE +*******************************************************************************/ +void ICACHE_FLASH_ATTR +uart_buf_free(struct UartBuffer* pBuff) +{ + os_free(pBuff->pUartBuff); + os_free(pBuff); +} + + +//rx buffer dequeue +uint16 ICACHE_FLASH_ATTR +rx_buff_deq(char* pdata, uint16 data_len ) +{ + uint16 buf_len = (pRxBuffer->UartBuffSize- pRxBuffer->Space); + uint16 tail_len = pRxBuffer->pUartBuff + pRxBuffer->UartBuffSize - pRxBuffer->pOutPos ; + uint16 len_tmp = 0; + len_tmp = ((data_len > buf_len)?buf_len:data_len); + if(pRxBuffer->pOutPos <= pRxBuffer->pInPos){ + os_memcpy(pdata, pRxBuffer->pOutPos,len_tmp); + pRxBuffer->pOutPos+= len_tmp; + pRxBuffer->Space += len_tmp; + }else{ + if(len_tmp>tail_len){ + os_memcpy(pdata, pRxBuffer->pOutPos, tail_len); + pRxBuffer->pOutPos += tail_len; + pRxBuffer->pOutPos = (pRxBuffer->pUartBuff + (pRxBuffer->pOutPos- pRxBuffer->pUartBuff) % pRxBuffer->UartBuffSize ); + pRxBuffer->Space += tail_len; + + os_memcpy(pdata+tail_len , pRxBuffer->pOutPos, len_tmp-tail_len); + pRxBuffer->pOutPos+= ( len_tmp-tail_len ); + pRxBuffer->pOutPos= (pRxBuffer->pUartBuff + (pRxBuffer->pOutPos- pRxBuffer->pUartBuff) % pRxBuffer->UartBuffSize ); + pRxBuffer->Space +=( len_tmp-tail_len); + }else{ + //os_printf("case 3 in rx deq\n\r"); + os_memcpy(pdata, pRxBuffer->pOutPos, len_tmp); + pRxBuffer->pOutPos += len_tmp; + pRxBuffer->pOutPos = (pRxBuffer->pUartBuff + (pRxBuffer->pOutPos- pRxBuffer->pUartBuff) % pRxBuffer->UartBuffSize ); + pRxBuffer->Space += len_tmp; + } + } + if(pRxBuffer->Space >= UART_FIFO_LEN){ + uart_rx_intr_enable(UART0); + } + return len_tmp; +} + + +//move data from uart fifo to rx buffer +void Uart_rx_buff_enq() +{ + uint8 fifo_len,buf_idx; + uint8 fifo_data; + #if 1 + fifo_len = (READ_PERI_REG(UART_STATUS(UART0))>>UART_RXFIFO_CNT_S)&UART_RXFIFO_CNT; + if(fifo_len >= pRxBuffer->Space){ + os_printf("buf full!!!\n\r"); + }else{ + buf_idx=0; + while(buf_idx < fifo_len){ + buf_idx++; + fifo_data = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF; + *(pRxBuffer->pInPos++) = fifo_data; + if(pRxBuffer->pInPos == (pRxBuffer->pUartBuff + pRxBuffer->UartBuffSize)){ + pRxBuffer->pInPos = pRxBuffer->pUartBuff; + } + } + pRxBuffer->Space -= fifo_len ; + if(pRxBuffer->Space >= UART_FIFO_LEN){ + //os_printf("after rx enq buf enough\n\r"); + uart_rx_intr_enable(UART0); + } + } + #endif +} + + +//fill the uart tx buffer +void ICACHE_FLASH_ATTR +tx_buff_enq(char* pdata, uint16 data_len ) +{ + CLEAR_PERI_REG_MASK(UART_INT_ENA(UART0), UART_TXFIFO_EMPTY_INT_ENA); + + if(pTxBuffer == NULL){ + DBG1("\n\rnull, create buffer struct\n\r"); + pTxBuffer = Uart_Buf_Init(UART_TX_BUFFER_SIZE); + if(pTxBuffer!= NULL){ + Uart_Buf_Cpy(pTxBuffer , pdata, data_len ); + }else{ + DBG1("uart tx MALLOC no buf \n\r"); + } + }else{ + if(data_len <= pTxBuffer->Space){ + Uart_Buf_Cpy(pTxBuffer , pdata, data_len); + }else{ + DBG1("UART TX BUF FULL!!!!\n\r"); + } + } + #if 0 + if(pTxBuffer->Space <= URAT_TX_LOWER_SIZE){ + set_tcp_block(); + } + #endif + SET_PERI_REG_MASK(UART_CONF1(UART0), (UART_TX_EMPTY_THRESH_VAL & UART_TXFIFO_EMPTY_THRHD)<pOutPos++)); + if(pTxBuff->pOutPos == (pTxBuff->pUartBuff + pTxBuff->UartBuffSize)){ + pTxBuff->pOutPos = pTxBuff->pUartBuff; + } + } + pTxBuff->pOutPos = (pTxBuff->pUartBuff + (pTxBuff->pOutPos - pTxBuff->pUartBuff) % pTxBuff->UartBuffSize ); + pTxBuff->Space += data_len; +} + + +/****************************************************************************** + * FunctionName : tx_start_uart_buffer + * Description : get data from the tx buffer and fill the uart tx fifo, co-work with the uart fifo empty interrupt + * Parameters : uint8 uart_no - uart port num + * Returns : NONE +*******************************************************************************/ +void tx_start_uart_buffer(uint8 uart_no) +{ + uint8 tx_fifo_len = (READ_PERI_REG(UART_STATUS(uart_no))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT; + uint8 fifo_remain = UART_FIFO_LEN - tx_fifo_len ; + uint8 len_tmp; + uint16 tail_ptx_len,head_ptx_len,data_len; + //struct UartBuffer* pTxBuff = *get_buff_prt(); + + if(pTxBuffer){ + data_len = (pTxBuffer->UartBuffSize - pTxBuffer->Space); + if(data_len > fifo_remain){ + len_tmp = fifo_remain; + tx_fifo_insert( pTxBuffer,len_tmp,uart_no); + SET_PERI_REG_MASK(UART_INT_ENA(UART0), UART_TXFIFO_EMPTY_INT_ENA); + }else{ + len_tmp = data_len; + tx_fifo_insert( pTxBuffer,len_tmp,uart_no); + } + }else{ + DBG1("pTxBuff null \n\r"); + } +} + +#endif + + +void uart_rx_intr_disable(uint8 uart_no) +{ +#if 1 + CLEAR_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA|UART_RXFIFO_TOUT_INT_ENA); +#else + ETS_UART_INTR_DISABLE(); +#endif +} + +void uart_rx_intr_enable(uint8 uart_no) +{ +#if 1 + SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA|UART_RXFIFO_TOUT_INT_ENA); +#else + ETS_UART_INTR_ENABLE(); +#endif +} + + +//======================================================== +LOCAL void +uart0_write_char(char c) +{ + if (c == '\n') { + uart_tx_one_char(UART0, '\r'); + uart_tx_one_char(UART0, '\n'); + } else if (c == '\r') { + } else { + uart_tx_one_char(UART0, c); + } +} + +void ICACHE_FLASH_ATTR +UART_SetWordLength(uint8 uart_no, UartBitsNum4Char len) +{ + SET_PERI_REG_BITS(UART_CONF0(uart_no),UART_BIT_NUM,len,UART_BIT_NUM_S); +} + +void ICACHE_FLASH_ATTR +UART_SetStopBits(uint8 uart_no, UartStopBitsNum bit_num) +{ + SET_PERI_REG_BITS(UART_CONF0(uart_no),UART_STOP_BIT_NUM,bit_num,UART_STOP_BIT_NUM_S); +} + +void ICACHE_FLASH_ATTR +UART_SetLineInverse(uint8 uart_no, UART_LineLevelInverse inverse_mask) +{ + CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_LINE_INV_MASK); + SET_PERI_REG_MASK(UART_CONF0(uart_no), inverse_mask); +} + +void ICACHE_FLASH_ATTR +UART_SetParity(uint8 uart_no, UartParityMode Parity_mode) +{ + CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_PARITY |UART_PARITY_EN); + if(Parity_mode==NONE_BITS){ + }else{ + SET_PERI_REG_MASK(UART_CONF0(uart_no), Parity_mode|UART_PARITY_EN); + } +} + +void ICACHE_FLASH_ATTR +UART_SetBaudrate(uint8 uart_no,uint32 baud_rate) +{ + uart_div_modify(uart_no, UART_CLK_FREQ /baud_rate); +} + +void ICACHE_FLASH_ATTR +UART_SetFlowCtrl(uint8 uart_no,UART_HwFlowCtrl flow_ctrl,uint8 rx_thresh) +{ + if(flow_ctrl&USART_HardwareFlowControl_RTS){ + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS); + SET_PERI_REG_BITS(UART_CONF1(uart_no),UART_RX_FLOW_THRHD,rx_thresh,UART_RX_FLOW_THRHD_S); + SET_PERI_REG_MASK(UART_CONF1(uart_no), UART_RX_FLOW_EN); + }else{ + CLEAR_PERI_REG_MASK(UART_CONF1(uart_no), UART_RX_FLOW_EN); + } + if(flow_ctrl&USART_HardwareFlowControl_CTS){ + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_UART0_CTS); + SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_TX_FLOW_EN); + }else{ + CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_TX_FLOW_EN); + } +} + +void ICACHE_FLASH_ATTR +UART_WaitTxFifoEmpty(uint8 uart_no , uint32 time_out_us) //do not use if tx flow control enabled +{ + uint32 t_s = system_get_time(); + while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S)){ + + if(( system_get_time() - t_s )> time_out_us){ + break; + } + WRITE_PERI_REG(0X60000914, 0X73);//WTD + + } +} + + +bool ICACHE_FLASH_ATTR +UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us) +{ + uint32 t_start = system_get_time(); + uint8 tx_fifo_len; + uint32 tx_buff_len; + while(1){ + tx_fifo_len =( (READ_PERI_REG(UART_STATUS(uart_no))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT); + if(pTxBuffer){ + tx_buff_len = ((pTxBuffer->UartBuffSize)-(pTxBuffer->Space)); + }else{ + tx_buff_len = 0; + } + + if( tx_fifo_len==0 && tx_buff_len==0){ + return TRUE; + } + if( system_get_time() - t_start > time_out_us){ + return FALSE; + } + WRITE_PERI_REG(0X60000914, 0X73);//WTD + } +} + + +void ICACHE_FLASH_ATTR +UART_ResetFifo(uint8 uart_no) +{ + SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); + CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); +} + +void ICACHE_FLASH_ATTR +UART_ClearIntrStatus(uint8 uart_no,uint32 clr_mask) +{ + WRITE_PERI_REG(UART_INT_CLR(uart_no), clr_mask); +} + +void ICACHE_FLASH_ATTR +UART_SetIntrEna(uint8 uart_no,uint32 ena_mask) +{ + SET_PERI_REG_MASK(UART_INT_ENA(uart_no), ena_mask); +} + + +void ICACHE_FLASH_ATTR +UART_SetPrintPort(uint8 uart_no) +{ + if(uart_no==1){ + os_install_putc1(uart1_write_char); + }else{ + /*option 1: do not wait if uart fifo is full,drop current character*/ + os_install_putc1(uart0_write_char_no_wait); + /*option 2: wait for a while if uart fifo is full*/ + os_install_putc1(uart0_write_char); + } +} + + +//======================================================== + + +/*test code*/ +void ICACHE_FLASH_ATTR +uart_init_2(UartBautRate uart0_br, UartBautRate uart1_br) +{ + // rom use 74880 baut_rate, here reinitialize + UartDev.baut_rate = uart0_br; + UartDev.exist_parity = STICK_PARITY_EN; + UartDev.parity = EVEN_BITS; + UartDev.stop_bits = ONE_STOP_BIT; + UartDev.data_bits = EIGHT_BITS; + + uart_config(UART0); + UartDev.baut_rate = uart1_br; + uart_config(UART1); + ETS_UART_INTR_ENABLE(); + + // install uart1 putc callback + os_install_putc1((void *)uart1_write_char);//print output at UART1 +} + + diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/include/driver/gpio16.h b/esp_iot_sdk_v1.3.0/examples/driver_lib/include/driver/gpio16.h new file mode 100644 index 0000000..fd62f80 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/include/driver/gpio16.h @@ -0,0 +1,9 @@ +#ifndef __GPIO16_H__ +#define __GPIO16_H__ + +void gpio16_output_conf(void); +void gpio16_output_set(uint8 value); +void gpio16_input_conf(void); +uint8 gpio16_input_get(void); + +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/include/driver/i2c_master.h b/esp_iot_sdk_v1.3.0/examples/driver_lib/include/driver/i2c_master.h new file mode 100644 index 0000000..7455add --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/include/driver/i2c_master.h @@ -0,0 +1,57 @@ +#ifndef __I2C_MASTER_H__ +#define __I2C_MASTER_H__ + +#define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U +#define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_MTMS_U +#define I2C_MASTER_SDA_GPIO 2 +#define I2C_MASTER_SCL_GPIO 14 +#define I2C_MASTER_SDA_FUNC FUNC_GPIO2 +#define I2C_MASTER_SCL_FUNC FUNC_GPIO14 + +//#define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U +//#define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_GPIO0_U +//#define I2C_MASTER_SDA_GPIO 2 +//#define I2C_MASTER_SCL_GPIO 0 +//#define I2C_MASTER_SDA_FUNC FUNC_GPIO2 +//#define I2C_MASTER_SCL_FUNC FUNC_GPIO0 + +#if 0 +#define I2C_MASTER_GPIO_SET(pin) \ + gpio_output_set(1<. + */ +#ifndef UART_APP_H +#define UART_APP_H + +#include "uart_register.h" +#include "eagle_soc.h" +#include "c_types.h" + +#define UART_TX_BUFFER_SIZE 256 //Ring buffer length of tx buffer +#define UART_RX_BUFFER_SIZE 256 //Ring buffer length of rx buffer + +#define UART_BUFF_EN 0 //use uart buffer , FOR UART0 +#define UART_SELFTEST 0 //set 1:enable the loop test demo for uart buffer, FOR UART0 + +#define UART_HW_RTS 0 //set 1: enable uart hw flow control RTS, PIN MTDO, FOR UART0 +#define UART_HW_CTS 0 //set1: enable uart hw flow contrl CTS , PIN MTCK, FOR UART0 + + + + +#define UART0 0 +#define UART1 1 + + +typedef enum { + FIVE_BITS = 0x0, + SIX_BITS = 0x1, + SEVEN_BITS = 0x2, + EIGHT_BITS = 0x3 +} UartBitsNum4Char; + +typedef enum { + ONE_STOP_BIT = 0x1, + ONE_HALF_STOP_BIT = 0x2, + TWO_STOP_BIT = 0x3 +} UartStopBitsNum; + +typedef enum { + NONE_BITS = 0x2, + ODD_BITS = 1, + EVEN_BITS = 0 +} UartParityMode; + +typedef enum { + STICK_PARITY_DIS = 0, + STICK_PARITY_EN = 1 +} UartExistParity; + +typedef enum { + UART_None_Inverse = 0x0, + UART_Rxd_Inverse = UART_RXD_INV, + UART_CTS_Inverse = UART_CTS_INV, + UART_Txd_Inverse = UART_TXD_INV, + UART_RTS_Inverse = UART_RTS_INV, +} UART_LineLevelInverse; + + +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, +} UartBautRate; + +typedef enum { + NONE_CTRL, + HARDWARE_CTRL, + XON_XOFF_CTRL +} UartFlowCtrl; + +typedef enum { + USART_HardwareFlowControl_None = 0x0, + USART_HardwareFlowControl_RTS = 0x1, + USART_HardwareFlowControl_CTS = 0x2, + USART_HardwareFlowControl_CTS_RTS = 0x3 +} UART_HwFlowCtrl; + +typedef enum { + EMPTY, + UNDER_WRITE, + WRITE_OVER +} RcvMsgBuffState; + +typedef struct { + uint32 RcvBuffSize; + uint8 *pRcvMsgBuff; + uint8 *pWritePos; + uint8 *pReadPos; + uint8 TrigLvl; //JLU: may need to pad + RcvMsgBuffState BuffState; +} RcvMsgBuff; + +typedef struct { + uint32 TrxBuffSize; + uint8 *pTrxBuff; +} TrxMsgBuff; + +typedef enum { + BAUD_RATE_DET, + WAIT_SYNC_FRM, + SRCH_MSG_HEAD, + RCV_MSG_BODY, + RCV_ESC_CHAR, +} RcvMsgState; + +typedef struct { + UartBautRate baut_rate; + UartBitsNum4Char data_bits; + UartExistParity exist_parity; + UartParityMode parity; + UartStopBitsNum stop_bits; + UartFlowCtrl flow_ctrl; + RcvMsgBuff rcv_buff; + TrxMsgBuff trx_buff; + RcvMsgState rcv_state; + int received; + int buff_uart_no; //indicate which uart use tx/rx buffer +} UartDevice; + +void uart_init(UartBautRate uart0_br, UartBautRate uart1_br); +void uart0_sendStr(const char *str); + + +/////////////////////////////////////// +#define UART_FIFO_LEN 128 //define the tx fifo length +#define UART_TX_EMPTY_THRESH_VAL 0x10 + + + struct UartBuffer{ + uint32 UartBuffSize; + uint8 *pUartBuff; + uint8 *pInPos; + uint8 *pOutPos; + STATUS BuffState; + uint16 Space; //remanent space of the buffer + uint8 TcpControl; + struct UartBuffer * nextBuff; +}; + +struct UartRxBuff{ + uint32 UartRxBuffSize; + uint8 *pUartRxBuff; + uint8 *pWritePos; + uint8 *pReadPos; + STATUS RxBuffState; + uint32 Space; //remanent space of the buffer +} ; + +typedef enum { + RUN = 0, + BLOCK = 1, +} TCPState; + +//void ICACHE_FLASH_ATTR uart_test_rx(); +STATUS uart_tx_one_char(uint8 uart, uint8 TxChar); +STATUS uart_tx_one_char_no_wait(uint8 uart, uint8 TxChar); +void uart1_sendStr_no_wait(const char *str); +struct UartBuffer* Uart_Buf_Init(); + + +#if UART_BUFF_EN +LOCAL void Uart_Buf_Cpy(struct UartBuffer* pCur, char* pdata , uint16 data_len); +void uart_buf_free(struct UartBuffer* pBuff); +void tx_buff_enq(char* pdata, uint16 data_len ); +LOCAL void tx_fifo_insert(struct UartBuffer* pTxBuff, uint8 data_len, uint8 uart_no); +void tx_start_uart_buffer(uint8 uart_no); +uint16 rx_buff_deq(char* pdata, uint16 data_len ); +void Uart_rx_buff_enq(); +#endif +void uart_rx_intr_enable(uint8 uart_no); +void uart_rx_intr_disable(uint8 uart_no); +void uart0_tx_buffer(uint8 *buf, uint16 len); + +//============================================== +#define FUNC_UART0_CTS 4 +#define FUNC_U0CTS 4 +#define FUNC_U1TXD_BK 2 +#define UART_LINE_INV_MASK (0x3f<<19) +void UART_SetWordLength(uint8 uart_no, UartBitsNum4Char len); +void UART_SetStopBits(uint8 uart_no, UartStopBitsNum bit_num); +void UART_SetLineInverse(uint8 uart_no, UART_LineLevelInverse inverse_mask); +void UART_SetParity(uint8 uart_no, UartParityMode Parity_mode); +void UART_SetBaudrate(uint8 uart_no,uint32 baud_rate); +void UART_SetFlowCtrl(uint8 uart_no,UART_HwFlowCtrl flow_ctrl,uint8 rx_thresh); +void UART_WaitTxFifoEmpty(uint8 uart_no , uint32 time_out_us); //do not use if tx flow control enabled +void UART_ResetFifo(uint8 uart_no); +void UART_ClearIntrStatus(uint8 uart_no,uint32 clr_mask); +void UART_SetIntrEna(uint8 uart_no,uint32 ena_mask); +void UART_SetPrintPort(uint8 uart_no); +bool UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us); +//============================================== + +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/include/driver/uart_register.h b/esp_iot_sdk_v1.3.0/examples/driver_lib/include/driver/uart_register.h new file mode 100644 index 0000000..05f6cea --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/include/driver/uart_register.h @@ -0,0 +1,156 @@ +/* + * File : uart_register.h + * Copyright (C) 2013 - 2016, Espressif Systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of version 3 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +/* + * Copyright (c) 2010 - 2011 Espressif System + * + */ + +#ifndef UART_REGISTER_H_ +#define UART_REGISTER_H_ + +#define REG_UART_BASE(i) (0x60000000 + (i)*0xf00) +//version value:32'h062000 + +#define UART_FIFO(i) (REG_UART_BASE(i) + 0x0) +#define UART_RXFIFO_RD_BYTE 0x000000FF +#define UART_RXFIFO_RD_BYTE_S 0 + +#define UART_INT_RAW(i) (REG_UART_BASE(i) + 0x4) +#define UART_RXFIFO_TOUT_INT_RAW (BIT(8)) +#define UART_BRK_DET_INT_RAW (BIT(7)) +#define UART_CTS_CHG_INT_RAW (BIT(6)) +#define UART_DSR_CHG_INT_RAW (BIT(5)) +#define UART_RXFIFO_OVF_INT_RAW (BIT(4)) +#define UART_FRM_ERR_INT_RAW (BIT(3)) +#define UART_PARITY_ERR_INT_RAW (BIT(2)) +#define UART_TXFIFO_EMPTY_INT_RAW (BIT(1)) +#define UART_RXFIFO_FULL_INT_RAW (BIT(0)) + +#define UART_INT_ST(i) (REG_UART_BASE(i) + 0x8) +#define UART_RXFIFO_TOUT_INT_ST (BIT(8)) +#define UART_BRK_DET_INT_ST (BIT(7)) +#define UART_CTS_CHG_INT_ST (BIT(6)) +#define UART_DSR_CHG_INT_ST (BIT(5)) +#define UART_RXFIFO_OVF_INT_ST (BIT(4)) +#define UART_FRM_ERR_INT_ST (BIT(3)) +#define UART_PARITY_ERR_INT_ST (BIT(2)) +#define UART_TXFIFO_EMPTY_INT_ST (BIT(1)) +#define UART_RXFIFO_FULL_INT_ST (BIT(0)) + +#define UART_INT_ENA(i) (REG_UART_BASE(i) + 0xC) +#define UART_RXFIFO_TOUT_INT_ENA (BIT(8)) +#define UART_BRK_DET_INT_ENA (BIT(7)) +#define UART_CTS_CHG_INT_ENA (BIT(6)) +#define UART_DSR_CHG_INT_ENA (BIT(5)) +#define UART_RXFIFO_OVF_INT_ENA (BIT(4)) +#define UART_FRM_ERR_INT_ENA (BIT(3)) +#define UART_PARITY_ERR_INT_ENA (BIT(2)) +#define UART_TXFIFO_EMPTY_INT_ENA (BIT(1)) +#define UART_RXFIFO_FULL_INT_ENA (BIT(0)) + +#define UART_INT_CLR(i) (REG_UART_BASE(i) + 0x10) +#define UART_RXFIFO_TOUT_INT_CLR (BIT(8)) +#define UART_BRK_DET_INT_CLR (BIT(7)) +#define UART_CTS_CHG_INT_CLR (BIT(6)) +#define UART_DSR_CHG_INT_CLR (BIT(5)) +#define UART_RXFIFO_OVF_INT_CLR (BIT(4)) +#define UART_FRM_ERR_INT_CLR (BIT(3)) +#define UART_PARITY_ERR_INT_CLR (BIT(2)) +#define UART_TXFIFO_EMPTY_INT_CLR (BIT(1)) +#define UART_RXFIFO_FULL_INT_CLR (BIT(0)) + +#define UART_CLKDIV(i) (REG_UART_BASE(i) + 0x14) +#define UART_CLKDIV_CNT 0x000FFFFF +#define UART_CLKDIV_S 0 + +#define UART_AUTOBAUD(i) (REG_UART_BASE(i) + 0x18) +#define UART_GLITCH_FILT 0x000000FF +#define UART_GLITCH_FILT_S 8 +#define UART_AUTOBAUD_EN (BIT(0)) + +#define UART_STATUS(i) (REG_UART_BASE(i) + 0x1C) +#define UART_TXD (BIT(31)) +#define UART_RTSN (BIT(30)) +#define UART_DTRN (BIT(29)) +#define UART_TXFIFO_CNT 0x000000FF +#define UART_TXFIFO_CNT_S 16 +#define UART_RXD (BIT(15)) +#define UART_CTSN (BIT(14)) +#define UART_DSRN (BIT(13)) +#define UART_RXFIFO_CNT 0x000000FF +#define UART_RXFIFO_CNT_S 0 + +#define UART_CONF0(i) (REG_UART_BASE(i) + 0x20) +#define UART_DTR_INV (BIT(24)) +#define UART_RTS_INV (BIT(23)) +#define UART_TXD_INV (BIT(22)) +#define UART_DSR_INV (BIT(21)) +#define UART_CTS_INV (BIT(20)) +#define UART_RXD_INV (BIT(19)) +#define UART_TXFIFO_RST (BIT(18)) +#define UART_RXFIFO_RST (BIT(17)) +#define UART_IRDA_EN (BIT(16)) +#define UART_TX_FLOW_EN (BIT(15)) +#define UART_LOOPBACK (BIT(14)) +#define UART_IRDA_RX_INV (BIT(13)) +#define UART_IRDA_TX_INV (BIT(12)) +#define UART_IRDA_WCTL (BIT(11)) +#define UART_IRDA_TX_EN (BIT(10)) +#define UART_IRDA_DPLX (BIT(9)) +#define UART_TXD_BRK (BIT(8)) +#define UART_SW_DTR (BIT(7)) +#define UART_SW_RTS (BIT(6)) +#define UART_STOP_BIT_NUM 0x00000003 +#define UART_STOP_BIT_NUM_S 4 +#define UART_BIT_NUM 0x00000003 +#define UART_BIT_NUM_S 2 +#define UART_PARITY_EN (BIT(1)) +#define UART_PARITY_EN_M 0x00000001 +#define UART_PARITY_EN_S 1 +#define UART_PARITY (BIT(0)) +#define UART_PARITY_M 0x00000001 +#define UART_PARITY_S 0 + +#define UART_CONF1(i) (REG_UART_BASE(i) + 0x24) +#define UART_RX_TOUT_EN (BIT(31)) +#define UART_RX_TOUT_THRHD 0x0000007F +#define UART_RX_TOUT_THRHD_S 24 +#define UART_RX_FLOW_EN (BIT(23)) +#define UART_RX_FLOW_THRHD 0x0000007F +#define UART_RX_FLOW_THRHD_S 16 +#define UART_TXFIFO_EMPTY_THRHD 0x0000007F +#define UART_TXFIFO_EMPTY_THRHD_S 8 +#define UART_RXFIFO_FULL_THRHD 0x0000007F +#define UART_RXFIFO_FULL_THRHD_S 0 + +#define UART_LOWPULSE(i) (REG_UART_BASE(i) + 0x28) +#define UART_LOWPULSE_MIN_CNT 0x000FFFFF +#define UART_LOWPULSE_MIN_CNT_S 0 + +#define UART_HIGHPULSE(i) (REG_UART_BASE(i) + 0x2C) +#define UART_HIGHPULSE_MIN_CNT 0x000FFFFF +#define UART_HIGHPULSE_MIN_CNT_S 0 + +#define UART_PULSE_NUM(i) (REG_UART_BASE(i) + 0x30) +#define UART_PULSE_NUM_CNT 0x0003FF +#define UART_PULSE_NUM_CNT_S 0 + +#define UART_DATE(i) (REG_UART_BASE(i) + 0x78) +#define UART_ID(i) (REG_UART_BASE(i) + 0x7C) + +#endif // UART_REGISTER_H_INCLUDED + diff --git a/esp_iot_sdk_v1.3.0/examples/driver_lib/readme.txt b/esp_iot_sdk_v1.3.0/examples/driver_lib/readme.txt new file mode 100644 index 0000000..460d458 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/driver_lib/readme.txt @@ -0,0 +1,12 @@ +STEP 1: Copy driver and include folders to your project sub-folder, such as app folder. Unused drivers can be removed in your project. + +STEP 2: Modify Makefile in app folder. + 1). Search SUBDIRS, add driver as subdir: + SUBDIRS= \ + user \ + driver + + 2). Search COMPONENTS_eagle.app.v6, add libdriver.a: + COMPONENTS_eagle.app.v6 = \ + user/libuser.a \ + driver/libdriver.a \ No newline at end of file diff --git a/esp_iot_sdk_v1.3.0/examples/readme.txt b/esp_iot_sdk_v1.3.0/examples/readme.txt new file mode 100644 index 0000000..99f4554 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/readme.txt @@ -0,0 +1,40 @@ +1¡¢compile options + +(1) COMPILE + Possible value: gcc + Default value: + If not set, use xt-xcc by default. + +(2) BOOT + Possible value: none/old/new + none: no need boot + old: use boot_v1.1 + new: use boot_v1.2+ + Default value: none + +(3) APP + Possible value: 0/1/2 + 0: original mode, generate eagle.app.v6.flash.bin and eagle.app.v6.irom0text.bin + 1: generate user1 + 2: generate user2 + Default value: 0 + +(3) SPI_SPEED + Possible value: 20/26.7/40/80 + Default value: 40 + +(4) SPI_MODE + Possible value: QIO/QOUT/DIO/DOUT + Default value: QIO + +(4) SPI_SIZE_MAP + Possible value: 0/2/3/4/5/6 + Default value: 0 + +For example: + make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=0 + +2¡¢You can also use gen_misc to make and generate specific bin you needed. + Linux: ./gen_misc.sh + Windows: gen_misc.bat + Follow the tips and steps. \ No newline at end of file diff --git a/esp_iot_sdk_v1.3.0/examples/smart_config/Makefile b/esp_iot_sdk_v1.3.0/examples/smart_config/Makefile new file mode 100644 index 0000000..3e59c83 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/smart_config/Makefile @@ -0,0 +1,122 @@ +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of object file images to be generated () +# GEN_BINS - list of binaries to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +TARGET = eagle +#FLAVOR = release +FLAVOR = debug + +#EXTRA_CCFLAGS += -u + +ifndef PDIR # { +GEN_IMAGES= eagle.app.v6.out +GEN_BINS= eagle.app.v6.bin +SPECIAL_MKTARGETS=$(APP_MKTARGETS) +SUBDIRS= \ + user + +endif # } PDIR + +APPDIR = . +LDDIR = ../ld + +CCFLAGS += -Os + +TARGET_LDFLAGS = \ + -nostdlib \ + -Wl,-EL \ + --longcalls \ + --text-section-literals + +ifeq ($(FLAVOR),debug) + TARGET_LDFLAGS += -g -O2 +endif + +ifeq ($(FLAVOR),release) + TARGET_LDFLAGS += -g -O0 +endif + +COMPONENTS_eagle.app.v6 = \ + user/libuser.a + +LINKFLAGS_eagle.app.v6 = \ + -L../lib \ + -nostdlib \ + -T$(LD_FILE) \ + -Wl,--no-check-sections \ + -u call_user_start \ + -Wl,-static \ + -Wl,--start-group \ + -lc \ + -lgcc \ + -lhal \ + -lphy \ + -lpp \ + -lnet80211 \ + -llwip \ + -lwpa \ + -lmain \ + -ljson \ + -lssl \ + -lupgrade \ + -lsmartconfig \ + $(DEP_LIBS_eagle.app.v6) \ + -Wl,--end-group + +DEPENDS_eagle.app.v6 = \ + $(LD_FILE) \ + $(LDDIR)/eagle.rom.addr.v6.ld + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# + +#UNIVERSAL_TARGET_DEFINES = \ + +# Other potential configuration flags include: +# -DTXRX_TXBUF_DEBUG +# -DTXRX_RXBUF_DEBUG +# -DWLAN_CONFIG_CCX +CONFIGURATION_DEFINES = -DICACHE_FLASH + +DEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + +DDEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + +.PHONY: FORCE +FORCE: + diff --git a/esp_iot_sdk_v1.3.0/examples/smart_config/gen_misc.bat b/esp_iot_sdk_v1.3.0/examples/smart_config/gen_misc.bat new file mode 100644 index 0000000..8856e66 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/smart_config/gen_misc.bat @@ -0,0 +1,147 @@ +@echo off + +echo gen_misc.bat version 20150511 +echo . + +echo Please follow below steps(1-5) to generate specific bin(s): +echo STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none) +set input=default +set /p input=enter(0/1/2, default 2): + +if %input% equ 0 ( + set boot=old +) else ( +if %input% equ 1 ( + set boot=new +) else ( + set boot=none +) +) + +echo boot mode: %boot% +echo. + +echo STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin) +set input=default +set /p input=enter (0/1/2, default 0): + +if %input% equ 1 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=1 + echo generate bin: user1.bin + ) +) else ( +if %input% equ 2 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=2 + echo generate bin: user2.bin + ) +) else ( + if %boot% neq none ( + set boot=none + echo ignore boot + ) + set app=0 + echo generate bin: eagle.flash.bin+eagle.irom0text.bin +)) + +echo. + +echo STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz) +set input=default +set /p input=enter (0/1/2/3, default 2): + +if %input% equ 0 ( + set spi_speed=20 +) else ( +if %input% equ 1 ( + set spi_speed=26.7 +) else ( +if %input% equ 3 ( + set spi_speed=80 +) else ( + set spi_speed=40 +))) + +echo spi speed: %spi_speed% MHz +echo. + +echo STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT) +set input=default +set /p input=enter (0/1/2/3, default 0): + +if %input% equ 1 ( + set spi_mode=QOUT +) else ( +if %input% equ 2 ( + set spi_mode=DIO +) else ( +if %input% equ 3 ( + set spi_mode=DOUT +) else ( + set spi_mode=QIO +))) + +echo spi mode: %spi_mode% +echo. + +echo STEP 5: choose flash 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) +set input=default +set /p input=enter (0/1/2/3/4/5/6, default 0): + +if %input% equ 2 ( + set spi_size_map=2 + echo spi size: 1024KB + echo spi ota map: 512KB + 512KB +) else ( + if %input% equ 3 ( + set spi_size_map=3 + echo spi size: 2048KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 4 ( + set spi_size_map=4 + echo spi size: 4096KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 5 ( + set spi_size_map=5 + echo spi size: 2048KB + echo spi ota map: 1024KB + 1024KB + ) else ( + if %input% equ 6 ( + set spi_size_map=6 + echo spi size: 4096KB + echo spi ota map: 1024KB + 1024KB + ) else ( + set spi_size_map=0 + echo spi size: 512KB + echo spi ota map: 256KB + 256KB + ) + ) + ) + ) +) + +touch user/user_main.c + +echo. +echo start... +echo. + +make BOOT=%boot% APP=%app% SPI_SPEED=%spi_speed% SPI_MODE=%spi_mode% SPI_SIZE=%spi_size_map% + diff --git a/esp_iot_sdk_v1.3.0/examples/smart_config/gen_misc.sh b/esp_iot_sdk_v1.3.0/examples/smart_config/gen_misc.sh new file mode 100644 index 0000000..1612cd9 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/smart_config/gen_misc.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +echo "gen_misc.sh version 20150511" +echo "" + +echo "Please follow below steps(1-5) to generate specific bin(s):" +echo "STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none)" +echo "enter(0/1/2, default 2):" +read input + +if [ -z "$input" ]; then + boot=none +elif [ $input == 0 ]; then + boot=old +elif [ $input == 1 ]; then + boot=new +else + boot=none +fi + +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 "" + +touch user/user_main.c + +echo "" +echo "start..." +echo "" + +make COMPILE=gcc BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map diff --git a/esp_iot_sdk_v1.3.0/examples/smart_config/include/user_config.h b/esp_iot_sdk_v1.3.0/examples/smart_config/include/user_config.h new file mode 100644 index 0000000..cca256b --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/smart_config/include/user_config.h @@ -0,0 +1,5 @@ +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/smart_config/user/Makefile b/esp_iot_sdk_v1.3.0/examples/smart_config/user/Makefile new file mode 100644 index 0000000..5795e20 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/smart_config/user/Makefile @@ -0,0 +1,45 @@ + +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of images to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +ifndef PDIR +GEN_LIBS = libuser.a +endif + + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# +#DEFINES += + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I ./ +INCLUDES += -I ../../include/ets +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + diff --git a/esp_iot_sdk_v1.3.0/examples/smart_config/user/user_main.c b/esp_iot_sdk_v1.3.0/examples/smart_config/user/user_main.c new file mode 100644 index 0000000..8939fb3 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/smart_config/user/user_main.c @@ -0,0 +1,68 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_main.c + * + * Description: entry file of user application + * + * Modification history: + * 2014/1/1, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "osapi.h" + +#include "user_interface.h" +#include "smartconfig.h" + +void ICACHE_FLASH_ATTR +smartconfig_done(sc_status status, void *pdata) +{ + switch(status) { + case SC_STATUS_WAIT: + os_printf("SC_STATUS_WAIT\n"); + break; + case SC_STATUS_FIND_CHANNEL: + os_printf("SC_STATUS_FIND_CHANNEL\n"); + break; + case SC_STATUS_GETTING_SSID_PSWD: + os_printf("SC_STATUS_GETTING_SSID_PSWD\n"); + sc_type *type = pdata; + if (*type == SC_TYPE_ESPTOUCH) { + os_printf("SC_TYPE:SC_TYPE_ESPTOUCH\n"); + } else { + os_printf("SC_TYPE:SC_TYPE_AIRKISS\n"); + } + break; + case SC_STATUS_LINK: + os_printf("SC_STATUS_LINK\n"); + struct station_config *sta_conf = pdata; + + wifi_station_set_config(sta_conf); + wifi_station_disconnect(); + wifi_station_connect(); + break; + case SC_STATUS_LINK_OVER: + os_printf("SC_STATUS_LINK_OVER\n"); + if (pdata != NULL) { + uint8 phone_ip[4] = {0}; + + os_memcpy(phone_ip, (uint8*)pdata, 4); + os_printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]); + } + smartconfig_stop(); + break; + } + +} + +void user_rf_pre_init(void) +{ +} + +void user_init(void) +{ + os_printf("SDK version:%s\n", system_get_sdk_version()); + + wifi_set_opmode(STATION_MODE); + smartconfig_start(smartconfig_done); +} diff --git a/esp_iot_sdk_v1.3.0/examples/wps/Makefile b/esp_iot_sdk_v1.3.0/examples/wps/Makefile new file mode 100644 index 0000000..ac9c11b --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/wps/Makefile @@ -0,0 +1,122 @@ +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of object file images to be generated () +# GEN_BINS - list of binaries to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +TARGET = eagle +#FLAVOR = release +FLAVOR = debug + +#EXTRA_CCFLAGS += -u + +ifndef PDIR # { +GEN_IMAGES= eagle.app.v6.out +GEN_BINS= eagle.app.v6.bin +SPECIAL_MKTARGETS=$(APP_MKTARGETS) +SUBDIRS= \ + user \ + driver + +endif # } PDIR + +APPDIR = . +LDDIR = ../ld + +CCFLAGS += -Os + +TARGET_LDFLAGS = \ + -nostdlib \ + -Wl,-EL \ + --longcalls \ + --text-section-literals + +ifeq ($(FLAVOR),debug) + TARGET_LDFLAGS += -g -O2 +endif + +ifeq ($(FLAVOR),release) + TARGET_LDFLAGS += -g -O0 +endif + +COMPONENTS_eagle.app.v6 = \ + user/libuser.a \ + driver/libdriver.a + +LINKFLAGS_eagle.app.v6 = \ + -L../lib \ + -nostdlib \ + -T$(LD_FILE) \ + -Wl,--no-check-sections \ + -u call_user_start \ + -Wl,-static \ + -Wl,--start-group \ + -lc \ + -lgcc \ + -lhal \ + -lphy \ + -lpp \ + -lnet80211 \ + -llwip \ + -lwpa \ + -lmain \ + -lwps \ + -lcrypto \ + $(DEP_LIBS_eagle.app.v6) \ + -Wl,--end-group + +DEPENDS_eagle.app.v6 = \ + $(LD_FILE) \ + $(LDDIR)/eagle.rom.addr.v6.ld + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# + +#UNIVERSAL_TARGET_DEFINES = \ + +# Other potential configuration flags include: +# -DTXRX_TXBUF_DEBUG +# -DTXRX_RXBUF_DEBUG +# -DWLAN_CONFIG_CCX +CONFIGURATION_DEFINES = -DICACHE_FLASH + +DEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + +DDEFINES += \ + $(UNIVERSAL_TARGET_DEFINES) \ + $(CONFIGURATION_DEFINES) + + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + +.PHONY: FORCE +FORCE: + diff --git a/esp_iot_sdk_v1.3.0/examples/wps/driver/Makefile b/esp_iot_sdk_v1.3.0/examples/wps/driver/Makefile new file mode 100644 index 0000000..ffdb4d0 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/wps/driver/Makefile @@ -0,0 +1,44 @@ + +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of images to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +ifndef PDIR +GEN_LIBS = libdriver.a +endif + + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# +#DEFINES += + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I ./ +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + diff --git a/esp_iot_sdk_v1.3.0/examples/wps/driver/key.c b/esp_iot_sdk_v1.3.0/examples/wps/driver/key.c new file mode 100644 index 0000000..1b2d0df --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/wps/driver/key.c @@ -0,0 +1,162 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: key.c + * + * Description: key driver, now can use different gpio and install different function + * + * Modification history: + * 2014/5/1, v1.0 create this file. +*******************************************************************************/ +#include "ets_sys.h" +#include "os_type.h" +#include "osapi.h" +#include "mem.h" +#include "gpio.h" +#include "user_interface.h" + +#include "driver/key.h" + +LOCAL void key_intr_handler(struct keys_param *keys); + +/****************************************************************************** + * FunctionName : key_init_single + * Description : init single key's gpio and register function + * Parameters : uint8 gpio_id - which gpio to use + * uint32 gpio_name - gpio mux name + * uint32 gpio_func - gpio function + * key_function long_press - long press function, needed to install + * key_function short_press - short press function, needed to install + * Returns : single_key_param - single key parameter, needed by key init +*******************************************************************************/ +struct single_key_param *ICACHE_FLASH_ATTR +key_init_single(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func, key_function long_press, key_function short_press) +{ + struct single_key_param *single_key = (struct single_key_param *)os_zalloc(sizeof(struct single_key_param)); + + single_key->gpio_id = gpio_id; + single_key->gpio_name = gpio_name; + single_key->gpio_func = gpio_func; + single_key->long_press = long_press; + single_key->short_press = short_press; + + return single_key; +} + +/****************************************************************************** + * FunctionName : key_init + * Description : init keys + * Parameters : key_param *keys - keys parameter, which inited by key_init_single + * Returns : none +*******************************************************************************/ +void ICACHE_FLASH_ATTR +key_init(struct keys_param *keys) +{ + uint8 i; + + ETS_GPIO_INTR_ATTACH(key_intr_handler, keys); + + ETS_GPIO_INTR_DISABLE(); + + for (i = 0; i < keys->key_num; i++) { + keys->single_key[i]->key_level = 1; + + PIN_FUNC_SELECT(keys->single_key[i]->gpio_name, keys->single_key[i]->gpio_func); + + gpio_output_set(0, 0, 0, GPIO_ID_PIN(keys->single_key[i]->gpio_id)); + + gpio_register_set(GPIO_PIN_ADDR(keys->single_key[i]->gpio_id), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) + | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) + | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)); + + //clear gpio14 status + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(keys->single_key[i]->gpio_id)); + + //enable interrupt + gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_NEGEDGE); + } + + ETS_GPIO_INTR_ENABLE(); +} + +/****************************************************************************** + * FunctionName : key_5s_cb + * Description : long press 5s timer callback + * Parameters : single_key_param *single_key - single key parameter + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +key_5s_cb(struct single_key_param *single_key) +{ + os_timer_disarm(&single_key->key_5s); + + // low, then restart + if (0 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { + if (single_key->long_press) { + single_key->long_press(); + } + } +} + +/****************************************************************************** + * FunctionName : key_50ms_cb + * Description : 50ms timer callback to check it's a real key push + * Parameters : single_key_param *single_key - single key parameter + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +key_50ms_cb(struct single_key_param *single_key) +{ + os_timer_disarm(&single_key->key_50ms); + + // high, then key is up + if (1 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { + os_timer_disarm(&single_key->key_5s); + single_key->key_level = 1; + gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_NEGEDGE); + + if (single_key->short_press) { + single_key->short_press(); + } + } else { + gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_POSEDGE); + } +} + +/****************************************************************************** + * FunctionName : key_intr_handler + * Description : key interrupt handler + * Parameters : key_param *keys - keys parameter, which inited by key_init_single + * Returns : none +*******************************************************************************/ +LOCAL void +key_intr_handler(struct keys_param *keys) +{ + uint8 i; + uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); + + for (i = 0; i < keys->key_num; i++) { + if (gpio_status & BIT(keys->single_key[i]->gpio_id)) { + //disable interrupt + gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_DISABLE); + + //clear interrupt status + GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(keys->single_key[i]->gpio_id)); + + if (keys->single_key[i]->key_level == 1) { + // 5s, restart & enter softap mode + os_timer_disarm(&keys->single_key[i]->key_5s); + os_timer_setfn(&keys->single_key[i]->key_5s, (os_timer_func_t *)key_5s_cb, keys->single_key[i]); + os_timer_arm(&keys->single_key[i]->key_5s, 5000, 0); + keys->single_key[i]->key_level = 0; + gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_POSEDGE); + } else { + // 50ms, check if this is a real key up + os_timer_disarm(&keys->single_key[i]->key_50ms); + os_timer_setfn(&keys->single_key[i]->key_50ms, (os_timer_func_t *)key_50ms_cb, keys->single_key[i]); + os_timer_arm(&keys->single_key[i]->key_50ms, 50, 0); + } + } + } +} + diff --git a/esp_iot_sdk_v1.3.0/examples/wps/gen_misc.bat b/esp_iot_sdk_v1.3.0/examples/wps/gen_misc.bat new file mode 100644 index 0000000..8856e66 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/wps/gen_misc.bat @@ -0,0 +1,147 @@ +@echo off + +echo gen_misc.bat version 20150511 +echo . + +echo Please follow below steps(1-5) to generate specific bin(s): +echo STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none) +set input=default +set /p input=enter(0/1/2, default 2): + +if %input% equ 0 ( + set boot=old +) else ( +if %input% equ 1 ( + set boot=new +) else ( + set boot=none +) +) + +echo boot mode: %boot% +echo. + +echo STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin) +set input=default +set /p input=enter (0/1/2, default 0): + +if %input% equ 1 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=1 + echo generate bin: user1.bin + ) +) else ( +if %input% equ 2 ( + if %boot% equ none ( + set app=0 + echo choose no boot before + echo generate bin: eagle.flash.bin+eagle.irom0text.bin + ) else ( + set app=2 + echo generate bin: user2.bin + ) +) else ( + if %boot% neq none ( + set boot=none + echo ignore boot + ) + set app=0 + echo generate bin: eagle.flash.bin+eagle.irom0text.bin +)) + +echo. + +echo STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz) +set input=default +set /p input=enter (0/1/2/3, default 2): + +if %input% equ 0 ( + set spi_speed=20 +) else ( +if %input% equ 1 ( + set spi_speed=26.7 +) else ( +if %input% equ 3 ( + set spi_speed=80 +) else ( + set spi_speed=40 +))) + +echo spi speed: %spi_speed% MHz +echo. + +echo STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT) +set input=default +set /p input=enter (0/1/2/3, default 0): + +if %input% equ 1 ( + set spi_mode=QOUT +) else ( +if %input% equ 2 ( + set spi_mode=DIO +) else ( +if %input% equ 3 ( + set spi_mode=DOUT +) else ( + set spi_mode=QIO +))) + +echo spi mode: %spi_mode% +echo. + +echo STEP 5: choose flash 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) +set input=default +set /p input=enter (0/1/2/3/4/5/6, default 0): + +if %input% equ 2 ( + set spi_size_map=2 + echo spi size: 1024KB + echo spi ota map: 512KB + 512KB +) else ( + if %input% equ 3 ( + set spi_size_map=3 + echo spi size: 2048KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 4 ( + set spi_size_map=4 + echo spi size: 4096KB + echo spi ota map: 512KB + 512KB + ) else ( + if %input% equ 5 ( + set spi_size_map=5 + echo spi size: 2048KB + echo spi ota map: 1024KB + 1024KB + ) else ( + if %input% equ 6 ( + set spi_size_map=6 + echo spi size: 4096KB + echo spi ota map: 1024KB + 1024KB + ) else ( + set spi_size_map=0 + echo spi size: 512KB + echo spi ota map: 256KB + 256KB + ) + ) + ) + ) +) + +touch user/user_main.c + +echo. +echo start... +echo. + +make BOOT=%boot% APP=%app% SPI_SPEED=%spi_speed% SPI_MODE=%spi_mode% SPI_SIZE=%spi_size_map% + diff --git a/esp_iot_sdk_v1.3.0/examples/wps/gen_misc.sh b/esp_iot_sdk_v1.3.0/examples/wps/gen_misc.sh new file mode 100644 index 0000000..1612cd9 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/wps/gen_misc.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +echo "gen_misc.sh version 20150511" +echo "" + +echo "Please follow below steps(1-5) to generate specific bin(s):" +echo "STEP 1: choose boot version(0=boot_v1.1, 1=boot_v1.2+, 2=none)" +echo "enter(0/1/2, default 2):" +read input + +if [ -z "$input" ]; then + boot=none +elif [ $input == 0 ]; then + boot=old +elif [ $input == 1 ]; then + boot=new +else + boot=none +fi + +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 "" + +touch user/user_main.c + +echo "" +echo "start..." +echo "" + +make COMPILE=gcc BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map diff --git a/esp_iot_sdk_v1.3.0/examples/wps/include/driver/key.h b/esp_iot_sdk_v1.3.0/examples/wps/include/driver/key.h new file mode 100644 index 0000000..09c8e16 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/wps/include/driver/key.h @@ -0,0 +1,27 @@ +#ifndef __KEY_H__ +#define __KEY_H__ + +#include "gpio.h" + +typedef void (* key_function)(void); + +struct single_key_param { + uint8 key_level; + uint8 gpio_id; + uint8 gpio_func; + uint32 gpio_name; + os_timer_t key_5s; + os_timer_t key_50ms; + key_function short_press; + key_function long_press; +}; + +struct keys_param { + uint8 key_num; + struct single_key_param **single_key; +}; + +struct single_key_param *key_init_single(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func, key_function long_press, key_function short_press); +void key_init(struct keys_param *key); + +#endif diff --git a/esp_iot_sdk_v1.3.0/examples/wps/include/user_config.h b/esp_iot_sdk_v1.3.0/examples/wps/include/user_config.h new file mode 100644 index 0000000..cca256b --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/wps/include/user_config.h @@ -0,0 +1,5 @@ +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +#endif + diff --git a/esp_iot_sdk_v1.3.0/examples/wps/user/Makefile b/esp_iot_sdk_v1.3.0/examples/wps/user/Makefile new file mode 100644 index 0000000..639fe9b --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/wps/user/Makefile @@ -0,0 +1,45 @@ + +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of images to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +ifndef PDIR +GEN_LIBS = libuser.a +endif + + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# +#DEFINES += + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I ./ +INCLUDES += -I ../../include/ets +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + diff --git a/esp_iot_sdk_v1.3.0/examples/wps/user/user_main.c b/esp_iot_sdk_v1.3.0/examples/wps/user/user_main.c new file mode 100644 index 0000000..d4f546f --- /dev/null +++ b/esp_iot_sdk_v1.3.0/examples/wps/user/user_main.c @@ -0,0 +1,67 @@ +/****************************************************************************** + * Copyright 2013-2014 Espressif Systems (Wuxi) + * + * FileName: user_main.c + * + * Description: entry file of user application + * + * Modification history: + * 2015/7/3, v1.0 create this file. +*******************************************************************************/ + +#include "osapi.h" +#include "user_interface.h" + +#include "driver/key.h" + +#define WPS_KEY_NUM 1 + +#define WPS_KEY_IO_MUX PERIPHS_IO_MUX_MTCK_U +#define WPS_KEY_IO_NUM 13 +#define WPS_KEY_IO_FUNC FUNC_GPIO13 + +LOCAL struct keys_param keys; +LOCAL struct single_key_param *single_key; + +LOCAL void ICACHE_FLASH_ATTR +user_wps_status_cb(int status) +{ + switch (status) { + case WPS_CB_ST_SUCCESS: + wifi_wps_disable(); + wifi_station_connect(); + break; + case WPS_CB_ST_FAILED: + case WPS_CB_ST_TIMEOUT: + wifi_wps_start(); + break; + } +} + +LOCAL void ICACHE_FLASH_ATTR +user_wps_key_short_press(void) +{ + wifi_wps_disable(); + wifi_wps_enable(WPS_TYPE_PBC); + wifi_set_wps_cb(user_wps_status_cb); + wifi_wps_start(); +} + +void ICACHE_FLASH_ATTR +user_rf_pre_init(void) +{ +} + +void ICACHE_FLASH_ATTR +user_init(void) +{ + single_key = key_init_single(WPS_KEY_IO_NUM, WPS_KEY_IO_MUX, WPS_KEY_IO_FUNC, + NULL, user_wps_key_short_press); + + keys.key_num = WPS_KEY_NUM; + keys.single_key = &single_key; + + key_init(&keys); + + wifi_set_opmode(STATION_MODE); +} diff --git a/esp_iot_sdk_v1.3.0/include/at_custom.h b/esp_iot_sdk_v1.3.0/include/at_custom.h new file mode 100644 index 0000000..59f1a57 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/at_custom.h @@ -0,0 +1,143 @@ + +/* + * custom_at.h + * + * This file is part of Espressif's AT+ command set program. + * Copyright (C) 2013 - 2016, Espressif Systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of version 3 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef CUSTOM_AT_H_ +#define CUSTOM_AT_H_ + +#include "c_types.h" + +typedef struct +{ + char *at_cmdName; + int8_t at_cmdLen; + void (*at_testCmd)(uint8_t id); + void (*at_queryCmd)(uint8_t id); + void (*at_setupCmd)(uint8_t id, char *pPara); + void (*at_exeCmd)(uint8_t id); +}at_funcationType; + +typedef void (*at_custom_uart_rx_intr)(uint8* data,int32 len); + +typedef void (*at_custom_response_func_type)(const char *str); + +extern uint8 at_customLinkMax; + +/** + * @brief Response "OK" to uart. + * @param None + * @retval None + */ +void at_response_ok(void); +/** + * @brief Response "ERROR" to uart. + * @param None + * @retval None + */ +void at_response_error(void); +/** + * @brief Response string. + * It is equivalent to at_port_print,if not call at_register_response_func or call at_register_response_func(NULL); + * It will run custom response function,if call at_register_response_func and parameter is not NULL. + * @param string + * @retval None + */ +void at_response(const char *str); +/** + * @brief register custom response function. + * @param response_func: the function that will run when call at_response + * @retval None + */ +void at_register_response_func(at_custom_response_func_type response_func); +/** + * @brief Task of process command or txdata. + * @param custom_at_cmd_array: the array of at cmd that custom defined + * cmd_num : the num of at cmd that custom defined + * @retval None + */ +void at_cmd_array_regist(at_funcationType *custom_at_cmd_array,uint32 cmd_num); +/** + * @brief get digit form at cmd line.the maybe alter pSrc + * @param p_src: at cmd line string + * result:the buffer to be placed result + * err : err num + * @retval TRUE: + * FALSE: + */ +bool at_get_next_int_dec(char **p_src,int*result,int* err); +/** + * @brief get string form at cmd line.the maybe alter pSrc + * @param p_dest: the buffer to be placed result + * p_src: at cmd line string + * max_len :max len of string excepted to get + * @retval None + */ +int32 at_data_str_copy(char *p_dest, char **p_src, int32 max_len); + +/** + * @brief initialize at module + * @param None + * @retval None + */ +void at_init(void); +/** + * @brief print string to at port + * @param string + * @retval None + */ +void at_port_print(const char *str); +/** + * @brief print custom information when AT+GMR + * @param string + * @retval None + */ +void at_set_custom_info(char* info); +/** + * @brief if current at command is processing,you can call at_enter_special_state, + * then if other comamnd coming,it will return busy. + * @param None + * @retval None + */ +void at_enter_special_state(void); +/** + * @brief + * @param None + * @retval None + */ +void at_leave_special_state(void); +/** + * @brief get at version + * @param None + * @retval at version + * bit24~31: at main version + * bit23~16: at sub version + * bit15~8 : at test version + * bit7~0 : customized version + */ +uint32 at_get_version(void); + +/** + * @brief register custom uart rx interrupt function + * @param rx_func: custom uart rx interrupt function. + * If rx_func is non-void,when rx interrupt comming,it will call rx_func(data,len), + * data is the buffer of data,len is the length of data.Otherwise,it will run AT rx function. + * @retval None + */ +void at_register_uart_rx_intr(at_custom_uart_rx_intr rx_func); +#endif diff --git a/esp_iot_sdk_v1.3.0/include/c_types.h b/esp_iot_sdk_v1.3.0/include/c_types.h new file mode 100644 index 0000000..592a2dd --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/c_types.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2010 - 2011 Espressif System + * + */ + +#ifndef _C_TYPES_H_ +#define _C_TYPES_H_ + +typedef unsigned char uint8_t; +typedef signed char sint8_t; +typedef signed char int8_t; +typedef unsigned short uint16_t; +typedef signed short sint16_t; +typedef signed short int16_t; +typedef unsigned long uint32_t; +typedef signed long sint32_t; +typedef signed long int32_t; +typedef signed long long sint64_t; +typedef unsigned long long uint64_t; +typedef unsigned long long u_int64_t; +typedef float real32_t; +typedef double real64_t; + +typedef unsigned char uint8; +typedef unsigned char u8; +typedef signed char sint8; +typedef signed char int8; +typedef signed char s8; +typedef unsigned short uint16; +typedef unsigned short u16; +typedef signed short sint16; +typedef signed short s16; +typedef unsigned int uint32; +typedef unsigned int u_int; +typedef unsigned int u32; +typedef signed int sint32; +typedef signed int s32; +typedef int int32; +typedef signed long long sint64; +typedef unsigned long long uint64; +typedef unsigned long long u64; +typedef float real32; +typedef double real64; + +#define __le16 u16 + +typedef unsigned int size_t; + +#define __packed __attribute__((packed)) + +#define LOCAL static + +#ifndef NULL +#define NULL (void *)0 +#endif /* NULL */ + +/* probably should not put STATUS here */ +typedef enum { + OK = 0, + FAIL, + PENDING, + BUSY, + CANCEL, +} STATUS; + +#define BIT(nr) (1UL << (nr)) + +#define REG_SET_BIT(_r, _b) (*(volatile uint32_t*)(_r) |= (_b)) +#define REG_CLR_BIT(_r, _b) (*(volatile uint32_t*)(_r) &= ~(_b)) + +#define DMEM_ATTR __attribute__((section(".bss"))) +#define SHMEM_ATTR + +#ifdef ICACHE_FLASH +#define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text"))) +#define ICACHE_RODATA_ATTR __attribute__((section(".irom.text"))) +#else +#define ICACHE_FLASH_ATTR +#define ICACHE_RODATA_ATTR +#endif /* ICACHE_FLASH */ + +#ifndef __cplusplus +typedef unsigned char bool; +#define BOOL bool +#define true (1) +#define false (0) +#define TRUE true +#define FALSE false + + +#endif /* !__cplusplus */ + +#endif /* _C_TYPES_H_ */ diff --git a/esp_iot_sdk_v1.3.0/include/eagle_soc.h b/esp_iot_sdk_v1.3.0/include/eagle_soc.h new file mode 100644 index 0000000..c1d498a --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/eagle_soc.h @@ -0,0 +1,256 @@ +/* + * Copyright (c) Espressif System 2010 - 2012 + * + */ + +#ifndef _EAGLE_SOC_H_ +#define _EAGLE_SOC_H_ + +//Register Bits{{ +#define BIT31 0x80000000 +#define BIT30 0x40000000 +#define BIT29 0x20000000 +#define BIT28 0x10000000 +#define BIT27 0x08000000 +#define BIT26 0x04000000 +#define BIT25 0x02000000 +#define BIT24 0x01000000 +#define BIT23 0x00800000 +#define BIT22 0x00400000 +#define BIT21 0x00200000 +#define BIT20 0x00100000 +#define BIT19 0x00080000 +#define BIT18 0x00040000 +#define BIT17 0x00020000 +#define BIT16 0x00010000 +#define BIT15 0x00008000 +#define BIT14 0x00004000 +#define BIT13 0x00002000 +#define BIT12 0x00001000 +#define BIT11 0x00000800 +#define BIT10 0x00000400 +#define BIT9 0x00000200 +#define BIT8 0x00000100 +#define BIT7 0x00000080 +#define BIT6 0x00000040 +#define BIT5 0x00000020 +#define BIT4 0x00000010 +#define BIT3 0x00000008 +#define BIT2 0x00000004 +#define BIT1 0x00000002 +#define BIT0 0x00000001 +//}} + +//Registers Operation {{ +#define ETS_UNCACHED_ADDR(addr) (addr) +#define ETS_CACHED_ADDR(addr) (addr) + + +#define READ_PERI_REG(addr) (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) +#define WRITE_PERI_REG(addr, val) (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val) +#define CLEAR_PERI_REG_MASK(reg, mask) WRITE_PERI_REG((reg), (READ_PERI_REG(reg)&(~(mask)))) +#define SET_PERI_REG_MASK(reg, mask) WRITE_PERI_REG((reg), (READ_PERI_REG(reg)|(mask))) +#define GET_PERI_REG_BITS(reg, hipos,lowpos) ((READ_PERI_REG(reg)>>(lowpos))&((1<<((hipos)-(lowpos)+1))-1)) +#define SET_PERI_REG_BITS(reg,bit_map,value,shift) (WRITE_PERI_REG((reg),(READ_PERI_REG(reg)&(~((bit_map)<<(shift))))|((value)<<(shift)) )) +//}} + +//Periheral Clock {{ +#define CPU_CLK_FREQ 80*1000000 //unit: Hz +#define APB_CLK_FREQ CPU_CLK_FREQ +#define UART_CLK_FREQ APB_CLK_FREQ +#define TIMER_CLK_FREQ (APB_CLK_FREQ>>8) //divided by 256 +//}} + +//Peripheral device base address define{{ +#define PERIPHS_DPORT_BASEADDR 0x3ff00000 +#define PERIPHS_GPIO_BASEADDR 0x60000300 +#define PERIPHS_TIMER_BASEDDR 0x60000600 +#define PERIPHS_RTC_BASEADDR 0x60000700 +#define PERIPHS_IO_MUX 0x60000800 +//}} + +//Interrupt remap control registers define{{ +#define EDGE_INT_ENABLE_REG (PERIPHS_DPORT_BASEADDR+0x04) +#define TM1_EDGE_INT_ENABLE() SET_PERI_REG_MASK(EDGE_INT_ENABLE_REG, BIT1) +#define TM1_EDGE_INT_DISABLE() CLEAR_PERI_REG_MASK(EDGE_INT_ENABLE_REG, BIT1) +//}} + +//GPIO reg {{ +#define GPIO_REG_READ(reg) READ_PERI_REG(PERIPHS_GPIO_BASEADDR + reg) +#define GPIO_REG_WRITE(reg, val) WRITE_PERI_REG(PERIPHS_GPIO_BASEADDR + reg, val) +#define GPIO_OUT_ADDRESS 0x00 +#define GPIO_OUT_W1TS_ADDRESS 0x04 +#define GPIO_OUT_W1TC_ADDRESS 0x08 + +#define GPIO_ENABLE_ADDRESS 0x0c +#define GPIO_ENABLE_W1TS_ADDRESS 0x10 +#define GPIO_ENABLE_W1TC_ADDRESS 0x14 +#define GPIO_OUT_W1TC_DATA_MASK 0x0000ffff + +#define GPIO_IN_ADDRESS 0x18 + +#define GPIO_STATUS_ADDRESS 0x1c +#define GPIO_STATUS_W1TS_ADDRESS 0x20 +#define GPIO_STATUS_W1TC_ADDRESS 0x24 +#define GPIO_STATUS_INTERRUPT_MASK 0x0000ffff + +#define GPIO_RTC_CALIB_SYNC PERIPHS_GPIO_BASEADDR+0x6c +#define RTC_CALIB_START BIT31 //first write to zero, then to one to start +#define RTC_PERIOD_NUM_MASK 0x3ff //max 8ms +#define GPIO_RTC_CALIB_VALUE PERIPHS_GPIO_BASEADDR+0x70 +#define RTC_CALIB_RDY_S 31 //after measure, flag to one, when start from zero to one, turn to zero +#define RTC_CALIB_VALUE_MASK 0xfffff + +#define GPIO_PIN0_ADDRESS 0x28 + +#define GPIO_ID_PIN0 0 +#define GPIO_ID_PIN(n) (GPIO_ID_PIN0+(n)) +#define GPIO_LAST_REGISTER_ID GPIO_ID_PIN(15) +#define GPIO_ID_NONE 0xffffffff + +#define GPIO_PIN_COUNT 16 + +#define GPIO_PIN_CONFIG_MSB 12 +#define GPIO_PIN_CONFIG_LSB 11 +#define GPIO_PIN_CONFIG_MASK 0x00001800 +#define GPIO_PIN_CONFIG_GET(x) (((x) & GPIO_PIN_CONFIG_MASK) >> GPIO_PIN_CONFIG_LSB) +#define GPIO_PIN_CONFIG_SET(x) (((x) << GPIO_PIN_CONFIG_LSB) & GPIO_PIN_CONFIG_MASK) + +#define GPIO_WAKEUP_ENABLE 1 +#define GPIO_WAKEUP_DISABLE (~GPIO_WAKEUP_ENABLE) +#define GPIO_PIN_WAKEUP_ENABLE_MSB 10 +#define GPIO_PIN_WAKEUP_ENABLE_LSB 10 +#define GPIO_PIN_WAKEUP_ENABLE_MASK 0x00000400 +#define GPIO_PIN_WAKEUP_ENABLE_GET(x) (((x) & GPIO_PIN_WAKEUP_ENABLE_MASK) >> GPIO_PIN_WAKEUP_ENABLE_LSB) +#define GPIO_PIN_WAKEUP_ENABLE_SET(x) (((x) << GPIO_PIN_WAKEUP_ENABLE_LSB) & GPIO_PIN_WAKEUP_ENABLE_MASK) + +#define GPIO_PIN_INT_TYPE_MASK 0x380 +#define GPIO_PIN_INT_TYPE_MSB 9 +#define GPIO_PIN_INT_TYPE_LSB 7 +#define GPIO_PIN_INT_TYPE_GET(x) (((x) & GPIO_PIN_INT_TYPE_MASK) >> GPIO_PIN_INT_TYPE_LSB) +#define GPIO_PIN_INT_TYPE_SET(x) (((x) << GPIO_PIN_INT_TYPE_LSB) & GPIO_PIN_INT_TYPE_MASK) + +#define GPIO_PAD_DRIVER_ENABLE 1 +#define GPIO_PAD_DRIVER_DISABLE (~GPIO_PAD_DRIVER_ENABLE) +#define GPIO_PIN_PAD_DRIVER_MSB 2 +#define GPIO_PIN_PAD_DRIVER_LSB 2 +#define GPIO_PIN_PAD_DRIVER_MASK 0x00000004 +#define GPIO_PIN_PAD_DRIVER_GET(x) (((x) & GPIO_PIN_PAD_DRIVER_MASK) >> GPIO_PIN_PAD_DRIVER_LSB) +#define GPIO_PIN_PAD_DRIVER_SET(x) (((x) << GPIO_PIN_PAD_DRIVER_LSB) & GPIO_PIN_PAD_DRIVER_MASK) + +#define GPIO_AS_PIN_SOURCE 0 +#define SIGMA_AS_PIN_SOURCE (~GPIO_AS_PIN_SOURCE) +#define GPIO_PIN_SOURCE_MSB 0 +#define GPIO_PIN_SOURCE_LSB 0 +#define GPIO_PIN_SOURCE_MASK 0x00000001 +#define GPIO_PIN_SOURCE_GET(x) (((x) & GPIO_PIN_SOURCE_MASK) >> GPIO_PIN_SOURCE_LSB) +#define GPIO_PIN_SOURCE_SET(x) (((x) << GPIO_PIN_SOURCE_LSB) & GPIO_PIN_SOURCE_MASK) +// }} + +// TIMER reg {{ +#define RTC_REG_READ(addr) READ_PERI_REG(PERIPHS_TIMER_BASEDDR + addr) +#define RTC_REG_WRITE(addr, val) WRITE_PERI_REG(PERIPHS_TIMER_BASEDDR + addr, val) +#define RTC_CLR_REG_MASK(reg, mask) CLEAR_PERI_REG_MASK(PERIPHS_TIMER_BASEDDR +reg, mask) +/* Returns the current time according to the timer timer. */ +#define NOW() RTC_REG_READ(FRC2_COUNT_ADDRESS) + +//load initial_value to timer1 +#define FRC1_LOAD_ADDRESS 0x00 + +//timer1's counter value(count from initial_value to 0) +#define FRC1_COUNT_ADDRESS 0x04 + +#define FRC1_CTRL_ADDRESS 0x08 + +//clear timer1's interrupt when write this address +#define FRC1_INT_ADDRESS 0x0c +#define FRC1_INT_CLR_MASK 0x00000001 + +//timer2's counter value(count from initial_value to 0) +#define FRC2_COUNT_ADDRESS 0x24 +// }} + +//RTC reg {{ +#define REG_RTC_BASE PERIPHS_RTC_BASEADDR + +#define RTC_GPIO_OUT (REG_RTC_BASE + 0x068) +#define RTC_GPIO_ENABLE (REG_RTC_BASE + 0x074) +#define RTC_GPIO_IN_DATA (REG_RTC_BASE + 0x08C) +#define RTC_GPIO_CONF (REG_RTC_BASE + 0x090) +#define PAD_XPD_DCDC_CONF (REG_RTC_BASE + 0x0A0) +//}} + +//PIN Mux reg {{ +#define PERIPHS_IO_MUX_FUNC 0x13 +#define PERIPHS_IO_MUX_FUNC_S 4 +#define PERIPHS_IO_MUX_PULLUP BIT7 +#define PERIPHS_IO_MUX_PULLUP2 BIT6 +#define PERIPHS_IO_MUX_SLEEP_PULLUP BIT3 +#define PERIPHS_IO_MUX_SLEEP_PULLUP2 BIT2 +#define PERIPHS_IO_MUX_SLEEP_OE BIT1 +#define PERIPHS_IO_MUX_OE BIT0 + +#define PERIPHS_IO_MUX_CONF_U (PERIPHS_IO_MUX + 0x00) +#define SPI0_CLK_EQU_SYS_CLK BIT8 +#define SPI1_CLK_EQU_SYS_CLK BIT9 +#define PERIPHS_IO_MUX_MTDI_U (PERIPHS_IO_MUX + 0x04) +#define FUNC_GPIO12 3 +#define PERIPHS_IO_MUX_MTCK_U (PERIPHS_IO_MUX + 0x08) +#define FUNC_GPIO13 3 +#define PERIPHS_IO_MUX_MTMS_U (PERIPHS_IO_MUX + 0x0C) +#define FUNC_GPIO14 3 +#define PERIPHS_IO_MUX_MTDO_U (PERIPHS_IO_MUX + 0x10) +#define FUNC_GPIO15 3 +#define FUNC_U0RTS 4 +#define PERIPHS_IO_MUX_U0RXD_U (PERIPHS_IO_MUX + 0x14) +#define FUNC_GPIO3 3 +#define PERIPHS_IO_MUX_U0TXD_U (PERIPHS_IO_MUX + 0x18) +#define FUNC_U0TXD 0 +#define FUNC_GPIO1 3 +#define PERIPHS_IO_MUX_SD_CLK_U (PERIPHS_IO_MUX + 0x1c) +#define FUNC_SDCLK 0 +#define FUNC_SPICLK 1 +#define PERIPHS_IO_MUX_SD_DATA0_U (PERIPHS_IO_MUX + 0x20) +#define FUNC_SDDATA0 0 +#define FUNC_SPIQ 1 +#define FUNC_U1TXD 4 +#define PERIPHS_IO_MUX_SD_DATA1_U (PERIPHS_IO_MUX + 0x24) +#define FUNC_SDDATA1 0 +#define FUNC_SPID 1 +#define FUNC_U1RXD 4 +#define FUNC_SDDATA1_U1RXD 7 +#define PERIPHS_IO_MUX_SD_DATA2_U (PERIPHS_IO_MUX + 0x28) +#define FUNC_SDDATA2 0 +#define FUNC_SPIHD 1 +#define FUNC_GPIO9 3 +#define PERIPHS_IO_MUX_SD_DATA3_U (PERIPHS_IO_MUX + 0x2c) +#define FUNC_SDDATA3 0 +#define FUNC_SPIWP 1 +#define FUNC_GPIO10 3 +#define PERIPHS_IO_MUX_SD_CMD_U (PERIPHS_IO_MUX + 0x30) +#define FUNC_SDCMD 0 +#define FUNC_SPICS0 1 +#define PERIPHS_IO_MUX_GPIO0_U (PERIPHS_IO_MUX + 0x34) +#define FUNC_GPIO0 0 +#define PERIPHS_IO_MUX_GPIO2_U (PERIPHS_IO_MUX + 0x38) +#define FUNC_GPIO2 0 +#define FUNC_U1TXD_BK 2 +#define FUNC_U0TXD_BK 4 +#define PERIPHS_IO_MUX_GPIO4_U (PERIPHS_IO_MUX + 0x3C) +#define FUNC_GPIO4 0 +#define PERIPHS_IO_MUX_GPIO5_U (PERIPHS_IO_MUX + 0x40) +#define FUNC_GPIO5 0 + +#define PIN_PULLUP_DIS(PIN_NAME) CLEAR_PERI_REG_MASK(PIN_NAME, PERIPHS_IO_MUX_PULLUP) +#define PIN_PULLUP_EN(PIN_NAME) SET_PERI_REG_MASK(PIN_NAME, PERIPHS_IO_MUX_PULLUP) + +#define PIN_FUNC_SELECT(PIN_NAME, FUNC) do { \ + WRITE_PERI_REG(PIN_NAME, \ + READ_PERI_REG(PIN_NAME) \ + & (~(PERIPHS_IO_MUX_FUNC<= 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_ANYEDGE = 3, + GPIO_PIN_INTR_LOLEVEL = 4, + GPIO_PIN_INTR_HILEVEL = 5 +} GPIO_INT_TYPE; + +#define GPIO_OUTPUT_SET(gpio_no, bit_value) \ + gpio_output_set((bit_value)<>gpio_no)&BIT0) + +/* GPIO interrupt handler, registered through gpio_intr_handler_register */ +typedef void (* gpio_intr_handler_fn_t)(uint32 intr_mask, void *arg); + + +/* + * Initialize GPIO. This includes reading the GPIO Configuration DataSet + * to initialize "output enables" and pin configurations for each gpio pin. + * Must be called once during startup. + */ +void gpio_init(void); + +/* + * Change GPIO pin output by setting, clearing, or disabling pins. + * In general, it is expected that a bit will be set in at most one + * of these masks. If a bit is clear in all masks, the output state + * remains unchanged. + * + * There is no particular ordering guaranteed; so if the order of + * writes is significant, calling code should divide a single call + * into multiple calls. + */ +void gpio_output_set(uint32 set_mask, + uint32 clear_mask, + uint32 enable_mask, + uint32 disable_mask); + +/* + * Sample the value of GPIO input pins and returns a bitmask. + */ +uint32 gpio_input_get(void); + +/* + * Set the specified GPIO register to the specified value. + * This is a very general and powerful interface that is not + * expected to be used during normal operation. It is intended + * mainly for debug, or for unusual requirements. + */ +void gpio_register_set(uint32 reg_id, uint32 value); + +/* Get the current value of the specified GPIO register. */ +uint32 gpio_register_get(uint32 reg_id); + +/* + * Register an application-specific interrupt handler for GPIO pin + * interrupts. Once the interrupt handler is called, it will not + * be called again until after a call to gpio_intr_ack. Any GPIO + * interrupts that occur during the interim are masked. + * + * The application-specific handler is called with a mask of + * pending GPIO interrupts. After processing pin interrupts, the + * application-specific handler may wish to use gpio_intr_pending + * to check for any additional pending interrupts before it returns. + */ +void gpio_intr_handler_register(gpio_intr_handler_fn_t fn, void *arg); + +/* Determine which GPIO interrupts are pending. */ +uint32 gpio_intr_pending(void); + +/* + * Acknowledge GPIO interrupts. + * Intended to be called from the gpio_intr_handler_fn. + */ +void gpio_intr_ack(uint32 ack_mask); + +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); + +#endif // _GPIO_H_ diff --git a/esp_iot_sdk_v1.3.0/include/ip_addr.h b/esp_iot_sdk_v1.3.0/include/ip_addr.h new file mode 100644 index 0000000..106d831 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/ip_addr.h @@ -0,0 +1,63 @@ +#ifndef __IP_ADDR_H__ +#define __IP_ADDR_H__ + +#include "c_types.h" + +struct ip_addr { + uint32 addr; +}; + +typedef struct ip_addr ip_addr_t; + +struct ip_info { + struct ip_addr ip; + struct ip_addr netmask; + struct ip_addr gw; +}; + +/** + * Determine if two address are on the same network. + * + * @arg addr1 IP address 1 + * @arg addr2 IP address 2 + * @arg mask network identifier mask + * @return !0 if the network identifiers of both address match + */ +#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \ + (mask)->addr) == \ + ((addr2)->addr & \ + (mask)->addr)) + +/** Set an IP address given by the four byte-parts. + Little-endian version that prevents the use of htonl. */ +#define IP4_ADDR(ipaddr, a,b,c,d) \ + (ipaddr)->addr = ((uint32)((d) & 0xff) << 24) | \ + ((uint32)((c) & 0xff) << 16) | \ + ((uint32)((b) & 0xff) << 8) | \ + (uint32)((a) & 0xff) + +#define ip4_addr1(ipaddr) (((uint8*)(ipaddr))[0]) +#define ip4_addr2(ipaddr) (((uint8*)(ipaddr))[1]) +#define ip4_addr3(ipaddr) (((uint8*)(ipaddr))[2]) +#define ip4_addr4(ipaddr) (((uint8*)(ipaddr))[3]) + +#define ip4_addr1_16(ipaddr) ((uint16)ip4_addr1(ipaddr)) +#define ip4_addr2_16(ipaddr) ((uint16)ip4_addr2(ipaddr)) +#define ip4_addr3_16(ipaddr) ((uint16)ip4_addr3(ipaddr)) +#define ip4_addr4_16(ipaddr) ((uint16)ip4_addr4(ipaddr)) + + +/** 255.255.255.255 */ +#define IPADDR_NONE ((uint32)0xffffffffUL) +/** 0.0.0.0 */ +#define IPADDR_ANY ((uint32)0x00000000UL) +uint32 ipaddr_addr(const char *cp); + +#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \ + ip4_addr2_16(ipaddr), \ + ip4_addr3_16(ipaddr), \ + ip4_addr4_16(ipaddr) + +#define IPSTR "%d.%d.%d.%d" + +#endif /* __IP_ADDR_H__ */ diff --git a/esp_iot_sdk_v1.3.0/include/json/json.h b/esp_iot_sdk_v1.3.0/include/json/json.h new file mode 100644 index 0000000..45ff40a --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/json/json.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2011-2012, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + */ + +/** + * \file + * A few JSON defines used for parsing and generating JSON. + * \author + * Niclas Finne + * Joakim Eriksson + */ + +#ifndef __JSON_H__ +#define __JSON_H__ + +#define JSON_TYPE_ARRAY '[' +#define JSON_TYPE_OBJECT '{' +#define JSON_TYPE_PAIR ':' +#define JSON_TYPE_PAIR_NAME 'N' /* for N:V pairs */ +#define JSON_TYPE_STRING '"' +#define JSON_TYPE_INT 'I' +#define JSON_TYPE_NUMBER '0' +#define JSON_TYPE_ERROR 0 + +/* how should we handle null vs false - both can be 0? */ +#define JSON_TYPE_NULL 'n' +#define JSON_TYPE_TRUE 't' +#define JSON_TYPE_FALSE 'f' + +#define JSON_TYPE_CALLBACK 'C' + +enum { + JSON_ERROR_OK, + JSON_ERROR_SYNTAX, + JSON_ERROR_UNEXPECTED_ARRAY, + JSON_ERROR_UNEXPECTED_END_OF_ARRAY, + JSON_ERROR_UNEXPECTED_OBJECT, + JSON_ERROR_UNEXPECTED_STRING +}; + +#define JSON_CONTENT_TYPE "application/json" + +#endif /* __JSON_H__ */ diff --git a/esp_iot_sdk_v1.3.0/include/json/jsonparse.h b/esp_iot_sdk_v1.3.0/include/json/jsonparse.h new file mode 100644 index 0000000..b608214 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/json/jsonparse.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2011-2012, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + */ + +#ifndef __JSONPARSE_H__ +#define __JSONPARSE_H__ + +#include "c_types.h" +#include "json/json.h" + +#ifdef JSONPARSE_CONF_MAX_DEPTH +#define JSONPARSE_MAX_DEPTH JSONPARSE_CONF_MAX_DEPTH +#else +#define JSONPARSE_MAX_DEPTH 10 +#endif + +struct jsonparse_state { + const char *json; + int pos; + int len; + int depth; + /* for handling atomic values */ + int vstart; + int vlen; + char vtype; + char error; + char stack[JSONPARSE_MAX_DEPTH]; +}; + +/** + * \brief Initialize a JSON parser state. + * \param state A pointer to a JSON parser state + * \param json The string to parse as JSON + * \param len The length of the string to parse + * + * This function initializes a JSON parser state for + * parsing a string as JSON. + */ +void jsonparse_setup(struct jsonparse_state *state, const char *json, + int len); + +/* move to next JSON element */ +int jsonparse_next(struct jsonparse_state *state); + +/* copy the current JSON value into the specified buffer */ +int jsonparse_copy_value(struct jsonparse_state *state, char *buf, + int buf_size); + +/* get the current JSON value parsed as an int */ +int jsonparse_get_value_as_int(struct jsonparse_state *state); + +/* get the current JSON value parsed as a long */ +long jsonparse_get_value_as_long(struct jsonparse_state *state); + +/* get the current JSON value parsed as a unsigned long */ +unsigned long jsonparse_get_value_as_ulong(struct jsonparse_state *state); + +/* get the length of the current JSON value */ +int jsonparse_get_len(struct jsonparse_state *state); + +/* get the type of the current JSON value */ +int jsonparse_get_type(struct jsonparse_state *state); + +/* compare the JSON value with the specified string */ +int jsonparse_strcmp_value(struct jsonparse_state *state, const char *str); + +#endif /* __JSONPARSE_H__ */ diff --git a/esp_iot_sdk_v1.3.0/include/json/jsontree.h b/esp_iot_sdk_v1.3.0/include/json/jsontree.h new file mode 100644 index 0000000..d434d42 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/json/jsontree.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2011-2012, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + */ + +/** + * \file + * JSON output generation + * \author + * Niclas Finne + * Joakim Eriksson + */ + +#ifndef __JSONTREE_H__ +#define __JSONTREE_H__ + +#include "c_types.h" +#include "json/json.h" + +#ifdef JSONTREE_CONF_MAX_DEPTH +#define JSONTREE_MAX_DEPTH JSONTREE_CONF_MAX_DEPTH +#else +#define JSONTREE_MAX_DEPTH 10 +#endif /* JSONTREE_CONF_MAX_DEPTH */ + +struct jsontree_context { + struct jsontree_value *values[JSONTREE_MAX_DEPTH]; + uint16_t index[JSONTREE_MAX_DEPTH]; + int (* putchar)(int); + uint8_t depth; + uint8_t path; + int callback_state; +}; + +struct jsontree_value { + uint8_t type; + /* followed by a value */ +}; + +struct jsontree_string { + uint8_t type; + const char *value; +}; + +struct jsontree_int { + uint8_t type; + int value; +}; + +/* NOTE: the jsontree_callback set will receive a jsonparse state */ +struct jsonparse_state; +struct jsontree_callback { + uint8_t type; + int (* output)(struct jsontree_context *js_ctx); + int (* set)(struct jsontree_context *js_ctx, struct jsonparse_state *parser); +}; + +struct jsontree_pair { + const char *name; + struct jsontree_value *value; +}; + +struct jsontree_object { + uint8_t type; + uint8_t count; + struct jsontree_pair *pairs; +}; + +struct jsontree_array { + uint8_t type; + uint8_t count; + struct jsontree_value **values; +}; + +#define JSONTREE_STRING(text) {JSON_TYPE_STRING, (text)} +#define JSONTREE_PAIR(name, value) {(name), (struct jsontree_value *)(value)} +#define JSONTREE_CALLBACK(output, set) {JSON_TYPE_CALLBACK, (output), (set)} + +#define JSONTREE_OBJECT(name, ...) \ + static struct jsontree_pair jsontree_pair_##name[] = {__VA_ARGS__}; \ + static struct jsontree_object name = { \ + JSON_TYPE_OBJECT, \ + sizeof(jsontree_pair_##name)/sizeof(struct jsontree_pair), \ + jsontree_pair_##name } + +#define JSONTREE_PAIR_ARRAY(value) (struct jsontree_value *)(value) +#define JSONTREE_ARRAY(name, ...) \ + static struct jsontree_value* jsontree_value_##name[] = {__VA_ARGS__}; \ + static struct jsontree_array name = { \ + JSON_TYPE_ARRAY, \ + sizeof(jsontree_value_##name)/sizeof(struct jsontree_value*), \ + jsontree_value_##name } + +#define JSONTREE_OBJECT_EXT(name, ...) \ + static struct jsontree_pair jsontree_pair_##name[] = {__VA_ARGS__}; \ + struct jsontree_object name = { \ + JSON_TYPE_OBJECT, \ + sizeof(jsontree_pair_##name)/sizeof(struct jsontree_pair), \ + jsontree_pair_##name } + +void jsontree_setup(struct jsontree_context *js_ctx, + struct jsontree_value *root, int (* putchar)(int)); +void jsontree_reset(struct jsontree_context *js_ctx); + +const char *jsontree_path_name(const struct jsontree_context *js_ctx, + int depth); + +void jsontree_write_int(const struct jsontree_context *js_ctx, int value); +void jsontree_write_int_array(const struct jsontree_context *js_ctx, const int *text, uint32 length); + +void jsontree_write_atom(const struct jsontree_context *js_ctx, + const char *text); +void jsontree_write_string(const struct jsontree_context *js_ctx, + const char *text); +int jsontree_print_next(struct jsontree_context *js_ctx); +struct jsontree_value *jsontree_find_next(struct jsontree_context *js_ctx, + int type); + +#endif /* __JSONTREE_H__ */ diff --git a/esp_iot_sdk_v1.3.0/include/mem.h b/esp_iot_sdk_v1.3.0/include/mem.h new file mode 100644 index 0000000..bce0680 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/mem.h @@ -0,0 +1,12 @@ +#ifndef __MEM_H__ +#define __MEM_H__ + +//void *pvPortMalloc( size_t xWantedSize ); +//void vPortFree( void *pv ); +//void *pvPortZalloc(size_t size); + +#define os_malloc pvPortMalloc +#define os_free vPortFree +#define os_zalloc pvPortZalloc + +#endif diff --git a/esp_iot_sdk_v1.3.0/include/os_type.h b/esp_iot_sdk_v1.3.0/include/os_type.h new file mode 100644 index 0000000..99d7c8f --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/os_type.h @@ -0,0 +1,19 @@ +/* + * copyright (c) Espressif System 2010 + * + * mapping to ETS structures + * + */ +#ifndef _OS_TYPES_H_ +#define _OS_TYPES_H_ + +#include "ets_sys.h" + +#define os_signal_t ETSSignal +#define os_param_t ETSParam +#define os_event_t ETSEvent +#define os_task_t ETSTask +#define os_timer_t ETSTimer +#define os_timer_func_t ETSTimerFunc + +#endif diff --git a/esp_iot_sdk_v1.3.0/include/osapi.h b/esp_iot_sdk_v1.3.0/include/osapi.h new file mode 100644 index 0000000..b3ffed4 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/osapi.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010 Espressif System + */ + +#ifndef _OSAPI_H_ +#define _OSAPI_H_ + +#include +#include "user_config.h" + +#define os_bzero ets_bzero +#define os_delay_us ets_delay_us +#define os_install_putc1 ets_install_putc1 + +#define os_memcmp ets_memcmp +#define os_memcpy ets_memcpy +#define os_memmove ets_memmove +#define os_memset ets_memset +#define os_strcat strcat +#define os_strchr strchr +#define os_strcmp ets_strcmp +#define os_strcpy ets_strcpy +#define os_strlen ets_strlen +#define os_strncmp ets_strncmp +#define os_strncpy ets_strncpy +#define os_strstr ets_strstr +#ifdef USE_US_TIMER +#define os_timer_arm_us(a, b, c) ets_timer_arm_new(a, b, c, 0) +#endif +#define os_timer_arm(a, b, c) ets_timer_arm_new(a, b, c, 1) +#define os_timer_disarm ets_timer_disarm +#define os_timer_setfn ets_timer_setfn + +#define os_sprintf ets_sprintf + +#ifdef USE_OPTIMIZE_PRINTF +#define os_printf(fmt, ...) do { \ + static const char flash_str[] ICACHE_RODATA_ATTR __attribute__((aligned(4))) = fmt; \ + os_printf_plus(flash_str, ##__VA_ARGS__); \ + } while(0) +#else +#define os_printf os_printf_plus +#endif + +unsigned long os_random(void); +int os_get_random(unsigned char *buf, size_t len); + +#endif + diff --git a/esp_iot_sdk_v1.3.0/include/ping.h b/esp_iot_sdk_v1.3.0/include/ping.h new file mode 100644 index 0000000..4ecd032 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/ping.h @@ -0,0 +1,32 @@ +#ifndef __PING_H__ +#define __PING_H__ + + +typedef void (* ping_recv_function)(void* arg, void *pdata); +typedef void (* ping_sent_function)(void* arg, void *pdata); + +struct ping_option{ + uint32 count; + uint32 ip; + uint32 coarse_time; + ping_recv_function recv_function; + ping_sent_function sent_function; + void* reverse; +}; + +struct ping_resp{ + uint32 total_count; + uint32 resp_time; + uint32 seqno; + uint32 timeout_count; + uint32 bytes; + uint32 total_bytes; + uint32 total_time; + sint8 ping_err; +}; + +bool ping_start(struct ping_option *ping_opt); +bool ping_regist_recv(struct ping_option *ping_opt, ping_recv_function ping_recv); +bool ping_regist_sent(struct ping_option *ping_opt, ping_sent_function ping_sent); + +#endif /* __PING_H__ */ diff --git a/esp_iot_sdk_v1.3.0/include/pwm.h b/esp_iot_sdk_v1.3.0/include/pwm.h new file mode 100644 index 0000000..501a5fe --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/pwm.h @@ -0,0 +1,34 @@ +#ifndef __PWM_H__ +#define __PWM_H__ + +/*pwm.h: function and macro definition of PWM API , driver level */ +/*user_light.h: user interface for light API, user level*/ +/*user_light_adj: API for color changing and lighting effects, user level*/ + + + /*NOTE!! : DO NOT CHANGE THIS FILE*/ + + /*SUPPORT UP TO 8 PWM CHANNEL*/ +#define PWM_CHANNEL_NUM_MAX 8 + +struct pwm_param { + uint32 period; + uint32 freq; + uint32 duty[PWM_CHANNEL_NUM_MAX]; //PWM_CHANNEL<=8 +}; + + +/* pwm_init should be called only once, for now */ +void pwm_init(uint32 period, uint32 *duty,uint32 pwm_channel_num,uint32 (*pin_info_list)[3]); +void pwm_start(void); + +void pwm_set_duty(uint32 duty, uint8 channel); +uint32 pwm_get_duty(uint8 channel); +void pwm_set_period(uint32 period); +uint32 pwm_get_period(void); + +uint32 get_pwm_version(void); +void set_pwm_debug_en(uint8 print_en); + +#endif + diff --git a/esp_iot_sdk_v1.3.0/include/queue.h b/esp_iot_sdk_v1.3.0/include/queue.h new file mode 100644 index 0000000..a760c8d --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/queue.h @@ -0,0 +1,204 @@ +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +#define QMD_SAVELINK(name, link) +#define TRASHIT(x) + +/* + * Singly-linked List declarations. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) + +#define SLIST_FIRST(head) ((head)->slh_first) + +#define SLIST_FOREACH(var, head, field) \ + for ((var) = SLIST_FIRST((head)); \ + (var); \ + (var) = SLIST_NEXT((var), field)) + +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST((head)); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ + for ((varp) = &SLIST_FIRST((head)); \ + ((var) = *(varp)) != NULL; \ + (varp) = &SLIST_NEXT((var), field)) + +#define SLIST_INIT(head) do { \ + SLIST_FIRST((head)) = NULL; \ +} while (0) + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ + SLIST_NEXT((slistelm), field) = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ + SLIST_FIRST((head)) = (elm); \ +} while (0) + +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.sle_next); \ + if (SLIST_FIRST((head)) == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = SLIST_FIRST((head)); \ + while (SLIST_NEXT(curelm, field) != (elm)) \ + curelm = SLIST_NEXT(curelm, field); \ + SLIST_REMOVE_AFTER(curelm, field); \ + } \ + TRASHIT(*oldnext); \ +} while (0) + +#define SLIST_REMOVE_AFTER(elm, field) do { \ + SLIST_NEXT(elm, field) = \ + SLIST_NEXT(SLIST_NEXT(elm, field), field); \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ +} while (0) + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ + struct name { \ + struct type *stqh_first;/* first element */ \ + struct type **stqh_last;/* addr of last next element */ \ + } + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ + struct { \ + struct type *stqe_next; /* next element */ \ + } + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ + } while (0) + +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) + +#define STAILQ_FIRST(head) ((head)->stqh_first) + +#define STAILQ_FOREACH(var, head, field) \ + for((var) = STAILQ_FIRST((head)); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST((head)); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define STAILQ_INIT(head) do { \ + STAILQ_FIRST((head)) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ + } while (0) + +#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_NEXT((tqelm), field) = (elm); \ + } while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_FIRST((head)) = (elm); \ + } while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + STAILQ_NEXT((elm), field) = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + } while (0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY((head)) ? \ + NULL : \ + ((struct type *)(void *) \ + ((char *)((head)->stqh_last) - __offsetof(struct type, field)))) + +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.stqe_next); \ + if (STAILQ_FIRST((head)) == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = STAILQ_FIRST((head)); \ + while (STAILQ_NEXT(curelm, field) != (elm)) \ + curelm = STAILQ_NEXT(curelm, field); \ + STAILQ_REMOVE_AFTER(head, curelm, field); \ + } \ + TRASHIT(*oldnext); \ + } while (0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if ((STAILQ_FIRST((head)) = \ + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ + } while (0) + +#define STAILQ_REMOVE_AFTER(head, elm, field) do { \ + if ((STAILQ_NEXT(elm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + } while (0) + +#define STAILQ_SWAP(head1, head2, type) do { \ + struct type *swap_first = STAILQ_FIRST(head1); \ + struct type **swap_last = (head1)->stqh_last; \ + STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_FIRST(head2) = swap_first; \ + (head2)->stqh_last = swap_last; \ + if (STAILQ_EMPTY(head1)) \ + (head1)->stqh_last = &STAILQ_FIRST(head1); \ + if (STAILQ_EMPTY(head2)) \ + (head2)->stqh_last = &STAILQ_FIRST(head2); \ + } while (0) + +#define STAILQ_INSERT_CHAIN_HEAD(head, elm_chead, elm_ctail, field) do { \ + if ((STAILQ_NEXT(elm_ctail, field) = STAILQ_FIRST(head)) == NULL ) { \ + (head)->stqh_last = &STAILQ_NEXT(elm_ctail, field); \ + } \ + STAILQ_FIRST(head) = (elm_chead); \ + } while (0) + +#endif /* !_SYS_QUEUE_H_ */ diff --git a/esp_iot_sdk_v1.3.0/include/smartconfig.h b/esp_iot_sdk_v1.3.0/include/smartconfig.h new file mode 100644 index 0000000..6fd86d6 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/smartconfig.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2015 -2018 Espressif System + * + */ + +#ifndef __SMARTCONFIG_H__ +#define __SMARTCONFIG_H__ + +typedef enum { + SC_STATUS_WAIT = 0, + SC_STATUS_FIND_CHANNEL, + SC_STATUS_GETTING_SSID_PSWD, + SC_STATUS_LINK, + SC_STATUS_LINK_OVER, +} sc_status; + +typedef enum { + SC_TYPE_ESPTOUCH = 0, + SC_TYPE_AIRKISS, +} sc_type; + +typedef void (*sc_callback_t)(sc_status status, void *pdata); + +const char *smartconfig_get_version(void); +bool smartconfig_start(sc_callback_t cb, ...); +bool smartconfig_stop(void); +bool esptouch_set_timeout(uint8 time_s); //15s~255s, offset:45s + +#endif diff --git a/esp_iot_sdk_v1.3.0/include/sntp.h b/esp_iot_sdk_v1.3.0/include/sntp.h new file mode 100644 index 0000000..db02748 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/sntp.h @@ -0,0 +1,68 @@ +#ifndef __SNTP_H__ +#define __SNTP_H__ + +#include "os_type.h" +#ifdef LWIP_OPEN_SRC +#include "lwip/ip_addr.h" +#else +#include "ip_addr.h" +#endif +/** + * get the seconds since Jan 01, 1970, 00:00 (GMT + 8) + */ +uint32 sntp_get_current_timestamp(); +/** + * get real time (GTM + 8 time zone) + */ +char* sntp_get_real_time(long t); +/** + * SNTP get time_zone default GMT + 8 + */ +sint8 sntp_get_timezone(void); +/** + * SNTP set time_zone (default GMT + 8) + */ +bool sntp_set_timezone(sint8 timezone); +/** + * Initialize this module. + * Send out request instantly or after SNTP_STARTUP_DELAY(_FUNC). + */ +void sntp_init(void); +/** + * Stop this module. + */ +void sntp_stop(void); +/** + * Initialize one of the NTP servers by IP address + * + * @param numdns the index of the NTP server to set must be < SNTP_MAX_SERVERS + * @param dnsserver IP address of the NTP server to set + */ +void sntp_setserver(unsigned char idx, ip_addr_t *addr); +/** + * Obtain one of the currently configured by IP address (or DHCP) NTP servers + * + * @param numdns the index of the NTP server + * @return IP address of the indexed NTP server or "ip_addr_any" if the NTP + * server has not been configured by address (or at all). + */ +ip_addr_t sntp_getserver(unsigned char idx); +/** + * Initialize one of the NTP servers by name + * + * @param numdns the index of the NTP server to set must be < SNTP_MAX_SERVERS,now sdk support SNTP_MAX_SERVERS = 3 + * @param dnsserver DNS name of the NTP server to set, to be resolved at contact time + */ +void sntp_setservername(unsigned char idx, char *server); +/** + * Obtain one of the currently configured by name NTP servers. + * + * @param numdns the index of the NTP server + * @return IP address of the indexed NTP server or NULL if the NTP + * server has not been configured by name (or at all) + */ +char *sntp_getservername(unsigned char idx); + +#define sntp_servermode_dhcp(x) + +#endif diff --git a/esp_iot_sdk_v1.3.0/include/spi_flash.h b/esp_iot_sdk_v1.3.0/include/spi_flash.h new file mode 100644 index 0000000..d5a16a1 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/spi_flash.h @@ -0,0 +1,39 @@ +/* + * copyright (c) Espressif System 2010 + * + */ + +#ifndef SPI_FLASH_H +#define SPI_FLASH_H + +typedef enum { + SPI_FLASH_RESULT_OK, + SPI_FLASH_RESULT_ERR, + SPI_FLASH_RESULT_TIMEOUT +} SpiFlashOpResult; + +typedef struct{ + uint32 deviceId; + uint32 chip_size; // chip size in byte + uint32 block_size; + uint32 sector_size; + uint32 page_size; + uint32 status_mask; +} SpiFlashChip; + +#define SPI_FLASH_SEC_SIZE 4096 + +uint32 spi_flash_get_id(void); +SpiFlashOpResult spi_flash_erase_sector(uint16 sec); +SpiFlashOpResult spi_flash_write(uint32 des_addr, uint32 *src_addr, uint32 size); +SpiFlashOpResult spi_flash_read(uint32 src_addr, uint32 *des_addr, uint32 size); + +typedef SpiFlashOpResult (* user_spi_flash_read)( + SpiFlashChip *spi, + uint32 src_addr, + uint32 *des_addr, + uint32 size); + +void spi_flash_set_read_func(user_spi_flash_read read); + +#endif diff --git a/esp_iot_sdk_v1.3.0/include/upgrade.h b/esp_iot_sdk_v1.3.0/include/upgrade.h new file mode 100644 index 0000000..cddf839 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/upgrade.h @@ -0,0 +1,50 @@ +#ifndef __UPGRADE_H__ +#define __UPGRADE_H__ + +#define SPI_FLASH_SEC_SIZE 4096 +#define LIMIT_ERASE_SIZE 0x10000 + +#define USER_BIN1 0x00 +#define USER_BIN2 0x01 + +#define UPGRADE_FLAG_IDLE 0x00 +#define UPGRADE_FLAG_START 0x01 +#define UPGRADE_FLAG_FINISH 0x02 + +#define UPGRADE_FW_BIN1 0x00 +#define UPGRADE_FW_BIN2 0x01 + +typedef void (*upgrade_states_check_callback)(void * arg); + +//#define UPGRADE_SSL_ENABLE + +struct upgrade_server_info { + uint8 ip[4]; + uint16 port; + + uint8 upgrade_flag; + + uint8 pre_version[16]; + uint8 upgrade_version[16]; + + uint32 check_times; + uint8 *url; + + upgrade_states_check_callback check_cb; + struct espconn *pespconn; +}; + +#define UPGRADE_FLAG_IDLE 0x00 +#define UPGRADE_FLAG_START 0x01 +#define UPGRADE_FLAG_FINISH 0x02 + +void system_upgrade_init(); +void system_upgrade_deinit(); +bool system_upgrade(uint8 *data, uint16 len); + +#ifdef UPGRADE_SSL_ENABLE +bool system_upgrade_start_ssl(struct upgrade_server_info *server); // not supported now +#else +bool system_upgrade_start(struct upgrade_server_info *server); +#endif +#endif diff --git a/esp_iot_sdk_v1.3.0/include/user_interface.h b/esp_iot_sdk_v1.3.0/include/user_interface.h new file mode 100644 index 0000000..ee156b2 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/include/user_interface.h @@ -0,0 +1,450 @@ +/* + * Copyright (C) 2013 -2014 Espressif System + * + */ + +#ifndef __USER_INTERFACE_H__ +#define __USER_INTERFACE_H__ + +#include "os_type.h" +#ifdef LWIP_OPEN_SRC +#include "lwip/ip_addr.h" +#else +#include "ip_addr.h" +#endif + +#include "queue.h" +#include "user_config.h" +#include "spi_flash.h" + +#ifndef MAC2STR +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] +#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" +#endif + +enum rst_reason { + REASON_DEFAULT_RST = 0, + REASON_WDT_RST = 1, + REASON_EXCEPTION_RST = 2, + REASON_SOFT_WDT_RST = 3, + REASON_SOFT_RESTART = 4, + REASON_DEEP_SLEEP_AWAKE = 5, + REASON_EXT_SYS_RST = 6 +}; + +struct rst_info{ + uint32 reason; + uint32 exccause; + uint32 epc1; + uint32 epc2; + uint32 epc3; + uint32 excvaddr; + uint32 depc; +}; + +struct rst_info* system_get_rst_info(void); + +#define UPGRADE_FW_BIN1 0x00 +#define UPGRADE_FW_BIN2 0x01 + +void system_restore(void); +void system_restart(void); + +bool system_deep_sleep_set_option(uint8 option); +void system_deep_sleep(uint32 time_in_us); + +uint8 system_upgrade_userbin_check(void); +void system_upgrade_reboot(void); +uint8 system_upgrade_flag_check(); +void system_upgrade_flag_set(uint8 flag); + +void system_timer_reinit(void); +uint32 system_get_time(void); + +/* user task's prio must be 0/1/2 !!!*/ +enum { + USER_TASK_PRIO_0 = 0, + USER_TASK_PRIO_1, + USER_TASK_PRIO_2, + USER_TASK_PRIO_MAX +}; + +bool system_os_task(os_task_t task, uint8 prio, os_event_t *queue, uint8 qlen); +bool system_os_post(uint8 prio, os_signal_t sig, os_param_t par); + +void system_print_meminfo(void); +uint32 system_get_free_heap_size(void); + +void system_set_os_print(uint8 onoff); +uint8 system_get_os_print(); + +uint64 system_mktime(uint32 year, uint32 mon, uint32 day, uint32 hour, uint32 min, uint32 sec); + +uint32 system_get_chip_id(void); + +typedef void (* init_done_cb_t)(void); + +void system_init_done_cb(init_done_cb_t cb); + +uint32 system_rtc_clock_cali_proc(void); +uint32 system_get_rtc_time(void); + +bool system_rtc_mem_read(uint8 src_addr, void *des_addr, uint16 load_size); +bool system_rtc_mem_write(uint8 des_addr, const void *src_addr, uint16 save_size); + +void system_uart_swap(void); +void system_uart_de_swap(void); + +uint16 system_adc_read(void); +uint16 system_get_vdd33(void); + +const char *system_get_sdk_version(void); + +#define SYS_BOOT_ENHANCE_MODE 0 +#define SYS_BOOT_NORMAL_MODE 1 + +#define SYS_BOOT_NORMAL_BIN 0 +#define SYS_BOOT_TEST_BIN 1 + +uint8 system_get_boot_version(void); +uint32 system_get_userbin_addr(void); +uint8 system_get_boot_mode(void); +bool system_restart_enhance(uint8 bin_type, uint32 bin_addr); + +#define SYS_CPU_80MHZ 80 +#define SYS_CPU_160MHZ 160 + +bool system_update_cpu_freq(uint8 freq); +uint8 system_get_cpu_freq(void); + +enum flash_size_map { + FLASH_SIZE_4M_MAP_256_256 = 0, + FLASH_SIZE_2M, + FLASH_SIZE_8M_MAP_512_512, + FLASH_SIZE_16M_MAP_512_512, + FLASH_SIZE_32M_MAP_512_512, + FLASH_SIZE_16M_MAP_1024_1024, + FLASH_SIZE_32M_MAP_1024_1024 +}; + +enum flash_size_map system_get_flash_size_map(void); + +void system_phy_set_max_tpw(uint8 max_tpw); +void system_phy_set_tpw_via_vdd33(uint16 vdd33); +void system_phy_set_rfoption(uint8 option); + +bool system_param_save_with_protect(uint16 start_sec, void *param, uint16 len); +bool system_param_load(uint16 start_sec, uint16 offset, void *param, uint16 len); + +void system_soft_wdt_stop(void); +void system_soft_wdt_restart(void); +void system_soft_wdt_feed(void); + +#define NULL_MODE 0x00 +#define STATION_MODE 0x01 +#define SOFTAP_MODE 0x02 +#define STATIONAP_MODE 0x03 + +typedef enum _auth_mode { + AUTH_OPEN = 0, + AUTH_WEP, + AUTH_WPA_PSK, + AUTH_WPA2_PSK, + AUTH_WPA_WPA2_PSK, + AUTH_MAX +} AUTH_MODE; + +uint8 wifi_get_opmode(void); +uint8 wifi_get_opmode_default(void); +bool wifi_set_opmode(uint8 opmode); +bool wifi_set_opmode_current(uint8 opmode); +uint8 wifi_get_broadcast_if(void); +bool wifi_set_broadcast_if(uint8 interface); + +struct bss_info { + STAILQ_ENTRY(bss_info) next; + + uint8 bssid[6]; + uint8 ssid[32]; + uint8 channel; + sint8 rssi; + AUTH_MODE authmode; + uint8 is_hidden; + sint16 freq_offset; +}; + +typedef struct _scaninfo { + STAILQ_HEAD(, bss_info) *pbss; + struct espconn *pespconn; + uint8 totalpage; + uint8 pagenum; + uint8 page_sn; + uint8 data_cnt; +} scaninfo; + +typedef void (* scan_done_cb_t)(void *arg, STATUS status); + +struct station_config { + uint8 ssid[32]; + uint8 password[64]; + uint8 bssid_set; // Note: If bssid_set is 1, station will just connect to the router + // with both ssid[] and bssid[] matched. Please check about this. + uint8 bssid[6]; +}; + +bool wifi_station_get_config(struct station_config *config); +bool wifi_station_get_config_default(struct station_config *config); +bool wifi_station_set_config(struct station_config *config); +bool wifi_station_set_config_current(struct station_config *config); + +bool wifi_station_connect(void); +bool wifi_station_disconnect(void); + +sint8 wifi_station_get_rssi(void); + +struct scan_config { + uint8 *ssid; // Note: ssid == NULL, don't filter ssid. + uint8 *bssid; // Note: bssid == NULL, don't filter bssid. + uint8 channel; // Note: channel == 0, scan all channels, otherwise scan set channel. + uint8 show_hidden; // Note: show_hidden == 1, can get hidden ssid routers' info. +}; + +bool wifi_station_scan(struct scan_config *config, scan_done_cb_t cb); + +uint8 wifi_station_get_auto_connect(void); +bool wifi_station_set_auto_connect(uint8 set); + +bool wifi_station_set_reconnect_policy(bool set); + +enum { + STATION_IDLE = 0, + STATION_CONNECTING, + STATION_WRONG_PASSWORD, + STATION_NO_AP_FOUND, + STATION_CONNECT_FAIL, + STATION_GOT_IP +}; + +enum dhcp_status { + DHCP_STOPPED, + DHCP_STARTED +}; + +uint8 wifi_station_get_connect_status(void); + +uint8 wifi_station_get_current_ap_id(void); +bool wifi_station_ap_change(uint8 current_ap_id); +bool wifi_station_ap_number_set(uint8 ap_number); +uint8 wifi_station_get_ap_info(struct station_config config[]); + +bool wifi_station_dhcpc_start(void); +bool wifi_station_dhcpc_stop(void); +enum dhcp_status wifi_station_dhcpc_status(void); + +char* wifi_station_get_hostname(void); +bool wifi_station_set_hostname(char *name); + +struct softap_config { + uint8 ssid[32]; + uint8 password[64]; + uint8 ssid_len; // Note: Recommend to set it according to your ssid + uint8 channel; // Note: support 1 ~ 13 + AUTH_MODE authmode; // Note: Don't support AUTH_WEP in softAP mode. + uint8 ssid_hidden; // Note: default 0 + uint8 max_connection; // Note: default 4, max 4 + uint16 beacon_interval; // Note: support 100 ~ 60000 ms, default 100 +}; + +bool wifi_softap_get_config(struct softap_config *config); +bool wifi_softap_get_config_default(struct softap_config *config); +bool wifi_softap_set_config(struct softap_config *config); +bool wifi_softap_set_config_current(struct softap_config *config); + +struct station_info { + STAILQ_ENTRY(station_info) next; + + uint8 bssid[6]; + struct ip_addr ip; +}; + +struct dhcps_lease { + struct ip_addr start_ip; + struct ip_addr end_ip; +}; + +enum dhcps_offer_option{ + OFFER_START = 0x00, + OFFER_ROUTER = 0x01, + OFFER_END +}; + +uint8 wifi_softap_get_station_num(void); +struct station_info * wifi_softap_get_station_info(void); +void wifi_softap_free_station_info(void); + +bool wifi_softap_dhcps_start(void); +bool wifi_softap_dhcps_stop(void); +bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please); +bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please); +enum dhcp_status wifi_softap_dhcps_status(void); +bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg); + +#define STATION_IF 0x00 +#define SOFTAP_IF 0x01 + +bool wifi_get_ip_info(uint8 if_index, struct ip_info *info); +bool wifi_set_ip_info(uint8 if_index, struct ip_info *info); +bool wifi_get_macaddr(uint8 if_index, uint8 *macaddr); +bool wifi_set_macaddr(uint8 if_index, uint8 *macaddr); + +uint8 wifi_get_channel(void); +bool wifi_set_channel(uint8 channel); + +void wifi_status_led_install(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func); +void wifi_status_led_uninstall(); + +/** Get the absolute difference between 2 u32_t values (correcting overflows) + * 'a' is expected to be 'higher' (without overflow) than 'b'. */ +#define ESP_U32_DIFF(a, b) (((a) >= (b)) ? ((a) - (b)) : (((a) + ((b) ^ 0xFFFFFFFF) + 1))) + +void wifi_promiscuous_enable(uint8 promiscuous); + +typedef void (* wifi_promiscuous_cb_t)(uint8 *buf, uint16 len); + +void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb); + +void wifi_promiscuous_set_mac(const uint8_t *address); + +enum phy_mode { + PHY_MODE_11B = 1, + PHY_MODE_11G = 2, + PHY_MODE_11N = 3 +}; + +enum phy_mode wifi_get_phy_mode(void); +bool wifi_set_phy_mode(enum phy_mode mode); + +enum sleep_type { + NONE_SLEEP_T = 0, + LIGHT_SLEEP_T, + MODEM_SLEEP_T +}; + +bool wifi_set_sleep_type(enum sleep_type type); +enum sleep_type wifi_get_sleep_type(void); + +enum { + EVENT_STAMODE_CONNECTED = 0, + EVENT_STAMODE_DISCONNECTED, + EVENT_STAMODE_AUTHMODE_CHANGE, + EVENT_STAMODE_GOT_IP, + EVENT_SOFTAPMODE_STACONNECTED, + EVENT_SOFTAPMODE_STADISCONNECTED, + EVENT_MAX +}; + +enum { + REASON_UNSPECIFIED = 1, + REASON_AUTH_EXPIRE = 2, + REASON_AUTH_LEAVE = 3, + REASON_ASSOC_EXPIRE = 4, + REASON_ASSOC_TOOMANY = 5, + REASON_NOT_AUTHED = 6, + REASON_NOT_ASSOCED = 7, + REASON_ASSOC_LEAVE = 8, + REASON_ASSOC_NOT_AUTHED = 9, + REASON_DISASSOC_PWRCAP_BAD = 10, /* 11h */ + REASON_DISASSOC_SUPCHAN_BAD = 11, /* 11h */ + REASON_IE_INVALID = 13, /* 11i */ + REASON_MIC_FAILURE = 14, /* 11i */ + REASON_4WAY_HANDSHAKE_TIMEOUT = 15, /* 11i */ + REASON_GROUP_KEY_UPDATE_TIMEOUT = 16, /* 11i */ + REASON_IE_IN_4WAY_DIFFERS = 17, /* 11i */ + REASON_GROUP_CIPHER_INVALID = 18, /* 11i */ + REASON_PAIRWISE_CIPHER_INVALID = 19, /* 11i */ + REASON_AKMP_INVALID = 20, /* 11i */ + REASON_UNSUPP_RSN_IE_VERSION = 21, /* 11i */ + REASON_INVALID_RSN_IE_CAP = 22, /* 11i */ + REASON_802_1X_AUTH_FAILED = 23, /* 11i */ + REASON_CIPHER_SUITE_REJECTED = 24, /* 11i */ + + REASON_BEACON_TIMEOUT = 200, + REASON_NO_AP_FOUND = 201, +}; + +typedef struct { + uint8 ssid[32]; + uint8 ssid_len; + uint8 bssid[6]; + uint8 channel; +} Event_StaMode_Connected_t; + +typedef struct { + uint8 ssid[32]; + uint8 ssid_len; + uint8 bssid[6]; + uint8 reason; +} Event_StaMode_Disconnected_t; + +typedef struct { + uint8 old_mode; + uint8 new_mode; +} Event_StaMode_AuthMode_Change_t; + +typedef struct { + struct ip_addr ip; + struct ip_addr mask; + struct ip_addr gw; +} Event_StaMode_Got_IP_t; + +typedef struct { + uint8 mac[6]; + uint8 aid; +} Event_SoftAPMode_StaConnected_t; + +typedef struct { + uint8 mac[6]; + uint8 aid; +} Event_SoftAPMode_StaDisconnected_t; + +typedef union { + Event_StaMode_Connected_t connected; + Event_StaMode_Disconnected_t disconnected; + Event_StaMode_AuthMode_Change_t auth_change; + Event_StaMode_Got_IP_t got_ip; + Event_SoftAPMode_StaConnected_t sta_connected; + Event_SoftAPMode_StaDisconnected_t sta_disconnected; +} Event_Info_u; + +typedef struct _esp_event { + uint32 event; + Event_Info_u event_info; +} System_Event_t; + +typedef void (* wifi_event_handler_cb_t)(System_Event_t *event); + +void wifi_set_event_handler_cb(wifi_event_handler_cb_t cb); + +typedef enum wps_type { + WPS_TYPE_DISABLE = 0, + WPS_TYPE_PBC, + WPS_TYPE_PIN, + WPS_TYPE_DISPLAY, + WPS_TYPE_MAX, +} WPS_TYPE_t; + +enum wps_cb_status { + WPS_CB_ST_SUCCESS = 0, + WPS_CB_ST_FAILED, + WPS_CB_ST_TIMEOUT, + WPS_CB_ST_WEP, +}; + +bool wifi_wps_enable(WPS_TYPE_t wps_type); +bool wifi_wps_disable(void); +bool wifi_wps_start(void); + +typedef void (*wps_st_cb_t)(int status); +bool wifi_set_wps_cb(wps_st_cb_t cb); + +#endif diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.ld new file mode 100644 index 0000000..f600219 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.1024.app1.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.1024.app1.ld new file mode 100644 index 0000000..3a135f9 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.1024.app1.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 = 0x40201010, len = 0x6B000 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.1024.app2.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.1024.app2.ld new file mode 100644 index 0000000..4d5b56c --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.1024.app2.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 = 0x40281010, len = 0x6B000 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.2048.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.2048.ld new file mode 100644 index 0000000..1978c20 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.2048.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 = 0x40201010, len = 0xE0000 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.512.app1.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.512.app1.ld new file mode 100644 index 0000000..d24959d --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.512.app1.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 = 0x40201010, len = 0x2B000 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.512.app2.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.512.app2.ld new file mode 100644 index 0000000..1d7c9c7 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.new.512.app2.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 = 0x40241010, len = 0x2B000 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.1024.app1.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.1024.app1.ld new file mode 100644 index 0000000..e301463 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.1024.app1.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 = 0x40211000, len = 0x6B000 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.1024.app2.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.1024.app2.ld new file mode 100644 index 0000000..5c336ab --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.1024.app2.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 = 0x40291000, len = 0x6B000 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.512.app1.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.512.app1.ld new file mode 100644 index 0000000..27b4895 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.512.app1.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 = 0x40211000, len = 0x2B000 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.512.app2.ld b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.512.app2.ld new file mode 100644 index 0000000..20ab0aa --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.app.v6.old.512.app2.ld @@ -0,0 +1,211 @@ +/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* Linker Script for ld -N */ +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 = 0x40251000, len = 0x2B000 +} + +PHDRS +{ + dport0_0_phdr PT_LOAD; + dram0_0_phdr PT_LOAD; + dram0_0_bss_phdr PT_LOAD; + iram1_0_phdr PT_LOAD; + irom0_0_phdr PT_LOAD; +} + + +/* Default entry point: */ +ENTRY(call_user_start) +EXTERN(_DebugExceptionVector) +EXTERN(_DoubleExceptionVector) +EXTERN(_KernelExceptionVector) +EXTERN(_NMIExceptionVector) +EXTERN(_UserExceptionVector) +PROVIDE(_memmap_vecbase_reset = 0x40000000); +/* Various memory-map dependent cache attribute settings: */ +_memmap_cacheattr_wb_base = 0x00000110; +_memmap_cacheattr_wt_base = 0x00000110; +_memmap_cacheattr_bp_base = 0x00000220; +_memmap_cacheattr_unused_mask = 0xFFFFF00F; +_memmap_cacheattr_wb_trapnull = 0x2222211F; +_memmap_cacheattr_wba_trapnull = 0x2222211F; +_memmap_cacheattr_wbna_trapnull = 0x2222211F; +_memmap_cacheattr_wt_trapnull = 0x2222211F; +_memmap_cacheattr_bp_trapnull = 0x2222222F; +_memmap_cacheattr_wb_strict = 0xFFFFF11F; +_memmap_cacheattr_wt_strict = 0xFFFFF11F; +_memmap_cacheattr_bp_strict = 0xFFFFF22F; +_memmap_cacheattr_wb_allvalid = 0x22222112; +_memmap_cacheattr_wt_allvalid = 0x22222112; +_memmap_cacheattr_bp_allvalid = 0x22222222; +PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull); + +SECTIONS +{ + + .dport0.rodata : ALIGN(4) + { + _dport0_rodata_start = ABSOLUTE(.); + *(.dport0.rodata) + *(.dport.rodata) + _dport0_rodata_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.literal : ALIGN(4) + { + _dport0_literal_start = ABSOLUTE(.); + *(.dport0.literal) + *(.dport.literal) + _dport0_literal_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .dport0.data : ALIGN(4) + { + _dport0_data_start = ABSOLUTE(.); + *(.dport0.data) + *(.dport.data) + _dport0_data_end = ABSOLUTE(.); + } >dport0_0_seg :dport0_0_phdr + + .data : ALIGN(4) + { + _data_start = ABSOLUTE(.); + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.data1) + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + *(.jcr) + _data_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .rodata : ALIGN(4) + { + _rodata_start = ABSOLUTE(.); + *(.sdk.version) + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + /* C++ constructor and destructor tables, properly ordered: */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + /* C++ exception handlers table: */ + __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* this table MUST be 4-byte aligned */ + _bss_table_start = ABSOLUTE(.); + LONG(_bss_start) + LONG(_bss_end) + _bss_table_end = ABSOLUTE(.); + _rodata_end = ABSOLUTE(.); + } >dram0_0_seg :dram0_0_phdr + + .bss ALIGN(8) (NOLOAD) : ALIGN(4) + { + . = ALIGN (8); + _bss_start = ABSOLUTE(.); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN (8); + _bss_end = ABSOLUTE(.); + _heap_start = ABSOLUTE(.); +/* _stack_sentry = ALIGN(0x8); */ + } >dram0_0_seg :dram0_0_bss_phdr +/* __stack = 0x3ffc8000; */ + + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >iram1_0_seg :iram1_0_phdr + + .lit4 : ALIGN(4) + { + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _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) + _irom0_text_end = ABSOLUTE(.); + } >irom0_0_seg :irom0_0_phdr +} + +/* get ROM code address */ +INCLUDE "../ld/eagle.rom.addr.v6.ld" diff --git a/esp_iot_sdk_v1.3.0/ld/eagle.rom.addr.v6.ld b/esp_iot_sdk_v1.3.0/ld/eagle.rom.addr.v6.ld new file mode 100644 index 0000000..5613cfc --- /dev/null +++ b/esp_iot_sdk_v1.3.0/ld/eagle.rom.addr.v6.ld @@ -0,0 +1,347 @@ +PROVIDE ( Cache_Read_Disable = 0x400047f0 ); +PROVIDE ( Cache_Read_Enable = 0x40004678 ); +PROVIDE ( FilePacketSendReqMsgProc = 0x400035a0 ); +PROVIDE ( FlashDwnLdParamCfgMsgProc = 0x4000368c ); +PROVIDE ( FlashDwnLdStartMsgProc = 0x40003538 ); +PROVIDE ( FlashDwnLdStopReqMsgProc = 0x40003658 ); +PROVIDE ( GetUartDevice = 0x40003f4c ); +PROVIDE ( MD5Final = 0x40009900 ); +PROVIDE ( MD5Init = 0x40009818 ); +PROVIDE ( MD5Update = 0x40009834 ); +PROVIDE ( MemDwnLdStartMsgProc = 0x400036c4 ); +PROVIDE ( MemDwnLdStopReqMsgProc = 0x4000377c ); +PROVIDE ( MemPacketSendReqMsgProc = 0x400036f0 ); +PROVIDE ( RcvMsg = 0x40003eac ); +PROVIDE ( SHA1Final = 0x4000b648 ); +PROVIDE ( SHA1Init = 0x4000b584 ); +PROVIDE ( SHA1Transform = 0x4000a364 ); +PROVIDE ( SHA1Update = 0x4000b5a8 ); +PROVIDE ( SPI_read_status = 0x400043c8 ); +PROVIDE ( SPI_write_status = 0x40004400 ); +PROVIDE ( SPI_write_enable = 0x4000443c ); +PROVIDE ( Wait_SPI_Idle = 0x4000448c ); +PROVIDE ( SPIEraseArea = 0x40004b44 ); +PROVIDE ( SPIEraseBlock = 0x400049b4 ); +PROVIDE ( SPIEraseChip = 0x40004984 ); +PROVIDE ( SPIEraseSector = 0x40004a00 ); +PROVIDE ( SPILock = 0x400048a8 ); +PROVIDE ( SPIParamCfg = 0x40004c2c ); +PROVIDE ( SPIRead = 0x40004b1c ); +PROVIDE ( SPIReadModeCnfig = 0x400048ec ); +PROVIDE ( SPIUnlock = 0x40004878 ); +PROVIDE ( SPIWrite = 0x40004a4c ); +PROVIDE ( SelectSpiFunction = 0x40003f58 ); +PROVIDE ( SendMsg = 0x40003cf4 ); +PROVIDE ( UartConnCheck = 0x40003230 ); +PROVIDE ( UartConnectProc = 0x400037a0 ); +PROVIDE ( UartDwnLdProc = 0x40003368 ); +PROVIDE ( UartGetCmdLn = 0x40003ef4 ); +PROVIDE ( UartRegReadProc = 0x4000381c ); +PROVIDE ( UartRegWriteProc = 0x400037ac ); +PROVIDE ( UartRxString = 0x40003c30 ); +PROVIDE ( Uart_Init = 0x40003a14 ); +PROVIDE ( _DebugExceptionVector = 0x40000010 ); +PROVIDE ( _DoubleExceptionVector = 0x40000070 ); +PROVIDE ( _KernelExceptionVector = 0x40000030 ); +PROVIDE ( _NMIExceptionVector = 0x40000020 ); +PROVIDE ( _ResetHandler = 0x400000a4 ); +PROVIDE ( _ResetVector = 0x40000080 ); +PROVIDE ( _UserExceptionVector = 0x40000050 ); +PROVIDE ( __adddf3 = 0x4000c538 ); +PROVIDE ( __addsf3 = 0x4000c180 ); +PROVIDE ( __divdf3 = 0x4000cb94 ); +PROVIDE ( __divdi3 = 0x4000ce60 ); +PROVIDE ( __divsi3 = 0x4000dc88 ); +PROVIDE ( __extendsfdf2 = 0x4000cdfc ); +PROVIDE ( __fixdfsi = 0x4000ccb8 ); +PROVIDE ( __fixunsdfsi = 0x4000cd00 ); +PROVIDE ( __fixunssfsi = 0x4000c4c4 ); +PROVIDE ( __floatsidf = 0x4000e2f0 ); +PROVIDE ( __floatsisf = 0x4000e2ac ); +PROVIDE ( __floatunsidf = 0x4000e2e8 ); +PROVIDE ( __floatunsisf = 0x4000e2a4 ); +PROVIDE ( __muldf3 = 0x4000c8f0 ); +PROVIDE ( __muldi3 = 0x40000650 ); +PROVIDE ( __mulsf3 = 0x4000c3dc ); +PROVIDE ( __subdf3 = 0x4000c688 ); +PROVIDE ( __subsf3 = 0x4000c268 ); +PROVIDE ( __truncdfsf2 = 0x4000cd5c ); +PROVIDE ( __udivdi3 = 0x4000d310 ); +PROVIDE ( __udivsi3 = 0x4000e21c ); +PROVIDE ( __umoddi3 = 0x4000d770 ); +PROVIDE ( __umodsi3 = 0x4000e268 ); +PROVIDE ( __umulsidi3 = 0x4000dcf0 ); +PROVIDE ( _rom_store = 0x4000e388 ); +PROVIDE ( _rom_store_table = 0x4000e328 ); +PROVIDE ( _start = 0x4000042c ); +PROVIDE ( _xtos_alloca_handler = 0x4000dbe0 ); +PROVIDE ( _xtos_c_wrapper_handler = 0x40000598 ); +PROVIDE ( _xtos_cause3_handler = 0x40000590 ); +PROVIDE ( _xtos_ints_off = 0x4000bda4 ); +PROVIDE ( _xtos_ints_on = 0x4000bd84 ); +PROVIDE ( _xtos_l1int_handler = 0x4000048c ); +PROVIDE ( _xtos_p_none = 0x4000dbf8 ); +PROVIDE ( _xtos_restore_intlevel = 0x4000056c ); +PROVIDE ( _xtos_return_from_exc = 0x4000dc54 ); +PROVIDE ( _xtos_set_exception_handler = 0x40000454 ); +PROVIDE ( _xtos_set_interrupt_handler = 0x4000bd70 ); +PROVIDE ( _xtos_set_interrupt_handler_arg = 0x4000bd28 ); +PROVIDE ( _xtos_set_intlevel = 0x4000dbfc ); +PROVIDE ( _xtos_set_min_intlevel = 0x4000dc18 ); +PROVIDE ( _xtos_set_vpri = 0x40000574 ); +PROVIDE ( _xtos_syscall_handler = 0x4000dbe4 ); +PROVIDE ( _xtos_unhandled_exception = 0x4000dc44 ); +PROVIDE ( _xtos_unhandled_interrupt = 0x4000dc3c ); +PROVIDE ( aes_decrypt = 0x400092d4 ); +PROVIDE ( aes_decrypt_deinit = 0x400092e4 ); +PROVIDE ( aes_decrypt_init = 0x40008ea4 ); +PROVIDE ( aes_unwrap = 0x40009410 ); +PROVIDE ( base64_decode = 0x40009648 ); +PROVIDE ( base64_encode = 0x400094fc ); +PROVIDE ( bzero = 0x4000de84 ); +PROVIDE ( cmd_parse = 0x40000814 ); +PROVIDE ( conv_str_decimal = 0x40000b24 ); +PROVIDE ( conv_str_hex = 0x40000cb8 ); +PROVIDE ( convert_para_str = 0x40000a60 ); +PROVIDE ( dtm_get_intr_mask = 0x400026d0 ); +PROVIDE ( dtm_params_init = 0x4000269c ); +PROVIDE ( dtm_set_intr_mask = 0x400026c8 ); +PROVIDE ( dtm_set_params = 0x400026dc ); +PROVIDE ( eprintf = 0x40001d14 ); +PROVIDE ( eprintf_init_buf = 0x40001cb8 ); +PROVIDE ( eprintf_to_host = 0x40001d48 ); +PROVIDE ( est_get_printf_buf_remain_len = 0x40002494 ); +PROVIDE ( est_reset_printf_buf_len = 0x4000249c ); +PROVIDE ( ets_bzero = 0x40002ae8 ); +PROVIDE ( ets_char2xdigit = 0x40002b74 ); +PROVIDE ( ets_delay_us = 0x40002ecc ); +PROVIDE ( ets_enter_sleep = 0x400027b8 ); +PROVIDE ( ets_external_printf = 0x40002578 ); +PROVIDE ( ets_get_cpu_frequency = 0x40002f0c ); +PROVIDE ( ets_getc = 0x40002bcc ); +PROVIDE ( ets_install_external_printf = 0x40002450 ); +PROVIDE ( ets_install_putc1 = 0x4000242c ); +PROVIDE ( ets_install_putc2 = 0x4000248c ); +PROVIDE ( ets_install_uart_printf = 0x40002438 ); +PROVIDE ( ets_intr_lock = 0x40000f74 ); +PROVIDE ( ets_intr_unlock = 0x40000f80 ); +PROVIDE ( ets_isr_attach = 0x40000f88 ); +PROVIDE ( ets_isr_mask = 0x40000f98 ); +PROVIDE ( ets_isr_unmask = 0x40000fa8 ); +PROVIDE ( ets_memcmp = 0x400018d4 ); +PROVIDE ( ets_memcpy = 0x400018b4 ); +PROVIDE ( ets_memmove = 0x400018c4 ); +PROVIDE ( ets_memset = 0x400018a4 ); +PROVIDE ( ets_post = 0x40000e24 ); +PROVIDE ( ets_printf = 0x400024cc ); +PROVIDE ( ets_putc = 0x40002be8 ); +PROVIDE ( ets_rtc_int_register = 0x40002a40 ); +PROVIDE ( ets_run = 0x40000e04 ); +PROVIDE ( ets_set_idle_cb = 0x40000dc0 ); +PROVIDE ( ets_set_user_start = 0x40000fbc ); +PROVIDE ( ets_str2macaddr = 0x40002af8 ); +PROVIDE ( ets_strcmp = 0x40002aa8 ); +PROVIDE ( ets_strcpy = 0x40002a88 ); +PROVIDE ( ets_strlen = 0x40002ac8 ); +PROVIDE ( ets_strncmp = 0x40002ab8 ); +PROVIDE ( ets_strncpy = 0x40002a98 ); +PROVIDE ( ets_strstr = 0x40002ad8 ); +PROVIDE ( ets_task = 0x40000dd0 ); +PROVIDE ( ets_timer_arm = 0x40002cc4 ); +PROVIDE ( ets_timer_disarm = 0x40002d40 ); +PROVIDE ( ets_timer_done = 0x40002d80 ); +PROVIDE ( ets_timer_handler_isr = 0x40002da8 ); +PROVIDE ( ets_timer_init = 0x40002e68 ); +PROVIDE ( ets_timer_setfn = 0x40002c48 ); +PROVIDE ( ets_uart_printf = 0x40002544 ); +PROVIDE ( ets_update_cpu_frequency = 0x40002f04 ); +PROVIDE ( ets_vprintf = 0x40001f00 ); +PROVIDE ( ets_wdt_disable = 0x400030f0 ); +PROVIDE ( ets_wdt_enable = 0x40002fa0 ); +PROVIDE ( ets_wdt_get_mode = 0x40002f34 ); +PROVIDE ( ets_wdt_init = 0x40003170 ); +PROVIDE ( ets_wdt_restore = 0x40003158 ); +PROVIDE ( ets_write_char = 0x40001da0 ); +PROVIDE ( get_first_seg = 0x4000091c ); +PROVIDE ( gpio_init = 0x40004c50 ); +PROVIDE ( gpio_input_get = 0x40004cf0 ); +PROVIDE ( gpio_intr_ack = 0x40004dcc ); +PROVIDE ( gpio_intr_handler_register = 0x40004e28 ); +PROVIDE ( gpio_intr_pending = 0x40004d88 ); +PROVIDE ( gpio_intr_test = 0x40004efc ); +PROVIDE ( gpio_output_set = 0x40004cd0 ); +PROVIDE ( gpio_pin_intr_state_set = 0x40004d90 ); +PROVIDE ( gpio_pin_wakeup_disable = 0x40004ed4 ); +PROVIDE ( gpio_pin_wakeup_enable = 0x40004e90 ); +PROVIDE ( gpio_register_get = 0x40004d5c ); +PROVIDE ( gpio_register_set = 0x40004d04 ); +PROVIDE ( hmac_md5 = 0x4000a2cc ); +PROVIDE ( hmac_md5_vector = 0x4000a160 ); +PROVIDE ( hmac_sha1 = 0x4000ba28 ); +PROVIDE ( hmac_sha1_vector = 0x4000b8b4 ); +PROVIDE ( lldesc_build_chain = 0x40004f40 ); +PROVIDE ( lldesc_num2link = 0x40005050 ); +PROVIDE ( lldesc_set_owner = 0x4000507c ); +PROVIDE ( main = 0x40000fec ); +PROVIDE ( md5_vector = 0x400097ac ); +PROVIDE ( mem_calloc = 0x40001c2c ); +PROVIDE ( mem_free = 0x400019e0 ); +PROVIDE ( mem_init = 0x40001998 ); +PROVIDE ( mem_malloc = 0x40001b40 ); +PROVIDE ( mem_realloc = 0x40001c6c ); +PROVIDE ( mem_trim = 0x40001a14 ); +PROVIDE ( mem_zalloc = 0x40001c58 ); +PROVIDE ( memcmp = 0x4000dea8 ); +PROVIDE ( memcpy = 0x4000df48 ); +PROVIDE ( memmove = 0x4000e04c ); +PROVIDE ( memset = 0x4000e190 ); +PROVIDE ( multofup = 0x400031c0 ); +PROVIDE ( pbkdf2_sha1 = 0x4000b840 ); +PROVIDE ( phy_get_romfuncs = 0x40006b08 ); +PROVIDE ( rand = 0x40000600 ); +PROVIDE ( rc4_skip = 0x4000dd68 ); +PROVIDE ( recv_packet = 0x40003d08 ); +PROVIDE ( remove_head_space = 0x40000a04 ); +PROVIDE ( rijndaelKeySetupDec = 0x40008dd0 ); +PROVIDE ( rijndaelKeySetupEnc = 0x40009300 ); +PROVIDE ( rom_abs_temp = 0x400060c0 ); +PROVIDE ( rom_ana_inf_gating_en = 0x40006b10 ); +PROVIDE ( rom_cal_tos_v50 = 0x40007a28 ); +PROVIDE ( rom_chip_50_set_channel = 0x40006f84 ); +PROVIDE ( rom_chip_v5_disable_cca = 0x400060d0 ); +PROVIDE ( rom_chip_v5_enable_cca = 0x400060ec ); +PROVIDE ( rom_chip_v5_rx_init = 0x4000711c ); +PROVIDE ( rom_chip_v5_sense_backoff = 0x4000610c ); +PROVIDE ( rom_chip_v5_tx_init = 0x4000718c ); +PROVIDE ( rom_dc_iq_est = 0x4000615c ); +PROVIDE ( rom_en_pwdet = 0x400061b8 ); +PROVIDE ( rom_get_bb_atten = 0x40006238 ); +PROVIDE ( rom_get_corr_power = 0x40006260 ); +PROVIDE ( rom_get_fm_sar_dout = 0x400062dc ); +PROVIDE ( rom_get_noisefloor = 0x40006394 ); +PROVIDE ( rom_get_power_db = 0x400063b0 ); +PROVIDE ( rom_i2c_readReg = 0x40007268 ); +PROVIDE ( rom_i2c_readReg_Mask = 0x4000729c ); +PROVIDE ( rom_i2c_writeReg = 0x400072d8 ); +PROVIDE ( rom_i2c_writeReg_Mask = 0x4000730c ); +PROVIDE ( rom_iq_est_disable = 0x40006400 ); +PROVIDE ( rom_iq_est_enable = 0x40006430 ); +PROVIDE ( rom_linear_to_db = 0x40006484 ); +PROVIDE ( rom_mhz2ieee = 0x400065a4 ); +PROVIDE ( rom_pbus_dco___SA2 = 0x40007bf0 ); +PROVIDE ( rom_pbus_debugmode = 0x4000737c ); +PROVIDE ( rom_pbus_enter_debugmode = 0x40007410 ); +PROVIDE ( rom_pbus_exit_debugmode = 0x40007448 ); +PROVIDE ( rom_pbus_force_test = 0x4000747c ); +PROVIDE ( rom_pbus_rd = 0x400074d8 ); +PROVIDE ( rom_pbus_set_rxgain = 0x4000754c ); +PROVIDE ( rom_pbus_set_txgain = 0x40007610 ); +PROVIDE ( rom_pbus_workmode = 0x40007648 ); +PROVIDE ( rom_pbus_xpd_rx_off = 0x40007688 ); +PROVIDE ( rom_pbus_xpd_rx_on = 0x400076cc ); +PROVIDE ( rom_pbus_xpd_tx_off = 0x400076fc ); +PROVIDE ( rom_pbus_xpd_tx_on = 0x40007740 ); +PROVIDE ( rom_pbus_xpd_tx_on__low_gain = 0x400077a0 ); +PROVIDE ( rom_phy_reset_req = 0x40007804 ); +PROVIDE ( rom_restart_cal = 0x4000781c ); +PROVIDE ( rom_rfcal_pwrctrl = 0x40007eb4 ); +PROVIDE ( rom_rfcal_rxiq = 0x4000804c ); +PROVIDE ( rom_rfcal_rxiq_set_reg = 0x40008264 ); +PROVIDE ( rom_rfcal_txcap = 0x40008388 ); +PROVIDE ( rom_rfcal_txiq = 0x40008610 ); +PROVIDE ( rom_rfcal_txiq_cover = 0x400088b8 ); +PROVIDE ( rom_rfcal_txiq_set_reg = 0x40008a70 ); +PROVIDE ( rom_rfpll_reset = 0x40007868 ); +PROVIDE ( rom_rfpll_set_freq = 0x40007968 ); +PROVIDE ( rom_rxiq_cover_mg_mp = 0x40008b6c ); +PROVIDE ( rom_rxiq_get_mis = 0x40006628 ); +PROVIDE ( rom_sar_init = 0x40006738 ); +PROVIDE ( rom_set_ana_inf_tx_scale = 0x4000678c ); +PROVIDE ( rom_set_channel_freq = 0x40006c50 ); +PROVIDE ( rom_set_loopback_gain = 0x400067c8 ); +PROVIDE ( rom_set_noise_floor = 0x40006830 ); +PROVIDE ( rom_set_rxclk_en = 0x40006550 ); +PROVIDE ( rom_set_txbb_atten = 0x40008c6c ); +PROVIDE ( rom_set_txclk_en = 0x4000650c ); +PROVIDE ( rom_set_txiq_cal = 0x40008d34 ); +PROVIDE ( rom_start_noisefloor = 0x40006874 ); +PROVIDE ( rom_start_tx_tone = 0x400068b4 ); +PROVIDE ( rom_stop_tx_tone = 0x4000698c ); +PROVIDE ( rom_tx_mac_disable = 0x40006a98 ); +PROVIDE ( rom_tx_mac_enable = 0x40006ad4 ); +PROVIDE ( rom_txtone_linear_pwr = 0x40006a1c ); +PROVIDE ( rom_write_rfpll_sdm = 0x400078dc ); +PROVIDE ( roundup2 = 0x400031b4 ); +PROVIDE ( rtc_enter_sleep = 0x40002870 ); +PROVIDE ( rtc_get_reset_reason = 0x400025e0 ); +PROVIDE ( rtc_intr_handler = 0x400029ec ); +PROVIDE ( rtc_set_sleep_mode = 0x40002668 ); +PROVIDE ( save_rxbcn_mactime = 0x400027a4 ); +PROVIDE ( save_tsf_us = 0x400027ac ); +PROVIDE ( send_packet = 0x40003c80 ); +PROVIDE ( sha1_prf = 0x4000ba48 ); +PROVIDE ( sha1_vector = 0x4000a2ec ); +PROVIDE ( sip_alloc_to_host_evt = 0x40005180 ); +PROVIDE ( sip_get_ptr = 0x400058a8 ); +PROVIDE ( sip_get_state = 0x40005668 ); +PROVIDE ( sip_init_attach = 0x4000567c ); +PROVIDE ( sip_install_rx_ctrl_cb = 0x4000544c ); +PROVIDE ( sip_install_rx_data_cb = 0x4000545c ); +PROVIDE ( sip_post = 0x400050fc ); +PROVIDE ( sip_post_init = 0x400056c4 ); +PROVIDE ( sip_reclaim_from_host_cmd = 0x4000534c ); +PROVIDE ( sip_reclaim_tx_data_pkt = 0x400052c0 ); +PROVIDE ( sip_send = 0x40005808 ); +PROVIDE ( sip_to_host_chain_append = 0x40005864 ); +PROVIDE ( sip_to_host_evt_send_done = 0x40005234 ); +PROVIDE ( slc_add_credits = 0x400060ac ); +PROVIDE ( slc_enable = 0x40005d90 ); +PROVIDE ( slc_from_host_chain_fetch = 0x40005f24 ); +PROVIDE ( slc_from_host_chain_recycle = 0x40005e94 ); +PROVIDE ( slc_init_attach = 0x40005c50 ); +PROVIDE ( slc_init_credit = 0x4000608c ); +PROVIDE ( slc_pause_from_host = 0x40006014 ); +PROVIDE ( slc_reattach = 0x40005c1c ); +PROVIDE ( slc_resume_from_host = 0x4000603c ); +PROVIDE ( slc_select_tohost_gpio = 0x40005dc0 ); +PROVIDE ( slc_select_tohost_gpio_mode = 0x40005db8 ); +PROVIDE ( slc_send_to_host_chain = 0x40005de4 ); +PROVIDE ( slc_set_host_io_max_window = 0x40006068 ); +PROVIDE ( slc_to_host_chain_recycle = 0x40005f10 ); +PROVIDE ( software_reset = 0x4000264c ); +PROVIDE ( spi_flash_attach = 0x40004644 ); +PROVIDE ( srand = 0x400005f0 ); +PROVIDE ( strcmp = 0x4000bdc8 ); +PROVIDE ( strcpy = 0x4000bec8 ); +PROVIDE ( strlen = 0x4000bf4c ); +PROVIDE ( strncmp = 0x4000bfa8 ); +PROVIDE ( strncpy = 0x4000c0a0 ); +PROVIDE ( strstr = 0x4000e1e0 ); +PROVIDE ( timer_insert = 0x40002c64 ); +PROVIDE ( uartAttach = 0x4000383c ); +PROVIDE ( uart_baudrate_detect = 0x40003924 ); +PROVIDE ( uart_buff_switch = 0x400038a4 ); +PROVIDE ( uart_div_modify = 0x400039d8 ); +PROVIDE ( uart_rx_intr_handler = 0x40003bbc ); +PROVIDE ( uart_rx_one_char = 0x40003b8c ); +PROVIDE ( uart_rx_one_char_block = 0x40003b64 ); +PROVIDE ( uart_rx_readbuff = 0x40003ec8 ); +PROVIDE ( uart_tx_one_char = 0x40003b30 ); +PROVIDE ( wepkey_128 = 0x4000bc40 ); +PROVIDE ( wepkey_64 = 0x4000bb3c ); +PROVIDE ( xthal_bcopy = 0x40000688 ); +PROVIDE ( xthal_copy123 = 0x4000074c ); +PROVIDE ( xthal_get_ccompare = 0x4000dd4c ); +PROVIDE ( xthal_get_ccount = 0x4000dd38 ); +PROVIDE ( xthal_get_interrupt = 0x4000dd58 ); +PROVIDE ( xthal_get_intread = 0x4000dd58 ); +PROVIDE ( xthal_memcpy = 0x400006c4 ); +PROVIDE ( xthal_set_ccompare = 0x4000dd40 ); +PROVIDE ( xthal_set_intclear = 0x4000dd60 ); +PROVIDE ( xthal_spill_registers_into_stack_nw = 0x4000e320 ); +PROVIDE ( xthal_window_spill = 0x4000e324 ); +PROVIDE ( xthal_window_spill_nw = 0x4000e320 ); + +PROVIDE ( Te0 = 0x3fffccf0 ); +PROVIDE ( UartDev = 0x3fffde10 ); +PROVIDE ( flashchip = 0x3fffc714); diff --git a/esp_iot_sdk_v1.3.0/lib/libat.a b/esp_iot_sdk_v1.3.0/lib/libat.a new file mode 100644 index 0000000..eafb08d Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libat.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libcrypto.a b/esp_iot_sdk_v1.3.0/lib/libcrypto.a new file mode 100644 index 0000000..d24bf9f Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libcrypto.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libespnow.a b/esp_iot_sdk_v1.3.0/lib/libespnow.a new file mode 100644 index 0000000..f6952d3 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libespnow.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libjson.a b/esp_iot_sdk_v1.3.0/lib/libjson.a new file mode 100644 index 0000000..99d4e33 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libjson.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/liblwip.a b/esp_iot_sdk_v1.3.0/lib/liblwip.a new file mode 100644 index 0000000..180e460 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/liblwip.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/liblwip_536.a b/esp_iot_sdk_v1.3.0/lib/liblwip_536.a new file mode 100644 index 0000000..46f08d5 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/liblwip_536.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libmain.a b/esp_iot_sdk_v1.3.0/lib/libmain.a new file mode 100644 index 0000000..e5b1c20 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libmain.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libnet80211.a b/esp_iot_sdk_v1.3.0/lib/libnet80211.a new file mode 100644 index 0000000..2051f94 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libnet80211.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libphy.a b/esp_iot_sdk_v1.3.0/lib/libphy.a new file mode 100644 index 0000000..0f2fdbd Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libphy.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libpp.a b/esp_iot_sdk_v1.3.0/lib/libpp.a new file mode 100644 index 0000000..5d5b3b7 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libpp.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libpwm.a b/esp_iot_sdk_v1.3.0/lib/libpwm.a new file mode 100644 index 0000000..1913f16 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libpwm.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libsmartconfig.a b/esp_iot_sdk_v1.3.0/lib/libsmartconfig.a new file mode 100644 index 0000000..7fc7b1c Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libsmartconfig.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libssl.a b/esp_iot_sdk_v1.3.0/lib/libssl.a new file mode 100644 index 0000000..8ba48e1 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libssl.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libupgrade.a b/esp_iot_sdk_v1.3.0/lib/libupgrade.a new file mode 100644 index 0000000..f8ca292 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libupgrade.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libwpa.a b/esp_iot_sdk_v1.3.0/lib/libwpa.a new file mode 100644 index 0000000..d22039e Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libwpa.a differ diff --git a/esp_iot_sdk_v1.3.0/lib/libwps.a b/esp_iot_sdk_v1.3.0/lib/libwps.a new file mode 100644 index 0000000..ea1deeb Binary files /dev/null and b/esp_iot_sdk_v1.3.0/lib/libwps.a differ diff --git a/esp_iot_sdk_v1.3.0/tools/gen_appbin.py b/esp_iot_sdk_v1.3.0/tools/gen_appbin.py new file mode 100644 index 0000000..f751cb4 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/tools/gen_appbin.py @@ -0,0 +1,273 @@ +#!/usr/bin/python +# +# File : gen_appbin.py +# This file is part of Espressif's generate bin script. +# Copyright (C) 2013 - 2016, Espressif Systems +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of version 3 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""This file is part of Espressif's generate bin script. + argv[1] is elf file name + argv[2] is version num""" + +import string +import sys +import os +import re +import binascii +import struct +import zlib + + +TEXT_ADDRESS = 0x40100000 +# app_entry = 0 +# data_address = 0x3ffb0000 +# data_end = 0x40000000 +# text_end = 0x40120000 + +CHECKSUM_INIT = 0xEF + +chk_sum = CHECKSUM_INIT +blocks = 0 + +def write_file(file_name,data): + if file_name is None: + print 'file_name cannot be none\n' + sys.exit(0) + + fp = open(file_name,'ab') + + if fp: + fp.seek(0,os.SEEK_END) + fp.write(data) + fp.close() + else: + print '%s write fail\n'%(file_name) + +def combine_bin(file_name,dest_file_name,start_offset_addr,need_chk): + global chk_sum + global blocks + if dest_file_name is None: + print 'dest_file_name cannot be none\n' + sys.exit(0) + + if file_name: + fp = open(file_name,'rb') + if fp: + ########## write text ########## + fp.seek(0,os.SEEK_END) + data_len = fp.tell() + if data_len: + if need_chk: + tmp_len = (data_len + 3) & (~3) + else: + tmp_len = (data_len + 15) & (~15) + data_bin = struct.pack(' eagle.app.sym' + else : + cmd = 'xt-nm -g ' + elf_file + ' > eagle.app.sym' + + os.system(cmd) + + fp = file('./eagle.app.sym') + if fp is None: + print "open sym file error\n" + sys.exit(0) + + lines = fp.readlines() + fp.close() + + entry_addr = None + p = re.compile('(\w*)(\sT\s)(call_user_start)$') + for line in lines: + m = p.search(line) + if m != None: + entry_addr = m.group(1) + # print entry_addr + + if entry_addr is None: + print 'no entry point!!' + sys.exit(0) + + data_start_addr = '0' + p = re.compile('(\w*)(\sA\s)(_data_start)$') + for line in lines: + m = p.search(line) + if m != None: + data_start_addr = m.group(1) + # print data_start_addr + + rodata_start_addr = '0' + p = re.compile('(\w*)(\sA\s)(_rodata_start)$') + for line in lines: + m = p.search(line) + if m != None: + rodata_start_addr = m.group(1) + # print rodata_start_addr + + # write flash bin header + #============================ + # SPI FLASH PARAMS + #------------------- + #flash_mode= + # 0: QIO + # 1: QOUT + # 2: DIO + # 3: DOUT + #------------------- + #flash_clk_div= + # 0 : 80m / 2 + # 1 : 80m / 3 + # 2 : 80m / 4 + # 0xf: 80m / 1 + #------------------- + #flash_size_map= + # 0 : 512 KB (256 KB + 256 KB) + # 1 : 256 KB + # 2 : 1024 KB (512 KB + 512 KB) + # 3 : 2048 KB (512 KB + 512 KB) + # 4 : 4096 KB (512 KB + 512 KB) + # 5 : 2048 KB (1024 KB + 1024 KB) + # 6 : 4096 KB (1024 KB + 1024 KB) + #------------------- + # END OF SPI FLASH PARAMS + #============================ + byte2=int(flash_mode)&0xff + byte3=(((int(flash_size_map)<<4)| int(flash_clk_div))&0xff) + + if boot_mode == '2': + # write irom bin head + data_bin = struct.pack('> 8)+chr((all_bin_crc & 0x00FF0000) >> 16)+chr((all_bin_crc & 0xFF000000) >> 24)) + cmd = 'rm eagle.app.sym' + os.system(cmd) + +if __name__=='__main__': + gen_appbin() diff --git a/esp_iot_sdk_v1.3.0/tools/make_cert.py b/esp_iot_sdk_v1.3.0/tools/make_cert.py new file mode 100644 index 0000000..b417dce --- /dev/null +++ b/esp_iot_sdk_v1.3.0/tools/make_cert.py @@ -0,0 +1,42 @@ +import os + + +class Cert(object): + def __init__(self, name, buff): + self.name = name + self.len = len(buff) + self.buff = buff + pass + + def __str__(self): + out_str = ['\0']*32 + for i in range(len(self.name)): + out_str[i] = self.name[i] + out_str = "".join(out_str) + out_str += str(chr(self.len & 0xFF)) + out_str += str(chr((self.len & 0xFF00) >> 8)) + out_str += self.buff + return out_str + pass + + +def main(): + cert_list = [] + file_list = os.listdir(os.getcwd()) + cert_file_list = [] + for _file in file_list: + pos = _file.find(".cer") + if pos != -1: + cert_file_list.append(_file[:pos]) + + for cert_file in cert_file_list: + with open(cert_file+".cer", 'rb') as f: + buff = f.read() + cert_list.append(Cert(cert_file, buff)) + with open('esp_ca_cert.bin', 'wb+') as f: + for _cert in cert_list: + f.write("%s" % _cert) + pass +if __name__ == '__main__': + main() + diff --git a/esp_iot_sdk_v1.3.0/tools/makefile.sh b/esp_iot_sdk_v1.3.0/tools/makefile.sh new file mode 100644 index 0000000..df37d51 --- /dev/null +++ b/esp_iot_sdk_v1.3.0/tools/makefile.sh @@ -0,0 +1,92 @@ +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the axTLS project nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +# +# Generate the certificates and keys for testing. +# + +PROJECT_NAME="TLS Project" + +# Generate the openssl configuration files. +cat > ca_cert.conf << EOF +[ req ] +distinguished_name = req_distinguished_name +prompt = no + +[ req_distinguished_name ] + O = $PROJECT_NAME Dodgy Certificate Authority +EOF + +cat > certs.conf << EOF +[ req ] +distinguished_name = req_distinguished_name +prompt = no + +[ req_distinguished_name ] + O = $PROJECT_NAME + CN = 127.0.0.1 +EOF + +cat > device_cert.conf << EOF +[ req ] +distinguished_name = req_distinguished_name +prompt = no + +[ req_distinguished_name ] + O = $PROJECT_NAME Device Certificate +EOF + +# private key generation +openssl genrsa -out TLS.ca_key.pem 1024 +openssl genrsa -out TLS.key_1024.pem 1024 + +# convert private keys into DER format +openssl rsa -in TLS.key_1024.pem -out TLS.key_1024 -outform DER + +# cert requests +openssl req -out TLS.ca_x509.req -key TLS.ca_key.pem -new \ + -config ./ca_cert.conf +openssl req -out TLS.x509_1024.req -key TLS.key_1024.pem -new \ + -config ./certs.conf + +# generate the actual certs. +openssl x509 -req -in TLS.ca_x509.req -out TLS.ca_x509.pem \ + -sha1 -days 5000 -signkey TLS.ca_key.pem +openssl x509 -req -in TLS.x509_1024.req -out TLS.x509_1024.pem \ + -sha1 -CAcreateserial -days 5000 \ + -CA TLS.ca_x509.pem -CAkey TLS.ca_key.pem + +# some cleanup +rm TLS*.req +rm *.conf + +openssl x509 -in TLS.ca_x509.pem -outform DER -out TLS.ca_x509.cer +openssl x509 -in TLS.x509_1024.pem -outform DER -out TLS.x509_1024.cer + +# +# Generate the certificates and keys for encrypt. +# + +# set default cert for use in the client +xxd -i TLS.x509_1024.cer | sed -e \ + "s/TLS_x509_1024_cer/default_certificate/" > cert.h +# set default key for use in the server +xxd -i TLS.key_1024 | sed -e \ + "s/TLS_key_1024/default_private_key/" > private_key.h diff --git a/esp_iot_sdk_v1.3.0/tools/xxd.exe b/esp_iot_sdk_v1.3.0/tools/xxd.exe new file mode 100644 index 0000000..d102b46 Binary files /dev/null and b/esp_iot_sdk_v1.3.0/tools/xxd.exe differ