palm-client: the module can't keep waking a Visor on failing batteries. A slot power handler (SbPwr, in the copied block) stops the chip interrupting on a low-voltage shutdown, as the Springboard guide asks of modules without LOWBAT*; since the Neo's OS never reports that reason, the wake's card event handler and BgArmWake also check the battery and turn the wake off at the OS's warning level. Host-tested; untested on hardware

This commit is contained in:
rich committed 2026-11-08 19:27:39 -05:00
1 parent 6846d4d79b
commit bb2fc014ab
8 files changed
+93 -5

No files matched your search

+2
View File
@@ -83,6 +83,8 @@ With the Slot link, a new message wakes the Visor:
- **App open, Visor asleep:** the app syncs within a few seconds and plays its sound, with the screen still off.
- **App closed:** set Preferences > Check when closed (any interval) before closing. A message starts the closed-app check at once, which syncs, plays the sound and shows the alert, instead of waiting for the next alarm. After a reset or a HotSync install, this starts again from the first regular check.
With the batteries at the OS's low-battery warning level, the wake turns itself off rather than keep waking the Visor; the next check after fresh batteries turns it back on. (The board doesn't use LOWBAT*, and the Neo's OS never tells the module's power handler about a low-voltage shutdown, so this is done in software.)
To test: close VisorMesh, turn the Visor off, and send a DM to the radio from another node (ask before sending on PhillyMesh). The Visor should chirp within a few seconds and show the alert. If it only does so at the next interval, the wake isn't working but the regular check is; note that and the screenshot of the SB-LoRa Test.
## 8. Standby current
+4 -1
View File
@@ -312,7 +312,10 @@ static void AddPending(UInt32 since)
void BgArmWake(void)
{
SbWakeArm(BgInterval() != 0 && TransportGetPort() == VM_PORT_SBLORA);
UInt16 warn = 0, volts = SysBatteryInfo(false, &warn, NULL, NULL, NULL, NULL, NULL);
Boolean low = warn && volts <= warn; /* the OS's low-battery warning level */
SbWakeArm(BgInterval() != 0 && TransportGetPort() == VM_PORT_SBLORA && !low);
}
UInt16 BgCheckRun(void)
+3 -2
View File
@@ -41,8 +41,9 @@ void BgDisplayAlarm(void);
void BgStatusText(Char *out) VM_SECT4;
/*
* With checks on and the Slot link, leaves the module waking the Visor for
* waiting messages after the app closes (SbWakeArm); otherwise removes that.
* With checks on, the Slot link and the battery above the OS's warning
* level, leaves the module waking the Visor for waiting messages after the
* app closes (SbWakeArm); otherwise removes that.
*/
void BgArmWake(void) VM_SECT4;
+5
View File
@@ -25,8 +25,13 @@
/* Called on IRQ* (level, active low); *sysAwakeP false = only memory accesses allowed. */
typedef void (*HsCardIntHandlerPtr)(UInt32 cardParam, Boolean *sysAwakeP);
#define hsCardAttrPwrHandler 10 /* HsCardPwrHandlerPtr */
#define hsCardAttrEvtHandler 11 /* HsCardEvtHandlerPtr */
/* Called as the Visor sleeps or wakes, maybe in interrupt context: memory accesses only. */
typedef void (*HsCardPwrHandlerPtr)(UInt32 cardParam, Boolean sleep, UInt16 reason);
#define hsCardPwrDownLowVoltage 1 /* an emergency shutdown; HsExt.h: never sent by the Neo's OS (HSX 3.5.2) */
/* Called from the event loop after HsCardEventPost; any system call is allowed. */
typedef Boolean (*HsCardEvtHandlerPtr)(UInt32 cardParam, UInt16 evtNum, UInt16 evtParam);
+24 -1
View File
@@ -167,6 +167,8 @@ void SbIrq(SbParam cardParam, Boolean *sysAwakeP)
SbRing *r = (SbRing *)cardParam;
SbDrainRx(r);
if (!(r->ier & SB_IER_RHR))
r->waiting = false; /* shut down for low voltage (SbPwr): no more wakes */
if (!r->waiting)
return;
if (!*sysAwakeP) {
@@ -186,12 +188,33 @@ void SbIrq(SbParam cardParam, Boolean *sysAwakeP)
r->woke = false;
}
void SbPwr(SbParam cardParam, Boolean sleep, UInt16 reason)
{
SbRing *r = (SbRing *)cardParam;
if (!sleep || reason != SB_PWR_LOW_VOLTAGE)
return;
r->ier = SB_IER_SLEEP;
r->waiting = false;
BusWriteReg(&r->bus, SB_IER, r->ier);
}
Boolean SbWakeEvt(SbParam cardParam, UInt16 evtNum, UInt16 evtParam)
{
#ifdef __palmos__
SbRing *r = (SbRing *)cardParam;
LocalID id = DmFindDatabase(r->appCard, r->appName);
UInt16 warn = 0, volts = SysBatteryInfo(false, &warn, NULL, NULL, NULL, NULL, NULL);
UInt8 off = false;
LocalID id;
if (warn && volts <= warn) {
/* no more wakes until the app arms it again (BgArmWake checks the battery too) */
r->ier = SB_IER_SLEEP;
BusWriteReg(&r->bus, SB_IER, r->ier);
HsCardAttrSet(hsCardSlot, hsCardAttrIntEnable, &off);
return true;
}
id = DmFindDatabase(r->appCard, r->appName);
if (id)
AlmSetAlarm(r->appCard, id, 0, TimGetSeconds(), true);
#else
+12 -1
View File
@@ -151,10 +151,21 @@ void SbIrq(SbParam cardParam, Boolean *sysAwakeP);
/*
* The card event handler while the app is closed: sets the app's alarm for
* now, so the closed-app check (bgcheck.c) connects, syncs and alerts.
* now, so the closed-app check (bgcheck.c) connects, syncs and alerts. With
* the battery at the OS's warning level it turns the wake off instead.
*/
Boolean SbWakeEvt(SbParam cardParam, UInt16 evtNum, UInt16 evtParam);
/*
* The slot power handler. On a low-voltage shutdown it stops the chip
* interrupting, so the module can't keep waking a Visor whose batteries are
* failing (the board doesn't use LOWBAT*, as the Springboard guide would
* have it). The Neo's OS never reports that reason, so SbWakeEvt and
* BgArmWake also check the battery themselves.
*/
#define SB_PWR_LOW_VOLTAGE 1
void SbPwr(SbParam cardParam, Boolean sleep, UInt16 reason);
/* The ends of the block SbWakeArm copies. */
void SbCoreStart(void);
void SbCoreEnd(void);
+8
View File
@@ -88,6 +88,7 @@ static Boolean InstallHandler(void)
UInt32 param = (UInt32)&gRing;
HsCardIntHandlerPtr handler = SbIrq;
HsCardEvtHandlerPtr evt = NULL;
HsCardPwrHandlerPtr pwr = SbPwr;
UInt8 enable = true;
MemSet(&gRing, sizeof(gRing) - SB_RING_SIZE, 0);
@@ -97,6 +98,7 @@ static Boolean InstallHandler(void)
HsCardAttrSet(hsCardSlot, hsCardAttrIntHandler, &handler) != errNone)
return false;
HsCardAttrSet(hsCardSlot, hsCardAttrEvtHandler, &evt);
HsCardAttrSet(hsCardSlot, hsCardAttrPwrHandler, &pwr);
SbWriteReg(SB_IER, SB_IER_RHR);
/* interrupts start disabled; the guide says to enable them after installing */
if (HsCardAttrSet(hsCardSlot, hsCardAttrIntEnable, &enable) != errNone) {
@@ -111,9 +113,11 @@ static Boolean InstallHandler(void)
static void RemoveHandler(void)
{
HsCardIntHandlerPtr handler = NULL;
HsCardPwrHandlerPtr pwr = NULL;
IrqEnable(false);
HsCardAttrSet(hsCardSlot, hsCardAttrIntHandler, &handler);
HsCardAttrSet(hsCardSlot, hsCardAttrPwrHandler, &pwr);
gIrq = false;
}
@@ -240,6 +244,7 @@ void SbWakeArm(Boolean on)
void (*start)(void) = SbCoreStart, (*end)(void) = SbCoreEnd;
HsCardIntHandlerPtr irq = SbIrq;
HsCardEvtHandlerPtr evtFn = SbWakeEvt;
HsCardPwrHandlerPtr pwrFn = SbPwr, pwr = NULL;
UInt32 addr, param, coreLen;
SbRing *r;
UInt8 *code;
@@ -253,6 +258,7 @@ void SbWakeArm(Boolean on)
HsCardAttrSet(hsCardSlot, hsCardAttrIntEnable, &enable);
HsCardAttrSet(hsCardSlot, hsCardAttrIntHandler, &handler);
HsCardAttrSet(hsCardSlot, hsCardAttrEvtHandler, &evt);
HsCardAttrSet(hsCardSlot, hsCardAttrPwrHandler, &pwr);
MemPtrFree((MemPtr)addr);
FtrUnregister(VM_CREATOR, VM_FTR_WAKE);
if (!on && ModuleInstalled())
@@ -282,10 +288,12 @@ void SbWakeArm(Boolean on)
param = (UInt32)r;
handler = (HsCardIntHandlerPtr)(code + ((UInt32)irq - (UInt32)start));
evt = (HsCardEvtHandlerPtr)(code + ((UInt32)evtFn - (UInt32)start));
pwr = (HsCardPwrHandlerPtr)(code + ((UInt32)pwrFn - (UInt32)start));
enable = true;
if (HsCardAttrSet(hsCardSlot, hsCardAttrCardParam, &param) != errNone ||
HsCardAttrSet(hsCardSlot, hsCardAttrIntHandler, &handler) != errNone ||
HsCardAttrSet(hsCardSlot, hsCardAttrEvtHandler, &evt) != errNone ||
HsCardAttrSet(hsCardSlot, hsCardAttrPwrHandler, &pwr) != errNone ||
HsCardAttrSet(hsCardSlot, hsCardAttrIntEnable, &enable) != errNone)
SbWakeArm(false);
}
+35
View File
@@ -383,6 +383,40 @@ static void test_wake(void)
CHECK(posts == 1 && resets == 1 && r.wakes == 2);
}
static void test_power(void)
{
static SbRing r;
static const UInt8 waiting[] = { 0x3E, 0x01, 0x00, 0x83 };
Boolean awake;
SimInsert(1);
CHECK(SbProbe());
SbUartInit();
SbSleep(false);
memset(&r, 0, sizeof(r));
r.bus = *SbCurrentBus();
r.ier = SB_IER_RHR | SB_IER_SLEEP;
SbWriteReg(SB_IER, r.ier);
/* a normal sleep or wake changes nothing */
SbPwr((SbParam)&r, 1, 0);
SbPwr((SbParam)&r, 0, 0);
CHECK(r.ier == (SB_IER_RHR | SB_IER_SLEEP) && regs[SB_IER] == r.ier);
/* a low-voltage shutdown: no RX interrupt any more, and a pending wake is dropped */
r.waiting = 1;
SbPwr((SbParam)&r, 1, SB_PWR_LOW_VOLTAGE);
CHECK(regs[SB_IER] == SB_IER_SLEEP && !r.waiting);
/* and a later interrupt (one already in flight) leaves it that way */
posts = resets = 0;
push(waiting, sizeof(waiting));
awake = 0;
SbIrq((SbParam)&r, &awake);
CHECK(!awake && posts == 0 && rxn == 0);
CHECK(regs[SB_IER] == SB_IER_SLEEP);
}
static void test_mapping(void)
{
UInt8 got[2];
@@ -431,6 +465,7 @@ int main(void)
test_drain();
test_waiting();
test_wake();
test_power();
test_mapping();
test_loopback();
if (failures) {