GCC Code Coverage Report


Directory: ./
File: non-gpl/BBB48String/BBB48String.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 585 674 86.8%
Functions: 23 26 88.5%
Branches: 591 1092 54.1%

Line Branch Exec Source
1 /*
2 * This file is part of the Falcon Player (FPP) and is Copyright (C)
3 * 2013-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
14 #include "fpp-pch.h"
15
16 #include "fpp-json.h"
17
18 #include <sys/wait.h>
19 #include <unistd.h>
20
21 #include <arm_neon.h>
22
23 #include <algorithm>
24
25 #include <fstream>
26
27 #define BBB_PRU 1
28
29 // #define PRINT_STATS
30
31 // FPP includes
32 #include "../../Sequence.h"
33 #include "../FalconV5Support/FalconV5Support.h"
34 #include "../../Warnings.h"
35 #include "../../channeloutput/ChannelOutputSetup.h"
36 #include "../../common.h"
37 #include "../../log.h"
38
39 #include "BBB48String.h"
40 #include "../CapeUtils/CapeUtils.h"
41 #include "channeloutput/stringtesters/PixelStringTester.h"
42 #include "util/BBBUtils.h"
43
44 #include "../../overlays/PixelOverlay.h"
45
46 #include "Plugin.h"
47 class BBB48StringPlugin : public FPPPlugins::Plugin,
48 public FPPPlugins::ChannelOutputPlugin {
49 public:
50
2/4
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
138 BBB48StringPlugin() : FPPPlugins::Plugin("BBB48String") {}
51 virtual ChannelOutput*
52 50 createChannelOutput(unsigned int startChannel,
53 unsigned int channelCount) override {
54
2/6
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 50 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
100 return new BBB48StringOutput(startChannel, channelCount);
55 }
56 };
57
58 extern "C" {
59
2/6
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 46 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
92 FPPPlugins::Plugin* createPlugin() { return new BBB48StringPlugin(); }
60 }
61
62 /*
63 *
64 */
65 50 BBB48StringOutput::BBB48StringOutput(unsigned int startChannel,
66 50 unsigned int channelCount) : ChannelOutput(startChannel, channelCount),
67 50 m_curFrame(0),
68 50 m_pru(NULL),
69 50 m_pruData(NULL),
70 50 m_pru0(NULL),
71 50 m_pru0Data(NULL),
72 50 m_stallCount(0) {
73
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 LogDebug(VB_CHANNELOUT, "BBB48StringOutput::BBB48StringOutput(%u, %u)\n",
74 startChannel, channelCount);
75 50 }
76
77 /*
78 *
79 */
80 200 BBB48StringOutput::~BBB48StringOutput() {
81 100 LogDebug(VB_CHANNELOUT, "BBB48StringOutput::~BBB48StringOutput()\n");
82
2/2
✓ Branch 0 taken 218 times.
✓ Branch 1 taken 50 times.
536 for (auto a : m_strings) {
83
1/2
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
436 delete a;
84 }
85 100 m_strings.clear();
86
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 48 times.
100 if (m_pru)
87
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 delete m_pru;
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
100 if (m_pru0)
89 ✗ delete m_pru0;
90
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 48 times.
100 if (falconV5Support)
91
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
4 delete falconV5Support;
92 200 }
93
94 51 static void compilePRUCode(const char* program,
95 const std::vector<std::string>& sargs,
96 const std::vector<std::string>& args1) {
97
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 std::vector<std::string> args = sargs;
98
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 args.insert(args.end(), args1.begin(), args1.end());
99
2/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
51 CompilePRUProgram(program, args);
100 51 }
101
102 45 static void compilePRUCode(const std::vector<std::string>& sargs,
103 const std::vector<std::string>& args0,
104 const std::vector<std::string>& args1, bool split) {
105 45 compilePRUCode("/opt/fpp/src/non-gpl/BBB48String/compileWS2811x.sh", sargs,
106 args1);
107
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 39 times.
45 if (split) {
108 6 compilePRUCode("/opt/fpp/src/non-gpl/BBB48String/compileWS2811x_gpio0.sh",
109 sargs, args0);
110 }
111 45 }
112
113 94 inline int mapSize(int max, int maxString) {
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
94 if (maxString > max) {
115 ✗ maxString = max;
116 }
117 94 int newHeight = maxString;
118 // make sure it's a multiple of 4 to keep things aligned in memory
119
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 53 times.
94 if (maxString == 0) {
120 41 return 0;
121
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 6 times.
53 } else if (maxString <= 4) {
122 47 newHeight = 4;
123
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 } else if (maxString <= 8) {
124 2 newHeight = 8;
125
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 } else if (maxString <= 12) {
126 2 newHeight = 12;
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (maxString <= 16) {
128 ✗ newHeight = 16;
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (maxString <= 20) {
130 ✗ newHeight = 20;
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (maxString <= 24) {
132 ✗ newHeight = 24;
133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (maxString <= 28) {
134 ✗ newHeight = 28;
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (maxString <= 32) {
136 ✗ newHeight = 32;
137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (maxString <= 36) {
138 ✗ newHeight = 36;
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (maxString <= 40) {
140 ✗ newHeight = 40;
141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 } else if (maxString <= 44) {
142 ✗ newHeight = 44;
143 } else {
144 2 newHeight = 48;
145 }
146 53 return newHeight;
147 }
148
149 90 void BBB48StringOutput::createOutputLengths(FrameData& d,
150 const std::string& pfx,
151 std::vector<std::string>& args) {
152
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 51 times.
90 if (d.gpioStringMap.empty()) {
153 39 return;
154 }
155
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 std::ofstream outputFile;
156
3/6
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 51 times.
✗ Branch 5 not taken.
51 outputFile.open("/tmp/OutputLengths" + pfx + ".hp",
157 std::ofstream::out | std::ofstream::trunc);
158
159 51 std::map<int, std::vector<GPIOCommand>> sizes;
160
2/2
✓ Branch 0 taken 228 times.
✓ Branch 1 taken 51 times.
279 for (int x : d.gpioStringMap) {
161
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 113 times.
228 if (x != -1) {
162 115 int pc = m_strings[x]->m_outputBytes;
163
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 4 times.
115 if (pc != 0) {
164
2/2
✓ Branch 0 taken 107 times.
✓ Branch 1 taken 111 times.
218 for (auto& a : m_strings[x]->m_gpioCommands) {
165
2/4
✓ Branch 0 taken 107 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 107 times.
✗ Branch 3 not taken.
107 sizes[a.channelOffset].push_back(a);
166 }
167 }
168 }
169 }
170
171 // Only offsets inside the frame get a check: the firmware turns every
172 // line off when the frame ends, so a command at or past the longest
173 // string never has anything to do. The last key is not necessarily the
174 // longest string's own end - a Falcon receiver chain has no end of
175 // string command, and a license clamped string keeps commands past its
176 // new length - so the chain is terminated explicitly rather than by
177 // looking one key past the end of the map.
178 51 std::vector<int> offsets;
179
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 51 times.
114 for (auto& s : sizes) {
180
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 52 times.
63 if (s.first < d.maxStringLen) {
181
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 offsets.push_back(s.first);
182 }
183 }
184
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 51 times.
62 for (size_t k = 0; k < offsets.size(); k++) {
185 11 int min = offsets[k];
186
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 outputFile << "\nCHECK_" << pfx << std::to_string(min) << ":\n";
187
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (min <= 255) {
188 11 outputFile << " QBNE skip_" << pfx << std::to_string(min)
189
6/12
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
11 << ", cur_data, " << std::to_string(min) << "\n";
190 } else {
191 ✗ if (min <= 0xFFFF) {
192 ✗ outputFile << " LDI r8, " << std::to_string(min) << "\n";
193 } else {
194 ✗ outputFile << " LDI32 r8, " << std::to_string(min) << "\n";
195 }
196 ✗ outputFile << " QBNE skip_" << pfx << std::to_string(min)
197 ✗ << ", cur_data, r8\n";
198 }
199
200
3/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 11 times.
22 for (auto& cmd : sizes[min]) {
201 11 int y = cmd.port;
202
1/2
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
23 for (int x = 0; x < d.gpioStringMap.size(); x++) {
203
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 12 times.
23 if (d.gpioStringMap[x] == y) {
204 11 y = x;
205 11 break;
206 }
207 }
208
209 11 std::string o = std::to_string(y + 1);
210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (cmd.type) {
211 outputFile << " SET GPIO_MASK(o" << o << "_gpio), GPIO_MASK(o"
212 ✗ << o << "_gpio), o" << o << "_pin\n";
213 } else {
214 outputFile << " CLR GPIO_MASK(o" << o << "_gpio), GPIO_MASK(o"
215
7/14
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11 times.
✗ Branch 13 not taken.
11 << o << "_gpio), o" << o << "_pin\n";
216 }
217 11 }
218
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 std::string next = "NO_PIXELS_CHECK";
219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (k + 1 < offsets.size()) {
220 ✗ next = "CHECK_" + pfx + std::to_string(offsets[k + 1]);
221 }
222
3/6
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
11 outputFile << " LDI next_check, $CODE(" << next << ")\n";
223
4/8
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
11 outputFile << "skip_" << pfx << std::to_string(min) << ":\n RET\n";
224 11 }
225
226
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 11 times.
51 if (offsets.empty()) {
227
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 args.emplace_back("-DFIRST_CHECK=NO_PIXELS_CHECK");
228 } else {
229
3/6
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
11 args.push_back("-DFIRST_CHECK=CHECK_" + pfx + std::to_string(offsets[0]));
230 }
231
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 outputFile.close();
232 51 }
233
234 47 void BBB48StringOutput::groupFalconV4Chains() {
235 // Group Falcon smart receiver ports into 4-port chains. Only the
236 // send-only V4 protocol is possible here: these capes have no listener
237 // hardware, so a V5 selection falls back to V4 handling. Done before
238 // the outputs are mapped so a chain whose first port has no pixels still
239 // gets a lane to carry its receiver's config packet.
240 47 int x = 0;
241
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 47 times.
255 while (x < m_strings.size()) {
242 208 int p = x;
243 208 PixelString* p1 = m_strings[x++];
244
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 206 times.
208 if (!p1->m_isSmartReceiver ||
245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 (p1->smartReceiverType != PixelString::ReceiverType::FalconV4 &&
246 ✗ p1->smartReceiverType != PixelString::ReceiverType::FalconV5)) {
247 206 continue;
248 }
249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (p1->smartReceiverType == PixelString::ReceiverType::FalconV5) {
250 ✗ LogWarn(VB_CHANNELOUT, "Falcon V5 (bidirectional) is not supported on BBB48String; using send-only V4 handling for output %d\n", p + 1);
251 ✗ p1->smartReceiverType = PixelString::ReceiverType::FalconV4;
252 }
253
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 PixelString* p2 = x < m_strings.size() ? m_strings[x++] : nullptr;
254
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 PixelString* p3 = x < m_strings.size() ? m_strings[x++] : nullptr;
255
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 PixelString* p4 = x < m_strings.size() ? m_strings[x++] : nullptr;
256
257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (p1->m_isInverted) {
258 ✗ AddOutputConfigWarning(UNKNOWN_WARNING_ID, "BBB48String: Falcon smart receivers are not supported on inverted output " + std::to_string(p + 1));
259 ✗ continue;
260 }
261
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!falconV5Support) {
262
3/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 falconV5Support = new FalconV5Support();
263 }
264
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 falconV5Support->addReceiverChain(p1, p2, p3, p4, 0, 0, true);
265
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 m_falconChainHeads.push_back(p);
266 // the four lines carry continuous pixel data - none of the v1/v2
267 // style mid-frame gpio toggling
268 2 p1->m_gpioCommands.clear();
269
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (p2) {
270 2 p2->m_gpioCommands.clear();
271 }
272
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (p3) {
273 2 p3->m_gpioCommands.clear();
274 }
275
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (p4) {
276 2 p4->m_gpioCommands.clear();
277 }
278 }
279 47 }
280
281 4 void BBB48StringOutput::setupFalconV4Lanes(FrameData& d, const std::vector<std::array<uint8_t, 64>>& packets,
282 Json::Value& root, std::vector<std::string>& args) {
283 // The chain heads this PRU drives get their packet bytes in their lane
284 // (bytes reversed: the firmware clocks MSB first, the wire wants the
285 // UART LSB first) and their pin in the FALCON_MASK_GPIOn the firmware
286 // toggles. Every other lane stays zero and its line stays low.
287 4 d.falconPacketLanes.clear();
288 4 uint32_t masks[4] = { 0, 0, 0, 0 };
289 4 int numStrings = d.gpioStringMap.size();
290
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 std::vector<uint8_t> lanes(57 * numStrings, 0);
291
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for (int lane = 0; lane < numStrings; lane++) {
292 16 int idx = d.gpioStringMap[lane];
293
7/8
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 2 times.
16 if (idx < 0 || std::find(m_falconChainHeads.begin(), m_falconChainHeads.end(), idx) == m_falconChainHeads.end()) {
294 14 continue;
295 }
296
5/10
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
2 const PinCapabilities& pin = PinCapabilities::getPinByName(root["outputs"][idx]["pin"].asString());
297
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 masks[pin.mappedGPIOIdx()] |= 1 << pin.mappedGPIO();
298
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 2 times.
116 for (int b = 0; b < 57; b++) {
299 114 uint8_t v = packets[idx][b];
300 114 v = ((v * 0x0802LU & 0x22110LU) | (v * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
301 114 lanes[b * numStrings + lane] = v;
302 }
303 }
304
6/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
4 if (!masks[0] && !masks[1] && !masks[2] && !masks[3]) {
305 2 return;
306 }
307 2 d.falconPacketLanes = std::move(lanes);
308
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 args.push_back("-DFALCONV4");
309
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
10 for (int g = 0; g < 4; g++) {
310
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (masks[g]) {
311 char buf[40];
312 2 snprintf(buf, sizeof(buf), "-DFALCON_MASK_GPIO%d=0x%08X", g, masks[g]);
313
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 args.push_back(buf);
314 }
315 }
316
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 }
317
318 45 void BBB48StringOutput::setupFalconV4Support(Json::Value& root, std::vector<std::string>& args1, std::vector<std::string>& args0) {
319 // The packet content is static for a configuration, so it is generated
320 // once (after any license clamp has settled the pixel counts) and handed
321 // to whichever PRU drives each chain head: GPIO0 heads may be on the
322 // other PRU.
323
5/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 43 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 2 times.
45 if (!falconV5Support || falconV5Support->getReceiverChains().empty()) {
324 43 return;
325 }
326 2 std::vector<std::array<uint8_t, 64>> packets;
327
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 packets.resize(m_strings.size());
328
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
12 for (auto& pk : packets) {
329 10 memset(&pk[0], 0, 64);
330 }
331
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (auto& rc : falconV5Support->getReceiverChains()) {
332 2 int port = rc->getPixelStrings()[0]->m_portNumber;
333
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if (port < 0 || port >= (int)packets.size()) {
334 ✗ continue; // a port past the strings would write past the packets
335 }
336
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 rc->generateConfigPacket(&packets[port][0]);
337 }
338
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 setupFalconV4Lanes(m_gpioData, packets, root, args1);
339
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 setupFalconV4Lanes(m_gpio0Data, packets, root, args0);
340 2 }
341
342 /*
343 *
344 */
345 50 int BBB48StringOutput::Init(Json::Value config) {
346
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 LogDebug(VB_CHANNELOUT, "BBB48StringOutput::Init(JSON)\n");
347
348
2/4
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
50 m_subType = config["subType"].asString();
349
2/4
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
50 m_channelCount = config["channelCount"].asInt();
350 50 m_gpio0Data.copyToPru = false;
351
352
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 std::string verPostf = "";
353
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 Json::Value root;
354
2/4
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 50 times.
50 if (!CapeUtils::INSTANCE.getStringConfig(m_subType, root)) {
355 // might have the version number on it
356 ✗ if (config["pinoutVersion"].asString() == "2.x") {
357 ✗ verPostf = "-v2";
358 }
359 ✗ if (config["pinoutVersion"].asString() == "3.x") {
360 ✗ verPostf = "-v3";
361 }
362 ✗ if (!CapeUtils::INSTANCE.getStringConfig(m_subType + verPostf, root)) {
363 ✗ LogErr(VB_CHANNELOUT, "Could not read pin configuration for %s%s\n",
364 m_subType.c_str(), verPostf.c_str());
365 ✗ AddOutputConfigWarning(
366 ✗ 13, "BBB48String: Could not read pin configuration for " + m_subType +
367 ✗ verPostf);
368 ✗ return 0;
369 }
370 }
371
372
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 m_licensedOutputs = CapeUtils::INSTANCE.getLicensedOutputs();
373
374 // The mirror of the check in BBShiftString: this driver drives a header
375 // pin per output, so every output the cape declares has to name one. A
376 // shift-register cape's pinout gives a shift stage instead and its
377 // integer "pin" would come back through asString() as a pin name that
378 // matches nothing, leaving every port silently unconfigured.
379
2/4
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
50 const int capeOutputCount = root["outputs"].size();
380
2/2
✓ Branch 0 taken 268 times.
✓ Branch 1 taken 49 times.
317 for (int i = 0; i < capeOutputCount; i++) {
381
6/10
✓ Branch 0 taken 268 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 268 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 268 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 268 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 267 times.
✓ Branch 9 taken 1 times.
268 if (!root["outputs"][i]["pin"].isIntegral()) {
382 267 continue;
383 }
384
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 std::string capeDriver = root.get("driver", "BBShiftString").asString();
385
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogErr(VB_CHANNELOUT, "Cape %s is not a BBB48String cape - its string configuration gives shift register stages, so it needs the %s output type\n",
386 m_subType.c_str(), capeDriver.c_str());
387
4/8
✓ 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.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
2 AddOutputConfigWarning(UNKNOWN_WARNING_ID, "BBB48String: " + m_subType + " needs the " + capeDriver +
388
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 " output type - open the Pixel Strings page and save to correct it");
389 1 return 0;
390 1 }
391
392
2/4
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
49 config["base"] = root;
393
394 49 int maxStringLen = 0;
395
4/6
✓ Branch 0 taken 267 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 267 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 218 times.
✓ Branch 5 taken 49 times.
267 for (int i = 0; i < config["outputs"].size(); i++) {
396
3/6
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 218 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 218 times.
✗ Branch 5 not taken.
218 Json::Value s = config["outputs"][i];
397
3/8
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 218 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 218 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
218 PixelString* newString = new PixelString(true);
398
399
5/10
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 218 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 218 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 218 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 218 times.
218 if (!newString->Init(s, &root["outputs"][i]))
400 ✗ return 0;
401
402 // This PRU drives the pins directly and has no per-port idle level, so
403 // an inverted protocol would put inverted data on a line that still
404 // idles low - worse than not supporting it. Undo the inversion and
405 // drive the port as a normal ws281x string. The preamble has to go
406 // with it: those bytes are meaningless to a ws281x part and would
407 // offset every pixel on the port. (Cape declared inversion never
408 // reaches here: no cape using this driver sets it.)
409 // The fill loop here emits one byte per channel, so a 16 bit part
410 // would come out at half length with the wrong bytes. Refuse it and
411 // drive the port 8 bit rather than produce garbage.
412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if (newString->m_bytesPerChannel != 1) {
413 ✗ LogWarn(VB_CHANNELOUT, "16 bit protocols are not supported on this cape; output %d will be driven as 8 bit\n", i + 1);
414 ✗ AddOutputConfigWarning(UNKNOWN_WARNING_ID, "BBB48String: 16 bit protocols are not supported on this cape, output " + std::to_string(i + 1));
415 ✗ int pre = (int)newString->m_preamble.size();
416 ✗ newString->m_outputBytes = (newString->m_outputBytes - pre) / newString->m_bytesPerChannel + pre;
417 ✗ newString->m_bytesPerChannel = 1;
418 ✗ for (auto& vs : newString->m_virtualStrings) {
419 ✗ vs.brightnessMap16 = nullptr;
420 }
421 }
422
423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if (newString->m_protocolInverted) {
424 ✗ LogWarn(VB_CHANNELOUT, "Inverted protocols are not supported on this cape; output %d will be driven as ws2811\n", i + 1);
425 ✗ AddOutputConfigWarning(UNKNOWN_WARNING_ID, "BBB48String: inverted protocols are not supported on this cape, output " + std::to_string(i + 1));
426 ✗ newString->invertOutput();
427 ✗ newString->dropPreamble();
428 ✗ newString->m_protocolInverted = false;
429 }
430
431
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 167 times.
218 if (newString->m_outputBytes > maxStringLen) {
432 51 maxStringLen = newString->m_outputBytes;
433 }
434
435
1/2
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
218 m_strings.push_back(newString);
436
1/2
✓ Branch 0 taken 218 times.
✗ Branch 1 not taken.
218 }
437
438
2/4
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
49 int retVal = ChannelOutput::Init(config);
439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 if (retVal == 0) {
440 ✗ return 0;
441 }
442
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 47 times.
49 if (maxStringLen == 0) {
443
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogErr(VB_CHANNELOUT, "No pixels configured in any string\n");
444 2 return 1;
445 }
446
447 47 std::vector<std::string> args;
448
449 47 std::vector<std::string> split1args;
450
2/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
47 split1args.push_back("-DRUNNING_ON_PRU" + std::to_string(BBB_PRU ? 1 : 0));
451 47 std::vector<std::string> split0args;
452
2/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
47 split0args.push_back("-DRUNNING_ON_PRU" + std::to_string(BBB_PRU ? 0 : 1));
453
454
3/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 43 times.
47 if (config.isMember("pixelTiming")) {
455
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 int pixelTiming = config["pixelTiming"].asInt();
456
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (pixelTiming) {
457
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
4 args.push_back("-DPIXELTYPE_SLOW");
458 }
459 }
460
461
1/2
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
47 groupFalconV4Chains();
462
463 47 std::vector<int> allStringMap;
464 47 std::string outputList;
465 47 int allMax = 0;
466
2/2
✓ Branch 0 taken 214 times.
✓ Branch 1 taken 47 times.
261 for (int x = 0; x < m_strings.size(); x++) {
467
1/2
✓ Branch 0 taken 214 times.
✗ Branch 1 not taken.
214 bool chainHead = std::find(m_falconChainHeads.begin(), m_falconChainHeads.end(), x) != m_falconChainHeads.end();
468
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 214 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 214 times.
✗ Branch 5 not taken.
214 if (m_strings[x]->m_outputBytes > 0 || chainHead) {
469
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 213 times.
214 if (x >= capeOutputCount) {
470
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogErr(VB_CHANNELOUT, "Output %d is past the %d the %s cape declares\n",
471 x + 1, capeOutputCount, m_subType.c_str());
472
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 AddOutputConfigWarning(UNKNOWN_WARNING_ID, "BBB48String: output " + std::to_string(x + 1) +
473
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 " is past the end of the cape's pinout");
474 1 continue;
475 }
476 // need to output this pin, configure it
477
4/8
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 213 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 213 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 213 times.
✗ Branch 7 not taken.
213 std::string pinName = root["outputs"][x]["pin"].asString();
478
1/2
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
213 const PinCapabilities& pin = PinCapabilities::getPinByName(pinName);
479
1/2
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
213 m_usedGPIOS.push_back(pinName);
480
3/6
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 213 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 213 times.
✗ Branch 5 not taken.
426 pin.configPin("gpio", true, "BBB48String-" + std::to_string(x + 1));
481
1/2
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
213 allStringMap.push_back(x);
482
5/6
✓ Branch 0 taken 169 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 169 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 169 times.
✓ Branch 5 taken 44 times.
213 if (x >= m_licensedOutputs && m_strings[x]->m_outputBytes > 0) {
483 // apply limit
484 169 int pixels = 50;
485 169 int chanCount = 0;
486
2/2
✓ Branch 0 taken 169 times.
✓ Branch 1 taken 169 times.
338 for (auto& a : m_strings[x]->m_virtualStrings) {
487
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 165 times.
169 if (pixels < a.pixelCount) {
488 4 a.pixelCount = pixels;
489
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (outputList != "") {
490 ✗ outputList += ", ";
491 }
492
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 outputList += std::to_string(x + 1);
493 }
494 169 pixels -= a.pixelCount;
495
1/2
✓ Branch 0 taken 169 times.
✗ Branch 1 not taken.
169 chanCount += a.channelCount();
496 }
497
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 165 times.
169 if (m_strings[x]->m_isSmartReceiver) {
498 4 chanCount = 0;
499
3/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
4 if (outputList != "") {
500
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 outputList += ", ";
501 }
502
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 outputList += std::to_string(x + 1);
503 }
504
1/2
✓ Branch 0 taken 169 times.
✗ Branch 1 not taken.
169 m_strings[x]->setPixelDataChannels(chanCount);
505 }
506 213 allMax = std::max(allMax, m_strings[x]->m_outputBytes);
507
3/4
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 194 times.
213 if (pin.mappedGPIOIdx() == 0) {
508
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 m_gpio0Data.gpioStringMap.push_back(x);
509 19 m_gpio0Data.maxStringLen =
510 19 std::max(m_gpio0Data.maxStringLen, m_strings[x]->m_outputBytes);
511 } else {
512
1/2
✓ Branch 0 taken 194 times.
✗ Branch 1 not taken.
194 m_gpioData.gpioStringMap.push_back(x);
513 194 m_gpioData.maxStringLen =
514 194 std::max(m_gpioData.maxStringLen, m_strings[x]->m_outputBytes);
515 }
516 213 }
517 }
518
519
3/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 42 times.
47 if (outputList != "") {
520
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string warning = "BBB48String is licensed for ";
521
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 warning += std::to_string(m_licensedOutputs);
522 warning += " outputs, but one or more outputs is configured for more than "
523
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 "50 pixels. Output(s): ";
524
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 warning += outputList;
525
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 AddOutputConfigWarning(UNKNOWN_WARNING_ID, warning);
526
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 LogWarn(VB_CHANNELOUT, "WARNING: %s\n", warning.c_str());
527 5 }
528
529
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 45 times.
47 if (m_gpioData.gpioStringMap.empty()) {
530
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 m_gpioData.gpioStringMap = m_gpio0Data.gpioStringMap;
531 2 m_gpioData.maxStringLen = m_gpio0Data.maxStringLen;
532 2 m_gpio0Data.maxStringLen = 0;
533 2 m_gpio0Data.gpioStringMap.clear();
534 }
535 47 bool hasSerial = true;
536
3/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 41 times.
47 if (config.isMember("serialInUse")) {
537
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 hasSerial = config["serialInUse"].asBool();
538 }
539
540
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 6 times.
47 if (!m_gpio0Data.maxStringLen) {
541 // no GPIO0 output so no need for the second PRU to be used
542 41 hasSerial = true;
543 }
544 47 bool canSplit = !hasSerial;
545
3/4
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 41 times.
47 if (hasSerial && m_gpio0Data.maxStringLen &&
546 ✗ ((m_gpio0Data.maxStringLen + m_gpioData.maxStringLen) < 2000)) {
547 // if there is plenty of time to output the GPIO0 stuff
548 // after the other GPIO's, let's do that
549 ✗ args.push_back("-DSPLIT_GPIO0");
550 ✗ args.push_back(
551 ✗ "-DGPIO0OUTPUTS=" +
552 ✗ std::to_string(mapSize(48, m_gpio0Data.gpioStringMap.size())));
553
554 ✗ m_gpio0Data.gpioStringMap.insert(m_gpio0Data.gpioStringMap.end(),
555 m_gpioData.gpioStringMap.begin(),
556 m_gpioData.gpioStringMap.end());
557 ✗ m_gpioData.gpioStringMap = m_gpio0Data.gpioStringMap;
558 ✗ m_gpio0Data.gpioStringMap.clear();
559 ✗ m_gpioData.maxStringLen =
560 ✗ std::max(m_gpioData.maxStringLen, m_gpio0Data.maxStringLen);
561 ✗ m_gpio0Data.maxStringLen = 0;
562 ✗ canSplit = false;
563 }
564
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 6 times.
47 if (!canSplit) {
565
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 m_gpioData.gpioStringMap = allStringMap;
566 41 m_gpioData.maxStringLen = allMax;
567 41 m_gpio0Data.gpioStringMap.clear();
568 }
569
570
2/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
47 int i = mapSize(root["outputs"].size(), m_gpioData.gpioStringMap.size());
571
2/2
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 47 times.
142 while (m_gpioData.gpioStringMap.size() < i) {
572
1/2
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
95 m_gpioData.gpioStringMap.push_back(-1);
573 }
574
2/4
✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
47 i = mapSize(root["outputs"].size(), m_gpio0Data.gpioStringMap.size());
575
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 47 times.
65 while (m_gpio0Data.gpioStringMap.size() < i) {
576
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 m_gpio0Data.gpioStringMap.push_back(-1);
577 }
578 // The firmware loads one byte per output into r10-r21; past 48 the load
579 // runs on into the GPIO bank address registers and every later GPIO
580 // store goes to an address made of pixel data.
581
5/6
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 45 times.
47 if (m_gpioData.gpioStringMap.size() > 48 || m_gpio0Data.gpioStringMap.size() > 48) {
582
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogErr(VB_CHANNELOUT, "%s uses %d outputs on one PRU, more than the 48 the firmware supports\n",
583 m_subType.c_str(), (int)std::max(m_gpioData.gpioStringMap.size(), m_gpio0Data.gpioStringMap.size()));
584
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 AddOutputConfigWarning(UNKNOWN_WARNING_ID, "BBB48String: " + m_subType + " uses more than 48 outputs on one PRU");
585 2 return 0;
586 }
587
588
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 setupFalconV4Support(root, split1args, split0args);
589
590
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 std::string v = "-DOUTPUTS=";
591
2/4
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
45 v += std::to_string(m_gpioData.gpioStringMap.size());
592
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 split1args.push_back(v);
593
594
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 std::ofstream outputFile;
595
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 outputFile.open("/tmp/PinConfiguration.hp",
596 std::ofstream::out | std::ofstream::trunc);
597
2/2
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 45 times.
249 for (int x = 0; x < m_gpioData.gpioStringMap.size(); x++) {
598 204 int idx = m_gpioData.gpioStringMap[x];
599
2/2
✓ Branch 0 taken 109 times.
✓ Branch 1 taken 95 times.
204 if (idx >= 0) {
600 const PinCapabilities& pin =
601
5/10
✓ Branch 0 taken 109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 109 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 109 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 109 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 109 times.
✗ Branch 9 not taken.
109 PinCapabilities::getPinByName(root["outputs"][idx]["pin"].asString());
602 ✗ outputFile << "#define o" << std::to_string(x + 1) << "_gpio "
603
6/12
✓ Branch 0 taken 109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 109 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 109 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 109 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 109 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 109 times.
✗ Branch 11 not taken.
109 << std::to_string(pin.mappedGPIOIdx()) << "\n";
604 109 outputFile << "#define o" << std::to_string(x + 1) << "_pin "
605
6/12
✓ Branch 0 taken 109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 109 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 109 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 109 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 109 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 109 times.
✗ Branch 11 not taken.
109 << std::to_string(pin.mappedGPIO()) << "\n\n";
606 } else {
607
2/4
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 95 times.
✗ Branch 3 not taken.
95 split1args.push_back("-DNOOUT" + std::to_string(x + 1));
608 }
609 }
610
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 outputFile.close();
611
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 39 times.
45 if (m_gpio0Data.gpioStringMap.size() > 0) {
612
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 split1args.push_back("-DDDRONLY");
613 6 m_gpioData.copyToPru = false;
614 6 m_gpio0Data.copyToPru = true;
615
616
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 std::string v = "-DOUTPUTS=";
617
1/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 v += std::to_string(m_gpio0Data.gpioStringMap.size());
618
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 split0args.push_back(v);
619
620
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 outputFile.open("/tmp/PinConfigurationGPIO0.hp",
621 std::ofstream::out | std::ofstream::trunc);
622
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for (int x = 0; x < m_gpio0Data.gpioStringMap.size(); x++) {
623 24 int idx = m_gpio0Data.gpioStringMap[x];
624
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 if (idx >= 0) {
625
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 const PinCapabilities& pin = PinCapabilities::getPinByName(
626
4/8
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
12 root["outputs"][idx]["pin"].asString());
627 ✗ outputFile << "#define o" << std::to_string(x + 1) << "_gpio "
628
6/12
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
6 << std::to_string(pin.mappedGPIOIdx()) << "\n";
629 6 outputFile << "#define o" << std::to_string(x + 1) << "_pin "
630
6/12
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
6 << std::to_string(pin.mappedGPIO()) << "\n\n";
631 } else {
632
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 split0args.push_back("-DNOOUT" + std::to_string(x + 1));
633 }
634 }
635
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 outputFile.close();
636 6 }
637
638 #ifdef PRINT_STATS
639 args.push_back("-DRECORD_STATS");
640 #endif
641
642
2/4
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
90 createOutputLengths(m_gpioData, "", split1args);
643
2/4
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
90 createOutputLengths(m_gpio0Data, "GPIO0_", split0args);
644
645
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 compilePRUCode(args, split0args, split1args, !hasSerial);
646
3/4
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 43 times.
45 if (!StartPRU(!hasSerial)) {
647
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 AddOutputConfigWarning(UNKNOWN_WARNING_ID, "BBB48String: Could not start PRU");
648 2 return 0;
649 }
650
651 // give each area two chunks (frame flipping) of DDR memory, from the
652 // shared region allocator so other outputs on the region (BBBMatrix
653 // panels, BBBSerial - e.g. the K8-B-Scroller runs all three) cannot
654 // overlap us
655 // each with room for the Falcon V4 config packet appended after the
656 // frame data
657 50 m_gpioData.frameSize =
658 43 m_gpioData.gpioStringMap.size() * std::max(2400, m_gpioData.maxStringLen);
659 43 m_gpioData.frameSize += m_gpioData.falconPacketLanes.size();
660 // leave a full memory page between to avoid conflicts
661 43 int offset = ((m_gpioData.frameSize / 4096) + 2) * 4096;
662 43 m_gpio0Data.frameSize = m_gpio0Data.gpioStringMap.size() *
663 43 std::max(2400, m_gpio0Data.maxStringLen);
664 43 m_gpio0Data.frameSize += m_gpio0Data.falconPacketLanes.size();
665 43 int offset0 = ((m_gpio0Data.frameSize / 4096) + 2) * 4096;
666 43 uint32_t ddrPhys = 0;
667
2/4
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✗ Branch 3 not taken.
43 uint8_t* ddrBase = BBBPru::ddrAlloc("BBB48String", 2 * offset + 2 * offset0, ddrPhys);
668
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (!ddrBase) {
669 ✗ LogErr(VB_CHANNELOUT, "BBB48String: no room in the PRU DDR region\n");
670 ✗ AddOutputConfigWarning(20, "BBB48String: no room in the PRU DDR region - reduce string lengths or other outputs' buffers");
671 ✗ return 0;
672 }
673 43 m_gpioData.curData = ddrBase;
674 43 m_gpioData.lastData = m_gpioData.curData + offset;
675
676 43 m_gpio0Data.curData = m_gpioData.lastData + offset;
677 43 m_gpio0Data.lastData = m_gpio0Data.curData + offset0;
678
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 m_gpioData.fmtCur.assign(m_gpioData.frameSize, 0);
679
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 m_gpioData.fmtLast.assign(m_gpioData.frameSize, 0);
680
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 m_gpio0Data.fmtCur.assign(m_gpio0Data.frameSize, 0);
681
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 m_gpio0Data.fmtLast.assign(m_gpio0Data.frameSize, 0);
682
683 // flag the virtual strings whose channel map is a plain run so prepData
684 // can walk the channel data directly instead of through the map
685
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 m_vsAffine.resize(m_strings.size());
686
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 43 times.
155 for (size_t s = 0; s < m_strings.size(); s++) {
687
1/2
✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
112 m_vsAffine[s].resize(m_strings[s]->m_virtualStrings.size());
688
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 112 times.
224 for (size_t v = 0; v < m_strings[s]->m_virtualStrings.size(); v++) {
689 112 auto& vs = m_strings[s]->m_virtualStrings[v];
690 112 bool affine = true;
691
2/2
✓ Branch 0 taken 4683 times.
✓ Branch 1 taken 112 times.
4795 for (int i = 0; i + 3 < vs.chMapCount; i++) {
692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4683 times.
4683 if (vs.chMap[i + 3] != vs.chMap[i] + 3) {
693 ✗ affine = false;
694 ✗ break;
695 }
696 }
697 112 m_vsAffine[s][v] = affine;
698 }
699 }
700
701
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 PixelString::AutoCreateOverlayModels(m_strings, m_autoCreatedModelNames);
702 43 return retVal;
703 50 }
704
705 45 int BBB48StringOutput::StartPRU(bool both) {
706 45 m_curFrame = 0;
707 45 int pruNumber = BBB_PRU;
708
709 // The firmware is assembled per configuration just before this, so a
710 // missing program is a build failure (the assembler's errors are in the
711 // fppd output), not a PRU that needs a reboot. Like the others here it
712 // is a config warning: it comes down when the outputs are next loaded.
713
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
90 std::vector<std::string> programs = { "/tmp/FalconWS281x.out" };
714
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 39 times.
45 if (both) {
715
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 programs.push_back("/tmp/FalconWS281x_gpio0.out");
716 }
717
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 45 times.
96 for (auto& fw : programs) {
718
2/4
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 51 times.
51 if (!FileExists(fw)) {
719 ✗ LogErr(VB_CHANNELOUT, "BBB48String: PRU firmware %s failed to build\n", fw.c_str());
720 ✗ AddOutputConfigWarning(UNKNOWN_WARNING_ID, "BBB48String: PRU firmware failed to build for this configuration");
721 ✗ return 0;
722 }
723 }
724 // run() is told not to clear PRU memory. The firmware zeroes its own
725 // control block (address, command, response) before it first reads the
726 // command, and reads nothing else until a non-zero command arrives.
727 // SendData() writes that command only after the frame's address, and on
728 // the first frame a full copy of its pixel data into the PRU memories, so
729 // a stale word left from an earlier run can neither start output nor be
730 // sent as pixel data. Skipping the clear also keeps this from touching
731 // the PRUSS while both cores are offline (crash e80ad9caf7).
732
3/8
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 45 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
45 m_pru = new BBBPru(pruNumber, true, true);
733 45 m_pruData = (BBB48StringData*)m_pru->data_ram;
734
4/6
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 43 times.
135 if (!m_pru->run("/tmp/FalconWS281x.out", true, false)) {
735
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 LogErr(VB_CHANNELOUT,
736 "BBB48String: Unable to start PRU. May require a reboot.\n");
737
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 AddOutputConfigWarning(UNKNOWN_WARNING_ID,
738 "BBB48String: Unable to start PRU. May require a reboot.");
739 2 return 0;
740 }
741 43 m_pruData->command = 0;
742 43 m_pruData->address_dma = m_pru->ddr_addr;
743
744
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 37 times.
43 if (both) {
745
3/8
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6 m_pru0 = new BBBPru(!pruNumber, true, true);
746 6 m_pru0Data = (BBB48StringData*)m_pru0->data_ram;
747
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
18 if (!m_pru0->run("/tmp/FalconWS281x_gpio0.out", true, false)) {
748 ✗ LogErr(VB_CHANNELOUT,
749 "BBB48String: Unable to start PRU0. May require a reboot.\n");
750 ✗ AddOutputConfigWarning(UNKNOWN_WARNING_ID,
751 "BBB48String: Unable to start PRU0. May require a reboot.");
752 ✗ return 0;
753 }
754 6 m_pru0Data->command = 0;
755 6 m_pru0Data->address_dma = m_pru0->ddr_addr;
756 }
757
758 43 return 1;
759 45 }
760 43 void BBB48StringOutput::StopPRU(bool wait) {
761 // Send the stop command
762 43 m_pruData->response = 0;
763 43 m_pruData->command = 0xFFFF;
764
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 37 times.
43 if (m_pru0Data) {
765 6 m_pru0Data->response = 0;
766 6 m_pru0Data->command = 0xFFFF;
767 }
768 43 __asm__ __volatile__("" ::: "memory");
769
770 // Wait for BOTH cores to acknowledge before stopping EITHER. Stopping a
771 // core through remoteproc can leave the PRUSS data RAM unreachable, and a
772 // read of it then takes an external abort (SIGBUS) rather than returning
773 // a value - which is what happened when PRU0's response was polled after
774 // PRU1 had already been stopped. So every access to PRU RAM here finishes
775 // while both cores are still up, and nothing touches it afterwards.
776 43 int cnt = 0;
777
7/8
✓ Branch 0 taken 1018 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 979 times.
✓ Branch 3 taken 39 times.
✓ Branch 4 taken 975 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 975 times.
✓ Branch 7 taken 43 times.
1018 while (wait && cnt < 25 && m_pruData->response != 0xFFFF) {
778
1/2
✓ Branch 0 taken 975 times.
✗ Branch 1 not taken.
975 std::this_thread::sleep_for(std::chrono::milliseconds(1));
779 975 cnt++;
780 975 __asm__ __volatile__("" ::: "memory");
781 }
782
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 37 times.
43 if (m_pru0) {
783 6 cnt = 0;
784
6/8
✓ Branch 0 taken 156 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 150 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 150 times.
✓ Branch 7 taken 6 times.
156 while (wait && cnt < 25 && m_pru0Data->response != 0xFFFF) {
785
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
150 std::this_thread::sleep_for(std::chrono::milliseconds(1));
786 150 cnt++;
787 150 __asm__ __volatile__("" ::: "memory");
788 }
789 }
790
791 43 m_pru->stop();
792
1/2
✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
43 delete m_pru;
793
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 37 times.
43 if (m_pru0) {
794 6 m_pru0->stop();
795
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete m_pru0;
796 }
797 43 m_pru = NULL;
798 43 m_pru0 = NULL;
799 43 }
800 /*
801 *
802 */
803 45 int BBB48StringOutput::Close(void) {
804 45 LogDebug(VB_CHANNELOUT, "BBB48StringOutput::Close()\n");
805
2/4
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
45 BBBPru::ddrRelease("BBB48String");
806
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 45 times.
156 for (auto& n : m_autoCreatedModelNames) {
807
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 PixelOverlayManager::INSTANCE.removeAutoOverlayModel(n);
808 }
809
5/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 43 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 43 times.
✓ Branch 5 taken 2 times.
45 if (!m_gpioData.gpioStringMap.empty() || !m_gpio0Data.gpioStringMap.empty()) {
810 43 StopPRU();
811 }
812 45 return ChannelOutput::Close();
813 }
814
815 90 void BBB48StringOutput::GetRequiredChannelRanges(
816 const std::function<void(int, int)>& addRange) {
817 90 PixelString* ps = NULL;
818
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 90 times.
322 for (int s = 0; s < m_strings.size(); s++) {
819 232 ps = m_strings[s];
820 232 int inCh = 0;
821 232 int min = FPPD_MAX_CHANNELS;
822 232 int max = -1;
823
2/2
✓ Branch 0 taken 9030 times.
✓ Branch 1 taken 232 times.
9262 for (int p = 0; p < ps->m_outputBytes; p++) {
824 9030 int ch = ps->m_outputMap[inCh++];
825
1/2
✓ Branch 0 taken 9030 times.
✗ Branch 1 not taken.
9030 if (ch < FPPD_MAX_CHANNELS) {
826 9030 min = std::min(min, ch);
827 9030 max = std::max(max, ch);
828 }
829 }
830
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 16 times.
232 if (min < max) {
831
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 addRange(min, max);
832 }
833 }
834 90 }
835 ✗ void BBB48StringOutput::OverlayTestData(unsigned char* channelData,
836 int cycleNum, float percentOfCycle,
837 int testType,
838 const Json::Value& config) {
839 ✗ m_testCycle = cycleNum;
840 ✗ m_testType = testType;
841 ✗ m_testPercent = percentOfCycle;
842
843 // We won't overlay the data here because we could have multiple strings
844 // pointing at the same channel range so a per-port test cannot
845 // be done via channel ranges. We'll record the test information and use
846 // that in prepData
847 ✗ }
848
849 // 8x8 byte transpose: in, rows are 8 consecutive bytes of 8 strings; out,
850 // rows are the 8 strings' bytes for 8 consecutive positions. (Same helper
851 // as BBShiftString.)
852 72 static inline void transpose8x8(uint8x8_t r[8]) {
853 72 uint8x8x2_t t0 = vtrn_u8(r[0], r[1]);
854 72 uint8x8x2_t t1 = vtrn_u8(r[2], r[3]);
855 72 uint8x8x2_t t2 = vtrn_u8(r[4], r[5]);
856 72 uint8x8x2_t t3 = vtrn_u8(r[6], r[7]);
857 216 uint16x4x2_t s0 = vtrn_u16(vreinterpret_u16_u8(t0.val[0]), vreinterpret_u16_u8(t1.val[0]));
858 216 uint16x4x2_t s1 = vtrn_u16(vreinterpret_u16_u8(t0.val[1]), vreinterpret_u16_u8(t1.val[1]));
859 216 uint16x4x2_t s2 = vtrn_u16(vreinterpret_u16_u8(t2.val[0]), vreinterpret_u16_u8(t3.val[0]));
860 216 uint16x4x2_t s3 = vtrn_u16(vreinterpret_u16_u8(t2.val[1]), vreinterpret_u16_u8(t3.val[1]));
861 216 uint32x2x2_t u0 = vtrn_u32(vreinterpret_u32_u16(s0.val[0]), vreinterpret_u32_u16(s2.val[0]));
862 216 uint32x2x2_t u1 = vtrn_u32(vreinterpret_u32_u16(s1.val[0]), vreinterpret_u32_u16(s3.val[0]));
863 216 uint32x2x2_t u2 = vtrn_u32(vreinterpret_u32_u16(s0.val[1]), vreinterpret_u32_u16(s2.val[1]));
864 216 uint32x2x2_t u3 = vtrn_u32(vreinterpret_u32_u16(s1.val[1]), vreinterpret_u32_u16(s3.val[1]));
865 72 r[0] = vreinterpret_u8_u32(u0.val[0]);
866 72 r[1] = vreinterpret_u8_u32(u1.val[0]);
867 72 r[2] = vreinterpret_u8_u32(u2.val[0]);
868 72 r[3] = vreinterpret_u8_u32(u3.val[0]);
869 72 r[4] = vreinterpret_u8_u32(u0.val[1]);
870 72 r[5] = vreinterpret_u8_u32(u1.val[1]);
871 72 r[6] = vreinterpret_u8_u32(u2.val[1]);
872 72 r[7] = vreinterpret_u8_u32(u3.val[1]);
873 72 }
874
875 2142 void BBB48StringOutput::prepData(FrameData& d, unsigned char* channelData) {
876 2142 PixelStringTester* tester = nullptr;
877
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2142 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2142 if (m_testType && m_testCycle >= 0) {
878 ✗ tester = PixelStringTester::getPixelStringTester(m_testType);
879 // null for a test type no string tester implements; the strings then
880 // just send their normal data
881 ✗ if (tester) {
882 ✗ tester->prepareTestData(m_testCycle, m_testPercent);
883 }
884 }
885 2142 const int numStrings = d.gpioStringMap.size();
886 // per string slot: either a fully prepared buffer (test mode) or the
887 // PixelString whose virtual strings are rendered on the fly per tile,
888 // with a cursor tracking where in the virtual string list the next tile
889 // continues. (Same scheme as BBShiftString::prepData.)
890 struct SlotSrc {
891 const uint8_t* buf = nullptr;
892 PixelString* ps = nullptr;
893 const uint8_t* affine = nullptr;
894 uint32_t len = 0;
895 uint32_t vsIdx = 0;
896 uint32_t vsOff = 0;
897 };
898
1/2
✓ Branch 0 taken 2142 times.
✗ Branch 1 not taken.
4284 std::vector<SlotSrc> slots(numStrings);
899 2142 uint32_t newMaxLen = 0;
900
2/2
✓ Branch 0 taken 4572 times.
✓ Branch 1 taken 2142 times.
6714 for (int s = 0; s < numStrings; s++) {
901 4572 int idx = d.gpioStringMap[s];
902
2/2
✓ Branch 0 taken 2310 times.
✓ Branch 1 taken 2262 times.
4572 if (idx >= 0) {
903 2310 PixelString* ps = m_strings[idx];
904 2310 uint32_t newLen = ps->m_outputBytes;
905 2310 SlotSrc& sl = slots[s];
906
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2310 times.
2310 if (tester) {
907 ✗ sl.buf = tester->createTestData(ps, m_testCycle, m_testPercent,
908 channelData, newLen);
909 } else {
910 2310 sl.ps = ps;
911 2310 sl.affine = m_vsAffine[idx].data();
912 }
913 2310 sl.len = newLen;
914 2310 newMaxLen = std::max(newLen, newMaxLen);
915 }
916 }
917 2142 d.outputStringLen = newMaxLen;
918
919 // Interleave the string data in tiles that stay in the L1 cache instead
920 // of writing a byte every numStrings bytes across the whole frame, with
921 // the brightness/gamma application fused into the tile fill. Virtual
922 // strings whose channel map is a simple run skip the per-channel map
923 // indirection. Unmapped slots and the tail of strings shorter than the
924 // longest now output zeros instead of stale buffer content.
925 2142 uint8_t* out = d.fmtCur.data();
926 2142 constexpr uint32_t TILE = 64;
927 uint8_t col[8][TILE];
928
2/2
✓ Branch 0 taken 1693 times.
✓ Branch 1 taken 2142 times.
3835 for (uint32_t p0 = 0; p0 < newMaxLen; p0 += TILE) {
929 1693 const uint32_t n = std::min(TILE, newMaxLen - p0);
930 1693 const uint32_t nFull = n & ~7;
931
2/2
✓ Branch 0 taken 1705 times.
✓ Branch 1 taken 1693 times.
3398 for (int s0 = 0; s0 < numStrings; s0 += 8) {
932 1705 const int ns = std::min(8, numStrings - s0);
933
2/2
✓ Branch 0 taken 6916 times.
✓ Branch 1 taken 1705 times.
8621 for (int x = 0; x < ns; ++x) {
934 6916 SlotSrc& sl = slots[s0 + x];
935
2/2
✓ Branch 0 taken 3318 times.
✓ Branch 1 taken 3598 times.
6916 uint32_t avail = sl.len > p0 ? std::min(n, sl.len - p0) : 0;
936 6916 uint32_t p = 0;
937
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6916 times.
6916 if (sl.buf) {
938 ✗ memcpy(col[x], sl.buf + p0, avail);
939 ✗ p = avail;
940
2/2
✓ Branch 0 taken 3506 times.
✓ Branch 1 taken 3410 times.
6916 } else if (sl.ps) {
941 3506 auto& vstrings = sl.ps->m_virtualStrings;
942
5/6
✓ Branch 0 taken 3318 times.
✓ Branch 1 taken 3506 times.
✓ Branch 2 taken 3318 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3318 times.
✓ Branch 5 taken 3506 times.
6824 while (p < avail && sl.vsIdx < vstrings.size()) {
943 3318 auto& vs = vstrings[sl.vsIdx];
944 3318 uint32_t m = std::min(avail - p, (uint32_t)vs.chMapCount - sl.vsOff);
945 3318 const uint8_t* br = vs.brightnessMap;
946 3318 const int* mp = vs.chMap;
947
1/2
✓ Branch 0 taken 3318 times.
✗ Branch 1 not taken.
3318 if (sl.affine[sl.vsIdx]) {
948 3318 uint32_t c = sl.vsOff % 3;
949 3318 int32_t base = (int32_t)(sl.vsOff - c);
950
2/2
✓ Branch 0 taken 142920 times.
✓ Branch 1 taken 3318 times.
146238 for (uint32_t k = 0; k < m; ++k) {
951 142920 col[x][p++] = br[channelData[mp[c] + base]];
952
2/2
✓ Branch 0 taken 47640 times.
✓ Branch 1 taken 95280 times.
142920 if (++c == 3) {
953 47640 c = 0;
954 47640 base += 3;
955 }
956 }
957 } else {
958 ✗ const int* mo = mp + sl.vsOff;
959 ✗ for (uint32_t k = 0; k < m; ++k) {
960 ✗ col[x][p++] = br[channelData[mo[k]]];
961 }
962 }
963 3318 sl.vsOff += m;
964
2/2
✓ Branch 0 taken 2134 times.
✓ Branch 1 taken 1184 times.
3318 if (sl.vsOff >= (uint32_t)vs.chMapCount) {
965 2134 sl.vsOff = 0;
966 2134 sl.vsIdx++;
967 }
968 }
969 }
970
2/2
✓ Branch 0 taken 4036 times.
✓ Branch 1 taken 2880 times.
6916 if (p < n) {
971 4036 memset(&col[x][p], 0, n - p);
972 }
973 }
974 1705 uint32_t g = 0;
975
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1681 times.
1705 if (ns == 8) {
976
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 for (; g < nFull; g += 8) {
977 uint8x8_t r[8];
978
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 72 times.
648 for (int x = 0; x < 8; ++x) {
979
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
1152 r[x] = vld1_u8(&col[x][g]);
980 }
981 72 transpose8x8(r);
982
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 72 times.
648 for (int i = 0; i < 8; i++) {
983
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 vst1_u8(&out[(size_t)(p0 + g + i) * numStrings + s0], r[i]);
984 }
985 }
986 }
987
2/2
✓ Branch 0 taken 76428 times.
✓ Branch 1 taken 1705 times.
78133 for (uint32_t p = g; p < n; ++p) {
988
2/2
✓ Branch 0 taken 306144 times.
✓ Branch 1 taken 76428 times.
382572 for (int x = 0; x < ns; ++x) {
989 306144 out[(size_t)(p0 + p) * numStrings + s0 + x] = col[x][p];
990 }
991 }
992 }
993 }
994 2142 }
995
996 /*
997 *
998 */
999 1172 void BBB48StringOutput::PrepData(unsigned char* channelData) {
1000 1172 LogExcess(VB_CHANNELOUT, "BBB48StringOutput::PrepData(%p)\n", channelData);
1001
5/6
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 1071 times.
✓ Branch 2 taken 101 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 101 times.
✓ Branch 5 taken 1071 times.
1172 if (m_gpioData.gpioStringMap.empty() && m_gpio0Data.gpioStringMap.empty()) {
1002 101 return;
1003 }
1004
1005 1071 m_curFrame++;
1006
1007 #ifdef PRINT_STATS
1008 int max = 0;
1009 for (int x = 0; x < MAX_WS2811_TIMINGS; x++) {
1010 if (max < m_pruData->timings[x]) {
1011 max = m_pruData->timings[x];
1012 }
1013 }
1014 if (max > 300 || (m_curFrame % 10) == 1) {
1015 for (int x = 0; x < MAX_WS2811_TIMINGS;) {
1016 printf("%8X ", m_pruData->timings[x]);
1017 ++x;
1018 if ((x) % 16 == 0) {
1019 printf("\n");
1020 }
1021 }
1022 printf("\n%d: max %d\n", m_curFrame, max);
1023 }
1024 #endif
1025 1071 prepData(m_gpioData, channelData);
1026 1071 prepData(m_gpio0Data, channelData);
1027 1071 m_testCycle = -1;
1028
1029
6/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1059 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1069 times.
1071 if (!m_falconChainHeads.empty() && (m_curFrame % 12) == 1) {
1030 // append the config packet after the frame data; the firmware sends
1031 // it when the command has the packet bit set
1032
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 for (FrameData* d : { &m_gpioData, &m_gpio0Data }) {
1033
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (!d->falconPacketLanes.empty()) {
1034 4 memcpy(d->fmtCur.data() + d->outputStringLen * d->gpioStringMap.size(),
1035 2 d->falconPacketLanes.data(), d->falconPacketLanes.size());
1036 }
1037 }
1038 2 m_sendFalconPacket = true;
1039 }
1040 }
1041
1042 1021 void BBB48StringOutput::sendData(FrameData& d, uint32_t* dptr) {
1043 1021 bool doSwap = false;
1044 // compare everything the copy below would place in PRU memory - the
1045 // firmware reads those bytes from there rather than DDR, so a change
1046 // past the compared range would leave it sending the old data
1047 //
1048 // Both buffers compared here are the ordinary-memory copies, never the
1049 // DDR ones: see FrameData.
1050 1021 uint32_t pruCopySize = std::min(d.frameSize, (uint32_t)(7624 + 7624 + m_pru->shared_ram_size));
1051 1021 uint8_t* fmt = d.fmtCur.data();
1052
4/4
✓ Branch 0 taken 997 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 871 times.
2018 if (d.copyToPru &&
1053
4/4
✓ Branch 0 taken 959 times.
✓ Branch 1 taken 38 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 847 times.
997 (m_curFrame == 1 || memcmp(d.fmtLast.data(), fmt, pruCopySize))) {
1054 // don't copy to PRU memory unless really needed to avoid bus contention
1055
1056 // copy first 7.5K into PRU mem directly
1057 150 int fullsize = d.frameSize;
1058 150 int mx = d.frameSize;
1059
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
150 if (mx > (8 * 1024 - 512)) {
1060 150 mx = 8 * 1024 - 512;
1061 }
1062
1063 // first 7.5K to main PRU ram
1064
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
150 m_pru->memcpyToPRU(m_pru->data_ram + 512, fmt, mx);
1065 150 fullsize -= 7624;
1066
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
150 if (fullsize > 0) {
1067 150 int outsize = fullsize;
1068
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 140 times.
150 if (outsize > (8 * 1024 - 512)) {
1069 10 outsize = 8 * 1024 - 512;
1070 }
1071 // second 7.5K to other PRU ram
1072
1/2
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
150 m_pru->memcpyToPRU(m_pru->other_data_ram + 512, fmt + 7624,
1073 outsize);
1074 150 fullsize -= 7624;
1075 }
1076
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 140 times.
150 if (fullsize > 0) {
1077 10 int outsize = fullsize;
1078
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if (outsize > m_pru->shared_ram_size) {
1079 2 outsize = m_pru->shared_ram_size;
1080 }
1081
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 m_pru->memcpyToPRU(m_pru->shared_ram, fmt + 7624 + 7624, outsize);
1082 }
1083 }
1084
1085 // The PRU reads the rest of the frame (all of it when nothing went to
1086 // PRU memory) and any Falcon V4 packet after it from DDR.
1087 1021 uint32_t used = d.outputStringLen * d.gpioStringMap.size() + d.falconPacketLanes.size();
1088 1021 memcpy(d.curData, fmt, std::min(used, d.frameSize));
1089
1090 // Map
1091 1021 size_t offset = d.curData - m_pru->ddr;
1092 1021 *dptr = (m_pru->ddr_addr + offset);
1093 1021 std::swap(d.lastData, d.curData);
1094 1021 std::swap(d.fmtLast, d.fmtCur);
1095 1021 }
1096
1097 1094 int BBB48StringOutput::SendData(unsigned char* channelData) {
1098 1094 LogExcess(VB_CHANNELOUT, "BBB48StringOutput::SendData(%p)\n", channelData);
1099
5/6
✓ Branch 0 taken 97 times.
✓ Branch 1 taken 997 times.
✓ Branch 2 taken 97 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 97 times.
✓ Branch 5 taken 997 times.
1094 if (m_gpioData.gpioStringMap.empty() && m_gpio0Data.gpioStringMap.empty()) {
1100 97 return 0;
1101 }
1102
1103 997 sendData(m_gpioData, &m_pruData->address_dma);
1104
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 973 times.
997 if (m_pru0Data) {
1105 24 sendData(m_gpio0Data, &m_pru0Data->address_dma);
1106 }
1107
1108 // the frame data must reach DDR before the command reaches the PRU
1109 997 BBBPru::frameDataBarrier();
1110
1111 // Send the start command
1112 997 uint32_t flag = 0;
1113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 997 times.
997 if (m_testType == 999) {
1114 // pixel counting needs the GPIO commands and such turned off
1115 ✗ flag = 0x8000;
1116 }
1117 // bit 16: a Falcon V4 config packet follows the frame data, for the
1118 // PRUs that drive a chain head
1119 997 uint32_t flag0 = flag;
1120
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 995 times.
997 if (m_sendFalconPacket) {
1121
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!m_gpioData.falconPacketLanes.empty()) {
1122 2 flag |= 0x10000;
1123 }
1124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!m_gpio0Data.falconPacketLanes.empty()) {
1125 ✗ flag0 |= 0x10000;
1126 }
1127 2 m_sendFalconPacket = false;
1128 }
1129
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 973 times.
997 if (m_pru0Data) {
1130 24 m_pru0Data->command = m_gpio0Data.outputStringLen | flag0;
1131 }
1132 997 m_pruData->command = m_gpioData.outputStringLen | flag;
1133
1134 997 return m_channelCount;
1135 }
1136
1137 /*
1138 *
1139 */
1140 49 void BBB48StringOutput::DumpConfig(void) {
1141 49 LogDebug(VB_CHANNELOUT, "BBB48StringOutput::DumpConfig()\n");
1142 49 LogDebug(VB_CHANNELOUT, " type : %s\n", m_subType.c_str());
1143 49 LogDebug(VB_CHANNELOUT, " strings : %d\n", m_strings.size());
1144 49 LogDebug(VB_CHANNELOUT, " longest string: %d channels\n",
1145 std::max(m_gpio0Data.maxStringLen, m_gpioData.maxStringLen));
1146
1147
2/2
✓ Branch 0 taken 218 times.
✓ Branch 1 taken 49 times.
267 for (int i = 0; i < m_strings.size(); i++) {
1148 218 LogDebug(VB_CHANNELOUT, " string #%02d\n", i);
1149 218 m_strings[i]->DumpConfig();
1150 }
1151
1152 49 ChannelOutput::DumpConfig();
1153 49 }
1154