fix di8
This commit is contained in:
32
main.cpp
32
main.cpp
@ -1086,6 +1086,7 @@ struct Api {
|
||||
decltype(&X502_SetDinFreq) SetDinFreq = nullptr;
|
||||
decltype(&X502_SetOutFreq) SetOutFreq = nullptr;
|
||||
decltype(&X502_AsyncOutDig) AsyncOutDig = nullptr;
|
||||
decltype(&X502_AsyncInDig) AsyncInDig = nullptr;
|
||||
decltype(&X502_SetRefFreq) SetRefFreq = nullptr;
|
||||
decltype(&X502_SetStreamBufSize) SetStreamBufSize = nullptr;
|
||||
decltype(&X502_SetStreamStep) SetStreamStep = nullptr;
|
||||
@ -1146,6 +1147,7 @@ struct Api {
|
||||
SetDinFreq = load_symbol<decltype(SetDinFreq)>(x502_module, "X502_SetDinFreq");
|
||||
SetOutFreq = load_symbol<decltype(SetOutFreq)>(x502_module, "X502_SetOutFreq");
|
||||
AsyncOutDig = load_symbol<decltype(AsyncOutDig)>(x502_module, "X502_AsyncOutDig");
|
||||
AsyncInDig = load_symbol<decltype(AsyncInDig)>(x502_module, "X502_AsyncInDig");
|
||||
SetRefFreq = load_symbol<decltype(SetRefFreq)>(x502_module, "X502_SetRefFreq");
|
||||
SetStreamBufSize = load_symbol<decltype(SetStreamBufSize)>(x502_module, "X502_SetStreamBufSize");
|
||||
SetStreamStep = load_symbol<decltype(SetStreamStep)>(x502_module, "X502_SetStreamStep");
|
||||
@ -1195,7 +1197,7 @@ constexpr uint32_t kE502Digital1Mask = (static_cast<uint32_t>(1U) << 0U);
|
||||
constexpr uint32_t kE502Digital2Mask = (static_cast<uint32_t>(1U) << 1U);
|
||||
constexpr uint32_t kE502Do1Mask = (static_cast<uint32_t>(1U) << 0U);
|
||||
constexpr uint32_t kE502Do2Mask = (static_cast<uint32_t>(1U) << 1U);
|
||||
constexpr uint32_t kE502Digital8Mask = (static_cast<uint32_t>(1U) << 7U);
|
||||
constexpr uint32_t kE502Digital8Mask = (static_cast<uint32_t>(1U) << 6U); // DI8 reads as bit 6 (hardware offset confirmed by loopback test)
|
||||
constexpr uint32_t kE502Do8Mask = (static_cast<uint32_t>(1U) << 7U);
|
||||
constexpr uint32_t kDo1TogglePeriodTicks = 2U;
|
||||
constexpr uint32_t kDo1CyclePatternWords = kDo1TogglePeriodTicks * 2U;
|
||||
@ -1910,6 +1912,34 @@ int run(const Config& cfg) {
|
||||
|
||||
expect_ok(api, api.Configure(device.hnd, 0), "Configure device");
|
||||
expect_ok(api, api.AsyncOutDig(device.hnd, kE502Do2Mask, 0U), "Force DO2 HIGH");
|
||||
|
||||
// DO8/DI8 loopback diagnostic (before streams start, AsyncOutDig/AsyncInDig work)
|
||||
if (cfg.do8_freq_ref) {
|
||||
uint32_t din_val = 0;
|
||||
// Set DO8 HIGH
|
||||
expect_ok(api, api.AsyncOutDig(device.hnd, kE502Do2Mask | kE502Do8Mask, 0U),
|
||||
"DO8 loopback test: set DO8 HIGH");
|
||||
usleep(2000);
|
||||
expect_ok(api, api.AsyncInDig(device.hnd, &din_val), "DO8 loopback test: read DIN");
|
||||
const bool di8_high = (din_val & kE502Digital8Mask) != 0U;
|
||||
std::cerr << "DO8/DI8 loopback: DO8=HIGH -> DI8=" << (di8_high ? "HIGH" : "LOW")
|
||||
<< " (DIN=0x" << std::hex << din_val << std::dec << ")\n";
|
||||
// Set DO8 LOW
|
||||
expect_ok(api, api.AsyncOutDig(device.hnd, kE502Do2Mask, 0U),
|
||||
"DO8 loopback test: set DO8 LOW");
|
||||
usleep(2000);
|
||||
expect_ok(api, api.AsyncInDig(device.hnd, &din_val), "DO8 loopback test: read DIN");
|
||||
const bool di8_low = (din_val & kE502Digital8Mask) != 0U;
|
||||
std::cerr << "DO8/DI8 loopback: DO8=LOW -> DI8=" << (di8_low ? "HIGH" : "LOW")
|
||||
<< " (DIN=0x" << std::hex << din_val << std::dec << ")\n";
|
||||
if (!di8_high || di8_low) {
|
||||
std::cerr << "WARNING: DO8/DI8 loopback FAILED. Check physical connection.\n";
|
||||
} else {
|
||||
std::cerr << "DO8/DI8 loopback PASSED.\n";
|
||||
}
|
||||
// Restore
|
||||
expect_ok(api, api.AsyncOutDig(device.hnd, kE502Do2Mask, 0U), "Restore DO2 HIGH only");
|
||||
}
|
||||
uint32_t enabled_streams = X502_STREAM_ADC | X502_STREAM_DIN;
|
||||
if (cfg.do1_toggle_per_frame) {
|
||||
enabled_streams |= X502_STREAM_DOUT;
|
||||
|
||||
@ -30,6 +30,6 @@ exec "$BIN" \
|
||||
do1_toggle_per_frame \
|
||||
do1_pair_subtract_avg \
|
||||
do8_freq_ref \
|
||||
do8_cycle_period:10 \
|
||||
do8_cycle_period:8 \
|
||||
"tty:${TTY_PATH}" \
|
||||
"$@"
|
||||
|
||||
Reference in New Issue
Block a user