aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2021-11-20 14:29:08 -0500
committerClyne Sullivan <clyne@bitgloo.com>2021-11-20 14:29:08 -0500
commit3dd57491b1e81a9d93054eff19ca0e6c65c85b9b (patch)
tree5de7abe2bc67e9691097b2390f9f1d2a69cf7f0a
parent5944ae4d01eb27af7c86bedba5ee157f51ba78dd (diff)
fixed signal generator input data streaming
-rw-r--r--source/communication.cpp25
-rw-r--r--source/periph/dac.cpp13
-rw-r--r--source/periph/dac.hpp1
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<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);
+ }
}
}
}
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];