Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
51d5fb6
update gitignore
Michal-Pogorzelec Oct 7, 2026
0084bdf
removed docs/ dir
Michal-Pogorzelec Oct 7, 2026
7119991
rework to standalone repo
Michal-Pogorzelec Oct 7, 2026
4202ad7
remove link state stub
Michal-Pogorzelec Oct 7, 2026
8c0930d
hard define number of ports
Michal-Pogorzelec Oct 7, 2026
8ea68ca
update prefixes, braces, parenthesis, refactor long function
Michal-Pogorzelec Oct 7, 2026
4396498
move weak source definitions to dedicated dir
Michal-Pogorzelec Oct 7, 2026
098ff07
add more boundary tests
Michal-Pogorzelec Oct 15, 2026
7ae5b9e
update file headers and license update
Michal-Pogorzelec Oct 15, 2026
38504ca
update clang format
Michal-Pogorzelec Oct 15, 2026
b22f38e
add -Werror flag
Michal-Pogorzelec Oct 15, 2026
b097dfc
add sanitize
Michal-Pogorzelec Oct 15, 2026
b2f1fe2
update coverage
Michal-Pogorzelec Oct 15, 2026
37f52f1
update makefile
Michal-Pogorzelec Oct 15, 2026
a3cdde0
add CI
Michal-Pogorzelec Oct 15, 2026
21367e5
add logical address check
Michal-Pogorzelec Oct 15, 2026
71c07ae
cited clauses validation
Michal-Pogorzelec Oct 15, 2026
311ec67
rename virtual channel getter function
Michal-Pogorzelec Oct 15, 2026
04c445d
README update
Michal-Pogorzelec Oct 15, 2026
49f3887
Align CCSDS PTP with ECSS-E-ST-50-53C receive rules and addressing
Michal-Pogorzelec Oct 15, 2026
ef05767
rename sp_packet to sw_ptp
Michal-Pogorzelec Oct 15, 2026
8e6e797
fix overflow for huge valus in spw_packet_build
Michal-Pogorzelec Oct 16, 2026
3e2dd01
do not accept port 0 in sw router
Michal-Pogorzelec Oct 16, 2026
5989d90
move sw_end_marker definition to proper header
Michal-Pogorzelec Oct 16, 2026
665d3a2
Unify return values on sw_status_t
Michal-Pogorzelec Oct 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
Language: C
Language: Cpp
BasedOnStyle: LLVM

# Indentation
Expand All @@ -13,7 +13,7 @@ ColumnLimit: 100

# Braces
BreakBeforeBraces: Allman
InsertBraces: false
InsertBraces: true

# Spaces
SpaceAfterCStyleCast: false
Expand Down Expand Up @@ -58,4 +58,4 @@ MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: false

# Do not indent extern "C" blocks
IndentExternBlock: NoIndent
IndentExternBlock: NoIndent
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
unit-tests:
name: Unit tests and example (${{ matrix.cc }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cc: [gcc, clang]
steps:
- uses: actions/checkout@v4
- name: Build libraries, run both test binaries and the example (-Werror)
run: make CC=${{ matrix.cc }}

coverage:
name: Coverage (100% line and branch)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install gcovr
run: sudo apt-get update && sudo apt-get install -y gcovr
- name: Build instrumented tests, report, and enforce 100% line and branch
run: make coverage-html
- name: Upload HTML report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-html
path: build/coverage/
if-no-files-found: ignore

sanitizers:
name: ASan + UBSan (${{ matrix.cc }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cc: [gcc, clang]
steps:
- uses: actions/checkout@v4
- name: Build and run tests and example under ASan and UBSan
run: make sanitize CC=${{ matrix.cc }}

format:
name: clang-format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format
- name: Check formatting against .clang-format
run: git ls-files '*.c' '*.h' | xargs clang-format --dry-run --Werror
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ build/
.vscode/
.idea/

# Local review notes
TODO.md

3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2026 OpenSpaceCode contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
85 changes: 67 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
CC ?= cc
# Stronger warnings for code quality
CFLAGS ?= -O2 -Iinclude -Wall -Wextra -Wpedantic -Wconversion -Wshadow \
# Optimisation / instrumentation flags; overridden by the sanitize target
OPT ?= -O2
SANITIZE_OPT = -O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined \
-fno-sanitize-recover=all
# Stronger warnings for code quality; any warning fails the build
CFLAGS ?= $(OPT) -Iinclude -Werror -Wall -Wextra -Wpedantic -Wconversion -Wshadow \
-Wcast-align -Wcast-qual -Wpointer-arith -Wformat=2 \
-Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wundef \
-std=c99
AR ?= ar
CFLAGS += -I./external -fPIC
CFLAGS += -fPIC

BUILD_DIR ?= build
OBJ_DIR := $(BUILD_DIR)/obj
Expand All @@ -15,59 +19,80 @@ BIN_DIR := $(BUILD_DIR)/bin
# Source files
CORE_SRCS := src/spacewire_spw_packet.c \
src/spacewire_router.c \
src/spacewire_packet.c

ESP_SRCS := external/EmbeddedSpacePacket/src/space_packet.c
src/spacewire_ptp.c
# Weak default payload hooks, kept apart because an application may replace them.
WEAK_SRCS := src/weak/spacewire_payload.c

EXAMPLE_SRCS := examples/main.c
TEST_SRCS := tests/unit_tests.c \
tests/test_spw_packet.c \
tests/test_router.c \
tests/test_packet.c
tests/test_ptp.c \
tests/test_payload.c
# Linked as an object file, so its strong sw_payload_*() definitions replace the
# library's weak defaults (an override inside a static archive would be ignored).
OVERRIDE_TEST_SRCS := tests/test_payload_override.c

# Object files
CORE_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(CORE_SRCS))
ESP_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(ESP_SRCS))
WEAK_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(WEAK_SRCS))
EXAMPLE_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(EXAMPLE_SRCS))
TEST_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(TEST_SRCS))
OVERRIDE_TEST_OBJS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(OVERRIDE_TEST_SRCS))

