C · STAR-API · GNU Autotools

SpaceWire Software Collection

A set of small command-line tools for the STAR-Dundee Brick Mk3: loopback, RMAP write and read, packet send and receive, error injection and time-codes.

They were written at IAA-CSIC to bring up and configure the GR718B SpaceWire router of the PLATO Main Electronic Units, and to learn how to package a C project properly with Autoconf and Automake.

# generate configure and Makefile.in
$ autoreconf -vis
# point configure at the STAR-System SDK
$ env CPPFLAGS='-I/usr/local/STAR-Dundee/STAR-System/inc/star/' \
      LDFLAGS='-L…' ./configure
checking star-api.h presence... yes
config.status: creating src/Makefile
$ make
# write a GR718B port control register over RMAP
$ ./src/rmap -a 0x00000884 -d 0x000000FF -t 2
$ ./src/rd_rmap -a 0x00000884 -t 2
9Tools built
Mk3STAR-Dundee Brick
GR718BRouter under test
100Mbit/s links
RMAPRegister access
2017–21Development

Overview

SpaceWire is the point-to-point data link used on most ESA spacecraft. The STAR-Dundee Brick Mk3 is a USB interface with SpaceWire links that lets a PC act as a node on the network. Its vendor library, the STAR-API, exposes devices, channels and transfer operations.

What the collection does

Each tool is a short C program that does one thing on the network: open a channel on a Brick link, build a packet or an RMAP command, submit the transfer operation and print what came back. Options are parsed with getopt, so the tools can be chained from shell scripts.

The first program was a 64-byte loopback: Brick link 1 sends a packet with a one-byte address path, the GR718B routes it to port 2, and Brick link 2 receives it. Without the router the packet arrives with the path byte still in the header and is flagged as wrong.

Why it exists

The PLATO Main Electronic Units use a GR718B radiation-tolerant router to connect the instrument control unit, the six N-DPUs and the power supplies. On the test bench, the router ports, link rates and routing tables are set by RMAP writes from the ground equipment.

These tools did that job on the bench. The scripts/ folder holds the bash sequences that configure Router A of MEU 1 and check the links.

Loopback setup from test_loopback.c: 64-byte packets, both Brick links set to 100 Mbit/s (clock multiplier 2, divisor 4).

Built with GNU Autotools

The project started with a hand-written Makefile and moved to Autoconf and Automake on its second day. Two short input files replace the Makefile, and the generated configure script does the portability work: it finds the compiler, checks that the vendor SDK is installed, and writes Makefiles with the standard targets.

autoreconf -vis

Runs aclocal, autoconf, autoheader and automake, and installs the helper scripts.

configure.ac, Makefile.am → configure, Makefile.in
./configure

Probes the system and stops early if the STAR-API header is missing.

Makefile.in → Makefile, config.h
make

Builds the nine programs, each linked against the STAR libraries it needs.

