Skip to content

Commit

Permalink
fixes in simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 25, 2019
1 parent d070595 commit 2ac7b52
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
12 changes: 0 additions & 12 deletions src/eez/apps/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/eez/apps/psu/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions src/eez/apps/psu/simulator/dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/eez/modules/psu/simulator/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -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];
}
Expand Down
7 changes: 7 additions & 0 deletions src/eez/platform/simulator/cmsis_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,20 @@ 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 {
osOK,
0
};
}
#endif
}
uint16_t tail = queue_id->tail + 1;
if (tail >= queue_id->numElements) {
Expand Down

0 comments on commit 2ac7b52

Please sign in to comment.