ghi-electronics / TinyCLR-Libraries

Official Libraries supporting TinyCLR OS
https://www.ghielectronics.com/tinyclr/
17 stars 16 forks source link

RTC not waking from Sleep in 2.2.0.6 #1328

Closed Palomino34 closed 9 months ago

Palomino34 commented 11 months ago

https://forums.ghielectronics.com/t/rtc-not-waking-from-sleep-in-2-2-0-6/24739/23

Special code below can reproduce the issue on SC20260

class Program10
{
    static void Main()
    {
        //RtcController.GetDefault().Now = new DateTime(2000, 1, 1);
        RtcController.GetDefault().Now = new DateTime(2023, 10, 17, 13, 20, 15);
        RtcController.GetDefault().SetChargeMode(BatteryChargeMode.None);

        GpioPin ledDBG = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PH11);

        ledDBG.SetDriveMode(GpioPinDriveMode.Output);
        ledDBG.Write(GpioPinValue.High);

        GpioPin ldr = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PE3);
        ldr.SetDriveMode(GpioPinDriveMode.InputPullUp);
        ldr.ValueChangedEdge = GpioPinEdge.FallingEdge;
        ldr.ValueChanged += (GpioPin sender, GpioPinValueChangedEventArgs e) =>
        {
            Shutdown();
        };
        if (ldr.Read() == GpioPinValue.Low)
        {
            Shutdown();
        }

        Thread.Sleep(1000);

        Power.WakeupEdge = WakeupEdge.Falling;
        DateTime wakeupTime = RtcController.GetDefault().Now.AddSeconds(4);

        Power.Shutdown(false, wakeupTime);

        Thread.Sleep(Timeout.Infinite);

        void Shutdown()
        {
            Power.WakeupEdge = WakeupEdge.Falling;
            //Power.Shutdown(false, RtcController.GetDefault().Now.AddHours(24 * 365 * 5));
            Power.Shutdown(false, RtcController.GetDefault().Now.AddSeconds(7 * 24 * 60 * 60 + 10));
            //Power.Shutdown(false, DateTime.MaxValue);

            while (true) ;
        }
    }
}