Unverified Commit 310faf7f authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

Merge pull request #2886 from nodemcu/dev

Next master drop
parents 68c425c0 a08e74d9
...@@ -6,6 +6,7 @@ local/ ...@@ -6,6 +6,7 @@ local/
user_config.h user_config.h
server-ca.crt server-ca.crt
luac.cross luac.cross
luac.cross.int
uz_unzip uz_unzip
uz_zip uz_zip
tools/toolchains/ tools/toolchains/
...@@ -14,3 +15,7 @@ tools/toolchains/ ...@@ -14,3 +15,7 @@ tools/toolchains/
.cproject .cproject
.project .project
.settings/ .settings/
.vscode
#ignore temp file for build infos
buildinfo.h
#os:
# - windows
# - linux
language: cpp language: cpp
matrix:
include:
- os: linux
env:
- OS="$TRAVIS_OS_NAME"
- LUACC=./luac.cross
- os: windows
env:
- MSBUILD_PATH="c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
- OS="$TRAVIS_OS_NAME"
- LUACC=msvc/luac-cross/x64/Debug/luac.cross.exe
addons: addons:
apt: apt:
packages: packages:
...@@ -8,16 +24,13 @@ cache: ...@@ -8,16 +24,13 @@ cache:
- directories: - directories:
- cache - cache
script: script:
- export BUILD_DATE=$(date +%Y%m%d) - echo OS is $OS $TRAVIS_OS_NAME
- make EXTRA_CCFLAGS="-DBUILD_DATE='\"'$BUILD_DATE'\"'" all
- cd bin/
- file_name_float="nodemcu_float_${TRAVIS_TAG}.bin"
- srec_cat -output ${file_name_float} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
- cd ../
- make clean
- make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL -DBUILD_DATE='\"'$BUILD_DATE'\"'"
- cd bin/
- file_name_integer="nodemcu_integer_${TRAVIS_TAG}.bin"
- srec_cat -output ${file_name_integer} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
# http://docs.travis-ci.com/user/environment-variables/#Convenience-Variables # http://docs.travis-ci.com/user/environment-variables/#Convenience-Variables
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/pr-build.sh; fi - if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-linux.sh; fi
- if [ "$OS" = "windows" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-windows-ms.sh; fi
- if [ "$OS" = "linux" -a "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/pr-build.sh; fi
- cd "$TRAVIS_BUILD_DIR"
- echo "checking:"
- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo
- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 $LUACC -p
# - if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/run-luacheck.sh || true ; fi
...@@ -26,6 +26,13 @@ Use the platform and tools you feel most comfortable with. There are no constrai ...@@ -26,6 +26,13 @@ Use the platform and tools you feel most comfortable with. There are no constrai
- [Full-fledged Linux environment](http://www.esp8266.com/wiki/doku.php?id=toolchain#how_to_setup_a_vm_to_host_your_toolchain), either physical or virtual. - [Full-fledged Linux environment](http://www.esp8266.com/wiki/doku.php?id=toolchain#how_to_setup_a_vm_to_host_your_toolchain), either physical or virtual.
- [Docker image](https://hub.docker.com/r/marcelstoer/nodemcu-build/) which allows running the build inside the container as if you were running a build script on your local machine. - [Docker image](https://hub.docker.com/r/marcelstoer/nodemcu-build/) which allows running the build inside the container as if you were running a build script on your local machine.
## Writing Lua Code
A great resource about writing Lua for NodeMCU can be found in [Lua Developer FAQ](https://nodemcu.readthedocs.io/en/latest/lua-developer-faq/) - make sure to read it! When you're writing your Lua code and it's not working as it should you can test it with `luacheck` tool that can help you find various types of bugs. To install it you have to install [luarocks](https://luarocks.org/) and use command `sudo luarocks install luacheck` to install the tool. Now you're ready to go! By using this command (assuming you're in `nodemcu-firmware` directory):
`luacheck --config tools/luacheck_config.lua <your file to check>`
you can look for bugs and problems within the code!
## Writing Documentation ## Writing Documentation
The NodeMCU documentation is maintained within the same repository as the code. The primary reason is to keep the two in sync more easily. It's thus trivial for the NodeMCU team to verify that a PR includes the necessary documentation. Furthermore, the documentation is merged automatically with the code if it moves from branch X to Y. The NodeMCU documentation is maintained within the same repository as the code. The primary reason is to keep the two in sync more easily. It's thus trivial for the NodeMCU team to verify that a PR includes the necessary documentation. Furthermore, the documentation is merged automatically with the code if it moves from branch X to Y.
......
...@@ -2,29 +2,42 @@ ...@@ -2,29 +2,42 @@
# #
.NOTPARALLEL: .NOTPARALLEL:
TOOLCHAIN_VERSION:=20181106.0 TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
# SDK base version, as released by Espressif # SDK base version, as released by Espressif depends on the RELEASE flag
SDK_BASE_VER:=2.2.1 #
# RELEASE = lastest pulls the latest V3.0.0 branch version as at the issue of this make
# otherwise it pulls the labelled version in the SDK version's release directory
#
ifeq ("$(RELEASE)","latest-3.0")
SDK_VER := 3.0.0
SDK_FILE_SHA1 := NA
SDK_ZIP_ROOT := ESP8266_NONOS_SDK-release-v$(SDK_VER)
SDK_FILE_VER := release/v$(SDK_VER)
else ifeq ("$(RELEASE)","master")
SDK_VER := master
SDK_FILE_SHA1 := NA
SDK_ZIP_ROOT := ESP8266_NONOS_SDK-$(SDK_VER)
SDK_FILE_VER := $(SDK_VER)
else
# SDK_VER := 3.0
# SDK_FILE_VER := v$(SDK_VER)
SDK_FILE_VER := e4434aa730e78c63040ace360493aef420ec267c
SDK_VER := 3.0-e4434aa
SDK_FILE_SHA1 := ac6528a6a206d3d4c220e4035ced423eb314cfbf
SDK_ZIP_ROOT := ESP8266_NONOS_SDK-$(SDK_FILE_VER)
endif
SDK_REL_DIR := sdk/esp_iot_sdk_v$(SDK_VER)
SDK_DIR := $(TOP_DIR)/$(SDK_REL_DIR)
APP_DIR := $(TOP_DIR)/app
# no patch: SDK_VER equals SDK_BASE_VER and sdk dir depends on sdk_extracted ESPTOOL_VER := 2.6
SDK_VER:=$(SDK_BASE_VER)
SDK_DIR_DEPENDS:=sdk_extracted
# with patch: SDK_VER differs from SDK_BASE_VER and sdk dir depends on sdk_patched # Ensure that the Espresif SDK is search before application paths and also prevent
#SDK_PATCH_VER:=f8f27ce # the SDK's c_types.h from being included from anywhere, by predefining its include-guard.
#SDK_VER:=$(SDK_BASE_VER)-$(SDK_PATCH_VER)
#SDK_DIR_DEPENDS:=sdk_patched
SDK_FILE_VER:=$(SDK_BASE_VER) CCFLAGS := $(CCFLAGS) -I $(PDIR)sdk-overrides/include -I $(SDK_DIR)/include -D_C_TYPES_H_
SDK_FILE_SHA1:=48f2242d5895823709f222bf0fffce9d525996c8 LDFLAGS := -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS)
# SDK_PATCH_SHA1:=0bc21ec77b08488f04d3e1c9d161b711d07201a8
# Ensure we search "our" SDK before the tool-chain's SDK (if any)
TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
SDK_REL_DIR=sdk/esp_iot_sdk_v$(SDK_VER)
SDK_DIR:=$(TOP_DIR)/$(SDK_REL_DIR)
CCFLAGS:= -I$(TOP_DIR)/sdk-overrides/include -I$(TOP_DIR)/app/include/lwip/app -I$(SDK_DIR)/include
LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS)
ifdef DEBUG ifdef DEBUG
CCFLAGS += -ggdb -O0 CCFLAGS += -ggdb -O0
...@@ -33,111 +46,137 @@ else ...@@ -33,111 +46,137 @@ else
CCFLAGS += -O2 CCFLAGS += -O2
endif endif
#Handling of V=1/VERBOSE=1 flag
# Handling of V=1/VERBOSE=1 flag
# #
# if V=1, $(summary) does nothing # if V=1, $(summary) does nothing
# if V is unset or not 1, $(summary) echoes a summary # if V is unset or not 1, $(summary) echoes a summary
VERBOSE ?= VERBOSE ?=
V ?= $(VERBOSE) V ?= $(VERBOSE)
ifeq ("$(V)","1") ifeq ("$(V)","1")
export summary := @true export summary := @true
else else
export summary := @echo export summary := @echo
# disable echoing of commands, directory names
# disable echoing of commands, directory names MAKEFLAGS += --silent -w
MAKEFLAGS += --silent -w
endif # $(V)==1 endif # $(V)==1
ifndef BAUDRATE ifndef BAUDRATE
BAUDRATE=115200 BAUDRATE=115200
endif endif
############################################################# #############################################################
# Select compile # Select compile
# #
ifeq ($(OS),Windows_NT) # ** HEALTH WARNING ** This section is largely legacy directives left over from
# WIN32 # an Espressif template. As far as I (TerrryE) know, we've only used the Linux
# We are under windows. # Path. I have successfully build AMD and Intel (both x86, AMD64) and RPi ARM6
ifeq ($(XTENSA_CORE),lx106) # all under Ubuntu. Our docker container runs on Windows in an Ubuntu VM.
# It is xcc # Johny Mattson maintains a prebuild AMD64 xtensa cross-compile gcc v4.8.5
AR = xt-ar # toolchain which is compatible with the non-OS SDK and can be used on any recent
CC = xt-xcc # Ubuntu version including the Docker and Travis build environments.
CXX = xt-xcc #
NM = xt-nm # You have the option to build your own toolchain and specify a TOOLCHAIN_ROOT
CPP = xt-cpp # environment variable (see https://github.com/pfalcon/esp-open-sdk). If your
OBJCOPY = xt-objcopy # architecture is compatable then you can omit this variable and the make will
#MAKE = xt-make # download and use this prebuilt toolchain.
CCFLAGS += --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal #
else # If any developers wish to develop, test and support alternative environments
# It is gcc, may be cygwin # then please raise a GitHub issue on this work.
# Can we use -fdata-sections? #
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections
AR = xtensa-lx106-elf-ar ifndef $(OS)
CC = xtensa-lx106-elf-gcc # Assume Windows if MAKE_HOST contains "indows" and Linux otherwise
CXX = xtensa-lx106-elf-g++ ifneq (,$(findstring indows,$(MAKE_HOST)))
NM = xtensa-lx106-elf-nm OS := windows
CPP = xtensa-lx106-elf-cpp else
OBJCOPY = xtensa-lx106-elf-objcopy OS := linux
endif endif
FIRMWAREDIR = ..\\bin\\ endif
ifndef COMPORT
ESPPORT = com1 ifneq (,$(findstring indows,$(OS)))
else #------------ BEGIN UNTESTED ------------ We are not under Linux, e.g.under windows.
ESPPORT = $(COMPORT) ifeq ($(XTENSA_CORE),lx106)
endif # It is xcc
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) AR = xt-ar
CC = xt-xcc
CXX = xt-xcc
NM = xt-nm
CPP = xt-cpp
OBJCOPY = xt-objcopy
#MAKE = xt-make
CCFLAGS += --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal
else
# It is gcc, may be cygwin
# Can we use -fdata-sections?
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections
AR = xtensa-lx106-elf-ar
CC = xtensa-lx106-elf-gcc
CXX = xtensa-lx106-elf-g++
NM = xtensa-lx106-elf-nm
CPP = xtensa-lx106-elf-cpp
OBJCOPY = xtensa-lx106-elf-objcopy
endif
FIRMWAREDIR = ..\\bin\\
ifndef COMPORT
ESPPORT = com1
else
ESPPORT = $(COMPORT)
endif
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
# ->AMD64 # ->AMD64
endif endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86) ifeq ($(PROCESSOR_ARCHITECTURE),x86)
# ->IA32 # ->IA32
endif endif
#---------------- END UNTESTED ---------------- We are under windows.
else else
# We are under other system, may be Linux. Assume using gcc. # We are under other system, may be Linux. Assume using gcc.
# Can we use -fdata-sections?
PLATFORM:=linux-x86_64 UNAME_S := $(shell uname -s)
ifndef COMPORT UNAME_P := $(shell uname -p)
ESPPORT = /dev/ttyUSB0 ifeq ($(OS),linux)
else ifndef TOOLCHAIN_ROOT
ESPPORT = $(COMPORT) TOOLCHAIN_VERSION = 20181106.0
endif GCCTOOLCHAIN = linux-x86_64-$(TOOLCHAIN_VERSION)
export PATH := $(PATH):$(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/ TOOLCHAIN_ROOT = $(TOP_DIR)/tools/toolchains/esp8266-$(GCCTOOLCHAIN)
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections GITHUB_TOOLCHAIN = https://github.com/jmattsson/esp-toolchains
AR = xtensa-lx106-elf-ar export PATH:=$(PATH):$(TOOLCHAIN_ROOT)/bin
CC = $(WRAPCC) xtensa-lx106-elf-gcc
CXX = $(WRAPCC) xtensa-lx106-elf-g++
NM = xtensa-lx106-elf-nm
CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E
OBJCOPY = xtensa-lx106-elf-objcopy
FIRMWAREDIR = ../bin/
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
# LINUX
endif
ifeq ($(UNAME_S),Darwin)
# OSX
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
# ->AMD64
endif
ifneq ($(filter %86,$(UNAME_P)),)
# ->IA32
endif
ifneq ($(filter arm%,$(UNAME_P)),)
# ->ARM
endif endif
endif
ifndef COMPORT
ESPPORT = /dev/ttyUSB0
else
ESPPORT = $(COMPORT)
endif
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections
AR = xtensa-lx106-elf-ar
CC = $(WRAPCC) xtensa-lx106-elf-gcc
CXX = $(WRAPCC) xtensa-lx106-elf-g++
NM = xtensa-lx106-elf-nm
CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E
OBJCOPY = xtensa-lx106-elf-objcopy
FIRMWAREDIR = ../bin/
WGET = wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused
endif endif
#############################################################
ESPTOOL ?= ../tools/esptool.py
GITHUB_SDK = https://github.com/espressif/ESP8266_NONOS_SDK
GITHUB_ESPTOOL = https://github.com/espressif/esptool
ESPTOOL ?= $(TOP_DIR)/tools/toolchains/esptool.py
CSRCS ?= $(wildcard *.c)
CXXSRCS ?= $(wildcard *.cpp)
ASRCs ?= $(wildcard *.s)
ASRCS ?= $(wildcard *.S)
SUBDIRS ?= $(patsubst %/,%,$(dir $(filter-out tools/Makefile,$(wildcard */Makefile)))) SUBDIRS ?= $(patsubst %/,%,$(dir $(filter-out tools/Makefile,$(wildcard */Makefile))))
ODIR := .output ODIR := .output
ifdef TARGET
CSRCS ?= $(wildcard *.c)
CXXSRCS ?= $(wildcard *.cpp)
ASRCs ?= $(wildcard *.s)
ASRCS ?= $(wildcard *.S)
OBJODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/obj OBJODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/obj
OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \ OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \
...@@ -160,19 +199,19 @@ BINODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/bin ...@@ -160,19 +199,19 @@ BINODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/bin
OBINS := $(GEN_BINS:%=$(BINODIR)/%) OBINS := $(GEN_BINS:%=$(BINODIR)/%)
ifndef PDIR ifndef PDIR
ifneq ($(wildcard $(TOP_DIR)/local/fs/*),) ifneq ($(wildcard $(TOP_DIR)/local/fs/*),)
SPECIAL_MKTARGETS += spiffs-image SPECIAL_MKTARGETS += spiffs-image
else else
SPECIAL_MKTARGETS += spiffs-image-remove SPECIAL_MKTARGETS += spiffs-image-remove
endif endif
endif endif
endif # TARGET
# #
# Note: # Note:
# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html # https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
# If you add global optimize options like "-O2" here # If you add global optimize options then they will override "-Os" defined above.
# they will override "-Os" defined above. # Note that "-Os" should NOT be used to reduce code size because of the runtime
# "-Os" should be used to reduce code size # impact of the extra non-aligned exception burdon.
# #
CCFLAGS += \ CCFLAGS += \
-g \ -g \
...@@ -183,7 +222,7 @@ CCFLAGS += \ ...@@ -183,7 +222,7 @@ CCFLAGS += \
-fno-inline-functions \ -fno-inline-functions \
-nostdlib \ -nostdlib \
-mlongcalls \ -mlongcalls \
-mtext-section-literals -mtext-section-literals \
# -Wall # -Wall
CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES) CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
...@@ -194,6 +233,8 @@ DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES) ...@@ -194,6 +233,8 @@ DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
# Functions # Functions
# #
ifdef TARGET
define ShortcutRule define ShortcutRule
$(1): .subdirs $(2)/$(1) $(1): .subdirs $(2)/$(1)
endef endef
...@@ -226,70 +267,82 @@ $(BINODIR)/%.bin: $(IMAGEODIR)/%.out ...@@ -226,70 +267,82 @@ $(BINODIR)/%.bin: $(IMAGEODIR)/%.out
$(summary) ESPTOOL $(patsubst $(TOP_DIR)/%,%,$(CURDIR))/$< $(FIRMWAREDIR) $(summary) ESPTOOL $(patsubst $(TOP_DIR)/%,%,$(CURDIR))/$< $(FIRMWAREDIR)
$(ESPTOOL) elf2image --flash_mode dio --flash_freq 40m $< -o $(FIRMWAREDIR) $(ESPTOOL) elf2image --flash_mode dio --flash_freq 40m $< -o $(FIRMWAREDIR)
endif # TARGET
############################################################# #############################################################
# Rules base # Rules base
# Should be done in top-level makefile only # Should be done in top-level makefile only
# #
all: toolchain sdk_pruned pre_build .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS) ifndef TARGET
all: toolchain sdk_pruned pre_build buildinfo .subdirs
else
all: .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS)
endif
.PHONY: sdk_extracted .PHONY: sdk_extracted
.PHONY: sdk_patched
.PHONY: sdk_pruned .PHONY: sdk_pruned
.PHONY: toolchain .PHONY: toolchain
sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER) sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_VER)
sdk_patched: sdk_extracted $(TOP_DIR)/sdk/.patched-$(SDK_VER) sdk_pruned: sdk_extracted toolchain $(TOP_DIR)/sdk/.pruned-$(SDK_VER)
sdk_pruned: $(SDK_DIR_DEPENDS) $(TOP_DIR)/sdk/.pruned-$(SDK_VER)
ifeq ($(OS),Windows_NT) ifdef GITHUB_TOOLCHAIN
toolchain: TOOLCHAIN_ROOT := $(TOP_DIR)/tools/toolchains/esp8266-linux-x86_64-$(TOOLCHAIN_VERSION)
else
toolchain: $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc toolchain: $(TOOLCHAIN_ROOT)/bin $(ESPTOOL)
$(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc: $(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz $(TOOLCHAIN_ROOT)/bin: $(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz
mkdir -p $(TOP_DIR)/tools/toolchains/ mkdir -p $(TOP_DIR)/tools/toolchains/
$(summary) EXTRACT $(patsubst $(TOP_DIR)/%,%,$<) $(summary) EXTRACT $(patsubst $(TOP_DIR)/%,%,$<)
tar -xJf $< -C $(TOP_DIR)/tools/toolchains/ tar -xJf $< -C $(TOP_DIR)/tools/toolchains/
touch $@ touch $@
$(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz: $(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz:
mkdir -p $(TOP_DIR)/cache mkdir -p $(TOP_DIR)/cache
$(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@)
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused https://github.com/jmattsson/esp-toolchains/releases/download/$(PLATFORM)-$(TOOLCHAIN_VERSION)/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz -O $@ || { rm -f "$@"; exit 1; } $(WGET) $(GITHUB_TOOLCHAIN)/releases/download/$(GCCTOOLCHAIN)/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz -O $@ \
|| { rm -f "$@"; exit 1; }
else
toolchain: $(ESPTOOL)
endif endif
$(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER): $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip $(ESPTOOL): $(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz
mkdir -p "$(dir $@)" mkdir -p $(TOP_DIR)/tools/toolchains/
$(summary) UNZIP $(patsubst $(TOP_DIR)/%,%,$<) tar -C $(TOP_DIR)/tools/toolchains/ -xzf $< --strip-components=1 esptool-$(ESPTOOL_VER)/esptool.py
(cd "$(dir $@)" && rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-$(SDK_BASE_VER) && unzip $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip ESP8266_NONOS_SDK-$(SDK_BASE_VER)/lib/* ESP8266_NONOS_SDK-$(SDK_BASE_VER)/ld/eagle.rom.addr.v6.ld ESP8266_NONOS_SDK-$(SDK_BASE_VER)/include/* ESP8266_NONOS_SDK-$(SDK_BASE_VER)/bin/esp_init_data_default_v05.bin) chmod +x $@
mv $(dir $@)/ESP8266_NONOS_SDK-$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER)
touch $@ touch $@
$(TOP_DIR)/sdk/.patched-$(SDK_VER): $(TOP_DIR)/cache/$(SDK_PATCH_VER).patch $(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz:
mv $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_VER) mkdir -p $(TOP_DIR)/cache/esptool/
$(summary) APPLY $(patsubst $(TOP_DIR)/%,%,$<) $(WGET) $(GITHUB_ESPTOOL)/archive/v$(ESPTOOL_VER).tar.gz -O $@ || { rm -f "$@"; exit 1; }
git apply --verbose -p1 --exclude='*VERSION' --exclude='*bin/at*' --directory=$(SDK_REL_DIR) $<
$(TOP_DIR)/sdk/.extracted-$(SDK_VER): $(TOP_DIR)/cache/$(SDK_FILE_VER).zip
mkdir -p "$(dir $@)"
$(summary) UNZIP $(patsubst $(TOP_DIR)/%,%,$<)
(cd "$(dir $@)" && \
rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-* && \
unzip $(TOP_DIR)/cache/$(SDK_FILE_VER).zip \
'*/lib/*' \
'*/ld/*.v6.ld' \
'*/include/*' \
'*/bin/esp_init_data_default_v05.bin' \
)
mv $(dir $@)/$(SDK_ZIP_ROOT) $(dir $@)/esp_iot_sdk_v$(SDK_VER)
touch $@ touch $@
$(TOP_DIR)/sdk/.pruned-$(SDK_VER): $(TOP_DIR)/sdk/.pruned-$(SDK_VER):
rm -f $(SDK_DIR)/lib/liblwip.a $(SDK_DIR)/lib/libssl.a $(SDK_DIR)/lib/libmbedtls.a rm -f $(SDK_DIR)/lib/liblwip.a $(SDK_DIR)/lib/libssl.a $(SDK_DIR)/lib/libmbedtls.a
$(summary) PRUNE libmain.a libc.a $(summary) PRUNE libmain.a libc.a
echo $(PATH)
$(AR) d $(SDK_DIR)/lib/libmain.a time.o $(AR) d $(SDK_DIR)/lib/libmain.a time.o
$(AR) d $(SDK_DIR)/lib/libc.a lib_a-time.o $(AR) d $(SDK_DIR)/lib/libc.a lib_a-time.o
touch $@ touch $@
$(TOP_DIR)/cache/v$(SDK_FILE_VER).zip: $(TOP_DIR)/cache/$(SDK_FILE_VER).zip:
mkdir -p "$(dir $@)" mkdir -p "$(dir $@)"
$(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@) $(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@)
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused https://github.com/espressif/ESP8266_NONOS_SDK/archive/v$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; } $(WGET) $(GITHUB_SDK)/archive/$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; }
(echo "$(SDK_FILE_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; } if test "$(SDK_FILE_SHA1)" != "NA"; then echo "$(SDK_FILE_SHA1) $@" | sha1sum -c - || { rm -f "$@"; exit 1; }; fi
$(TOP_DIR)/cache/$(SDK_PATCH_VER).patch:
mkdir -p "$(dir $@)"
$(summary) WGET $(SDK_PATCH_VER).patch
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused "https://github.com/espressif/ESP8266_NONOS_SDK/compare/v$(SDK_BASE_VER)...$(SDK_PATCH_VER).patch" -O $@ || { rm -f "$@"; exit 1; }
(echo "$(SDK_PATCH_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; }
clean: clean:
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;) $(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;)
...@@ -318,7 +371,7 @@ flash1m-dout: ...@@ -318,7 +371,7 @@ flash1m-dout:
flashinternal: flashinternal:
ifndef PDIR ifndef PDIR
$(MAKE) -C ./app flashinternal $(MAKE) -C $(APP_DIR) flashinternal
else else
$(ESPTOOL) --port $(ESPPORT) --baud $(BAUDRATE) write_flash $(FLASHOPTIONS) 0x00000 $(FIRMWAREDIR)0x00000.bin 0x10000 $(FIRMWAREDIR)0x10000.bin $(ESPTOOL) --port $(ESPPORT) --baud $(BAUDRATE) write_flash $(FLASHOPTIONS) 0x00000 $(FIRMWAREDIR)0x00000.bin 0x10000 $(FIRMWAREDIR)0x10000.bin
endif endif
...@@ -326,15 +379,12 @@ endif ...@@ -326,15 +379,12 @@ endif
.subdirs: .subdirs:
@set -e; $(foreach d, $(SUBDIRS), $(MAKE) -C $(d);) @set -e; $(foreach d, $(SUBDIRS), $(MAKE) -C $(d);)
#.subdirs:
# $(foreach d, $(SUBDIRS), $(MAKE) -C $(d))
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),clobber) ifneq ($(MAKECMDGOALS),clobber)
ifdef DEPS ifdef DEPS
sinclude $(DEPS) sinclude $(DEPS)
endif endif
endif endif
endif endif
.PHONY: spiffs-image-remove .PHONY: spiffs-image-remove
...@@ -346,22 +396,28 @@ spiffs-image-remove: ...@@ -346,22 +396,28 @@ spiffs-image-remove:
spiffs-image: bin/0x10000.bin spiffs-image: bin/0x10000.bin
$(MAKE) -C tools $(MAKE) -C tools
############ Note: this target needs moving into app/modules make ############
.PHONY: pre_build .PHONY: pre_build
ifneq ($(wildcard $(TOP_DIR)/server-ca.crt),) ifneq ($(wildcard $(TOP_DIR)/server-ca.crt),)
pre_build: $(TOP_DIR)/app/modules/server-ca.crt.h pre_build: $(APP_DIR)/modules/server-ca.crt.h
$(TOP_DIR)/app/modules/server-ca.crt.h: $(TOP_DIR)/server-ca.crt $(APP_DIR)/modules/server-ca.crt.h: $(TOP_DIR)/server-ca.crt
$(summary) MKCERT $(patsubst $(TOP_DIR)/%,%,$<) $(summary) MKCERT $(patsubst $(TOP_DIR)/%,%,$<)
python $(TOP_DIR)/tools/make_server_cert.py $(TOP_DIR)/server-ca.crt > $(TOP_DIR)/app/modules/server-ca.crt.h python $(TOP_DIR)/tools/make_server_cert.py $(TOP_DIR)/server-ca.crt > $(APP_DIR)/modules/server-ca.crt.h
DEFINES += -DHAVE_SSL_SERVER_CRT=\"server-ca.crt.h\" DEFINES += -DHAVE_SSL_SERVER_CRT=\"server-ca.crt.h\"
else else
pre_build: pre_build:
@-rm -f $(TOP_DIR)/app/modules/server-ca.crt.h @-rm -f $(APP_DIR)/modules/server-ca.crt.h
endif endif
.PHONY: buildinfo
buildinfo:
tools/update_buildinfo.sh
ifdef TARGET
$(OBJODIR)/%.o: %.c $(OBJODIR)/%.o: %.c
@mkdir -p $(dir $@); @mkdir -p $(dir $@);
$(summary) CC $(patsubst $(TOP_DIR)/%,%,$(CURDIR))/$< $(summary) CC $(patsubst $(TOP_DIR)/%,%,$(CURDIR))/$<
...@@ -421,6 +477,7 @@ $(foreach lib,$(GEN_LIBS),$(eval $(call MakeLibrary,$(basename $(lib))))) ...@@ -421,6 +477,7 @@ $(foreach lib,$(GEN_LIBS),$(eval $(call MakeLibrary,$(basename $(lib)))))
$(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image))))) $(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image)))))
endif # TARGET
############################################################# #############################################################
# Recursion Magic - Don't touch this!! # Recursion Magic - Don't touch this!!
# #
...@@ -433,6 +490,5 @@ $(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image))))) ...@@ -433,6 +490,5 @@ $(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image)))))
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)include/$(TARGET)
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
# **NodeMCU 2.2.1** # # NodeMCU 3.0.0
[![Join the chat at https://gitter.im/nodemcu/nodemcu-firmware](https://img.shields.io/gitter/room/badges/shields.svg)](https://gitter.im/nodemcu/nodemcu-firmware?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join the chat at https://gitter.im/nodemcu/nodemcu-firmware](https://img.shields.io/gitter/room/badges/shields.svg)](https://gitter.im/nodemcu/nodemcu-firmware?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/nodemcu/nodemcu-firmware.svg)](https://travis-ci.org/nodemcu/nodemcu-firmware) [![Build Status](https://travis-ci.org/nodemcu/nodemcu-firmware.svg)](https://travis-ci.org/nodemcu/nodemcu-firmware)
...@@ -14,7 +14,7 @@ The firmware was initially developed as is a companion project to the popular ES ...@@ -14,7 +14,7 @@ The firmware was initially developed as is a companion project to the popular ES
# Summary # Summary
- Easy to program wireless node and/or access point - Easy to program wireless node and/or access point
- Based on Lua 5.1.4 (without `debug` & `os` modules) - Based on Lua 5.1.4 but without `debug`, `io`, `os` and (most of the) `math` modules
- Asynchronous event-driven programming model - Asynchronous event-driven programming model
- more than **65 built-in modules** - more than **65 built-in modules**
- Firmware available with or without floating point support (integer-only uses less memory) - Firmware available with or without floating point support (integer-only uses less memory)
......
...@@ -15,8 +15,6 @@ TARGET = eagle ...@@ -15,8 +15,6 @@ TARGET = eagle
#FLAVOR = release #FLAVOR = release
FLAVOR = debug FLAVOR = debug
#EXTRA_CCFLAGS += -u
ifndef PDIR # { ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin GEN_BINS= eagle.app.v6.bin
...@@ -42,10 +40,10 @@ SUBDIRS= \ ...@@ -42,10 +40,10 @@ SUBDIRS= \
smart \ smart \
modules \ modules \
spiffs \ spiffs \
net \ net \
fatfs \ fatfs \
esp-gdbstub \ esp-gdbstub \
pm \ pm \
uzlib \ uzlib \
$(OPT_SEL_MKTARGETS) $(OPT_SEL_MKTARGETS)
...@@ -54,19 +52,19 @@ endif # } PDIR ...@@ -54,19 +52,19 @@ endif # } PDIR
APPDIR = . APPDIR = .
LDDIR = ../ld LDDIR = ../ld
TARGET_LDFLAGS = \ TARGET_LDFLAGS = \
-nostdlib \ -nostdlib \
-Wl,-EL \ -Wl,-EL \
--longcalls \ --longcalls \
--text-section-literals --text-section-literals
LD_FILE = $(LDDIR)/nodemcu.ld LD_FILE = $(LDDIR)/nodemcu.ld
COMPONENTS_eagle.app.v6 = \ COMPONENTS_eagle.app.v6 = \
user/libuser.a \ user/libuser.a \
crypto/libcrypto.a \ crypto/libcrypto.a \
driver/libdriver.a \ driver/libdriver.a \
platform/libplatform.a \ platform/libplatform.a \
task/libtask.a \ task/libtask.a \
libc/liblibc.a \ libc/liblibc.a \
lua/liblua.a \ lua/liblua.a \
...@@ -74,48 +72,50 @@ COMPONENTS_eagle.app.v6 = \ ...@@ -74,48 +72,50 @@ COMPONENTS_eagle.app.v6 = \
smart/smart.a \ smart/smart.a \
spiffs/spiffs.a \ spiffs/spiffs.a \
fatfs/libfatfs.a \ fatfs/libfatfs.a \
pm/libpm.a \ pm/libpm.a \
esp-gdbstub/libgdbstub.a \ esp-gdbstub/libgdbstub.a \
net/libnodemcu_net.a \ net/libnodemcu_net.a \
mbedtls/libmbedtls.a \ mbedtls/libmbedtls.a \
modules/libmodules.a \ modules/libmodules.a \
smart/smart.a \ smart/smart.a \
uzlib/libuzlib.a \ uzlib/libuzlib.a \
$(OPT_SEL_COMPONENTS) $(OPT_SEL_COMPONENTS)
# Inspect the modules library and work out which modules need to be linked. # Inspect the modules library and work out which modules need to be linked.
# For each enabled module, a symbol name of the form XYZ_module_selected is # For each enabled module, a symbol name of the form XYZ_module_selected is
# returned. At link time those names are declared undefined, so those (and # returned. At link time those names are declared undefined, so those (and
# only those) modules are pulled in. # only those) modules are pulled in.
SELECTED_MODULE_SYMS=$(filter %_module_selected %module_selected1,$(shell $(NM) modules/.output/$(TARGET)/$(FLAVOR)/lib/libmodules.a)) SELECTED_MODULE_SYMS=$(filter %_module_selected %module_selected1,$(shell $(NM) modules/.output/$(TARGET)/$(FLAVOR)/lib/libmodules.a))
LINKFLAGS_eagle.app.v6 = \ LINKFLAGS_eagle.app.v6 = \
-Wl,--gc-sections \ -Wl,--gc-sections \
-Wl,-Map=mapfile \ -Wl,-Map=mapfile \
-nostdlib \ -nostdlib \
-T$(LD_FILE) \ -T$(LD_FILE) \
-Wl,@../ld/defsym.rom \ -Wl,@../ld/defsym.rom \
-Wl,--no-check-sections \ -Wl,--no-check-sections \
-Wl,--wrap=_xtos_set_exception_handler \ -Wl,-static \
-Wl,-static \
$(addprefix -u , $(SELECTED_MODULE_SYMS)) \ $(addprefix -u , $(SELECTED_MODULE_SYMS)) \
-Wl,--start-group \ -Wl,--start-group \
-lmain \ -lmain \
-lc \ $(DEP_LIBS_eagle.app.v6)\
-Wl,--end-group \
-Wl,--start-group \
-lgcc \ -lgcc \
-lhal \ -lhal \
-lphy \ -lphy \
-lpp \ -lpp \
-lnet80211 \ -lnet80211 \
-lsmartconfig \
-lwpa \ -lwpa \
-lwpa2 \ -lwpa2 \
-lsmartconfig \
-lcrypto \ -lcrypto \
-lwps \ -lwps \
$(DEP_LIBS_eagle.app.v6) \ -lc \
-Wl,--end-group \ -lm \
-lm -Wl,--end-group
# -Wl,--cref
# -Wl,--wrap=_xtos_set_exception_handler
DEPENDS_eagle.app.v6 = \ DEPENDS_eagle.app.v6 = \
$(LD_FILE) \ $(LD_FILE) \
...@@ -131,28 +131,15 @@ DEPENDS_eagle.app.v6 = \ ...@@ -131,28 +131,15 @@ DEPENDS_eagle.app.v6 = \
#UNIVERSAL_TARGET_DEFINES = \ #UNIVERSAL_TARGET_DEFINES = \
# Other potential configuration flags include: CONFIGURATION_DEFINES += -DLWIP_OPEN_SRC
# -DTXRX_TXBUF_DEBUG
# -DTXRX_RXBUF_DEBUG
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -D__ets__ \
-DICACHE_FLASH \
-DLUA_OPTIMIZE_MEMORY=2 \
-DMIN_OPT_LEVEL=2 \
-DLWIP_OPEN_SRC \
-DPBUF_RSV_FOR_WLAN \
-DEBUF_LWIP \
-DUSE_OPTIMIZE_PRINTF \
-DMBEDTLS_USER_CONFIG_FILE=\"user_mbedtls.h\" \
DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
DDEFINES += \ DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \ $(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES) $(CONFIGURATION_DEFINES)
DDEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
############################################################# #############################################################
# Recursion Magic - Don't touch this!! # Recursion Magic - Don't touch this!!
...@@ -165,10 +152,10 @@ DDEFINES += \ ...@@ -165,10 +152,10 @@ DDEFINES += \
# #
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES := -I $(PDIR)libc -I $(PDIR)lua -I $(PDIR)platform \
INCLUDES := $(INCLUDES) -I $(PDIR)include $(INCLUDES) -I $(PDIR) -I $(PDIR)include
INCLUDES += -I ./
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
.PHONY: FORCE .PHONY: FORCE
......
...@@ -36,10 +36,6 @@ endif ...@@ -36,10 +36,6 @@ endif
# Required for each makefile to inherit from the parent # Required for each makefile to inherit from the parent
# #
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../libc
INCLUDES += -I ../lua
PDIR := ../$(PDIR) PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile sinclude $(PDIR)Makefile
#include "user_config.h" #include "user_config.h"
#include "c_stdio.h" #include <stdio.h>
#include "c_string.h" #include <string.h>
#include "coap.h" #include "coap.h"
#include "uri.h" #include "uri.h"
...@@ -10,12 +10,12 @@ extern const coap_endpoint_t endpoints[]; ...@@ -10,12 +10,12 @@ extern const coap_endpoint_t endpoints[];
#ifdef COAP_DEBUG #ifdef COAP_DEBUG
void coap_dumpHeader(coap_header_t *hdr) void coap_dumpHeader(coap_header_t *hdr)
{ {
c_printf("Header:\n"); printf("Header:\n");
c_printf(" ver 0x%02X\n", hdr->ver); printf(" ver 0x%02X\n", hdr->ver);
c_printf(" t 0x%02X\n", hdr->ver); printf(" t 0x%02X\n", hdr->ver);
c_printf(" tkl 0x%02X\n", hdr->tkl); printf(" tkl 0x%02X\n", hdr->tkl);
c_printf(" code 0x%02X\n", hdr->code); printf(" code 0x%02X\n", hdr->code);
c_printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]); printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]);
} }
void coap_dump(const uint8_t *buf, size_t buflen, bool bare) void coap_dump(const uint8_t *buf, size_t buflen, bool bare)
...@@ -23,14 +23,14 @@ void coap_dump(const uint8_t *buf, size_t buflen, bool bare) ...@@ -23,14 +23,14 @@ void coap_dump(const uint8_t *buf, size_t buflen, bool bare)
if (bare) if (bare)
{ {
while(buflen--) while(buflen--)
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : ""); printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
} }
else else
{ {
c_printf("Dump: "); printf("Dump: ");
while(buflen--) while(buflen--)
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : ""); printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
c_printf("\n"); printf("\n");
} }
} }
#endif #endif
...@@ -100,7 +100,7 @@ int coap_buildToken(const coap_buffer_t *tokbuf, const coap_header_t *hdr, uint8 ...@@ -100,7 +100,7 @@ int coap_buildToken(const coap_buffer_t *tokbuf, const coap_header_t *hdr, uint8
return COAP_ERR_UNSUPPORTED; return COAP_ERR_UNSUPPORTED;
if (hdr->tkl > 0) if (hdr->tkl > 0)
c_memcpy(p, tokbuf->p, hdr->tkl); memcpy(p, tokbuf->p, hdr->tkl);
// http://tools.ietf.org/html/rfc7252#section-3.1 // http://tools.ietf.org/html/rfc7252#section-3.1
// inject options // inject options
...@@ -260,12 +260,12 @@ int coap_buildOptionHeader(uint32_t optDelta, size_t length, uint8_t *buf, size_ ...@@ -260,12 +260,12 @@ int coap_buildOptionHeader(uint32_t optDelta, size_t length, uint8_t *buf, size_
void coap_dumpOptions(coap_option_t *opts, size_t numopt) void coap_dumpOptions(coap_option_t *opts, size_t numopt)
{ {
size_t i; size_t i;
c_printf(" Options:\n"); printf(" Options:\n");
for (i=0;i<numopt;i++) for (i=0;i<numopt;i++)
{ {
c_printf(" 0x%02X [ ", opts[i].num); printf(" 0x%02X [ ", opts[i].num);
coap_dump(opts[i].buf.p, opts[i].buf.len, true); coap_dump(opts[i].buf.p, opts[i].buf.len, true);
c_printf(" ]\n"); printf(" ]\n");
} }
} }
...@@ -273,9 +273,9 @@ void coap_dumpPacket(coap_packet_t *pkt) ...@@ -273,9 +273,9 @@ void coap_dumpPacket(coap_packet_t *pkt)
{ {
coap_dumpHeader(&pkt->hdr); coap_dumpHeader(&pkt->hdr);
coap_dumpOptions(pkt->opts, pkt->numopts); coap_dumpOptions(pkt->opts, pkt->numopts);
c_printf("Payload: "); printf("Payload: ");
coap_dump(pkt->payload.p, pkt->payload.len, true); coap_dump(pkt->payload.p, pkt->payload.len, true);
c_printf("\n"); printf("\n");
} }
#endif #endif
...@@ -325,7 +325,7 @@ int coap_buffer_to_string(char *strbuf, size_t strbuflen, const coap_buffer_t *b ...@@ -325,7 +325,7 @@ int coap_buffer_to_string(char *strbuf, size_t strbuflen, const coap_buffer_t *b
{ {
if (buf->len+1 > strbuflen) if (buf->len+1 > strbuflen)
return COAP_ERR_BUFFER_TOO_SMALL; return COAP_ERR_BUFFER_TOO_SMALL;
c_memcpy(strbuf, buf->p, buf->len); memcpy(strbuf, buf->p, buf->len);
strbuf[buf->len] = 0; strbuf[buf->len] = 0;
return 0; return 0;
} }
...@@ -360,7 +360,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) ...@@ -360,7 +360,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt)
p += rc; p += rc;
left -= rc; left -= rc;
c_memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len); memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len);
p += pkt->opts[i].buf.len; p += pkt->opts[i].buf.len;
left -= pkt->opts[i].buf.len; left -= pkt->opts[i].buf.len;
running_delta = pkt->opts[i].num; running_delta = pkt->opts[i].num;
...@@ -373,7 +373,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) ...@@ -373,7 +373,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt)
if (*buflen < 4 + 1 + pkt->payload.len + opts_len) if (*buflen < 4 + 1 + pkt->payload.len + opts_len)
return COAP_ERR_BUFFER_TOO_SMALL; return COAP_ERR_BUFFER_TOO_SMALL;
buf[4 + opts_len] = 0xFF; // payload marker buf[4 + opts_len] = 0xFF; // payload marker
c_memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len); memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len);
*buflen = opts_len + 5 + pkt->payload.len; *buflen = opts_len + 5 + pkt->payload.len;
} }
else else
...@@ -471,7 +471,7 @@ int coap_make_request(coap_rw_buffer_t *scratch, coap_packet_t *pkt, coap_msgtyp ...@@ -471,7 +471,7 @@ int coap_make_request(coap_rw_buffer_t *scratch, coap_packet_t *pkt, coap_msgtyp
/* split arg into Uri-* options */ /* split arg into Uri-* options */
// const char *addr = uri->host.s; // const char *addr = uri->host.s;
// if(uri->host.length && (c_strlen(addr) != uri->host.length || c_memcmp(addr, uri->host.s, uri->host.length) != 0)){ // if(uri->host.length && (strlen(addr) != uri->host.length || memcmp(addr, uri->host.s, uri->host.length) != 0)){
if(uri->host.length){ if(uri->host.length){
/* add Uri-Host */ /* add Uri-Host */
// addr is destination address // addr is destination address
...@@ -525,9 +525,9 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_ ...@@ -525,9 +525,9 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_
goto next; goto next;
for (i=0;i<ep->path->count;i++) for (i=0;i<ep->path->count;i++)
{ {
if (opt[i].buf.len != c_strlen(ep->path->elems[i])) if (opt[i].buf.len != strlen(ep->path->elems[i]))
goto next; goto next;
if (0 != c_memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len)) if (0 != memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len))
goto next; goto next;
} }
// pre-path match! // pre-path match!
...@@ -551,5 +551,5 @@ void coap_setup(void) ...@@ -551,5 +551,5 @@ void coap_setup(void)
int int
check_token(coap_packet_t *pkt) { check_token(coap_packet_t *pkt) {
return pkt->tok.len == the_token.len && c_memcmp(pkt->tok.p, the_token.p, the_token.len) == 0; return pkt->tok.len == the_token.len && memcmp(pkt->tok.p, the_token.p, the_token.len) == 0;
} }
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
extern "C" { extern "C" {
#endif #endif
#include "c_stdint.h" #include <stdint.h>
#include "c_stddef.h" #include <stddef.h>
#include "lualib.h" #include "lualib.h"
#include "lauxlib.h" #include "lauxlib.h"
......
#include "user_config.h" #include "user_config.h"
#include "c_types.h" #include <stdint.h>
#include "coap.h" #include "coap.h"
#include "hash.h" #include "hash.h"
......
#include "c_string.h" #include <string.h>
#include "coap_io.h" #include "coap_io.h"
#include "node.h" #include "node.h"
#include "espconn.h" #include "espconn.h"
...@@ -16,10 +16,10 @@ coap_tid_t coap_send(struct espconn *pesp_conn, coap_pdu_t *pdu) { ...@@ -16,10 +16,10 @@ coap_tid_t coap_send(struct espconn *pesp_conn, coap_pdu_t *pdu) {
espconn_sent(pesp_conn, (unsigned char *)(pdu->msg.p), pdu->msg.len); espconn_sent(pesp_conn, (unsigned char *)(pdu->msg.p), pdu->msg.len);
if(pesp_conn->type == ESPCONN_TCP){ if(pesp_conn->type == ESPCONN_TCP){
c_memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip)); memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip));
port = pesp_conn->proto.tcp->remote_port; port = pesp_conn->proto.tcp->remote_port;
}else{ }else{
c_memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip)); memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip));
port = pesp_conn->proto.udp->remote_port; port = pesp_conn->proto.udp->remote_port;
} }
coap_transaction_id(ip, port, pdu->pkt, &id); coap_transaction_id(ip, port, pdu->pkt, &id);
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
extern "C" { extern "C" {
#endif #endif
#include "c_types.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "espconn.h" #include "espconn.h"
#include "pdu.h" #include "pdu.h"
......
#include "user_config.h" #include "user_config.h"
#include "c_types.h" #include <stdint.h>
#include "c_stdlib.h" #include <stddef.h>
#include <stdlib.h>
#include "coap.h" #include "coap.h"
...@@ -51,7 +52,7 @@ size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned ...@@ -51,7 +52,7 @@ size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned
#endif #endif
} }
if(rsppkt.content.p){ if(rsppkt.content.p){
c_free(rsppkt.content.p); free(rsppkt.content.p);
rsppkt.content.p = NULL; rsppkt.content.p = NULL;
rsppkt.content.len = 0; rsppkt.content.len = 0;
} }
......
#include "node.h" #include "node.h"
#include "coap_timer.h" #include "coap_timer.h"
#include "os_type.h" #include "os_type.h"
#include "osapi.h"
#include "pm/swtimer.h" #include "pm/swtimer.h"
static os_timer_t coap_timer; static os_timer_t coap_timer;
......
#include "c_stdio.h" #include <stdio.h>
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "coap.h" #include "coap.h"
#include "lua.h" #include "lua.h"
...@@ -21,14 +21,14 @@ void endpoint_setup(void) ...@@ -21,14 +21,14 @@ void endpoint_setup(void)
static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}}; static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}};
static int handle_get_well_known_core(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) static int handle_get_well_known_core(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{ {
outpkt->content.p = (uint8_t *)c_zalloc(MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond() outpkt->content.p = (uint8_t *)calloc(1,MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond()
if(outpkt->content.p == NULL){ if(outpkt->content.p == NULL){
NODE_DBG("not enough memory\n"); NODE_DBG("not enough memory\n");
return COAP_ERR_BUFFER_TOO_SMALL; return COAP_ERR_BUFFER_TOO_SMALL;
} }
outpkt->content.len = MAX_PAYLOAD_SIZE; outpkt->content.len = MAX_PAYLOAD_SIZE;
build_well_known_rsp(outpkt->content.p, outpkt->content.len); build_well_known_rsp(outpkt->content.p, outpkt->content.len);
return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, c_strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT); return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT);
} }
static const coap_endpoint_path_t path_variable = {2, {"v1", "v"}}; static const coap_endpoint_path_t path_variable = {2, {"v1", "v"}};
...@@ -49,17 +49,17 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra ...@@ -49,17 +49,17 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
{ {
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head) coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){ while(NULL != h){
if (opt[count-1].buf.len != c_strlen(h->name)) if (opt[count-1].buf.len != strlen(h->name))
{ {
h = h->next; h = h->next;
continue; continue;
} }
if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len)) if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
{ {
NODE_DBG("/v1/v/"); NODE_DBG("/v1/v/");
NODE_DBG((char *)h->name); NODE_DBG((char *)h->name);
NODE_DBG(" match.\n"); NODE_DBG(" match.\n");
if(c_strlen(h->name)) if(strlen(h->name))
{ {
n = lua_gettop(L); n = lua_gettop(L);
lua_getglobal(L, h->name); lua_getglobal(L, h->name);
...@@ -70,7 +70,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra ...@@ -70,7 +70,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
} else { } else {
const char *res = lua_tostring(L,-1); const char *res = lua_tostring(L,-1);
lua_settop(L, n); lua_settop(L, n);
return coap_make_response(scratch, outpkt, (const uint8_t *)res, c_strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type); return coap_make_response(scratch, outpkt, (const uint8_t *)res, strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type);
} }
} }
} else { } else {
...@@ -105,18 +105,18 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr ...@@ -105,18 +105,18 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr
{ {
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head) coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){ while(NULL != h){
if (opt[count-1].buf.len != c_strlen(h->name)) if (opt[count-1].buf.len != strlen(h->name))
{ {
h = h->next; h = h->next;
continue; continue;
} }
if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len)) if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
{ {
NODE_DBG("/v1/f/"); NODE_DBG("/v1/f/");
NODE_DBG((char *)h->name); NODE_DBG((char *)h->name);
NODE_DBG(" match.\n"); NODE_DBG(" match.\n");
if(c_strlen(h->name)) if(strlen(h->name))
{ {
n = lua_gettop(L); n = lua_gettop(L);
lua_getglobal(L, h->name); lua_getglobal(L, h->name);
...@@ -173,7 +173,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra ...@@ -173,7 +173,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
{ {
char line[LUA_MAXINPUT]; char line[LUA_MAXINPUT];
if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload) && if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload) &&
lua_put_line(line, c_strlen(line))) { lua_put_line(line, strlen(line))) {
NODE_DBG("\nResult(if any):\n"); NODE_DBG("\nResult(if any):\n");
system_os_post (LUA_TASK_PRIO, LUA_PROCESS_LINE_SIG, 0); system_os_post (LUA_TASK_PRIO, LUA_PROCESS_LINE_SIG, 0);
} }
...@@ -211,7 +211,7 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen) ...@@ -211,7 +211,7 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
int i; int i;
uint16_t len = rsplen; uint16_t len = rsplen;
c_memset(rsp, 0, len); memset(rsp, 0, len);
len--; // Null-terminated string len--; // Null-terminated string
...@@ -222,57 +222,57 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen) ...@@ -222,57 +222,57 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
continue; continue;
} }
if (NULL == ep->user_entry){ if (NULL == ep->user_entry){
if (0 < c_strlen(rsp)) { if (0 < strlen(rsp)) {
c_strncat(rsp, ",", len); strncat(rsp, ",", len);
len--; len--;
} }
c_strncat(rsp, "<", len); strncat(rsp, "<", len);
len--; len--;
for (i = 0; i < ep->path->count; i++) { for (i = 0; i < ep->path->count; i++) {
c_strncat(rsp, "/", len); strncat(rsp, "/", len);
len--; len--;
c_strncat(rsp, ep->path->elems[i], len); strncat(rsp, ep->path->elems[i], len);
len -= c_strlen(ep->path->elems[i]); len -= strlen(ep->path->elems[i]);
} }
c_strncat(rsp, ">;", len); strncat(rsp, ">;", len);
len -= 2; len -= 2;
c_strncat(rsp, ep->core_attr, len); strncat(rsp, ep->core_attr, len);
len -= c_strlen(ep->core_attr); len -= strlen(ep->core_attr);
} else { } else {
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head) coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){ while(NULL != h){
if (0 < c_strlen(rsp)) { if (0 < strlen(rsp)) {
c_strncat(rsp, ",", len); strncat(rsp, ",", len);
len--; len--;
} }
c_strncat(rsp, "<", len); strncat(rsp, "<", len);
len--; len--;
for (i = 0; i < ep->path->count; i++) { for (i = 0; i < ep->path->count; i++) {
c_strncat(rsp, "/", len); strncat(rsp, "/", len);
len--; len--;
c_strncat(rsp, ep->path->elems[i], len); strncat(rsp, ep->path->elems[i], len);
len -= c_strlen(ep->path->elems[i]); len -= strlen(ep->path->elems[i]);
} }
c_strncat(rsp, "/", len); strncat(rsp, "/", len);
len--; len--;
c_strncat(rsp, h->name, len); strncat(rsp, h->name, len);
len -= c_strlen(h->name); len -= strlen(h->name);
c_strncat(rsp, ">;", len); strncat(rsp, ">;", len);
len -= 2; len -= 2;
c_strncat(rsp, ep->core_attr, len); strncat(rsp, ep->core_attr, len);
len -= c_strlen(ep->core_attr); len -= strlen(ep->core_attr);
h = h->next; h = h->next;
} }
......
#include "hash.h" #include "hash.h"
#include "c_string.h" #include <string.h>
/* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY /* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY
* accordingly (see int coap_hash_path()); * accordingly (see int coap_hash_path());
*/ */
...@@ -20,7 +20,7 @@ void coap_hash(const unsigned char *s, unsigned int len, coap_key_t h) { ...@@ -20,7 +20,7 @@ void coap_hash(const unsigned char *s, unsigned int len, coap_key_t h) {
void coap_transaction_id(const uint32_t ip, const uint32_t port, const coap_packet_t *pkt, coap_tid_t *id) { void coap_transaction_id(const uint32_t ip, const uint32_t port, const coap_packet_t *pkt, coap_tid_t *id) {
coap_key_t h; coap_key_t h;
c_memset(h, 0, sizeof(coap_key_t)); memset(h, 0, sizeof(coap_key_t));
/* Compare the transport address. */ /* Compare the transport address. */
coap_hash((const unsigned char *)&(port), sizeof(port), h); coap_hash((const unsigned char *)&(port), sizeof(port), h);
......
#include "c_string.h" #include <string.h>
#include "c_stdlib.h" #include <stdlib.h>
#include "node.h" #include "node.h"
static inline coap_queue_t * static inline coap_queue_t *
coap_malloc_node(void) { coap_malloc_node(void) {
return (coap_queue_t *)c_zalloc(sizeof(coap_queue_t)); return (coap_queue_t *)calloc(1,sizeof(coap_queue_t));
} }
void coap_free_node(coap_queue_t *node) { void coap_free_node(coap_queue_t *node) {
c_free(node); free(node);
} }
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node) { int coap_insert_node(coap_queue_t **queue, coap_queue_t *node) {
...@@ -73,7 +73,7 @@ coap_queue_t * coap_new_node(void) { ...@@ -73,7 +73,7 @@ coap_queue_t * coap_new_node(void) {
return NULL; return NULL;
} }
c_memset(node, 0, sizeof(*node)); memset(node, 0, sizeof(*node));
return node; return node;
} }
......
#include "c_stdlib.h" #include <stdlib.h>
#include "pdu.h" #include "pdu.h"
coap_pdu_t * coap_new_pdu(void) { coap_pdu_t * coap_new_pdu(void) {
coap_pdu_t *pdu = NULL; coap_pdu_t *pdu = NULL;
pdu = (coap_pdu_t *)c_zalloc(sizeof(coap_pdu_t)); pdu = (coap_pdu_t *)calloc(1,sizeof(coap_pdu_t));
if(!pdu){ if(!pdu){
NODE_DBG("coap_new_pdu malloc error.\n"); NODE_DBG("coap_new_pdu malloc error.\n");
return NULL; return NULL;
} }
pdu->scratch.p = (uint8_t *)c_zalloc(MAX_REQ_SCRATCH_SIZE); pdu->scratch.p = (uint8_t *)calloc(1,MAX_REQ_SCRATCH_SIZE);
if(!pdu->scratch.p){ if(!pdu->scratch.p){
NODE_DBG("coap_new_pdu malloc error.\n"); NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu); free(pdu);
return NULL; return NULL;
} }
pdu->scratch.len = MAX_REQ_SCRATCH_SIZE; pdu->scratch.len = MAX_REQ_SCRATCH_SIZE;
pdu->pkt = (coap_packet_t *)c_zalloc(sizeof(coap_packet_t)); pdu->pkt = (coap_packet_t *)calloc(1,sizeof(coap_packet_t));
if(!pdu->pkt){ if(!pdu->pkt){
NODE_DBG("coap_new_pdu malloc error.\n"); NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->scratch.p); free(pdu->scratch.p);
c_free(pdu); free(pdu);
return NULL; return NULL;
} }
pdu->pkt->content.p = NULL; pdu->pkt->content.p = NULL;
pdu->pkt->content.len = 0; pdu->pkt->content.len = 0;
pdu->msg.p = (uint8_t *)c_zalloc(MAX_REQUEST_SIZE+1); // +1 for string '\0' pdu->msg.p = (uint8_t *)calloc(1,MAX_REQUEST_SIZE+1); // +1 for string '\0'
if(!pdu->msg.p){ if(!pdu->msg.p){
NODE_DBG("coap_new_pdu malloc error.\n"); NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->pkt); free(pdu->pkt);
c_free(pdu->scratch.p); free(pdu->scratch.p);
c_free(pdu); free(pdu);
return NULL; return NULL;
} }
pdu->msg.len = MAX_REQUEST_SIZE; pdu->msg.len = MAX_REQUEST_SIZE;
...@@ -44,22 +44,22 @@ void coap_delete_pdu(coap_pdu_t *pdu){ ...@@ -44,22 +44,22 @@ void coap_delete_pdu(coap_pdu_t *pdu){
return; return;
if(pdu->scratch.p){ if(pdu->scratch.p){
c_free(pdu->scratch.p); free(pdu->scratch.p);
pdu->scratch.p = NULL; pdu->scratch.p = NULL;
pdu->scratch.len = 0; pdu->scratch.len = 0;
} }
if(pdu->pkt){ if(pdu->pkt){
c_free(pdu->pkt); free(pdu->pkt);
pdu->pkt = NULL; pdu->pkt = NULL;
} }
if(pdu->msg.p){ if(pdu->msg.p){
c_free(pdu->msg.p); free(pdu->msg.p);
pdu->msg.p = NULL; pdu->msg.p = NULL;
pdu->msg.len = 0; pdu->msg.len = 0;
} }
c_free(pdu); free(pdu);
pdu = NULL; pdu = NULL;
} }
...@@ -6,23 +6,23 @@ ...@@ -6,23 +6,23 @@
* README for terms of use. * README for terms of use.
*/ */
#include "c_stdlib.h" #include <stdlib.h>
#include "c_types.h" #include <stddef.h>
#include "str.h" #include "str.h"
str * coap_new_string(size_t size) { str * coap_new_string(size_t size) {
str *s = (str *)c_malloc(sizeof(str) + size + 1); str *s = (str *)malloc(sizeof(str) + size + 1);
if ( !s ) { if ( !s ) {
return NULL; return NULL;
} }
c_memset(s, 0, sizeof(str)); memset(s, 0, sizeof(str));
s->s = ((unsigned char *)s) + sizeof(str); s->s = ((unsigned char *)s) + sizeof(str);
return s; return s;
} }
void coap_delete_string(str *s) { void coap_delete_string(str *s) {
c_free(s); free(s);
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef _COAP_STR_H_ #ifndef _COAP_STR_H_
#define _COAP_STR_H_ #define _COAP_STR_H_
#include "c_string.h" #include <string.h>
typedef struct { typedef struct {
size_t length; /* length of string */ size_t length; /* length of string */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment