Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jun 10, 2021
1 parent ff468ff commit a95a3ee
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 117 deletions.
50 changes: 50 additions & 0 deletions src/eez/firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ void boot() {
uint16_t prolog[3];
assert(sizeof(prolog) <= bp3c::eeprom::EEPROM_PROLOG_SIZE);
if (!bp3c::eeprom::read(slotIndex, (uint8_t *)prolog, bp3c::eeprom::EEPROM_PROLOG_SIZE, bp3c::eeprom::EEPROM_PROLOG_START_ADDRESS)) {
g_slots[slotIndex]->setTestResult(TEST_SKIPPED);
prolog[0] = MODULE_TYPE_NONE;
prolog[1] = 0;
prolog[2] = 0;
Expand Down Expand Up @@ -578,4 +579,53 @@ void shutdown() {
}
}

void updateSpiIrqPin(int slotIndex) {
if (slotIndex >= 0 && slotIndex < 3) {
#if defined(EEZ_PLATFORM_STM32)
GPIO_InitTypeDef GPIO_InitStruct = {0};
#endif

TestResult testResult = g_slots[slotIndex]->getTestResult();

static bool irqDisabled[NUM_SLOTS];

if (testResult == TEST_SKIPPED || testResult == TEST_FAILED) {
if (!irqDisabled[slotIndex]) {
irqDisabled[slotIndex] = true;

#if defined(EEZ_PLATFORM_STM32)
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
#endif
}
} else {
if (irqDisabled[slotIndex]) {
irqDisabled[slotIndex] = false;

#if defined(EEZ_PLATFORM_STM32)
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
#endif
}
}

if (slotIndex == 0) {
#if defined(EEZ_PLATFORM_STM32)
GPIO_InitStruct.Pin = SPI2_IRQ_Pin;
HAL_GPIO_Init(SPI2_IRQ_GPIO_Port, &GPIO_InitStruct);
#endif
} else if (slotIndex == 1) {
#if defined(EEZ_PLATFORM_STM32)
GPIO_InitStruct.Pin = SPI4_IRQ_Pin;
HAL_GPIO_Init(SPI4_IRQ_GPIO_Port, &GPIO_InitStruct);
#endif
} else if (slotIndex == 2) {
#if defined(EEZ_PLATFORM_STM32)
GPIO_InitStruct.Pin = SPI4_IRQ_Pin;
HAL_GPIO_Init(SPI4_IRQ_GPIO_Port, &GPIO_InitStruct);
#endif
}
}
}

} // namespace eez
2 changes: 2 additions & 0 deletions src/eez/firmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void standBy();
void restart();
void shutdown();

void updateSpiIrqPin(int slotIndex);

} // namespace eez

extern "C" int g_mcuRevision;
8 changes: 7 additions & 1 deletion src/eez/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ using namespace gui;
void Module::setEnabled(bool value) {
enabled = value;
psu::persist_conf::setSlotEnabled(slotIndex, value);
updateSpiIrqPin(slotIndex);
}

TestResult Module::getTestResult() {
return TEST_SKIPPED;
return enabled ? testResult : TEST_SKIPPED;
}

void Module::setTestResult(TestResult testResult) {
this->testResult = testResult;
updateSpiIrqPin(slotIndex);
}

