/// <summary> /// Looks up an alias for a registered type /// </summary> /// <param name="type">the type to lookup</param> /// <returns>a type alias or null if not found</returns> public virtual string GetTypeAlias(Type type) { string alias = null; if (!bindings.TryGetValue(type, out alias)) { alias = null; } return(alias); }
/// <summary> /// Get an entity from an identifier /// </summary> /// <param name="identity"></param> /// <typeparam name="TIdentity"></typeparam> /// <returns></returns> public RevolutionEntity GetEntityFromIdentifier <TIdentity>(TIdentity identity) { var id = new EntityIdentifier(); id.Set(identity); if (identifierToEntity.TryGetValue(id, out var entity)) { return(new RevolutionEntity(this, entity)); } return(default);
public int?Lookup(T entry) { int refId; if (map.TryGetValue(entry, out refId)) { return(refId); } return(null); }
private IntAlias <PolygonGrid2D> GetRoomTemplateInstanceAlias(RoomTemplateInstance roomTemplateInstance) { if (IntAliasMapping.TryGetValue(roomTemplateInstance, out var alias)) { return(alias); } var newAlias = new IntAlias <PolygonGrid2D>(IntAliasMapping.Count, roomTemplateInstance.RoomShape); IntAliasMapping.Add(roomTemplateInstance, newAlias); return(newAlias); }
public PSE_GPIO(Machine machine) : base(machine, 32) { locker = new object(); IRQ = new GPIO(); irqManager = new GPIOInterruptManager(IRQ, State); var registersMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.InterruptRegister, new DoubleWordRegister(this) .WithValueField(0, 32, writeCallback: (_, val) => { foreach (var i in BitHelper.GetSetBits(val)) { irqManager.ClearInterrupt(i); if ((irqManager.PinDirection[i] & GPIOInterruptManager.Direction.Input) != 0) { Connections[i].Set(false); } } }, valueProviderCallback: _ => BitHelper.GetValueFromBitsArray(irqManager.ActiveInterrupts), name: "INTR") }, { (long)Registers.InputRegister, new DoubleWordRegister(this) .WithValueField(0, 32, out inputReg, FieldMode.Read, valueProviderCallback: val => { var pins = irqManager.PinDirection.Select(x => (x & GPIOInterruptManager.Direction.Input) != 0); var result = pins.Zip(State, (pin, state) => pin && state); return(BitHelper.GetValueFromBitsArray(result)); }, name: "GPIN") }, { (long)Registers.OutputRegister, new DoubleWordRegister(this) .WithValueField(0, 32, valueProviderCallback: val => { var pins = irqManager.PinDirection.Select(x => (x & GPIOInterruptManager.Direction.Output) != 0); var result = pins.Zip(Connections.Values, (pin, state) => pin && state.IsSet); return(BitHelper.GetValueFromBitsArray(result)); }, writeCallback: (_, val) => { // Potentially we should raise an exception, as GPIO is bidirectional, // but we do not have such infrastructure. var bits = BitHelper.GetBits(val); for (var i = 0; i < bits.Length; i++) { if ((irqManager.PinDirection[i] & GPIOInterruptManager.Direction.Output) != 0) { Connections[i].Set(bits[i]); } } }, name: "GPOUT") }, { (long)Registers.ClearRegister, new DoubleWordRegister(this) .WithValueField(0, 32, writeCallback: (_, val) => SetRegisterBits(val, false), name: "CLEAR_BITS") }, { (long)Registers.SetRegister, new DoubleWordRegister(this) .WithValueField(0, 32, writeCallback: (_, val) => SetRegisterBits(val, true), name: "SET_BITS") }, }; var intTypeToVal = new TwoWayDictionary <GPIOInterruptManager.InterruptTrigger, uint>(); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.ActiveHigh, 0); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.ActiveLow, 1); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.RisingEdge, 2); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.FallingEdge, 3); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.BothEdges, 4); for (var i = 0; i < RegisterLength; i++) { var j = i; registersMap.Add(i * RegisterOffset, new DoubleWordRegister(this) .WithFlag(0, writeCallback: (_, val) => { if (val) { irqManager.PinDirection[j] |= GPIOInterruptManager.Direction.Output; } else { irqManager.PinDirection[j] &= ~GPIOInterruptManager.Direction.Output; } }, valueProviderCallback: _ => (irqManager.PinDirection[j] & GPIOInterruptManager.Direction.Output) != 0, name: "OutputRegEnable") .WithFlag(1, writeCallback: (_, value) => { if (value) { irqManager.PinDirection[j] |= GPIOInterruptManager.Direction.Input; } else { irqManager.PinDirection[j] &= ~GPIOInterruptManager.Direction.Input; } }, valueProviderCallback: _ => (irqManager.PinDirection[j] & GPIOInterruptManager.Direction.Input) != 0, name: "InputRegEnable") .WithTag("OutputBufferEnable", 2, 1) .WithFlag(3, writeCallback: (_, v) => { irqManager.InterruptEnable[j] = v; }, valueProviderCallback: _ => irqManager.InterruptEnable[j], name: "InterruptEnable") .WithReservedBits(4, 1) .WithValueField(5, 3, writeCallback: (_, value) => { if (!intTypeToVal.TryGetValue(value, out var type)) { this.Log(LogLevel.Warning, "Invalid interrupt type for pin #{0}: {1}", j, value); return; } irqManager.InterruptType[j] = type; }, valueProviderCallback: _ => intTypeToVal[irqManager.InterruptType[j]], name: "InterruptType")); } registers = new DoubleWordRegisterCollection(this, registersMap); }
public MiV_CoreGPIO(Machine machine) : base(machine, NumberOfInterrupts) { innerLock = new object(); IRQ = new GPIO(); irqManager = new GPIOInterruptManager(IRQ, State); var registersMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.OutputRegister, new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Write, writeCallback: (_, value) => { lock (innerLock) { var bits = BitHelper.GetBits(value); for (var i = 0; i < bits.Length; i++) { Connections[i].Set(bits[i]); } } }) }, { (long)Registers.InputRegister, new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => { lock (innerLock) { return(BitHelper.GetValueFromBitsArray(State)); } }) }, { (long)Registers.InterruptClearRegister, new DoubleWordRegister(this).WithValueField(0, 32, writeCallback: (_, value) => { lock (innerLock) { foreach (var i in BitHelper.GetSetBits(value)) { irqManager.ClearInterrupt((uint)i); } } }, valueProviderCallback: _ => { lock (innerLock) { return(BitHelper.GetValueFromBitsArray(irqManager.ActiveInterrupts)); } }) } }; var intTypeToVal = new TwoWayDictionary <GPIOInterruptManager.InterruptTrigger, uint>(); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.ActiveHigh, 0); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.ActiveLow, 1); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.RisingEdge, 2); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.FallingEdge, 3); intTypeToVal.Add(GPIOInterruptManager.InterruptTrigger.BothEdges, 4); for (var i = 0; i < NumberOfInterrupts; i++) { var j = i; registersMap.Add((long)Registers.ConfigurationRegisterBase + i * 0x4, new DoubleWordRegister(this) .WithFlag(0, writeCallback: (_, v) => { if (v) { irqManager.PinDirection[j] |= GPIOInterruptManager.Direction.Output; } else { irqManager.PinDirection[j] &= ~GPIOInterruptManager.Direction.Output; } }, valueProviderCallback: _ => (irqManager.PinDirection[j] & GPIOInterruptManager.Direction.Output) != 0, name: "OUTREG") .WithFlag(1, writeCallback: (_, value) => { if (value) { irqManager.PinDirection[j] |= GPIOInterruptManager.Direction.Input; } else { irqManager.PinDirection[j] &= ~GPIOInterruptManager.Direction.Input; } }, valueProviderCallback: _ => (irqManager.PinDirection[j] & GPIOInterruptManager.Direction.Input) != 0, name: "INREG") .WithTag("OUTBUFF", 2, 1) .WithFlag(3, writeCallback: (_, v) => { irqManager.InterruptEnable[j] = v; }, valueProviderCallback: _ => irqManager.InterruptEnable[j], name: "INTENABLE") //bit 4 unused .WithValueField(5, 3, writeCallback: (_, value) => { if (!intTypeToVal.TryGetValue(value, out var type)) { this.Log(LogLevel.Warning, "Invalid interrupt type for pin #{0}: {1}", j, value); return; } irqManager.InterruptType[j] = type; }, valueProviderCallback: _ => { if (!intTypeToVal.TryGetValue(irqManager.InterruptType[j], out var value)) { throw new ArgumentOutOfRangeException($"Unknown interrupt trigger type: {irqManager.InterruptType[j]}"); } return(value); }, name: "INTTYPE")); } registers = new DoubleWordRegisterCollection(this, registersMap); }
private static bool FindTypeForDescriptor(TwoWayDictionary <Type, MessageDescriptor> registeredTypes, MessageDescriptor descriptor, out Type type) => registeredTypes.TryGetValue(descriptor, out type);