211#if defined(FL_IS_ARM_LPC) && !defined(FASTLED_AUTORESEARCH_IEEE754_MODE) && \
212 !defined(FASTLED_AUTORESEARCH_FAULT_TEST)
216struct LowMemPinTogglePeriodStats {
224inline LowMemPinTogglePeriodStats computeLowMemPeriodStats(
226 LowMemPinTogglePeriodStats s{0, 0, 0, 0, 0};
231 fl::u32 min_ns = 0xFFFFFFFFu;
234 for (fl::size i = 0; i + 1 < edge_count; i += 2) {
235 const fl::u32 period_ns =
236 static_cast<fl::u32
>(edges[i].
ns) +
237 static_cast<fl::u32
>(edges[i + 1].ns);
238 if (period_ns == 0)
continue;
240 if (period_ns < min_ns) min_ns = period_ns;
241 if (period_ns > max_ns) max_ns = period_ns;
244 if (count == 0)
return s;
245 const fl::u32 mean =
static_cast<fl::u32
>(sum /
static_cast<fl::u64>(count));
247 for (fl::size i = 0; i + 1 < edge_count; i += 2) {
248 const fl::u32 period_ns =
249 static_cast<fl::u32
>(edges[i].
ns) +
250 static_cast<fl::u32
>(edges[i + 1].ns);
251 if (period_ns == 0)
continue;
252 const fl::u64 d = (period_ns > mean) ? (period_ns - mean) : (mean - period_ns);
264 while (bit > rem) bit >>= 2;
266 if (rem >= root + bit) {
268 root = (root >> 1) + bit;
274 const fl::u32 sig =
static_cast<fl::u32
>(root);
278 s.min_ns = (min_ns == 0xFFFFFFFFu) ? 0u : min_ns;
287struct LowMemTickClock {
290 fl::u32 last = (
static_cast<void>(millis()), SysTick->VAL);
293 const fl::u32 v = SysTick->VAL;
294 elapsed += (last >= v) ? (last - v) : (last + SysTick->LOAD + 1u - v);
311#if defined(FL_IS_ARM_LPC_845)
312 return pin == 10 || pin == 11;
320 delayMicroseconds(100);
326inline bool lowMemPinPairConnected(
int tx,
int rx)
FL_NO_EXCEPT {
330 ok = ok && lowMemSettledHigh(rx);
333 ok = ok && !lowMemSettledHigh(rx);
334 if (ok && !lowMemOpenDrainPin(tx)) {
337 ok = lowMemSettledHigh(rx);
339 ok = ok && !lowMemSettledHigh(rx);
348 constexpr int kPinCount = 32;
353 for (
int p = 0; p < kPinCount; ++p) {
355 skip << p <<
':' << why <<
' ';
365 for (
int p = 0; p < kPinCount; ++p) {
366 if (!(probe & (1u << p)))
continue;
367 if (lowMemOpenDrainPin(p)) {
373 const bool up = lowMemSettledHigh(p);
375 const bool down = lowMemSettledHigh(p);
380 stuck << p << (up ?
'H' : (down ?
'X' :
'L')) <<
' ';
384 for (
int tx = 0; tx < kPinCount; ++tx) {
385 if (!(usable & (1u << tx)))
continue;
387 for (
int rx = 0; rx < kPinCount; ++rx) {
388 if (rx == tx || !(usable & (1u << rx)) || lowMemOpenDrainPin(rx))
continue;
389 if (lowMemPinPairConnected(tx, rx)) {
390 pairs << tx <<
'>' << rx << (lowMemOpenDrainPin(tx) ?
"od" :
"") <<
' ';
395 for (
int p = 0; p < kPinCount; ++p) {
396 if (!(probe & (1u << p)))
continue;
401 out <<
"pairs=" << pairs.
str() <<
";stuck=" << stuck.
str()
402 <<
";skip=" << skip.
str() <<
";od=" << od.
str();
410#if defined(FL_IS_ARM_LPC_845) && defined(FASTLED_AUTORESEARCH_LPC_CORE_PULL_CHECK)
424 constexpr PinMode kCorePulldown = INPUT_PULLDOWN;
426 constexpr PinMode kCorePulldown = 0x3;
429 if (pin < 0 || pin >=
static_cast<int>(variant_pin_count) ||
434 const pin_size_t p =
static_cast<pin_size_t
>(pin);
436 ::pinMode(p, INPUT_PULLUP);
437 const int up = lowMemSettledHigh(pin) ? 1 : 0;
439 ::pinMode(p, kCorePulldown);
440 const int down = lowMemSettledHigh(pin) ? 1 : 0;
442 out <<
"up=" << up <<
",down=" << down <<
' ';
448#if defined(FL_IS_ARM_LPC_845) && defined(FASTLED_AUTORESEARCH_FAULT_TEST)
450 volatile fl::u32*
const p =
451 reinterpret_cast<volatile fl::u32*
>(0u);
459 volatile fl::u8 pad[64] = {0};
460 pad[
static_cast<fl::u8>(depth) & 0x3Fu] =
static_cast<fl::u8>(depth);
465 triggerLowMemoryNullFault();
467 return recurseLowMemoryStackBlow(depth + 1) + pad[depth & 0x3F];
490 remote.bind(
"echo", [](
int v) ->
int {
495#if defined(FL_IS_ARM_LPC_845) && defined(FASTLED_AUTORESEARCH_FAULT_TEST)
496 remote.bind(
"trigger_oom", []() ->
bool {
500 volatile char*
const p =
new char[16UL * 1024UL * 1024UL];
502 triggerLowMemoryNullFault();
505 triggerLowMemoryNullFault();
508 remote.bind(
"trigger_stackblow", []() ->
bool {
509 (void)recurseLowMemoryStackBlow(0);
510 triggerLowMemoryNullFault();
515#if defined(FL_IS_ESP8266)
516 autoresearch::esp8266::bindEsp8266Benches(
remote);
519#if defined(FASTLED_AUTORESEARCH_IEEE754_MODE)
524 response.set(
"success", r.success);
525 response.set(
"tests_run",
static_cast<int64_t
>(r.tests_run));
526 response.set(
"tests_failed",
static_cast<int64_t
>(r.tests_failed));
527 response.set(
"first_failure", r.first_failure ? r.first_failure :
"");
528 response.set(
"expected_bits",
static_cast<int64_t
>(r.expected_bits));
529 response.set(
"actual_bits",
static_cast<int64_t
>(r.actual_bits));
534#if defined(FL_IS_ARM_LPC) && !defined(FASTLED_AUTORESEARCH_IEEE754_MODE) && \
535 !defined(FASTLED_AUTORESEARCH_FAULT_TEST)
536#if defined(FL_IS_ARM_LPC_845)
539 remote.bind(
"findConnectedPins",
540 []() ->
fl::string {
return lowMemFindConnectedPins(); });
545#if !defined(FASTLED_AUTORESEARCH_LPC_DMA_LOOPBACK)
549 remote.bind(
"pinToggleRx",
550 [](
int tx_pin,
int rx_pin,
int freq_hz,
int duration_ms) ->
fl::string {
551 if (tx_pin < 0 || rx_pin < 0 || freq_hz <= 0 || duration_ms <= 0) {
554 const fl::u32 expected_edges =
555 2u *
static_cast<fl::u32
>(freq_hz) *
556 static_cast<fl::u32
>(duration_ms) / 1000u;
562 constexpr fl::u32 kLowMemEdgeBufSize = 64u;
563 fl::u32 cap = expected_edges + (expected_edges / 2u);
564 if (cap < 2u) cap = 2u;
565 if (cap > kLowMemEdgeBufSize) cap = kLowMemEdgeBufSize;
574 auto rx = fl::LpcSctRxChannel::create(rx_pin);
580 if (!rx->begin(cfg))
return fl::string(
"0,0,0,0,0,0,0");
582 const fl::u32 half_us = 500000u /
static_cast<fl::u32
>(freq_hz);
583 const fl::u32 cycles =
static_cast<fl::u32
>(freq_hz) *
584 static_cast<fl::u32
>(duration_ms) / 1000u;
594 const fl::u32 ticks_per_us = F_CPU / 1000000u;
595 const fl::u32 half_ticks = half_us * ticks_per_us;
596 const fl::i32 poll_guard =
static_cast<fl::i32
>(6u * ticks_per_us);
597 LowMemTickClock clock;
598 fl::u32 deadline = clock.now();
599 for (fl::u32 i = 0; i < 2u * cycles; ++i) {
603 deadline += half_ticks;
605 const fl::i32 left =
static_cast<fl::i32
>(deadline - clock.now());
606 if (left <= 0)
break;
607 if (left > poll_guard) rx->pollOnce();
609 if ((i & 0xFFu) == 0u) {
619 auto& edges_buf = autoresearch::low_memory::pinToggleState().edges;
620 const fl::size n_read = rx->getRawEdgeTimes(
623 LowMemPinTogglePeriodStats stats = computeLowMemPeriodStats(edges_buf, n_read);
626 const bool success = (stats.periods > 0);
627 s << (success ? 1 : 0) << ',' << static_cast<fl::u32>(n_read) <<
','
628 << stats.periods <<
',' << stats.mean_ns <<
',' << stats.sigma_ns <<
','
629 << stats.min_ns <<
',' << stats.max_ns;
632#if defined(FL_IS_ARM_LPC_845) && defined(FASTLED_AUTORESEARCH_LPC_CORE_PULL_CHECK)
638 remote.bind(
"corePullCheck",
639 [](
int pin_a,
int pin_b,
int pin_c,
int pin_d) ->
fl::string {
641 const int pins[] = {pin_a, pin_b, pin_c, pin_d};
642 for (
int pin :
pins) {
644 lowMemCorePullCheck(pin, out);
652#if defined(FASTLED_AUTORESEARCH_LPC_WS2812)
654 remote.bind(
"ws2812SctTest",
655 [](
int test_case,
int tx_pin,
int rx_pin,
int capture_ms) ->
fl::string {
662 if (test_case < 0 || test_case > 4 || tx_pin < 0 || tx_pin > 31 ||
663 rx_pin < 0 || rx_pin > 31 || tx_pin == rx_pin ||
670 case 1: num_leds = 3;
break;
671 case 4: num_leds = 100;
break;
672 default: num_leds = 1;
break;
674 const int expected_bytes = num_leds * 3;
679 f <<
"0," << test_case <<
',' << num_leds <<
',' << expected_bytes
687 for (
int i = 0; i < num_leds; ++i) {
688 u8 r = 0, g = 0, b = 0;
690 case 0: r = 0xFF;
break;
691 case 1: r = (i == 0) ? 0xFF : 0; g = (i == 1) ? 0xFF : 0;
692 b = (i == 2) ? 0xFF : 0;
break;
693 case 3: r = g = b = 0xFF;
break;
694 case 4: r = (i % 3 == 0) ? 0xFF : 0; g = (i % 3 == 1) ? 0xFF : 0;
695 b = (i % 3 == 2) ? 0xFF : 0;
break;
702 autoresearch::low_memory::Ws2812State& ws_state =
703 autoresearch::low_memory::ws2812State();
716 if (!frame || !tx.
canHandle(frame))
return setupFailed();
719 constexpr fl::u32 kTxDeadlineMs = 100u;
720 if (!tx.
waitForReady(kTxDeadlineMs))
return setupFailed();
721 const u8* expected_buf = frame->getData().data();
723 auto rx = fl::LpcSctRxChannel::create(rx_pin);
724 if (!rx)
return setupFailed();
726 const fl::u32 expected_edges = (fl::u32)num_leds * 24u * 2u;
727 fl::u32 cap = expected_edges + (expected_edges / 2u);
732 constexpr fl::u32 kLowMemWs2812EdgeCapacity = 192u;
733 if (cap < 48u) cap = 48u;
734 if (cap > kLowMemWs2812EdgeCapacity) cap = kLowMemWs2812EdgeCapacity;
737 if (!rx->begin(cfg))
return setupFailed();
745 rx->wait(capture_ms);
750 fl::lpc::LpcUartDmaRuntime::releaseTxPin();
753 uint8_t* decoded_buf = ws_state.decoded;
754 for (
int i = 0; i < expected_bytes; ++i) decoded_buf[i] = 0;
760 constexpr fl::u32 kWs2812DecodeToleranceNs = 200u;
764 kWs2812DecodeToleranceNs);
766 auto dec = rx->decode(timing,
fl::span<u8>(decoded_buf, expected_bytes));
767 const fl::u32 decoded_bytes = dec.ok() ? dec.value() : 0u;
772 fl::u32 mismatched = 0;
773 for (fl::u32 i = 0; i < decoded_bytes && i < (fl::u32)expected_bytes; ++i) {
774 if (decoded_buf[i] == expected_buf[i]) ++matched;
780 constexpr fl::size kLowMemWs2812ProbeSize = 64u;
782 fl::size edges_captured = 0;
783 for (fl::size n; (n = rx->getRawEdgeTimes(probe, edges_captured)) > 0;) {
790 fl::u32 need = cap / 16u;
791 if (need > (fl::u32)expected_bytes) need = (fl::u32)expected_bytes;
793 tx_done && mismatched == 0 && need > 0 && matched >= need;
796 s << (success ? 1 : 0) <<
',' << test_case <<
',' << num_leds <<
','
797 << expected_bytes <<
',' << decoded_bytes <<
','
798 << matched <<
',' << mismatched <<
','
799 <<
static_cast<fl::u32
>(edges_captured) <<
',' << cap <<
','
800 << (tx_done ? 1 : 0);
810#if defined(FL_IS_ARM_LPC_845) && defined(FASTLED_LPC_PWM_DMA)
811 autoresearch::pwm_dma_cl::bind(
remote);
817#if defined(FL_IS_ARM_LPC_845) && defined(FASTLED_LPC_SPI_DMA)
818 autoresearch::dma_spi::bind(
remote);
824#if defined(FL_IS_ARM_LPC_845) && FASTLED_AUTORESEARCH_LPC_UART_DMA
825 autoresearch::uart_dma::bind(
remote);