Rebuild obu-firmware on Niklas Dathe's microbu-firmware
Replace the vanetza-idf port with his current station firmware (microbu-firmware e4e4bd8: main/, components/microbu_v2x, components/vanetza, external/vanetza) and re-apply the MicrOBU additions, each marked "MicrOBU:" in the sources: - V2X_RX (opcode 0x90): every received ITS message, signed or not, through gn_unwrap.c, because the stack drops unsigned and foreign-root traffic. 0x85 is the spec's RAW_FRAME and 0x86 is reserved. The body is built in v2x_rx.hpp. - Unsigned transmission (geonet.c) for security profile 1 or station security 0, from a random MAC per configuration. - Radio polled from STATION_CONFIGURE on; manual country policy, TX power read-back, static RX buffer, short frames ignored. - Battery guard (battery_policy.hpp): deep sleep below 3.30 V with no phone on USB. - No USB writes without a host; last_frame_ms() for the guard. - 80 KB NVS with the app at 0x20000, 8 MB flash, XIAO ESP32-C5 board, 20 dBm. Remove the old C firmware, the bench listener and the old vanetza-idf copy. Add docs/station-link.tex as revision 2 of the interface reference (V2X_RX, unsigned sending, battery rule, revision history). Add 39 host unit tests (make firmware in test/host) next to the existing chain, replay, fuzz and battery tests, and point tools/station_status_watch.py at the new CONFIRM-based status.
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
// a station build that runs out of heap resets the board without a word on the framed log (the panic text
|
||||
// goes to the raw console only). The failed-allocation hook records each failure in RTC memory that survives a
|
||||
// software reset, and the next boot reports it with the reset reason. The hook must not allocate: it only writes
|
||||
// the record and prints with esp_rom_printf.
|
||||
#include "heap_diagnostics.hpp"
|
||||
#include <esp_attr.h>
|
||||
#include <esp_heap_caps.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_rom_sys.h>
|
||||
#include <esp_system.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace microbu::heap_diagnostics {
|
||||
namespace {
|
||||
const char* TAG = "heap";
|
||||
constexpr std::uint32_t kMagic = 0x48454150; // "HEAP"
|
||||
|
||||
struct Record {
|
||||
std::uint32_t magic;
|
||||
std::uint32_t failures; // failed allocations since the record was last reported
|
||||
std::uint32_t size; // of the last failed allocation
|
||||
std::uint32_t caps;
|
||||
std::uint32_t free; // free heap of those caps at that moment
|
||||
std::uint32_t largest; // largest free block of those caps at that moment
|
||||
char function[32];
|
||||
std::uint32_t first_size, first_free, first_largest; // the first failure since the last report
|
||||
};
|
||||
RTC_NOINIT_ATTR Record record;
|
||||
volatile unsigned failed_since_boot = 0;
|
||||
|
||||
void on_failed_allocation(size_t size, uint32_t caps, const char* function_name) {
|
||||
failed_since_boot = failed_since_boot + 1;
|
||||
if (record.magic != kMagic) { record = {}; record.magic = kMagic; }
|
||||
if (record.failures++ == 0) {
|
||||
record.first_size = size;
|
||||
record.first_free = heap_caps_get_free_size(caps);
|
||||
record.first_largest = heap_caps_get_largest_free_block(caps);
|
||||
}
|
||||
record.size = size;
|
||||
record.caps = caps;
|
||||
record.free = heap_caps_get_free_size(caps);
|
||||
record.largest = heap_caps_get_largest_free_block(caps);
|
||||
std::size_t i = 0;
|
||||
for (; function_name && function_name[i] && i + 1 < sizeof(record.function); ++i) record.function[i] = function_name[i];
|
||||
record.function[i] = '\0';
|
||||
esp_rom_printf("heap: allocation of %u bytes (caps 0x%x) failed in %s: free %u, largest block %u\n",
|
||||
unsigned(size), unsigned(caps), function_name ? function_name : "?", unsigned(record.free),
|
||||
unsigned(record.largest));
|
||||
}
|
||||
|
||||
const char* reason_name(esp_reset_reason_t reason) {
|
||||
switch (reason) {
|
||||
case ESP_RST_POWERON: return "power-on";
|
||||
case ESP_RST_EXT: return "external pin";
|
||||
case ESP_RST_SW: return "software (esp_restart)";
|
||||
case ESP_RST_PANIC: return "panic/exception (abort, std::terminate)";
|
||||
case ESP_RST_INT_WDT: return "interrupt watchdog";
|
||||
case ESP_RST_TASK_WDT: return "task watchdog";
|
||||
case ESP_RST_WDT: return "other watchdog";
|
||||
case ESP_RST_DEEPSLEEP: return "deep sleep";
|
||||
case ESP_RST_BROWNOUT: return "brownout";
|
||||
case ESP_RST_SDIO: return "SDIO";
|
||||
case ESP_RST_USB: return "USB peripheral";
|
||||
case ESP_RST_JTAG: return "JTAG";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
unsigned failed_allocations() { return failed_since_boot; }
|
||||
|
||||
void install() {
|
||||
heap_caps_register_failed_alloc_callback(on_failed_allocation);
|
||||
}
|
||||
|
||||
void report_boot() {
|
||||
const auto reason = esp_reset_reason();
|
||||
ESP_LOGI(TAG, "reset reason: %s (%d)", reason_name(reason), int(reason));
|
||||
if (reason == ESP_RST_POWERON || record.magic != kMagic) { // RTC memory is random after power-on
|
||||
record = {};
|
||||
record.magic = kMagic;
|
||||
return;
|
||||
}
|
||||
if (record.failures) {
|
||||
ESP_LOGW(TAG, "before this reset %u allocation(s) failed; first: %u bytes, free %u, largest block %u; "
|
||||
"last: %u bytes (caps 0x%x) in %s, free %u, largest block %u",
|
||||
unsigned(record.failures), unsigned(record.first_size), unsigned(record.first_free),
|
||||
unsigned(record.first_largest), unsigned(record.size), unsigned(record.caps), record.function,
|
||||
unsigned(record.free), unsigned(record.largest));
|
||||
}
|
||||
record.failures = 0;
|
||||
}
|
||||
|
||||
} // namespace microbu::heap_diagnostics
|
||||
Reference in New Issue
Block a user