]> code.bitgloo.com Git - clyne/stmdsp.git/commitdiff
fixed signal generator input data streaming
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 20 Nov 2021 19:29:08 +0000 (14:29 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 20 Nov 2021 19:29:08 +0000 (14:29 -0500)
source/communication.cpp
source/periph/dac.cpp
source/periph/dac.hpp

index ec02a42be2e7e6eacecd5e96a690635b729342c3..b5ee28e2985ed2e854afc3f4a9f59ced23913dc6 100644 (file)
@@ -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<uint8_t *>(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<uint8_t *>(
-                    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<const uint8_t *>("\0"), 1);
+                } else {
+                    USBSerial::write(reinterpret_cast<const uint8_t *>("\1"), 1);
+
+                    // Receive streamed samples in half-buffer chunks.
+                    USBSerial::read(reinterpret_cast<uint8_t *>(
+                        more == 0 ? Samples::Generator.data() : Samples::Generator.middata()),
+                        Samples::Generator.bytesize() / 2);
+                }
             }
         }
     }
index 1ff8867f7b3228a940d71587b604a79c5f122b62..35c29089d916801f4fafd651c7f997a815891c8c 100644 (file)
@@ -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)
index 4360c26596cea3954182d60a83d3493d5d075faa..7250a529e34d0866f718fea344123f871e3257ac 100644 (file)
@@ -24,6 +24,7 @@ public:
     static void stop(int channel);
 
     static int sigGenWantsMore();
+    static int isSigGenRunning();
 
 private:
     static DACDriver *m_driver[2];