Beispiel #1
0
        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);
        }
Beispiel #2
0
 //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);
 }
Beispiel #3
0
        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));
            }
        }
Beispiel #4
0
 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);
 }
Beispiel #5
0
 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);
     }
 }
Beispiel #6
0
 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);
     }
 }
Beispiel #7
0
        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);
        }
Beispiel #8
0
 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);
         }
     }
 }
Beispiel #9
0
        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);
        }
Beispiel #10
0
 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;
     }
 }
Beispiel #11
0
 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);
     }
 }
Beispiel #12
0
        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;
            }
        }
Beispiel #14
0
        //[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();
            }
        }
Beispiel #15
0
 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);
 }
Beispiel #18
0
 public GPIOEndpoint(IGPIOReceiver receiver, int number)
 {
     Receiver = receiver;
     Number = number;
 }
Beispiel #19
0
 private static GPIOAttribute GetAttribute(IGPIOReceiver per)
 {
     return((GPIOAttribute)per.GetType().GetCustomAttributes(true).FirstOrDefault(x => x is GPIOAttribute));
 }
Beispiel #20
0
 public Destination(IGPIOReceiver receiver, int destinationNo)
 {
     this.receiver      = receiver;
     this.destinationNo = destinationNo;
 }
 public void Unregister(IGPIOReceiver peripheral)
 {
     machine.UnregisterAsAChildOf(this, peripheral);
 }
Beispiel #22
0
 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));
     }           
 }
Beispiel #23
0
 //[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();
     }
 }
Beispiel #24
0
        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]);

        }
Beispiel #25
0
 public GPIOEndpoint(IGPIOReceiver receiver, int number)
 {
     Receiver = receiver;
     Number   = number;
 }
Beispiel #26
0
 public void Connect(IGPIOReceiver destination, int destinationNumber) => throw new InvalidOperationException($"Operation not supported in {this.GetType().Name}.");
Beispiel #27
0
 private static GPIOAttribute GetAttribute(IGPIOReceiver per)
 {
     return (GPIOAttribute)per.GetType().GetCustomAttributes(true).FirstOrDefault(x => x is GPIOAttribute);
 }