From 3dd57491b1e81a9d93054eff19ca0e6c65c85b9b Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 20 Nov 2021 14:29:08 -0500 Subject: [PATCH] fixed signal generator input data streaming --- source/communication.cpp | 25 +++++++++++++------------ source/periph/dac.cpp | 13 ++++++++++++- source/periph/dac.hpp | 1 + 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/source/communication.cpp b/source/communication.cpp index ec02a42..b5ee28e 100644 --- a/source/communication.cpp +++ b/source/communication.cpp @@ -112,22 +112,23 @@ void updateGenerator(unsigned char *cmd) if (EM.assert(USBSerial::read(&cmd[1], 2) == 2, Error::BadParamSize)) { unsigned int count = cmd[1] | (cmd[2] << 8); if (EM.assert(count <= MAX_SAMPLE_BUFFER_SIZE, Error::BadParam)) { - if (run_status == RunStatus::Idle) { + if (!DAC::isSigGenRunning()) { Samples::Generator.setSize(count); USBSerial::read( reinterpret_cast(Samples::Generator.data()), Samples::Generator.bytesize()); - } else if (run_status == RunStatus::Running) { - int more; - do { - chThdSleepMicroseconds(10); - more = DAC::sigGenWantsMore(); - } while (more == -1); - - // Receive streamed samples in half-buffer chunks. - USBSerial::read(reinterpret_cast( - more == 0 ? Samples::Generator.data() : Samples::Generator.middata()), - Samples::Generator.bytesize() / 2); + } else { + const int more = DAC::sigGenWantsMore(); + if (more == -1) { + USBSerial::write(reinterpret_cast("\0"), 1); + } else { + USBSerial::write(reinterpret_cast("\1"), 1); + + // Receive streamed samples in half-buffer chunks. + USBSerial::read(reinterpret_cast( + more == 0 ? Samples::Generator.data() : Samples::Generator.middata()), + Samples::Generator.bytesize() / 2); + } } } } diff --git a/source/periph/dac.cpp b/source/periph/dac.cpp index 1ff8867..35c2908 100644 --- a/source/periph/dac.cpp +++ b/source/periph/dac.cpp @@ -61,7 +61,18 @@ void DAC::start(int channel, dacsample_t *buffer, size_t count) int DAC::sigGenWantsMore() { - return dacIsDone; + if (dacIsDone != -1) { + int tmp = dacIsDone; + dacIsDone = -1; + return tmp; + } else { + return -1; + } +} + +int DAC::isSigGenRunning() +{ + return m_driver[1]->state == DAC_ACTIVE; } void DAC::stop(int channel) diff --git a/source/periph/dac.hpp b/source/periph/dac.hpp index 4360c26..7250a52 100644 --- a/source/periph/dac.hpp +++ b/source/periph/dac.hpp @@ -24,6 +24,7 @@ public: static void stop(int channel); static int sigGenWantsMore(); + static int isSigGenRunning(); private: static DACDriver *m_driver[2];