mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 17:42:48 +00:00
add crude check for brownout
This commit is contained in:
parent
f8ec072093
commit
87ec7b09aa
@ -25,7 +25,8 @@ typedef enum _CriticalErrorCode {
|
|||||||
CriticalErrorCode_UBloxInitFailed = 5,
|
CriticalErrorCode_UBloxInitFailed = 5,
|
||||||
CriticalErrorCode_NoAXP192 = 6,
|
CriticalErrorCode_NoAXP192 = 6,
|
||||||
CriticalErrorCode_InvalidRadioSetting = 7,
|
CriticalErrorCode_InvalidRadioSetting = 7,
|
||||||
CriticalErrorCode_TransmitFailed = 8
|
CriticalErrorCode_TransmitFailed = 8,
|
||||||
|
CriticalErrorCode_Brownout = 9
|
||||||
} CriticalErrorCode;
|
} CriticalErrorCode;
|
||||||
|
|
||||||
typedef enum _Routing_Error {
|
typedef enum _Routing_Error {
|
||||||
@ -177,8 +178,8 @@ typedef struct _ToRadio {
|
|||||||
#define _Constants_ARRAYSIZE ((Constants)(Constants_DATA_PAYLOAD_LEN+1))
|
#define _Constants_ARRAYSIZE ((Constants)(Constants_DATA_PAYLOAD_LEN+1))
|
||||||
|
|
||||||
#define _CriticalErrorCode_MIN CriticalErrorCode_None
|
#define _CriticalErrorCode_MIN CriticalErrorCode_None
|
||||||
#define _CriticalErrorCode_MAX CriticalErrorCode_TransmitFailed
|
#define _CriticalErrorCode_MAX CriticalErrorCode_Brownout
|
||||||
#define _CriticalErrorCode_ARRAYSIZE ((CriticalErrorCode)(CriticalErrorCode_TransmitFailed+1))
|
#define _CriticalErrorCode_ARRAYSIZE ((CriticalErrorCode)(CriticalErrorCode_Brownout+1))
|
||||||
|
|
||||||
#define _Routing_Error_MIN Routing_Error_NONE
|
#define _Routing_Error_MIN Routing_Error_NONE
|
||||||
#define _Routing_Error_MAX Routing_Error_TOO_LARGE
|
#define _Routing_Error_MAX Routing_Error_TOO_LARGE
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "NRF52Bluetooth.h"
|
#include "NRF52Bluetooth.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
#include "error.h"
|
||||||
#include "graphics/TFTDisplay.h"
|
#include "graphics/TFTDisplay.h"
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
@ -51,14 +52,14 @@ void getMacAddr(uint8_t *dmac)
|
|||||||
NRF52Bluetooth *nrf52Bluetooth;
|
NRF52Bluetooth *nrf52Bluetooth;
|
||||||
|
|
||||||
static bool bleOn = false;
|
static bool bleOn = false;
|
||||||
static const bool enableBle = false; // Set to false for easier debugging
|
static const bool useSoftDevice = false; // Set to false for easier debugging
|
||||||
|
|
||||||
void setBluetoothEnable(bool on)
|
void setBluetoothEnable(bool on)
|
||||||
{
|
{
|
||||||
if (on != bleOn) {
|
if (on != bleOn) {
|
||||||
if (on) {
|
if (on) {
|
||||||
if (!nrf52Bluetooth) {
|
if (!nrf52Bluetooth) {
|
||||||
if (!enableBle)
|
if (!useSoftDevice)
|
||||||
DEBUG_MSG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
DEBUG_MSG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
||||||
else {
|
else {
|
||||||
nrf52Bluetooth = new NRF52Bluetooth();
|
nrf52Bluetooth = new NRF52Bluetooth();
|
||||||
@ -87,6 +88,49 @@ int printf(const char *fmt, ...)
|
|||||||
|
|
||||||
#include "BQ25713.h"
|
#include "BQ25713.h"
|
||||||
|
|
||||||
|
void initBrownout()
|
||||||
|
{
|
||||||
|
auto vccthresh = POWER_POFCON_THRESHOLD_V28;
|
||||||
|
auto vcchthresh = POWER_POFCON_THRESHOLDVDDH_V27;
|
||||||
|
|
||||||
|
if (useSoftDevice) {
|
||||||
|
auto err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled);
|
||||||
|
assert(err_code == NRF_SUCCESS);
|
||||||
|
|
||||||
|
err_code = sd_power_pof_threshold_set(vccthresh);
|
||||||
|
assert(err_code == NRF_SUCCESS);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NRF_POWER->POFCON = POWER_POFCON_POF_Msk | (vccthresh << POWER_POFCON_THRESHOLD_Pos) | (vcchthresh << POWER_POFCON_THRESHOLDVDDH_Pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkSDEvents()
|
||||||
|
{
|
||||||
|
if (useSoftDevice) {
|
||||||
|
uint32_t evt;
|
||||||
|
while (NRF_ERROR_NOT_FOUND == sd_evt_get(&evt)) {
|
||||||
|
switch (evt) {
|
||||||
|
case NRF_EVT_POWER_FAILURE_WARNING:
|
||||||
|
recordCriticalError(CriticalErrorCode_Brownout);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
DEBUG_MSG("Unexpected SDevt %d\n", evt);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(NRF_POWER->EVENTS_POFWARN)
|
||||||
|
recordCriticalError(CriticalErrorCode_Brownout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nrf52Loop()
|
||||||
|
{
|
||||||
|
checkSDEvents();
|
||||||
|
}
|
||||||
|
|
||||||
void nrf52Setup()
|
void nrf52Setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -112,6 +156,8 @@ void nrf52Setup()
|
|||||||
// randomSeed(r);
|
// randomSeed(r);
|
||||||
DEBUG_MSG("FIXME, call randomSeed\n");
|
DEBUG_MSG("FIXME, call randomSeed\n");
|
||||||
// ::printf("TESTING PRINTF\n");
|
// ::printf("TESTING PRINTF\n");
|
||||||
|
|
||||||
|
initBrownout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cpuDeepSleep(uint64_t msecToWake)
|
void cpuDeepSleep(uint64_t msecToWake)
|
||||||
@ -128,7 +174,7 @@ void cpuDeepSleep(uint64_t msecToWake)
|
|||||||
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled
|
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled
|
||||||
|
|
||||||
auto ok = sd_power_system_off();
|
auto ok = sd_power_system_off();
|
||||||
if(ok != NRF_SUCCESS) {
|
if (ok != NRF_SUCCESS) {
|
||||||
DEBUG_MSG("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!\n");
|
DEBUG_MSG("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!\n");
|
||||||
NRF_POWER->SYSTEMOFF = 1;
|
NRF_POWER->SYSTEMOFF = 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user