fixed signal generator input data streaming

master
Clyne 3 years ago
parent 5944ae4d01
commit 3dd57491b1

@ -112,22 +112,23 @@ void updateGenerator(unsigned char *cmd)
if (EM.assert(USBSerial::read(&cmd[1], 2) == 2, Error::BadParamSize)) { if (EM.assert(USBSerial::read(&cmd[1], 2) == 2, Error::BadParamSize)) {
unsigned int count = cmd[1] | (cmd[2] << 8); unsigned int count = cmd[1] | (cmd[2] << 8);
if (EM.assert(count <= MAX_SAMPLE_BUFFER_SIZE, Error::BadParam)) { if (EM.assert(count <= MAX_SAMPLE_BUFFER_SIZE, Error::BadParam)) {
if (run_status == RunStatus::Idle) { if (!DAC::isSigGenRunning()) {
Samples::Generator.setSize(count); Samples::Generator.setSize(count);
USBSerial::read( USBSerial::read(
reinterpret_cast<uint8_t *>(Samples::Generator.data()), reinterpret_cast<uint8_t *>(Samples::Generator.data()),
Samples::Generator.bytesize()); Samples::Generator.bytesize());
} else if (run_status == RunStatus::Running) { } else {
int more; const int more = DAC::sigGenWantsMore();
do { if (more == -1) {
chThdSleepMicroseconds(10); USBSerial::write(reinterpret_cast<const uint8_t *>("\0"), 1);
more = DAC::sigGenWantsMore(); } else {
} while (more == -1); USBSerial::write(reinterpret_cast<const uint8_t *>("\1"), 1);
// Receive streamed samples in half-buffer chunks. // Receive streamed samples in half-buffer chunks.
USBSerial::read(reinterpret_cast<uint8_t *>( USBSerial::read(reinterpret_cast<uint8_t *>(
more == 0 ? Samples::Generator.data() : Samples::Generator.middata()), more == 0 ? Samples::Generator.data() : Samples::Generator.middata()),
Samples::Generator.bytesize() / 2); Samples::Generator.bytesize() / 2);
}
} }
} }
} }

@ -61,7 +61,18 @@ void DAC::start(int channel, dacsample_t *buffer, size_t count)
int DAC::sigGenWantsMore() 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) void DAC::stop(int channel)

@ -24,6 +24,7 @@ public:
static void stop(int channel); static void stop(int channel);
static int sigGenWantsMore(); static int sigGenWantsMore();
static int isSigGenRunning();
private: private:
static DACDriver *m_driver[2]; static DACDriver *m_driver[2];

Loading…
Cancel
Save