From 2ac7b52aea8d13b316868c3c7c9ab788b85fba87 Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Thu, 25 Jul 2019 22:04:16 +0200 Subject: [PATCH] fixes in simulator --- src/eez/apps/psu/channel.cpp | 12 ------------ src/eez/apps/psu/channel.h | 1 - src/eez/apps/psu/simulator/dac.cpp | 13 ++++--------- src/eez/modules/psu/simulator/adc.cpp | 6 +++--- src/eez/platform/simulator/cmsis_os.cpp | 7 +++++++ 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/eez/apps/psu/channel.cpp b/src/eez/apps/psu/channel.cpp index 56068954f..f771d5226 100644 --- a/src/eez/apps/psu/channel.cpp +++ b/src/eez/apps/psu/channel.cpp @@ -407,7 +407,6 @@ void Channel::set(uint8_t slotIndex_, uint8_t boardRevision_, float U_MIN_, floa flags.cvMode = 0; flags.ccMode = 0; - updateCcAndCvSwitch(); } int Channel::reg_get_ques_isum_bit_mask_for_channel_protection_value(ProtectionValue &cpv) { @@ -1020,17 +1019,10 @@ void Channel::adcDataIsReady(int16_t data, bool startAgain) { } } -void Channel::updateCcAndCvSwitch() { -} - void Channel::setCcMode(bool cc_mode) { - cc_mode = cc_mode && isOutputEnabled(); - if (cc_mode != flags.ccMode) { flags.ccMode = cc_mode; - updateCcAndCvSwitch(); - setOperBits(OPER_ISUM_CC, cc_mode); setQuesBits(QUES_ISUM_VOLT, cc_mode); @@ -1041,13 +1033,9 @@ void Channel::setCcMode(bool cc_mode) { } void Channel::setCvMode(bool cv_mode) { - cv_mode = cv_mode && isOutputEnabled(); - if (cv_mode != flags.cvMode) { flags.cvMode = cv_mode; - updateCcAndCvSwitch(); - setOperBits(OPER_ISUM_CV, cv_mode); setQuesBits(QUES_ISUM_CURR, cv_mode); diff --git a/src/eez/apps/psu/channel.h b/src/eez/apps/psu/channel.h index 453db4179..e7a5a05f5 100644 --- a/src/eez/apps/psu/channel.h +++ b/src/eez/apps/psu/channel.h @@ -646,7 +646,6 @@ class Channel { void setCcMode(bool cc_mode); void setCvMode(bool cv_mode); - void updateCcAndCvSwitch(); void executeOutputEnable(bool enable); void doOutputEnable(bool enable); diff --git a/src/eez/apps/psu/simulator/dac.cpp b/src/eez/apps/psu/simulator/dac.cpp index 3a0056546..4cb1cce17 100644 --- a/src/eez/apps/psu/simulator/dac.cpp +++ b/src/eez/apps/psu/simulator/dac.cpp @@ -74,17 +74,12 @@ void DigitalAnalogConverter::set_current(uint16_t current) { void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value) { if (buffer == DATA_BUFFER_A) { - float adcValue = remap(value, DAC_MIN, AnalogDigitalConverter::ADC_MIN, - DAC_MAX, AnalogDigitalConverter::ADC_MAX); - g_uSet[channel.index - 1] = (uint16_t)clamp(adcValue, AnalogDigitalConverter::ADC_MIN, - AnalogDigitalConverter::ADC_MAX); + float adcValue = remap(value, DAC_MIN, AnalogDigitalConverter::ADC_MIN, DAC_MAX, AnalogDigitalConverter::ADC_MAX); + g_uSet[channel.index - 1] = (uint16_t)clamp(adcValue, AnalogDigitalConverter::ADC_MIN, AnalogDigitalConverter::ADC_MAX); } else { - float adcValue = - remap(value, DAC_MIN, AnalogDigitalConverter::ADC_MIN, - DAC_MAX, AnalogDigitalConverter::ADC_MAX); - g_iSet[channel.index - 1] = (uint16_t)clamp(adcValue, AnalogDigitalConverter::ADC_MIN, - AnalogDigitalConverter::ADC_MAX); + float adcValue = remap(value, DAC_MIN, AnalogDigitalConverter::ADC_MIN, DAC_MAX, AnalogDigitalConverter::ADC_MAX); + g_iSet[channel.index - 1] = (uint16_t)clamp(adcValue, AnalogDigitalConverter::ADC_MIN, AnalogDigitalConverter::ADC_MAX); } #ifdef DEBUG diff --git a/src/eez/modules/psu/simulator/adc.cpp b/src/eez/modules/psu/simulator/adc.cpp index 1b1deeb2b..410c5cfbf 100644 --- a/src/eez/modules/psu/simulator/adc.cpp +++ b/src/eez/modules/psu/simulator/adc.cpp @@ -73,7 +73,7 @@ void updateValues(Channel &channel) { g_uMon[i] = 0; g_iMon[i] = 0; - simulator::setCV(channel.index - 1, false); + simulator::setCV(channel.index - 1, true); simulator::setCC(channel.index - 1, false); } @@ -90,6 +90,8 @@ bool AnalogDigitalConverter::test() { } void AnalogDigitalConverter::tick(uint32_t tick_usec) { + updateValues(channel); + if (start_reg0) { int16_t adc_data = read(); channel.eventAdcData(adc_data); @@ -104,8 +106,6 @@ void AnalogDigitalConverter::start(uint8_t reg0) { } int16_t AnalogDigitalConverter::read() { - updateValues(channel); - if (start_reg0 == AnalogDigitalConverter::ADC_REG0_READ_U_MON) { return g_uMon[channel.index - 1]; } diff --git a/src/eez/platform/simulator/cmsis_os.cpp b/src/eez/platform/simulator/cmsis_os.cpp index 4da87e5c7..b0f072859 100644 --- a/src/eez/platform/simulator/cmsis_os.cpp +++ b/src/eez/platform/simulator/cmsis_os.cpp @@ -129,6 +129,12 @@ osMessageQId osMessageCreate(osMessageQId queue_id, osThreadId thread_id) { osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec) { while (queue_id->tail == queue_id->head) { +#ifdef __EMSCRIPTEN__ + return { + osOK, + 0 + }; +#else osDelay(millisec == 0 ? 1 : millisec); if (millisec == 0) { return { @@ -136,6 +142,7 @@ osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec) { 0 }; } +#endif } uint16_t tail = queue_id->tail + 1; if (tail >= queue_id->numElements) {