diff --git a/hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.cpp b/hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.cpp index d27e812f..8ef3fa30 100644 --- a/hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.cpp +++ b/hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.cpp @@ -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(){ @@ -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); @@ -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; diff --git a/hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.h b/hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.h index fa23d9fc..b28302eb 100644 --- a/hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.h +++ b/hardware/arduino/zunoG2/cores/LLCore/zuno_sleep.h @@ -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); diff --git a/hardware/arduino/zunoG2/cores/ZWSupport/CommandQueue.c b/hardware/arduino/zunoG2/cores/ZWSupport/CommandQueue.c index 0ae52a23..99bae0cd 100644 --- a/hardware/arduino/zunoG2/cores/ZWSupport/CommandQueue.c +++ b/hardware/arduino/zunoG2/cores/ZWSupport/CommandQueue.c @@ -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){ @@ -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; diff --git a/hardware/arduino/zunoG2/cores/ZWSupport/ZWSupport.c b/hardware/arduino/zunoG2/cores/ZWSupport/ZWSupport.c index 6daa6f66..1adf0ae1 100644 --- a/hardware/arduino/zunoG2/cores/ZWSupport/ZWSupport.c +++ b/hardware/arduino/zunoG2/cores/ZWSupport/ZWSupport.c @@ -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()); diff --git a/hardware/arduino/zunoG2/cores/includes/ZUNO_SysTypes.h b/hardware/arduino/zunoG2/cores/includes/ZUNO_SysTypes.h index 2ab1251d..2345a28e 100644 --- a/hardware/arduino/zunoG2/cores/includes/ZUNO_SysTypes.h +++ b/hardware/arduino/zunoG2/cores/includes/ZUNO_SysTypes.h @@ -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;