public void AttachGPIO(IPeripheral source, string connectorName, IGPIOReceiver destination, int destinationNumber, int?localReceiverNumber = null) { var connectors = source.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.Name == connectorName && typeof(GPIO).IsAssignableFrom(x.PropertyType)).ToArray(); var actualDestination = GetActualReceiver(destination, localReceiverNumber); DoAttachGPIO(source, connectors, actualDestination, destinationNumber); }
//This method should not be executed on a runnning emulation, as IGPIO.Connect call //may lead to nondeterminism. public void SelectDestinationPin(IGPIOReceiver receiver, int pinNumber) { VerifyPeripheralOrThrow(receiver); if (connectorPin.IsConnected) { this.Log(LogLevel.Warning, "Overwriting destination PIN connection."); destinationMachine.MachineReset -= ResetDestinationPinState; } GetDestinationMachineAndAttachToEvent(receiver); connectorPin.Connect(receiver, pinNumber); }
private static void Validate(IGPIOReceiver to, int toNumber) { var destPeriAttribute = GetAttribute(to); var destPeriInNum = destPeriAttribute != null ? destPeriAttribute.NumberOfInputs : 0; if (destPeriInNum != 0 && toNumber >= destPeriInNum) { throw new ConstructionException(string.Format( "Cannot connect {0}th input of {1}; it has only {2} GPIO inputs.", toNumber, to, destPeriInNum)); } }
private static void DoAttachGPIO(IPeripheral source, PropertyInfo[] gpios, IGPIOReceiver destination, int destinationNumber) { if (gpios.Length == 0) { throw new RecoverableException("No GPIO connector found."); } if (gpios.Length > 1) { throw new RecoverableException("Ambiguous GPIO connector. Available connectors are: {0}." .FormatWith(gpios.Select(x => x.Name).Aggregate((x, y) => x + ", " + y))); } (gpios[0].GetValue(source, null) as GPIO).Connect(destination, destinationNumber); }
public void Connect(IGPIOReceiver destination, int destinationNumber) { if (destination == null) { throw new ArgumentNullException("destination"); } Validate(destination, destinationNumber); lock (sync) { target = destination; targetNumber = destinationNumber; target.OnGPIO(destinationNumber, state); } }
public void Connect(IGPIOReceiver destination, int destinationNumber) { if(destination == null) { throw new ArgumentNullException("destination"); } Validate(destination, destinationNumber); lock(sync) { target = destination; targetNumber = destinationNumber; target.OnGPIO(destinationNumber, state); } }
private static IGPIOReceiver GetActualReceiver(IGPIOReceiver receiver, int?localReceiverNumber) { var localReceiver = receiver as ILocalGPIOReceiver; if (localReceiverNumber.HasValue) { if (localReceiver != null) { return(localReceiver.GetLocalReceiver(localReceiverNumber.Value)); } throw new RecoverableException("The specified receiver does not support localReceiverNumber."); } return(receiver); }
public void Connect(IGPIOReceiver destination, int destinationNumber) { if (destination == null) { throw new ArgumentNullException("destination"); } Validate(destination, destinationNumber); lock (sync) { if (!targets.Any(x => x.Receiver == destination && x.Number == destinationNumber)) { targets.Add(new GPIOEndpoint(destination, destinationNumber)); destination.OnGPIO(destinationNumber, state); } } }
public void AttachGPIO(IPeripheral source, int sourceNumber, IGPIOReceiver destination, int destinationNumber, int?localReceiverNumber = null) { var sourceByNumber = source as INumberedGPIOOutput; IGPIO igpio; if (sourceByNumber == null) { throw new RecoverableException("Source peripheral cannot be connected by number."); } if (!sourceByNumber.Connections.TryGetValue(sourceNumber, out igpio)) { throw new RecoverableException(string.Format("Source peripheral has no GPIO number: {0}", source)); } var actualDestination = GetActualReceiver(destination, localReceiverNumber); igpio.Connect(actualDestination, destinationNumber); }
private void HandleIRQConnect(int src, IGPIOReceiver receiver, int dst) { switch(dst) { case 0: irqs[src].Connect(receiver, dst); break; case 1: resets[src].Connect(receiver, dst); break; case 2: runs[src].Connect(receiver, dst); break; default: this.Log(LogLevel.Warning, "Destination index value is undefined {0:X}", dst); break; } }
private void HandleIRQConnect(int sourceNumber, IGPIOReceiver destination, int destinationNumber) { if (sourceNumber > 223) { lock (interProcessorInterrupts) { if (sourceNumber - 224 >= interProcessorInterrupts.Length) { throw new ArgumentException("Invalid source number."); } interProcessorInterrupts[sourceNumber - 224].Connect(destination, destinationNumber); } return; } lock (routingTable) { destinations[sourceNumber] = new Destination(destination, destinationNumber); } }
void InitializeGPIO(IPeripheral device, string deviceName, IGPIOReceiver receiver, IList <object> irqEntry, PropertyInfo defaultConnector) { if (!(irqEntry[0] is string && irqEntry[1] is int)) { throw new ArgumentException(); } //May throw AmbiguousMatchException - then use BindingFlags.DeclaredOnly or sth var connector = device.GetType().GetProperty(irqEntry[0] as string); if (connector == null) { throw new ArgumentException(); } var gpio = connector.GetValue(device, null) as GPIO; if (gpio == null) { FailDevice(deviceName); } gpio.Connect(receiver, (int)irqEntry[1]); }
private void HandleIRQConnect(int src, IGPIOReceiver receiver, int dst) { switch (dst) { case 0: irqs[src].Connect(receiver, dst); break; case 1: resets[src].Connect(receiver, dst); break; case 2: runs[src].Connect(receiver, dst); break; default: this.Log(LogLevel.Warning, "Destination index value is undefined {0:X}", dst); break; } }
//[source,dest] or [dest] with non-null defaultConnector void InitializeGPIO(IPeripheral device, string deviceName, IGPIOReceiver receiver, IList <int> irqEntry, PropertyInfo defaultConnector) { var periByNumber = device as INumberedGPIOOutput; if (irqEntry.Count == 2 && periByNumber != null) { periByNumber.Connections[irqEntry[0]].Connect(receiver, irqEntry[1]); } else if (irqEntry.Count == 1 && defaultConnector != null) { var gpioField = defaultConnector.GetValue(device, null) as GPIO; if (gpioField == null) { FailDevice(deviceName); } gpioField.Connect(receiver, irqEntry[0]); } else { throw new ArgumentException(); } }
public void Connect(IGPIOReceiver destination, int destinationNumber) { throw new NotImplementedException(); }
public void Connect(IGPIOReceiver destination, int destinationNumber) { connector(id, destination, destinationNumber); }
public void Register(IGPIOReceiver peripheral, NumberRegistrationPoint <int> registrationPoint) { machine.RegisterAsAChildOf(this, peripheral, registrationPoint); }
public GPIOEndpoint(IGPIOReceiver receiver, int number) { Receiver = receiver; Number = number; }
private static GPIOAttribute GetAttribute(IGPIOReceiver per) { return((GPIOAttribute)per.GetType().GetCustomAttributes(true).FirstOrDefault(x => x is GPIOAttribute)); }
public Destination(IGPIOReceiver receiver, int destinationNo) { this.receiver = receiver; this.destinationNo = destinationNo; }
public void Unregister(IGPIOReceiver peripheral) { machine.UnregisterAsAChildOf(this, peripheral); }
private static void Validate(IGPIOReceiver to, int toNumber) { var destPeriAttribute = GetAttribute(to); var destPeriInNum = destPeriAttribute != null ? destPeriAttribute.NumberOfInputs : 0; if(destPeriInNum != 0 && toNumber >= destPeriInNum) { throw new ConstructionException(string.Format( "Cannot connect {0}th input of {1}; it has only {2} GPIO inputs.", toNumber, to, destPeriInNum)); } }
//[source,dest] or [dest] with non-null defaultConnector void InitializeGPIO(IPeripheral device, IGPIOReceiver receiver, IList<int> irqEntry, PropertyInfo defaultConnector) { var periByNumber = device as INumberedGPIOOutput; if(irqEntry.Count == 2 && periByNumber != null) { periByNumber.Connections[irqEntry[0]].Connect(receiver, irqEntry[1]); } else if(irqEntry.Count == 1 && defaultConnector != null) { var gpioField = defaultConnector.GetValue(device, null) as GPIO; if(gpioField == null) { defaultConnector.SetValue(device, new GPIO(), null); gpioField = defaultConnector.GetValue(device, null) as GPIO; } gpioField.Connect(receiver, irqEntry[0]); } else { throw new ArgumentException(); } }
void InitializeGPIO(IPeripheral device, IGPIOReceiver receiver, IList<object> irqEntry, PropertyInfo defaultConnector) { if(!(irqEntry[0] is string && irqEntry[1] is int)) { throw new ArgumentException(); } //May throw AmbiguousMatchException - then use BindingFlags.DeclaredOnly or sth var connector = device.GetType().GetProperty(irqEntry[0] as string); if(connector == null) { throw new ArgumentException(); } var gpio = connector.GetValue(device, null) as GPIO; if(gpio == null) { connector.SetValue(device, new GPIO(), null); gpio = connector.GetValue(device, null) as GPIO; } gpio.Connect(receiver, (int)irqEntry[1]); }
public void Connect(IGPIOReceiver destination, int destinationNumber) => throw new InvalidOperationException($"Operation not supported in {this.GetType().Name}.");
private static GPIOAttribute GetAttribute(IGPIOReceiver per) { return (GPIOAttribute)per.GetType().GetCustomAttributes(true).FirstOrDefault(x => x is GPIOAttribute); }