Start work on power saving modes.

cert
Rob Riggs 2018-09-19 22:38:18 -05:00
rodzic 8778ad3f1e
commit 7523bac4f4
2 zmienionych plików z 68 dodań i 0 usunięć

52
TNC/PowerMode.cpp 100644
Wyświetl plik

@ -0,0 +1,52 @@
// Copyright 2018 Rob Riggs <rob@mobilinkd.com>
// All rights reserved.
#include "main.h"
#include "PowerMode.h"
#include "stm32l4xx_hal.h"
#include <stdint.h>
volatile PowerMode power_mode{PowerMode::RUN};
PowerMode previous_mode{PowerMode::RUN}; // Always start in RUN mode.
/**
* Handle state transitions here. Valid transitions are from RUN to any mode,
* LPRUN to any mode, SLEEP to LPRUN or STOP, and STOP to LPRUN or SLEEP.
*
* If moving from RUN to any SLEEP or STOP, we assume the upper layers have
* already disconnected the connection, either bu
*
* @param ulExpectedIdleTime
*/
extern "C" void PreSleepProcessing(uint32_t *ulExpectedIdleTime)
{
switch (power_mode)
{
case PowerMode::RUN:
break;
case PowerMode::LPRUN:
if (previous_mode != power_mode);
break;
case PowerMode::SLEEP:
break;
case PowerMode::STOP:
break;
}
}
extern "C" void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
{
switch (power_mode)
{
case PowerMode::RUN:
break;
case PowerMode::LPRUN:
break;
case PowerMode::SLEEP:
break;
case PowerMode::STOP:
break;
}
}

16
TNC/PowerMode.h 100644
Wyświetl plik

@ -0,0 +1,16 @@
// Copyright 2018 Rob Riggs <rob@mobilinkd.com>
// All rights reserved.
#ifndef TNC_POWERMODE_H_
#define TNC_POWERMODE_H_
enum class PowerMode {
RUN, // Power on, connected.
LPRUN, // Power on, not connected.
SLEEP, // Power off, USB connected.
STOP // Power off, no USB connection.
};
extern volatile PowerMode power_mode;
#endif // TNC_POWERMODE_H_