| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the CC-BY-ND as described in the | ||
| 10 | * included LICENSE.CC-BY-ND file. This file may be modified for | ||
| 11 | * personal use, but modified copies MAY NOT be redistributed in any form. | ||
| 12 | */ | ||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #include <unistd.h> | ||
| 18 | |||
| 19 | #include "FalconV5Support.h" | ||
| 20 | |||
| 21 | #include <stdexcept> | ||
| 22 | #include "OutputMonitor.h" | ||
| 23 | #include "Warnings.h" | ||
| 24 | #include "common.h" | ||
| 25 | #include "settings.h" | ||
| 26 | #include "channeloutput/PixelString.h" | ||
| 27 | #include "channeloutput/serialutil.h" | ||
| 28 | #include "util/GPIOUtils.h" | ||
| 29 | |||
| 30 | #include "util/BBBPruUtils.h" | ||
| 31 | #include "pru/SMEMRing.hp" | ||
| 32 | #include "util/BBBUtils.h" | ||
| 33 | #include <sys/wait.h> | ||
| 34 | #include <arm_neon.h> | ||
| 35 | |||
| 36 | extern "C" { | ||
| 37 | bool encodeFalconV5Packet(const Json::Value& description, uint8_t* packet); | ||
| 38 | bool decodeFalconV5Packet(uint8_t* packet, Json::Value& result); | ||
| 39 | } | ||
| 40 | |||
| 41 | class FalconV5Listener { | ||
| 42 | public: | ||
| 43 | 35 | FalconV5Listener(const Json::Value& config) { | |
| 44 |
2/4✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
|
35 | pin = config["pin"].asString(); |
| 45 |
1/2✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
|
35 | const PinCapabilities& p = PinCapabilities::getPinByName(pin); |
| 46 | // the cape config comes from the cape EEPROM; a pin this board does | ||
| 47 | // not have fails the output (Init() catches this) instead of being | ||
| 48 | // dereferenced as null below | ||
| 49 |
3/4✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 34 times.
|
35 | if (p.ptr() == nullptr) { |
| 50 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | throw std::runtime_error("FalconV5 listener pin '" + pin + "' does not exist on this board"); |
| 51 | } | ||
| 52 |
3/6✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 34 times.
✗ Branch 5 not taken.
|
136 | p.configPin("pru0in", false, "FalconV5 Listener"); |
| 53 | |||
| 54 |
1/2✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
|
34 | const BBBPinCapabilities* pc = (const BBBPinCapabilities*)p.ptr(); |
| 55 | 34 | offset = pc->pruPin(0); | |
| 56 | 35 | } | |
| 57 | 34 | ~FalconV5Listener() { | |
| 58 | 34 | const PinCapabilities& p = PinCapabilities::getPinByName(pin); | |
| 59 | 34 | p.releasePin(); | |
| 60 | 34 | } | |
| 61 | std::string pin; | ||
| 62 | int offset = 0; | ||
| 63 | }; | ||
| 64 | |||
| 65 | // structure of the data at the start of the PRU ram | ||
| 66 | // that the pru program expects to see | ||
| 67 | typedef struct { | ||
| 68 | // 0xFFFF to abort | ||
| 69 | volatile uint32_t command; | ||
| 70 | // bytes captured in the last completed listen window. Written by the | ||
| 71 | // listener only when the string PRU closes the window, never while a | ||
| 72 | // capture is in progress; 'captures' is bumped right after it, so a | ||
| 73 | // changed count means a new, complete length is there to read. | ||
| 74 | volatile uint32_t length; | ||
| 75 | volatile uint32_t captures; | ||
| 76 | // 1 from the moment a listen window opens until the capture is published. | ||
| 77 | // The ARM reads it before and after copying the buffer: a window can open | ||
| 78 | // while the ARM is still reading the previous capture (the frame tick | ||
| 79 | // lands inside the next window whenever a frame overran its period), and | ||
| 80 | // the listener then overwrites the buffer from the start, splicing the | ||
| 81 | // new reply's head onto the old reply's tail. Two replies scrambled with | ||
| 82 | // different random keys decode into garbage that still parses. | ||
| 83 | volatile uint32_t busy; | ||
| 84 | } __attribute__((__packed__)) FalconV5PRUData; | ||
| 85 | |||
| 86 | class PRUControl { | ||
| 87 | public: | ||
| 88 | 40 | PRUControl() { | |
| 89 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | const std::string filename = "/opt/fpp/src/non-gpl/FalconV5Support/FalconV5PRUListener_pru0.out"; |
| 90 | |||
| 91 |
3/8✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
20 | pru = new BBBPru(0, true, false); |
| 92 | 20 | pruData = (FalconV5PRUData*)pru->data_ram; | |
| 93 | 20 | data = pru->shared_ram; | |
| 94 | // never clear the shared RAM here: on the AM62x the string PRU's | ||
| 95 | // data ring lives there and is already attached and live by the | ||
| 96 | // time the listener starts - zeroing its counters desyncs the ring | ||
| 97 | // and wedges the string PRU in its ring wait. The listener's own | ||
| 98 | // state lives in PRU0's data RAM (still cleared above) and the | ||
| 99 | // capture bytes are rewritten before each capture completes. | ||
| 100 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | pru->run(filename, false); |
| 101 | 20 | } | |
| 102 | 20 | ~PRUControl() { | |
| 103 | 20 | pruData->command = 0xFFFF; | |
| 104 | 20 | __asm__ __volatile__("" :: | |
| 105 | : "memory"); | ||
| 106 | 20 | pru->stop(); | |
| 107 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | delete pru; |
| 108 | 20 | } | |
| 109 | |||
| 110 | BBBPru* pru = nullptr; | ||
| 111 | FalconV5PRUData* pruData = nullptr; | ||
| 112 | uint8_t* data = nullptr; | ||
| 113 | }; | ||
| 114 | |||
| 115 | // a round of queries starts at least this often when the spacing is | ||
| 116 | // automatic: every receiver is still polled about twice a second | ||
| 117 | static constexpr float MAX_QUERY_ROUND_US = 500000.0f; | ||
| 118 | // the automatic spacing keeps the average query cost below this share of the | ||
| 119 | // period's slack | ||
| 120 | static constexpr float QUERY_SLACK_MARGIN = 0.8f; | ||
| 121 | |||
| 122 | 25 | FalconV5Support::FalconV5Support() { | |
| 123 | // one object per output init, so a config reload re-reads the override | ||
| 124 |
2/4✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
|
25 | queryRestOverride = std::clamp(getSettingInt("FalconV5QueryRestFrames", -1), -1, 10000); |
| 125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (queryRestOverride >= 0) { |
| 126 | ✗ | queryRestFrames = queryRestOverride; | |
| 127 | ✗ | LogInfo(VB_CHANNELOUT, "FalconV5: FalconV5QueryRestFrames = %d (test override of the automatic query spacing)\n", queryRestOverride); | |
| 128 | } | ||
| 129 |
1/2✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
|
25 | OutputMonitor::INSTANCE.setSmartReceiverEventCallback([this](int port, int index, const std::string& cmd) { |
| 130 | 285 | PendingToggle pt; | |
| 131 | 285 | pt.port = (int16_t)port; | |
| 132 | 285 | pt.index = (uint8_t)index; | |
| 133 |
2/4✓ Branch 0 taken 285 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 285 times.
✗ Branch 3 not taken.
|
285 | if (cmd == "ToggleOutput") { |
| 134 | 285 | pt.cmd = ToggleCommand::Toggle; | |
| 135 | ✗ | } else if (cmd == "ResetOutput") { | |
| 136 | ✗ | pt.cmd = ToggleCommand::Reset; | |
| 137 | } else { | ||
| 138 | 8 | return; | |
| 139 | } | ||
| 140 | { | ||
| 141 |
1/2✓ Branch 0 taken 285 times.
✗ Branch 1 not taken.
|
285 | std::unique_lock<std::mutex> lock(queriedPortsLock); |
| 142 |
7/10✓ Branch 0 taken 285 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 277 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 277 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 277 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 277 times.
|
285 | if (port < 0 || port >= (int)queriedPorts.size() || !queriedPorts[port]) { |
| 143 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | LogDebug(VB_CHANNELOUT, "FalconV5: %s for port %d dropped, no queried V5 chain covers it\n", cmd.c_str(), port); |
| 144 | 8 | return; | |
| 145 | } | ||
| 146 |
2/2✓ Branch 0 taken 277 times.
✓ Branch 1 taken 8 times.
|
285 | } |
| 147 | 277 | pendingToggle.store(pt); | |
| 148 | }); | ||
| 149 | 25 | } | |
| 150 | 25 | FalconV5Support::~FalconV5Support() { | |
| 151 | 25 | OutputMonitor::INSTANCE.setSmartReceiverEventCallback(nullptr); | |
| 152 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 25 times.
|
53 | for (auto rc : receiverChains) { |
| 153 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | delete rc; |
| 154 | } | ||
| 155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | for (auto& p : muxPins) { |
| 156 | ✗ | p->releasePin(); | |
| 157 | } | ||
| 158 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 25 times.
|
59 | for (auto l : listeners) { |
| 159 |
1/2✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
|
34 | delete l; |
| 160 | } | ||
| 161 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 5 times.
|
25 | if (pru) { |
| 162 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | delete pru; |
| 163 | } | ||
| 164 | 25 | listeners.clear(); | |
| 165 | 25 | receiverChains.clear(); | |
| 166 | 25 | } | |
| 167 | 21 | void FalconV5Support::addListeners(const Json::Value& config) { | |
| 168 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 20 times.
|
55 | for (int x = 0; x < config["listenerPins"].size(); x++) { |
| 169 |
8/14✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 34 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 34 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 34 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
|
36 | listeners.push_back(new FalconV5Listener(config["listenerPins"][x])); |
| 170 | } | ||
| 171 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (!listeners.empty()) { |
| 172 |
2/6✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
20 | pru = new PRUControl(); |
| 173 | } | ||
| 174 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | for (int x = 0; x < config["muxPins"].size(); x++) { |
| 175 | ✗ | std::string p = config["muxPins"][x].asString(); | |
| 176 | ✗ | if (PinCapabilities::getPinByName(p).ptr() == nullptr) { | |
| 177 | ✗ | throw std::runtime_error("FalconV5 mux pin '" + p + "' does not exist on this board"); | |
| 178 | } | ||
| 179 | ✗ | muxPins.push_back(PinCapabilities::getPinByName(p).ptr()); | |
| 180 | ✗ | muxPins.back()->configPin("gpio", true, "FalconV5 Mux Pin"); | |
| 181 | ✗ | muxPins.back()->setValue(0); | |
| 182 | ✗ | } | |
| 183 | 20 | } | |
| 184 | |||
| 185 | 7144 | static inline void maskBit(int len, int bit, uint8_t* s, uint8_t* d) { | |
| 186 | 7144 | uint8_t m1 = 1 << bit; | |
| 187 | 7144 | const uint8x8_t bitmask = { m1, m1, m1, m1, m1, m1, m1, m1 }; | |
| 188 | 7144 | int idx = 0; | |
| 189 |
2/2✓ Branch 0 taken 6228960 times.
✓ Branch 1 taken 7144 times.
|
6236104 | while (idx < len) { |
| 190 | 6228960 | uint8x8_t work = vld1_u8(s); // load 8 bytes | |
| 191 | 6228960 | uint8x8_t msk = vand_u8(work, bitmask); | |
| 192 | vst1_u8(d, msk); | ||
| 193 | 6228960 | s += 8; | |
| 194 | 6228960 | d += 8; | |
| 195 | 6228960 | idx += 8; | |
| 196 | } | ||
| 197 | 7144 | } | |
| 198 | ✗ | static void printDataBuf(int len, uint8_t* data) { | |
| 199 | ✗ | printf("Len: %d \n", len); | |
| 200 | ✗ | for (int x = 0; x < 40; x++) | |
| 201 | ✗ | printf("%02X %s", data[x], (x % 5 != 4 ? "" : " ")); | |
| 202 | ✗ | printf("\n"); | |
| 203 | ✗ | for (int x = 0; x < 40; x++) | |
| 204 | ✗ | printf("%02X %s", data[x + 40], (x % 5 != 4 ? "" : " ")); | |
| 205 | ✗ | printf("\n"); | |
| 206 | ✗ | for (int x = 0; x < 40; x++) | |
| 207 | ✗ | printf("%02X %s", data[x + 80], (x % 5 != 4 ? "" : " ")); | |
| 208 | ✗ | printf("\n\n"); | |
| 209 | ✗ | } | |
| 210 | 121597 | static uint8_t readByte(uint8_t* data, int& pos) { | |
| 211 | 121597 | constexpr int superSample = 5; | |
| 212 | 121597 | constexpr int sampleOffset = 2; | |
| 213 | // find start bit | ||
| 214 | 121597 | uint8_t ret = 0; | |
| 215 |
2/2✓ Branch 0 taken 44452389 times.
✓ Branch 1 taken 121597 times.
|
44573986 | while (data[pos] != 0) { |
| 216 | 44452389 | ++pos; | |
| 217 | } | ||
| 218 | 121597 | pos += sampleOffset + superSample; | |
| 219 |
2/2✓ Branch 0 taken 58596 times.
✓ Branch 1 taken 63001 times.
|
121597 | if (data[pos]) |
| 220 | 58596 | ret |= 0x1; | |
| 221 | 121597 | pos += superSample; | |
| 222 |
2/2✓ Branch 0 taken 63625 times.
✓ Branch 1 taken 57972 times.
|
121597 | if (data[pos]) |
| 223 | 63625 | ret |= 0x2; | |
| 224 | 121597 | pos += superSample; | |
| 225 |
2/2✓ Branch 0 taken 57406 times.
✓ Branch 1 taken 64191 times.
|
121597 | if (data[pos]) |
| 226 | 57406 | ret |= 0x4; | |
| 227 | 121597 | pos += superSample; | |
| 228 |
2/2✓ Branch 0 taken 59917 times.
✓ Branch 1 taken 61680 times.
|
121597 | if (data[pos]) |
| 229 | 59917 | ret |= 0x8; | |
| 230 | 121597 | pos += superSample; | |
| 231 |
2/2✓ Branch 0 taken 63287 times.
✓ Branch 1 taken 58310 times.
|
121597 | if (data[pos]) |
| 232 | 63287 | ret |= 0x10; | |
| 233 | 121597 | pos += superSample; | |
| 234 |
2/2✓ Branch 0 taken 60735 times.
✓ Branch 1 taken 60862 times.
|
121597 | if (data[pos]) |
| 235 | 60735 | ret |= 0x20; | |
| 236 | 121597 | pos += superSample; | |
| 237 |
2/2✓ Branch 0 taken 57952 times.
✓ Branch 1 taken 63645 times.
|
121597 | if (data[pos]) |
| 238 | 57952 | ret |= 0x40; | |
| 239 | 121597 | pos += superSample; | |
| 240 |
2/2✓ Branch 0 taken 54386 times.
✓ Branch 1 taken 67211 times.
|
121597 | if (data[pos]) |
| 241 | 54386 | ret |= 0x80; | |
| 242 | 121597 | pos += superSample; // should be in the stop bit now | |
| 243 | 121597 | return ret; | |
| 244 | } | ||
| 245 | |||
| 246 | 22 | float FalconV5Support::queryFrameShare() const { | |
| 247 | 22 | return queryFrameShare(queryRestFrames); | |
| 248 | } | ||
| 249 | |||
| 250 | 36 | int FalconV5Support::queriedReceivers() const { | |
| 251 | 36 | int receivers = 0; | |
| 252 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
|
72 | for (auto c : maxCount) { |
| 253 | 36 | receivers += c; | |
| 254 | } | ||
| 255 | 36 | return receivers; | |
| 256 | } | ||
| 257 | |||
| 258 | 36 | int FalconV5Support::queriedMuxes() const { | |
| 259 | 36 | int muxes = 0; | |
| 260 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 36 times.
|
72 | for (auto c : maxCount) { |
| 261 |
1/2✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
|
36 | if (c > 0) { |
| 262 | 36 | muxes++; | |
| 263 | } | ||
| 264 | } | ||
| 265 | 36 | return muxes; | |
| 266 | } | ||
| 267 | |||
| 268 | 32 | float FalconV5Support::queryFrameShare(int restFrames) const { | |
| 269 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 28 times.
|
32 | if (!pru) { |
| 270 | 4 | return 0.0f; | |
| 271 | } | ||
| 272 | 28 | int receivers = queriedReceivers(); | |
| 273 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (receivers == 0) { |
| 274 | ✗ | return 0.0f; | |
| 275 | } | ||
| 276 | 28 | return (float)receivers / (float)(receivers + queriedMuxes() * (1 + restFrames)); | |
| 277 | } | ||
| 278 | |||
| 279 | 10 | bool FalconV5Support::setFrameBudget(float frameRate, int frameTimeWithoutQueriesUs, int queryFrameCostUs) { | |
| 280 | 10 | int rest = queryRestFrames; | |
| 281 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (queryRestOverride >= 0) { |
| 282 | ✗ | rest = queryRestOverride; | |
| 283 |
7/10✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 2 times.
|
10 | } else if (frameRate > 0.0f && frameTimeWithoutQueriesUs > 0 && queryFrameCostUs > 0 && queryFrameShare(0) > 0.0f) { |
| 284 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | const int receivers = queriedReceivers(); |
| 285 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | const float muxes = (float)queriedMuxes(); |
| 286 | 8 | const float periodUs = 1000000.0f / frameRate; | |
| 287 | 8 | const float slackUs = periodUs - (float)frameTimeWithoutQueriesUs; | |
| 288 | // a round is one frame per query plus (1 + rest) rest frames per mux; | ||
| 289 | // the cap keeps a round within MAX_QUERY_ROUND_US | ||
| 290 | 8 | int maxRest = (int)((MAX_QUERY_ROUND_US / periodUs - (float)receivers) / muxes) - 1; | |
| 291 | 8 | maxRest = std::max(0, maxRest); | |
| 292 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (slackUs >= (float)queryFrameCostUs) { |
| 293 | // a query frame fits as it is: keep the fast status updates | ||
| 294 | 8 | rest = 0; | |
| 295 | ✗ | } else if (slackUs <= 0.0f) { | |
| 296 | // over budget without any queries: poll as rarely as the cap | ||
| 297 | // allows and leave the rest to the over-budget warning | ||
| 298 | ✗ | rest = maxRest; | |
| 299 | } else { | ||
| 300 | // the smallest rest whose average query cost fits the slack: | ||
| 301 | // share(rest) * cost <= target <=> muxes * (1 + rest) >= receivers * (cost - target) / target | ||
| 302 | ✗ | const float targetUs = slackUs * QUERY_SLACK_MARGIN; | |
| 303 | ✗ | const float need = (float)receivers * ((float)queryFrameCostUs - targetUs) / (targetUs * muxes) - 1.0f; | |
| 304 | ✗ | rest = std::clamp((int)std::ceil(need), 0, maxRest); | |
| 305 | } | ||
| 306 | } | ||
| 307 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | if (rest == queryRestFrames) { |
| 308 | 10 | return false; | |
| 309 | } | ||
| 310 | ✗ | queryRestFrames = rest; | |
| 311 | ✗ | LogInfo(VB_CHANNELOUT, "FalconV5: %d extra rest frame(s) per query round at %.4g fps -> queries on %.1f%% of frames\n", | |
| 312 | queryRestFrames, frameRate, queryFrameShare() * 100.0f); | ||
| 313 | ✗ | return true; | |
| 314 | } | ||
| 315 | |||
| 316 | 219725 | void FalconV5Support::stageListenerData() { | |
| 317 |
2/2✓ Branch 0 taken 16154 times.
✓ Branch 1 taken 203571 times.
|
219725 | if (!pru) { |
| 318 | 218832 | return; | |
| 319 | } | ||
| 320 | // The listener publishes the length and bumps the capture count only | ||
| 321 | // when the string PRU closes the window, and holds 'busy' from the | ||
| 322 | // moment a window opens until then. A window can open while we are | ||
| 323 | // still copying the previous capture (the frame tick lands inside the | ||
| 324 | // next window whenever a frame overran its period), and the listener | ||
| 325 | // then overwrites the buffer from the start, splicing the new reply's | ||
| 326 | // head onto the old reply's tail - two replies scrambled with different | ||
| 327 | // random keys, which decode into garbage that still parses. So: count | ||
| 328 | // first, copy, then busy and count again; anything that moved means the | ||
| 329 | // copy is a splice and is dropped. The next query repeats the question. | ||
| 330 | // both the pump thread and the output thread may call this | ||
| 331 |
1/2✓ Branch 0 taken 203571 times.
✗ Branch 1 not taken.
|
203571 | std::unique_lock<std::mutex> lock(stageLock); |
| 332 | 203571 | uint32_t busy0 = pru->pruData->busy; | |
| 333 | 203571 | uint32_t captures = pru->pruData->captures; | |
| 334 |
2/2✓ Branch 0 taken 202113 times.
✓ Branch 1 taken 1458 times.
|
203571 | if (captures == lastCaptures) { |
| 335 | 202113 | return; | |
| 336 | } | ||
| 337 | 1458 | lastCaptures = captures; | |
| 338 | 1458 | uint32_t len = pru->pruData->length; | |
| 339 | // the listener stops storing at its shared RAM reservation; on the | ||
| 340 | // AM62x the string PRU's ring starts immediately above it | ||
| 341 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1458 times.
|
1458 | if (len > SMEM_RING_LISTENER_BYTES) { |
| 342 | ✗ | len = SMEM_RING_LISTENER_BYTES; | |
| 343 | } | ||
| 344 |
2/2✓ Branch 0 taken 564 times.
✓ Branch 1 taken 894 times.
|
1458 | if (!len) { |
| 345 | 564 | return; | |
| 346 | } | ||
| 347 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 892 times.
|
894 | if (stageBuf.size() < SMEM_RING_LISTENER_BYTES + 8) { |
| 348 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | stageBuf.resize(SMEM_RING_LISTENER_BYTES + 8); |
| 349 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | workBuf.resize(SMEM_RING_LISTENER_BYTES + 8); |
| 350 | } | ||
| 351 | // copy exactly len: the listener publishes whole 32 byte stores, so len | ||
| 352 | // is a multiple of the 8 bytes maskBit() reads at a time, and the clamp | ||
| 353 | // above keeps it inside the capture reservation. Reading past it ran off | ||
| 354 | // the end of the AM335x's 12KB shared RAM. | ||
| 355 |
1/2✓ Branch 0 taken 894 times.
✗ Branch 1 not taken.
|
894 | pru->pru->memcpyToPRU(&stageBuf[0], pru->data, len); |
| 356 | 894 | uint32_t busy1 = pru->pruData->busy; | |
| 357 | 894 | uint32_t captures2 = pru->pruData->captures; | |
| 358 |
4/6✓ Branch 0 taken 893 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 893 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 893 times.
|
894 | if (busy0 || busy1 || captures2 != captures) { |
| 359 | 1 | lastCaptures = captures2; | |
| 360 | 1 | ++tornCaptures; | |
| 361 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogExcess(VB_CHANNELOUT, "FalconV5: listener capture %u overwritten while being read, dropped (%u so far)\n", captures, tornCaptures); |
| 362 | 1 | return; | |
| 363 | } | ||
| 364 | 893 | stageLen = len; | |
| 365 | 893 | stageValid = true; | |
| 366 |
2/2✓ Branch 0 taken 893 times.
✓ Branch 1 taken 202678 times.
|
203571 | } |
| 367 | |||
| 368 | 5518 | void FalconV5Support::processListenerData() { | |
| 369 |
2/2✓ Branch 0 taken 152 times.
✓ Branch 1 taken 5366 times.
|
5518 | if (!pru) { |
| 370 | 152 | return; | |
| 371 | } | ||
| 372 | // no pump thread polling for us (AM335x), or it has not looked yet | ||
| 373 | 5366 | stageListenerData(); | |
| 374 | 5366 | uint32_t len = 0; | |
| 375 | { | ||
| 376 |
1/2✓ Branch 0 taken 5366 times.
✗ Branch 1 not taken.
|
5366 | std::unique_lock<std::mutex> lock(stageLock); |
| 377 |
2/2✓ Branch 0 taken 4473 times.
✓ Branch 1 taken 893 times.
|
5366 | if (!stageValid) { |
| 378 | 4473 | return; | |
| 379 | } | ||
| 380 | 893 | std::swap(stageBuf, workBuf); | |
| 381 | 893 | len = stageLen; | |
| 382 | 893 | stageValid = false; | |
| 383 |
2/2✓ Branch 0 taken 893 times.
✓ Branch 1 taken 4473 times.
|
5366 | } |
| 384 | 893 | uint8_t* buf = &workBuf[0]; | |
| 385 |
2/2✓ Branch 0 taken 7144 times.
✓ Branch 1 taken 893 times.
|
8037 | for (auto& l : listeners) { |
| 386 | // readByte() walks up to a byte cell past 'len' while finishing the | ||
| 387 | // last byte, so the sample buffer carries a zeroed tail for it | ||
| 388 | uint8_t data[SMEM_RING_LISTENER_BYTES + 64]; | ||
| 389 | uint8_t packet[1024]; | ||
| 390 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
7144 | maskBit(len, l->offset, buf, data); |
| 391 | 7144 | memset(data + len, 0, 64); | |
| 392 | 7144 | int pidx = 0; | |
| 393 | 7144 | int pos = 0; | |
| 394 |
2/2✓ Branch 0 taken 121597 times.
✓ Branch 1 taken 7144 times.
|
128741 | while (pos < len) { |
| 395 | 121597 | packet[pidx++] = readByte(data, pos); | |
| 396 | } | ||
| 397 |
2/2✓ Branch 0 taken 893 times.
✓ Branch 1 taken 6251 times.
|
7144 | if (pidx > 1) { |
| 398 | // printf("L: %d\n", l->offset); | ||
| 399 | // printDataBuf(len, data); | ||
| 400 | // printDataBuf(pidx, packet); | ||
| 401 |
1/2✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
|
893 | Json::Value json; |
| 402 |
4/8✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 893 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 893 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 893 times.
✗ Branch 7 not taken.
|
893 | if (pidx != 0 && decodeFalconV5Packet(packet, json)) { |
| 403 |
2/4✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 893 times.
✗ Branch 3 not taken.
|
893 | int port = json["port"].asInt(); |
| 404 | // printf("Port: %d Index: %d\n", port, json["index"].asInt()); | ||
| 405 | // printf("%s\n", SaveJsonToString(json, " ").c_str()); | ||
| 406 |
2/2✓ Branch 0 taken 893 times.
✓ Branch 1 taken 893 times.
|
1786 | for (auto& rc : receiverChains) { |
| 407 |
1/2✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
|
893 | if (rc->getPixelStrings()[0]->m_portNumber == port) { |
| 408 |
1/2✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
|
893 | rc->handleQueryResponse(json); |
| 409 | } | ||
| 410 | } | ||
| 411 | } | ||
| 412 | 893 | } | |
| 413 | } | ||
| 414 | } | ||
| 415 | |||
| 416 | ✗ | void FalconV5Support::setCurrentMux(int i) { | |
| 417 | ✗ | curMux = i; | |
| 418 | ✗ | for (auto& p : muxPins) { | |
| 419 | ✗ | int d = i & 0x1; | |
| 420 | ✗ | p->setValue(d); | |
| 421 | ✗ | i >>= 1; | |
| 422 | } | ||
| 423 | ✗ | } | |
| 424 | 28 | FalconV5Support::ReceiverChain::ReceiverChain(PixelString* p1, PixelString* p2, PixelString* p3, PixelString* p4, int grp, int m, bool so) : | |
| 425 | 28 | group(grp), mux(m), numReceivers(1), sendOnly(so) { | |
| 426 | 28 | strings[0] = p1; | |
| 427 | 28 | strings[1] = p2; | |
| 428 | 28 | strings[2] = p3; | |
| 429 | 28 | strings[3] = p4; | |
| 430 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 28 times.
|
140 | for (auto& s : strings) { |
| 431 | // a chain head in the last three strings has fewer than four | ||
| 432 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
|
112 | if (s == nullptr) { |
| 433 | ✗ | continue; | |
| 434 | } | ||
| 435 | 112 | uint32_t srCount = 1; | |
| 436 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 112 times.
|
224 | for (auto& vs : s->m_virtualStrings) { |
| 437 |
2/4✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 112 times.
|
112 | if (vs.isFalconV5SmartReceiver()) { |
| 438 | ✗ | srCount++; | |
| 439 | } | ||
| 440 | } | ||
| 441 | 112 | numReceivers = std::max(numReceivers, srCount); | |
| 442 | } | ||
| 443 | 28 | } | |
| 444 | 28 | FalconV5Support::ReceiverChain* FalconV5Support::addReceiverChain(PixelString* p1, PixelString* p2, PixelString* p3, PixelString* p4, int group, int m, bool sendOnly) { | |
| 445 | // the mux comes from the cape config (falconV5ListenerMux); a negative | ||
| 446 | // one compares as huge against the sizes below and grew maxCount until | ||
| 447 | // memory ran out | ||
| 448 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27 times.
|
28 | if (m < 0) { |
| 449 | 1 | m = 0; | |
| 450 | } | ||
| 451 |
3/8✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 28 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
28 | FalconV5Support::ReceiverChain* rc = new FalconV5Support::ReceiverChain(p1, p2, p3, p4, group, m, sendOnly); |
| 452 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | receiverChains.push_back(rc); |
| 453 | |||
| 454 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 24 times.
|
28 | if (sendOnly) { |
| 455 | // V4 chains only get the config packet: keep them out of the query | ||
| 456 | // scheduling entirely so no query/listen frames are generated | ||
| 457 | 4 | return rc; | |
| 458 | } | ||
| 459 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
|
24 | if (m >= queryData.size()) { |
| 460 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | queryData.resize(m + 1); |
| 461 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | while (m >= maxCount.size()) { |
| 462 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | maxCount.push_back(0); |
| 463 | } | ||
| 464 | } | ||
| 465 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | queryData[m][group].push_back(rc); |
| 466 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | if (p1 && p1->m_portNumber >= 0) { |
| 467 | // generateDynamicPacket() hands a toggle to the chain whose first | ||
| 468 | // port is within 4 below it | ||
| 469 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | std::unique_lock<std::mutex> lock(queriedPortsLock); |
| 470 | 24 | size_t end = (size_t)p1->m_portNumber + 4; | |
| 471 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (queriedPorts.size() < end) { |
| 472 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | queriedPorts.resize(end, false); |
| 473 | } | ||
| 474 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 24 times.
|
120 | for (size_t p = p1->m_portNumber; p < end; p++) { |
| 475 |
1/2✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
|
96 | queriedPorts[p] = true; |
| 476 | } | ||
| 477 | 24 | } | |
| 478 | |||
| 479 | // A round of queries needs as many frames as the receivers of ONE listener | ||
| 480 | // group, not of all groups together: every group's front chain is queried | ||
| 481 | // in the same frame and all replies land in the one listen window (the | ||
| 482 | // listener captures every group's pin). Summing the groups made n blocks | ||
| 483 | // of one receiver cost n query frames per rest frame and asked each chain | ||
| 484 | // n times per round. Take the largest group instead. | ||
| 485 | 24 | int newM = 0; | |
| 486 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 24 times.
|
54 | for (auto& g : queryData[m]) { |
| 487 | 30 | int inGroup = 0; | |
| 488 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 30 times.
|
61 | for (auto& rc : g.second) { |
| 489 | 31 | inGroup += rc->getReceiverCount(); | |
| 490 | } | ||
| 491 | 30 | newM = std::max(newM, inGroup); | |
| 492 | } | ||
| 493 | 24 | maxCount[m] = std::max(maxCount[m], newM); | |
| 494 | 24 | return rc; | |
| 495 | } | ||
| 496 | |||
| 497 | 112 | static bool generateConfigJSONForPixelString(const PixelString* p, Json::Value& config) { | |
| 498 |
5/6✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
✓ Branch 3 taken 33 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 69 times.
|
112 | if (p && (p->smartReceiverType == PixelString::ReceiverType::FalconV5 || p->smartReceiverType == PixelString::ReceiverType::FalconV4)) { |
| 499 |
1/2✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
|
43 | Json::Value v; |
| 500 |
3/6✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 43 times.
✗ Branch 5 not taken.
|
43 | v["startChannels"].append(0); |
| 501 | |||
| 502 | 43 | int srCount = 0; | |
| 503 | 43 | int curChanCount = 0; | |
| 504 |
2/2✓ Branch 0 taken 43 times.
✓ Branch 1 taken 43 times.
|
86 | for (auto& vs : p->m_virtualStrings) { |
| 505 | 43 | curChanCount += vs.chMapCount; | |
| 506 |
2/4✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 43 times.
|
43 | if (vs.isFalconV5SmartReceiver()) { |
| 507 | ✗ | srCount++; | |
| 508 | ✗ | v["startChannels"].append(curChanCount); | |
| 509 | } | ||
| 510 | } | ||
| 511 | 43 | srCount++; | |
| 512 |
3/6✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 43 times.
✗ Branch 5 not taken.
|
43 | v["startChannels"].append(curChanCount); |
| 513 |
2/4✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✗ Branch 3 not taken.
|
43 | config["ports"].append(v); |
| 514 | 43 | return true; | |
| 515 | 43 | } | |
| 516 |
1/2✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
|
69 | Json::Value v; |
| 517 |
3/6✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
69 | v["startChannels"].append(0); |
| 518 |
2/4✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | config["ports"].append(v); |
| 519 | 69 | return false; | |
| 520 | 69 | } | |
| 521 | 28 | bool FalconV5Support::ReceiverChain::generateConfigPacket(uint8_t* packet) const { | |
| 522 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | Json::Value config; |
| 523 |
2/4✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
28 | config["type"] = "config"; |
| 524 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | bool hasSR = generateConfigJSONForPixelString(strings[0], config); |
| 525 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | hasSR |= generateConfigJSONForPixelString(strings[1], config); |
| 526 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | hasSR |= generateConfigJSONForPixelString(strings[2], config); |
| 527 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | hasSR |= generateConfigJSONForPixelString(strings[3], config); |
| 528 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | if (hasSR) { |
| 529 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | return encodeFalconV5Packet(config, packet); |
| 530 | } | ||
| 531 | ✗ | return false; | |
| 532 | 28 | } | |
| 533 | 1460 | bool FalconV5Support::ReceiverChain::generateQueryPacket(uint8_t* packet, int receiver) const { | |
| 534 |
1/2✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
|
1460 | Json::Value config; |
| 535 |
2/4✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1460 times.
✗ Branch 3 not taken.
|
1460 | config["type"] = "query"; |
| 536 |
2/4✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1460 times.
✗ Branch 3 not taken.
|
1460 | config["receiver"] = receiver; |
| 537 |
1/2✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
|
2920 | return encodeFalconV5Packet(config, packet); |
| 538 | 1460 | } | |
| 539 | ✗ | bool FalconV5Support::ReceiverChain::generateToggleEFusePacket(uint8_t* packet, int receiver, int port) const { | |
| 540 | ✗ | Json::Value config; | |
| 541 | ✗ | config["type"] = "toggleFuse"; | |
| 542 | ✗ | config["receiver"] = receiver; | |
| 543 | ✗ | config["port"] = port; | |
| 544 | ✗ | return encodeFalconV5Packet(config, packet); | |
| 545 | ✗ | } | |
| 546 | |||
| 547 | 24 | bool FalconV5Support::ReceiverChain::generateNumberPackets(uint8_t* packet, uint8_t* packet2) const { | |
| 548 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | Json::Value config; |
| 549 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | config["type"] = "number"; |
| 550 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | config["port"] = strings[0]->m_portNumber; |
| 551 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | config["phase"] = 1; |
| 552 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | if (encodeFalconV5Packet(config, packet)) { |
| 553 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | config["phase"] = 2; |
| 554 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | return encodeFalconV5Packet(config, packet2); |
| 555 | } | ||
| 556 | ✗ | return false; | |
| 557 | 24 | } | |
| 558 | ✗ | bool FalconV5Support::ReceiverChain::generateResetEFusePacket(uint8_t* packet, int receiver, int port) const { | |
| 559 | ✗ | Json::Value config; | |
| 560 | ✗ | config["type"] = "resetFuses"; | |
| 561 | ✗ | config["receiver"] = receiver; | |
| 562 | ✗ | config["port"] = port; | |
| 563 | ✗ | return encodeFalconV5Packet(config, packet); | |
| 564 | ✗ | } | |
| 565 | |||
| 566 | 24 | bool FalconV5Support::ReceiverChain::generateSetFusesPacket(uint8_t* packet, bool on) const { | |
| 567 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | Json::Value config; |
| 568 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | config["type"] = "setFuses"; |
| 569 |
3/6✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
|
24 | config["state"] = on ? 1 : 0; |
| 570 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
48 | return encodeFalconV5Packet(config, packet); |
| 571 | 24 | } | |
| 572 | |||
| 573 | ✗ | bool FalconV5Support::ReceiverChain::generateResetFusesPacket(uint8_t* packet) const { | |
| 574 | ✗ | Json::Value config; | |
| 575 | ✗ | config["type"] = "resetFuses"; | |
| 576 | ✗ | return encodeFalconV5Packet(config, packet); | |
| 577 | ✗ | } | |
| 578 | 1460 | bool FalconV5Support::ReceiverChain::generateQueryPacket(uint8_t* packet) { | |
| 579 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1460 times.
|
1460 | if (curReceiverQuery == numReceivers) { |
| 580 | ✗ | curReceiverQuery = 0; | |
| 581 | } | ||
| 582 | 1460 | return generateQueryPacket(packet, curReceiverQuery++); | |
| 583 | } | ||
| 584 | ✗ | bool FalconV5Support::ReceiverChain::generatePixelCountPacket(uint8_t* packet) const { | |
| 585 | ✗ | Json::Value config; | |
| 586 | ✗ | config["type"] = "pixelCount"; | |
| 587 | ✗ | return encodeFalconV5Packet(config, packet); | |
| 588 | ✗ | } | |
| 589 | |||
| 590 | 893 | void FalconV5Support::ReceiverChain::handleQueryResponse(Json::Value& json) { | |
| 591 | try { | ||
| 592 |
2/4✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 893 times.
✗ Branch 3 not taken.
|
893 | int index = json["index"].asInt(); |
| 593 |
2/4✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 893 times.
✗ Branch 3 not taken.
|
893 | int port = json["port"].asInt(); |
| 594 |
2/4✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 893 times.
✗ Branch 3 not taken.
|
893 | int dial = json["dial"].asInt(); |
| 595 | // decoded from a reply on the wire; a receiver has at most 4 ports | ||
| 596 |
3/6✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 893 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 893 times.
✗ Branch 5 not taken.
|
893 | int numPorts = std::clamp(json["numPorts"].asInt(), 0, 4); |
| 597 |
2/4✓ Branch 0 taken 893 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 893 times.
✗ Branch 3 not taken.
|
893 | int id = json["id"].asInt(); |
| 598 | // printf("Resp: Idx: %d Port: %d dial: %d NP: %d ID: %d\n", index, port, dial, numPorts, id); | ||
| 599 |
2/2✓ Branch 0 taken 3572 times.
✓ Branch 1 taken 893 times.
|
4465 | for (int x = 0; x < numPorts; x++) { |
| 600 |
1/2✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
|
3572 | OutputMonitor::INSTANCE.setSmartReceiverInfo(port + x % 4, index, |
| 601 |
4/8✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3572 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3572 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3572 times.
✗ Branch 7 not taken.
|
3572 | json["ports"][x]["fuseOn"].asBool(), |
| 602 |
4/8✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3572 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3572 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3572 times.
✗ Branch 7 not taken.
|
3572 | json["ports"][x]["fuseBlown"].asBool(), |
| 603 |
4/8✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3572 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3572 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3572 times.
✗ Branch 7 not taken.
|
3572 | json["ports"][x]["current"].asInt(), |
| 604 |
4/8✓ Branch 0 taken 3572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3572 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3572 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3572 times.
✗ Branch 7 not taken.
|
3572 | json["ports"][x]["pixelCount"].asInt()); |
| 605 | } | ||
| 606 | ✗ | } catch (std::exception& e) { | |
| 607 | ✗ | LogWarn(VB_CHANNELOUT, "Error (%s) handling response JSON: %s\n", e.what(), SaveJsonToString(json, " ").c_str()); | |
| 608 | ✗ | } | |
| 609 | 893 | } | |
| 610 | |||
| 611 | 2927 | bool FalconV5Support::generateDynamicPacket(std::vector<std::array<uint8_t, 64>>& packets, bool& listen) { | |
| 612 |
2/2✓ Branch 0 taken 129 times.
✓ Branch 1 taken 2798 times.
|
2927 | if (maxCount.empty()) { |
| 613 | 129 | return false; | |
| 614 | } | ||
| 615 | 2798 | const int rest = queryRestFrames; | |
| 616 |
6/6✓ Branch 0 taken 2675 times.
✓ Branch 1 taken 123 times.
✓ Branch 2 taken 1338 times.
✓ Branch 3 taken 1337 times.
✓ Branch 4 taken 1338 times.
✓ Branch 5 taken 1460 times.
|
2798 | if (curCount >= maxCount[curMux] && curCount <= maxCount[curMux] + rest) { |
| 617 | // finished this mux: one frame to wait before changing muxes, then | ||
| 618 | // 'rest' more to space the rounds out. A pending eFuse toggle/reset | ||
| 619 | // ends the extra rest so it goes out on the next frame instead of | ||
| 620 | // waiting for the next round. | ||
| 621 |
2/6✗ Branch 0 not taken.
✓ Branch 1 taken 1338 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1338 times.
|
1338 | if (curCount > maxCount[curMux] && pendingToggle.load().cmd != ToggleCommand::None) { |
| 622 | ✗ | curCount = maxCount[curMux] + rest + 1; | |
| 623 | } else { | ||
| 624 | 1338 | ++curCount; | |
| 625 | 1338 | return false; | |
| 626 | } | ||
| 627 | } | ||
| 628 |
2/2✓ Branch 0 taken 1337 times.
✓ Branch 1 taken 123 times.
|
1460 | if (curCount > maxCount[curMux] + rest) { |
| 629 | 1337 | curCount = 0; | |
| 630 | // skip muxes without receivers: switching to one only spent a frame | ||
| 631 | // (and 'rest' more) on a position nothing answers on | ||
| 632 | 1337 | int newMux = curMux; | |
| 633 | do { | ||
| 634 |
1/2✓ Branch 0 taken 1337 times.
✗ Branch 1 not taken.
|
1337 | if (++newMux >= (int)maxCount.size()) { |
| 635 | 1337 | newMux = 0; | |
| 636 | 1337 | triggerPixelCount = false; | |
| 637 | } | ||
| 638 |
2/6✗ Branch 0 not taken.
✓ Branch 1 taken 1337 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1337 times.
|
1337 | } while (maxCount[newMux] == 0 && newMux != curMux); |
| 639 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1337 times.
|
1337 | if (newMux != curMux) { |
| 640 | ✗ | setCurrentMux(newMux); | |
| 641 | } | ||
| 642 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1337 times.
|
1337 | if (maxCount[newMux] == 0) { |
| 643 | ✗ | curCount++; | |
| 644 | ✗ | return false; | |
| 645 | } | ||
| 646 | } | ||
| 647 | 1460 | curCount++; | |
| 648 | // Snapshot the pending toggle once for this pass so every chain sees the | ||
| 649 | // same port/index/command triple. | ||
| 650 | 1460 | PendingToggle toggle = pendingToggle.load(); | |
| 651 |
2/2✓ Branch 0 taken 1460 times.
✓ Branch 1 taken 1460 times.
|
2920 | for (auto& g : queryData[curMux]) { |
| 652 | 1460 | auto rc = g.second.front(); | |
| 653 |
2/2✓ Branch 0 taken 1457 times.
✓ Branch 1 taken 3 times.
|
1460 | if (!rc->hasMoreQueries()) { |
| 654 | 1457 | rc->resetQueryCount(); | |
| 655 | 1457 | g.second.pop_front(); | |
| 656 |
1/2✓ Branch 0 taken 1457 times.
✗ Branch 1 not taken.
|
1457 | g.second.push_back(rc); |
| 657 | 1457 | rc = g.second.front(); | |
| 658 | } | ||
| 659 | 1460 | int rcP = rc->getPixelStrings().front()->m_portNumber; | |
| 660 |
3/6✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1460 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1460 times.
|
1460 | if (rcP < 0 || rcP >= (int)packets.size()) { |
| 661 | ✗ | continue; // a port past the strings would write past the packets | |
| 662 | } | ||
| 663 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 1460 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
1460 | if (toggle.cmd != ToggleCommand::None && rcP <= toggle.port && (rcP + 4) > toggle.port) { |
| 664 | ✗ | if (toggle.cmd == ToggleCommand::Toggle) { | |
| 665 | ✗ | rc->generateToggleEFusePacket(&packets[rcP][0], toggle.index, toggle.port % 4); | |
| 666 | } else { | ||
| 667 | ✗ | rc->generateResetEFusePacket(&packets[rcP][0], toggle.index, toggle.port % 4); | |
| 668 | } | ||
| 669 | // Clear only the toggle we just acted on: a compare_exchange keeps | ||
| 670 | // a request that arrived since the snapshot from being dropped. | ||
| 671 | // 'expected' is a copy because a failed exchange writes through it. | ||
| 672 | ✗ | PendingToggle expected = toggle; | |
| 673 | ✗ | pendingToggle.compare_exchange_strong(expected, PendingToggle()); | |
| 674 | ✗ | toggle = PendingToggle(); | |
| 675 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1460 times.
|
1460 | } else if (triggerPixelCount) { |
| 676 | ✗ | rc->generatePixelCountPacket(&packets[rcP][0]); | |
| 677 | ✗ | listen = false; | |
| 678 | } else { | ||
| 679 |
1/2✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
|
1460 | rc->generateQueryPacket(&packets[rcP][0]); |
| 680 | 1460 | listen = true; | |
| 681 | } | ||
| 682 | } | ||
| 683 | 1460 | return true; | |
| 684 | } | ||
| 685 | |||
| 686 | ✗ | void FalconV5Support::sendCountPixelPackets() { | |
| 687 | ✗ | setCurrentMux(0); | |
| 688 | ✗ | curCount = 0; | |
| 689 | ✗ | triggerPixelCount = true; | |
| 690 | ✗ | } | |
| 691 |