void Module::boot() {
Expand Down
2 changes: 2 additions & 0 deletions src/eez/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,14 @@ struct Module {
uint32_t idw2 = 0;
char label[SLOT_LABEL_MAX_LENGTH + 1] = { 0 };
uint8_t color = 0;
TestResult testResult = TEST_NONE;

virtual void setEnabled(bool value);

virtual Module *createModule() = 0;

virtual TestResult getTestResult();
virtual void setTestResult(TestResult testResult);

virtual void boot();
virtual psu::Channel *createPowerChannel(int slotIndex, int channelIndex, int subchannelIndex);
Expand Down
34 changes: 15 additions & 19 deletions src/eez/modules/dib-dcm220/dib-dcm220.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ struct DcmChannel : public Channel {

void onPowerDown() override;
bool test() override;
TestResult getTestResult() override;
void tickSpecific() override;

bool isInCcMode() override {
Expand Down Expand Up @@ -364,7 +363,6 @@ struct DcmChannel : public Channel {

struct DcmModule : public PsuModule {
public:
TestResult testResult = TEST_NONE;
bool synchronized = false;
int numCrcErrors = 0;
uint8_t input[BUFFER_SIZE];
Expand Down Expand Up @@ -397,7 +395,7 @@ struct DcmModule : public PsuModule {

void initChannels() override {
if (enabled && !synchronized) {
testResult = TEST_CONNECTING;
setTestResult(TEST_CONNECTING);
if (bp3c::comm::masterSynchro(slotIndex)) {
//DebugTrace("DCM220 slot #%d firmware version %d.%d\n", slotIndex + 1, (int)firmwareMajorVersion, (int)firmwareMinorVersion);
synchronized = true;
Expand All @@ -423,19 +421,17 @@ struct DcmModule : public PsuModule {
}
#endif
synchronized = false;
testResult = TEST_FAILED;
setTestResult(TEST_FAILED);
}

void test() {
/*
if (!enabled) {
testResult = TEST_SKIPPED;
setTestResult(TEST_SKIPPED);
return;
}
*/

if (!synchronized) {
testResult = TEST_FAILED;
setTestResult(TEST_FAILED);
return;
}

Expand Down Expand Up @@ -463,13 +459,17 @@ struct DcmModule : public PsuModule {
channel.flags.powerOk = pwrGood ? 1 : 0;
}

testResult = pwrGood ? TEST_OK : TEST_FAILED;
setTestResult(pwrGood ? TEST_OK : TEST_FAILED);

// test temp. sensors
for (int subchannelIndex = 0; testResult == TEST_OK && subchannelIndex < 2; subchannelIndex++) {
auto &channel = *Channel::getBySlotIndex(slotIndex, subchannelIndex);
testResult = temp_sensor::sensors[temp_sensor::CH1 + channel.channelIndex].test() ? TEST_OK : TEST_FAILED;
}
if (getTestResult() == TEST_OK) {
// test temp. sensors
for (int subchannelIndex = 0; testResult == TEST_OK && subchannelIndex < 2; subchannelIndex++) {
auto &channel = *Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (!temp_sensor::sensors[temp_sensor::CH1 + channel.channelIndex].test()) {
setTestResult(TEST_FAILED);
}
}
}
}

#if defined(EEZ_PLATFORM_STM32)
Expand All @@ -482,7 +482,7 @@ struct DcmModule : public PsuModule {
if (++numCrcErrors >= 4) {
event_queue::pushEvent(event_queue::EVENT_ERROR_SLOT1_CRC_CHECK_ERROR + slotIndex);
synchronized = false;
testResult = TEST_FAILED;
setTestResult(TEST_FAILED);
} else {
DebugTrace("Slot %d CRC %d\n", slotIndex + 1, numCrcErrors);
}
Expand Down Expand Up @@ -609,10 +609,6 @@ bool DcmChannel::test() {
return isOk();
}

TestResult DcmChannel::getTestResult() {
return ((DcmModule *)g_slots[slotIndex])->testResult;
}

void DcmChannel::tickSpecific() {
#if defined(EEZ_PLATFORM_STM32)
if (subchannelIndex == 0) {
Expand Down
32 changes: 15 additions & 17 deletions src/eez/modules/dib-dcm224/dib-dcm224.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ struct DcmChannel : public Channel {

void onPowerDown() override;
bool test() override;
TestResult getTestResult() override;
void tickSpecific() override;

bool isInCcMode() override {
Expand Down Expand Up @@ -451,7 +450,6 @@ static const float DEFAULT_COUNTERPHASE_FREQUENCY = 500000.0f;

struct DcmModule : public PsuModule {
public:
TestResult testResult = TEST_NONE;
bool synchronized = false;
uint8_t numConsecutiveTransferErrors;
uint32_t lastTransferTickCount;
Expand Down Expand Up @@ -488,7 +486,7 @@ struct DcmModule : public PsuModule {

void initChannels() override {
if (enabled && !synchronized) {
testResult = TEST_CONNECTING;
setTestResult(TEST_CONNECTING);
if (bp3c::comm::masterSynchro(slotIndex)) {
synchronized = true;
lastTransferTickCount = millis();
Expand All @@ -514,17 +512,17 @@ struct DcmModule : public PsuModule {
}
#endif
synchronized = false;
testResult = TEST_FAILED;
setTestResult(TEST_FAILED);
}

void test() {
if (!enabled) {
testResult = TEST_SKIPPED;
setTestResult(TEST_SKIPPED);
return;
}

if (!synchronized) {
testResult = TEST_FAILED;
setTestResult(TEST_FAILED);
return;
}

Expand Down Expand Up @@ -569,13 +567,17 @@ struct DcmModule : public PsuModule {
channel.flags.powerOk = pwrGood ? 1 : 0;
}

testResult = pwrGood ? TEST_OK : TEST_FAILED;
setTestResult(pwrGood ? TEST_OK : TEST_FAILED);

// test temp. sensors
for (int subchannelIndex = 0; testResult == TEST_OK && subchannelIndex < 2; subchannelIndex++) {
auto &channel = *Channel::getBySlotIndex(slotIndex, subchannelIndex);
testResult = temp_sensor::sensors[temp_sensor::CH1 + channel.channelIndex].test() ? TEST_OK : TEST_FAILED;
}
if (getTestResult() == TEST_OK) {
// test temp. sensors
for (int subchannelIndex = 0; testResult == TEST_OK && subchannelIndex < 2; subchannelIndex++) {
auto &channel = *Channel::getBySlotIndex(slotIndex, subchannelIndex);
if (!temp_sensor::sensors[temp_sensor::CH1 + channel.channelIndex].test()) {
setTestResult(TEST_FAILED);
}
}
}
}

#if defined(EEZ_PLATFORM_STM32)
Expand Down Expand Up @@ -606,7 +608,7 @@ struct DcmModule : public PsuModule {
#else
event_queue::pushEvent(event_queue::EVENT_ERROR_SLOT1_CRC_CHECK_ERROR + slotIndex);
synchronized = false;
testResult = TEST_FAILED;
setTestResult(TEST_FAILED);
result = TRANSFER_TIMEOUT;
#endif
}
Expand Down Expand Up @@ -803,10 +805,6 @@ bool DcmChannel::test() {
return isOk();
}

TestResult DcmChannel::getTestResult() {
return ((DcmModule *)g_slots[slotIndex])->testResult;
}

void DcmChannel::tickSpecific() {
if (subchannelIndex == 0) {
((DcmModule *)g_slots[slotIndex])->tick(slotIndex);
Expand Down
33 changes: 11 additions & 22 deletions src/eez/modules/dib-dcp405/dib-dcp405.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ struct DcpChannel : public Channel {
DigitalAnalogConverter dac;
IOExpander ioexp;

TestResult tempSensorTestResult = TEST_OK;

bool delayed_dp_off;
uint32_t delayed_dp_off_start;
bool dpOn;
Expand Down Expand Up @@ -200,6 +198,8 @@ struct DcpChannel : public Channel {
}

void init() {
g_slots[slotIndex]->setTestResult(TEST_NONE);

ioexp.testResult = TEST_OK;
ioexp.init();
adc.init();
Expand All @@ -208,7 +208,7 @@ struct DcpChannel : public Channel {

void onPowerDown() override {
Channel::onPowerDown();
ioexp.testResult = TEST_FAILED;
g_slots[slotIndex]->setTestResult(TEST_FAILED);
}

void reset(bool resetLabelAndColor) override {
Expand All @@ -228,6 +228,8 @@ struct DcpChannel : public Channel {
return true;
}

g_slots[slotIndex]->setTestResult(TEST_NONE);

flags.powerOk = 0;

init();
Expand All @@ -239,28 +241,15 @@ struct DcpChannel : public Channel {
adc.test();
dac.test(ioexp, adc);

tempSensorTestResult = TEST_OK;
if (!temp_sensor::sensors[temp_sensor::CH1 + channelIndex].test()) {
tempSensorTestResult = TEST_FAILED;
}

return isOk();
}
g_slots[slotIndex]->setTestResult(ioexp.testResult == TEST_OK && adc.testResult == TEST_OK && dac.testResult == TEST_OK ? TEST_OK : TEST_FAILED);

TestResult getTestResult() override {
if (!g_slots[slotIndex]->enabled) {
return TEST_SKIPPED;
}

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

if (ioexp.testResult == TEST_OK && adc.testResult == TEST_OK && dac.testResult == TEST_OK && tempSensorTestResult == TEST_OK) {
return TEST_OK;
if (getTestResult() == TEST_OK) {
if (!temp_sensor::sensors[temp_sensor::CH1 + channelIndex].test()) {
g_slots[slotIndex]->setTestResult(TEST_FAILED);
}
}

return TEST_FAILED;
return isOk();
}

AdcDataType getNextAdcDataType(AdcDataType adcDataType) {
Expand Down
Loading

0 comments on commit a95a3ee

Please sign in to comment.