diff --git a/debug_log/ring_buffer.h b/debug_log/ring_buffer.h index 5220335..8486171 100644 --- a/debug_log/ring_buffer.h +++ b/debug_log/ring_buffer.h @@ -3,6 +3,9 @@ #include #include +// Fixed-capacity FIFO with wrap-around. push_overwrite drops the oldest entry +// when full -- used by the debug log so dlog never blocks or fails. Iteration +// walks logical positions head..tail, hiding the modular indexing. template struct ring_buffer { std::array data = {}; diff --git a/include/callback_list.h b/include/callback_list.h index acd6af6..2f6a33a 100644 --- a/include/callback_list.h +++ b/include/callback_list.h @@ -1,6 +1,9 @@ #pragma once #include +// Fixed-capacity doubly-linked list with an embedded node array and intrusive +// free list. Used for callback registries (frame callbacks, timers) needing +// O(1) insert/remove with stable handles, without heap in IRQ-adjacent paths. template struct callback_list { struct node { diff --git a/include/parse_buffer.h b/include/parse_buffer.h index 9ee7014..5ff204a 100644 --- a/include/parse_buffer.h +++ b/include/parse_buffer.h @@ -3,6 +3,9 @@ #include #include +// Bounds-checked sequential reader for byte streams. consume() returns a +// typed pointer into the underlying buffer or nullptr on underflow. Used to +// walk packet headers in order without UB and without copies. class parse_buffer { const uint8_t* m_data; size_t m_remaining; diff --git a/include/prepend_buffer.h b/include/prepend_buffer.h index 9dc8155..b05e169 100644 --- a/include/prepend_buffer.h +++ b/include/prepend_buffer.h @@ -4,6 +4,10 @@ #include #include +// Buffer that grows in both directions from a midpoint. Payload is appended at +// the back; each protocol layer then prepends its header in reverse order +// (UDP, then IPv4, then Ethernet) without moving payload bytes. Lets the +// network stack build outbound frames bottom-up with no copies or scratch. template class prepend_buffer { uint8_t m_buf[N]; diff --git a/include/static_vector.h b/include/static_vector.h index df3934c..0a9a449 100644 --- a/include/static_vector.h +++ b/include/static_vector.h @@ -3,6 +3,9 @@ #include #include +// Fixed-capacity contiguous container: std::vector's interface with std::array's +// storage. Used for response payloads sized at parse time but bounded at compile +// time, where heap allocation is unavailable or undesirable. template class static_vector { T m_data[Capacity]; diff --git a/include/timer_queue.h b/include/timer_queue.h index c8c304d..697682e 100644 --- a/include/timer_queue.h +++ b/include/timer_queue.h @@ -9,6 +9,9 @@ struct timer_entry { using timer_handle = callback_list::node*; +// Deadline-sorted callback list with a single hardware alarm armed at the +// head. The alarm IRQ sets a flag; run() drains expired entries on the main +// loop, so callbacks execute in normal context rather than interrupt context. struct timer_queue { callback_list list; alarm_id_t alarm = -1; diff --git a/util/span_writer.h b/util/span_writer.h index 47506d0..d46c1ac 100644 --- a/util/span_writer.h +++ b/util/span_writer.h @@ -4,6 +4,9 @@ #include #include +// Bounded writer over a caller-owned byte buffer. Tracks fill level and a +// sticky overflow flag so packing code can write blindly and check once at the +// end. Unlike std::span, it has a size cursor that grows toward capacity. class span_writer { uint8_t *m_data; size_t m_capacity;