Skip to content

Commit

Permalink
2 second timeout for last radio command
Browse files Browse the repository at this point in the history
  • Loading branch information
amatilda committed Oct 24, 2024
1 parent 94060b4 commit a2be93e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
22 changes: 21 additions & 1 deletion hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@
// LOGGING_UART.println(regs->lr, HEX);
// #endif
// }
uint64_t rtcc_micros(void);
void zunoSleepUpdateSendRadioCmd(void) {
zunoEnterCritical();
g_sleep_data.last_radio_cmd = rtcc_micros();
zunoExitCritical();
}

static bool _zunoSleepUpdateSendRadioCmdIsSleep(void) {
bool b_sleep;

zunoEnterCritical();
if ((rtcc_micros() > g_sleep_data.last_radio_cmd + (2 * 1000 * 1000)))
b_sleep = true;
else
b_sleep = false;
zunoExitCritical();
return (b_sleep);
}

__WEAK bool zunoSysServiceCanSleep();
static uint8_t __zunoSleepingUpd(){
Expand Down Expand Up @@ -69,7 +87,8 @@ static uint8_t __zunoSleepingUpd(){
if(timeout >= millis()){
return 10;
}

if(_zunoSleepUpdateSendRadioCmdIsSleep() == false)
return (11);
#ifdef LOGGING_DBG
LOGGING_UART.print("CORE CODE (");
LOGGING_UART.print((uint32_t)zunoGetCurrentThreadHandle(), HEX);
Expand Down Expand Up @@ -262,6 +281,7 @@ void _zunoInitDefaultWakeup(){
void _zunoInitSleepingData(){
if (zunoIsSleepingMode() == false)
return ;
g_sleep_data.last_radio_cmd = 0x0;
g_sleep_data.timeout = ZUNO_SLEEP_INITIAL_TIMEOUT;
g_sleep_data.user_latch = true;
g_sleep_data.inclusion_latch = false;
Expand Down
1 change: 1 addition & 0 deletions hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ void zunoSetSleepTimeout(uint8_t index, uint32_t timeout);
void zunoSendDeviceToSleep(uint8_t mode = SLEEP_MODE_EM4);
void zunoLockSleep(void);
bool zunoIsSleepLocked();
void zunoSleepUpdateSendRadioCmd(void);
void zunoKickSleepTimeout(uint32_t ms);
void zunoSetSleepingMode(byte mode);
uint8_t zunoGetSleepingMode(void);
Expand Down
8 changes: 7 additions & 1 deletion hardware/arduino/zunoG2/cores/ZWSupport/CommandQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ static void _ZWQSend_outside(ZUNOCommandPacket_t *info, ZUNOCommandCmd_t *p) {
p->src_zw_channel = 0;
zunoSysCall(ZUNO_SYSFUNC_SENDPACKET, 1, p);
p->src_zw_channel = mapped_channel;
#if defined(WITH_CC_BATTERY) || defined(WITH_CC_WAKEUP)
zunoSleepUpdateSendRadioCmd();
#endif
}

void _ZWQSend(ZUNOCommandPacket_t *info){
Expand All @@ -159,7 +162,10 @@ void _ZWQSend(ZUNOCommandPacket_t *info){
return; // do not send association with multichannel encap to plain group
if (_ZWQSend_test(info, p, true) == false)
return ;
zunoSysCall(ZUNO_SYSFUNC_SENDPACKET, 1, p);
zunoSysCall(ZUNO_SYSFUNC_SENDPACKET, 1, p);
#if defined(WITH_CC_BATTERY) || defined(WITH_CC_WAKEUP)
zunoSleepUpdateSendRadioCmd();
#endif
}
void _ZWQRemovePkg(ZUNOCommandPacket_t *info){
ZUNOCommandCmd_t *p;
Expand Down
3 changes: 3 additions & 0 deletions hardware/arduino/zunoG2/cores/ZWSupport/ZWSupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,9 @@ int zuno_CommandHandler(ZUNOCommandCmd_t *cmd) {
bool supervision;
bool multi;

#if defined(WITH_CC_BATTERY) || defined(WITH_CC_WAKEUP)
zunoSleepUpdateSendRadioCmd();
#endif
// delay(10); // TST!
#ifdef LOGGING_DBG
LOGGING_UART.print(millis());
Expand Down
1 change: 1 addition & 0 deletions hardware/arduino/zunoG2/cores/includes/ZUNO_SysTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ typedef struct HandlerFunc_s{

#define MAX_SLEEP_TIMERS 2
typedef struct ZUNOSleepData_s{
uint64_t last_radio_cmd;
uint32_t timeout;
uint32_t wup_timeout;
uint32_t em4_map;
Expand Down

0 comments on commit a2be93e

Please sign in to comment.