1 //
2 // Copyright (c) 2010-2023 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 
9 namespace Antmicro.Renode.Peripherals.Helpers
10 {
11     public class CadenceInterruptFlag
12     {
CadenceInterruptFlag(Func<bool> statusProvider = null, bool initialMask = false)13         public CadenceInterruptFlag(Func<bool> statusProvider = null, bool initialMask = false)
14         {
15             this.statusProvider = statusProvider ?? (() => false);
16             this.initialMask = initialMask;
17             Reset();
18         }
19 
Reset()20         public void Reset()
21         {
22             InterruptMask = initialMask;
23             StickyStatus = false;
24             UpdateStickyStatus();
25         }
26 
UpdateStickyStatus()27         public void UpdateStickyStatus()
28         {
29             StickyStatus = StickyStatus || Status;
30         }
31 
SetSticky(bool set)32         public void SetSticky(bool set)
33         {
34             StickyStatus |= set;
35         }
36 
ClearSticky(bool clear)37         public void ClearSticky(bool clear)
38         {
39             StickyStatus &= !clear;
40         }
41 
InterruptEnable(bool enable)42         public void InterruptEnable(bool enable)
43         {
44             InterruptMask |= enable;
45         }
46 
InterruptDisable(bool disable)47         public void InterruptDisable(bool disable)
48         {
49             InterruptMask &= !disable;
50         }
51 
52         public bool Status
53         {
54             get => statusProvider();
55         }
56 
57         public bool StickyStatus { get; private set; }
58 
59         public bool InterruptMask { get; private set; }
60 
61         public bool InterruptStatus
62         {
63             get => StickyStatus && InterruptMask;
64         }
65 
66         private readonly Func<bool> statusProvider;
67         private readonly bool initialMask;
68     }
69 }
70