Hal_ticks from a 32-bit counter?

Hi,

I am trying to make it so my Feather M0 can sleep without upsetting LMIC.

I have set up a uint32_t counter (TC4/5) at 32768 Hz (XOSC32K, RUNSTDBY) and modified hal_ticks() to read that counter for its value.

Given LMIC uses a uint32_t for ticks, and its default freq seems to be 32768 Hz, I figured this should work.

Uplinks and downlinks are working so far, but there hasn’t been a roll-over on the counter yet.

The tick value is updated during sleep - I tested that in a separate program.

As long as I take care to not sleep while LMIC wants to do something, does this seem like the right approach?

Yes, that’s exactly the right approach. Much better than what we did several years ago (which also works, but is clunkier): setting alarms using the calendar clock.

You may find that you need to adjust the return value of millis() to match the sleep time; but given that you’ve updated the hal, the LMIC won’t need this.