SAMD21 wake up time from deep sleep

Hi Martin,

The 6ms delay is gone but I think I prematurely concluded it was "working".

I updated the RTCZero setAlarmEpoch() to use a non-blocking write as follows:

void RTCZero::setAlarmEpoch(uint32_t ts)
{
  if (_configured) {
    if (ts < EPOCH_TIME_OFF) {
      ts = EPOCH_TIME_OFF;
    }

    time_t t = ts;
    struct tm* tmp = gmtime(&t);
    RTC_MODE2_CLOCK_Type alarmTime;

    alarmTime.bit.YEAR = tmp->tm_year - EPOCH_TIME_YEAR_OFF;
    alarmTime.bit.MONTH = tmp->tm_mon + 1;
    alarmTime.bit.DAY = tmp->tm_mday;
    alarmTime.bit.HOUR = tmp->tm_hour;
    alarmTime.bit.MINUTE = tmp->tm_min;
    alarmTime.bit.SECOND = tmp->tm_sec;

    if ( !RTCisSyncing() ) {
      RTC->MODE2.Mode2Alarm[0].ALARM.reg = alarmTime.reg;
    }
//    while (RTCisSyncing())
//      ;

  }

Unfortunately, I am observing that after the second awake cycle, the application appears to hang and my watchdog timer times out and resets the MCU. This is likely caused by "missing" writes to the alarm because the SYNCBUSY flag is set. I surmise now that the register sync is suspended during sleep, not processed. So, when I wake the second time, the SYNCBUSY flag is set and I do not write the next alarm wake time. Thus, the MCU cannot wake and the watchdog resets the MCU.

I think the only way around this problem is to use the event system and the RTC periodic events.