From db436d91aeeb2679f1eb0602915b602b160470ce Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 27 Jun 2016 17:19:37 -0700 Subject: [PATCH] Unify example apps across all example platforms. (#215) --- .travis/script.sh | 6 +- README.md | 4 +- configure.ac | 17 ++-- examples/{cc2538 => }/Makefile-cc2538 | 9 +- .../Makefile-posix | 12 ++- examples/Makefile.am | 19 ++-- examples/{cc2538/app => apps}/Makefile.am | 0 examples/{cc2538/app => apps}/cli/Makefile.am | 36 ++++--- examples/{posix/app => apps}/cli/README.md | 5 +- examples/{cc2538/app => apps}/cli/main.c | 4 +- examples/{posix/app => apps}/ncp/Makefile.am | 37 ++++--- examples/{cc2538/app => apps}/ncp/main.c | 4 +- examples/cc2538/.default-version | 1 - examples/cc2538/Makefile.am | 57 ----------- examples/cc2538/app/cli/README.md | 73 -------------- examples/cc2538/app/ncp/Makefile.am | 55 ----------- examples/cc2538/platform/platform.h | 96 ------------------- examples/{posix/app => platforms}/Makefile.am | 27 +++--- .../platform => platforms/cc2538}/Makefile.am | 7 +- examples/{ => platforms}/cc2538/README.md | 13 +-- .../platform => platforms/cc2538}/alarm.c | 2 +- .../cc2538}/cc2538-reg.h | 0 .../platform => platforms/cc2538}/cc2538.ld | 0 .../platform => platforms/cc2538}/logging.c | 0 examples/platforms/cc2538/platform-cc2538.h | 78 +++++++++++++++ .../platform => platforms/cc2538}/platform.c | 16 ++-- .../platform => platforms/cc2538}/radio.c | 2 +- .../platform => platforms/cc2538}/random.c | 2 +- .../platform => platforms/cc2538}/serial.c | 2 +- .../cc2538}/startup-gcc.c | 0 .../posix-platform.c => platforms/platform.h} | 18 +++- .../platform => platforms/posix}/Makefile.am | 11 +-- examples/platforms/posix/README.md | 57 +++++++++++ .../platform => platforms/posix}/alarm.c | 8 +- .../platform => platforms/posix}/logging.c | 0 .../posix/platform-posix.h} | 62 ++++-------- .../platform => platforms/posix}/platform.c | 32 ++++--- .../platform => platforms/posix}/radio.c | 8 +- .../platform => platforms/posix}/random.c | 4 +- .../platform => platforms/posix}/serial.c | 6 +- examples/posix/Makefile.am | 52 ---------- examples/posix/app/cli/Makefile.am | 52 ---------- examples/posix/app/cli/main.c | 59 ------------ examples/posix/app/ncp/main.c | 59 ------------ tests/scripts/thread-cert/node.py | 2 +- tests/unit/Makefile.am | 54 +++++------ 46 files changed, 350 insertions(+), 718 deletions(-) rename examples/{cc2538 => }/Makefile-cc2538 (98%) rename Makefile-Standalone => examples/Makefile-posix (94%) rename examples/{cc2538/app => apps}/Makefile.am (100%) rename examples/{cc2538/app => apps}/cli/Makefile.am (78%) rename examples/{posix/app => apps}/cli/README.md (95%) rename examples/{cc2538/app => apps}/cli/main.c (97%) rename examples/{posix/app => apps}/ncp/Makefile.am (80%) rename examples/{cc2538/app => apps}/ncp/main.c (97%) delete mode 100644 examples/cc2538/.default-version delete mode 100644 examples/cc2538/Makefile.am delete mode 100644 examples/cc2538/app/cli/README.md delete mode 100644 examples/cc2538/app/ncp/Makefile.am delete mode 100644 examples/cc2538/platform/platform.h rename examples/{posix/app => platforms}/Makefile.am (82%) rename examples/{cc2538/platform => platforms/cc2538}/Makefile.am (93%) rename examples/{ => platforms}/cc2538/README.md (80%) rename examples/{cc2538/platform => platforms/cc2538}/alarm.c (99%) rename examples/{cc2538/platform => platforms/cc2538}/cc2538-reg.h (100%) rename examples/{cc2538/platform => platforms/cc2538}/cc2538.ld (100%) rename examples/{cc2538/platform => platforms/cc2538}/logging.c (100%) create mode 100644 examples/platforms/cc2538/platform-cc2538.h rename examples/{cc2538/platform => platforms/cc2538}/platform.c (89%) rename examples/{cc2538/platform => platforms/cc2538}/radio.c (99%) rename examples/{cc2538/platform => platforms/cc2538}/random.c (98%) rename examples/{cc2538/platform => platforms/cc2538}/serial.c (99%) rename examples/{cc2538/platform => platforms/cc2538}/startup-gcc.c (100%) rename examples/{posix/platform/posix-platform.c => platforms/platform.h} (82%) rename examples/{posix/platform => platforms/posix}/Makefile.am (87%) create mode 100644 examples/platforms/posix/README.md rename examples/{posix/platform => platforms/posix}/alarm.c (94%) rename examples/{posix/platform => platforms/posix}/logging.c (100%) rename examples/{posix/platform/posix-platform.h => platforms/posix/platform-posix.h} (63%) rename examples/{posix/platform => platforms/posix}/platform.c (81%) rename examples/{posix/platform => platforms/posix}/radio.c (98%) rename examples/{posix/platform => platforms/posix}/random.c (97%) rename examples/{posix/platform => platforms/posix}/serial.c (97%) delete mode 100644 examples/posix/Makefile.am delete mode 100644 examples/posix/app/cli/Makefile.am delete mode 100644 examples/posix/app/cli/main.c delete mode 100644 examples/posix/app/ncp/main.c diff --git a/.travis/script.sh b/.travis/script.sh index c2d7ae31d..f8caf4468 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -43,16 +43,16 @@ set -x } [ $BUILD_TARGET != posix ] || { - make -f Makefile-Standalone distcheck || die + make -f examples/Makefile-posix distcheck || die } [ $BUILD_TARGET != posix-32-bit ] || { - CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 make -f Makefile-Standalone distcheck || die + CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 make -f examples/Makefile-posix distcheck || die } [ $BUILD_TARGET != cc2538 ] || { export PATH=/tmp/gcc-arm-none-eabi-4_9-2015q3/bin:$PATH || die - make -f examples/cc2538/Makefile-cc2538 || die + make -f examples/Makefile-cc2538 || die } [ $BUILD_TARGET != scan-build ] || { diff --git a/README.md b/README.md index db5120451..aac79f6f7 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ contributing to the ongoing development of OpenThread. # Getting started # The easiest way to get started is to run the CLI example in -`/examples/posix/app/cli`. See the -[CLI example README](examples/posix/app/cli/README.md) +`/examples/apps/cli`. See the +[CLI example README](examples/apps/cli/README.md) for more details. diff --git a/configure.ac b/configure.ac index 5d5575d87..6de3dd913 100644 --- a/configure.ac +++ b/configure.ac @@ -412,6 +412,7 @@ esac AC_MSG_RESULT(${OPENTHREAD_EXAMPLES}) AC_SUBST(OPENTHREAD_EXAMPLES) +AM_CONDITIONAL([OPENTHREAD_EXAMPLES], [test ${with_examples} != "none"]) AC_DEFINE_UNQUOTED([OPENTHREAD_EXAMPLES],[${OPENTHREAD_EXAMPLES}],[OpenThread examples]) AC_SUBST(OPENTHREAD_EXAMPLES_POSIX) @@ -527,16 +528,12 @@ src/core/Makefile third_party/Makefile third_party/mbedtls/Makefile examples/Makefile -examples/posix/Makefile -examples/posix/app/Makefile -examples/posix/app/cli/Makefile -examples/posix/app/ncp/Makefile -examples/posix/platform/Makefile -examples/cc2538/Makefile -examples/cc2538/app/Makefile -examples/cc2538/app/cli/Makefile -examples/cc2538/app/ncp/Makefile -examples/cc2538/platform/Makefile +examples/apps/Makefile +examples/apps/cli/Makefile +examples/apps/ncp/Makefile +examples/platforms/Makefile +examples/platforms/cc2538/Makefile +examples/platforms/posix/Makefile tests/Makefile tests/scripts/Makefile tests/unit/Makefile diff --git a/examples/cc2538/Makefile-cc2538 b/examples/Makefile-cc2538 similarity index 98% rename from examples/cc2538/Makefile-cc2538 rename to examples/Makefile-cc2538 index 3e58376e9..bf644f1fa 100644 --- a/examples/cc2538/Makefile-cc2538 +++ b/examples/Makefile-cc2538 @@ -79,9 +79,6 @@ LDFLAGS = \ -Wl,-Map=map.map \ $(NULL) -LIBS = \ - $(NULL) - ECHO := @echo MAKE := make MKDIR_P := mkdir -p @@ -91,8 +88,8 @@ RM_F := rm -f INSTALL := /usr/bin/install INSTALLFLAGS := -p -TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST))))../../ -AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))../../ +TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. +AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))).. BuildPath = build TopBuildDir = $(BuildPath) @@ -119,7 +116,7 @@ define configure-arch $(ECHO) " CONFIG $(1)-$(TargetTuple)..." (cd $(BuildPath)/$(1)-$(TargetTuple) && $(AbsTopSourceDir)/configure \ INSTALL="$(INSTALL) $(INSTALLFLAGS)" \ -CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)" OBJC="$(OBJC)" OBJCXX="$(OBJCXX)" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" STRIP="$(STRIP)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" \ +CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)" OBJC="$(OBJC)" OBJCXX="$(OBJCXX)" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" STRIP="$(STRIP)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \ --host=arm-none-eabi \ --target=arm-none-eabi \ --prefix=/ \ diff --git a/Makefile-Standalone b/examples/Makefile-posix similarity index 94% rename from Makefile-Standalone rename to examples/Makefile-posix index 658bd831c..fe1a33827 100644 --- a/Makefile-Standalone +++ b/examples/Makefile-posix @@ -42,8 +42,8 @@ RM_F := rm -f INSTALL := /usr/bin/install INSTALLFLAGS := -p -TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))) -AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. +AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))).. BuildPath = build TopBuildDir = $(BuildPath) @@ -53,15 +53,17 @@ ResultPath = output TopResultDir = $(ResultPath) AbsTopResultDir = $(PWD)/$(TopResultDir) -TargetTuple = $(shell ${AbsTopSourceDir}/build/nlbuild-autotools/repo/autoconf/config.guess | sed -e 's/[[:digit:].]*$$//g') +TargetTuple = $(shell ${AbsTopSourceDir}/third_party/nlbuild-autotools/repo/autoconf/config.guess | sed -e 's/[[:digit:].]*$$//g') # If the user has asserted COVERAGE, alter the configuration options # accordingly. +configure_OPTIONS = --with-examples=posix --enable-cli --enable-ncp + ifeq ($(COVERAGE),1) -configure_OPTIONS = --enable-coverage +configure_OPTIONS += --enable-coverage else -configure_OPTIONS = +configure_OPTIONS += endif # If the user has asserted DEBUG, alter the configuration options diff --git a/examples/Makefile.am b/examples/Makefile.am index c715ffa3b..99a9764a5 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -31,25 +31,24 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am # Always package (e.g. for 'make dist') these subdirectories. DIST_SUBDIRS = \ - posix \ - cc2538 \ + platforms \ + apps \ $(NULL) # Always build (e.g. for 'make all') these subdirectories. -if OPENTHREAD_EXAMPLES_POSIX -SUBDIRS = posix -endif - -if OPENTHREAD_EXAMPLES_CC2538 -SUBDIRS = cc2538 +if OPENTHREAD_EXAMPLES +SUBDIRS = \ + platforms \ + apps \ + $(NULL) endif # Always pretty (e.g. for 'make pretty') these subdirectories. PRETTY_SUBDIRS = \ - posix \ - cc2538 \ + platforms \ + apps \ $(NULL) include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/cc2538/app/Makefile.am b/examples/apps/Makefile.am similarity index 100% rename from examples/cc2538/app/Makefile.am rename to examples/apps/Makefile.am diff --git a/examples/cc2538/app/cli/Makefile.am b/examples/apps/cli/Makefile.am similarity index 78% rename from examples/cc2538/app/cli/Makefile.am rename to examples/apps/cli/Makefile.am index 561a5695c..edf8d00e6 100644 --- a/examples/cc2538/app/cli/Makefile.am +++ b/examples/apps/cli/Makefile.am @@ -28,28 +28,36 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am -bin_PROGRAMS = \ - ot-cli \ +bin_PROGRAMS = \ + ot-cli \ $(NULL) -ot_cli_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/examples/cc2538/platform \ +ot_cli_CPPFLAGS = \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/examples/platforms \ $(NULL) -ot_cli_LDADD = \ - $(top_builddir)/src/core/libopenthread.a \ - $(top_builddir)/src/cli/libopenthread-cli.a \ - $(top_builddir)/examples/cc2538/platform/libopenthread-cc2538.a \ - $(top_builddir)/third_party/mbedtls/libmbedcrypto.a \ +ot_cli_LDADD = \ + $(top_builddir)/src/core/libopenthread.a \ + $(top_builddir)/src/cli/libopenthread-cli.a \ + $(top_builddir)/third_party/mbedtls/libmbedcrypto.a \ + -lstdc++ \ $(NULL) -ot_cli_LDFLAGS = \ - -T $(top_srcdir)/examples/cc2538/platform/cc2538.ld \ +if OPENTHREAD_EXAMPLES_POSIX +ot_cli_LDADD += \ + $(top_builddir)/examples/platforms/posix/libopenthread-posix.a \ $(NULL) +endif -ot_cli_SOURCES = \ - main.c \ +if OPENTHREAD_EXAMPLES_CC2538 +ot_cli_LDADD += \ + $(top_builddir)/examples/platforms/cc2538/libopenthread-cc2538.a \ + $(NULL) +endif + +ot_cli_SOURCES = \ + main.c \ $(NULL) include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/posix/app/cli/README.md b/examples/apps/cli/README.md similarity index 95% rename from examples/posix/app/cli/README.md rename to examples/apps/cli/README.md index c89b93815..dab482989 100644 --- a/examples/posix/app/cli/README.md +++ b/examples/apps/cli/README.md @@ -9,10 +9,9 @@ another emulated Thread device. ## 1. Build ```bash -$ cd openthread +$ cd $ ./bootstrap -$ ./configure --enable-cli --with-examples=posix -$ make +$ make -f examples/Makefile-posix ``` ## 2. Start node 1 diff --git a/examples/cc2538/app/cli/main.c b/examples/apps/cli/main.c similarity index 97% rename from examples/cc2538/app/cli/main.c rename to examples/apps/cli/main.c index 9daf4d241..3113d943b 100644 --- a/examples/cc2538/app/cli/main.c +++ b/examples/apps/cli/main.c @@ -26,8 +26,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include - #include #include #include @@ -38,7 +36,7 @@ void otSignalTaskletPending(void) int main(int argc, char *argv[]) { - PlatformInit(); + PlatformInit(argc, argv); otInit(); otCliSerialInit(); diff --git a/examples/posix/app/ncp/Makefile.am b/examples/apps/ncp/Makefile.am similarity index 80% rename from examples/posix/app/ncp/Makefile.am rename to examples/apps/ncp/Makefile.am index 9e89b0dc9..0778b4234 100644 --- a/examples/posix/app/ncp/Makefile.am +++ b/examples/apps/ncp/Makefile.am @@ -28,25 +28,36 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am -bin_PROGRAMS = \ - ot-ncp \ +bin_PROGRAMS = \ + ot-ncp \ $(NULL) -ot_ncp_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/examples/posix/platform \ +ot_ncp_CPPFLAGS = \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/examples/platforms \ $(NULL) -ot_ncp_LDADD = \ - $(top_builddir)/src/ncp/libopenthread-ncp.a \ - $(top_builddir)/src/core/libopenthread.a \ - $(top_builddir)/examples/posix/platform/libopenthread-posix.a \ - $(top_builddir)/third_party/mbedtls/libmbedcrypto.a \ - -lstdc++ \ +ot_ncp_LDADD = \ + $(top_builddir)/src/core/libopenthread.a \ + $(top_builddir)/src/ncp/libopenthread-ncp.a \ + $(top_builddir)/third_party/mbedtls/libmbedcrypto.a \ + -lstdc++ \ $(NULL) -ot_ncp_SOURCES = \ - main.c \ +if OPENTHREAD_EXAMPLES_POSIX +ot_ncp_LDADD += \ + $(top_builddir)/examples/platforms/posix/libopenthread-posix.a \ + $(NULL) +endif + +if OPENTHREAD_EXAMPLES_CC2538 +ot_ncp_LDADD += \ + $(top_builddir)/examples/platforms/cc2538/libopenthread-cc2538.a \ + $(NULL) +endif + +ot_ncp_SOURCES = \ + main.c \ $(NULL) include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/cc2538/app/ncp/main.c b/examples/apps/ncp/main.c similarity index 97% rename from examples/cc2538/app/ncp/main.c rename to examples/apps/ncp/main.c index 0545f916c..e8e03c1fb 100644 --- a/examples/cc2538/app/ncp/main.c +++ b/examples/apps/ncp/main.c @@ -26,8 +26,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include - #include #include #include @@ -38,7 +36,7 @@ void otSignalTaskletPending(void) int main(int argc, char *argv[]) { - PlatformInit(); + PlatformInit(argc, argv); otInit(); otNcpInit(); diff --git a/examples/cc2538/.default-version b/examples/cc2538/.default-version deleted file mode 100644 index 2eb3c4fe4..000000000 --- a/examples/cc2538/.default-version +++ /dev/null @@ -1 +0,0 @@ -0.5 diff --git a/examples/cc2538/Makefile.am b/examples/cc2538/Makefile.am deleted file mode 100644 index 5cf619ed1..000000000 --- a/examples/cc2538/Makefile.am +++ /dev/null @@ -1,57 +0,0 @@ -# -# Copyright (c) 2016, Nest Labs, Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder 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 HOLDER 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 $(abs_top_nlbuild_autotools_dir)/automake/pre.am - -EXTRA_DIST = \ - Makefile-cc2538 \ - README.md \ - $(NULL) - -# Always package (e.g. for 'make dist') these subdirectories. - -DIST_SUBDIRS = \ - platform \ - app \ - $(NULL) - -# Always build (e.g. for 'make all') these subdirectories. - -SUBDIRS = \ - platform \ - app \ - $(NULL) - -# Always pretty (e.g. for 'make pretty') these subdirectories. - -PRETTY_SUBDIRS = \ - platform \ - app \ - $(NULL) - -include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/cc2538/app/cli/README.md b/examples/cc2538/app/cli/README.md deleted file mode 100644 index 7c23c141d..000000000 --- a/examples/cc2538/app/cli/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# OpenThread CLI Example - -This example application demonstrates a minimal OpenThread application -that exposes the OpenThread configuration and management interfaces -via a basic command-line interface. The steps below take you through -the minimal steps required to ping one emulated Thread device from -another emulated Thread device. - -## 1. Build - -Follow the [CC2538 example build instructions](../../README.md). - -## 2. Start node 1 - -Open a terminal to UART0 on node 1 (115200 8-N-1). - -Start OpenThread: - -```bash -> start -Done -``` - -Wait a few seconds and verify that the device has become a Thread Leader: - -```bash -> state -leader -Done -``` - -View IPv6 addresses assigned to Node 1's Thread interface: - -```bash -> ipaddr -fdde:ad00:beef:0:0:ff:fe00:0 -fe80:0:0:0:0:ff:fe00:0 -fdde:ad00:beef:0:558:f56b:d688:799 -fe80:0:0:0:f3d9:2a82:c8d8:fe43 -Done -``` - -## 2. Start node 2 - -Open a terminal to UART0 on node 2 (115200 8-N-1). - -Start OpenThread: - -```bash -> start -Done -``` - -Wait a few seconds and verify that the device has become a Thread Router: - -```bash -> state -router -Done -``` - -## 3. Ping Node 1 from Node 2 - -```bash -> ping fdde:ad00:beef:0:558:f56b:d688:799 -16 bytes from fdde:ad00:beef:0:558:f56b:d688:799: icmp_seq=1 hlim=64 -``` - -## 4. Want more? - -You may note that the example above did not include any network parameter configuration, such as the IEEE 802.15.4 PAN ID or the Thread Master Key. OpenThread currently implements default values for network parameters, however, you may use the CLI to change network parameters, other configurations, and perform other operations. - -See the [OpenThread CLI Reference README.md](../../../../src/cli/README.md) to explore more. diff --git a/examples/cc2538/app/ncp/Makefile.am b/examples/cc2538/app/ncp/Makefile.am deleted file mode 100644 index efbd54b36..000000000 --- a/examples/cc2538/app/ncp/Makefile.am +++ /dev/null @@ -1,55 +0,0 @@ -# -# Copyright (c) 2016, Nest Labs, Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder 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 HOLDER 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 $(abs_top_nlbuild_autotools_dir)/automake/pre.am - -bin_PROGRAMS = \ - ot-ncp \ - $(NULL) - -ot_ncp_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/examples/cc2538/platform \ - $(NULL) - -ot_ncp_LDADD = \ - $(top_builddir)/src/ncp/libopenthread-ncp.a \ - $(top_builddir)/src/core/libopenthread.a \ - $(top_builddir)/examples/cc2538/platform/libopenthread-cc2538.a \ - $(top_builddir)/third_party/mbedtls/libmbedcrypto.a \ - $(NULL) - -ot_ncp_LDFLAGS = \ - -T $(top_srcdir)/examples/cc2538/platform/cc2538.ld \ - $(NULL) - -ot_ncp_SOURCES = \ - main.c \ - $(NULL) - -include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/cc2538/platform/platform.h b/examples/cc2538/platform/platform.h deleted file mode 100644 index 68a0ccf47..000000000 --- a/examples/cc2538/platform/platform.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2016, Nest Labs, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder 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 HOLDER 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. - */ - -/** - * @file - * This file includes the platform-specific initializers. - * - */ - -#ifndef PLATFORM_H_ -#define PLATFORM_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * This method performs all platform-specific initialization. - * - */ -void PlatformInit(void); - -/** - * This method performs all platform-specific processing. - * - */ -void PlatformProcessDrivers(void); - -/** - * This method initializes the alarm service used by OpenThread. - * - */ -void PlatformAlarmInit(void); - -/** - * This method performs alarm driver processing. - * - */ -void PlatformAlarmProcess(void); - -/** - * This method initializes the radio service used by OpenThread. - * - */ -void PlatformRadioInit(void); - -/** - * This method performs radio driver processing. - * - */ -void PlatformRadioProcess(void); - -/** - * This method initializes the random number service used by OpenThread. - * - */ -void PlatformRandomInit(void); - -/** - * This method performs radio driver processing. - * - */ -void PlatformSerialProcess(void); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // PLATFORM_H_ diff --git a/examples/posix/app/Makefile.am b/examples/platforms/Makefile.am similarity index 82% rename from examples/posix/app/Makefile.am rename to examples/platforms/Makefile.am index 626990532..8c8ef753b 100644 --- a/examples/posix/app/Makefile.am +++ b/examples/platforms/Makefile.am @@ -31,28 +31,29 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am # Always package (e.g. for 'make dist') these subdirectories. DIST_SUBDIRS = \ - cli \ - ncp \ + cc2538 \ + posix \ $(NULL) # Always build (e.g. for 'make all') these subdirectories. -SUBDIRS = \ +if OPENTHREAD_EXAMPLES_POSIX +SUBDIRS = posix +endif + +if OPENTHREAD_EXAMPLES_CC2538 +SUBDIRS = cc2538 +endif + +noinst_HEADERS = \ + platform.h \ $(NULL) -if OPENTHREAD_ENABLE_CLI -SUBDIRS += cli -endif - -if OPENTHREAD_ENABLE_NCP -SUBDIRS += ncp -endif - # Always pretty (e.g. for 'make pretty') these subdirectories. PRETTY_SUBDIRS = \ - cli \ - ncp \ + cc2538 \ + posix \ $(NULL) include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/cc2538/platform/Makefile.am b/examples/platforms/cc2538/Makefile.am similarity index 93% rename from examples/cc2538/platform/Makefile.am rename to examples/platforms/cc2538/Makefile.am index 1064c9ba5..7c35e0c86 100644 --- a/examples/cc2538/platform/Makefile.am +++ b/examples/platforms/cc2538/Makefile.am @@ -32,7 +32,6 @@ lib_LIBRARIES = libopenthread-cc2538.a libopenthread_cc2538_a_CPPFLAGS = \ -I$(top_srcdir)/include \ - -I$(top_srcdir)/src \ -I$(top_srcdir)/src/core \ $(NULL) @@ -48,7 +47,11 @@ libopenthread_cc2538_a_SOURCES = \ noinst_HEADERS = \ cc2538-reg.h \ - platform.h \ + platform-cc2538.h \ $(NULL) +if OPENTHREAD_BUILD_COVERAGE +CLEANFILES = $(wildcard *.gcda *.gcno) +endif # OPENTHREAD_BUILD_COVERAGE + include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/cc2538/README.md b/examples/platforms/cc2538/README.md similarity index 80% rename from examples/cc2538/README.md rename to examples/platforms/cc2538/README.md index f9d9310c0..372c87aa6 100644 --- a/examples/cc2538/README.md +++ b/examples/platforms/cc2538/README.md @@ -1,7 +1,7 @@ # OpenThread on CC2538 Example -This directory contains example applications and platform drivers for -the [Texas Instruments CC2538][cc2538]. +This directory contains example platform drivers for the [Texas +Instruments CC2538][cc2538]. [cc2538]: http://www.ti.com/product/CC2538 @@ -9,13 +9,6 @@ The example platform drivers are intended to present the minimal code necessary to support OpenThread. As a result, the example platform drivers do not necessarily highlight the platform's full capabilities. -## What's Included - -Folder | Description ------------|----------------------------------------- -`apps/cli` | Example application that exposes the CLI over UART -`platform` | Minimal implementation of `otPlat*` APIs - ## Toolchain Download and install the [GNU toolchain for ARM @@ -28,7 +21,7 @@ Cortex-M][gnu-toolchain]. ```bash $ cd $ ./bootstrap -$ make -f examples/cc2538/Makefile-cc2538 +$ make -f examples/Makefile-cc2538 ``` After a successful build, the `elf` files are found in diff --git a/examples/cc2538/platform/alarm.c b/examples/platforms/cc2538/alarm.c similarity index 99% rename from examples/cc2538/platform/alarm.c rename to examples/platforms/cc2538/alarm.c index 3fdd6eef2..54441d1bf 100644 --- a/examples/cc2538/platform/alarm.c +++ b/examples/platforms/cc2538/alarm.c @@ -36,7 +36,7 @@ #include #include -#include "cc2538-reg.h" +#include "platform-cc2538.h" enum { diff --git a/examples/cc2538/platform/cc2538-reg.h b/examples/platforms/cc2538/cc2538-reg.h similarity index 100% rename from examples/cc2538/platform/cc2538-reg.h rename to examples/platforms/cc2538/cc2538-reg.h diff --git a/examples/cc2538/platform/cc2538.ld b/examples/platforms/cc2538/cc2538.ld similarity index 100% rename from examples/cc2538/platform/cc2538.ld rename to examples/platforms/cc2538/cc2538.ld diff --git a/examples/cc2538/platform/logging.c b/examples/platforms/cc2538/logging.c similarity index 100% rename from examples/cc2538/platform/logging.c rename to examples/platforms/cc2538/logging.c diff --git a/examples/platforms/cc2538/platform-cc2538.h b/examples/platforms/cc2538/platform-cc2538.h new file mode 100644 index 000000000..fb9b55e07 --- /dev/null +++ b/examples/platforms/cc2538/platform-cc2538.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2016, Nest Labs, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder 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 HOLDER 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. + */ + +/** + * @file + * This file includes the platform-specific initializers. + * + */ + +#ifndef PLATFORM_CC2538_H_ +#define PLATFORM_CC2538_H_ + +#include + +#include "cc2538-reg.h" + +/** + * This function initializes the alarm service used by OpenThread. + * + */ +void cc2538AlarmInit(void); + +/** + * This function performs alarm driver processing. + * + */ +void cc2538AlarmProcess(void); + +/** + * This function initializes the radio service used by OpenThread. + * + */ +void cc2538RadioInit(void); + +/** + * This function performs radio driver processing. + * + */ +void cc2538RadioProcess(void); + +/** + * This function initializes the random number service used by OpenThread. + * + */ +void cc2538RandomInit(void); + +/** + * This function performs radio driver processing. + * + */ +void cc2538SerialProcess(void); + +#endif // PLATFORM_CC2538_H_ diff --git a/examples/cc2538/platform/platform.c b/examples/platforms/cc2538/platform.c similarity index 89% rename from examples/cc2538/platform/platform.c rename to examples/platforms/cc2538/platform.c index 297401238..e17b46e45 100644 --- a/examples/cc2538/platform/platform.c +++ b/examples/platforms/cc2538/platform.c @@ -33,13 +33,13 @@ */ #include -#include "platform.h" +#include "platform-cc2538.h" -void PlatformInit(void) +void PlatformInit(int argc, char *argv[]) { - PlatformAlarmInit(); - PlatformRadioInit(); - PlatformRandomInit(); + cc2538AlarmInit(); + cc2538RadioInit(); + cc2538RandomInit(); otPlatSerialEnable(); } @@ -47,7 +47,7 @@ void PlatformProcessDrivers(void) { // should sleep and wait for interrupts here - PlatformSerialProcess(); - PlatformRadioProcess(); - PlatformAlarmProcess(); + cc2538SerialProcess(); + cc2538RadioProcess(); + cc2538AlarmProcess(); } diff --git a/examples/cc2538/platform/radio.c b/examples/platforms/cc2538/radio.c similarity index 99% rename from examples/cc2538/platform/radio.c rename to examples/platforms/cc2538/radio.c index 88022b708..a3efa4d60 100644 --- a/examples/cc2538/platform/radio.c +++ b/examples/platforms/cc2538/radio.c @@ -36,7 +36,7 @@ #include #include -#include "cc2538-reg.h" +#include "platform-cc2538.h" enum { diff --git a/examples/cc2538/platform/random.c b/examples/platforms/cc2538/random.c similarity index 98% rename from examples/cc2538/platform/random.c rename to examples/platforms/cc2538/random.c index f2b108110..3bb018c41 100644 --- a/examples/cc2538/platform/random.c +++ b/examples/platforms/cc2538/random.c @@ -35,7 +35,7 @@ */ #include -#include "cc2538-reg.h" +#include "platform-cc2538.h" static uint32_t s_state = 1; diff --git a/examples/cc2538/platform/serial.c b/examples/platforms/cc2538/serial.c similarity index 99% rename from examples/cc2538/platform/serial.c rename to examples/platforms/cc2538/serial.c index a55880375..edf053efa 100644 --- a/examples/cc2538/platform/serial.c +++ b/examples/platforms/cc2538/serial.c @@ -37,7 +37,7 @@ #include #include #include -#include "cc2538-reg.h" +#include "platform-cc2538.h" enum { diff --git a/examples/cc2538/platform/startup-gcc.c b/examples/platforms/cc2538/startup-gcc.c similarity index 100% rename from examples/cc2538/platform/startup-gcc.c rename to examples/platforms/cc2538/startup-gcc.c diff --git a/examples/posix/platform/posix-platform.c b/examples/platforms/platform.h similarity index 82% rename from examples/posix/platform/posix-platform.c rename to examples/platforms/platform.h index 000b1711a..a6fb7986f 100644 --- a/examples/posix/platform/posix-platform.c +++ b/examples/platforms/platform.h @@ -29,10 +29,22 @@ /** * @file * @brief - * This file includes the platform-specific initializers. + * This file includes the posix platform-specific initializers. */ -#include +#ifndef PLATFORM_H_ +#define PLATFORM_H_ -uint32_t NODE_ID = 1; +/** + * This function performs all platform-specific initialization. + * + */ +void PlatformInit(int argc, char *argv[]); +/** + * This function performs all platform-specific processing. + * + */ +void PlatformProcessDrivers(void); + +#endif // PLATFORM_H_ diff --git a/examples/posix/platform/Makefile.am b/examples/platforms/posix/Makefile.am similarity index 87% rename from examples/posix/platform/Makefile.am rename to examples/platforms/posix/Makefile.am index 225d39bab..db4717ee2 100644 --- a/examples/posix/platform/Makefile.am +++ b/examples/platforms/posix/Makefile.am @@ -32,9 +32,7 @@ lib_LIBRARIES = libopenthread-posix.a libopenthread_posix_a_CPPFLAGS = \ -I$(top_srcdir)/include \ - -I$(top_srcdir)/src \ -I$(top_srcdir)/src/core \ - -I$(top_srcdir)/examples/posix/platform \ -D_GNU_SOURCE \ $(NULL) @@ -42,20 +40,17 @@ libopenthread_posix_a_SOURCES = \ alarm.c \ logging.c \ platform.c \ - posix-platform.c \ radio.c \ random.c \ serial.c \ $(NULL) -include_HEADERS = \ - posix-platform.h \ +noinst_HEADERS = \ + platform-posix.h \ $(NULL) -install-headers: install-includeHEADERS - if OPENTHREAD_BUILD_COVERAGE -CLEANFILES = $(wildcard *.gcda *.gcno) +CLEANFILES = $(wildcard *.gcda *.gcno) endif # OPENTHREAD_BUILD_COVERAGE include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/platforms/posix/README.md b/examples/platforms/posix/README.md new file mode 100644 index 000000000..3806519e3 --- /dev/null +++ b/examples/platforms/posix/README.md @@ -0,0 +1,57 @@ +# OpenThread on POSIX Emulation Example + +This directory contains example platform drivers for POSIX emulation. + +## Build Examples + +```bash +$ cd +$ ./bootstrap +$ make -f examples/Makefile-posix +``` + +After a successful build, the `elf` files are found in +`/output/x86_64-apple-darwin/bin`. + +## + +## Interact + +1. Spawn the process: + +```bash +$ cd openthread/examples/posix/app/cli +$ ./ot-cli 1 +``` + +2. Type `help` for list of commands. + +```bash +> help +help +channel +childtimeout +contextreusedelay +extaddr +extpanid +ipaddr +keysequence +leaderweight +masterkey +mode +netdataregister +networkidtimeout +networkname +panid +ping +prefix +releaserouterid +rloc16 +route +routerupgradethreshold +scan +start +state +stop +whitelist +``` diff --git a/examples/posix/platform/alarm.c b/examples/platforms/posix/alarm.c similarity index 94% rename from examples/posix/platform/alarm.c rename to examples/platforms/posix/alarm.c index 60c38dff0..affec1881 100644 --- a/examples/posix/platform/alarm.c +++ b/examples/platforms/posix/alarm.c @@ -32,13 +32,13 @@ #include #include -#include +#include "platform-posix.h" static bool s_is_running = false; static uint32_t s_alarm = 0; static struct timeval s_start; -void posixPlatformAlarmInit(void) +void posixAlarmInit(void) { gettimeofday(&s_start, NULL); } @@ -64,7 +64,7 @@ void otPlatAlarmStop(void) s_is_running = false; } -void posixPlatformAlarmUpdateTimeout(struct timeval *aTimeout) +void posixAlarmUpdateTimeout(struct timeval *aTimeout) { int32_t remaining; @@ -95,7 +95,7 @@ void posixPlatformAlarmUpdateTimeout(struct timeval *aTimeout) } } -void posixPlatformAlarmProcess(void) +void posixAlarmProcess(void) { int32_t remaining; diff --git a/examples/posix/platform/logging.c b/examples/platforms/posix/logging.c similarity index 100% rename from examples/posix/platform/logging.c rename to examples/platforms/posix/logging.c diff --git a/examples/posix/platform/posix-platform.h b/examples/platforms/posix/platform-posix.h similarity index 63% rename from examples/posix/platform/posix-platform.h rename to examples/platforms/posix/platform-posix.h index 11db426fe..773d4659b 100644 --- a/examples/posix/platform/posix-platform.h +++ b/examples/platforms/posix/platform-posix.h @@ -32,17 +32,13 @@ * This file includes the posix platform-specific initializers. */ -#ifndef POSIX_PLATFORM_H_ -#define POSIX_PLATFORM_H_ +#ifndef PLATFORM_POSIX_H_ +#define PLATFORM_POSIX_H_ #include #include #include -#ifdef __cplusplus -extern "C" { -#endif - /** * Unique node ID. * @@ -56,83 +52,67 @@ extern uint32_t NODE_ID; extern uint32_t WELLKNOWN_NODE_ID; /** - * This method performs all platform-specific initialization. + * This function initializes the alarm service used by OpenThread. * */ -void posixPlatformInit(void); +void posixAlarmInit(void); /** - * This method performs all platform-specific processing. - * - */ -void posixPlatformProcessDrivers(void); - -/** - * This method initializes the alarm service used by OpenThread. - * - */ -void posixPlatformAlarmInit(void); - -/** - * This method retrieves the time remaining until the alarm fires. + * This function retrieves the time remaining until the alarm fires. * * @param[out] aTimeval A pointer to the timeval struct. * */ -void posixPlatformAlarmUpdateTimeout(struct timeval *tv); +void posixAlarmUpdateTimeout(struct timeval *tv); /** - * This method performs alarm driver processing. + * This function performs alarm driver processing. * */ -void posixPlatformAlarmProcess(void); +void posixAlarmProcess(void); /** - * This method initializes the radio service used by OpenThread. + * This function initializes the radio service used by OpenThread. * */ -void posixPlatformRadioInit(void); +void posixRadioInit(void); /** - * This method updates the file descriptor sets with file descriptors used by the radio driver. + * This function updates the file descriptor sets with file descriptors used by the radio driver. * * @param[inout] aReadFdSet A pointer to the read file descriptors. * @param[inout] aWriteFdSet A pointer to the write file descriptors. * @param[inout] aMaxFd A pointer to the max file descriptor. * */ -void posixPlatformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd); +void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd); /** - * This method performs radio driver processing. + * This function performs radio driver processing. * */ -void posixPlatformRadioProcess(void); +void posixRadioProcess(void); /** - * This method initializes the random number service used by OpenThread. + * This function initializes the random number service used by OpenThread. * */ -void posixPlatformRandomInit(void); +void posixRandomInit(void); /** - * This method updates the file descriptor sets with file descriptors used by the serial driver. + * This function updates the file descriptor sets with file descriptors used by the serial driver. * * @param[inout] aReadFdSet A pointer to the read file descriptors. * @param[inout] aWriteFdSet A pointer to the write file descriptors. * @param[inout] aMaxFd A pointer to the max file descriptor. * */ -void posixPlatformSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd); +void posixSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd); /** - * This method performs radio driver processing. + * This function performs radio driver processing. * */ -void posixPlatformSerialProcess(void); +void posixSerialProcess(void); -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // POSIX_PLATFORM_H_ +#endif // PLATFORM_POSIX_H_ diff --git a/examples/posix/platform/platform.c b/examples/platforms/posix/platform.c similarity index 81% rename from examples/posix/platform/platform.c rename to examples/platforms/posix/platform.c index fe9fe08ac..6b2d71f63 100644 --- a/examples/posix/platform/platform.c +++ b/examples/platforms/posix/platform.c @@ -36,25 +36,33 @@ #include #include #include +#include #include #include #include #include -#include +#include "platform-posix.h" uint32_t NODE_ID = 1; uint32_t WELLKNOWN_NODE_ID = 34; -void posixPlatformInit(void) +void PlatformInit(int argc, char *argv[]) { - posixPlatformAlarmInit(); - posixPlatformRadioInit(); - posixPlatformRandomInit(); + if (argc != 2) + { + exit(1); + } + + NODE_ID = atoi(argv[1]); + + posixAlarmInit(); + posixRadioInit(); + posixRandomInit(); otPlatSerialEnable(); } -void posixPlatformProcessDrivers(void) +void PlatformProcessDrivers(void) { fd_set read_fds; fd_set write_fds; @@ -65,9 +73,9 @@ void posixPlatformProcessDrivers(void) FD_ZERO(&read_fds); FD_ZERO(&write_fds); - posixPlatformSerialUpdateFdSet(&read_fds, &write_fds, &max_fd); - posixPlatformRadioUpdateFdSet(&read_fds, &write_fds, &max_fd); - posixPlatformAlarmUpdateTimeout(&timeout); + posixSerialUpdateFdSet(&read_fds, &write_fds, &max_fd); + posixRadioUpdateFdSet(&read_fds, &write_fds, &max_fd); + posixAlarmUpdateTimeout(&timeout); if (!otAreTaskletsPending()) { @@ -75,8 +83,8 @@ void posixPlatformProcessDrivers(void) assert(rval >= 0 && errno != ETIME); } - posixPlatformSerialProcess(); - posixPlatformRadioProcess(); - posixPlatformAlarmProcess(); + posixSerialProcess(); + posixRadioProcess(); + posixAlarmProcess(); } diff --git a/examples/posix/platform/radio.c b/examples/platforms/posix/radio.c similarity index 98% rename from examples/posix/platform/radio.c rename to examples/platforms/posix/radio.c index 3cb78703e..6a7f7cc91 100644 --- a/examples/posix/platform/radio.c +++ b/examples/platforms/posix/radio.c @@ -42,7 +42,7 @@ #include #include -#include "posix-platform.h" +#include "platform-posix.h" enum { @@ -289,7 +289,7 @@ ThreadError otPlatRadioSetShortAddress(uint16_t address) return kThreadError_None; } -void posixPlatformRadioInit(void) +void posixRadioInit(void) { struct sockaddr_in sockaddr; memset(&sockaddr, 0, sizeof(sockaddr)); @@ -521,7 +521,7 @@ int radioTransmit(void) return rval; } -void posixPlatformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd) +void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd) { if (aReadFdSet != NULL && (s_state == kStateDisabled || s_state == kStateSleep || s_state == kStateListen || s_state == kStateAckWait)) @@ -545,7 +545,7 @@ void posixPlatformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int } } -void posixPlatformRadioProcess(void) +void posixRadioProcess(void) { const int flags = POLLRDNORM | POLLERR | POLLNVAL | POLLHUP; struct pollfd pollfd = { s_sockfd, flags, 0 }; diff --git a/examples/posix/platform/random.c b/examples/platforms/posix/random.c similarity index 97% rename from examples/posix/platform/random.c rename to examples/platforms/posix/random.c index bed03486d..a7eb9f0be 100644 --- a/examples/posix/platform/random.c +++ b/examples/platforms/posix/random.c @@ -35,11 +35,11 @@ */ #include -#include +#include "platform-posix.h" static uint32_t s_state = 1; -void posixPlatformRandomInit(void) +void posixRandomInit(void) { s_state = NODE_ID; } diff --git a/examples/posix/platform/serial.c b/examples/platforms/posix/serial.c similarity index 97% rename from examples/posix/platform/serial.c rename to examples/platforms/posix/serial.c index 5ecd30dee..4654f0e49 100644 --- a/examples/posix/platform/serial.c +++ b/examples/platforms/posix/serial.c @@ -36,7 +36,7 @@ #include #include -#include +#include "platform-posix.h" #ifdef OPENTHREAD_TARGET_LINUX int posix_openpt(int oflag); @@ -163,7 +163,7 @@ exit: return error; } -void posixPlatformSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd) +void posixSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd) { if (aReadFdSet != NULL) { @@ -186,7 +186,7 @@ void posixPlatformSerialUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int } } -void posixPlatformSerialProcess(void) +void posixSerialProcess(void) { const int flags = POLLRDNORM | POLLERR | POLLNVAL | POLLHUP; struct pollfd pollfd = { s_in_fd, flags, 0 }; diff --git a/examples/posix/Makefile.am b/examples/posix/Makefile.am deleted file mode 100644 index 8c44607d3..000000000 --- a/examples/posix/Makefile.am +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright (c) 2016, Nest Labs, Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder 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 HOLDER 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 $(abs_top_nlbuild_autotools_dir)/automake/pre.am - -# Always package (e.g. for 'make dist') these subdirectories. - -DIST_SUBDIRS = \ - platform \ - app \ - $(NULL) - -# Always build (e.g. for 'make all') these subdirectories. - -SUBDIRS = \ - platform \ - app \ - $(NULL) - -# Always pretty (e.g. for 'make pretty') these subdirectories. - -PRETTY_SUBDIRS = \ - platform \ - app \ - $(NULL) - -include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/posix/app/cli/Makefile.am b/examples/posix/app/cli/Makefile.am deleted file mode 100644 index d115976e1..000000000 --- a/examples/posix/app/cli/Makefile.am +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright (c) 2016, Nest Labs, Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder 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 HOLDER 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 $(abs_top_nlbuild_autotools_dir)/automake/pre.am - -bin_PROGRAMS = \ - ot-cli \ - $(NULL) - -ot_cli_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/examples/posix/platform \ - $(NULL) - -ot_cli_LDADD = \ - $(top_builddir)/src/core/libopenthread.a \ - $(top_builddir)/src/cli/libopenthread-cli.a \ - $(top_builddir)/examples/posix/platform/libopenthread-posix.a \ - $(top_builddir)/third_party/mbedtls/libmbedcrypto.a \ - -lstdc++ \ - $(NULL) - -ot_cli_SOURCES = \ - main.c \ - $(NULL) - -include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/posix/app/cli/main.c b/examples/posix/app/cli/main.c deleted file mode 100644 index 5b6b60264..000000000 --- a/examples/posix/app/cli/main.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2016, Nest Labs, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder 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 HOLDER 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 - -#include -#include -#include - -void otSignalTaskletPending(void) -{ -} - -int main(int argc, char *argv[]) -{ - if (argc != 2) - { - exit(1); - } - - NODE_ID = atoi(argv[1]); - - posixPlatformInit(); - otInit(); - otCliSerialInit(); - - while (1) - { - otProcessNextTasklet(); - posixPlatformProcessDrivers(); - } - - return 0; -} diff --git a/examples/posix/app/ncp/main.c b/examples/posix/app/ncp/main.c deleted file mode 100644 index 6216e83a4..000000000 --- a/examples/posix/app/ncp/main.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2016, Nest Labs, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder 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 HOLDER 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 - -#include -#include -#include - -void otSignalTaskletPending(void) -{ -} - -int main(int argc, char *argv[]) -{ - if (argc != 2) - { - exit(1); - } - - NODE_ID = atoi(argv[1]); - - posixPlatformInit(); - otInit(); - otNcpInit(); - - while (1) - { - otProcessNextTasklet(); - posixPlatformProcessDrivers(); - } - - return 0; -} diff --git a/tests/scripts/thread-cert/node.py b/tests/scripts/thread-cert/node.py index ad758cd6d..1813f8442 100755 --- a/tests/scripts/thread-cert/node.py +++ b/tests/scripts/thread-cert/node.py @@ -54,7 +54,7 @@ class Node: """ Initialize a simulation node. """ if "top_builddir" in os.environ.keys(): srcdir = os.environ['top_builddir'] - cmd = '%s/examples/posix/app/cli/ot-cli' % srcdir + cmd = '%s/examples/apps/cli/ot-cli' % srcdir else: cmd = './ot-cli' cmd += ' %d' % nodeid diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 0a3e5a424..988a4781f 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -32,60 +32,60 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am # Local headers to build against and distribute but not to install # since they are not part of the package. # -noinst_HEADERS = \ - test_util.h \ - test_util.hpp \ - test_vector.h \ +noinst_HEADERS = \ + test_util.h \ + test_util.hpp \ + test_vector.h \ $(NULL) # # Other files we do want to distribute with the package. # -EXTRA_DIST = \ +EXTRA_DIST = \ $(NULL) if OPENTHREAD_BUILD_TESTS # C preprocessor option flags that will apply to all compiled objects in this # makefile. -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/core \ - -I$(top_srcdir)/third_party/mbedtls/repo/include \ +AM_CPPFLAGS = \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/core \ + -I$(top_srcdir)/third_party/mbedtls/repo/include \ $(NULL) -COMMON_LDADD = \ - $(top_builddir)/src/core/libopenthread.a \ - $(top_builddir)/examples/posix/platform/libopenthread-posix.a \ - $(top_builddir)/third_party/mbedtls/libmbedcrypto.a \ - -lpthread \ +COMMON_LDADD = \ + $(top_builddir)/src/core/libopenthread.a \ + $(top_builddir)/examples/platforms/posix/libopenthread-posix.a \ + $(top_builddir)/third_party/mbedtls/libmbedcrypto.a \ + -lpthread \ $(NULL) # Test applications that should be run when the 'check' target is run. -check_PROGRAMS = \ - test-aes \ - test-hmac-sha256 \ - test-lowpan \ - test-link-quality \ - test-mac-frame \ - test-message \ - test-timer \ - test-toolchain \ +check_PROGRAMS = \ + test-aes \ + test-hmac-sha256 \ + test-lowpan \ + test-link-quality \ + test-mac-frame \ + test-message \ + test-timer \ + test-toolchain \ $(NULL) # Test applications and scripts that should be built and run when the # 'check' target is run. -TESTS = \ - $(check_PROGRAMS) \ +TESTS = \ + $(check_PROGRAMS) \ $(NULL) # The additional environment variables and their values that will be # made available to all programs and scripts in TESTS. -TESTS_ENVIRONMENT = \ +TESTS_ENVIRONMENT = \ $(NULL) # Source, compiler, and linker options for test programs.