diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2023-09-05 10:11:39 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2023-09-05 10:11:39 +0200 |
commit | 0f11a2bc9b22a1362245459ae45ae4f86cb9374e (patch) | |
tree | 50844dee723a73cae8198b2a8f760a9214fd5d15 /src/output | |
parent | 4a1ef9edbf8c32d87292beac6cf96606442bf302 (diff) | |
download | dabmod-0f11a2bc9b22a1362245459ae45ae4f86cb9374e.tar.gz dabmod-0f11a2bc9b22a1362245459ae45ae4f86cb9374e.tar.bz2 dabmod-0f11a2bc9b22a1362245459ae45ae4f86cb9374e.zip |
Dexter: make channel_down wait for underflow to occur
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/Dexter.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/output/Dexter.cpp b/src/output/Dexter.cpp index 8e2a6c5..26472e8 100644 --- a/src/output/Dexter.cpp +++ b/src/output/Dexter.cpp @@ -187,11 +187,33 @@ void Dexter::channel_down() etiLog.level(error) << "Failed to set dexter_dsp_tx.gain0 = 0: " << get_iio_error(r); } - // This will flush out the FIFO + // Setting stream0_start_clocks to 0 will flush out the FIFO, but we need to wait a bit before + // we "up" the channel again if ((r = iio_device_attr_write_longlong(m_dexter_dsp_tx, "stream0_start_clks", 0)) != 0) { etiLog.level(warn) << "Failed to set dexter_dsp_tx.stream0_start_clks = 0 : " << get_iio_error(r); } + long long underflows_old = 0; + + if ((r = iio_device_attr_read_longlong(m_dexter_dsp_tx, "buffer_underflows0", &underflows_old)) != 0) { + etiLog.level(warn) << "Failed to read dexter_dsp_tx.buffer_underflows0 : " << get_iio_error(r); + } + + long long underflows = underflows_old; + + // Limiting to 10*96ms is just a safety to avoid running into an infinite loop + for (size_t i = 0; underflows == underflows_old && i < 10; i++) { + if ((r = iio_device_attr_read_longlong(m_dexter_dsp_tx, "buffer_underflows0", &underflows)) != 0) { + etiLog.level(warn) << "Failed to read dexter_dsp_tx.buffer_underflows0 : " << get_iio_error(r); + } + + this_thread::sleep_for(chrono::milliseconds(96)); + } + + if (underflows == underflows_old) { + etiLog.level(warn) << "DEXTER CHANNEL_DOWN, no underflow detected! " << underflows; + } + m_channel_is_up = false; etiLog.level(debug) << "DEXTER CHANNEL_DOWN"; } |