1 // 2 // Copyright (c) 2010-2024 Antmicro 3 // Copyright (c) 2011-2015 Realtime Embedded 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 using System.Linq; 9 using Antmicro.Renode.Core; 10 using Antmicro.Renode.Logging; 11 using Antmicro.Renode.Peripherals.Miscellaneous; 12 13 namespace Antmicro.Renode.Peripherals.Bus 14 { 15 public interface IGaislerAPB : IBusPeripheral 16 { GetVendorID()17 uint GetVendorID(); GetDeviceID()18 uint GetDeviceID(); GetInterruptNumber()19 uint GetInterruptNumber(); GetSpaceType()20 GaislerAPBPlugAndPlayRecord.SpaceType GetSpaceType(); 21 } 22 23 public static class IGaislerAPBExtensions 24 { GetCpuInterruptNumber(this IGaislerAPB @this, IGPIO gpio)25 public static uint GetCpuInterruptNumber(this IGaislerAPB @this, IGPIO gpio) 26 { 27 var endpoint = gpio.Endpoints.FirstOrDefault(); 28 if(endpoint == null) 29 { 30 return 0; 31 } 32 // For CombinedInputs, the true endpoint is the (*)-marked one in the 33 // Peripheral->CombinedInput->[CombinedInput...]->(*)CPU chain 34 while(endpoint?.Receiver is CombinedInput combiner) 35 { 36 endpoint = combiner.OutputLine.Endpoints.SingleOrDefault(); 37 if(endpoint == null) 38 { 39 @this.WarningLog("IRQ output is connected to a CombinedInput, but this CombinedInput is not " 40 + "connected to a single destination. Check your platform description file."); 41 return 0; 42 } 43 } 44 return (uint)endpoint.Number; 45 } 46 } 47 } 48 49