# Output files
LIB_STATIC := $(LIB_DIR)/libspacewire.a
LIB_SHARED := $(LIB_DIR)/libspacewire.so
EXAMPLE_BIN := $(BIN_DIR)/spacewire_example
TEST_BIN := $(BIN_DIR)/spacewire_tests
OVERRIDE_TEST_BIN := $(BIN_DIR)/spacewire_override_tests

# The instrumented build lives apart from the normal one and is removed after the run.
SANITIZE_DIR := $(BUILD_DIR)/sanitize
SANITIZE_BINS := spacewire_tests spacewire_override_tests spacewire_example

# Build targets
.PHONY: all clean test example lib coverage-html help distclean
.PHONY: all clean test example lib coverage-html sanitize help distclean

all: lib test
all: lib test example

lib: $(LIB_STATIC) $(LIB_SHARED)

$(LIB_STATIC): $(CORE_OBJS) $(ESP_OBJS)
$(LIB_STATIC): $(CORE_OBJS) $(WEAK_OBJS)
@mkdir -p $(dir $@)
$(AR) rcs $@ $^

$(LIB_SHARED): $(CORE_OBJS) $(ESP_OBJS)
$(LIB_SHARED): $(CORE_OBJS) $(WEAK_OBJS)
@mkdir -p $(dir $@)
$(CC) -shared -o $@ $^

example: $(EXAMPLE_BIN)
$(EXAMPLE_BIN)

$(EXAMPLE_BIN): $(EXAMPLE_OBJS) $(LIB_STATIC)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $^

test: $(TEST_BIN)
./$(TEST_BIN)
test: $(TEST_BIN) $(OVERRIDE_TEST_BIN)
$(TEST_BIN)
$(OVERRIDE_TEST_BIN)

$(TEST_BIN): $(TEST_OBJS) $(LIB_STATIC)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $^

$(OVERRIDE_TEST_BIN): $(OVERRIDE_TEST_OBJS) $(LIB_STATIC)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $^

# -MMD -MP write a .d file next to each object listing the headers it includes, so a
# header edit rebuilds exactly the objects that depend on it.
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
$(CC) $(CFLAGS) -MMD -MP -c -o $@ $<

-include $(CORE_OBJS:.o=.d) $(WEAK_OBJS:.o=.d) $(EXAMPLE_OBJS:.o=.d) $(TEST_OBJS:.o=.d) \
$(OVERRIDE_TEST_OBJS:.o=.d)

clean:
rm -rf $(BUILD_DIR)
Expand All @@ -76,18 +101,42 @@ clean:
coverage-html:
bash tools/coverage_html.sh

# Rebuild with ASan + UBSan and run both test binaries and the example. Program output is
# shown only on failure; sanitizer reports go to stderr and are always visible. The
# instrumented build is removed afterwards, on success and on failure.
sanitize:
@rm -rf $(SANITIZE_DIR)
@$(MAKE) --no-print-directory BUILD_DIR=$(SANITIZE_DIR) OPT="$(SANITIZE_OPT)" \
$(addprefix $(SANITIZE_DIR)/bin/,$(SANITIZE_BINS)) >/dev/null \
|| { rm -rf $(SANITIZE_DIR); exit 1; }
@echo "Sanitizers (ASan + UBSan):"
@for bin in $(SANITIZE_BINS); do \
if ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1 \
$(SANITIZE_DIR)/bin/$$bin >$(SANITIZE_DIR)/$$bin.log; then \
printf ' %-26s no errors detected\n' "$$bin"; \
else \
cat $(SANITIZE_DIR)/$$bin.log; \
printf ' %-26s FAILED\n' "$$bin"; \
rm -rf $(SANITIZE_DIR); \
exit 1; \
fi; \
done
@rm -rf $(SANITIZE_DIR)
@echo "Result: PASS"

distclean: clean
find . -name "*.o" -delete

help:
@echo "EmbeddedSpaceWire Build System"
@echo "=============================="
@echo "Targets:"
@echo " all - Build library and examples (default)"
@echo " all - Build the libraries, run the unit tests and the example (default)"
@echo " lib - Build static and shared libraries"
@echo " example - Build example application"
@echo " test - Build and run unit tests"
@echo " example - Build and run the example application"
@echo " test - Build and run unit tests (default and overridden payload hooks)"
@echo " coverage-html - Generate HTML coverage report"
@echo " sanitize - Build with ASan + UBSan and run the tests and the example"
@echo " output - Build artifacts are written to ./build"
@echo " clean - Remove build artifacts"
@echo " distclean - Clean including object files"
Expand Down
Loading
Loading