From 67bed086faed1948a9c04e53760b809d0a962999 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Tue, 3 May 2016 17:21:38 -0400 Subject: [PATCH 01/31] UAVCAN: Update version --- canutils/uavcan/Kconfig | 2 +- ...tch => nuttx-b04396ace50155573e545ed9bf2fb09964ee2367.patch} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename canutils/uavcan/{nuttx-c152f28a620ceec9f63581a7c99fe77c89938048.patch => nuttx-b04396ace50155573e545ed9bf2fb09964ee2367.patch} (100%) diff --git a/canutils/uavcan/Kconfig b/canutils/uavcan/Kconfig index 0985ba88d..89e6bf60f 100644 --- a/canutils/uavcan/Kconfig +++ b/canutils/uavcan/Kconfig @@ -26,7 +26,7 @@ config UAVCAN_LIBUAVCAN_URL config UAVCAN_LIBUAVCAN_VERSION string "UAVCAN Version" - default "c152f28a620ceec9f63581a7c99fe77c89938048" + default "b04396ace50155573e545ed9bf2fb09964ee2367" ---help--- UAVCAN version. diff --git a/canutils/uavcan/nuttx-c152f28a620ceec9f63581a7c99fe77c89938048.patch b/canutils/uavcan/nuttx-b04396ace50155573e545ed9bf2fb09964ee2367.patch similarity index 100% rename from canutils/uavcan/nuttx-c152f28a620ceec9f63581a7c99fe77c89938048.patch rename to canutils/uavcan/nuttx-b04396ace50155573e545ed9bf2fb09964ee2367.patch From 231be599774af39475bd57445d9ff6eea4a16170 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 6 May 2016 05:03:11 -0600 Subject: [PATCH 02/31] Update ChangeLog --- ChangeLog.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index b17e2577b..50854b7c0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1583,4 +1583,5 @@ of the RTC driver (2016-04-03). * apps/examples/nximage: No configuration option to select greyscale. - + * apps/canutils/uavcan: Update UAVCAN version. From Paul Alexander + Patience (2016-05-03) From aa2bcd0a527e9e57da0d418052cc824a0a93397a Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Mon, 9 May 2016 09:10:04 -0400 Subject: [PATCH 03/31] UAVCAN: Fix typo in Makefile --- canutils/uavcan/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/canutils/uavcan/Makefile b/canutils/uavcan/Makefile index 9ad5f4216..ff012bb85 100644 --- a/canutils/uavcan/Makefile +++ b/canutils/uavcan/Makefile @@ -248,7 +248,7 @@ clean: distclean: clean $(call DELFILE, Make.dep) $(call DELFILE, .depend) - $(call DEFLFILE, .libuavcan_patched) + $(call DELFILE, .libuavcan_patched) $(call DELDIR, $(LIBUAVCAN_UNPACKNAME)) $(call DELFILE, $(LIBUAVCAN_PACKNAME)) $(call DELDIR, $(DSDL_UNPACKNAME)) From 29e8b8e059a9ba4bb1d3bebd71296d285bb0269a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 10 May 2016 15:40:20 -0600 Subject: [PATCH 04/31] Several Makefiles: Add .PHONY definitions to prevent 'clean up to date' message weirdness; Add default definitions for some commonly used things when 'make clean' is used without .config or Make.defs files installed. --- ChangeLog.txt | 4 ++++ examples/elf/tests/errno/Makefile | 6 +++++- examples/elf/tests/hello/Makefile | 6 +++++- examples/elf/tests/helloxx/Makefile | 6 +++++- examples/elf/tests/longjmp/Makefile | 6 +++++- examples/elf/tests/mutex/Makefile | 6 +++++- examples/elf/tests/pthread/Makefile | 6 +++++- examples/elf/tests/signal/Makefile | 6 +++++- examples/elf/tests/struct/Makefile | 6 +++++- examples/elf/tests/task/Makefile | 6 +++++- examples/module/Makefile | 6 +++++- examples/module/drivers/chardev/Makefile | 6 +++++- .../posix_spawn/filesystem/hello/Makefile | 3 ++- .../posix_spawn/filesystem/redirect/Makefile | 3 ++- examples/thttpd/content/hello/Makefile | 13 +++++++------ examples/thttpd/content/netstat/Makefile | 13 +++++++------ examples/thttpd/content/tasks/Makefile | 16 ++++++++++------ examples/usbserial/Makefile | 2 +- examples/usbserial/Makefile.host | 19 ++++++++++--------- interpreters/micropython/Makefile | 3 ++- platform/Makefile | 6 ++++-- 21 files changed, 104 insertions(+), 44 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 50854b7c0..f5f8f8374 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1585,3 +1585,7 @@ greyscale. * apps/canutils/uavcan: Update UAVCAN version. From Paul Alexander Patience (2016-05-03) + * Several Makefiles: Add .PHONY definitions to prevent 'clean up to date' + message weirdness; Add default definitions for some commonly used + things when 'make clean' is used without .config or Make.defs files + installed (2016-05-10). diff --git a/examples/elf/tests/errno/Makefile b/examples/elf/tests/errno/Makefile index 89e3f2bfd..6b2d4e0b4 100644 --- a/examples/elf/tests/errno/Makefile +++ b/examples/elf/tests/errno/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/errno/Makefile # -# Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + ifeq ($(WINTOOL),y) NUTTXLIB = "${shell cygpath -w $(TOPDIR)$(DELIM)lib}" else @@ -69,6 +72,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=$(OBJEXT)) all: $(BIN) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.c @echo "CC: $<" diff --git a/examples/elf/tests/hello/Makefile b/examples/elf/tests/hello/Makefile index f89759a66..28ad22211 100644 --- a/examples/elf/tests/hello/Makefile +++ b/examples/elf/tests/hello/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/hello/Makefile # -# Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + ifeq ($(WINTOOL),y) NUTTXLIB = "${shell cygpath -w $(TOPDIR)$(DELIM)lib}" else @@ -69,6 +72,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=$(OBJEXT)) all: $(BIN) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.c @echo "CC: $<" diff --git a/examples/elf/tests/helloxx/Makefile b/examples/elf/tests/helloxx/Makefile index 4ab072a21..135bbd1b8 100644 --- a/examples/elf/tests/helloxx/Makefile +++ b/examples/elf/tests/helloxx/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/helloxx/Makefile # -# Copyright (C) 2012, 2014-2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2014-2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + ifeq ($(WINTOOL),y) NUTTXLIB = "${shell cygpath -w $(TOPDIR)$(DELIM)lib}" else @@ -98,6 +101,7 @@ LDLIBSTDC_STUBS_DIR = $(TOPDIR)/libxx LDLIBSTDC_STUBS_LIB = $(LDLIBSTDC_STUBS_DIR)/liblibxx.a all: $(BIN1) $(BIN2) $(BIN3) $(BIN4) $(BIN5) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.cpp @echo "CC: $<" diff --git a/examples/elf/tests/longjmp/Makefile b/examples/elf/tests/longjmp/Makefile index 26fa393bd..da76c2dbb 100644 --- a/examples/elf/tests/longjmp/Makefile +++ b/examples/elf/tests/longjmp/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/longjmp/Makefile # -# Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + ifeq ($(WINTOOL),y) NUTTXLIB = "${shell cygpath -w $(TOPDIR)$(DELIM)lib}" else @@ -69,6 +72,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=$(OBJEXT)) all: $(BIN) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.c @echo "CC: $<" diff --git a/examples/elf/tests/mutex/Makefile b/examples/elf/tests/mutex/Makefile index f8ce4f613..865ccf497 100644 --- a/examples/elf/tests/mutex/Makefile +++ b/examples/elf/tests/mutex/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/mutex/Makefile # -# Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + ifeq ($(WINTOOL),y) NUTTXLIB = "${shell cygpath -w $(TOPDIR)$(DELIM)lib}" else @@ -69,6 +72,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=$(OBJEXT)) all: $(BIN) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.c @echo "CC: $<" diff --git a/examples/elf/tests/pthread/Makefile b/examples/elf/tests/pthread/Makefile index 9d4ce496b..370dab604 100644 --- a/examples/elf/tests/pthread/Makefile +++ b/examples/elf/tests/pthread/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/pthread/Makefile # -# Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + ifeq ($(WINTOOL),y) NUTTXLIB = "${shell cygpath -w $(TOPDIR)$(DELIM)lib}" else @@ -69,6 +72,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=$(OBJEXT)) all: $(BIN) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.c @echo "CC: $<" diff --git a/examples/elf/tests/signal/Makefile b/examples/elf/tests/signal/Makefile index c442ae9c6..22b1185d5 100644 --- a/examples/elf/tests/signal/Makefile +++ b/examples/elf/tests/signal/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/signal/Makefile # -# Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + ifeq ($(WINTOOL),y) NUTTXLIB = "${shell cygpath -w $(TOPDIR)$(DELIM)lib}" else @@ -69,6 +72,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=$(OBJEXT)) all: $(BIN) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.c @echo "CC: $<" diff --git a/examples/elf/tests/struct/Makefile b/examples/elf/tests/struct/Makefile index 8fe7cf710..8045ed386 100644 --- a/examples/elf/tests/struct/Makefile +++ b/examples/elf/tests/struct/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/struct/Makefile # -# Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + CELFFLAGS += -I. ifeq ($(WINTOOL),y) @@ -70,6 +73,7 @@ SRCS = struct_main.c struct_dummy.c OBJS = $(SRCS:.c=$(OBJEXT)) all: $(BIN) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.c @echo "CC: $<" diff --git a/examples/elf/tests/task/Makefile b/examples/elf/tests/task/Makefile index 572d1072e..88289fcc6 100644 --- a/examples/elf/tests/task/Makefile +++ b/examples/elf/tests/task/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/task/Makefile # -# Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + ifeq ($(WINTOOL),y) NUTTXLIB = "${shell cygpath -w $(TOPDIR)$(DELIM)lib}" else @@ -69,6 +72,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=$(OBJEXT)) all: $(BIN) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.c @echo "CC: $<" diff --git a/examples/module/Makefile b/examples/module/Makefile index f869adf30..680b6e58c 100644 --- a/examples/module/Makefile +++ b/examples/module/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/examples/module/Makefile # -# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,10 @@ -include $(TOPDIR)/.config -include $(TOPDIR)/Make.defs + +OBJEXT ?= .o +DELIM ?= / + include $(APPDIR)/Make.defs # Module example built-in application info diff --git a/examples/module/drivers/chardev/Makefile b/examples/module/drivers/chardev/Makefile index 256e5821f..67ae38255 100644 --- a/examples/module/drivers/chardev/Makefile +++ b/examples/module/drivers/chardev/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/module/drivers/chardev/Makefile # -# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,9 @@ -include $(TOPDIR)/Make.defs +OBJEXT ?= .o +DELIM ?= / + ifeq ($(WINTOOL),y) NUTTXLIB = "${shell cygpath -w $(TOPDIR)$(DELIM)lib}" else @@ -71,6 +74,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=$(OBJEXT)) all: $(BIN) +.PHONY: clean install $(OBJS): %$(OBJEXT): %.c @echo "CC: $<" diff --git a/examples/posix_spawn/filesystem/hello/Makefile b/examples/posix_spawn/filesystem/hello/Makefile index 4097c6f86..728f49904 100644 --- a/examples/posix_spawn/filesystem/hello/Makefile +++ b/examples/posix_spawn/filesystem/hello/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/elf/tests/hello/Makefile # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=.o) all: $(BIN) +.PHONY: clean install $(OBJS): %.o: %.c @echo "CC: $<" diff --git a/examples/posix_spawn/filesystem/redirect/Makefile b/examples/posix_spawn/filesystem/redirect/Makefile index c6259d819..fa1a9a818 100644 --- a/examples/posix_spawn/filesystem/redirect/Makefile +++ b/examples/posix_spawn/filesystem/redirect/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/posix_spawn/filesystem/redirect/Makefile # -# Copyright (C) 2013 Gregory Nutt. All rights reserved. +# Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ SRCS = $(BIN).c OBJS = $(SRCS:.c=.o) all: $(BIN) +.PHONY: clean install $(OBJS): %.o: %.c @echo "CC: $<" diff --git a/examples/thttpd/content/hello/Makefile b/examples/thttpd/content/hello/Makefile index 2856490ab..046684981 100644 --- a/examples/thttpd/content/hello/Makefile +++ b/examples/thttpd/content/hello/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/thttpd/content/hello/Makefile # -# Copyright (C) 2009 Gregory Nutt. All rights reserved. +# Copyright (C) 2009, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,15 +35,16 @@ -include $(TOPDIR)/Make.defs -BIN = hello +BIN = hello -R1SRCS = $(BIN).c -R1OBJS = $(R1SRCS:.c=.o) +R1SRCS = $(BIN).c +R1OBJS = $(R1SRCS:.c=.o) -R2SRC = $(BIN)-thunk.S -R2OBJ = $(R2SRC:.S=.o) +R2SRC = $(BIN)-thunk.S +R2OBJ = $(R2SRC:.S=.o) all: $(BIN) +.PHONY: clean install $(R1OBJS): %.o: %.c @echo "CC: $<" diff --git a/examples/thttpd/content/netstat/Makefile b/examples/thttpd/content/netstat/Makefile index 6d89bcd88..9b8c84b9c 100644 --- a/examples/thttpd/content/netstat/Makefile +++ b/examples/thttpd/content/netstat/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/thttpd/content/netstat/Makefile # -# Copyright (C) 2009 Gregory Nutt. All rights reserved. +# Copyright (C) 2009, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,15 +35,16 @@ -include $(TOPDIR)/Make.defs -BIN = netstat +BIN = netstat -R1SRCS = $(BIN).c -R1OBJS = $(R1SRCS:.c=.o) +R1SRCS = $(BIN).c +R1OBJS = $(R1SRCS:.c=.o) -R2SRC = $(BIN)-thunk.S -R2OBJ = $(R2SRC:.S=.o) +R2SRC = $(BIN)-thunk.S +R2OBJ = $(R2SRC:.S=.o) all: $(BIN) +.PHONY: clean install $(R1OBJS): %.o: %.c @echo "CC: $<" diff --git a/examples/thttpd/content/tasks/Makefile b/examples/thttpd/content/tasks/Makefile index 418fca2b3..0754b1ed4 100644 --- a/examples/thttpd/content/tasks/Makefile +++ b/examples/thttpd/content/tasks/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/thttpd/content/tasks/Makefile # -# Copyright (C) 2009 Gregory Nutt. All rights reserved. +# Copyright (C) 2009, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -35,15 +35,19 @@ -include $(TOPDIR)/Make.defs -BIN = tasks +OBJEXT ?= .o +DELIM ?= / -R1SRCS = $(BIN).c -R1OBJS = $(R1SRCS:.c=.o) +BIN = tasks -R2SRC = $(BIN)-thunk.S -R2OBJ = $(R2SRC:.S=.o) +R1SRCS = $(BIN).c +R1OBJS = $(R1SRCS:.c=.o) + +R2SRC = $(BIN)-thunk.S +R2OBJ = $(R2SRC:.S=.o) all: $(BIN) +.PHONY: clean install $(R1OBJS): %.o: %.c @echo "CC: $<" diff --git a/examples/usbserial/Makefile b/examples/usbserial/Makefile index f7d0b9602..3b8444449 100644 --- a/examples/usbserial/Makefile +++ b/examples/usbserial/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/examples/usbserial/Makefile # -# Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2008, 2010-2012, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/examples/usbserial/Makefile.host b/examples/usbserial/Makefile.host index c6ebf54e5..6abf77966 100644 --- a/examples/usbserial/Makefile.host +++ b/examples/usbserial/Makefile.host @@ -1,7 +1,7 @@ ############################################################################ # apps/examples/usbserial/Makefile.host # -# Copyright (C) 2008, 2011, 2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2008, 2011, 2015-2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,27 +37,28 @@ -include $(TOPDIR)/Make.defs -SRC = host.c -BIN = host$(EXEEXT) +SRC = host.c +BIN = host$(EXEEXT) -DEFINES = +DEFINES = ifeq ($(CONFIG_EXAMPLES_USBSERIAL_INONLY),y) -DEFINES += -DCONFIG_EXAMPLES_USBSERIAL_INONLY=1 +DEFINES += -DCONFIG_EXAMPLES_USBSERIAL_INONLY=1 endif ifeq ($(CONFIG_EXAMPLES_USBSERIAL_OUTONLY),y) -DEFINES += -DCONFIG_EXAMPLES_USBSERIAL_OUTONLY=1 +DEFINES += -DCONFIG_EXAMPLES_USBSERIAL_OUTONLY=1 endif ifeq ($(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL),y) -DEFINES += -DCONFIG_EXAMPLES_USBSERIAL_ONLYSMALL=1 +DEFINES += -DCONFIG_EXAMPLES_USBSERIAL_ONLYSMALL=1 endif ifeq ($(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG),y) -DEFINES += -DCONFIG_EXAMPLES_USBSERIAL_ONLYBIG=1 +DEFINES += -DCONFIG_EXAMPLES_USBSERIAL_ONLYBIG=1 endif ifeq ($(CONFIG_CDCACM),y) -DEFINES += -DCONFIG_CDCACM=1 +DEFINES += -DCONFIG_CDCACM=1 endif all: $(BIN) +.PHONY: clean $(BIN): $(SRC) @$(HOSTCC) $(HOSTCFLAGS) $(DEFINES) $^ -o $@ diff --git a/interpreters/micropython/Makefile b/interpreters/micropython/Makefile index fec76d913..7c9fe19ed 100644 --- a/interpreters/micropython/Makefile +++ b/interpreters/micropython/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/ interpreters/micropython/Makefile # -# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2015, 2016 Gregory Nutt. All rights reserved. # Authors: Gregory Nutt # Dave Marples # @@ -127,6 +127,7 @@ ROOTDEPPATH = --dep-path . # Common build all: .built +.PHONY: install context clean distclean $(MICROPYTHON_TARBALL): @echo "Downloading: $(MICROPYTHON_TARBALL)" diff --git a/platform/Makefile b/platform/Makefile index 0e811ffc7..58e9dc50a 100644 --- a/platform/Makefile +++ b/platform/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/platform/Makefile # -# Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2013-2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -96,7 +96,7 @@ endif # Build targets all: .built -.PHONY: context .depend depend clean distclean +.PHONY: $(TOPDIR)$(DELIM).config context .depend depend clean distclean ifneq ($(ASRCS),) $(AOBJS): bin$(DELIM)%$(OBJEXT): %.S @@ -116,6 +116,8 @@ endif # Build context setup +$(TOPDIR)$(DELIM).config: + $(PLATFORMDIR): $(TOPDIR)$(DELIM).config @echo "LN: platform$(DELIM)board to $(LINKDIR)" $(Q) $(DIRUNLINK) $(PLATFORMDIR) From 0a33420e0203ead8df4d9f286c50ea94620810cc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 10 May 2016 16:40:16 -0600 Subject: [PATCH 05/31] apps/platform/Makefile: .config should not be a .PHONY target --- platform/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/Makefile b/platform/Makefile index 58e9dc50a..ca4cc1795 100644 --- a/platform/Makefile +++ b/platform/Makefile @@ -96,7 +96,7 @@ endif # Build targets all: .built -.PHONY: $(TOPDIR)$(DELIM).config context .depend depend clean distclean +.PHONY: context .depend depend clean distclean ifneq ($(ASRCS),) $(AOBJS): bin$(DELIM)%$(OBJEXT): %.S From 1106658ab1417d52792250ccc0b13e23869292fc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 10 May 2016 18:25:13 -0600 Subject: [PATCH 06/31] Another minor Makefile improvement for the case of no .config file --- platform/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platform/Makefile b/platform/Makefile index ca4cc1795..4687b110c 100644 --- a/platform/Makefile +++ b/platform/Makefile @@ -36,7 +36,9 @@ -include $(TOPDIR)/.config -include $(TOPDIR)/Make.defs +CONFIG_ARCH_BOARD ?= dummy DELIM ?= $(strip /) + include $(APPDIR)$(DELIM)Make.defs # Platform-specific Appliction Support From 0fcc63b642c7cfe49e17d92c932ff1422e8106c7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 10 May 2016 18:32:31 -0600 Subject: [PATCH 07/31] I don't think it is necessary to create the apps/platform/board link when cleaning --- platform/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/Makefile b/platform/Makefile index 4687b110c..a6f030a89 100644 --- a/platform/Makefile +++ b/platform/Makefile @@ -139,7 +139,7 @@ depend: .depend # Clean targets -clean: $(PLATFORMDIR) +clean: $(call DELFILE, .built) $(Q) $(MAKE) -C bin TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" clean From 6a68a12269297e5ec01c2992e1814dcfdc7803d6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 11 May 2016 17:41:13 -0600 Subject: [PATCH 08/31] apps/examplessmp: Fix a place where a spurious semicolon causes bad conditional logic --- examples/smp/smp_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/smp/smp_main.c b/examples/smp/smp_main.c index 59987758b..8ed0f942b 100644 --- a/examples/smp/smp_main.c +++ b/examples/smp/smp_main.c @@ -309,7 +309,7 @@ int smp_main(int argc, char *argv[]) for (i = 0; i < CONFIG_EXAMPLES_SMP_NBARRIER_THREADS; i++) { - if (threadid[i] != 0); + if (threadid[i] != 0) { ret = pthread_join(threadid[i], &result); show_cpu_conditional(" Main", 0); From 1556424b92edbece957c8400d1a6f447a5001d59 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Thu, 12 May 2016 11:50:50 -0400 Subject: [PATCH 09/31] libcanard: Add libcanard UAVCAN library --- canutils/Kconfig | 1 + canutils/libcanard/.gitignore | 2 + canutils/libcanard/Kconfig | 27 +++++++++ canutils/libcanard/Make.defs | 39 ++++++++++++ canutils/libcanard/Makefile | 111 ++++++++++++++++++++++++++++++++++ include/canutils/.gitignore | 1 + 6 files changed, 181 insertions(+) create mode 100644 canutils/libcanard/.gitignore create mode 100644 canutils/libcanard/Kconfig create mode 100644 canutils/libcanard/Make.defs create mode 100644 canutils/libcanard/Makefile create mode 100644 include/canutils/.gitignore diff --git a/canutils/Kconfig b/canutils/Kconfig index 59830cba2..a0907602b 100644 --- a/canutils/Kconfig +++ b/canutils/Kconfig @@ -6,5 +6,6 @@ menu "CAN Utilities" source "$APPSDIR/canutils/uavcan/Kconfig" +source "$APPSDIR/canutils/libcanard/Kconfig" endmenu # CAN Utilities diff --git a/canutils/libcanard/.gitignore b/canutils/libcanard/.gitignore new file mode 100644 index 000000000..5ca33bd27 --- /dev/null +++ b/canutils/libcanard/.gitignore @@ -0,0 +1,2 @@ +/.built +/libcanard-* diff --git a/canutils/libcanard/Kconfig b/canutils/libcanard/Kconfig new file mode 100644 index 000000000..e4635cb63 --- /dev/null +++ b/canutils/libcanard/Kconfig @@ -0,0 +1,27 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config CANUTILS_LIBCANARD + bool "libcanard UAVCAN Library" + default n + depends on CAN && CAN_EXTID + ---help--- + Enable the libcanard UAVCAN library. + +if CANUTILS_LIBCANARD + +config LIBCANARD_URL + string "libcanard URL" + default "https://github.com/UAVCAN/libcanard/archive" + ---help--- + libcanard URL. + +config LIBCANARD_VERSION + string "libcanard Version" + default "34195e7f13637bdc79198c94bd1b2e5ecffe9383" + ---help--- + libcanard version. + +endif diff --git a/canutils/libcanard/Make.defs b/canutils/libcanard/Make.defs new file mode 100644 index 000000000..22cd3e077 --- /dev/null +++ b/canutils/libcanard/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/canutils/libcanard/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved. +# Author: Paul Alexander Patience +# +# 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 NuttX 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. +# +############################################################################ + +ifeq ($(CONFIG_CANUTILS_LIBCANARD),y) +CONFIGURED_APPS += canutils/libcanard +endif diff --git a/canutils/libcanard/Makefile b/canutils/libcanard/Makefile new file mode 100644 index 000000000..79c2bb853 --- /dev/null +++ b/canutils/libcanard/Makefile @@ -0,0 +1,111 @@ +############################################################################ +# apps/canutils/libcanard/Makefile +# +# Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved. +# Authors: Paul Alexander Patience +# +# 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 NuttX 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. +# +############################################################################ + +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +WGET = wget +UNPACK = unzip +PACKEXT = .zip + +LIBCANARD_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARD_URL))) +LIBCANARD_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBCANARD_VERSION))) +LIBCANARD_UNPACKNAME = libcanard-$(LIBCANARD_VERSION) +LIBCANARD_PACKNAME = $(LIBCANARD_UNPACKNAME)$(PACKEXT) +LIBCANARD_SRCDIR = $(LIBCANARD_UNPACKNAME)$(DELIM)src + +CSRCS = $(LIBCANARD_SRCDIR)$(DELIM)canard.c +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(CSRCS) +OBJS = $(COBJS) + +ifeq ($(WINTOOL),y) + BIN = "${shell cygpath -w $(APPDIR)$(DELIM)libapps$(LIBEXT)}" +else + BIN = $(APPDIR)$(DELIM)libapps$(LIBEXT) +endif + +ROOTDEPPATH = --dep-path . + +VPATH = + +all: .built +.PHONY: clean depend distclean + +$(LIBCANARD_PACKNAME): + @echo "Downloading: $@" + $(Q) $(WGET) -O $@ $(LIBCANARD_URL)$(DELIM)$(LIBCANARD_VERSION)$(PACKEXT) + +$(LIBCANARD_UNPACKNAME): $(LIBCANARD_PACKNAME) + @echo "Unpacking: $< -> $@" + $(Q) $(UNPACK) $< + $(Q) touch $@ + +$(LIBCANARD_SRCDIR)$(DELIM)canard.h: $(LIBCANARD_UNPACKNAME) + +$(APPDIR)$(DELIM)include$(DELIM)canutils$(DELIM)canard.h: $(LIBCANARD_SRCDIR)$(DELIM)canard.h + $(Q) cp $< $@ + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + $(Q) touch $@ + +install: + +context: $(APPDIR)$(DELIM)include$(DELIM)canutils$(DELIM)canard.h + +.depend: Makefile $(SRCS) + $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + $(foreach OBJ, $(OBJS), $(call DELFILE, $(OBJ))) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + $(call DELFILE, $(APPDIR)$(DELIM)include$(DELIM)canutils$(DELIM)canard.h) + $(call DELDIR, $(LIBCANARD_UNPACKNAME)) + $(call DELFILE, $(LIBCANARD_PACKNAME)) + +-include Make.dep diff --git a/include/canutils/.gitignore b/include/canutils/.gitignore new file mode 100644 index 000000000..369d64802 --- /dev/null +++ b/include/canutils/.gitignore @@ -0,0 +1 @@ +/canard.h From 6fded1a8e19ef32ed7a427e2bd7b2f133c76aa07 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Thu, 12 May 2016 14:17:40 -0400 Subject: [PATCH 10/31] Simplify some Makefiles --- Application.mk | 4 ++-- canutils/uavcan/Makefile | 34 +++++++++++++++---------------- interpreters/micropython/Makefile | 12 +++++------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Application.mk b/Application.mk index cd9d247c2..5b7a4e5ad 100644 --- a/Application.mk +++ b/Application.mk @@ -90,13 +90,13 @@ endif .built: $(OBJS) $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built + $(Q) touch $@ ifeq ($(CONFIG_BUILD_KERNEL),y) $(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ) @echo "LD: $(PROGNAME)" $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS) - $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) + $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) install: $(BIN_DIR)$(DELIM)$(PROGNAME) else diff --git a/canutils/uavcan/Makefile b/canutils/uavcan/Makefile index 9ad5f4216..f561c5e0d 100644 --- a/canutils/uavcan/Makefile +++ b/canutils/uavcan/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/canutils/uavcan/Makefile # -# Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. +# Copyright (C) 2015-2016 Omni Hoverboards Inc. All rights reserved. # Author: Paul Alexander Patience # # Redistribution and use in source and binary forms, with or without @@ -177,31 +177,31 @@ all: .built .PHONY: clean depend distclean $(LIBUAVCAN_PACKNAME): - @echo "Downloading: $(LIBUAVCAN_PACKNAME)" - $(Q) $(WGET) -O $(LIBUAVCAN_PACKNAME) $(LIBUAVCAN_URL)$(DELIM)$(LIBUAVCAN_VERSION)$(PACKEXT) + @echo "Downloading: $@" + $(Q) $(WGET) -O $@ $(LIBUAVCAN_URL)$(DELIM)$(LIBUAVCAN_VERSION)$(PACKEXT) $(LIBUAVCAN_UNPACKNAME): $(LIBUAVCAN_PACKNAME) - @echo "Unpacking: $(LIBUAVCAN_PACKNAME) -> $(LIBUAVCAN_UNPACKNAME)" - $(Q) $(UNPACK) $(LIBUAVCAN_PACKNAME) - $(Q) touch $(LIBUAVCAN_UNPACKNAME) + @echo "Unpacking: $< -> $@" + $(Q) $(UNPACK) $< + $(Q) touch $@ $(DSDL_PACKNAME): - @echo "Downloading: $(DSDL_PACKNAME)" - $(Q) $(WGET) -O $(DSDL_PACKNAME) $(DSDL_URL)$(DELIM)$(DSDL_VERSION)$(PACKEXT) + @echo "Downloading: $@" + $(Q) $(WGET) -O $@ $(DSDL_URL)$(DELIM)$(DSDL_VERSION)$(PACKEXT) $(DSDL_UNPACKNAME): $(DSDL_PACKNAME) - @echo "Unpacking: $(DSDL_PACKNAME) -> $(DSDL_UNPACKNAME)" - $(Q) $(UNPACK) $(DSDL_PACKNAME) - $(Q) touch $(DSDL_UNPACKNAME) + @echo "Unpacking: $< -> $@" + $(Q) $(UNPACK) $< + $(Q) touch $@ $(PYUAVCAN_PACKNAME): - @echo "Downloading: $(PYUAVCAN_PACKNAME)" - $(Q) $(WGET) -O $(PYUAVCAN_PACKNAME) $(PYUAVCAN_URL)$(DELIM)$(PYUAVCAN_VERSION)$(PACKEXT) + @echo "Downloading: $@" + $(Q) $(WGET) -O $@ $(PYUAVCAN_URL)$(DELIM)$(PYUAVCAN_VERSION)$(PACKEXT) $(PYUAVCAN_UNPACKNAME): $(PYUAVCAN_PACKNAME) - @echo "Unpacking: $(PYUAVCAN_PACKNAME) -> $(PYUAVCAN_UNPACKNAME)" - $(Q) $(UNPACK) $(PYUAVCAN_PACKNAME) - $(Q) touch $(PYUAVCAN_UNPACKNAME) + @echo "Unpacking: $< -> $@" + $(Q) $(UNPACK) $< + $(Q) touch $@ libuavcan: $(LIBUAVCAN_UNPACKNAME) $(DSDL_UNPACKNAME) $(PYUAVCAN_UNPACKNAME) $(Q) cp -R $(LIBUAVCAN_UNPACKNAME) libuavcan @@ -226,7 +226,7 @@ $(CXXOBJS): %$(OBJEXT): %$(CXXEXT) .built: $(CXXOBJS) $(call ARCHIVE, $(BIN), $(CXXOBJS)) - $(Q) touch .built + $(Q) touch $@ install: diff --git a/interpreters/micropython/Makefile b/interpreters/micropython/Makefile index fec76d913..61c5d010d 100644 --- a/interpreters/micropython/Makefile +++ b/interpreters/micropython/Makefile @@ -55,7 +55,7 @@ MICROPYTHON_UNPACKNAME = micropython-$(MICROPYTHON_VERSION) UNPACK ?= tar -zxf MICROPYTHON_UNPACKDIR = $(WD)/$(MICROPYTHON_UNPACKNAME) -MICROPTHYON_SRCDIR = $(MICROPYTHON_UNPACKDIR)/py +MICROPYTHON_SRCDIR = $(MICROPYTHON_UNPACKDIR)/py # Get the Micro Python build environment. mkenv.mk has these dependencies # @@ -63,7 +63,7 @@ MICROPTHYON_SRCDIR = $(MICROPYTHON_UNPACKDIR)/py # CROSS_COMPILE - Tool prefix (same as CROSSDEV in NuttX) CROSS_COMPILE ?= $(CROSSDEV) --include $(MICROPTHYON_SRCDIR)/mkenv.mk +-include $(MICROPYTHON_SRCDIR)/mkenv.mk # qstr definitions (must come before including py.mk) @@ -71,7 +71,7 @@ QSTR_DEFS = qstrdefsport.h # Include py core make definitions --include $(MICROPTHYON_SRCDIR)/py.mk +-include $(MICROPYTHON_SRCDIR)/py.mk # c99 is needed for Micro Python @@ -139,13 +139,13 @@ $(MICROPYTHON_UNPACKNAME): $(MICROPYTHON_TARBALL) .built: $(MICROPYTHON_UNPACKNAME) $(OBJ) $(call ARCHIVE, $(BIN), $(OBJ)) - @touch .built + @touch $@ ifeq ($(CONFIG_BUILD_KERNEL),y) $(BIN_DIR)$(DELIM)$(PROGNAME): $(MICROPYTHON_UNPACKNAME) $(OBJ) $(MAINOBJ) @echo "LD: $(PROGNAME)" $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS) - $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) + $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) install: $(BIN_DIR)$(DELIM)$(PROGNAME) else @@ -179,5 +179,5 @@ distclean: clean $(call DELFILE, .downloaded) $(call DELFILE, $(MICROPYTHON_TARBALL)) --include $(MICROPTHYON_SRCDIR)/mkrules.mk +-include $(MICROPYTHON_SRCDIR)/mkrules.mk -include Make.dep From 4f33dd14d4e969b1250ec72b46fd222339fcb3a5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 May 2016 19:21:51 -0600 Subject: [PATCH 11/31] apps/examples/watchdog: Remove call to up_wdginitialize(). This must be done in board-specific initialization. The call fram application space is not permitted. --- examples/watchdog/Kconfig | 15 +++++++++++++++ examples/watchdog/watchdog_main.c | 29 +---------------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/examples/watchdog/Kconfig b/examples/watchdog/Kconfig index 6e9e5c55f..42121531d 100644 --- a/examples/watchdog/Kconfig +++ b/examples/watchdog/Kconfig @@ -9,6 +9,21 @@ config EXAMPLES_WATCHDOG ---help--- Enable the watchdog timer example + In order to use this example, board specific logic must register the + watchdog timer driver. That would be in the board bring-up logic + in the configs//src directory for the board. + + The way that this is done depends on the underlying MCU architecture. + For STM32, this would be done like: + + #include "stm32_wdg.h" + + #if defined(CONFIG_STM32_WWDG) + stm32_wwdginitialize(CONFIG_STM32_WDG_DEVPATH); + #elif defined(CONFIG_STM32_IWDG) + stm32_iwdginitialize(CONFIG_STM32_WDG_DEVPATH, CONFIG_STM32_LSIFREQ); + #endif + if EXAMPLES_WATCHDOG config EXAMPLES_WATCHDOG_DEVPATH diff --git a/examples/watchdog/watchdog_main.c b/examples/watchdog/watchdog_main.c index aeff559dd..edce88b4e 100644 --- a/examples/watchdog/watchdog_main.c +++ b/examples/watchdog/watchdog_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/watchdog/watchdog_main.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -53,10 +53,6 @@ #include "watchdog.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ @@ -68,18 +64,6 @@ struct wdog_example_s uint32_t timeout; }; -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -238,17 +222,6 @@ int wdog_main(int argc, char *argv[]) parse_args(&wdog, argc, argv); - /* Initialization of the WATCHDOG hardware is performed by logic external to - * this test. - */ - - ret = up_wdginitialize(); - if (ret != OK) - { - printf("wdog_main: up_wdginitialize failed: %d\n", ret); - goto errout; - } - /* Open the watchdog device for reading */ fd = open(CONFIG_EXAMPLES_WATCHDOG_DEVPATH, O_RDONLY); From 62fec5d57df4f75da0cc3ec70ed0774e3951121a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 May 2016 19:22:47 -0600 Subject: [PATCH 12/31] apps/system/sched_note: Move the schduler note monitor from example/ to system/ --- examples/Kconfig | 1 - examples/README.txt | 5 --- examples/sched_note/Make.defs | 39 --------------------- system/Kconfig | 1 + system/Make.defs | 4 +++ system/hex2bin/Makefile | 8 ++--- system/mdio/Makefile | 2 +- system/mdio/mdio_main.c | 2 +- system/prun/prun.h | 8 ++--- {examples => system}/sched_note/.gitignore | 0 {examples => system}/sched_note/Kconfig | 20 +++++------ {examples => system}/sched_note/Makefile | 14 ++++---- {examples => system}/sched_note/note_main.c | 12 +++---- 13 files changed, 38 insertions(+), 78 deletions(-) delete mode 100644 examples/sched_note/Make.defs rename {examples => system}/sched_note/.gitignore (100%) rename {examples => system}/sched_note/Kconfig (64%) rename {examples => system}/sched_note/Makefile (86%) rename {examples => system}/sched_note/note_main.c (97%) diff --git a/examples/Kconfig b/examples/Kconfig index 780502cff..bf8a2b3de 100644 --- a/examples/Kconfig +++ b/examples/Kconfig @@ -68,7 +68,6 @@ source "$APPSDIR/examples/relays/Kconfig" source "$APPSDIR/examples/rgbled/Kconfig" source "$APPSDIR/examples/rgmp/Kconfig" source "$APPSDIR/examples/romfs/Kconfig" -source "$APPSDIR/examples/sched_note/Kconfig" source "$APPSDIR/examples/sendmail/Kconfig" source "$APPSDIR/examples/serialblaster/Kconfig" source "$APPSDIR/examples/serialrx/Kconfig" diff --git a/examples/README.txt b/examples/README.txt index ee603ace6..14291a07f 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -1751,11 +1751,6 @@ examples/romfs * CONFIG_EXAMPLES_ROMFS_MOUNTPOINT The location to mount the ROM disk. Deafault: "/usr/local/share" -examples/sched_note -^^^^^^^^^^^^^^^^^^^ - - This is a simple test of the Scheduler instrumentation logic. - examples/sendmail ^^^^^^^^^^^^^^^^^ diff --git a/examples/sched_note/Make.defs b/examples/sched_note/Make.defs deleted file mode 100644 index ba503e473..000000000 --- a/examples/sched_note/Make.defs +++ /dev/null @@ -1,39 +0,0 @@ -############################################################################ -# apps/examples/note/Make.defs -# Adds selected applications to apps/ build -# -# Copyright (C) 2016 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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 NuttX 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. -# -############################################################################ - -ifeq ($(CONFIG_EXAMPLES_NOTE),y) -CONFIGURED_APPS += examples/sched_note -endif diff --git a/system/Kconfig b/system/Kconfig index 8ad2b6769..3a57198fb 100644 --- a/system/Kconfig +++ b/system/Kconfig @@ -22,6 +22,7 @@ source "$APPSDIR/system/mdio/Kconfig" source "$APPSDIR/system/sudoku/Kconfig" source "$APPSDIR/system/lm75/Kconfig" source "$APPSDIR/system/vi/Kconfig" +source "$APPSDIR/system/sched_note/Kconfig" source "$APPSDIR/system/stackmonitor/Kconfig" source "$APPSDIR/system/symtab/Kconfig" source "$APPSDIR/system/cdcacm/Kconfig" diff --git a/system/Make.defs b/system/Make.defs index 2caba6179..984d9f670 100644 --- a/system/Make.defs +++ b/system/Make.defs @@ -102,6 +102,10 @@ ifeq ($(CONFIG_SYSTEM_READLINE),y) CONFIGURED_APPS += system/readline endif +ifeq ($(CONFIG_SYSTEM_NOTE),y) +CONFIGURED_APPS += system/sched_note +endif + ifeq ($(CONFIG_SYSTEM_SUDOKU),y) CONFIGURED_APPS += system/sudoku endif diff --git a/system/hex2bin/Makefile b/system/hex2bin/Makefile index 9c49afad5..6c5b34340 100644 --- a/system/hex2bin/Makefile +++ b/system/hex2bin/Makefile @@ -87,11 +87,11 @@ else INSTALL_DIR = $(BIN_DIR) endif -CONFIG_EXAMPLES_HEX2BIN_PROGNAME ?= hex2bin$(EXEEXT) -HEX2BIN_PROGNAME = $(CONFIG_EXAMPLES_HEX2BIN_PROGNAME) +CONFIG_SYSTEM_HEX2BIN_PROGNAME ?= hex2bin$(EXEEXT) +HEX2BIN_PROGNAME = $(CONFIG_SYSTEM_HEX2BIN_PROGNAME) -CONFIG_EXAMPLES_HEX2MEM_PROGNAME ?= hex2mem$(EXEEXT) -HEX2MEM_PROGNAME = $(CONFIG_EXAMPLES_HEX2MEM_PROGNAME) +CONFIG_SYSTEM_HEX2MEM_PROGNAME ?= hex2mem$(EXEEXT) +HEX2MEM_PROGNAME = $(CONFIG_SYSTEM_HEX2MEM_PROGNAME) ROOTDEPPATH = --dep-path . VPATH = diff --git a/system/mdio/Makefile b/system/mdio/Makefile index 2fa178583..2d400ea09 100644 --- a/system/mdio/Makefile +++ b/system/mdio/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# apps/examples/mdio/Makefile +# apps/system/mdio/Makefile # # Copyright (C) 2008, 2010-2013 Gregory Nutt. All rights reserved. # Author: Gregory Nutt diff --git a/system/mdio/mdio_main.c b/system/mdio/mdio_main.c index 74549a27d..9300458ce 100644 --- a/system/mdio/mdio_main.c +++ b/system/mdio/mdio_main.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/mdio/mdio_main.c + * system/mdio/mdio_main.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/system/prun/prun.h b/system/prun/prun.h index ddb6ee650..fb5b96ab3 100644 --- a/system/prun/prun.h +++ b/system/prun/prun.h @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/prun/prun.h + * apps/system/prun/prun.h * * Copyright (C) 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __EXAMPLES_PASHELLO_H -#define __EXAMPLES_PASHELLO_H +#ifndef __APPS_SYSTEM_PRUN_H +#define __APPS_SYSTEM_PRUN_H /**************************************************************************** * Included Files @@ -52,4 +52,4 @@ extern void hello_register(void); -#endif /* __EXAMPLES_PASHELLO_H */ +#endif /* __APPS_SYSTEM_PRUN_H */ diff --git a/examples/sched_note/.gitignore b/system/sched_note/.gitignore similarity index 100% rename from examples/sched_note/.gitignore rename to system/sched_note/.gitignore diff --git a/examples/sched_note/Kconfig b/system/sched_note/Kconfig similarity index 64% rename from examples/sched_note/Kconfig rename to system/sched_note/Kconfig index eeae2e660..9ad1f1e0c 100644 --- a/examples/sched_note/Kconfig +++ b/system/sched_note/Kconfig @@ -3,16 +3,16 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -config EXAMPLES_NOTE - bool "Scheduler instrumentation example" +config SYSTEM_NOTE + bool "Scheduler monitor" default n depends on DRIVER_NOTE ---help--- - Enable the schedler instrumentation example + Enable the schedler instrumentation monitor -if EXAMPLES_NOTE +if SYSTEM_NOTE -config EXAMPLES_NOTE_PROGNAME +config SYSTEM_NOTE_PROGNAME string "Program name" default "note" depends on BUILD_KERNEL @@ -20,20 +20,20 @@ config EXAMPLES_NOTE_PROGNAME This is the name of the program that will be use when the NSH ELF program is installed. -config EXAMPLES_NOTE_PRIORITY +config SYSTEM_NOTE_PRIORITY int "Note daemon task priority" default 100 -config EXAMPLES_NOTE_STACKSIZE +config SYSTEM_NOTE_STACKSIZE int "Note daemon stack size" default 2048 -config EXAMPLES_NOTE_BUFFERSIZE +config SYSTEM_NOTE_BUFFERSIZE int "Note daemon I/O buffer size" default 1024 -config EXAMPLES_NOTE_DELAY +config SYSTEM_NOTE_DELAY int "Note daemon sample delay (msec)" default 1000 -endif # EXAMPLES_NOTE +endif # SYSTEM_NOTE diff --git a/examples/sched_note/Makefile b/system/sched_note/Makefile similarity index 86% rename from examples/sched_note/Makefile rename to system/sched_note/Makefile index 89d0bfee8..913d7ae20 100644 --- a/examples/sched_note/Makefile +++ b/system/sched_note/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# apps/examples/note/Makefile +# apps/system/note/Makefile # # Copyright (C) 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt @@ -37,12 +37,12 @@ # LED driver test built-in application info -CONFIG_EXAMPLES_NOTE_PRIORITY ?= SCHED_PRIORITY_DEFAULT -CONFIG_EXAMPLES_NOTE_STACKSIZE ?= 2048 +CONFIG_SYSTEM_NOTE_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_SYSTEM_NOTE_STACKSIZE ?= 2048 APPNAME = note -PRIORITY = $(CONFIG_EXAMPLES_NOTE_PRIORITY) -STACKSIZE = $(CONFIG_EXAMPLES_NOTE_STACKSIZE) +PRIORITY = $(CONFIG_SYSTEM_NOTE_PRIORITY) +STACKSIZE = $(CONFIG_SYSTEM_NOTE_STACKSIZE) # LED driver test @@ -50,7 +50,7 @@ ASRCS = CSRCS = MAINSRC = note_main.c -CONFIG_EXAMPLES_NOTE_PROGNAME ?= note$(EXEEXT) -PROGNAME = $(CONFIG_EXAMPLES_NOTE_PROGNAME) +CONFIG_SYSTEM_NOTE_PROGNAME ?= note$(EXEEXT) +PROGNAME = $(CONFIG_SYSTEM_NOTE_PROGNAME) include $(APPDIR)/Application.mk diff --git a/examples/sched_note/note_main.c b/system/sched_note/note_main.c similarity index 97% rename from examples/sched_note/note_main.c rename to system/sched_note/note_main.c index dd0ea4219..fa76f8e5c 100644 --- a/examples/sched_note/note_main.c +++ b/system/sched_note/note_main.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/note/note_main.c + * system/note/note_main.c * * Copyright (C) 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -54,7 +54,7 @@ ****************************************************************************/ static bool g_note_daemon_started; -static uint8_t g_note_buffer[CONFIG_EXAMPLES_NOTE_BUFFERSIZE]; +static uint8_t g_note_buffer[CONFIG_SYSTEM_NOTE_BUFFERSIZE]; /* Names of task/thread states */ @@ -377,13 +377,13 @@ static int note_daemon(int argc, char *argv[]) for (; ; ) { - nread = read(fd, g_note_buffer, CONFIG_EXAMPLES_NOTE_BUFFERSIZE); + nread = read(fd, g_note_buffer, CONFIG_SYSTEM_NOTE_BUFFERSIZE); if (nread > 0) { dump_notes(nread); } - usleep(CONFIG_EXAMPLES_NOTE_DELAY * 1000L); + usleep(CONFIG_SYSTEM_NOTE_DELAY * 1000L); } (void)close(fd); @@ -422,8 +422,8 @@ int note_main(int argc, FAR char *argv[]) ledargv[0] = "note_daemon"; ledargv[1] = NULL; - ret = task_create("note_daemon", CONFIG_EXAMPLES_NOTE_PRIORITY, - CONFIG_EXAMPLES_NOTE_STACKSIZE, note_daemon, + ret = task_create("note_daemon", CONFIG_SYSTEM_NOTE_PRIORITY, + CONFIG_SYSTEM_NOTE_STACKSIZE, note_daemon, (FAR char * const *)ledargv); if (ret < 0) { From 172971fb3cba5e1cd9a95045ccd31158e001e72a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 18 May 2016 19:50:55 -0600 Subject: [PATCH 13/31] Kconfig: Extend some help comments --- examples/watchdog/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/watchdog/Kconfig b/examples/watchdog/Kconfig index 42121531d..3d7faaef9 100644 --- a/examples/watchdog/Kconfig +++ b/examples/watchdog/Kconfig @@ -24,6 +24,13 @@ config EXAMPLES_WATCHDOG stm32_iwdginitialize(CONFIG_STM32_WDG_DEVPATH, CONFIG_STM32_LSIFREQ); #endif + For some Atmel SAM configurations, the board-specific initialization + sequence would be like: + + #include "sam_wdt.h" + + sam_wdt_initialize(); + if EXAMPLES_WATCHDOG config EXAMPLES_WATCHDOG_DEVPATH From 7c790c7dc022405cd1c5732ea054e82914d00d07 Mon Sep 17 00:00:00 2001 From: Mark Olsson Date: Thu, 19 May 2016 13:34:51 +0200 Subject: [PATCH 14/31] Add platform files for NUCLEO-144 (NUCLEO-F746ZG) --- platform/nucleo-144/Kconfig | 8 ++ platform/nucleo-144/Make.defs | 41 ++++++ platform/nucleo-144/stm32_cxxinitialize.c | 154 ++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 platform/nucleo-144/Kconfig create mode 100644 platform/nucleo-144/Make.defs create mode 100644 platform/nucleo-144/stm32_cxxinitialize.c diff --git a/platform/nucleo-144/Kconfig b/platform/nucleo-144/Kconfig new file mode 100644 index 000000000..03bdaac41 --- /dev/null +++ b/platform/nucleo-144/Kconfig @@ -0,0 +1,8 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if CONFIG_ARCH_BOARD_NUCLEO_144 + +endif diff --git a/platform/nucleo-144/Make.defs b/platform/nucleo-144/Make.defs new file mode 100644 index 000000000..1a2218dd0 --- /dev/null +++ b/platform/nucleo-144/Make.defs @@ -0,0 +1,41 @@ +############################################################################ +# apps/platform/nucleo-144/Make.defs +# +# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# Author: Mark Olsson +# +# 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 NuttX 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. +# +############################################################################ + +# Add platform specific sources to ASRCS and CSRCS + +ifeq ($(CONFIG_HAVE_CXX),y) +CSRCS += stm32_cxxinitialize.c +endif diff --git a/platform/nucleo-144/stm32_cxxinitialize.c b/platform/nucleo-144/stm32_cxxinitialize.c new file mode 100644 index 000000000..3d81e480a --- /dev/null +++ b/platform/nucleo-144/stm32_cxxinitialize.c @@ -0,0 +1,154 @@ +/**************************************************************************** + * apps/platform/nucleo-144/stm32_cxxinitialize.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * Author: Mark Olsson + * + * 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 NuttX 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Debug ********************************************************************/ +/* Non-standard debug that may be enabled just for testing the static + * constructors + */ + +#ifndef CONFIG_DEBUG +# undef CONFIG_DEBUG_CXX +#endif + +#ifdef CONFIG_DEBUG_CXX +# define cxxdbg dbg +# define cxxlldbg lldbg +# ifdef CONFIG_DEBUG_VERBOSE +# define cxxvdbg vdbg +# define cxxllvdbg llvdbg +# else +# define cxxvdbg(x...) +# define cxxllvdbg(x...) +# endif +#else +# define cxxdbg(x...) +# define cxxlldbg(x...) +# define cxxvdbg(x...) +# define cxxllvdbg(x...) +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ +/* This type defines one entry in initialization array */ + +typedef void (*initializer_t)(void); + +/**************************************************************************** + * External References + ****************************************************************************/ +/* _sinit and _einit are symbols exported by the linker script that mark the + * beginning and the end of the C++ initialization section. + */ + +extern initializer_t _sinit; +extern initializer_t _einit; + +/* _stext and _etext are symbols exported by the linker script that mark the + * beginning and the end of text. + */ + +extern uint32_t _stext; +extern uint32_t _etext; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_cxxinitialize + * + * Description: + * If C++ and C++ static constructors are supported, then this function + * must be provided by board-specific logic in order to perform + * initialization of the static C++ class instances. + * + * This function should then be called in the application-specific + * user_start logic in order to perform the C++ initialization. NOTE + * that no component of the core NuttX RTOS logic is involved; this + * function definition only provides the 'contract' between application + * specific C++ code and platform-specific toolchain support. + * + ****************************************************************************/ + +void up_cxxinitialize(void) +{ + initializer_t *initp; + + cxxdbg("_sinit: %p _einit: %p _stext: %p _etext: %p\n", + &_sinit, &_einit, &_stext, &_etext); + + /* Visit each entry in the initialization table */ + + for (initp = &_sinit; initp != &_einit; initp++) + { + initializer_t initializer = *initp; + cxxdbg("initp: %p initializer: %p\n", initp, initializer); + + /* Make sure that the address is non-NULL and lies in the text region + * defined by the linker script. Some toolchains may put NULL values + * or counts in the initialization table. + */ + + if ((void *)initializer > (void *)&_stext && + (void *)initializer < (void *)&_etext) + { + cxxdbg("Calling %p\n", initializer); + initializer(); + } + } +} + +#endif /* CONFIG_HAVE_CXX && CONFIG_HAVE_CXXINITIALIZE */ From da7c5fd5dadf94653104f544dae8a50763f9d559 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 May 2016 07:39:06 -0600 Subject: [PATCH 15/31] Update ChangeLog --- ChangeLog.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index f5f8f8374..c0de67e93 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1589,3 +1589,11 @@ message weirdness; Add default definitions for some commonly used things when 'make clean' is used without .config or Make.defs files installed (2016-05-10). + * apps/canutils/libcanard: Add libcanard UAVCAN library. From Paul + Alexander Patience (2016-05-12) + * apps/examples/watchdog: Remove call to up_wdginitialize(). This + interface should not be accessed from application code (2016-05-18). + * apps/system/sched_note: Move the schduler note monitor from examples/ + to system/ (2016-05-18). + * apps/platform/nucleo-144: Add platform files for NUCLEO-144 + (NUCLEO-F746ZG). From Mark Olsson (2016-05-19). From abdf703746f5da676af9b89396c553042cec8941 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 May 2016 09:13:23 -0600 Subject: [PATCH 16/31] Add ESP8266 driver application. From Pierre-noel Bouteville --- include/netutils/esp8266.h | 122 ++++ netutils/Kconfig | 1 + netutils/Make.defs | 10 +- netutils/README.txt | 2 + netutils/esp8266/Kconfig | 34 + netutils/esp8266/Makefile | 102 +++ netutils/esp8266/esp8266.c | 1413 ++++++++++++++++++++++++++++++++++++ 7 files changed, 1681 insertions(+), 3 deletions(-) create mode 100644 include/netutils/esp8266.h create mode 100644 netutils/esp8266/Kconfig create mode 100644 netutils/esp8266/Makefile create mode 100644 netutils/esp8266/esp8266.c diff --git a/include/netutils/esp8266.h b/include/netutils/esp8266.h new file mode 100644 index 000000000..a9dda56bf --- /dev/null +++ b/include/netutils/esp8266.h @@ -0,0 +1,122 @@ +/**************************************************************************** + * apps/include/netutils/esp8266.h + * + * Copyright (C) 2015 Pierre-Noel Bouteville. All rights reserved. + * Author: Pierre-Noel Bouteville + * + * 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 NuttX 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. + * + ****************************************************************************/ + +#ifndef __APPS_INCLUDE_NETUTILS_ESP8266_H +#define __APPS_INCLUDE_NETUTILS_ESP8266_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "nuttx/config.h" + +#include + +#ifdef CONFIG_NETUTILS_ESP8266 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define lespBSSID_SIZE 6 + +#define lespIP(x1,x2,x3,x4) ( (x1)<<24 |(x2)<<16 |(x3)<<8 |(x4)<<0 ) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +typedef enum +{ + lesp_eMODE_AP = 0, + lesp_eMODE_STATION = 1, + lesp_eMODE_BOTH = 2, +} lesp_mode_t; + +typedef enum +{ + lesp_eSECURITY_NONE=0, + lesp_eSECURITY_WEP, + lesp_eSECURITY_WPA_PSK, + lesp_eSECURITY_WPA2_PSK, + lesp_eSECURITY_WPA_WPA2_PSK, + lesp_eSECURITY_NBR +} lesp_security_t; + +typedef struct +{ + lesp_security_t security; + const char *ssid; + uint8_t bssid[lespBSSID_SIZE]; + int rssi; +} lesp_ap_t; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int lesp_initialize(void); +int lesp_soft_reset(void); + +const char *lesp_security_to_str(lesp_security_t security); + +int lesp_ap_connect(const char* ssid_name, const char* ap_key, int timeout_s); + +int lesp_ap_is_connected(void); + +int lesp_set_dhcp(lesp_mode_t mode,bool enable); +int lesp_set_net(lesp_mode_t mode, + in_addr_t ip, + in_addr_t mask, + in_addr_t gateway + ); + +typedef void (*lesp_cb_t)(lesp_ap_t* wlan); + +int lesp_list_access_points(lesp_cb_t cb); + +int lesp_socket(int domain, int type, int protocol); +int lesp_closesocket(int sockfd); +int lesp_bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen); +int lesp_connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen); +int lesp_listen(int sockfd, int backlog); +int lesp_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); +ssize_t lesp_send(int sockfd, FAR const uint8_t *buf, size_t len, int flags); +ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags); +int lesp_setsockopt(int sockfd, int level, int option, + FAR const void *value, socklen_t value_len); + +#endif /* CONFIG_NETUTILS_ESP8266 */ +#endif /* __APPS_INCLUDE_NETUTILS_ESP8266_H */ diff --git a/netutils/Kconfig b/netutils/Kconfig index 023e33f82..2f439ce7d 100644 --- a/netutils/Kconfig +++ b/netutils/Kconfig @@ -9,6 +9,7 @@ source "$APPSDIR/netutils/chat/Kconfig" source "$APPSDIR/netutils/codecs/Kconfig" source "$APPSDIR/netutils/dhcpc/Kconfig" source "$APPSDIR/netutils/dhcpd/Kconfig" +source "$APPSDIR/netutils/esp8266/Kconfig" source "$APPSDIR/netutils/ftpc/Kconfig" source "$APPSDIR/netutils/ftpd/Kconfig" source "$APPSDIR/netutils/json/Kconfig" diff --git a/netutils/Make.defs b/netutils/Make.defs index 25fb73601..f4a36dcf7 100644 --- a/netutils/Make.defs +++ b/netutils/Make.defs @@ -2,7 +2,7 @@ # apps/netutils/Make.defs # Adds selected applications to apps/ build # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in include and binary forms, with or without @@ -46,8 +46,12 @@ ifeq ($(CONFIG_NETUTILS_DHCPC),y) CONFIGURED_APPS += netutils/dhcpc endif -ifeq ($(CONFIG_NETUTILS_DHCPD),y) -CONFIGURED_APPS += netutils/dhcpd +ifeq ($(CONFIG_NETUTILS_ESP8266),y) +CONFIGURED_APPS += netutils/esp8266 +endif + +ifeq ($(CONFIG_NETUTILS_FTPC),y) +CONFIGURED_APPS += netutils/ftpc endif ifeq ($(CONFIG_NETUTILS_FTPC),y) diff --git a/netutils/README.txt b/netutils/README.txt index 88be41dd4..50ea2d189 100644 --- a/netutils/README.txt +++ b/netutils/README.txt @@ -45,6 +45,8 @@ highly influenced by uIP) include: device class so that groups of devices can be discovered. It is also possible to address all classes with a kind of broadcast discover. (Contributed by Max Holtzberg). + esp8266 - An ESP8266 networking layer contributed by Pierre-noel + Bouteville json - cJSON is an ultra-lightweight, portable, single-file, simple-as-can-be ANSI-C compliant JSON parser, under MIT license. Embeddable Lightweight XML-RPC Server discussed at diff --git a/netutils/esp8266/Kconfig b/netutils/esp8266/Kconfig new file mode 100644 index 000000000..febd10aa2 --- /dev/null +++ b/netutils/esp8266/Kconfig @@ -0,0 +1,34 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config NETUTILS_ESP8266 + bool "ESP8266" + default n + ---help--- + Enable support for ESP8266 application interface. + +if NETUTILS_ESP8266 + +config ESP8266_DEV_PATH + string "Serial device path" + default "/dev/ttyS1" + +config ESP8266_BAUDRATE + int "Serial BAUD rate" + default 115200 + +config WIFI_MAX_TX_LEN + int "Max. TX length" + default 256 + +config WIFI_MAX_RX_LEN + int "Max. RX length" + default 256 + +config LESP_THREAD_PRIO + int "Worker thread priority" + default 100 + +endif diff --git a/netutils/esp8266/Makefile b/netutils/esp8266/Makefile new file mode 100644 index 000000000..924753033 --- /dev/null +++ b/netutils/esp8266/Makefile @@ -0,0 +1,102 @@ +############################################################################ +# apps/netutils/esp8266/Makefile +# +# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 NuttX 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. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +# ESP8266 Library + +ASRCS = +CSRCS = + +ifeq ($(CONFIG_NET_TCP),y) +CSRCS += esp8266.c +endif + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built +.PHONY: context depend clean distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + $(Q) touch .built + +install: + +context: + +.depend: Makefile $(SRCS) + $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep diff --git a/netutils/esp8266/esp8266.c b/netutils/esp8266/esp8266.c new file mode 100644 index 000000000..d4cbb987f --- /dev/null +++ b/netutils/esp8266/esp8266.c @@ -0,0 +1,1413 @@ +/**************************************************************************** + * apps/netutils/esp8266/esp8266.c + * + * Derives from an application to demo an Arduino connected to the ESPRESSIF + * ESP8266 with AT command firmware. + * + * Copyright (C) 2015 Pierre-Noel Bouteville. All rights reserved. + * Author: Pierre-Noel Bouteville + * + * 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 NuttX 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "sys/socket.h" + +#include "apps/netutils/esp8266.h" + +#ifdef CONFIG_NETUTILS_ESP8266 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define NETAPP_IPCONFIG_MAC_OFFSET (20) + +#ifndef CONFIG_WIFI_MAX_TX_LEN +# define CONFIG_WIFI_MAX_TX_LEN 256 +#endif + +#ifndef CONFIG_WIFI_MAX_RX_LEN +# define CONFIG_WIFI_MAX_RX_LEN 256 +#endif + +#define BUF_CMD_LEN CONFIG_WIFI_MAX_TX_LEN +#define BUF_ANS_LEN CONFIG_WIFI_MAX_RX_LEN +#define BUF_WORKER_LEN 1024 + +#define CON_NBR 4 + +#define ESP8266_ACCESS_POINT_NBR_MAX 32 + +#define lespWAITING_OK_POLLING_MS 250 +#define lespTIMEOUT_MS 1000 +#define lespTIMEOUT_MS_SEND 1000 +#define lespTIMEOUT_MS_CONNECTION 30000 +#define lespTIMEOUT_MS_LISP_AP 5000 +#define lespTIMEOUT_FLOODING_OFFSET_S 3 +#define lespTIMEOUT_MS_RECV_S 60 + +#define lespCON_USED_MASK(idx) (1<<(idx)) +#define lespPOLLING_TIME_MS 1000 + +/* Must be a power of 2 */ + +#define SOCKET_FIFO_SIZE 2048 +#define SOCKET_NBR 4 + +#define FLAGS_SOCK_USED (1 << 0) +#define FLAGS_SOCK_CONNECTED (1 << 1) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +typedef struct +{ + int flags; + int nfifo; + sem_t *sem; + uint8_t rxbuf[SOCKET_FIFO_SIZE]; +} lesp_socket_t; + +typedef struct +{ + bool running; + pthread_t thread; + uint8_t buf[BUF_WORKER_LEN]; + int buf_size; +} lesp_worker_t; + +typedef struct +{ + pthread_mutex_t mutex; + bool is_initialized; + int fd; + lesp_worker_t worker; + lesp_socket_t sockets[SOCKET_NBR]; + sem_t sem; + char buf[BUF_ANS_LEN]; + char buf_ans[BUF_ANS_LEN]; + char buf_cmd[BUF_CMD_LEN]; +} lesp_state_t; + +/**************************************************************************** + * Private Functions prototypes + ****************************************************************************/ + +static int lesp_low_level_read(uint8_t* buf,int size); +static inline int lesp_read_ipd(void); +static lesp_socket_t* get_sock(int sockfd); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +lesp_state_t g_lesp_state = +{ + .mutex = PTHREAD_MUTEX_INITIALIZER, + .is_initialized = false, + .fd = -1, + .worker.running = false, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: get_sock + * + * Description: + * Get socket structure pointer of sockfd. + * + * Input Parmeters: + * sockfd : socket id + * + * Returned Value: + * socket id pointer, NULL on error. + * + ****************************************************************************/ + +static lesp_socket_t *get_sock(int sockfd) +{ + if (!g_lesp_state.is_initialized) + { + syslog(LOG_DEBUG,"Esp8266 not initialized; can't list access points.\n"); + return NULL; + } + + if (((unsigned int)sockfd) >= SOCKET_NBR) + { + syslog(LOG_DEBUG,"Esp8266 invalid sockfd.\n",sockfd); + return NULL; + } + + if ((g_lesp_state.sockets[sockfd].flags & FLAGS_SOCK_USED) == 0) + { + syslog(LOG_ERR,"Connection id %d not Created!\n",sockfd); + return NULL; + } + + return &g_lesp_state.sockets[sockfd]; +} + +/**************************************************************************** + * Name: lesp_low_level_read + * + * Description: + * put size data from esp8266 into buf. + * + * Input Parmeters: + * buf : buffer to store read data + * size : size of data to read + * + * Returned Value: + * number of byte read, -1 in case of error. + * + ****************************************************************************/ + +static int lesp_low_level_read(uint8_t* buf, int size) +{ + int ret = 0; + + struct pollfd fds[1]; + + memset(fds, 0, sizeof( struct pollfd)); + fds[0].fd = g_lesp_state.fd; + fds[0].events = POLLIN; + + /* poll return 1=>even occur 0=>timeout or -1=>error */ + + ret = poll(fds, 1, lespPOLLING_TIME_MS); + if (ret < 0) + { + int err = errno; + syslog(LOG_ERR, + "worker read Error %d (errno %d:%d)\n",ret, + err,strerror(err)); + } + else if ((fds[0].revents & POLLERR) && (fds[0].revents & POLLHUP)) + { + syslog(LOG_ERR,"worker poll read Error %d\n",ret); + ret = -1; + } + else if (fds[0].revents & POLLIN) + { + ret = read(g_lesp_state.fd, buf, size); + } + + if (ret < 0) + { + return -1; + } + + return ret; +} + +/**************************************************************************** + * Name: lesp_read_ipd + * + * Description: + * Try to treat an '+IPD' command in worker buffer. Worker buffer should + * already contain '+IPD,,:' + * + * Input Parmeters: + * None + * + * Returned Value: + * 1 was an IPD, 0 is not an IPD, -1 on error. + * + ****************************************************************************/ + +static inline int lesp_read_ipd(void) +{ + int sockfd; + lesp_socket_t *sock; + char *ptr; + int len; + + ptr = (char *)g_lesp_state.worker.buf; + + /* Put a null at end */ + + *(ptr + g_lesp_state.worker.buf_size) = '\0'; + + if (memcmp(ptr,"+IPD,",5) != 0) + { + return 0; + } + + ptr += 5; + + sockfd = strtol(ptr, &ptr, 10); + + sock = get_sock(sockfd); + + if (sock == NULL) + { + return -1; + } + + if (*ptr++ != ',') + { + return -1; + } + + len = strtol(ptr,&ptr,10); + + if (*ptr != ':') + { + return -1; + } + + syslog(LOG_DEBUG,"Read %d bytes for socket %d \n",len,sockfd); + + while(len) + { + int size; + uint8_t *buf = g_lesp_state.worker.buf; + + size = len; + if (size >= BUF_WORKER_LEN) + { + size = BUF_WORKER_LEN; + } + + size = lesp_low_level_read(buf,size); + if (size <= 0) + { + return -1; + } + + len -= size; + pthread_mutex_lock(&g_lesp_state.mutex); + while(size --) + { + uint8_t b = *buf++; + if (sock->nfifo < SOCKET_FIFO_SIZE) + { + int ndx = sock->nfifo; + sock->rxbuf[ndx] = b; + sock->nfifo = ndx + 1; + } + else + { + syslog(LOG_DEBUG,"overflow socket 0x%02X\n", b); + } + } + + if (sock->sem) + { + sem_post(sock->sem); + } + + pthread_mutex_unlock(&g_lesp_state.mutex); + } + + return 0; +} + +/**************************************************************************** + * Name: lesp_vsend_cmd + * + * Description: + * Send cmd with format and argument like sprintf. + * + * Input Parmeters: + * format : null terminated format string to send. + * ap : format values. + * + * Returned Value: + * len of cmd on success, -1 on error. + * + ****************************************************************************/ + +int lesp_vsend_cmd(FAR const IPTR char *format, va_list ap) +{ + int ret = 0; + + ret = vsnprintf(g_lesp_state.buf_cmd,BUF_CMD_LEN,format,ap); + if (ret >= BUF_CMD_LEN) + { + g_lesp_state.buf_cmd[BUF_CMD_LEN-1]='\0'; + syslog(LOG_DEBUG,"Buffer too small for '%s'...\n", g_lesp_state.buf_cmd); + ret = -1; + } + + syslog(LOG_DEBUG,"Write:%s\n",g_lesp_state.buf_cmd); + + ret = write(g_lesp_state.fd,g_lesp_state.buf_cmd,ret); + if (ret < 0) + { + ret = -1; + } + + return ret; +} + +/**************************************************************************** + * Name: lesp_send_cmd + * + * Description: + * Send cmd with format and argument like sprintf. + * + * Input Parmeters: + * format : null terminated format string to send. + * ... : format values. + * + * Returned Value: + * len of cmd on success, -1 on error. + * + ****************************************************************************/ + +static int lesp_send_cmd(FAR const IPTR char *format, ...) +{ + int ret = 0; + va_list ap; + + /* Let lesp_vsend_cmd do the real work */ + + va_start(ap, format); + ret = lesp_vsend_cmd(format, ap); + va_end(ap); + + return ret; +} + +/**************************************************************************** + * Name: lesp_read + * + * Description: + * Read a answer line with timeout. + * + * Input Parmeters: + * timeout_ms : timeout in millisecond. + * + * Returned Value: + * len of line without line return on success, -1 on error. + * + ****************************************************************************/ + +static int lesp_read(int timeout_ms) +{ + int ret = 0; + + struct timespec ts; + + if (! g_lesp_state.is_initialized) + { + syslog(LOG_DEBUG,"Esp8266 not initialized; can't list access points.\n"); + return -1; + } + + if (clock_gettime(CLOCK_REALTIME,&ts) < 0) + { + return -1; + } + + ts.tv_sec += (timeout_ms/1000) + lespTIMEOUT_FLOODING_OFFSET_S; + + do + { + if (sem_timedwait(&g_lesp_state.sem,&ts) < 0) + { + return -1; + } + + pthread_mutex_lock(&g_lesp_state.mutex); + + ret = strlen(g_lesp_state.buf); + if (ret > 0) + { + memcpy(g_lesp_state.buf_ans,g_lesp_state.buf,ret+1); /* +1 to copy null */ + } + + g_lesp_state.buf[0] = '\0'; + + pthread_mutex_unlock(&g_lesp_state.mutex); + + } + while (ret == 0); + + syslog(LOG_DEBUG,"read %d=>%s\n",ret,g_lesp_state.buf_ans); + + return ret; +} + +/**************************************************************************** + * Name: lesp_flush + * + * Description: + * Read and discard all waiting data in rx buffer. + * + * Input Parmeters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void lesp_flush(void) +{ + while (lesp_read(lespTIMEOUT_MS) >= 0); +} + +/**************************************************************************** + * Name: lesp_read_ans_ok + * + * Description: + * Read up to read OK, ERROR, or FAIL. + * + * Input Parmeters: + * timeout_ms : timeout in millisecond. + * + * Returned Value: + * 0 on OK, -1 on error. + * + ****************************************************************************/ + +int lesp_read_ans_ok(int timeout_ms) +{ + time_t end; + end = time(NULL) + (timeout_ms/1000) + lespTIMEOUT_FLOODING_OFFSET_S; + do + { + if (lesp_read(timeout_ms) < 0) + { + return -1; + } + + /* Answers sorted in probability case */ + + if (strcmp(g_lesp_state.buf_ans,"OK") == 0) + { + return 0; + } + + if (strcmp(g_lesp_state.buf_ans,"FAIL") == 0) + { + return -1; + } + + if (strcmp(g_lesp_state.buf_ans,"ERROR") == 0) + { + return -1; + } + + syslog(LOG_INFO,"Got:%s\n",g_lesp_state.buf_ans); + + /* Ro quit in case of message flooding */ + } + while (time(NULL) < end); + + lesp_flush(); + + return -1; +} + +/**************************************************************************** + * Name: lesp_ask_ans_ok + * + * Description: + * Ask and ignore line start with '+' and except a "OK" answer. + * + * Input Parmeters: + * cmd : command sent + * timeout_ms : timeout in millisecond + * + * Returned Value: + * len of line without line return on success, -1 on error. + * + ****************************************************************************/ + +static int lesp_ask_ans_ok(int timeout_ms, FAR const IPTR char *format, ...) +{ + int ret = 0; + va_list ap; + + va_start(ap, format); + ret = lesp_vsend_cmd(format, ap); + va_end(ap); + + if (ret >= 0) + { + ret = lesp_read_ans_ok(timeout_ms); + } + + return ret; +} + +/**************************************************************************** + * Name: + * + * Description: + * Try to decode @b +CWLAP line. + * see in: + * https://room-15.github.io/blog/2015/03/26/esp8266-at-command-reference/ + * + * +CWLAP:(0,"FreeWifi",-90,"00:07:cb:07:b6:00",1) + * 0 => security + * "FreeWifi" => ssid + * -90 => rssi + * "00:07:cb:07:b6:00" => mac + * + * Note: Content of ptr is modified and string in ap point into ptr string. + * + * Input Parmeters: + * ptr : +CWLAP line null terminated string pointer. + * ap : ap result of parsing. + * + * Returned Value: + * 0 on success, -1 in case of error. + * + ****************************************************************************/ + +static int lesp_parse_cwlap_ans_line(char* ptr, lesp_ap_t *ap) +{ + int field_idx; + char* ptr_next; + + for(field_idx = 0; field_idx <= 5; field_idx++) + { + if (field_idx == 0) + { + ptr_next = strchr(ptr,'('); + } + else if (field_idx == 5) + { + ptr_next = strchr(ptr,')'); + } + else + { + ptr_next = strchr(ptr,','); + } + + if (ptr_next == NULL) + { + return -1; + } + + *ptr_next = '\0'; + + switch (field_idx) + { + case 0: + if (strcmp(ptr,"+CWLAP:") != 0) + { + return -1; + } + + break; + + case 1: + { + int i = *ptr - '0'; + + if ((i < 0) || (i >= lesp_eSECURITY_NBR)) + { + return -1; + } + + ap->security = i; + } + break; + + case 2: + ptr++; /* Remove first '"' */ + *(ptr_next -1 ) = '\0'; + ap->ssid = ptr; + break; + + case 3: + { + int i = atoi(ptr); + + if (i > 0) + { + i = -i; + } + + ap->rssi = i; + } + break; + + case 4: + { + int i; + + ptr++; /* Remove first '"' */ + *(ptr_next - 1) = '\0'; + + for (i = 0; i < lespBSSID_SIZE ; i++) + { + ap->bssid[i] = strtol(ptr,&ptr,16); + if (*ptr == ':') + { + ptr++; + } + } + } + break; + } + + ptr = ptr_next + 1; + } + + return 0; +} + +static void *lesp_worker(void *args) +{ + int ret = 0; + + lesp_worker_t *p = &g_lesp_state.worker; + + UNUSED(args); + + pthread_mutex_lock(&g_lesp_state.mutex); + syslog(LOG_INFO,"worker Started \n"); + p->buf_size = 0; + pthread_mutex_unlock(&g_lesp_state.mutex); + + while(p->running) + { + uint8_t c; + + ret = lesp_low_level_read(&c,1); + + if (ret < 0) + { + syslog(LOG_ERR,"worker read data Error %d\n",ret); + } + else if (ret > 0) + { + //syslog(LOG_DEBUG,"c:0x%02X (%c)\n",c); + + pthread_mutex_lock(&g_lesp_state.mutex); + if (c == '\n') + { + if (p->buf[p->buf_size-1] == '\r') + { + p->buf_size--; + } + + if (p->buf_size != 0) + { + p->buf[p->buf_size] = '\0'; + memcpy(g_lesp_state.buf,p->buf,p->buf_size+1); + syslog(LOG_DEBUG,"Read data:%s\n",g_lesp_state.buf); + sem_post(&g_lesp_state.sem); + p->buf_size = 0; + } + } + else if (p->buf_size < BUF_ANS_LEN-1) + { + p->buf[p->buf_size++] = c; + } + else + { + syslog(LOG_DEBUG,"Read char overflow:%c\n",c); + } + + pthread_mutex_unlock(&g_lesp_state.mutex); + + if ((c == ':') && (lesp_read_ipd() != 0)) + { + p->buf_size = 0; + } + } + } + + return NULL; +} + +static inline int lesp_create_worker(int priority) +{ + int ret = 0; + + /* Thread */ + + pthread_attr_t thread_attr; + + /* Ihm priority lower than normal */ + + struct sched_param param; + + ret = pthread_attr_init(&thread_attr); + + if (ret < 0) + { + syslog(LOG_ERR,"Cannot Set scheduler parameter thread (%d)\n",ret); + } + else + { + ret = pthread_attr_getschedparam(&thread_attr,¶m); + if (ret >= 0) + { + param.sched_priority += priority; + ret = pthread_attr_setschedparam(&thread_attr,¶m); + } + else + { + syslog(LOG_ERR,"Cannot Get/Set scheduler parameter thread (%d)\n", + ret); + } + + g_lesp_state.worker.running = true; + + ret = pthread_create(&g_lesp_state.worker.thread, + (ret < 0)?NULL:&thread_attr, lesp_worker, NULL); + if (ret < 0) + { + syslog(LOG_ERR,"Cannot Create thread return (%d)\n",ret); + g_lesp_state.worker.running = false; + } + + if (pthread_attr_destroy(&thread_attr) < 0) + { + syslog(LOG_ERR,"Cannot destroy thread attribute (%d)\n",ret); + } + } + + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int lesp_initialize(void) +{ + int ret = 0; + + pthread_mutex_lock(&g_lesp_state.mutex); + + if (g_lesp_state.is_initialized) + { + syslog(LOG_DEBUG,"Esp8266 already initialized.\n"); + pthread_mutex_unlock(&g_lesp_state.mutex); + return 0; + } + + syslog(LOG_DEBUG,"Initializing Esp8266...\n"); + + memset(g_lesp_state.sockets, 0, SOCKET_NBR * sizeof(lesp_socket_t)); + + if (sem_init(&g_lesp_state.sem, 0, 0) < 0) + { + syslog(LOG_DEBUG,"Cannot create semaphore.\n"); + pthread_mutex_unlock(&g_lesp_state.mutex); + return -1; + } + + if (g_lesp_state.fd < 0) + { + g_lesp_state.fd = open(CONFIG_ESP8266_DEV_PATH, O_RDWR); + } + + if (g_lesp_state.fd < 0) + { + syslog(LOG_ERR,"Cannot open %s.\n", CONFIG_ESP8266_DEV_PATH); + ret = -1; + } + +#if 0 // lesp_set_baudrate is not defined + if (ret >= 0 && lesp_set_baudrate(g_lesp_state.fd, CONFIG_ESP8266_BAUDRATE) < 0) + { + syslog(LOG_ERR,"Cannot set baud rate %d.\n", CONFIG_ESP8266_BAUDRATE); + ret = -1; + } +#endif + + if ((ret >= 0) && (g_lesp_state.worker.running == false)) + { + ret = lesp_create_worker(CONFIG_LESP_THREAD_PRIO); + } + + pthread_mutex_unlock(&g_lesp_state.mutex); + g_lesp_state.is_initialized = true; + syslog(LOG_DEBUG,"Esp8266 initialized.\n"); + + return 0; +} + +int lesp_soft_reset(void) +{ + int ret = 0; + int i; + + /* Rry to close opened reset */ + + for(i = 0; i < SOCKET_NBR; i++) + { + if ((g_lesp_state.sockets[i].flags & FLAGS_SOCK_USED) != 0) + { + lesp_closesocket(i); + } + } + + /* Leave time to close socket */ + + sleep(1); + + /* Send reset */ + + lesp_send_cmd("AT+RST\r\n"); + + /* Leave time to reset */ + + sleep(1); + + lesp_flush(); + + while(lesp_ask_ans_ok(lespTIMEOUT_MS, "ATE0\r\n") < 0) + { + sleep(1); + lesp_flush(); + } + + if (ret >= 0) + { + ret = lesp_ask_ans_ok(lespTIMEOUT_MS,"AT+GMR\r\n"); + } + + /* Enable the module to act as a “Station” */ + + if (ret >= 0) + { + ret = lesp_ask_ans_ok(lespTIMEOUT_MS,"AT+CWMODE_CUR=1\r\n"); + } + + /* Enable the multi connection */ + + if (ret >= 0) + { + ret = lesp_ask_ans_ok(lespTIMEOUT_MS,"AT+CIPMUX=1\r\n"); + } + + if (ret < 0) + { + ret = -1; + } + + return 0; +} + +int lesp_ap_connect(const char* ssid_name, const char* ap_key, int timeout_s) +{ + int ret = 0; + + syslog(LOG_DEBUG,"Starting manual connect...\n"); + + if (! g_lesp_state.is_initialized) + { + syslog(LOG_ERR,"ESP8266 not initialized; can't run manual connect.\n"); + ret = -1; + } + else + { + ret = lesp_ask_ans_ok(timeout_s*1000, + "AT+CWJAP=\"%s\",\"%s\"\r\n", + ssid_name,ap_key); + } + + if (ret < 0) + { + return -1; + } + + syslog(LOG_DEBUG,"Wifi connected.\n"); + return 0; +} + +/**************************************************************************** + * Name: lesp_set_net + * + * Description: + * It will set network ip of mode. + * Warning: use lesp_eMODE_STATION or lesp_eMODE_AP. + * + * Input Parmeters: + * mode : mode to configure. + * ip : ip of interface. + * mask : network mask of interface. + * gateway : gateway ip of network. + * + * Returned Value: + * 0 on success, -1 on error. + * + ****************************************************************************/ + +int lesp_set_net(lesp_mode_t mode, in_addr_t ip, in_addr_t mask, in_addr_t gateway) +{ + int ret = 0; + + ret = lesp_ask_ans_ok(lespTIMEOUT_MS, + "AT+CIP%s_CUR=" + "\"%d.%d.%d.%d\"," + "\"%d.%d.%d.%d\"," + "\"%d.%d.%d.%d\"" + "\r\n", + (mode==lesp_eMODE_STATION)?"STA":"AP", + *((uint8_t*)&(ip)+0), + *((uint8_t*)&(ip)+1), + *((uint8_t*)&(ip)+2), + *((uint8_t*)&(ip)+3), + *((uint8_t*)&(gateway)+0), + *((uint8_t*)&(gateway)+1), + *((uint8_t*)&(gateway)+2), + *((uint8_t*)&(gateway)+3), + *((uint8_t*)&(mask)+0), + *((uint8_t*)&(mask)+1), + *((uint8_t*)&(mask)+2), + *((uint8_t*)&(mask)+3)); + + if (ret < 0) + { + return -1; + } + + return 0; +} + +/**************************************************************************** + * Name: lesp_set_dhcp + * + * Description: + * It will Enable or disable DHCP of mode. + * + * Input Parmeters: + * mode : mode to configure. + * enable : true for enable, false for disable. + * + * Returned Value: + * 0 on success, -1 on error. + * + ****************************************************************************/ + +int lesp_set_dhcp(lesp_mode_t mode,bool enable) +{ + int ret = 0; + + ret = lesp_ask_ans_ok(lespTIMEOUT_MS, + "AT+CWDHCP_CUR=%d,%c\r\n", + mode,(enable)?'1':'0'); + + if (ret < 0) + { + return -1; + } + + return 0; +} + +/**************************************************************************** + * Name: lesp_list_access_points + * + * Description: + * Search all access points. + * + * Input Parmeters: + * cb : call back call for each access point found. + * + * Returned Value: + * Number access point(s) found on success, -1 on error. + * + ****************************************************************************/ + +int lesp_list_access_points(lesp_cb_t cb) +{ + lesp_ap_t ap; + int ret = 0; + int number = 0; + + /* Check esp */ + + ret = lesp_ask_ans_ok(lespTIMEOUT_MS,"AT\r\n"); + + if (ret < 0) + { + ret = lesp_send_cmd("AT+CWLAP\r\n"); + } + + while (ret >= 0) + { + ret = lesp_read(lespTIMEOUT_MS_LISP_AP); + if (ret < 0) + { + continue; + } + + syslog(LOG_DEBUG,"Read:%s.\n",g_lesp_state.buf_ans); + + if (strcmp(g_lesp_state.buf_ans,"OK") == 0) + { + break; + } + + ret = lesp_parse_cwlap_ans_line(g_lesp_state.buf_ans,&ap); + if (ret < 0) + { + syslog(LOG_ERR,"Line badly formed."); + } + + cb(&ap); + number++; + } + + if (ret < 0) + { + return -1; + } + + syslog(LOG_DEBUG,"Access Point list finished with %d ap founds.\n",number); + + return number; +} + +const char *lesp_security_to_str(lesp_security_t security) +{ + switch(security) + { + case lesp_eSECURITY_NONE: + return "NONE"; + case lesp_eSECURITY_WEP: + return "WEP"; + case lesp_eSECURITY_WPA_PSK: + return "WPA_PSK"; + case lesp_eSECURITY_WPA2_PSK: + return "WPA2_PSK"; + case lesp_eSECURITY_WPA_WPA2_PSK: + return "WPA_WPA2_PSK"; + default: + return "Unknown"; + } +} + +int lesp_socket(int domain, int type, int protocol) +{ + int ret = 0; + int i = CON_NBR; + + if ((domain != PF_INET) && (type != SOCK_STREAM) && (IPPROTO_TCP)) + { + syslog(LOG_ERR,"Not Implemented!\n"); + return -1; + } + + pthread_mutex_lock(&g_lesp_state.mutex); + + ret = -1; + if (!g_lesp_state.is_initialized) + { + syslog(LOG_DEBUG,"Esp8266 not initialized; can't list access points.\n"); + } + else + { + for (i = 0; i < CON_NBR;i++) + { + if ((g_lesp_state.sockets[i].flags & FLAGS_SOCK_USED) == 0) + { + g_lesp_state.sockets[i].flags |= FLAGS_SOCK_USED; + ret = i; + break; + } + } + } + + pthread_mutex_unlock(&g_lesp_state.mutex); + + return ret; +} + +int lesp_closesocket(int sockfd) +{ + int ret = 0; + lesp_socket_t *sock; + + sock = get_sock(sockfd); + if (sock == NULL) + { + ret = -1; + } + + if (ret >= 0) + { + ret = lesp_ask_ans_ok(lespTIMEOUT_MS, + "AT+CIPCLOSE=%d\r\n", + sockfd); + + memset(sock, 0, sizeof(lesp_socket_t)); + sock->flags = 0; + sock->nfifo = 0; + } + + if (ret < 0) + { + return -1; + } + + return 0; +} + +int lesp_bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) +{ + syslog(LOG_ERR,"Not implemented %s\n",__func__); + return -1; +} + +int lesp_connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) +{ + int ret = 0; + lesp_socket_t *sock; + struct sockaddr_in *in; + unsigned short port; + in_addr_t ip; + + in = (struct sockaddr_in*)addr; + port = ntohs(in->sin_port); // e.g. htons(3490) + ip = in->sin_addr.s_addr; + + DEBUGASSERT(in->sin_family = AF_INET); + + sock = get_sock(sockfd); + if (sock == NULL) + { + ret = -1; + } + + if (ret >= 0) + { + ret = lesp_ask_ans_ok(lespTIMEOUT_MS, + "AT+CIPSTART=%d," + "\"TCP\"," + "\"%d.%d.%d.%d\"," + "%d" + "\r\n", + sockfd, + *((uint8_t*)&(ip)+0), + *((uint8_t*)&(ip)+1), + *((uint8_t*)&(ip)+2), + *((uint8_t*)&(ip)+3), + port); + } + + if (ret < 0) + { + return -1; + } + + return 0; +} + +int lesp_listen(int sockfd, int backlog) +{ + syslog(LOG_ERR,"Not implemented %s\n", __func__); + return -1; +} + +int lesp_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) +{ + syslog(LOG_ERR,"Not implemented %s\n", __func__); + return -1; +} + +ssize_t lesp_send(int sockfd, FAR const uint8_t *buf, size_t len, int flags) +{ + int ret = 0; + lesp_socket_t *sock; + + UNUSED(flags); + + sock = get_sock(sockfd); + if (sock == NULL) + { + ret = -1; + } + + if (ret >= 0) + { + ret = lesp_ask_ans_ok(lespTIMEOUT_MS,"AT+CIPSEND=%d,%d\r\n",sockfd,len); + } + + if (ret >= 0) + { + syslog(LOG_DEBUG,"Sending in socket %d, %d bytes.\n",sockfd,len); + ret = write(g_lesp_state.fd,buf,len); + } + + while (ret >= 0) + { + char * ptr = g_lesp_state.buf_ans; + ret = lesp_read(lespTIMEOUT_MS); + + if (ret < 0) + { + break; + } + + while ((*ptr != 0) && (*ptr != 'S')) + { + ptr++; + } + + if (*ptr == 'S') + { + if (strcmp(ptr,"SEND OK") == 0) + break; + } + } + + if (ret >= 0) + { + syslog(LOG_DEBUG,"Sent.\n"); + } + + if (ret < 0) + { + syslog(LOG_ERR,"Cannot send in socket %d, %d bytes.\n",sockfd,len); + return -1; + } + + return 0; +} + +ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) +{ + int ret = 0; + lesp_socket_t *sock; + sem_t sem; + + if (sem_init(&sem, 0, 0) < 0) + { + syslog(LOG_DEBUG,"Cannot create semaphore.\n"); + return -1; + } + + pthread_mutex_lock(&g_lesp_state.mutex); + + UNUSED(flags); + + sock = get_sock(sockfd); + if (sock == NULL) + { + ret = -1; + } + + if ((ret >= 0) && (sock->nfifo == 0)) + { + struct timespec ts; + if (clock_gettime(CLOCK_REALTIME,&ts) < 0) + { + ret = -1; + } + else + { + ts.tv_sec += lespTIMEOUT_MS_RECV_S; + sock->sem = &sem; + while ((ret >= 0) && (sock->nfifo == 0)) + { + pthread_mutex_unlock(&g_lesp_state.mutex); + ret = sem_timedwait(&sem,&ts); + pthread_mutex_lock(&g_lesp_state.mutex); + } + + sock->sem = NULL; + } + } + + if (ret >= 0) + { + ret = 0; + while (ret < len && sock->nfifo > 0) + { + int ndx = sock->nfifo; + *buf++ = sock->rxbuf[ndx]; + sock->nfifo = ndx - 1; + ret++; + } + } + + pthread_mutex_unlock(&g_lesp_state.mutex); + + if (ret < 0) + { + return -1; + } + + return ret; +} + +int lesp_setsockopt(int sockfd, int level, int option, + FAR const void *value, socklen_t value_len) +{ + syslog(LOG_ERR,"Not implemented %s\n", __func__); + return -1; +} + +int lesp_getsockopt(int sockfd, int level, int option, FAR void *value, + FAR socklen_t *value_len) +{ + syslog(LOG_ERR,"Not implemented %s\n", __func__); + return -1; +} + +int lesp_gethostbyname(char *hostname, uint16_t usNameLen, + unsigned long *out_ip_addr) +{ + syslog(LOG_ERR,"Not implemented %s\n", __func__); + return -1; +} + +int lesp_mdnsadvertiser(uint16_t mdnsEnabled, char *deviceServiceName, + uint16_t deviceServiceNameLength) +{ + syslog(LOG_ERR,"Not implemented %s\n",__func__); + return -1; +} + +#endif /* CONFIG_NETUTILS_ESP8266 */ From 6789eec9d8cc83144d480631bf92cad8b87e1379 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 May 2016 09:20:37 -0600 Subject: [PATCH 17/31] ESP8266: Fix fifo logic; make configration variable naming consistent --- netutils/esp8266/Kconfig | 10 +++++----- netutils/esp8266/esp8266.c | 31 ++++++++++++++++--------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/netutils/esp8266/Kconfig b/netutils/esp8266/Kconfig index febd10aa2..f08d763fe 100644 --- a/netutils/esp8266/Kconfig +++ b/netutils/esp8266/Kconfig @@ -11,23 +11,23 @@ config NETUTILS_ESP8266 if NETUTILS_ESP8266 -config ESP8266_DEV_PATH +config NETUTILS_ESP8266_DEV_PATH string "Serial device path" default "/dev/ttyS1" -config ESP8266_BAUDRATE +config NETUTILS_ESP8266_BAUDRATE int "Serial BAUD rate" default 115200 -config WIFI_MAX_TX_LEN +config NETUTILS_ESP8266_MAXTXLEN int "Max. TX length" default 256 -config WIFI_MAX_RX_LEN +config NETUTILS_ESP8266_MAXRXLEN int "Max. RX length" default 256 -config LESP_THREAD_PRIO +config NETUTILS_ESP8266_THREADPRIO int "Worker thread priority" default 100 diff --git a/netutils/esp8266/esp8266.c b/netutils/esp8266/esp8266.c index d4cbb987f..d14340d9d 100644 --- a/netutils/esp8266/esp8266.c +++ b/netutils/esp8266/esp8266.c @@ -65,16 +65,16 @@ #define NETAPP_IPCONFIG_MAC_OFFSET (20) -#ifndef CONFIG_WIFI_MAX_TX_LEN -# define CONFIG_WIFI_MAX_TX_LEN 256 +#ifndef CONFIG_NETUTILS_ESP8266_MAXTXLEN +# define CONFIG_NETUTILS_ESP8266_MAXTXLEN 256 #endif -#ifndef CONFIG_WIFI_MAX_RX_LEN -# define CONFIG_WIFI_MAX_RX_LEN 256 +#ifndef CONFIG_NETUTILS_ESP8266_MAXRXLEN +# define CONFIG_NETUTILS_ESP8266_MAXRXLEN 256 #endif -#define BUF_CMD_LEN CONFIG_WIFI_MAX_TX_LEN -#define BUF_ANS_LEN CONFIG_WIFI_MAX_RX_LEN +#define BUF_CMD_LEN CONFIG_NETUTILS_ESP8266_MAXTXLEN +#define BUF_ANS_LEN CONFIG_NETUTILS_ESP8266_MAXRXLEN #define BUF_WORKER_LEN 1024 #define CON_NBR 4 @@ -846,26 +846,26 @@ int lesp_initialize(void) if (g_lesp_state.fd < 0) { - g_lesp_state.fd = open(CONFIG_ESP8266_DEV_PATH, O_RDWR); + g_lesp_state.fd = open(CONFIG_NETUTILS_ESP8266_DEV_PATH, O_RDWR); } if (g_lesp_state.fd < 0) { - syslog(LOG_ERR,"Cannot open %s.\n", CONFIG_ESP8266_DEV_PATH); + syslog(LOG_ERR,"Cannot open %s.\n", CONFIG_NETUTILS_ESP8266_DEV_PATH); ret = -1; } #if 0 // lesp_set_baudrate is not defined - if (ret >= 0 && lesp_set_baudrate(g_lesp_state.fd, CONFIG_ESP8266_BAUDRATE) < 0) + if (ret >= 0 && lesp_set_baudrate(g_lesp_state.fd, CONFIG_NETUTILS_ESP8266_BAUDRATE) < 0) { - syslog(LOG_ERR,"Cannot set baud rate %d.\n", CONFIG_ESP8266_BAUDRATE); + syslog(LOG_ERR,"Cannot set baud rate %d.\n", CONFIG_NETUTILS_ESP8266_BAUDRATE); ret = -1; } #endif if ((ret >= 0) && (g_lesp_state.worker.running == false)) { - ret = lesp_create_worker(CONFIG_LESP_THREAD_PRIO); + ret = lesp_create_worker(CONFIG_NETUTILS_ESP8266_THREADPRIO); } pthread_mutex_unlock(&g_lesp_state.mutex); @@ -1338,9 +1338,10 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) ret = -1; } - if ((ret >= 0) && (sock->nfifo == 0)) + if (ret >= 0 && sock->nfifo == 0) { struct timespec ts; + if (clock_gettime(CLOCK_REALTIME,&ts) < 0) { ret = -1; @@ -1349,7 +1350,7 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) { ts.tv_sec += lespTIMEOUT_MS_RECV_S; sock->sem = &sem; - while ((ret >= 0) && (sock->nfifo == 0)) + while (ret >= 0 && sock->nfifo == 0) { pthread_mutex_unlock(&g_lesp_state.mutex); ret = sem_timedwait(&sem,&ts); @@ -1365,9 +1366,9 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) ret = 0; while (ret < len && sock->nfifo > 0) { - int ndx = sock->nfifo; + int ndx = sock->nfifo - 1; *buf++ = sock->rxbuf[ndx]; - sock->nfifo = ndx - 1; + sock->nfifo = ndx; ret++; } } From 15fd860a2fa0179b04963d352395beb384a54ebb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 May 2016 09:42:53 -0600 Subject: [PATCH 18/31] Space after comma --- netutils/esp8266/esp8266.c | 90 +++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/netutils/esp8266/esp8266.c b/netutils/esp8266/esp8266.c index d14340d9d..a6ec06894 100644 --- a/netutils/esp8266/esp8266.c +++ b/netutils/esp8266/esp8266.c @@ -175,19 +175,19 @@ static lesp_socket_t *get_sock(int sockfd) { if (!g_lesp_state.is_initialized) { - syslog(LOG_DEBUG,"Esp8266 not initialized; can't list access points.\n"); + syslog(LOG_DEBUG, "Esp8266 not initialized; can't list access points.\n"); return NULL; } if (((unsigned int)sockfd) >= SOCKET_NBR) { - syslog(LOG_DEBUG,"Esp8266 invalid sockfd.\n",sockfd); + syslog(LOG_DEBUG, "Esp8266 invalid sockfd.\n", sockfd); return NULL; } if ((g_lesp_state.sockets[sockfd].flags & FLAGS_SOCK_USED) == 0) { - syslog(LOG_ERR,"Connection id %d not Created!\n",sockfd); + syslog(LOG_ERR, "Connection id %d not Created!\n", sockfd); return NULL; } @@ -226,12 +226,12 @@ static int lesp_low_level_read(uint8_t* buf, int size) { int err = errno; syslog(LOG_ERR, - "worker read Error %d (errno %d:%d)\n",ret, - err,strerror(err)); + "worker read Error %d (errno %d:%d)\n", ret, + err, strerror(err)); } else if ((fds[0].revents & POLLERR) && (fds[0].revents & POLLHUP)) { - syslog(LOG_ERR,"worker poll read Error %d\n",ret); + syslog(LOG_ERR, "worker poll read Error %d\n", ret); ret = -1; } else if (fds[0].revents & POLLIN) @@ -303,7 +303,7 @@ static inline int lesp_read_ipd(void) return -1; } - syslog(LOG_DEBUG,"Read %d bytes for socket %d \n",len,sockfd); + syslog(LOG_DEBUG, "Read %d bytes for socket %d \n", len, sockfd); while(len) { @@ -335,7 +335,7 @@ static inline int lesp_read_ipd(void) } else { - syslog(LOG_DEBUG,"overflow socket 0x%02X\n", b); + syslog(LOG_DEBUG, "overflow socket 0x%02X\n", b); } } @@ -373,11 +373,11 @@ int lesp_vsend_cmd(FAR const IPTR char *format, va_list ap) if (ret >= BUF_CMD_LEN) { g_lesp_state.buf_cmd[BUF_CMD_LEN-1]='\0'; - syslog(LOG_DEBUG,"Buffer too small for '%s'...\n", g_lesp_state.buf_cmd); + syslog(LOG_DEBUG, "Buffer too small for '%s'...\n", g_lesp_state.buf_cmd); ret = -1; } - syslog(LOG_DEBUG,"Write:%s\n",g_lesp_state.buf_cmd); + syslog(LOG_DEBUG, "Write:%s\n", g_lesp_state.buf_cmd); ret = write(g_lesp_state.fd,g_lesp_state.buf_cmd,ret); if (ret < 0) @@ -439,7 +439,7 @@ static int lesp_read(int timeout_ms) if (! g_lesp_state.is_initialized) { - syslog(LOG_DEBUG,"Esp8266 not initialized; can't list access points.\n"); + syslog(LOG_DEBUG, "Esp8266 not initialized; can't list access points.\n"); return -1; } @@ -472,7 +472,7 @@ static int lesp_read(int timeout_ms) } while (ret == 0); - syslog(LOG_DEBUG,"read %d=>%s\n",ret,g_lesp_state.buf_ans); + syslog(LOG_DEBUG, "read %d=>%s\n", ret, g_lesp_state.buf_ans); return ret; } @@ -721,11 +721,11 @@ static void *lesp_worker(void *args) if (ret < 0) { - syslog(LOG_ERR,"worker read data Error %d\n",ret); + syslog(LOG_ERR, "worker read data Error %d\n", ret); } else if (ret > 0) { - //syslog(LOG_DEBUG,"c:0x%02X (%c)\n",c); + //syslog(LOG_DEBUG, "c:0x%02X (%c)\n", c); pthread_mutex_lock(&g_lesp_state.mutex); if (c == '\n') @@ -739,7 +739,7 @@ static void *lesp_worker(void *args) { p->buf[p->buf_size] = '\0'; memcpy(g_lesp_state.buf,p->buf,p->buf_size+1); - syslog(LOG_DEBUG,"Read data:%s\n",g_lesp_state.buf); + syslog(LOG_DEBUG, "Read data:%s\n", g_lesp_state.buf); sem_post(&g_lesp_state.sem); p->buf_size = 0; } @@ -750,7 +750,7 @@ static void *lesp_worker(void *args) } else { - syslog(LOG_DEBUG,"Read char overflow:%c\n",c); + syslog(LOG_DEBUG, "Read char overflow:%c\n", c); } pthread_mutex_unlock(&g_lesp_state.mutex); @@ -781,7 +781,7 @@ static inline int lesp_create_worker(int priority) if (ret < 0) { - syslog(LOG_ERR,"Cannot Set scheduler parameter thread (%d)\n",ret); + syslog(LOG_ERR, "Cannot Set scheduler parameter thread (%d)\n", ret); } else { @@ -793,7 +793,7 @@ static inline int lesp_create_worker(int priority) } else { - syslog(LOG_ERR,"Cannot Get/Set scheduler parameter thread (%d)\n", + syslog(LOG_ERR, "Cannot Get/Set scheduler parameter thread (%d)\n", ret); } @@ -803,13 +803,13 @@ static inline int lesp_create_worker(int priority) (ret < 0)?NULL:&thread_attr, lesp_worker, NULL); if (ret < 0) { - syslog(LOG_ERR,"Cannot Create thread return (%d)\n",ret); + syslog(LOG_ERR, "Cannot Create thread return (%d)\n", ret); g_lesp_state.worker.running = false; } if (pthread_attr_destroy(&thread_attr) < 0) { - syslog(LOG_ERR,"Cannot destroy thread attribute (%d)\n",ret); + syslog(LOG_ERR, "Cannot destroy thread attribute (%d)\n", ret); } } @@ -828,18 +828,18 @@ int lesp_initialize(void) if (g_lesp_state.is_initialized) { - syslog(LOG_DEBUG,"Esp8266 already initialized.\n"); + syslog(LOG_DEBUG, "Esp8266 already initialized.\n"); pthread_mutex_unlock(&g_lesp_state.mutex); return 0; } - syslog(LOG_DEBUG,"Initializing Esp8266...\n"); + syslog(LOG_DEBUG, "Initializing Esp8266...\n"); memset(g_lesp_state.sockets, 0, SOCKET_NBR * sizeof(lesp_socket_t)); if (sem_init(&g_lesp_state.sem, 0, 0) < 0) { - syslog(LOG_DEBUG,"Cannot create semaphore.\n"); + syslog(LOG_DEBUG, "Cannot create semaphore.\n"); pthread_mutex_unlock(&g_lesp_state.mutex); return -1; } @@ -851,14 +851,14 @@ int lesp_initialize(void) if (g_lesp_state.fd < 0) { - syslog(LOG_ERR,"Cannot open %s.\n", CONFIG_NETUTILS_ESP8266_DEV_PATH); + syslog(LOG_ERR, "Cannot open %s.\n", CONFIG_NETUTILS_ESP8266_DEV_PATH); ret = -1; } #if 0 // lesp_set_baudrate is not defined if (ret >= 0 && lesp_set_baudrate(g_lesp_state.fd, CONFIG_NETUTILS_ESP8266_BAUDRATE) < 0) { - syslog(LOG_ERR,"Cannot set baud rate %d.\n", CONFIG_NETUTILS_ESP8266_BAUDRATE); + syslog(LOG_ERR, "Cannot set baud rate %d.\n", CONFIG_NETUTILS_ESP8266_BAUDRATE); ret = -1; } #endif @@ -870,7 +870,7 @@ int lesp_initialize(void) pthread_mutex_unlock(&g_lesp_state.mutex); g_lesp_state.is_initialized = true; - syslog(LOG_DEBUG,"Esp8266 initialized.\n"); + syslog(LOG_DEBUG, "Esp8266 initialized.\n"); return 0; } @@ -941,11 +941,11 @@ int lesp_ap_connect(const char* ssid_name, const char* ap_key, int timeout_s) { int ret = 0; - syslog(LOG_DEBUG,"Starting manual connect...\n"); + syslog(LOG_DEBUG, "Starting manual connect...\n"); if (! g_lesp_state.is_initialized) { - syslog(LOG_ERR,"ESP8266 not initialized; can't run manual connect.\n"); + syslog(LOG_ERR, "ESP8266 not initialized; can't run manual connect.\n"); ret = -1; } else @@ -960,7 +960,7 @@ int lesp_ap_connect(const char* ssid_name, const char* ap_key, int timeout_s) return -1; } - syslog(LOG_DEBUG,"Wifi connected.\n"); + syslog(LOG_DEBUG, "Wifi connected.\n"); return 0; } @@ -1082,7 +1082,7 @@ int lesp_list_access_points(lesp_cb_t cb) continue; } - syslog(LOG_DEBUG,"Read:%s.\n",g_lesp_state.buf_ans); + syslog(LOG_DEBUG, "Read:%s.\n", g_lesp_state.buf_ans); if (strcmp(g_lesp_state.buf_ans,"OK") == 0) { @@ -1092,7 +1092,7 @@ int lesp_list_access_points(lesp_cb_t cb) ret = lesp_parse_cwlap_ans_line(g_lesp_state.buf_ans,&ap); if (ret < 0) { - syslog(LOG_ERR,"Line badly formed."); + syslog(LOG_ERR, "Line badly formed."); } cb(&ap); @@ -1104,7 +1104,7 @@ int lesp_list_access_points(lesp_cb_t cb) return -1; } - syslog(LOG_DEBUG,"Access Point list finished with %d ap founds.\n",number); + syslog(LOG_DEBUG, "Access Point list finished with %d ap founds.\n", number); return number; } @@ -1135,7 +1135,7 @@ int lesp_socket(int domain, int type, int protocol) if ((domain != PF_INET) && (type != SOCK_STREAM) && (IPPROTO_TCP)) { - syslog(LOG_ERR,"Not Implemented!\n"); + syslog(LOG_ERR, "Not Implemented!\n"); return -1; } @@ -1144,7 +1144,7 @@ int lesp_socket(int domain, int type, int protocol) ret = -1; if (!g_lesp_state.is_initialized) { - syslog(LOG_DEBUG,"Esp8266 not initialized; can't list access points.\n"); + syslog(LOG_DEBUG, "Esp8266 not initialized; can't list access points.\n"); } else { @@ -1196,7 +1196,7 @@ int lesp_closesocket(int sockfd) int lesp_bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) { - syslog(LOG_ERR,"Not implemented %s\n",__func__); + syslog(LOG_ERR, "Not implemented %s\n", __func__); return -1; } @@ -1246,13 +1246,13 @@ int lesp_connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) int lesp_listen(int sockfd, int backlog) { - syslog(LOG_ERR,"Not implemented %s\n", __func__); + syslog(LOG_ERR, "Not implemented %s\n", __func__); return -1; } int lesp_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { - syslog(LOG_ERR,"Not implemented %s\n", __func__); + syslog(LOG_ERR, "Not implemented %s\n", __func__); return -1; } @@ -1276,7 +1276,7 @@ ssize_t lesp_send(int sockfd, FAR const uint8_t *buf, size_t len, int flags) if (ret >= 0) { - syslog(LOG_DEBUG,"Sending in socket %d, %d bytes.\n",sockfd,len); + syslog(LOG_DEBUG, "Sending in socket %d, %d bytes.\n", sockfd,len); ret = write(g_lesp_state.fd,buf,len); } @@ -1304,12 +1304,12 @@ ssize_t lesp_send(int sockfd, FAR const uint8_t *buf, size_t len, int flags) if (ret >= 0) { - syslog(LOG_DEBUG,"Sent.\n"); + syslog(LOG_DEBUG, "Sent.\n"); } if (ret < 0) { - syslog(LOG_ERR,"Cannot send in socket %d, %d bytes.\n",sockfd,len); + syslog(LOG_ERR, "Cannot send in socket %d, %d bytes.\n", sockfd, len); return -1; } @@ -1324,7 +1324,7 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) if (sem_init(&sem, 0, 0) < 0) { - syslog(LOG_DEBUG,"Cannot create semaphore.\n"); + syslog(LOG_DEBUG, "Cannot create semaphore.\n"); return -1; } @@ -1386,28 +1386,28 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) int lesp_setsockopt(int sockfd, int level, int option, FAR const void *value, socklen_t value_len) { - syslog(LOG_ERR,"Not implemented %s\n", __func__); + syslog(LOG_ERR, "Not implemented %s\n", __func__); return -1; } int lesp_getsockopt(int sockfd, int level, int option, FAR void *value, FAR socklen_t *value_len) { - syslog(LOG_ERR,"Not implemented %s\n", __func__); + syslog(LOG_ERR, "Not implemented %s\n", __func__); return -1; } int lesp_gethostbyname(char *hostname, uint16_t usNameLen, unsigned long *out_ip_addr) { - syslog(LOG_ERR,"Not implemented %s\n", __func__); + syslog(LOG_ERR, "Not implemented %s\n", __func__); return -1; } int lesp_mdnsadvertiser(uint16_t mdnsEnabled, char *deviceServiceName, uint16_t deviceServiceNameLength) { - syslog(LOG_ERR,"Not implemented %s\n",__func__); + syslog(LOG_ERR, "Not implemented %s\n",__func__); return -1; } From 8217864a102dcebcb22e6c3d438b306dff309d0f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 May 2016 11:11:32 -0600 Subject: [PATCH 19/31] Add .gitignore file for ESP8266 --- include/netutils/esp8266.h | 4 ++-- netutils/esp8266/.gitignore | 6 ++++++ netutils/esp8266/Makefile | 24 ++++++++++++------------ netutils/esp8266/esp8266.c | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 netutils/esp8266/.gitignore diff --git a/include/netutils/esp8266.h b/include/netutils/esp8266.h index a9dda56bf..2df3e4e0a 100644 --- a/include/netutils/esp8266.h +++ b/include/netutils/esp8266.h @@ -52,7 +52,7 @@ #define lespBSSID_SIZE 6 -#define lespIP(x1,x2,x3,x4) ( (x1)<<24 |(x2)<<16 |(x3)<<8 |(x4)<<0 ) +#define lespIP(x1,x2,x3,x4) ((x1) << 24 | (x2) << 16 | (x3) << 8 | (x4) << 0) /**************************************************************************** * Public Types @@ -62,7 +62,7 @@ typedef enum { lesp_eMODE_AP = 0, lesp_eMODE_STATION = 1, - lesp_eMODE_BOTH = 2, + lesp_eMODE_BOTH = 2 } lesp_mode_t; typedef enum diff --git a/netutils/esp8266/.gitignore b/netutils/esp8266/.gitignore new file mode 100644 index 000000000..f21c854d1 --- /dev/null +++ b/netutils/esp8266/.gitignore @@ -0,0 +1,6 @@ +/.built +/.depend +/Make.dep +/*.src +/*.obj +/*.lst diff --git a/netutils/esp8266/Makefile b/netutils/esp8266/Makefile index 924753033..7435c082b 100644 --- a/netutils/esp8266/Makefile +++ b/netutils/esp8266/Makefile @@ -39,34 +39,34 @@ include $(APPDIR)/Make.defs # ESP8266 Library -ASRCS = -CSRCS = +ASRCS = +CSRCS = ifeq ($(CONFIG_NET_TCP),y) -CSRCS += esp8266.c +CSRCS += esp8266.c endif -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) + BIN = ..\..\libapps$(LIBEXT) else ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) + BIN = ..\\..\\libapps$(LIBEXT) else - BIN = ../../libapps$(LIBEXT) + BIN = ../../libapps$(LIBEXT) endif endif -ROOTDEPPATH = --dep-path . +ROOTDEPPATH = --dep-path . # Common build -VPATH = +VPATH = all: .built .PHONY: context depend clean distclean diff --git a/netutils/esp8266/esp8266.c b/netutils/esp8266/esp8266.c index a6ec06894..a6178a2e3 100644 --- a/netutils/esp8266/esp8266.c +++ b/netutils/esp8266/esp8266.c @@ -1407,7 +1407,7 @@ int lesp_gethostbyname(char *hostname, uint16_t usNameLen, int lesp_mdnsadvertiser(uint16_t mdnsEnabled, char *deviceServiceName, uint16_t deviceServiceNameLength) { - syslog(LOG_ERR, "Not implemented %s\n",__func__); + syslog(LOG_ERR, "Not implemented %s\n", __func__); return -1; } From d5b00bafbd3ce20c54694ea9420e6f5ee427f97c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 May 2016 15:42:35 -0600 Subject: [PATCH 20/31] eps8266: Fix FIFO implementation; it was a stack not a FIFO. --- netutils/esp8266/esp8266.c | 86 +++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/netutils/esp8266/esp8266.c b/netutils/esp8266/esp8266.c index a6178a2e3..37993cc93 100644 --- a/netutils/esp8266/esp8266.c +++ b/netutils/esp8266/esp8266.c @@ -106,10 +106,11 @@ typedef struct { - int flags; - int nfifo; - sem_t *sem; - uint8_t rxbuf[SOCKET_FIFO_SIZE]; + sem_t *sem; + uint8_t flags; + uint16_t in; + uint16_t out; + uint8_t rxbuf[SOCKET_FIFO_SIZE]; } lesp_socket_t; typedef struct @@ -117,7 +118,7 @@ typedef struct bool running; pthread_t thread; uint8_t buf[BUF_WORKER_LEN]; - int buf_size; + int bufsize; } lesp_worker_t; typedef struct @@ -129,8 +130,8 @@ typedef struct lesp_socket_t sockets[SOCKET_NBR]; sem_t sem; char buf[BUF_ANS_LEN]; - char buf_ans[BUF_ANS_LEN]; - char buf_cmd[BUF_CMD_LEN]; + char bufans[BUF_ANS_LEN]; + char bufcmd[BUF_CMD_LEN]; } lesp_state_t; /**************************************************************************** @@ -273,7 +274,7 @@ static inline int lesp_read_ipd(void) /* Put a null at end */ - *(ptr + g_lesp_state.worker.buf_size) = '\0'; + *(ptr + g_lesp_state.worker.bufsize) = '\0'; if (memcmp(ptr,"+IPD,",5) != 0) { @@ -327,11 +328,11 @@ static inline int lesp_read_ipd(void) while(size --) { uint8_t b = *buf++; - if (sock->nfifo < SOCKET_FIFO_SIZE) + if (sock->in < SOCKET_FIFO_SIZE) { - int ndx = sock->nfifo; + int ndx = sock->in; sock->rxbuf[ndx] = b; - sock->nfifo = ndx + 1; + sock->in = ndx + 1; } else { @@ -369,17 +370,17 @@ int lesp_vsend_cmd(FAR const IPTR char *format, va_list ap) { int ret = 0; - ret = vsnprintf(g_lesp_state.buf_cmd,BUF_CMD_LEN,format,ap); + ret = vsnprintf(g_lesp_state.bufcmd,BUF_CMD_LEN,format,ap); if (ret >= BUF_CMD_LEN) { - g_lesp_state.buf_cmd[BUF_CMD_LEN-1]='\0'; - syslog(LOG_DEBUG, "Buffer too small for '%s'...\n", g_lesp_state.buf_cmd); + g_lesp_state.bufcmd[BUF_CMD_LEN-1]='\0'; + syslog(LOG_DEBUG, "Buffer too small for '%s'...\n", g_lesp_state.bufcmd); ret = -1; } - syslog(LOG_DEBUG, "Write:%s\n", g_lesp_state.buf_cmd); + syslog(LOG_DEBUG, "Write:%s\n", g_lesp_state.bufcmd); - ret = write(g_lesp_state.fd,g_lesp_state.buf_cmd,ret); + ret = write(g_lesp_state.fd,g_lesp_state.bufcmd,ret); if (ret < 0) { ret = -1; @@ -462,7 +463,7 @@ static int lesp_read(int timeout_ms) ret = strlen(g_lesp_state.buf); if (ret > 0) { - memcpy(g_lesp_state.buf_ans,g_lesp_state.buf,ret+1); /* +1 to copy null */ + memcpy(g_lesp_state.bufans,g_lesp_state.buf,ret+1); /* +1 to copy null */ } g_lesp_state.buf[0] = '\0'; @@ -472,7 +473,7 @@ static int lesp_read(int timeout_ms) } while (ret == 0); - syslog(LOG_DEBUG, "read %d=>%s\n", ret, g_lesp_state.buf_ans); + syslog(LOG_DEBUG, "read %d=>%s\n", ret, g_lesp_state.bufans); return ret; } @@ -523,22 +524,22 @@ int lesp_read_ans_ok(int timeout_ms) /* Answers sorted in probability case */ - if (strcmp(g_lesp_state.buf_ans,"OK") == 0) + if (strcmp(g_lesp_state.bufans,"OK") == 0) { return 0; } - if (strcmp(g_lesp_state.buf_ans,"FAIL") == 0) + if (strcmp(g_lesp_state.bufans,"FAIL") == 0) { return -1; } - if (strcmp(g_lesp_state.buf_ans,"ERROR") == 0) + if (strcmp(g_lesp_state.bufans,"ERROR") == 0) { return -1; } - syslog(LOG_INFO,"Got:%s\n",g_lesp_state.buf_ans); + syslog(LOG_INFO,"Got:%s\n",g_lesp_state.bufans); /* Ro quit in case of message flooding */ } @@ -710,7 +711,7 @@ static void *lesp_worker(void *args) pthread_mutex_lock(&g_lesp_state.mutex); syslog(LOG_INFO,"worker Started \n"); - p->buf_size = 0; + p->bufsize = 0; pthread_mutex_unlock(&g_lesp_state.mutex); while(p->running) @@ -730,23 +731,23 @@ static void *lesp_worker(void *args) pthread_mutex_lock(&g_lesp_state.mutex); if (c == '\n') { - if (p->buf[p->buf_size-1] == '\r') + if (p->buf[p->bufsize-1] == '\r') { - p->buf_size--; + p->bufsize--; } - if (p->buf_size != 0) + if (p->bufsize != 0) { - p->buf[p->buf_size] = '\0'; - memcpy(g_lesp_state.buf,p->buf,p->buf_size+1); + p->buf[p->bufsize] = '\0'; + memcpy(g_lesp_state.buf,p->buf,p->bufsize+1); syslog(LOG_DEBUG, "Read data:%s\n", g_lesp_state.buf); sem_post(&g_lesp_state.sem); - p->buf_size = 0; + p->bufsize = 0; } } - else if (p->buf_size < BUF_ANS_LEN-1) + else if (p->bufsize < BUF_ANS_LEN - 1) { - p->buf[p->buf_size++] = c; + p->buf[p->bufsize++] = c; } else { @@ -757,7 +758,7 @@ static void *lesp_worker(void *args) if ((c == ':') && (lesp_read_ipd() != 0)) { - p->buf_size = 0; + p->bufsize = 0; } } } @@ -1082,14 +1083,14 @@ int lesp_list_access_points(lesp_cb_t cb) continue; } - syslog(LOG_DEBUG, "Read:%s.\n", g_lesp_state.buf_ans); + syslog(LOG_DEBUG, "Read:%s.\n", g_lesp_state.bufans); - if (strcmp(g_lesp_state.buf_ans,"OK") == 0) + if (strcmp(g_lesp_state.bufans,"OK") == 0) { break; } - ret = lesp_parse_cwlap_ans_line(g_lesp_state.buf_ans,&ap); + ret = lesp_parse_cwlap_ans_line(g_lesp_state.bufans,&ap); if (ret < 0) { syslog(LOG_ERR, "Line badly formed."); @@ -1183,7 +1184,8 @@ int lesp_closesocket(int sockfd) memset(sock, 0, sizeof(lesp_socket_t)); sock->flags = 0; - sock->nfifo = 0; + sock->in = 0; + sock->out = 0; } if (ret < 0) @@ -1282,7 +1284,7 @@ ssize_t lesp_send(int sockfd, FAR const uint8_t *buf, size_t len, int flags) while (ret >= 0) { - char * ptr = g_lesp_state.buf_ans; + char * ptr = g_lesp_state.bufans; ret = lesp_read(lespTIMEOUT_MS); if (ret < 0) @@ -1338,7 +1340,7 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) ret = -1; } - if (ret >= 0 && sock->nfifo == 0) + if (ret >= 0 && sock->in == 0) { struct timespec ts; @@ -1350,7 +1352,7 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) { ts.tv_sec += lespTIMEOUT_MS_RECV_S; sock->sem = &sem; - while (ret >= 0 && sock->nfifo == 0) + while (ret >= 0 && sock->in == 0) { pthread_mutex_unlock(&g_lesp_state.mutex); ret = sem_timedwait(&sem,&ts); @@ -1364,11 +1366,11 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) if (ret >= 0) { ret = 0; - while (ret < len && sock->nfifo > 0) + while (ret < len && sock->out < sock->in) { - int ndx = sock->nfifo - 1; + int ndx = sock->out; *buf++ = sock->rxbuf[ndx]; - sock->nfifo = ndx; + sock->out = ndx + 1; ret++; } } From cf2ee7e409fbb0b5fb41204dd2884024b285f866 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 21 May 2016 15:50:24 -0600 Subject: [PATCH 21/31] ESP8266: Used NuttX dbg() instead of unconditional syslog() calls. --- netutils/esp8266/esp8266.c | 100 ++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/netutils/esp8266/esp8266.c b/netutils/esp8266/esp8266.c index 37993cc93..20aad0fd1 100644 --- a/netutils/esp8266/esp8266.c +++ b/netutils/esp8266/esp8266.c @@ -48,9 +48,9 @@ #include #include #include -#include #include #include +#include #include #include "sys/socket.h" @@ -176,19 +176,19 @@ static lesp_socket_t *get_sock(int sockfd) { if (!g_lesp_state.is_initialized) { - syslog(LOG_DEBUG, "Esp8266 not initialized; can't list access points.\n"); - return NULL; + nvdbg("Esp8266 not initialized; can't list access points\n"); + return NULL; } if (((unsigned int)sockfd) >= SOCKET_NBR) { - syslog(LOG_DEBUG, "Esp8266 invalid sockfd.\n", sockfd); + nvdbg("Esp8266 invalid sockfd\n", sockfd); return NULL; } if ((g_lesp_state.sockets[sockfd].flags & FLAGS_SOCK_USED) == 0) { - syslog(LOG_ERR, "Connection id %d not Created!\n", sockfd); + ndbg("Connection id %d not Created!\n", sockfd); return NULL; } @@ -226,13 +226,12 @@ static int lesp_low_level_read(uint8_t* buf, int size) if (ret < 0) { int err = errno; - syslog(LOG_ERR, - "worker read Error %d (errno %d:%d)\n", ret, - err, strerror(err)); + ndbg("worker read Error %d (errno %d)\n", ret, err); + UNUSED(err); } else if ((fds[0].revents & POLLERR) && (fds[0].revents & POLLHUP)) { - syslog(LOG_ERR, "worker poll read Error %d\n", ret); + ndbg("worker poll read Error %d\n", ret); ret = -1; } else if (fds[0].revents & POLLIN) @@ -304,7 +303,7 @@ static inline int lesp_read_ipd(void) return -1; } - syslog(LOG_DEBUG, "Read %d bytes for socket %d \n", len, sockfd); + nvdbg("Read %d bytes for socket %d \n", len, sockfd); while(len) { @@ -336,7 +335,7 @@ static inline int lesp_read_ipd(void) } else { - syslog(LOG_DEBUG, "overflow socket 0x%02X\n", b); + nvdbg("overflow socket 0x%02X\n", b); } } @@ -374,11 +373,11 @@ int lesp_vsend_cmd(FAR const IPTR char *format, va_list ap) if (ret >= BUF_CMD_LEN) { g_lesp_state.bufcmd[BUF_CMD_LEN-1]='\0'; - syslog(LOG_DEBUG, "Buffer too small for '%s'...\n", g_lesp_state.bufcmd); + nvdbg("Buffer too small for '%s'...\n", g_lesp_state.bufcmd); ret = -1; } - syslog(LOG_DEBUG, "Write:%s\n", g_lesp_state.bufcmd); + nvdbg("Write:%s\n", g_lesp_state.bufcmd); ret = write(g_lesp_state.fd,g_lesp_state.bufcmd,ret); if (ret < 0) @@ -440,7 +439,7 @@ static int lesp_read(int timeout_ms) if (! g_lesp_state.is_initialized) { - syslog(LOG_DEBUG, "Esp8266 not initialized; can't list access points.\n"); + nvdbg("Esp8266 not initialized; can't list access points\n"); return -1; } @@ -473,7 +472,7 @@ static int lesp_read(int timeout_ms) } while (ret == 0); - syslog(LOG_DEBUG, "read %d=>%s\n", ret, g_lesp_state.bufans); + nvdbg("read %d=>%s\n", ret, g_lesp_state.bufans); return ret; } @@ -539,7 +538,7 @@ int lesp_read_ans_ok(int timeout_ms) return -1; } - syslog(LOG_INFO,"Got:%s\n",g_lesp_state.bufans); + nvdbg("Got:%s\n", g_lesp_state.bufans); /* Ro quit in case of message flooding */ } @@ -710,7 +709,7 @@ static void *lesp_worker(void *args) UNUSED(args); pthread_mutex_lock(&g_lesp_state.mutex); - syslog(LOG_INFO,"worker Started \n"); + nvdbg("worker Started \n"); p->bufsize = 0; pthread_mutex_unlock(&g_lesp_state.mutex); @@ -722,11 +721,11 @@ static void *lesp_worker(void *args) if (ret < 0) { - syslog(LOG_ERR, "worker read data Error %d\n", ret); + ndbg("worker read data Error %d\n", ret); } else if (ret > 0) { - //syslog(LOG_DEBUG, "c:0x%02X (%c)\n", c); + //nvdbg("c:0x%02X (%c)\n", c); pthread_mutex_lock(&g_lesp_state.mutex); if (c == '\n') @@ -740,7 +739,7 @@ static void *lesp_worker(void *args) { p->buf[p->bufsize] = '\0'; memcpy(g_lesp_state.buf,p->buf,p->bufsize+1); - syslog(LOG_DEBUG, "Read data:%s\n", g_lesp_state.buf); + nvdbg("Read data:%s\n", g_lesp_state.buf); sem_post(&g_lesp_state.sem); p->bufsize = 0; } @@ -751,7 +750,7 @@ static void *lesp_worker(void *args) } else { - syslog(LOG_DEBUG, "Read char overflow:%c\n", c); + nvdbg("Read char overflow:%c\n", c); } pthread_mutex_unlock(&g_lesp_state.mutex); @@ -782,7 +781,7 @@ static inline int lesp_create_worker(int priority) if (ret < 0) { - syslog(LOG_ERR, "Cannot Set scheduler parameter thread (%d)\n", ret); + ndbg("Cannot Set scheduler parameter thread (%d)\n", ret); } else { @@ -794,8 +793,7 @@ static inline int lesp_create_worker(int priority) } else { - syslog(LOG_ERR, "Cannot Get/Set scheduler parameter thread (%d)\n", - ret); + ndbg("Cannot Get/Set scheduler parameter thread (%d)\n", ret); } g_lesp_state.worker.running = true; @@ -804,13 +802,13 @@ static inline int lesp_create_worker(int priority) (ret < 0)?NULL:&thread_attr, lesp_worker, NULL); if (ret < 0) { - syslog(LOG_ERR, "Cannot Create thread return (%d)\n", ret); + ndbg("Cannot Create thread return (%d)\n", ret); g_lesp_state.worker.running = false; } if (pthread_attr_destroy(&thread_attr) < 0) { - syslog(LOG_ERR, "Cannot destroy thread attribute (%d)\n", ret); + ndbg("Cannot destroy thread attribute (%d)\n", ret); } } @@ -829,18 +827,18 @@ int lesp_initialize(void) if (g_lesp_state.is_initialized) { - syslog(LOG_DEBUG, "Esp8266 already initialized.\n"); + nvdbg("Esp8266 already initialized\n"); pthread_mutex_unlock(&g_lesp_state.mutex); return 0; } - syslog(LOG_DEBUG, "Initializing Esp8266...\n"); + nvdbg("Initializing Esp8266...\n"); memset(g_lesp_state.sockets, 0, SOCKET_NBR * sizeof(lesp_socket_t)); if (sem_init(&g_lesp_state.sem, 0, 0) < 0) { - syslog(LOG_DEBUG, "Cannot create semaphore.\n"); + nvdbg("Cannot create semaphore\n"); pthread_mutex_unlock(&g_lesp_state.mutex); return -1; } @@ -852,14 +850,14 @@ int lesp_initialize(void) if (g_lesp_state.fd < 0) { - syslog(LOG_ERR, "Cannot open %s.\n", CONFIG_NETUTILS_ESP8266_DEV_PATH); + ndbg("Cannot open %s\n", CONFIG_NETUTILS_ESP8266_DEV_PATH); ret = -1; } #if 0 // lesp_set_baudrate is not defined if (ret >= 0 && lesp_set_baudrate(g_lesp_state.fd, CONFIG_NETUTILS_ESP8266_BAUDRATE) < 0) { - syslog(LOG_ERR, "Cannot set baud rate %d.\n", CONFIG_NETUTILS_ESP8266_BAUDRATE); + ndbg("Cannot set baud rate %d\n", CONFIG_NETUTILS_ESP8266_BAUDRATE); ret = -1; } #endif @@ -871,7 +869,7 @@ int lesp_initialize(void) pthread_mutex_unlock(&g_lesp_state.mutex); g_lesp_state.is_initialized = true; - syslog(LOG_DEBUG, "Esp8266 initialized.\n"); + nvdbg("Esp8266 initialized\n"); return 0; } @@ -942,11 +940,11 @@ int lesp_ap_connect(const char* ssid_name, const char* ap_key, int timeout_s) { int ret = 0; - syslog(LOG_DEBUG, "Starting manual connect...\n"); + nvdbg("Starting manual connect...\n"); if (! g_lesp_state.is_initialized) { - syslog(LOG_ERR, "ESP8266 not initialized; can't run manual connect.\n"); + ndbg("ESP8266 not initialized; can't run manual connect\n"); ret = -1; } else @@ -961,7 +959,7 @@ int lesp_ap_connect(const char* ssid_name, const char* ap_key, int timeout_s) return -1; } - syslog(LOG_DEBUG, "Wifi connected.\n"); + nvdbg("Wifi connected\n"); return 0; } @@ -1083,7 +1081,7 @@ int lesp_list_access_points(lesp_cb_t cb) continue; } - syslog(LOG_DEBUG, "Read:%s.\n", g_lesp_state.bufans); + nvdbg("Read:%s\n", g_lesp_state.bufans); if (strcmp(g_lesp_state.bufans,"OK") == 0) { @@ -1093,7 +1091,7 @@ int lesp_list_access_points(lesp_cb_t cb) ret = lesp_parse_cwlap_ans_line(g_lesp_state.bufans,&ap); if (ret < 0) { - syslog(LOG_ERR, "Line badly formed."); + ndbg("Line badly formed."); } cb(&ap); @@ -1105,7 +1103,7 @@ int lesp_list_access_points(lesp_cb_t cb) return -1; } - syslog(LOG_DEBUG, "Access Point list finished with %d ap founds.\n", number); + nvdbg("Access Point list finished with %d ap founds\n", number); return number; } @@ -1136,7 +1134,7 @@ int lesp_socket(int domain, int type, int protocol) if ((domain != PF_INET) && (type != SOCK_STREAM) && (IPPROTO_TCP)) { - syslog(LOG_ERR, "Not Implemented!\n"); + ndbg("Not Implemented!\n"); return -1; } @@ -1145,7 +1143,7 @@ int lesp_socket(int domain, int type, int protocol) ret = -1; if (!g_lesp_state.is_initialized) { - syslog(LOG_DEBUG, "Esp8266 not initialized; can't list access points.\n"); + nvdbg("Esp8266 not initialized; can't list access points\n"); } else { @@ -1198,7 +1196,7 @@ int lesp_closesocket(int sockfd) int lesp_bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) { - syslog(LOG_ERR, "Not implemented %s\n", __func__); + ndbg("Not implemented %s\n", __func__); return -1; } @@ -1248,13 +1246,13 @@ int lesp_connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) int lesp_listen(int sockfd, int backlog) { - syslog(LOG_ERR, "Not implemented %s\n", __func__); + ndbg("Not implemented %s\n", __func__); return -1; } int lesp_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { - syslog(LOG_ERR, "Not implemented %s\n", __func__); + ndbg("Not implemented %s\n", __func__); return -1; } @@ -1278,7 +1276,7 @@ ssize_t lesp_send(int sockfd, FAR const uint8_t *buf, size_t len, int flags) if (ret >= 0) { - syslog(LOG_DEBUG, "Sending in socket %d, %d bytes.\n", sockfd,len); + nvdbg("Sending in socket %d, %d bytes\n", sockfd,len); ret = write(g_lesp_state.fd,buf,len); } @@ -1306,12 +1304,12 @@ ssize_t lesp_send(int sockfd, FAR const uint8_t *buf, size_t len, int flags) if (ret >= 0) { - syslog(LOG_DEBUG, "Sent.\n"); + nvdbg("Sent\n"); } if (ret < 0) { - syslog(LOG_ERR, "Cannot send in socket %d, %d bytes.\n", sockfd, len); + ndbg("Cannot send in socket %d, %d bytes\n", sockfd, len); return -1; } @@ -1326,7 +1324,7 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) if (sem_init(&sem, 0, 0) < 0) { - syslog(LOG_DEBUG, "Cannot create semaphore.\n"); + nvdbg("Cannot create semaphore\n"); return -1; } @@ -1388,28 +1386,28 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) int lesp_setsockopt(int sockfd, int level, int option, FAR const void *value, socklen_t value_len) { - syslog(LOG_ERR, "Not implemented %s\n", __func__); + ndbg("Not implemented %s\n", __func__); return -1; } int lesp_getsockopt(int sockfd, int level, int option, FAR void *value, FAR socklen_t *value_len) { - syslog(LOG_ERR, "Not implemented %s\n", __func__); + ndbg("Not implemented %s\n", __func__); return -1; } int lesp_gethostbyname(char *hostname, uint16_t usNameLen, unsigned long *out_ip_addr) { - syslog(LOG_ERR, "Not implemented %s\n", __func__); + ndbg("Not implemented %s\n", __func__); return -1; } int lesp_mdnsadvertiser(uint16_t mdnsEnabled, char *deviceServiceName, uint16_t deviceServiceNameLength) { - syslog(LOG_ERR, "Not implemented %s\n", __func__); + ndbg("Not implemented %s\n", __func__); return -1; } From 074a0a2c94c3f6b2b2117ae52445d1334900e59c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 May 2016 15:10:20 -0600 Subject: [PATCH 22/31] Update ChangeLog --- ChangeLog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index c0de67e93..966b07fde 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1597,3 +1597,5 @@ to system/ (2016-05-18). * apps/platform/nucleo-144: Add platform files for NUCLEO-144 (NUCLEO-F746ZG). From Mark Olsson (2016-05-19). + * apps/netutils/esp8266: ESP8266 driver application. From Pierre-noel + Bouteville (2016-05-21). \ No newline at end of file From eb1533ffc2c77a17fbe5e6d3e64f4fd509b02da7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 23 May 2016 07:48:14 -0600 Subject: [PATCH 23/31] ESP8266: Correctly integrate into Make system. Does not depend on CONFIG_NET. FIFO should probably be a circular buffer. --- netutils/Makefile | 4 +-- netutils/esp8266/Makefile | 6 +--- netutils/esp8266/esp8266.c | 71 +++++++++++++++++++++++++++++--------- 3 files changed, 57 insertions(+), 24 deletions(-) diff --git a/netutils/Makefile b/netutils/Makefile index 69c3e8df7..2bafef333 100644 --- a/netutils/Makefile +++ b/netutils/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/netutils/Makefile # -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,7 +37,7 @@ # Sub-directories -SUBDIRS = chat json codecs +SUBDIRS = chat json codecs esp8266 ifeq ($(CONFIG_NET),y) SUBDIRS += netlib dhcpc dhcpd discover ftpc ftpd smtp telnetd SUBDIRS += webclient webserver tftpc thttpd xmlrpc pppd diff --git a/netutils/esp8266/Makefile b/netutils/esp8266/Makefile index 7435c082b..7aac00a5a 100644 --- a/netutils/esp8266/Makefile +++ b/netutils/esp8266/Makefile @@ -40,11 +40,7 @@ include $(APPDIR)/Make.defs # ESP8266 Library ASRCS = -CSRCS = - -ifeq ($(CONFIG_NET_TCP),y) -CSRCS += esp8266.c -endif +CSRCS = esp8266.c AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/netutils/esp8266/esp8266.c b/netutils/esp8266/esp8266.c index 20aad0fd1..ee2b71e40 100644 --- a/netutils/esp8266/esp8266.c +++ b/netutils/esp8266/esp8266.c @@ -108,8 +108,8 @@ typedef struct { sem_t *sem; uint8_t flags; - uint16_t in; - uint16_t out; + uint16_t inndx; + uint16_t outndx; uint8_t rxbuf[SOCKET_FIFO_SIZE]; } lesp_socket_t; @@ -324,17 +324,41 @@ static inline int lesp_read_ipd(void) len -= size; pthread_mutex_lock(&g_lesp_state.mutex); - while(size --) + while (size--) { - uint8_t b = *buf++; - if (sock->in < SOCKET_FIFO_SIZE) + int next; + uint8_t b; + + /* Read the next byte from the buffer */ + + b = *buf++; + + /* Pre-calculate the next 'inndx'. We do this so that we can + * check if the FIFO is full. + */ + + next = sock->inndx + 1; + if (next >= SOCKET_FIFO_SIZE) { - int ndx = sock->in; - sock->rxbuf[ndx] = b; - sock->in = ndx + 1; + next -= SOCKET_FIFO_SIZE; + } + + /* Is there space in the circular buffer for another byte? If + * the next 'inndx' would be equal to the 'outndx', then the + * circular buffer is full. + */ + + if (next != sock->outndx) + { + /* Yes.. add the byte to the circular buffer */ + + sock->rxbuf[sock->inndx] = b; + sock->inndx = next; } else { + /* No.. the we have lost data */ + nvdbg("overflow socket 0x%02X\n", b); } } @@ -1181,9 +1205,9 @@ int lesp_closesocket(int sockfd) sockfd); memset(sock, 0, sizeof(lesp_socket_t)); - sock->flags = 0; - sock->in = 0; - sock->out = 0; + sock->flags = 0; + sock->inndx = 0; + sock->outndx = 0; } if (ret < 0) @@ -1338,7 +1362,7 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) ret = -1; } - if (ret >= 0 && sock->in == 0) + if (ret >= 0 && sock->inndx == sock->outndx) { struct timespec ts; @@ -1350,7 +1374,7 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) { ts.tv_sec += lespTIMEOUT_MS_RECV_S; sock->sem = &sem; - while (ret >= 0 && sock->in == 0) + while (ret >= 0 && sock->inndx == sock->outndx) { pthread_mutex_unlock(&g_lesp_state.mutex); ret = sem_timedwait(&sem,&ts); @@ -1364,11 +1388,24 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags) if (ret >= 0) { ret = 0; - while (ret < len && sock->out < sock->in) + while (ret < len && sock->outndx != sock->inndx) { - int ndx = sock->out; - *buf++ = sock->rxbuf[ndx]; - sock->out = ndx + 1; + /* Remove one byte from the circular buffer */ + + int ndx = sock->outndx; + *buf++ = sock->rxbuf[ndx]; + + /* Increment the circular buffer 'outndx' */ + + if (++ndx >= SOCKET_FIFO_SIZE) + { + ndx -= SOCKET_FIFO_SIZE; + } + + sock->outndx = ndx; + + /* Increment the count of bytes returned */ + ret++; } } From 1df46096ff30004c52ae2e9a6001152e8ec05390 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Wed, 25 May 2016 09:07:32 -0400 Subject: [PATCH 24/31] libuavcan: Rename uavcan to libuavcan --- canutils/Kconfig | 2 +- canutils/{uavcan => libuavcan}/.gitignore | 0 canutils/{uavcan => libuavcan}/Kconfig | 102 +++++++++--------- canutils/{uavcan => libuavcan}/Make.defs | 8 +- canutils/{uavcan => libuavcan}/Makefile | 68 ++++++------ ...96ace50155573e545ed9bf2fb09964ee2367.patch | 0 .../{uavcan => libuavcan}/platform_stm32.cpp | 23 ++-- 7 files changed, 102 insertions(+), 101 deletions(-) rename canutils/{uavcan => libuavcan}/.gitignore (100%) rename canutils/{uavcan => libuavcan}/Kconfig (69%) rename canutils/{uavcan => libuavcan}/Make.defs (90%) rename canutils/{uavcan => libuavcan}/Makefile (77%) rename canutils/{uavcan => libuavcan}/nuttx-b04396ace50155573e545ed9bf2fb09964ee2367.patch (100%) rename canutils/{uavcan => libuavcan}/platform_stm32.cpp (83%) diff --git a/canutils/Kconfig b/canutils/Kconfig index a0907602b..5fe2e45ce 100644 --- a/canutils/Kconfig +++ b/canutils/Kconfig @@ -5,7 +5,7 @@ menu "CAN Utilities" -source "$APPSDIR/canutils/uavcan/Kconfig" source "$APPSDIR/canutils/libcanard/Kconfig" +source "$APPSDIR/canutils/libuavcan/Kconfig" endmenu # CAN Utilities diff --git a/canutils/uavcan/.gitignore b/canutils/libuavcan/.gitignore similarity index 100% rename from canutils/uavcan/.gitignore rename to canutils/libuavcan/.gitignore diff --git a/canutils/uavcan/Kconfig b/canutils/libuavcan/Kconfig similarity index 69% rename from canutils/uavcan/Kconfig rename to canutils/libuavcan/Kconfig index 89e6bf60f..64d7157dd 100644 --- a/canutils/uavcan/Kconfig +++ b/canutils/libuavcan/Kconfig @@ -3,8 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -config CANUTILS_UAVCAN - bool "UAVCAN Library" +config CANUTILS_LIBUAVCAN + bool "libuavcan Library" default n depends on STM32_HAVE_CAN1 depends on !STM32_CAN1 @@ -14,47 +14,47 @@ config CANUTILS_UAVCAN depends on HAVE_CXX depends on !DISABLE_POLL ---help--- - Enables support for the UAVCAN library. + Enables support for the libuavcan library. -if CANUTILS_UAVCAN +if CANUTILS_LIBUAVCAN -config UAVCAN_LIBUAVCAN_URL - string "UAVCAN URL" +config LIBUAVCAN_URL + string "libuavcan URL" default "https://github.com/UAVCAN/libuavcan/archive" ---help--- - UAVCAN URL. + libuavcan URL. -config UAVCAN_LIBUAVCAN_VERSION - string "UAVCAN Version" +config LIBUAVCAN_VERSION + string "libuavcan Version" default "b04396ace50155573e545ed9bf2fb09964ee2367" ---help--- - UAVCAN version. + libuavcan version. -config UAVCAN_DSDL_URL +config LIBUAVCAN_DSDL_URL string "DSDL URL" default "https://github.com/UAVCAN/dsdl/archive" ---help--- DSDL URL. -config UAVCAN_DSDL_VERSION +config LIBUAVCAN_DSDL_VERSION string "DSDL Version" default "9804a3e6972825586be252ce08dd899f44994b14" ---help--- DSDL version. -config UAVCAN_PYUAVCAN_URL - string "Python UAVCAN URL" +config LIBUAVCAN_PYUAVCAN_URL + string "pyuavcan URL" default "https://github.com/UAVCAN/pyuavcan/archive" ---help--- - Python UAVCAN URL. + pyuavcan URL. -config UAVCAN_PYUAVCAN_VERSION - string "Python UAVCAN Version" +config LIBUAVCAN_PYUAVCAN_VERSION + string "pyuavcan Version" default "c58477a644d20ccf95a20c151f3a0402f271c3b8" ---help--- - Python UAVCAN version. + pyuavcan version. -config UAVCAN_STM32_NUM_IFACES +config LIBUAVCAN_STM32_NUM_IFACES int "Number of CAN Interfaces" default 1 range 1 1 if !STM32_HAVE_CAN2 @@ -62,44 +62,44 @@ config UAVCAN_STM32_NUM_IFACES choice prompt "Timer" - default UAVCAN_STM32_TIM2 if !STM32_TIM2 - default UAVCAN_STM32_TIM3 if STM32_HAVE_TIM3 && !STM32_TIM3 - default UAVCAN_STM32_TIM4 if STM32_HAVE_TIM4 && !STM32_TIM4 - default UAVCAN_STM32_TIM5 if STM32_HAVE_TIM5 && !STM32_TIM5 - default UAVCAN_STM32_TIM6 if STM32_HAVE_TIM6 && !STM32_TIM6 - default UAVCAN_STM32_TIM7 if STM32_HAVE_TIM7 && !STM32_TIM7 + default LIBUAVCAN_STM32_TIM2 if !STM32_TIM2 + default LIBUAVCAN_STM32_TIM3 if STM32_HAVE_TIM3 && !STM32_TIM3 + default LIBUAVCAN_STM32_TIM4 if STM32_HAVE_TIM4 && !STM32_TIM4 + default LIBUAVCAN_STM32_TIM5 if STM32_HAVE_TIM5 && !STM32_TIM5 + default LIBUAVCAN_STM32_TIM6 if STM32_HAVE_TIM6 && !STM32_TIM6 + default LIBUAVCAN_STM32_TIM7 if STM32_HAVE_TIM7 && !STM32_TIM7 -config UAVCAN_STM32_TIM2 +config LIBUAVCAN_STM32_TIM2 bool "TIM2" depends on !STM32_TIM2 ---help--- The library will use TIM2. -config UAVCAN_STM32_TIM3 +config LIBUAVCAN_STM32_TIM3 bool "TIM3" depends on STM32_HAVE_TIM3 && !STM32_TIM3 ---help--- The library will use TIM3. -config UAVCAN_STM32_TIM4 +config LIBUAVCAN_STM32_TIM4 bool "TIM4" depends on STM32_HAVE_TIM4 && !STM32_TIM4 ---help--- The library will use TIM4. -config UAVCAN_STM32_TIM5 +config LIBUAVCAN_STM32_TIM5 bool "TIM5" depends on STM32_HAVE_TIM5 && !STM32_TIM5 ---help--- The library will use TIM5. -config UAVCAN_STM32_TIM6 +config LIBUAVCAN_STM32_TIM6 bool "TIM6" depends on STM32_HAVE_TIM6 && !STM32_TIM6 ---help--- The library will use TIM6. -config UAVCAN_STM32_TIM7 +config LIBUAVCAN_STM32_TIM7 bool "TIM7" depends on STM32_HAVE_TIM7 && !STM32_TIM7 ---help--- @@ -109,111 +109,111 @@ endchoice choice prompt "C++ Version" - default UAVCAN_CPP03 + default LIBUAVCAN_CPP03 -config UAVCAN_CPP03 +config LIBUAVCAN_CPP03 bool "C++03" ---help--- The library will use C++03. -config UAVCAN_CPP11 +config LIBUAVCAN_CPP11 bool "C++11" ---help--- The library will use C++11. endchoice -config UAVCAN_DEBUG +config LIBUAVCAN_DEBUG bool "Debug" default n ---help--- Enables debug. -config UAVCAN_EXCEPTIONS +config LIBUAVCAN_EXCEPTIONS bool "Exceptions" default n ---help--- Enables exceptions. -config UAVCAN_TINY +config LIBUAVCAN_TINY bool "Tiny" default n ---help--- Removes some features to save memory. -config UAVCAN_NO_GLOBAL_DATA_TYPE_REGISTRY +config LIBUAVCAN_NO_GLOBAL_DATA_TYPE_REGISTRY bool "No Global Data Type Registry" default n ---help--- Removes the global data type registry. -config UAVCAN_TOSTRING +config LIBUAVCAN_TOSTRING bool "Implement toString" default n - depends on UAVCAN_EXCEPTIONS + depends on LIBUAVCAN_EXCEPTIONS ---help--- The library will add a toString method to most of its classes. -config UAVCAN_IMPLEMENT_PLACEMENT_NEW +config LIBUAVCAN_IMPLEMENT_PLACEMENT_NEW bool "Implement Placement new" default n ---help--- The library will implement placement new. -config UAVCAN_USE_EXTERNAL_SNPRINTF +config LIBUAVCAN_USE_EXTERNAL_SNPRINTF bool "Use External snprintf" default n ---help--- The library will use an external snprintf. -config UAVCAN_USE_EXTERNAL_FLOAT16_CONVERSION +config LIBUAVCAN_USE_EXTERNAL_FLOAT16_CONVERSION bool "Use External float16 Conversion" default n ---help--- The library will use an external float16 conversion. -config UAVCAN_NO_ASSERTIONS +config LIBUAVCAN_NO_ASSERTIONS bool "No Assertions" default n ---help--- Disables assertions. -config UAVCAN_MEM_POOL_BLOCK_SIZE +config LIBUAVCAN_MEM_POOL_BLOCK_SIZE int "Memory Pool Block Size" default 0 ---help--- Specifies the memory pool block size. If the value is 0, the library will use a default value. -config UAVCAN_FLOAT_COMPARISON_EPSILON_MULT +config LIBUAVCAN_FLOAT_COMPARISON_EPSILON_MULT int "Float Comparion Epsilon Mult" default 0 ---help--- Specifies the float comparison epsilon mult. If the value is 0, the library will use a default value. -config UAVCAN_MAX_CAN_ACCEPTANCE_FILTERS +config LIBUAVCAN_MAX_CAN_ACCEPTANCE_FILTERS int "Max CAN Acceptance Filters" default 0 ---help--- Specifies the maximum number of CAN acceptance filters. If the value is 0, the library will use a default value. -config UAVCAN_MAX_NETWORK_SIZE_HINT +config LIBUAVCAN_MAX_NETWORK_SIZE_HINT int "Max Network Size Hint" default 0 ---help--- Specifies the maximum network size. If the value is 0, the library will use a default value. -config UAVCAN_RX_QUEUE_CAPACITY +config LIBUAVCAN_RX_QUEUE_CAPACITY int "Rx Queue Capacity" default 0 ---help--- Specifies the rx queue capacity. If the value is 0, the library will use a default value. -config UAVCAN_BIT_RATE +config LIBUAVCAN_BIT_RATE int "Bit Rate" default 0 range 0 1000000 @@ -221,7 +221,7 @@ config UAVCAN_BIT_RATE Specifies the CAN bit rate. If the value is 0, the library will automatically detect the bit rate. -config UAVCAN_INIT_RETRIES +config LIBUAVCAN_INIT_RETRIES int "Initialization Retries" default 0 ---help--- diff --git a/canutils/uavcan/Make.defs b/canutils/libuavcan/Make.defs similarity index 90% rename from canutils/uavcan/Make.defs rename to canutils/libuavcan/Make.defs index fa3c9c602..de45b2130 100644 --- a/canutils/uavcan/Make.defs +++ b/canutils/libuavcan/Make.defs @@ -1,7 +1,7 @@ ############################################################################ -# apps/canutils/uavcan/Make.defs +# apps/canutils/libuavcan/Make.defs # -# Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. +# Copyright (C) 2015-2016 Omni Hoverboards Inc. All rights reserved. # Author: Paul Alexander Patience # # Redistribution and use in source and binary forms, with or without @@ -33,6 +33,6 @@ # ############################################################################ -ifeq ($(CONFIG_CANUTILS_UAVCAN),y) -CONFIGURED_APPS += canutils/uavcan +ifeq ($(CONFIG_CANUTILS_LIBUAVCAN),y) +CONFIGURED_APPS += canutils/libuavcan endif diff --git a/canutils/uavcan/Makefile b/canutils/libuavcan/Makefile similarity index 77% rename from canutils/uavcan/Makefile rename to canutils/libuavcan/Makefile index decf9e117..c4752e69b 100644 --- a/canutils/uavcan/Makefile +++ b/canutils/libuavcan/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# apps/canutils/uavcan/Makefile +# apps/canutils/libuavcan/Makefile # # Copyright (C) 2015-2016 Omni Hoverboards Inc. All rights reserved. # Author: Paul Alexander Patience @@ -41,21 +41,21 @@ WGET = wget UNPACK = unzip PACKEXT = .zip -LIBUAVCAN_URL = $(patsubst "%",%,$(strip $(CONFIG_UAVCAN_LIBUAVCAN_URL))) -LIBUAVCAN_VERSION = $(patsubst "%",%,$(strip $(CONFIG_UAVCAN_LIBUAVCAN_VERSION))) +LIBUAVCAN_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBUAVCAN_URL))) +LIBUAVCAN_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBUAVCAN_VERSION))) LIBUAVCAN_UNPACKNAME = libuavcan-$(LIBUAVCAN_VERSION) LIBUAVCAN_PACKNAME = $(LIBUAVCAN_UNPACKNAME)$(PACKEXT) LIBUAVCAN_DSDL_PATH = libuavcan$(DELIM)dsdl LIBUAVCAN_PYUAVCAN_PATH = libuavcan$(DELIM)libuavcan$(DELIM)dsdl_compiler$(DELIM)pyuavcan LIBUAVCAN_PATCHNAME = nuttx-$(LIBUAVCAN_VERSION).patch -DSDL_URL = $(patsubst "%",%,$(strip $(CONFIG_UAVCAN_DSDL_URL))) -DSDL_VERSION = $(patsubst "%",%,$(strip $(CONFIG_UAVCAN_DSDL_VERSION))) +DSDL_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBUAVCAN_DSDL_URL))) +DSDL_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBUAVCAN_DSDL_VERSION))) DSDL_UNPACKNAME = dsdl-$(DSDL_VERSION) DSDL_PACKNAME = $(DSDL_UNPACKNAME)$(PACKEXT) -PYUAVCAN_URL = $(patsubst "%",%,$(strip $(CONFIG_UAVCAN_PYUAVCAN_URL))) -PYUAVCAN_VERSION = $(patsubst "%",%,$(strip $(CONFIG_UAVCAN_PYUAVCAN_VERSION))) +PYUAVCAN_URL = $(patsubst "%",%,$(strip $(CONFIG_LIBUAVCAN_PYUAVCAN_URL))) +PYUAVCAN_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LIBUAVCAN_PYUAVCAN_VERSION))) PYUAVCAN_UNPACKNAME = pyuavcan-$(PYUAVCAN_VERSION) PYUAVCAN_PACKNAME = $(PYUAVCAN_UNPACKNAME)$(PACKEXT) @@ -70,24 +70,24 @@ CXXFLAGS += -I$(TOPDIR)$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)stm32 CXXFLAGS += -D__KERNEL__ CXXFLAGS += -DUAVCAN_STM32_NUTTX=1 -CXXFLAGS += -DUAVCAN_STM32_NUM_IFACES=$(CONFIG_UAVCAN_STM32_NUM_IFACES) +CXXFLAGS += -DUAVCAN_STM32_NUM_IFACES=$(CONFIG_LIBUAVCAN_STM32_NUM_IFACES) -ifeq ($(CONFIG_UAVCAN_STM32_TIM2),y) +ifeq ($(CONFIG_LIBUAVCAN_STM32_TIM2),y) CXXFLAGS += -DUAVCAN_STM32_TIMER_NUMBER=2 else -ifeq ($(CONFIG_UAVCAN_STM32_TIM3),y) +ifeq ($(CONFIG_LIBUAVCAN_STM32_TIM3),y) CXXFLAGS += -DUAVCAN_STM32_TIMER_NUMBER=3 else -ifeq ($(CONFIG_UAVCAN_STM32_TIM4),y) +ifeq ($(CONFIG_LIBUAVCAN_STM32_TIM4),y) CXXFLAGS += -DUAVCAN_STM32_TIMER_NUMBER=4 else -ifeq ($(CONFIG_UAVCAN_STM32_TIM5),y) +ifeq ($(CONFIG_LIBUAVCAN_STM32_TIM5),y) CXXFLAGS += -DUAVCAN_STM32_TIMER_NUMBER=5 else -ifeq ($(CONFIG_UAVCAN_STM32_TIM6),y) +ifeq ($(CONFIG_LIBUAVCAN_STM32_TIM6),y) CXXFLAGS += -DUAVCAN_STM32_TIMER_NUMBER=6 else -ifeq ($(CONFIG_UAVCAN_STM32_TIM7),y) +ifeq ($(CONFIG_LIBUAVCAN_STM32_TIM7),y) CXXFLAGS += -DUAVCAN_STM32_TIMER_NUMBER=7 endif endif @@ -96,68 +96,68 @@ endif endif endif -ifeq ($(CONFIG_UAVCAN_CPP03),y) +ifeq ($(CONFIG_LIBUAVCAN_CPP03),y) CXXFLAGS += -std=c++03 -DUAVCAN_CPP_VERSION=UAVCAN_CPP03 else -ifeq ($(CONFIG_UAVCAN_CPP11),y) +ifeq ($(CONFIG_LIBUAVCAN_CPP11),y) CXXFLAGS += -std=c++11 -DUAVCAN_CPP_VERSION=UAVCAN_CPP11 endif endif -ifeq ($(CONFIG_UAVCAN_DEBUG),y) +ifeq ($(CONFIG_LIBUAVCAN_DEBUG),y) CXXFLAGS += -DUAVCAN_DEBUG=1 endif -ifeq ($(CONFIG_UAVCAN_EXCEPTIONS),y) +ifeq ($(CONFIG_LIBUAVCAN_EXCEPTIONS),y) CXXFLAGS += -DUAVCAN_EXCEPTIONS=1 else CXXFLAGS += -DUAVCAN_EXCEPTIONS=0 endif -ifeq ($(CONFIG_UAVCAN_TINY),y) +ifeq ($(CONFIG_LIBUAVCAN_TINY),y) CXXFLAGS += -DUAVCAN_TINY=1 endif -ifeq ($(CONFIG_UAVCAN_NO_GLOBAL_DATA_TYPE_REGISTRY),y) +ifeq ($(CONFIG_LIBUAVCAN_NO_GLOBAL_DATA_TYPE_REGISTRY),y) CXXFLAGS += -DUAVCAN_NO_GLOBAL_DATA_TYPE_REGISTRY=1 endif -ifeq ($(CONFIG_UAVCAN_TOSTRING),y) +ifeq ($(CONFIG_LIBUAVCAN_TOSTRING),y) CXXFLAGS += -DUAVCAN_TOSTRING=1 else CXXFLAGS += -DUAVCAN_TOSTRING=0 endif -ifeq ($(CONFIG_UAVCAN_IMPLEMENT_PLACEMENT_NEW),y) +ifeq ($(CONFIG_LIBUAVCAN_IMPLEMENT_PLACEMENT_NEW),y) CXXFLAGS += -DUAVCAN_IMPLEMENT_PLACEMENT_NEW=1 endif -ifeq ($(CONFIG_UAVCAN_USE_EXTERNAL_SNPRINTF),y) +ifeq ($(CONFIG_LIBUAVCAN_USE_EXTERNAL_SNPRINTF),y) CXXFLAGS += -DUAVCAN_USE_EXTERNAL_SNPRINTF=1 endif -ifeq ($(CONFIG_UAVCAN_USE_EXTERNAL_FLOAT16_CONVERSION),y) +ifeq ($(CONFIG_LIBUAVCAN_USE_EXTERNAL_FLOAT16_CONVERSION),y) CXXFLAGS += -DUAVCAN_USE_EXTERNAL_FLOAT16_CONVERSION=1 endif -ifeq ($(CONFIG_UAVCAN_NO_ASSERTIONS),y) +ifeq ($(CONFIG_LIBUAVCAN_NO_ASSERTIONS),y) CXXFLAGS += -DUAVCAN_NO_ASSERTIONS=1 endif -ifneq ($(CONFIG_UAVCAN_MEM_POOL_BLOCK_SIZE),0) -CXXFLAGS += -DUAVCAN_MEM_POOL_BLOCK_SIZE=$(CONFIG_UAVCAN_MEM_POOL_BLOCK_SIZE) +ifneq ($(CONFIG_LIBUAVCAN_MEM_POOL_BLOCK_SIZE),0) +CXXFLAGS += -DUAVCAN_MEM_POOL_BLOCK_SIZE=$(CONFIG_LIBUAVCAN_MEM_POOL_BLOCK_SIZE) endif -ifneq ($(CONFIG_UAVCAN_FLOAT_COMPARISON_EPSILON_MULT),0) -CXXFLAGS += -DUAVCAN_FLOAT_COMPARISON_EPSILON_MULT=$(CONFIG_UAVCAN_FLOAT_COMPARISON_EPSILON_MULT) +ifneq ($(CONFIG_LIBUAVCAN_FLOAT_COMPARISON_EPSILON_MULT),0) +CXXFLAGS += -DUAVCAN_FLOAT_COMPARISON_EPSILON_MULT=$(CONFIG_LIBUAVCAN_FLOAT_COMPARISON_EPSILON_MULT) endif -ifneq ($(CONFIG_UAVCAN_MAX_CAN_ACCEPTANCE_FILTERS),0) -CXXFLAGS += -DUAVCAN_MAX_CAN_ACCEPTANCE_FILTERS=$(CONFIG_UAVCAN_MAX_CAN_ACCEPTANCE_FILTERS) +ifneq ($(CONFIG_LIBUAVCAN_MAX_CAN_ACCEPTANCE_FILTERS),0) +CXXFLAGS += -DUAVCAN_MAX_CAN_ACCEPTANCE_FILTERS=$(CONFIG_LIBUAVCAN_MAX_CAN_ACCEPTANCE_FILTERS) endif -ifneq ($(CONFIG_UAVCAN_MAX_NETWORK_SIZE_HINT),0) -CXXFLAGS += -DUAVCAN_MAX_NETWORK_SIZE_HINT=$(CONFIG_UAVCAN_MAX_NETWORK_SIZE_HINT) +ifneq ($(CONFIG_LIBUAVCAN_MAX_NETWORK_SIZE_HINT),0) +CXXFLAGS += -DUAVCAN_MAX_NETWORK_SIZE_HINT=$(CONFIG_LIBUAVCAN_MAX_NETWORK_SIZE_HINT) endif CXXEXT = .cpp @@ -212,6 +212,7 @@ libuavcan: $(LIBUAVCAN_UNPACKNAME) $(DSDL_UNPACKNAME) $(PYUAVCAN_UNPACKNAME) $(Q) cp -R $(DSDL_UNPACKNAME) $(LIBUAVCAN_DSDL_PATH) $(call DELDIR, $(LIBUAVCAN_PYUAVCAN_PATH)) $(Q) cp -R $(PYUAVCAN_UNPACKNAME) $(LIBUAVCAN_PYUAVCAN_PATH) + $(Q) touch $@ dsdlc_generated: libuavcan $(info $(shell $(LIBUAVCAN_DSDLC) $(UAVCAN_DSDL_DIR))) @@ -248,7 +249,6 @@ clean: distclean: clean $(call DELFILE, Make.dep) $(call DELFILE, .depend) - $(call DELFILE, .libuavcan_patched) $(call DELDIR, $(LIBUAVCAN_UNPACKNAME)) $(call DELFILE, $(LIBUAVCAN_PACKNAME)) $(call DELDIR, $(DSDL_UNPACKNAME)) diff --git a/canutils/uavcan/nuttx-b04396ace50155573e545ed9bf2fb09964ee2367.patch b/canutils/libuavcan/nuttx-b04396ace50155573e545ed9bf2fb09964ee2367.patch similarity index 100% rename from canutils/uavcan/nuttx-b04396ace50155573e545ed9bf2fb09964ee2367.patch rename to canutils/libuavcan/nuttx-b04396ace50155573e545ed9bf2fb09964ee2367.patch diff --git a/canutils/uavcan/platform_stm32.cpp b/canutils/libuavcan/platform_stm32.cpp similarity index 83% rename from canutils/uavcan/platform_stm32.cpp rename to canutils/libuavcan/platform_stm32.cpp index 026bbafc2..e1adeddf0 100644 --- a/canutils/uavcan/platform_stm32.cpp +++ b/canutils/libuavcan/platform_stm32.cpp @@ -1,7 +1,7 @@ /**************************************************************************** - * canutils/uavcan/uavcan_platform.cpp + * canutils/libuavcan/platform_stm32.cpp * - * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Copyright (C) 2015-2016 Omni Hoverboards Inc. All rights reserved. * Author: Paul Alexander Patience * * Redistribution and use in source and binary forms, with or without @@ -47,9 +47,9 @@ * Configuration ****************************************************************************/ -#if CONFIG_UAVCAN_RX_QUEUE_CAPACITY == 0 -# undef CONFIG_UAVCAN_RX_QUEUE_CAPACITY -# define CONFIG_UAVCAN_RX_QUEUE_CAPACITY +#if CONFIG_LIBUAVCAN_RX_QUEUE_CAPACITY == 0 +# undef CONFIG_LIBUAVCAN_RX_QUEUE_CAPACITY +# define CONFIG_LIBUAVCAN_RX_QUEUE_CAPACITY #endif /**************************************************************************** @@ -58,7 +58,8 @@ static void delay(void) { - std::usleep(uavcan_stm32::CanInitHelper:: + std::usleep(uavcan_stm32:: + CanInitHelper:: getRecommendedListeningDelay().toUSec()); } @@ -68,22 +69,22 @@ static void delay(void) uavcan::ICanDriver &getCanDriver(void) { - static uavcan_stm32::CanInitHelper can; + static uavcan_stm32::CanInitHelper can; static bool initialized = false; if (!initialized) { - uavcan::uint32_t bitrate = CONFIG_UAVCAN_BIT_RATE; + uavcan::uint32_t bitrate = CONFIG_LIBUAVCAN_BIT_RATE; -#if CONFIG_UAVCAN_INIT_RETRIES > 0 +#if CONFIG_LIBUAVCAN_INIT_RETRIES > 0 int retries = 0; #endif while (can.init(delay, bitrate) < 0) { -#if CONFIG_UAVCAN_INIT_RETRIES > 0 +#if CONFIG_LIBUAVCAN_INIT_RETRIES > 0 retries++; - if (retries >= CONFIG_UAVCAN_INIT_RETRIES) + if (retries >= CONFIG_LIBUAVCAN_INIT_RETRIES) { PANIC(); } From b2f8a0f0479709daa9c84ad86ce52cdf8d618045 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Wed, 25 May 2016 09:35:28 -0400 Subject: [PATCH 25/31] examples/uavcan: Update configuration --- examples/uavcan/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/uavcan/Kconfig b/examples/uavcan/Kconfig index 6d47c3b57..a8b980fb5 100644 --- a/examples/uavcan/Kconfig +++ b/examples/uavcan/Kconfig @@ -6,7 +6,7 @@ config EXAMPLES_UAVCAN bool "UAVCAN example" default n - depends on CANUTILS_UAVCAN + depends on CANUTILS_LIBUAVCAN ---help--- Enable the UAVCAN example From 6a0bb1374a32c7c0f1f402b24f17c652548ba5c5 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Wed, 25 May 2016 09:44:06 -0400 Subject: [PATCH 26/31] libuavcan: Delete libuavcan directory on distclean --- canutils/libuavcan/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/canutils/libuavcan/Makefile b/canutils/libuavcan/Makefile index c4752e69b..5e13e7244 100644 --- a/canutils/libuavcan/Makefile +++ b/canutils/libuavcan/Makefile @@ -249,6 +249,7 @@ clean: distclean: clean $(call DELFILE, Make.dep) $(call DELFILE, .depend) + $(call DELDIR, libuavcan) $(call DELDIR, $(LIBUAVCAN_UNPACKNAME)) $(call DELFILE, $(LIBUAVCAN_PACKNAME)) $(call DELDIR, $(DSDL_UNPACKNAME)) From ff8f175cd235c21e559fa7154fca02a45b0a69a6 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Wed, 25 May 2016 09:58:43 -0400 Subject: [PATCH 27/31] libuavcan: Delete directories before unpacking --- canutils/libuavcan/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/canutils/libuavcan/Makefile b/canutils/libuavcan/Makefile index 5e13e7244..05fc45f61 100644 --- a/canutils/libuavcan/Makefile +++ b/canutils/libuavcan/Makefile @@ -182,6 +182,7 @@ $(LIBUAVCAN_PACKNAME): $(LIBUAVCAN_UNPACKNAME): $(LIBUAVCAN_PACKNAME) @echo "Unpacking: $< -> $@" + $(call DELDIR, $@) $(Q) $(UNPACK) $< $(Q) touch $@ @@ -191,6 +192,7 @@ $(DSDL_PACKNAME): $(DSDL_UNPACKNAME): $(DSDL_PACKNAME) @echo "Unpacking: $< -> $@" + $(call DELDIR, $@) $(Q) $(UNPACK) $< $(Q) touch $@ @@ -200,11 +202,13 @@ $(PYUAVCAN_PACKNAME): $(PYUAVCAN_UNPACKNAME): $(PYUAVCAN_PACKNAME) @echo "Unpacking: $< -> $@" + $(call DELDIR, $@) $(Q) $(UNPACK) $< $(Q) touch $@ libuavcan: $(LIBUAVCAN_UNPACKNAME) $(DSDL_UNPACKNAME) $(PYUAVCAN_UNPACKNAME) - $(Q) cp -R $(LIBUAVCAN_UNPACKNAME) libuavcan + $(call DELDIR, $@) + $(Q) cp -R $(LIBUAVCAN_UNPACKNAME) $@ $(Q) if [ -r $(LIBUAVCAN_PATCHNAME) ]; then \ cat $(LIBUAVCAN_PATCHNAME) | patch -p0 || { echo "ERROR: Patch failed"; exit 1; }; \ fi From a25bbaf8f9242c1be32073b84a22c48ddc0a43d1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 May 2016 14:07:35 -0600 Subject: [PATCH 28/31] No newline at end of file --- ChangeLog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 966b07fde..cf8d02332 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1598,4 +1598,4 @@ * apps/platform/nucleo-144: Add platform files for NUCLEO-144 (NUCLEO-F746ZG). From Mark Olsson (2016-05-19). * apps/netutils/esp8266: ESP8266 driver application. From Pierre-noel - Bouteville (2016-05-21). \ No newline at end of file + Bouteville (2016-05-21). From ee3f0fffe425f15185663531a53494dcdb300f88 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 May 2016 14:20:17 -0600 Subject: [PATCH 29/31] netutils: Fix error in build system recently introduced --- netutils/Make.defs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netutils/Make.defs b/netutils/Make.defs index f4a36dcf7..f3897a4eb 100644 --- a/netutils/Make.defs +++ b/netutils/Make.defs @@ -50,8 +50,8 @@ ifeq ($(CONFIG_NETUTILS_ESP8266),y) CONFIGURED_APPS += netutils/esp8266 endif -ifeq ($(CONFIG_NETUTILS_FTPC),y) -CONFIGURED_APPS += netutils/ftpc +ifeq ($(CONFIG_NETUTILS_DHCPD),y) +CONFIGURED_APPS += netutils/dhcpd endif ifeq ($(CONFIG_NETUTILS_FTPC),y) From 2e882c728980b0fb1b83c725277da7fd80359675 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 25 May 2016 14:21:37 -0600 Subject: [PATCH 30/31] Lets use alphabetical ordering in last change --- netutils/Make.defs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netutils/Make.defs b/netutils/Make.defs index f3897a4eb..d03af9969 100644 --- a/netutils/Make.defs +++ b/netutils/Make.defs @@ -46,14 +46,14 @@ ifeq ($(CONFIG_NETUTILS_DHCPC),y) CONFIGURED_APPS += netutils/dhcpc endif -ifeq ($(CONFIG_NETUTILS_ESP8266),y) -CONFIGURED_APPS += netutils/esp8266 -endif - ifeq ($(CONFIG_NETUTILS_DHCPD),y) CONFIGURED_APPS += netutils/dhcpd endif +ifeq ($(CONFIG_NETUTILS_ESP8266),y) +CONFIGURED_APPS += netutils/esp8266 +endif + ifeq ($(CONFIG_NETUTILS_FTPC),y) CONFIGURED_APPS += netutils/ftpc endif From 8bdf3e1f25bcf8fcced6f8cacf7992f48d9b4289 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Mon, 30 May 2016 10:14:23 -0400 Subject: [PATCH 31/31] zmodem: Add missing slash --- system/zmodem/host/nuttx/ascii.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/zmodem/host/nuttx/ascii.h b/system/zmodem/host/nuttx/ascii.h index 6c11ba8e0..67a6d088c 100644 --- a/system/zmodem/host/nuttx/ascii.h +++ b/system/zmodem/host/nuttx/ascii.h @@ -1,4 +1,4 @@ -**************************************************************************** +/**************************************************************************** * apps/system/zmodem/host/ascii.h * ASCII Control Codes *