src/*.c → src/loopback, src/rmap…
make dist

Packs a source tarball that builds with only a C compiler and make.

→ spw-software-collection-1.0.tar.gz

configure.ac

AC_INIT([SpW Software Collection], [1.0], [jmgomez@iaa.es]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_CHECK_HEADER(star-api.h, [AC_DEFINE(HAVE_STAR_H, 1, ...)], [AC_MSG_ERROR([Could not locate STAR-API ...])]) AC_OUTPUT
  • foreign tells Automake not to demand the GNU set of files (NEWS, AUTHORS, ChangeLog).
  • -Wall -Werror turns Automake warnings into errors, so a bad Makefile.am fails at once.
  • AC_CHECK_HEADER is the useful part: if the proprietary SDK is not on the include path, configure stops with a message that says which CPPFLAGS to pass, instead of a compiler error halfway through the build.

src/Makefile.am

bin_PROGRAMS = list inject_error loopback rmap rd_rmap \ receiv send timecode reset loopback_SOURCES = test_loopback.c utility.c loopback_LDADD = -lstar_conf_api_brick_mk3 \ -lstar_conf_api_mk2 -lstar_conf_api_router -lstar-api rmap_SOURCES = test_rmap.c utility.c rmap_LDADD = ... -lstar-api -lrmap_packet_library timecode_LDADD = -lpthread ... -lrmap_packet_library
  • One line per program and one line for its libraries. Adding a tool is two lines, and Automake writes the compile, link, install, clean and dependency rules.
  • The top-level Makefile.am is two lines: SUBDIRS = src and dist_doc_DATA = README.md.
  • For free you get make install, make dist, make distclean and make TAGS for Emacs navigation.

Out-of-tree builds

scripts/build.sh builds in a separate build/ folder by calling ../configure from inside it. Objects and binaries stay out of the source tree, and .gitignore lists every file Autotools generates, so the repository holds only the two inputs and the sources.

mkdir -p build && cd build env CPPFLAGS='-I/usr/local/STAR-Dundee/STAR-System/inc/star/' \ LDFLAGS='-L…' ../configure make

Lessons

  • For a vendor SDK in a non-standard path, a header check in configure.ac plus a clear error message saves more time than any amount of README.
  • Keep generated files out of git. The commented-out LIBSTAR lines in configure.ac show the next step: an AC_CHECK_LIB per STAR library, so the link step is checked as well as the header.
  • The per-program _LDADD lists repeat the same libraries. A shared variable or LIBS set by configure would shorten Makefile.am to one line per tool.

The tools

Nine programs are built by default. Most share the same options: -a address (hex), -d data (hex), -t timeout in ms, -v verbose, -i flash the Brick LEDs to identify it, and in some tools -s to pick a Brick by serial number when several are connected.

BinarySourceWhat it does
listtest_list_devices.cLists the STAR-Dundee devices on USB with name and serial number, and can identify or reset them.
loopbacktest_loopback.cSends a packet on link 1 through the router and checks it arrives on link 2.
rmaptest_rmap.cRMAP write: puts a 32-bit value into a router register (-a, -d).
rd_rmaptest_read_rmap.cRMAP read: reads a register and decodes the reply header and status.
sendtest_send.cSends a single packet on one link.
receivtest_receiv.cReceives packets continuously on one link and stores them in a file.
inject_errortest_error.cSends a packet split into data chunks with a disconnect or parity error in the middle, to exercise error handling on the link.
timecodetest_timecode.cTransmits SpaceWire time-codes from one thread while another receives packets.
resettest_reset_dev.cResets the Brick.

Also in src/, not in the default build: router set-up experiments (test_static_routing.c, test_la_routing.c, test_la2_routing.c, test_routing_NDPU.c), multi-packet RMAP loads (load_reg.c, stipa.c, apus.c) and disable_if.c. utility.c holds packet-dump and buffer helpers taken from the STAR-Dundee example code.

Configuring the GR718B

The router is configured through its port 0 with RMAP writes. Once rmap and rd_rmap worked, configuring a whole router became a shell script: one line per register.

scripts/rtr1A_config.sh (excerpt)

# check status, then enable ports at 100 or 10 Mbit/s ./src/rd_rmap -a ${ROUTER_LINK_RUN_STATUS_REGISTER} -t 1 ./src/rmap -a ${RTR_PCTRL_PORT_1} \ -d ${RTR_PCTRL_PORT_VALUE_START_AND_100MHZ} -t 1 ./src/rmap -a ${RTR_PCTRL_PORT_6} \ -d ${RTR_PCTRL_PORT_VALUE_START_AND_10MHZ} -t 1 ./src/rmap -a ${RTR_PCTRL_PORT_4} \ -d ${RTR_PCTRL_PORT_VALUE_DISABLE_PORT} -t 1

Register addresses and values live in scripts/router_defs.sh, so the same names are used by every script.

Scripts

rtr1A_config.shPort control and routing tables for Router A of MEU 1.
get_rtr1A_status.shReads back port and link status.
rtr1A_loopback_check.shChecks the links after configuration.
rtrBroadcast_config.shSets up and tests broadcast routing.
rtr_sist_test.shPort 1 error clearing and SIST port status.
router_defs.shRegister map shared by the scripts.
grmon_script.shPort control writes as GRMON wmem commands.

Documentation/ keeps the reference router configuration and constants used in the ground support equipment for the MEU router, and notes on decoding RMAP read replies.

History

Loopback through the GR718B

First test: 64-byte packets at 100 Mbit/s from Brick link 1 to link 2 through the router. The next day the project moved from a Makefile to Autotools.

RMAP write and read

First RMAP write packet to router register 0x808, then the read command.

Router examples

Routing configuration examples and continuous packet reception.

Tools for the PLATO MEU

Out-of-tree build, rmap and rd_rmap with options, reset command, and the first script to configure Router A of MEU 1. Broadcast test.

Device list, send, error injection

Tools to find connected Bricks, send single packets and inject disconnect errors, with two test descriptions of the verification procedure.

SIST port and reference configuration

Script to check the SIST port status, and the reference router constants from the ground equipment.

Code map

configure.acAutoconf input: compiler and STAR-API checks.
src/Makefile.amAutomake input: the nine programs and their libraries.
src/Tool sources, utility.c and system_config.h (MEU logical and physical addresses).
scripts/Build script and router configuration sequences.
Documentation/Router constants and RMAP reply notes.

Requirements

  • Linux with gcc, make, autoconf and automake.
  • A STAR-Dundee Brick Mk3 and the STAR-System SDK, which provides star-api.h, the configuration libraries and the RMAP packet library. The SDK is proprietary and is not included.
  • A GR718B, or any SpaceWire router, for the loopback and RMAP tests.

Further reading