Skip to content

Commit

Permalink
change power state in psu thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Aug 18, 2019
1 parent b8a7b2e commit f9fda24
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/eez/apps/psu/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void mainLoop(const void *);
#pragma GCC diagnostic ignored "-Wwrite-strings"
#endif

osThreadDef(g_psuTask, mainLoop, osPriorityAboveNormal, 0, 1024);
osThreadDef(g_psuTask, mainLoop, osPriorityAboveNormal, 0, 2048);

#if defined(EEZ_PLATFORM_STM32)
#pragma GCC diagnostic pop
Expand Down
33 changes: 15 additions & 18 deletions src/eez/apps/psu/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,24 +598,23 @@ bool isPowerUp() {
return g_powerIsUp;
}

bool changePowerState(bool up) {
// if (osThreadGetId() != g_psuTaskHandle) {
// osMessagePut(g_psuMessageQueueId, PSU_QUEUE_MESSAGE(PSU_QUEUE_MESSAGE_TYPE_CHANGE_POWER_STATE, up ? 1 : 0), osWaitForever);
// osDelay(1000);
// return up == g_powerIsUp;
// }

void changePowerState(bool up) {
if (up == g_powerIsUp)
return true;
return;

if (up) {
// at least MIN_POWER_UP_DELAY seconds shall pass after last power down
if (g_testPowerUpDelay) {
if (millis() - g_powerDownTime < MIN_POWER_UP_DELAY * 1000)
return false;
g_testPowerUpDelay = false;
}
// at least MIN_POWER_UP_DELAY seconds shall pass after last power down
if (g_testPowerUpDelay) {
if (millis() - g_powerDownTime < MIN_POWER_UP_DELAY * 1000)
return;
g_testPowerUpDelay = false;
}

if (osThreadGetId() != g_psuTaskHandle) {
osMessagePut(g_psuMessageQueueId, PSU_QUEUE_MESSAGE(PSU_QUEUE_MESSAGE_TYPE_CHANGE_POWER_STATE, up ? 1 : 0), osWaitForever);
return;
}

if (up) {
g_bootTestSuccess = true;

// auto recall channels parameters from profile
Expand All @@ -624,7 +623,7 @@ bool changePowerState(bool up) {
auto recall = loadAutoRecallProfile(&profile, &location);

if (!powerUp()) {
return false;
return;
}

// auto recall channels parameters from profile
Expand Down Expand Up @@ -652,8 +651,6 @@ bool changePowerState(bool up) {
g_testPowerUpDelay = true;
g_powerDownTime = millis();
}

return true;
}

void powerDownBySensor() {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/apps/psu/psu.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern bool g_isBooted;
bool powerUp();
void powerDown();
bool isPowerUp();
bool changePowerState(bool up);
void changePowerState(bool up);
void powerDownBySensor();

bool reset();
Expand Down
8 changes: 7 additions & 1 deletion src/eez/apps/psu/scpi/syst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <eez/system.h>

#include <eez/apps/psu/psu.h>

#include <stdio.h>
Expand Down Expand Up @@ -79,7 +81,11 @@ scpi_result_t scpi_cmd_systemPower(scpi_t *context) {
}
#endif

if (!changePowerState(up)) {
changePowerState(up);

osDelay(1000);

if (!isPowerUp()) {
SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR);
return SCPI_RES_ERR;
}
Expand Down

0 comments on commit f9fda24

Please sign in to comment.