Beispiel #1
0
 public static R WithEnumField <R, T>(this R register, string range, out IEnumRegisterField <T> enumField, FieldMode mode = FieldMode.Read | FieldMode.Write, Action <T, T> readCallback = null,
                                      Action <T, T> writeCallback = null, Action <T, T> changeCallback = null, Func <T, T> valueProviderCallback = null, string name = null, Type enumType = null) where R : PeripheralRegister
     where T : struct, IConvertible
 {
     enumField = register.DefineEnumField <T>(range, mode, readCallback, writeCallback, changeCallback, valueProviderCallback, name, enumType);
     return(register);
 }
        /// <summary>
        /// Fluent API for creation of set of enum fields. For parameters see the other overload of <see cref="PeripheralRegisterExtensions.WithEnumFields"/>.
        /// This overload allows you to retrieve the created array of fields via <c>enumFields</c> parameter.
        /// </summary>
        /// <returns>This register with defined enum fields.</returns>
        public static R WithEnumFields <R, T>(this R register, int position, int width, int count, out IEnumRegisterField <T>[] enumFields, FieldMode mode = FieldMode.Read | FieldMode.Write, Action <int, T, T> readCallback = null,
                                              Action <int, T, T> writeCallback = null, Action <int, T, T> changeCallback = null, Func <int, T, T> valueProviderCallback = null, string name = null) where R : PeripheralRegister where T : struct, IConvertible
        {
            enumFields = new IEnumRegisterField <T> [count];
            for (var i = 0; i < count; i++)
            {
                var j = i;

                enumFields[j] = register.DefineEnumField <T>(position + (j * width), width, mode,
                                                             readCallback == null ? null : (Action <T, T>)((x, y) => readCallback(j, x, y)),
                                                             writeCallback == null ? null : (Action <T, T>)((x, y) => writeCallback(j, x, y)),
                                                             changeCallback == null ? null : (Action <T, T>)((x, y) => changeCallback(j, x, y)),
                                                             valueProviderCallback == null ? null : (Func <T, T>)((x) => valueProviderCallback(j, x)),
                                                             name == null ? null : $"{name}_{j}");
            }
            return(register);
        }
Beispiel #3
0
        public Emios(Machine machine) : base(machine, 2 * NumberOfChannels)
        {
            controlRegisters = new DoubleWordRegister[NumberOfChannels];
            statusRegisters = new DoubleWordRegister[NumberOfChannels];
            channelModes = new IEnumRegisterField<ChannelMode>[NumberOfChannels];
            channelFlags = new IFlagRegisterField[NumberOfChannels];
            inputState = new IFlagRegisterField[NumberOfChannels];
            interruptEnabled = new IFlagRegisterField[NumberOfChannels];

            for(var i = 0; i < controlRegisters.Length; i++)
            {
                var j = i;
                controlRegisters[i] = new DoubleWordRegister(this);
                controlRegisters[i].DefineFlagField(7, writeCallback: 
					(oldValue, newValue) =>
                {
                    if(channelModes[j].Value == ChannelMode.Output)
                    {
                        Connections[j].Set(newValue);
                    }
                }, name: "Edge polarity");
                channelModes[i] = controlRegisters[i].DefineEnumField<ChannelMode>(0, 7);
                interruptEnabled[i] = controlRegisters[i].DefineFlagField(17);

                statusRegisters[i] = new DoubleWordRegister(this);
                channelFlags[i] = statusRegisters[i].DefineFlagField(0, FieldMode.WriteOneToClear, 
                    writeCallback: (oldValue, newValue) =>
                    {
                        if(newValue)
                        {
                            Connections[NumberOfChannels + j].Unset();
                        }
                    });
                inputState[i] = statusRegisters[i].DefineFlagField(2, FieldMode.Read);
            }
        }
Beispiel #4
0
        public Emios(Machine machine) : base(machine, 2 * NumberOfChannels)
        {
            controlRegisters = new DoubleWordRegister[NumberOfChannels];
            statusRegisters  = new DoubleWordRegister[NumberOfChannels];
            channelModes     = new IEnumRegisterField <ChannelMode> [NumberOfChannels];
            channelFlags     = new IFlagRegisterField[NumberOfChannels];
            inputState       = new IFlagRegisterField[NumberOfChannels];
            interruptEnabled = new IFlagRegisterField[NumberOfChannels];

            for (var i = 0; i < controlRegisters.Length; i++)
            {
                var j = i;
                controlRegisters[i] = new DoubleWordRegister(this);
                controlRegisters[i].DefineFlagField(7, writeCallback:
                                                    (oldValue, newValue) =>
                {
                    if (channelModes[j].Value == ChannelMode.Output)
                    {
                        Connections[j].Set(newValue);
                    }
                }, name: "Edge polarity");
                channelModes[i]     = controlRegisters[i].DefineEnumField <ChannelMode>(0, 7);
                interruptEnabled[i] = controlRegisters[i].DefineFlagField(17);

                statusRegisters[i] = new DoubleWordRegister(this);
                channelFlags[i]    = statusRegisters[i].DefineFlagField(0, FieldMode.WriteOneToClear,
                                                                        writeCallback: (oldValue, newValue) =>
                {
                    if (newValue)
                    {
                        Connections[NumberOfChannels + j].Unset();
                    }
                });
                inputState[i] = statusRegisters[i].DefineFlagField(2, FieldMode.Read);
            }
        }