Keep Full C3 Companion queues within the DRAM budget

Place 32 existing retained frames in RTC FAST without changing the 224 normal or 128 active-OTA queue capacities. Keep the default backing layout unchanged for other boards and cover ownership, wraparound and OTA transfers.
This commit is contained in:
mikecarper committed 2026-10-27 08:17:23 -07:00
1 parent d1a2fd74ba
commit cfcfc832b1
8 files changed
+213 -32

No files matched your search

+16 -3
View File
@@ -6,16 +6,28 @@
namespace mesh {
template<class Frame, size_t Count> class InlineRetainedFrames {
Frame frames[Count];
public:
static constexpr size_t frame_count = Count;
Frame& at(size_t index) { return frames[index]; }
};
// One owner at a time: an offline FIFO borrows the workspace's storage while
// idle. Switching owners compacts the ring in place, without allocating RAM or
// dropping unread frames. The caller owns the FIFO's length and head index.
template<class Frame, size_t Capacity, size_t Reserved, class Workspace>
// Qualified boards can supply a physically separate retained-frame bank. It
// replaces only existing retained slots, never the extra frames or workspace.
template<class Frame, size_t Capacity, size_t Reserved, class Workspace,
class RetainedFrames = InlineRetainedFrames<Frame, Reserved>>
class BorrowableFrameBuffer {
static_assert(Reserved > 0 && Reserved < Capacity, "Invalid shared queue capacities");
static_assert(RetainedFrames::frame_count == Reserved,
"The retained backing must preserve every active-OTA slot");
struct ExtraFrames { Frame frames[Capacity - Reserved]; };
static_assert(sizeof(Workspace) <= sizeof(ExtraFrames), "mOTA exceeds borrowed queue storage");
Frame _retained[Reserved];
RetainedFrames _retained;
union Extra {
ExtraFrames queue;
Workspace workspace;
@@ -45,6 +57,7 @@ class BorrowableFrameBuffer {
public:
BorrowableFrameBuffer() = default;
BorrowableFrameBuffer(Frame* fast, Frame* slow) : _retained(fast, slow) {}
BorrowableFrameBuffer(const BorrowableFrameBuffer&) = delete;
BorrowableFrameBuffer& operator=(const BorrowableFrameBuffer&) = delete;
~BorrowableFrameBuffer() {
@@ -53,7 +66,7 @@ public:
size_t capacity() const { return _borrowed ? Reserved : Capacity; }
Frame& at(size_t physical_index) {
return physical_index < Reserved ? _retained[physical_index]
return physical_index < Reserved ? _retained.at(physical_index)
: _extra.queue.frames[physical_index - Reserved];
}
+6 -2
View File
@@ -16,8 +16,7 @@
#if !defined(ESP32_PLATFORM) || !defined(COMPANION_RADIO_FULL)
#error "RTC offline frames require a qualified ESP32 Full Companion recipe"
#endif
#if defined(BOARD_HAS_PSRAM) || defined(OTA_SHARED_COMPANION_QUEUE) \
|| ONE_KEY_DM_SHARED_OFFLINE_QUEUE
#if defined(BOARD_HAS_PSRAM) || ONE_KEY_DM_SHARED_OFFLINE_QUEUE
#error "RTC offline frames require the independent fixed-capacity queue"
#endif
#include <sdkconfig.h>
@@ -36,6 +35,10 @@
#if COMPANION_RTC_SLOW_OFFLINE_FRAMES && !defined(CONFIG_IDF_TARGET_ESP32S3)
#error "The separate RTC SLOW offline-frame bank requires ESP32-S3"
#endif
#if defined(OTA_SHARED_COMPANION_QUEUE) \
&& (!defined(CONFIG_IDF_TARGET_ESP32C3) || COMPANION_RTC_SLOW_OFFLINE_FRAMES)
#error "RTC retained shared-OTA frames are qualified only on ESP32-C3 FAST memory"
#endif
namespace mesh {
namespace companion_rtc {
@@ -75,6 +78,7 @@ template<typename Frame, size_t Count> class CompanionRtcQueue {
}
public:
static constexpr size_t frame_count = Count;
CompanionRtcQueue(Frame* fast, Frame* slow) : fast_frames(fast), slow_frames(slow) {
if ((FastCount && (!fast || reinterpret_cast<uintptr_t>(fast) % 4))
|| (SlowCount && (!slow || reinterpret_cast<uintptr_t>(slow) % 4))) abort();