From e8ca4c3fde17c6b0215ed848576540cc2c07faab Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Wed, 30 Sep 2015 21:19:59 -0400 Subject: [PATCH] UAVCAN: Add example application --- canutils/uavcan/Makefile | 6 +- canutils/uavcan/platform_stm32.cpp | 17 ++--- examples/Kconfig | 1 + examples/uavcan/Kconfig | 33 ++++++++++ examples/uavcan/Make.defs | 39 +++++++++++ examples/uavcan/Makefile | 42 ++++++++++++ examples/uavcan/uavcan_main.cxx | 101 +++++++++++++++++++++++++++++ 7 files changed, 226 insertions(+), 13 deletions(-) create mode 100644 examples/uavcan/Kconfig create mode 100644 examples/uavcan/Make.defs create mode 100644 examples/uavcan/Makefile create mode 100644 examples/uavcan/uavcan_main.cxx diff --git a/canutils/uavcan/Makefile b/canutils/uavcan/Makefile index 590cef404..72346f49f 100644 --- a/canutils/uavcan/Makefile +++ b/canutils/uavcan/Makefile @@ -159,8 +159,10 @@ libuavcan: $(LIBUAVCAN_UNPACKNAME) $(DSDL_UNPACKNAME) $(PYUAVCAN_UNPACKNAME) dsdlc_generated: libuavcan $(info $(shell $(LIBUAVCAN_DSDLC) $(UAVCAN_DSDL_DIR))) -$(APPDIR)/include/uavcan: libuavcan/libuavcan/include/uavcan - $(Q) cp -R libuavcan/libuavcan/include/uavcan $(APPDIR)/include +$(APPDIR)/include/uavcan: libuavcan/libuavcan/include/uavcan dsdlc_generated/uavcan + $(Q) mkdir -p $(APPDIR)/include/uavcan + $(Q) cp -R libuavcan/libuavcan/include/uavcan/* $(APPDIR)/include/uavcan + $(Q) cp -R dsdlc_generated/uavcan/* $(APPDIR)/include/uavcan $(CXXOBJS): %$(OBJEXT): %$(CXXEXT) $(call COMPILEXX, $<, $@) diff --git a/canutils/uavcan/platform_stm32.cpp b/canutils/uavcan/platform_stm32.cpp index 27cd72155..596b3eb69 100644 --- a/canutils/uavcan/platform_stm32.cpp +++ b/canutils/uavcan/platform_stm32.cpp @@ -66,11 +66,6 @@ static void delay_callable() * Public Functions ****************************************************************************/ -uavcan::ISystemClock& getSystemClock() -{ - return uavcan_stm32::SystemClock::instance(); -} - uavcan::ICanDriver& getCanDriver() { static bool initialized = false; @@ -83,13 +78,8 @@ uavcan::ICanDriver& getCanDriver() int retries = 0; #endif - for (;;) + while (can.init(delay_callable, bitrate) < 0) { - if (can.init(delay_callable, bitrate) >= 0) - { - break; - } - #if CONFIG_UAVCAN_INIT_RETRIES > 0 retries++; if (retries >= CONFIG_UAVCAN_INIT_RETRIES) @@ -104,3 +94,8 @@ uavcan::ICanDriver& getCanDriver() return can.driver; } + +uavcan::ISystemClock& getSystemClock() +{ + return uavcan_stm32::SystemClock::instance(); +} diff --git a/examples/Kconfig b/examples/Kconfig index c0540f518..c3349e487 100644 --- a/examples/Kconfig +++ b/examples/Kconfig @@ -74,6 +74,7 @@ source "$APPSDIR/examples/thttpd/Kconfig" source "$APPSDIR/examples/timer/Kconfig" source "$APPSDIR/examples/tiff/Kconfig" source "$APPSDIR/examples/touchscreen/Kconfig" +source "$APPSDIR/examples/uavcan/Kconfig" source "$APPSDIR/examples/udp/Kconfig" source "$APPSDIR/examples/udpblaster/Kconfig" source "$APPSDIR/examples/discover/Kconfig" diff --git a/examples/uavcan/Kconfig b/examples/uavcan/Kconfig new file mode 100644 index 000000000..9f29497b7 --- /dev/null +++ b/examples/uavcan/Kconfig @@ -0,0 +1,33 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_UAVCAN + bool "UAVCAN example" + default n + depends on CANUTILS_UAVCAN && LIB_BOARDCTL + ---help--- + Enable the UAVCAN example + +if EXAMPLES_UAVCAN + +config EXAMPLES_UAVCAN_NODE_MEM_POOL_SIZE + int "Node Memory Pool Size" + default 4096 + ---help--- + Specifies the node's memory pool size + +config EXAMPLES_UAVCAN_NODE_ID + int "Node ID" + default 0 + ---help--- + Specifies the node's ID + +config EXAMPLES_UAVCAN_NODE_NAME + string "Node Name" + default "org.nuttx.apps.examples.uavcan" + ---help--- + Specifies the node's name + +endif diff --git a/examples/uavcan/Make.defs b/examples/uavcan/Make.defs new file mode 100644 index 000000000..e72f62ca2 --- /dev/null +++ b/examples/uavcan/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/examples/uavcan/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. +# Author: Paul Alexander Patience +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_EXAMPLES_UAVCAN),y) +CONFIGURED_APPS += examples/uavcan +endif diff --git a/examples/uavcan/Makefile b/examples/uavcan/Makefile new file mode 100644 index 000000000..8d5df1888 --- /dev/null +++ b/examples/uavcan/Makefile @@ -0,0 +1,42 @@ +############################################################################ +# apps/examples/uavcan/Makefile +# +# Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. +# Author: Paul Alexander Patience +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +-include $(TOPDIR)/Make.defs + +MAINSRC = uavcan_main.cxx + +CXXFLAGS += -I$(TOPDIR)/include/apps + +include $(APPDIR)/Application.mk diff --git a/examples/uavcan/uavcan_main.cxx b/examples/uavcan/uavcan_main.cxx new file mode 100644 index 000000000..74f8924a0 --- /dev/null +++ b/examples/uavcan/uavcan_main.cxx @@ -0,0 +1,101 @@ +/**************************************************************************** + * examples/uavcan/uavcan_main.cxx + * + * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. + * Author: Paul Alexander Patience + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef CONFIG_BUILD_KERNEL +extern "C" +{ + int uavcan_main(int argc, FAR char *argv[]); +} +#endif + +uavcan::ICanDriver& getCanDriver(); +uavcan::ISystemClock& getSystemClock(); + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uavcan_main + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int uavcan_main(int argc, FAR char *argv[]) +#endif +{ + uavcan::Node + node(getCanDriver(), getSystemClock()); + int ret; + + node.setNodeID(CONFIG_EXAMPLES_UAVCAN_NODE_ID); + node.setName(CONFIG_EXAMPLES_UAVCAN_NODE_NAME); + + ret = node.start(); + if (ret < 0) + { + std::fprintf(stderr, "ERROR: node.start failed: %d\n", ret); + return EXIT_FAILURE; + } + + node.setModeOperational(); + + for (;;) + { + ret = node.spin(uavcan::MonotonicDuration::fromMSec(100)); + if (ret < 0) + { + std::fprintf(stderr, "ERROR: node.spin failed: %d\n", ret); + } + } + + return EXIT_SUCCESS; +}