Skip to content

Commit

Permalink
revive dcp405 after test
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Sep 9, 2020
1 parent 9753c26 commit 9691145
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
18 changes: 10 additions & 8 deletions src/eez/modules/dib-dcp405/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,14 @@ void AnalogDigitalConverter::init() {
#endif

#if defined(EEZ_PLATFORM_SIMULATOR)
g_testResult = TEST_OK;
testResult = TEST_OK;
#endif
}

bool AnalogDigitalConverter::test() {
#if defined(EEZ_PLATFORM_STM32)
testResult = TEST_OK;

#if defined(EEZ_PLATFORM_STM32)
uint8_t data[4];
uint8_t result[4];

Expand All @@ -250,25 +252,25 @@ bool AnalogDigitalConverter::test() {
uint8_t reg3 = result[3];

if (reg1 != getReg1Val()) {
g_testResult = TEST_FAILED;
testResult = TEST_FAILED;
}

if (reg2 != ADC_REG2_VAL) {
g_testResult = TEST_FAILED;
testResult = TEST_FAILED;
}

if (reg3 != ADC_REG3_VAL) {
g_testResult = TEST_FAILED;
testResult = TEST_FAILED;
}

if (g_testResult == TEST_FAILED) {
if (testResult == TEST_FAILED) {
generateChannelError(SCPI_ERROR_CH1_ADC_TEST_FAILED, channelIndex);
} else {
g_testResult = TEST_OK;
testResult = TEST_OK;
}
#endif

return g_testResult != TEST_FAILED;
return testResult != TEST_FAILED;
}

void AnalogDigitalConverter::start(AdcDataType adcDataType_) {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/dib-dcp405/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AnalogDigitalConverter {

uint8_t channelIndex;
uint8_t slotIndex;
TestResult g_testResult;
TestResult testResult;

AdcDataType adcDataType;

Expand Down
22 changes: 12 additions & 10 deletions src/eez/modules/dib-dcp405/dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ void DigitalAnalogConverter::init() {
}

bool DigitalAnalogConverter::test(IOExpander &ioexp, AnalogDigitalConverter &adc) {
testResult = TEST_OK;

#if defined(EEZ_PLATFORM_STM32)
if (ioexp.g_testResult != TEST_OK) {
g_testResult = TEST_SKIPPED;
if (ioexp.testResult != TEST_OK) {
testResult = TEST_SKIPPED;
return true;
}

if (adc.g_testResult != TEST_OK) {
g_testResult = TEST_SKIPPED;
if (adc.testResult != TEST_OK) {
testResult = TEST_SKIPPED;
return true;
}

Expand All @@ -89,31 +91,31 @@ bool DigitalAnalogConverter::test(IOExpander &ioexp, AnalogDigitalConverter &adc
float uMon = channel.u.mon_dac_last;
float uDiff = uMon - uSet;
if (fabsf(uDiff) > uSet * DAC_TEST_TOLERANCE / 100) {
g_testResult = TEST_FAILED;
testResult = TEST_FAILED;
DebugTrace("Ch%d DAC test, U_set failure: expected=%g, got=%g, abs diff=%g\n", channel.channelIndex + 1, uSet, uMon, uDiff);
}

float iMon = channel.i.mon_dac_last;
float iDiff = iMon - iSet;
if (fabsf(iDiff) > iSet * DAC_TEST_TOLERANCE / 100) {
g_testResult = TEST_FAILED;
testResult = TEST_FAILED;
DebugTrace("Ch%d DAC test, I_set failure: expected=%g, got=%g, abs diff=%g\n", channel.channelIndex + 1, iSet, iMon, iDiff);
}

if (g_testResult == TEST_FAILED) {
if (testResult == TEST_FAILED) {
generateChannelError(SCPI_ERROR_CH1_DAC_TEST_FAILED, channel.channelIndex);
} else {
g_testResult = TEST_OK;
testResult = TEST_OK;
}

m_testing = false;
#endif

#if defined(EEZ_PLATFORM_SIMULATOR)
g_testResult = TEST_OK;
testResult = TEST_OK;
#endif

return g_testResult != TEST_FAILED;
return testResult != TEST_FAILED;
}

void DigitalAnalogConverter::tick(uint32_t tickCount) {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/dib-dcp405/dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DigitalAnalogConverter {

uint8_t slotIndex;
uint8_t channelIndex;
TestResult g_testResult;
TestResult testResult;
bool m_isRampActive = false;

void init();
Expand Down
6 changes: 4 additions & 2 deletions src/eez/modules/dib-dcp405/dib-dcp405.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ struct DcpChannel : public Channel {
}

bool test() override {
init();

flags.powerOk = 0;

doRemoteSensingEnable(false);
Expand All @@ -220,11 +222,11 @@ struct DcpChannel : public Channel {
}

TestResult getTestResult() override {
if (ioexp.g_testResult == TEST_NONE || adc.g_testResult == TEST_NONE || dac.g_testResult == TEST_NONE || tempSensorTestResult == TEST_NONE) {
if (ioexp.testResult == TEST_NONE || adc.testResult == TEST_NONE || dac.testResult == TEST_NONE || tempSensorTestResult == TEST_NONE) {
return TEST_NONE;
}

if (ioexp.g_testResult == TEST_OK && adc.g_testResult == TEST_OK && dac.g_testResult == TEST_OK && tempSensorTestResult == TEST_OK) {
if (ioexp.testResult == TEST_OK && adc.testResult == TEST_OK && dac.testResult == TEST_OK && tempSensorTestResult == TEST_OK) {
return TEST_OK;
}

Expand Down
16 changes: 9 additions & 7 deletions src/eez/modules/dib-dcp405/ioexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ void IOExpander::init() {
}

bool IOExpander::test() {
testResult = TEST_OK;

#if defined(EEZ_PLATFORM_STM32)
Channel &channel = Channel::get(channelIndex);

Expand All @@ -200,24 +202,24 @@ bool IOExpander::test() {
if (value != expectedValue) {
DebugTrace("Ch%d IO expander reg check failure: reg=%d, expected=%d, got=%d\n", channel.channelIndex + 1, (int)REG_VALUES[3 * i], (int)expectedValue, (int)value);

g_testResult = TEST_FAILED;
testResult = TEST_FAILED;
break;
}
}
}

readGpio();

if (g_testResult == TEST_FAILED) {
if (testResult == TEST_FAILED) {
generateChannelError(SCPI_ERROR_CH1_IOEXP_TEST_FAILED, channel.channelIndex);
channel.flags.powerOk = 0;
} else {
#if !CONF_SKIP_PWRGOOD_TEST
channel.flags.powerOk = testBit(IO_BIT_IN_PWRGOOD);
if (channel.flags.powerOk) {
g_testResult = TEST_OK;
testResult = TEST_OK;
} else {
g_testResult = TEST_FAILED;
testResult = TEST_FAILED;
DebugTrace("Ch%d power fault\n", channel.channelIndex + 1);
generateChannelError(SCPI_ERROR_CH1_FAULT_DETECTED, channel.channelIndex);
}
Expand All @@ -227,11 +229,11 @@ bool IOExpander::test() {

#if defined(EEZ_PLATFORM_SIMULATOR)
Channel &channel = Channel::get(channelIndex);
g_testResult = TEST_OK;
testResult = TEST_OK;
channel.flags.powerOk = 1;
#endif

return g_testResult != TEST_FAILED;
return testResult != TEST_FAILED;
}

#if defined(EEZ_PLATFORM_STM32)
Expand Down Expand Up @@ -270,7 +272,7 @@ void IOExpander::tick(uint32_t tick_usec) {
reinit();
readGpio();

// g_testResult = TEST_FAILED;
// testResult = TEST_FAILED;
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/dib-dcp405/ioexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class IOExpander {

uint8_t slotIndex;
uint8_t channelIndex;
TestResult g_testResult;
TestResult testResult;

void init();
bool test();
Expand Down

0 comments on commit 9691145

Please sign in to comment.