1 // 2 // Copyright (c) 2010-2024 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 8 using Antmicro.Renode.Logging; 9 10 namespace Antmicro.Renode.Peripherals.IRQControllers.PLIC 11 { 12 public class IrqSource 13 { IrqSource(uint id, IPlatformLevelInterruptController irqController)14 public IrqSource(uint id, IPlatformLevelInterruptController irqController) 15 { 16 this.parent = irqController; 17 18 Id = id; 19 Reset(); 20 } 21 ToString()22 public override string ToString() 23 { 24 return $"IrqSource id: {Id}, priority: {Priority}, state: {State}"; 25 } 26 Reset()27 public void Reset() 28 { 29 Priority = DefaultPriority; 30 State = false; 31 } 32 33 public uint Id { get; private set; } 34 35 public uint Priority 36 { 37 get { return priority; } 38 set 39 { 40 if(value == priority) 41 { 42 return; 43 } 44 45 parent.Log(LogLevel.Noisy, "Setting priority {0} for source #{1}", value, Id); 46 priority = value; 47 } 48 } 49 50 public bool State 51 { 52 get { return state; } 53 set 54 { 55 if(value == state) 56 { 57 return; 58 } 59 60 state = value; 61 parent.Log(LogLevel.Noisy, "Setting state to {0} for source #{1}", value, Id); 62 } 63 } 64 65 private uint priority; 66 private bool state; 67 68 private readonly IPlatformLevelInterruptController parent; 69 70 // 1 is the default, lowest value. 0 means "no interrupt". 71 private const uint DefaultPriority = 1; 72 } 73 } 74