Skip to content

Commit

Permalink
g_fastTickEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Dec 4, 2021
1 parent 6ea8724 commit 65fc42c
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/bb3/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ void action_user_switch_clicked() {
break;

case persist_conf::USER_SWITCH_ACTION_STANDBY:
changePowerState(isPowerUp() ? false : true);
changePowerState(g_powerIsUp ? false : true);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bb3/aux_ps/fan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ int updateFanSpeed() {
fanSpeed = psu::persist_conf::devConf.fanSpeedPWM;
}

if (psu::isPowerUp() && fanMode == FAN_MODE_MANUAL) {
if (psu::g_powerIsUp && fanMode == FAN_MODE_MANUAL) {
if (fanSpeed == 0) {
newFanSpeedPWM = 0;
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/bb3/dib-dcp405/dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void DigitalAnalogConverter::tick() {
if (diff >= CONF_U_RAMP_DURATION_USEC) {
value = m_uRampTargetValue;
m_uIsRampActive = false;
updateFastTickEnabled();
} else {
value = m_uRampTargetValue * diff / CONF_U_RAMP_DURATION_USEC;
}
Expand All @@ -156,6 +157,7 @@ void DigitalAnalogConverter::tick() {
if (diff >= CONF_I_RAMP_DURATION_USEC) {
value = m_iRampTargetValue;
m_iIsRampActive = false;
updateFastTickEnabled();
} else {
value = m_iRampTargetValue * diff / CONF_I_RAMP_DURATION_USEC;
}
Expand Down Expand Up @@ -233,6 +235,7 @@ void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value, RampOption ramp
!ramp::isActive(channel)
) {
m_uIsRampActive = true;
updateFastTickEnabled();
m_uRampTargetValue = value;
value = 0;
rampOption = FROM_RAMP;
Expand All @@ -243,6 +246,7 @@ void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value, RampOption ramp

if (rampOption != FROM_RAMP) {
m_uIsRampActive = false;
updateFastTickEnabled();
}

m_uLastValue = value;
Expand All @@ -253,6 +257,7 @@ void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value, RampOption ramp
!ramp::isActive(channel)
) {
m_iIsRampActive = true;
updateFastTickEnabled();
m_iRampTargetValue = value;
value = 0;
rampOption = FROM_RAMP;
Expand All @@ -263,6 +268,7 @@ void DigitalAnalogConverter::set(uint8_t buffer, uint16_t value, RampOption ramp

if (rampOption != FROM_RAMP) {
m_iIsRampActive = false;
updateFastTickEnabled();
}

m_iLastValue = value;
Expand Down
2 changes: 1 addition & 1 deletion src/bb3/firmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ void shutdown() {
channel_dispatcher::disableOutputForAllChannels();
psu::tick();

if (psu::isPowerUp()) {
if (psu::g_powerIsUp) {
psu::changePowerState(false);
}

Expand Down
34 changes: 2 additions & 32 deletions src/bb3/function_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@ void executionStart() {

if (triggerMode == TRIGGER_MODE_FUNCTION_GENERATOR) {
g_active = true;
updateFastTickEnabled();
reloadWaveformParameters();
return;
}
Expand Down Expand Up @@ -2005,13 +2006,12 @@ void tick() {
}
}
}


}

void abort() {
if (g_active) {
g_active = false;
updateFastTickEnabled();

for (int i = 0; i < CH_NUM; i++) {
if (g_dprogStateModified[i]) {
Expand All @@ -2027,36 +2027,6 @@ void abort() {
}
}

void tickGui() {
// // change m_selectedItem to the currently selected channel in max view
// if (psu::gui::getActivePageId() == PAGE_ID_MAIN && persist_conf::isMaxView()) {
// int maxSlotIndex = persist_conf::getMaxSlotIndex();
// int maxSubchannelIndex = persist_conf::getMaxSubchannelIndex();

// auto &waveformParameters = g_functionGeneratorPage.m_selectedResources.m_waveformParameters[g_functionGeneratorPage.m_selectedItem];
// int slotIndex;
// int subchannelIndex;
// int resourceIndex;
// AllResources::findResource(waveformParameters.absoluteResourceIndex,
// slotIndex, subchannelIndex, resourceIndex);

// if (slotIndex != maxSlotIndex || (maxSubchannelIndex != -1 && subchannelIndex != maxSubchannelIndex)) {
// for (int i = 0; i < g_selectedResources.m_numResources; i++) {
// auto &waveformParameters = g_functionGeneratorPage.m_selectedResources.m_waveformParameters[i];
// int slotIndex;
// int subchannelIndex;
// int resourceIndex;
// AllResources::findResource(waveformParameters.absoluteResourceIndex,
// slotIndex, subchannelIndex, resourceIndex);
// if (slotIndex == maxSlotIndex && (maxSubchannelIndex == -1 || maxSubchannelIndex == subchannelIndex)) {
// g_functionGeneratorPage.m_selectedItem = i;
// break;
// }
// }
// }
// }
}

} // namespace function_generator
} // namespace eez

Expand Down
2 changes: 0 additions & 2 deletions src/bb3/function_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ void executionStart();
void tick();
void abort();

void tickGui();

extern eez::gui::SetPage *g_pFunctionGeneratorPage;
extern eez::gui::SetPage *g_pFunctionGeneratorSelectChannelsPage;

Expand Down
6 changes: 3 additions & 3 deletions src/bb3/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ void onIncomingPublish(const char *topic, const char *payload) {
char *endptr;
int powerUp = strtol(payload, &endptr, 10);
if (endptr > payload) {
if (powerUp && !isPowerUp()) {
if (powerUp && !g_powerIsUp) {
changePowerState(1);
} else if (!powerUp && isPowerUp()) {
} else if (!powerUp && g_powerIsUp) {
standBy();
}
}
Expand Down Expand Up @@ -616,7 +616,7 @@ void tick() {
uint32_t period = (uint32_t)roundf(persist_conf::devConf.mqttPeriod * 1000);

// publish power state
int powState = isPowerUp() ? 1 : 0;
int powState = g_powerIsUp ? 1 : 0;
if (powState != g_powState) {
if (publish(PUB_TOPIC_SYSTEM_POW, powState, true)) {
g_powState = powState;
Expand Down
8 changes: 2 additions & 6 deletions src/bb3/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,6 @@ void Channel::clearProtectionConf() {
temperature::sensors[temp_sensor::CH1 + channelIndex].prot_conf.delay = OTP_CH_DEFAULT_DELAY;
}

bool Channel::isPowerOk() {
return flags.powerOk;
}

TestResult Channel::getTestResult() {
return g_slots[slotIndex]->getTestResult();
}
Expand All @@ -614,7 +610,7 @@ bool Channel::isTestOk() {
}

bool Channel::isOk() {
return (g_slots[slotIndex]->enabled && isPowerUp() && isPowerOk() && isTestOk() && !bp3c::flash_slave::g_bootloaderMode) ||
return (g_slots[slotIndex]->enabled && g_powerIsUp && flags.powerOk && g_slots[slotIndex]->getTestResult() == TEST_OK && !bp3c::flash_slave::g_bootloaderMode) ||
(bp3c::flash_slave::g_bootloaderMode && bp3c::flash_slave::g_ate && channelIndex == 0);
}

Expand Down Expand Up @@ -1052,7 +1048,7 @@ void Channel::doRemoteProgrammingEnable(bool enable) {
}

bool Channel::isOutputEnabled() {
return isPowerUp() && flags.outputEnabled;
return g_powerIsUp && flags.outputEnabled;
}

void Channel::doCalibrationEnable(bool enable) {
Expand Down
3 changes: 0 additions & 3 deletions src/bb3/psu/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,6 @@ struct Channel {

void initParams(uint16_t moduleRevision);

/// Is channel power ok (state of PWRGOOD bit in IO Expander)?
bool isPowerOk();

/// Is channel test failed?
bool isTestFailed();

Expand Down
4 changes: 1 addition & 3 deletions src/bb3/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void PsuAppContext::stateManagment() {
#endif

// turn the screen off if power is down and system is booted
if (!psu::isPowerUp()) {
if (!g_powerIsUp) {
if (g_isBooted && !g_shutdownInProgress && getActivePageId() != PAGE_ID_NONE) {
showPage(PAGE_ID_NONE);
eez::display::turnOff();
Expand Down Expand Up @@ -393,8 +393,6 @@ void PsuAppContext::stateManagment() {
}

testIsEncoderEnabledInActivePage();

function_generator::tickGui();
}

bool PsuAppContext::isActiveWidget(const WidgetCursor &widgetCursor) {
Expand Down
4 changes: 2 additions & 2 deletions src/bb3/psu/io_pins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void ioPinWrite(int pin, int state) {

uint8_t isOutputFault() {
#if OPTION_FAN
if (isPowerUp()) {
if (g_powerIsUp) {
if (aux_ps::fan::g_testResult == TEST_FAILED) {
return 1;
}
Expand Down Expand Up @@ -244,7 +244,7 @@ void updatePwmFrequency(int pin) {

updatePwmDuty(pin);

if (isPowerUp() && frequency > 0) {
if (g_powerIsUp && frequency > 0) {
if (!g_pwmStarted) {
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
g_pwmStarted = true;
Expand Down
2 changes: 1 addition & 1 deletion src/bb3/psu/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ static bool repositionChannelsInProfileToMatchCurrentChannelConfiguration(Parame

static void saveState(Parameters &profile, List *lists) {
profile.flags.couplingType = channel_dispatcher::getCouplingType();
profile.flags.powerIsUp = isPowerUp();
profile.flags.powerIsUp = g_powerIsUp;

for (int i = 0; i < NUM_SLOTS; ++i) {
profile.slots[i].moduleType = g_slots[i]->moduleType;
Expand Down
18 changes: 11 additions & 7 deletions src/bb3/psu/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ extern "C" void PSU_IncTick() {

using namespace eez;
using namespace eez::psu;
if (ramp::isActive() || eez::dcp405::isDacRampActive() || function_generator::isActive()) {
if (g_fastTickEnabled) {
sendMessageToPsu(PSU_MESSAGE_TICK, 0, 0);
}
}
Expand All @@ -193,7 +193,7 @@ namespace psu {

////////////////////////////////////////////////////////////////////////////////

static bool g_powerIsUp;
bool g_powerIsUp;
static bool g_testPowerUpDelay;
static uint32_t g_powerDownTime;

Expand All @@ -207,6 +207,14 @@ void (*g_diagCallback)();

bool g_adcMeasureAllFinished = false;

bool g_fastTickEnabled;

////////////////////////////////////////////////////////////////////////////////

void updateFastTickEnabled() {
g_fastTickEnabled = ramp::isActive() || eez::dcp405::isDacRampActive() || function_generator::isActive();
}

////////////////////////////////////////////////////////////////////////////////

void PsuModule::setEnabled(bool value) {
Expand Down Expand Up @@ -1307,10 +1315,6 @@ void powerDownChannels(bool onlyPowerChannels) {
}
}

bool isPowerUp() {
return g_powerIsUp;
}

void changePowerState(bool up) {
if (up == g_powerIsUp)
return;
Expand Down Expand Up @@ -1355,7 +1359,7 @@ void powerDownBySensor() {
////////////////////////////////////////////////////////////////////////////////

void onProtectionTripped() {
if (isPowerUp()) {
if (g_powerIsUp) {
if (persist_conf::isShutdownWhenProtectionTrippedEnabled()) {
powerDownBySensor();
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/bb3/psu/psu.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ bool powerUp();
void powerDown();
void powerDownOnlyPowerChannels();
void powerDownChannels(bool onlyPowerChannels = false);
bool isPowerUp();
extern bool g_powerIsUp;
void changePowerState(bool up);
void powerDownBySensor();

Expand All @@ -186,6 +186,9 @@ bool autoRecall(int recallOptions = 0);

void onProtectionTripped();

extern bool g_fastTickEnabled;
void updateFastTickEnabled();

void tick();

void setQuesBits(int bit_mask, bool on);
Expand Down
1 change: 1 addition & 0 deletions src/bb3/psu/ramp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ static void updateChannelsWithVisibleCountersList() {
static void setActive(bool active, bool forceUpdate) {
if (g_active != active) {
g_active = active;
updateFastTickEnabled();
updateChannelsWithVisibleCountersList();
} else {
if (forceUpdate) {
Expand Down
4 changes: 2 additions & 2 deletions src/bb3/psu/scpi/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ bool checkPowerChannel(scpi_t *context, int channelIndex) {
return false;
}

if (!isPowerUp()) {
if (!g_powerIsUp) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return false;
}
Expand All @@ -332,7 +332,7 @@ bool checkPowerChannel(scpi_t *context, int channelIndex) {
return false;
}

if (!channel.isPowerOk()) {
if (!channel.flags.powerOk) {
if (channelIndex < 6) {
SCPI_ErrorPush(context, SCPI_ERROR_CH1_FAULT_DETECTED - channelIndex);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/bb3/psu/scpi/syst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ scpi_result_t scpi_cmd_systemPower(scpi_t *context) {
}

scpi_result_t scpi_cmd_systemPowerQ(scpi_t *context) {
SCPI_ResultBool(context, isPowerUp());
SCPI_ResultBool(context, g_powerIsUp);
return SCPI_RES_OK;
}

Expand Down Expand Up @@ -2013,7 +2013,7 @@ scpi_result_t scpi_cmd_systemMeasureScalarTemperatureThermistorDcQ(scpi_t *conte
}

Channel *channel = temperature::sensors[sensor].getChannel();
if (channel && (!isPowerUp() || !channel->isPowerOk())) {
if (channel && (!g_powerIsUp || !channel->flags.powerOk)) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bb3/psu/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void tick() {
}

// check if max_channel_temperature is too high
if (isPowerUp() && maxChannelTemperature > FAN_MAX_TEMP) {
if (g_powerIsUp && maxChannelTemperature > FAN_MAX_TEMP) {
if (g_lastMaxChannelTemperature <= FAN_MAX_TEMP) {
g_maxTempCheckStartTickMs = tickCountMs;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bb3/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void highPriorityThreadOneIter() {
if (diffMs == 0) {
return;
}
if (psu::ramp::isActive() || eez::dcp405::isDacRampActive() || function_generator::isActive()) {
if (psu::g_fastTickEnabled) {
return;
}
#endif
Expand Down

0 comments on commit 65fc42c

Please sign in to comment.