This commit is contained in:
awe
2026-04-21 22:15:12 +03:00
parent deb21dc681
commit 38a76ead58

View File

@ -508,8 +508,7 @@ void print_help(const char* exe_name) {
<< " di1_group_avg -> with tty + di1:trace, emit one averaged 4-word step per constant DI1 run\n" << " di1_group_avg -> with tty + di1:trace, emit one averaged 4-word step per constant DI1 run\n"
<< " do1_toggle_per_frame -> DI_SYN2 level-gated DO1 modulation:\n" << " do1_toggle_per_frame -> DI_SYN2 level-gated DO1 modulation:\n"
<< " DO1 is forced LOW when DI_SYN2 is LOW,\n" << " DO1 is forced LOW when DI_SYN2 is LOW,\n"
<< " while DI_SYN2 is HIGH on the full frame (CH1 and CH2 ticks),\n" << " while DI_SYN2 is HIGH, DO1 toggles every 3 ADC ticks\n"
<< " DO1 toggles every 3 complete CH1+CH2 frames\n"
<< " tty+di1_group_avg -> fast stream-only mode: skip CSV/SVG/live outputs and send only averaged tty data\n" << " tty+di1_group_avg -> fast stream-only mode: skip CSV/SVG/live outputs and send only averaged tty data\n"
<< " If sample_clock_hz is omitted together with clock:internal, the maximum ADC speed is used\n" << " If sample_clock_hz is omitted together with clock:internal, the maximum ADC speed is used\n"
<< "\n" << "\n"
@ -1042,7 +1041,7 @@ constexpr uint32_t kE502DiSyn2Mask =
constexpr uint32_t kE502Digital1Mask = (static_cast<uint32_t>(1U) << 0U); constexpr uint32_t kE502Digital1Mask = (static_cast<uint32_t>(1U) << 0U);
constexpr uint32_t kE502Digital2Mask = (static_cast<uint32_t>(1U) << 1U); constexpr uint32_t kE502Digital2Mask = (static_cast<uint32_t>(1U) << 1U);
constexpr uint32_t kE502Do1Mask = (static_cast<uint32_t>(1U) << 0U); constexpr uint32_t kE502Do1Mask = (static_cast<uint32_t>(1U) << 0U);
constexpr uint32_t kDo1TogglePeriodFrames = 3U; constexpr uint32_t kDo1TogglePeriodTicks = 3U;
constexpr uint32_t kStreamInputAdcFlag = 0x80000000U; constexpr uint32_t kStreamInputAdcFlag = 0x80000000U;
constexpr uint32_t kStreamInputCalibratedAdcFlag = 0x40000000U; constexpr uint32_t kStreamInputCalibratedAdcFlag = 0x40000000U;
@ -1397,9 +1396,10 @@ int run(const Config& cfg) {
} }
double actual_dout_freq_hz = actual_frame_freq_hz; double actual_dout_freq_hz = actual_frame_freq_hz;
if (cfg.do1_toggle_per_frame) { if (cfg.do1_toggle_per_frame) {
if (actual_frame_freq_hz <= 0.0) { if (actual_sample_clock_hz <= 0.0) {
fail("do1_toggle_per_frame requires a positive ADC frame rate"); fail("do1_toggle_per_frame requires a positive ADC sample rate");
} }
actual_dout_freq_hz = actual_sample_clock_hz;
expect_ok(api, api.SetOutFreq(device.hnd, &actual_dout_freq_hz), "Set DOUT frequency"); expect_ok(api, api.SetOutFreq(device.hnd, &actual_dout_freq_hz), "Set DOUT frequency");
} }
@ -1463,7 +1463,7 @@ int run(const Config& cfg) {
<< ((cfg.channel_count >= 2U) ? phy_channel_name(cfg.mode, cfg.ch2) : std::string("disabled")) << "\n" << ((cfg.channel_count >= 2U) ? phy_channel_name(cfg.mode, cfg.ch2) : std::string("disabled")) << "\n"
<< " DI1 handling: " << di1_mode_to_string(cfg.di1_mode) << "\n" << " DI1 handling: " << di1_mode_to_string(cfg.di1_mode) << "\n"
<< " DO1 toggle per frame: " << " DO1 toggle per frame: "
<< (cfg.do1_toggle_per_frame ? std::string("enabled (DI_SYN2 level-gated, toggle each 3 frames, LOW outside HIGH)") << (cfg.do1_toggle_per_frame ? std::string("enabled (DI_SYN2 level-gated, toggle each 3 ADC ticks, LOW outside HIGH)")
: std::string("disabled")) << "\n" : std::string("disabled")) << "\n"
<< " DOUT rate: " << " DOUT rate: "
<< (cfg.do1_toggle_per_frame ? std::to_string(actual_dout_freq_hz) + " Hz" : std::string("disabled")) << "\n" << (cfg.do1_toggle_per_frame ? std::to_string(actual_dout_freq_hz) + " Hz" : std::string("disabled")) << "\n"
@ -1589,8 +1589,7 @@ int run(const Config& cfg) {
TickMs last_live_update = 0; TickMs last_live_update = 0;
bool do1_output_high = false; bool do1_output_high = false;
bool do1_gate_active = false; bool do1_gate_active = false;
uint32_t do1_frames_since_toggle = 0; uint32_t do1_ticks_since_toggle = 0;
bool do1_frame_all_high = true;
uint64_t do1_packet_toggle_count = 0; uint64_t do1_packet_toggle_count = 0;
uint64_t do1_packet_queued_words = 0; uint64_t do1_packet_queued_words = 0;
uint64_t do1_packet_sent_words_baseline = 0; uint64_t do1_packet_sent_words_baseline = 0;
@ -1795,7 +1794,6 @@ int run(const Config& cfg) {
} else { } else {
do1_output_high = do1_high; do1_output_high = do1_high;
} }
flush_dout_queue(0U, false);
}; };
auto do1_on_packet_start = [&]() { auto do1_on_packet_start = [&]() {
@ -1807,26 +1805,26 @@ int run(const Config& cfg) {
do1_packet_sent_words_baseline = do1_total_sent_words; do1_packet_sent_words_baseline = do1_total_sent_words;
}; };
auto do1_on_frame_complete = [&](bool di_syn2_frame_high) { auto do1_on_tick = [&](bool di_syn2_high) {
if (!cfg.do1_toggle_per_frame) { if (!cfg.do1_toggle_per_frame) {
return; return;
} }
bool next_state_high = false; bool next_state_high = false;
if (di_syn2_frame_high) { if (di_syn2_high) {
if (!do1_gate_active) { if (!do1_gate_active) {
do1_gate_active = true; do1_gate_active = true;
do1_frames_since_toggle = 0U; do1_ticks_since_toggle = 0U;
next_state_high = true; next_state_high = true;
} else if ((do1_frames_since_toggle + 1U) >= kDo1TogglePeriodFrames) { } else if ((do1_ticks_since_toggle + 1U) >= kDo1TogglePeriodTicks) {
do1_frames_since_toggle = 0U; do1_ticks_since_toggle = 0U;
next_state_high = !do1_output_high; next_state_high = !do1_output_high;
} else { } else {
++do1_frames_since_toggle; ++do1_ticks_since_toggle;
next_state_high = do1_output_high; next_state_high = do1_output_high;
} }
} else { } else {
do1_gate_active = false; do1_gate_active = false;
do1_frames_since_toggle = 0U; do1_ticks_since_toggle = 0U;
next_state_high = false; next_state_high = false;
} }
do1_queue_level(next_state_high, packet_active); do1_queue_level(next_state_high, packet_active);
@ -2223,13 +2221,8 @@ int run(const Config& cfg) {
} }
trigger_prev_level = di_syn2_level; trigger_prev_level = di_syn2_level;
} }
const bool frame_complete = (lch == (cfg.channel_count - 1U));
if (cfg.do1_toggle_per_frame) { if (cfg.do1_toggle_per_frame) {
do1_frame_all_high = do1_frame_all_high && di_syn2_level; do1_on_tick(di_syn2_level);
if (frame_complete) {
do1_on_frame_complete(do1_frame_all_high);
do1_frame_all_high = true;
}
} }
if (!packet_active && (cfg.sync_start_mode == X502_SYNC_INTERNAL)) { if (!packet_active && (cfg.sync_start_mode == X502_SYNC_INTERNAL)) {