spi-hdlc-adapter: New Linux userspace SPI-HDLC adapter (#232)

`spi-hdlc-adapter` is an adapter tool for using a SPI interface as if
it were an HDLC-lite encoded bidirectional asynchronous serial stream.
It uses the SPI protocol outlined in [Appendix A.2][1] of the Spinel
protocol document.

Note that since we don't have a slave implementation of this protocol,
this adapter hasn't been well tested yet. You have to start somewhere.

[1]: https://goo.gl/bwHt5r
This commit is contained in:
Robert Quattlebaum
2016-07-06 18:53:33 -07:00
committed by Jonathan Hui
parent 8ef67d223b
commit 862edfb1de
7 changed files with 1406 additions and 0 deletions
+2
View File
@@ -42,6 +42,7 @@ SUBDIRS = \
third_party \
examples \
tests \
tools \
doc \
$(NULL)
@@ -73,6 +74,7 @@ PRETTY_SUBDIRS = \
include \
src \
tests \
tools \
$(NULL)
#
+2
View File
@@ -561,6 +561,8 @@ examples/apps/ncp/Makefile
examples/platforms/Makefile
examples/platforms/cc2538/Makefile
examples/platforms/posix/Makefile
tools/Makefile
tools/spi-hdlc-adapter/Makefile
tests/Makefile
tests/scripts/Makefile
tests/unit/Makefile
+51
View File
@@ -0,0 +1,51 @@
#
# 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 = \
spi-hdlc-adapter \
$(NULL)
# Always build (e.g. for 'make all') these subdirectories.
SUBDIRS = \
$(NULL)
if OPENTHREAD_TARGET_LINUX
SUBDIRS += spi-hdlc-adapter
endif
# Always pretty (e.g. for 'make pretty') these subdirectories.
PRETTY_SUBDIRS = \
$(NULL)
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
+2
View File
@@ -0,0 +1,2 @@
spi-hdlc-adapter
+50
View File
@@ -0,0 +1,50 @@
#
# 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 = README.md .gitignore
bin_PROGRAMS = \
spi-hdlc-adapter \
$(NULL)
spi_hdlc_adapter_CPPFLAGS = \
$(NULL)
spi_hdlc_adapter_LDADD = \
$(NULL)
spi_hdlc_adapter_LDFLAGS = \
$(NULL)
spi_hdlc_adapter_SOURCES = \
spi-hdlc-adapter.c \
$(NULL)
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
+58
View File
@@ -0,0 +1,58 @@
SPI/HDLC Adaptor
================
`spi-hdlc-adapter` is an adapter tool for using a SPI interface as if
it were an HDLC-lite encoded bidirectional asynchronous serial stream.
It uses the SPI protocol outlined in [Appendix A.2][1] of the Spinel
protocol document.
[1]: https://goo.gl/bwHt5r
## Syntax ##
spi-hdlc-adapter [options] <spi-device-path>
## Options ##
* `--stdio`: Use `stdin` and `stdout` for HDLC input/output. Useful
when directly started by the program that will be using it.
* `--pty`: Create a pseudo terminal for HDLC input/output. The path
of the newly-created PTY will be written to `stdout`, followed by
a newline.
* `--gpio-int[=gpio-path]`: Specify a path to the Linux
sysfs-exported GPIO directory for the `I̅N̅T̅` pin. If not
specified, `spi-hdlc-adapter` will fall back to polling, which is
inefficient.
* `--gpio-reset[=gpio-path]`: Specify a path to the Linux
sysfs-exported GPIO directory for the `R̅E̅S̅` pin.
* `--spi-mode[=mode]`: Specify the SPI mode to use (0-3).
* `--spi-speed[=hertz]`: Specify the SPI speed in hertz.
* `--verbose`: Increase debug verbosity.
* `--help`: Print out usage information to `stdout` and exit.
`spi-device-path` is a required argument since it indicates which SPI
device to use. An example path might be `/dev/spidev1.0`.
The GPIO paths are to the top-level directory for that GPIO. They must
be already be exported before `spi-hdlc-adapter` can use them.
## Behavior ##
If an MCU reset is detected by the reset bit being set on a SPI frame,
the special vendor-specific HDLC-lite symbol `0xF8` is emitted. If
`--gpio-reset` is specified, the HDLC client can trigger an MCU reset
by sending the symbols `0x7E 0x13 0x11 0x7E` or by sending `SIGUSR1`.
When started, `spi-hdlc-adapter` will configure the following
properties on the GPIOs:
1. Set `I̅N̅T̅/direction` to `in`.
2. Set `I̅N̅T̅/edge` to `falling`.
3. Set `R̅E̅S̅/direction` to `high`.
When resetting the slave device, `spi-hdlc` performs the following
procedure:
1. Set `R̅E̅S̅/direction` to `low`.
2. Sleep for 30ms.
3. Set `R̅E̅S̅/direction` to `high`.
File diff suppressed because it is too large Load Diff