SDK
Builds, linking, data formats, and call order for three C libraries.
On this page
Libraries and version
XTOS provides a user-space SDK for Linux real-time threads. The libraries provide scheduling and memory helpers, signal-processing baselines, and BCI character-device sessions. The application owns thread layout, input validation, device configuration, and recovery; linking the SDK does not enable real-time policy or establish a hardware-to-algorithm validation path.
This page follows the README, SDK headers, and implementation in OpenXTOS v1.0.2 (c24e923717670c4724cdaf24c7c105caee8dc2fb). Limits below describe the released source.
System version and repository channel are separate fields. Read the installed version from /etc/xtos-release; source VERSION pins 1.0.2. Release indexes carry version/channel independently. An older index channel label does not redefine the system version, and the website version does not establish synchronized mirror endpoints.
| Library and headers | Role | Prerequisites |
|---|---|---|
| libxtos-rt: xtos/rt.h, xtos/spsc.h | sched_* for the calling thread, CPU affinity, mlock, and a fixed-capacity SPSC queue. | Linux; policy and memory locking depend on permissions and limits. No BCI device. |
| libxtos-signal: xtos/signal.h | Timestamps, one-sided DFT power, causal IIR, and SSVEP/P300 research features. | Valid numeric arrays and a sample rate; link libm. Synthetic or CSV input is sufficient. |
| libxtos-bci: xtos/bci.h, xtos/bci_uapi.h | open/read/ioctl/mmap session wrappers; device capability comes from the kernel driver. | A matching driver, a registered /dev/xtosN, hardware, and read/write permission. |
Build and link
Run these commands from the OpenXTOS repository root. An SDK build does not require a kernel build. Each library produces a static archive and shared objects. Use the full archive path to avoid a missing runtime path or an older shared library. Headers come from each library’s include directory.
make -C sdk/libxtos-rt all test
make -C sdk/libxtos-signal all test
make -C sdk/libxtos-bci all test
./scripts/check_abi.shIn v1.0.2, BCI make test runs test_samples, test_snapshot, test_snapshot_uapi, test_config, and test_frame, covering FIFO conversion, snapshot lifecycle, UAPI layout, configuration validation, and frame views. These are not physical-device acceptance or exhaustive error-path coverage. ABI checks default to source sdk/; use the override below for staged SDKs.
XTOS_ABI_SDK_ROOT="${BUILD_ROOT:-$PWD/.build}/userspace-source/sdk" ./scripts/check_abi.shgcc -std=c11 -Wall -Wextra -Werror -O2 \
-Isdk/libxtos-signal/include signal-example.c \
sdk/libxtos-signal/libxtos-signal.a -lm -o signal-exampleLink caller objects or source, then the SDK archive, then dependencies; put signal’s -lm last. An RT application using pthread supplies -pthread. For cross builds, CC, AR, headers, archives, application, and target architecture must match; do not reuse a stale .a from another architecture.
ABI macros are in sdk/<library>/include/xtos/*_version.h. Current shared objects are libxtos-*.so.1.0 with SONAME libxtos-*.so.1. Check headers, SONAMEs, and the target driver UAPI together; matching versions do not remove format or capability differences.
Data and ownership
| Object | Units and constraints | Ownership and lifetime |
|---|---|---|
| xtos_sample_frame | timestamp_ns is nonzero nanoseconds; samples_nv has channels int32 nanovolt values; the application defines sequence and quality_flags. | push deep-copies samples; pop writes caller storage and points frame.samples_nv at it. |
| signal | Arrays use double, sample rate is Hz, and P300 windows are milliseconds; the application keeps amplitude units consistent. | The caller provides arrays, results, and filter state; FFT/SSVEP allocate temporary heap memory. |
| Locked memory | length is a positive byte count, not a sample count. | alloc_locked returns caller-owned memory; free_locked requires the original pointer and length. |
| BCI session and mapping | Input range is integer mV and impedance is integer kΩ; read_samples returns float microvolts, while versioned snapshot/frame views retain int32 nanovolts. | The session owns its fd, frame buffers, and snapshot mappings. get_fd borrows the fd; views expire according to their interface lifetime. Legacy get_mmap_buffer is unsupported. |
v1.0.2 read_samples numerically converts int32 nanovolts to float microvolts. int32 nanovolts from the raw fd or versioned snapshot/frame views need numeric division by 1000.0 for microvolts, not a pointer cast. Promote values individually for double DSP and preserve units; do not divide read_samples microvolts by 1000 again. CSV can enter signal without the driver.
Calls and errors
- Prepare: inspect device capability, sample rate, and channels; create queues; allocate and touch working memory; initialize one filter per channel.
- Threads: set scheduling and affinity in the worker that will run, then read the policy back. The two settings are not a rollback transaction.
- Run: the acquisition thread checks time and frame boundaries before push; one consumer pops, converts units, filters continuously, and extracts window features. Define the full-queue drop or load-reduction policy.
- Stop: request stop and join workers before destroying queues, sessions, or locked memory. Do not destroy objects while push/pop or borrowed mappings are in use.
Most int interfaces return 0 or -1 with errno; pointer interfaces return NULL on failure. Read errno only after failure; success does not clear an old value. Save it before printing, cleanup, or another call. A void destructor cannot report cleanup failure.
Real-time calls
SCHED_FIFO/SCHED_RR does not bound all calls. Queue push/pop do not allocate; creation/destruction do. FFT/SSVEP allocate internally. BCI read_samples mallocs/frees a raw integer buffer on every call and may block in multiple reads while filling the request; it is not an allocation-free, RT-safe acquisition interface. ioctl, printf, and file I/O may also wait.
Keep high-priority work to acquisition and frame transfer; run window algorithms and logging separately. Measure worst service time, queue level, rejections, and sequence gaps. mlock reduces paging risk only for its range; it does not guarantee zero faults, jitter, or a deadline.
Sources: sdk/libxtos-rt/src/rt.c and spsc.c; sdk/libxtos-signal/src/signal.c; sdk/libxtos-bci/src/session.c.
Validate deterministic input under ordinary scheduling first, then permission failures, full queues, anomalous timestamps, and the target device.
QEMU boot and SDK tests do not replace physical acquisition, latency measurement, or electrode-quality validation.