Deniz Gursoy Electrical Engineering at UPenn · Hardware Design, Robotics, and Embedded Systems
All projects

Embedded · Simulation

FreeRTOS battery-module CAN node, simulated

A FreeRTOS telemetry node for one module of a battery pack, simulated on a laptop: the firmware runs on the FreeRTOS POSIX port with a modeled CAN controller, sensor front end and watchdog.

Dates
Nov 2026 to now
Context
Personal project
Role
Solo
Status
In progress: phases 0 to 3 of 8 done
Timeline of CAN frames from the node: an overvoltage bit sets and clears, then a hung sensor task ends in a watchdog reset and a restart.
0 to 3 of 8phases finished; the A/B bootloader is next
978Python tests pass in CI, plus 55 C test runs under sanitizers
99.8%line coverage of the portable C library in CI
9logged bugs, each re-created by a patch and caught again in CI

It publishes end-to-end protected telemetry, records faults as UDS-style diagnostic trouble codes and resets itself when a task hangs. Phases 0 to 3 of 8 are finished; the A/B bootloader, UDS firmware download and a Cortex-M3 build in QEMU are still to come.

The problem

A battery-module node reports cell voltages, temperatures and current on CAN, flags faults and recovers when its own firmware hangs. I wanted it built and tested on a laptop and in CI, with no board on the bench.

So the node runs as a Linux process on the FreeRTOS POSIX port. That port's tick runs slow against the wall clock, and a plain socket delivers every frame instantly and intact, which hides what a real bus does.

What I built

A host platform layer removes three errors of the port without touching the V11.3.3 kernel. It locks the tick to CLOCK_MONOTONIC at link time, delivers simulated interrupts through lock-free rings and measures each task's real stack peak.

Five statically allocated tasks read a deterministic sensor model, filter the readings in fixed point and publish eight cyclic messages defined in a DBC file. Five of them carry AUTOSAR E2E (end-to-end) Profile 11 protection: a CRC and a rolling counter.

Faults come from outside, as on a bench: a control channel shorts the bus, opens a sense wire or hangs the sensor read.

  • CAN controller model with exact stuffed frame lengths, arbitration and Bosch fault confinement, over SocketCAN or a UDP virtual bus.
  • Sixteen faults mapped to 24-bit trouble codes with the ISO 14229-1 (UDS) status byte.
  • AUTOSAR-style alive supervision gating an STM32 independent watchdog (IWDG) model, with the reset cause kept in a CRC-checked retained RAM cell.
  • C11 under -Werror, with cppcheck's MISRA C:2012 addon and clang-tidy in CI.

Results

As of Nov 21, 2026, 978 Python tests pass in CI, plus 55 C test runs under AddressSanitizer and UBSan. Line coverage of the portable library is 99.8%. The E2E code matches an independent Python implementation on 20,193 requests.

On the laptop the locked tick measured 1000.1 µs, against 1128.8 µs for the stock port. When I hang the sensor read, the bus shows SAMPLE_TIMEOUT after about 100 ms and SUPERVISION_EXPIRED after about 300 ms. About 700 ms after the hang the watchdog resets the node.

A response-time analysis finds every task schedulable with the design budgets. The CAN transmit task is tightest: 973 µs worst case against a 1000 µs deadline. Moving the trouble-code work into the processing task would raise that to 1209 µs, so the lowest-priority task owns the codes.

The bug log holds nine defects: seven found in reviews of phases 0 and 1, two by tests as the code was written. CI re-creates each one from a patch and checks that its tests fail.

Telemetry decoded from the bus, simulated sensor front end
Two plots over 21 seconds: pack current stepping through rest, discharge, peak and charge, and eight cell voltages sagging under load.
Response-time analysis with design budgets, not measurements
Bar list of seven tasks and interrupts showing worst-case response time as a share of each deadline; can_tx uses 973 of 1000 microseconds.
Host platform layer: tick accuracy and interrupt latency, host timing
Histogram of a 10 ms task's wake-up interval for the stock port and the locked tick, beside cumulative latency curves for two ways of delivering a simulated interrupt.

Limits and next steps

None of this has run on a microcontroller. Every timing figure belongs to a laptop, and the execution-time budgets are design figures until phase 6 measures them. The bus model works on whole frames, with no bit timing or CAN FD.

Trouble codes live in RAM for now, so a reset loses them. The MISRA check is cppcheck's addon with documented deviations, which falls short of a compliance claim.

Phase 4 adds a simulated NOR flash and an A/B bootloader. After that come ISO-TP and UDS firmware download, measurements, and a Cortex-M3 build in QEMU.

Ask a question about this project

An AI assistant answers from this site's text. It can be wrong; this page is the source.