mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 23:57:47 +00:00
Unify example apps across all example platforms. (#215)
This commit is contained in:
@@ -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=/ \
|
||||
@@ -0,0 +1,258 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# Don't allow this top-level makefile's targets to be built in parallel.
|
||||
|
||||
.NOTPARALLEL:
|
||||
|
||||
COVERAGE ?= 0
|
||||
DEBUG ?= 0
|
||||
|
||||
ECHO := @echo
|
||||
MAKE := make
|
||||
MKDIR_P := mkdir -p
|
||||
LN_S := ln -s
|
||||
RM_F := rm -f
|
||||
|
||||
INSTALL := /usr/bin/install
|
||||
INSTALLFLAGS := -p
|
||||
|
||||
TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST))))..
|
||||
AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))..
|
||||
|
||||
BuildPath = build
|
||||
TopBuildDir = $(BuildPath)
|
||||
AbsTopBuildDir = $(PWD)/$(TopBuildDir)
|
||||
|
||||
ResultPath = output
|
||||
TopResultDir = $(ResultPath)
|
||||
AbsTopResultDir = $(PWD)/$(TopResultDir)
|
||||
|
||||
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
|
||||
else
|
||||
configure_OPTIONS +=
|
||||
endif
|
||||
|
||||
# If the user has asserted DEBUG, alter the configuration options
|
||||
# accordingly.
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
configure_OPTIONS += --enable-debug --enable-optimization=no
|
||||
else
|
||||
configure_OPTIONS +=
|
||||
endif
|
||||
|
||||
#
|
||||
# configure-arch <target>
|
||||
#
|
||||
# Configure OpenThread for the specified target.
|
||||
#
|
||||
# target - The target to configure.
|
||||
#
|
||||
define configure-target
|
||||
$(ECHO) " CONFIG $(1)..."
|
||||
(cd $(BuildPath)/$(1) && $(AbsTopSourceDir)/configure \
|
||||
INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
|
||||
--prefix=/ \
|
||||
--exec-prefix=/$(1) \
|
||||
$(configure_OPTIONS))
|
||||
endef # configure-target
|
||||
|
||||
#
|
||||
# build-target <target>
|
||||
#
|
||||
# Build the OpenThread intermediate build products for the specified
|
||||
# target.
|
||||
#
|
||||
# target - The target to build.
|
||||
#
|
||||
define build-target
|
||||
$(ECHO) " BUILD $(1)"
|
||||
$(MAKE) -C $(BuildPath)/$(1) --no-print-directory \
|
||||
all
|
||||
endef # build-target
|
||||
|
||||
#
|
||||
# check-target <target>
|
||||
#
|
||||
# Check (run unit tests) OpenThread for the specified target.
|
||||
#
|
||||
# target - The target to check.
|
||||
#
|
||||
define check-target
|
||||
$(ECHO) " CHECK $(1)"
|
||||
$(MAKE) -C $(BuildPath)/$(1) --no-print-directory \
|
||||
check
|
||||
endef # check-target
|
||||
|
||||
#
|
||||
# distcheck-target <target>
|
||||
#
|
||||
# Check (run unit tests) OpenThread for the specified target.
|
||||
#
|
||||
# target - The target to distcheck.
|
||||
#
|
||||
define distcheck-target
|
||||
$(ECHO) " DISTCHECK $(1)"
|
||||
$(MAKE) -C $(BuildPath)/$(1) --no-print-directory \
|
||||
distcheck
|
||||
endef # distcheck-target
|
||||
|
||||
#
|
||||
# coverage-target <target>
|
||||
#
|
||||
# Generate code coverage from unit tests for OpenThread for the
|
||||
# specified target.
|
||||
#
|
||||
# target - The target to generate code coverage for.
|
||||
#
|
||||
define coverage-target
|
||||
$(ECHO) " COVERAGE $(1)"
|
||||
$(MAKE) -C $(BuildPath)/$(1) --no-print-directory \
|
||||
coverage
|
||||
endef # coverage-target
|
||||
|
||||
#
|
||||
# stage-target <target>
|
||||
#
|
||||
# Stage (install) the OpenThread final build products for the specified
|
||||
# target.
|
||||
#
|
||||
# target - The target to stage.
|
||||
#
|
||||
define stage-target
|
||||
$(ECHO) " STAGE $(1)"
|
||||
$(MAKE) -C $(BuildPath)/$(1) --no-print-directory \
|
||||
DESTDIR=$(AbsTopResultDir) \
|
||||
install
|
||||
endef # stage-target
|
||||
|
||||
#
|
||||
# TARGET_template <target>
|
||||
#
|
||||
# Define macros, targets and rules to configure, build, and stage
|
||||
# OpenThread for a single target.
|
||||
#
|
||||
# target - The target to instantiate the template for.
|
||||
#
|
||||
define TARGET_template
|
||||
CONFIGURE_TARGETS += configure-$(1)
|
||||
BUILD_TARGETS += do-build-$(1)
|
||||
CHECK_TARGETS += check-$(1)
|
||||
DISTCHECK_TARGETS += distcheck-$(1)
|
||||
COVERAGE_TARGETS += coverage-$(1)
|
||||
STAGE_TARGETS += stage-$(1)
|
||||
BUILD_DIRS += $(BuildPath)/$(1)
|
||||
DIRECTORIES += $(BuildPath)/$(1)
|
||||
|
||||
configure-$(1): $(BuildPath)/$(1)/config.status
|
||||
|
||||
$(BuildPath)/$(1)/config.status: | $(BuildPath)/$(1)
|
||||
$$(call configure-target,$(1))
|
||||
|
||||
do-build-$(1): configure-$(1)
|
||||
|
||||
do-build-$(1):
|
||||
$$(call build-target,$(1))
|
||||
|
||||
check-$(1): do-build-$(1)
|
||||
|
||||
check-$(1):
|
||||
$$(call check-target,$(1))
|
||||
|
||||
distcheck-$(1): do-build-$(1)
|
||||
|
||||
distcheck-$(1):
|
||||
$$(call distcheck-target,$(1))
|
||||
|
||||
coverage-$(1): do-build-$(1)
|
||||
|
||||
coverage-$(1):
|
||||
$$(call coverage-target,$(1))
|
||||
|
||||
stage-$(1): do-build-$(1)
|
||||
|
||||
stage-$(1): | $(TopResultDir)
|
||||
$$(call stage-target,$(1))
|
||||
|
||||
$(1): stage-$(1)
|
||||
endef # TARGET_template
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
all: stage
|
||||
|
||||
# Instantiate an target-specific build template for the target.
|
||||
|
||||
$(eval $(call TARGET_template,$(TargetTuple)))
|
||||
|
||||
#
|
||||
# Common / Finalization
|
||||
#
|
||||
|
||||
configure: $(CONFIGURE_TARGETS)
|
||||
|
||||
build: $(BUILD_TARGETS)
|
||||
|
||||
check: $(CHECK_TARGETS)
|
||||
|
||||
distcheck: $(DISTCHECK_TARGETS)
|
||||
|
||||
coverage: $(COVERAGE_TARGETS)
|
||||
|
||||
stage: $(STAGE_TARGETS)
|
||||
|
||||
DIRECTORIES = $(TopResultDir) $(TopResultDir)/$(TargetTuple)/lib $(BUILD_DIRS)
|
||||
|
||||
CLEAN_DIRS = $(TopResultDir) $(BUILD_DIRS)
|
||||
|
||||
all: stage
|
||||
|
||||
$(DIRECTORIES):
|
||||
$(ECHO) " MKDIR $@"
|
||||
@$(MKDIR_P) "$@"
|
||||
|
||||
clean:
|
||||
$(ECHO) " CLEAN"
|
||||
@$(RM_F) -r $(CLEAN_DIRS)
|
||||
|
||||
help:
|
||||
$(ECHO) "Simply type 'make -f $(firstword $(MAKEFILE_LIST))' to build OpenThread for the following "
|
||||
$(ECHO) "target:"
|
||||
$(ECHO) ""
|
||||
$(ECHO) " $(TargetTuple)"
|
||||
$(ECHO) ""
|
||||
|
||||
+9
-10
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -9,10 +9,9 @@ another emulated Thread device.
|
||||
## 1. Build
|
||||
|
||||
```bash
|
||||
$ cd openthread
|
||||
$ cd <path-to-openthread>
|
||||
$ ./bootstrap
|
||||
$ ./configure --enable-cli --with-examples=posix
|
||||
$ make
|
||||
$ make -f examples/Makefile-posix
|
||||
```
|
||||
|
||||
## 2. Start node 1
|
||||
@@ -26,8 +26,6 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <cli/cli-serial.h>
|
||||
#include <platform.h>
|
||||
@@ -38,7 +36,7 @@ void otSignalTaskletPending(void)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
PlatformInit();
|
||||
PlatformInit(argc, argv);
|
||||
otInit();
|
||||
otCliSerialInit();
|
||||
|
||||
@@ -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
|
||||
@@ -26,8 +26,6 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <ncp/ncp.h>
|
||||
#include <platform.h>
|
||||
@@ -38,7 +36,7 @@ void otSignalTaskletPending(void)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
PlatformInit();
|
||||
PlatformInit(argc, argv);
|
||||
otInit();
|
||||
otNcpInit();
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
0.5
|
||||
@@ -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
|
||||
@@ -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.
|
||||
@@ -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
|
||||
@@ -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 <stdint.h>
|
||||
|
||||
#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_
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 <path-to-openthread>
|
||||
$ ./bootstrap
|
||||
$ make -f examples/cc2538/Makefile-cc2538
|
||||
$ make -f examples/Makefile-cc2538
|
||||
```
|
||||
|
||||
After a successful build, the `elf` files are found in
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <platform/alarm.h>
|
||||
#include "cc2538-reg.h"
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -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 <stdint.h>
|
||||
|
||||
#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_
|
||||
@@ -33,13 +33,13 @@
|
||||
*/
|
||||
|
||||
#include <platform/serial.h>
|
||||
#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();
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <platform/radio.h>
|
||||
#include "cc2538-reg.h"
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include <platform/random.h>
|
||||
#include "cc2538-reg.h"
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
static uint32_t s_state = 1;
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <openthread-types.h>
|
||||
#include <common/code_utils.hpp>
|
||||
#include <platform/serial.h>
|
||||
#include "cc2538-reg.h"
|
||||
#include "platform-cc2538.h"
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -29,10 +29,22 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* This file includes the platform-specific initializers.
|
||||
* This file includes the posix platform-specific initializers.
|
||||
*/
|
||||
|
||||
#include <posix-platform.h>
|
||||
#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_
|
||||
@@ -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
|
||||
@@ -0,0 +1,57 @@
|
||||
# OpenThread on POSIX Emulation Example
|
||||
|
||||
This directory contains example platform drivers for POSIX emulation.
|
||||
|
||||
## Build Examples
|
||||
|
||||
```bash
|
||||
$ cd <path-to-openthread>
|
||||
$ ./bootstrap
|
||||
$ make -f examples/Makefile-posix
|
||||
```
|
||||
|
||||
After a successful build, the `elf` files are found in
|
||||
`<path-to-openthread>/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
|
||||
```
|
||||
@@ -32,13 +32,13 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <platform/alarm.h>
|
||||
#include <posix-platform.h>
|
||||
#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;
|
||||
|
||||
+21
-41
@@ -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 <stdint.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#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_
|
||||
@@ -36,25 +36,33 @@
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <platform/alarm.h>
|
||||
#include <platform/serial.h>
|
||||
#include <posix-platform.h>
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include <platform/radio.h>
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#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 };
|
||||
@@ -35,11 +35,11 @@
|
||||
*/
|
||||
|
||||
#include <platform/random.h>
|
||||
#include <posix-platform.h>
|
||||
#include "platform-posix.h"
|
||||
|
||||
static uint32_t s_state = 1;
|
||||
|
||||
void posixPlatformRandomInit(void)
|
||||
void posixRandomInit(void)
|
||||
{
|
||||
s_state = NODE_ID;
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <platform/serial.h>
|
||||
#include <posix-platform.h>
|
||||
#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 };
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 <stdlib.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <cli/cli-serial.h>
|
||||
#include <posix-platform.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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 <stdlib.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <ncp/ncp.h>
|
||||
#include <posix-platform.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user