1 //
2 // Copyright (c) 2010-2022 Antmicro
3 //
4 // This file is licensed under the MIT License.
5 // Full license text is available in 'licenses/MIT.txt'.
6 //
7 using System;
8 using System.Collections.Generic;
9 using Antmicro.Renode.Core;
10 using Antmicro.Renode.Core.Structure.Registers;
11 using Antmicro.Renode.Peripherals.Timers;
12 
13 namespace Antmicro.Renode.Peripherals.Miscellaneous
14 {
15     public class MAX32650_PWRSEQ : BasicDoubleWordPeripheral, IKnownSize
16     {
MAX32650_PWRSEQ(IMachine machine, MAX32650_RTC rtc)17         public MAX32650_PWRSEQ(IMachine machine, MAX32650_RTC rtc) : base(machine)
18         {
19             RTC = rtc;
20             DefineRegisters();
21         }
22 
23         public long Size => 0x400;
24 
DefineRegisters()25         private void DefineRegisters()
26         {
27             Registers.Control.Define(this, 0x1800)
28                 .WithTag("LP_CTRL.ramret", 0, 2)
29                 .WithReservedBits(2, 6)
30                 .WithTaggedFlag("LP_CTRL.rregen", 8)
31                 .WithTaggedFlag("LP_CTRL.bkgrnd", 9)
32                 .WithTaggedFlag("LP_CTRL.fwkm", 10)
33                 .WithTaggedFlag("LP_CTRL.bgoff", 11)
34                 .WithTaggedFlag("LP_CTRL.porvcoremd", 12)
35                 .WithReservedBits(13, 7)
36                 .WithFlag(20, name: "LP_CTRL.vcoremd",
37                     valueProviderCallback: _ => (RTC.SubSecondsSignificantBits & 0x01) != 0x00)
38                 .WithFlag(21, name: "LP_CTRL.vrt(cmd",
39                     valueProviderCallback: _ => (RTC.SubSecondsSignificantBits & 0x02) != 0x00)
40                 .WithFlag(22, name: "LP_CTRL.vdd(amd",
41                     valueProviderCallback: _ => (RTC.SubSecondsSignificantBits & 0x04) != 0x00)
42                 .WithFlag(23, name: "LP_CTRL.vdd(iomd",
43                     valueProviderCallback: _ => (RTC.SubSecondsSignificantBits & 0x08) != 0x00)
44                 .WithTaggedFlag("LP_CTRL.vddiohmd", 24)
45                 .WithReservedBits(25, 2)
46                 .WithTaggedFlag("LP_CTRL.vddbmd", 27)
47                 .WithReservedBits(28, 4);
48         }
49 
50         private readonly MAX32650_RTC RTC;
51 
52         private enum Registers
53         {
54             Control = 0x00,
55             GPIO0WakeupEnable = 0x04,
56             GPIO0WakeupFlags = 0x08,
57             GPIO1WakeupEnable = 0x0C,
58             GPIO1WakeupFlags = 0x10,
59             GPIO2WakeupEnable = 0x14,
60             GPIO2WakeupFlags = 0x18,
61             GPIO3WakeupEnable = 0x1C,
62             GPIO3WakeupFlags = 0x20,
63             USBWakeupStatus = 0x30,
64             USBWakeupEnable = 0x34,
65             RAMShutDownControl = 0x40,
66         }
67     }
68 }
69