Skip to content

Commit

Permalink
read DCP405 channel temperature only inside PSU thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Sep 16, 2020
1 parent f0e25c2 commit 04c6f8c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/eez/drivers/tc77.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ float readTemperature(uint8_t slotIndex) {
uint8_t output[2] = { 0, 0 };
uint8_t result[2];

if (g_isBooted && !isPsuThread()) {
DebugTrace("wrong thread\n");
}

spi::select(slotIndex, spi::CHIP_TEMP_SENSOR);
spi::transfer2(slotIndex, output, result);
spi::deselect(slotIndex);
Expand Down
4 changes: 4 additions & 0 deletions src/eez/modules/dib-dcp405/adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ bool AnalogDigitalConverter::test() {
data[2] = 0;
data[3] = 0;

if (g_isBooted && !isPsuThread()) {
DebugTrace("wrong thread\n");
}

spi::select(slotIndex, spi::CHIP_ADC);
spi::transfer4(slotIndex, data, result);
spi::deselect(slotIndex);
Expand Down
33 changes: 22 additions & 11 deletions src/eez/modules/dib-dcp405/dib-dcp405.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,17 +811,7 @@ struct DcpChannel : public Channel {
return false;
}

float readTemperature() override {
#if defined(EEZ_PLATFORM_STM32)
auto &slot = *g_slots[slotIndex];
if (slot.moduleRevision >= MODULE_REVISION_DCP405_R1B1) {
return drivers::tc77::readTemperature(slotIndex);
} else {
return drivers::tmp1075::readTemperature(slotIndex);
}
#endif
return NAN;
}
float readTemperature() override;

int getAdvancedOptionsPageId() override {
return gui::PAGE_ID_CH_SETTINGS_ADV_OPTIONS;
Expand All @@ -830,6 +820,8 @@ struct DcpChannel : public Channel {

struct DcpModule : public PsuModule {
public:
float temperature = 0;

DcpModule() {
moduleType = MODULE_TYPE_DCP405;
moduleName = "DCP405";
Expand Down Expand Up @@ -952,6 +944,25 @@ struct DcpModule : public PsuModule {
static DcpModule g_dcpModule;
Module *g_module = &g_dcpModule;

float DcpChannel::readTemperature() {
#if defined(EEZ_PLATFORM_STM32)
DcpModule *module = (DcpModule *)g_slots[slotIndex];

if (!isPsuThread()) {
sendMessageToPsu(PSU_MESSAGE_READ_CHANNEL_TEMPERATURE, channelIndex);
} else {
if (module->moduleRevision >= MODULE_REVISION_DCP405_R1B1) {
module->temperature = drivers::tc77::readTemperature(slotIndex);
} else {
module->temperature = drivers::tmp1075::readTemperature(slotIndex);
}
}

return module->temperature;
#endif
return NAN;
}

bool isDacRampActive() {
for (int i = 0; i < CH_NUM; i++) {
auto &channel = Channel::get(i);
Expand Down
5 changes: 4 additions & 1 deletion src/eez/modules/psu/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,10 @@ void onThreadMessage(uint8_t type, uint32_t param) {
} else if (type == PSU_MESSAGE_REMOTE_SENSING_EANBLE) {
Channel &channel = Channel::get((param >> 8) & 0xFF);
channel_dispatcher::remoteSensingEnable(channel, param & 0xFF);
}
} else if (type == PSU_MESSAGE_READ_CHANNEL_TEMPERATURE) {
Channel &channel = Channel::get(param);
channel.readTemperature();
}
}

bool measureAllAdcValuesOnChannel(int channelIndex) {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void lowPriorityThreadOneIter() {
else if (type == THREAD_MESSAGE_GENERATE_ERROR) {
generateError(param);
} else if (type == THREAD_MESSAGE_SAVE_CHANNEL_CALIBRATION) {
if (param < CH_NUM) {
if (param < (unsigned)CH_NUM) {
persist_conf::saveChannelCalibration(Channel::get(param));
} else {
param -= CH_NUM;
Expand Down
3 changes: 2 additions & 1 deletion src/eez/tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ enum HighPriorityThreadMessage {
PSU_MESSAGE_RECALL_STATE,
PSU_MESSAGE_SLOT_SET_ENABLED,
PSU_MESSAGE_SET_CURRENT_RANGE_SELECTION_MODE,
PSU_MESSAGE_REMOTE_SENSING_EANBLE
PSU_MESSAGE_REMOTE_SENSING_EANBLE,
PSU_MESSAGE_READ_CHANNEL_TEMPERATURE
};

enum LowPriorityThreadMessage {
Expand Down

0 comments on commit 04c6f8c

Please sign in to comment.