Exemplo n.º 1
0
 public InterruptPort(IO60P16Module parentModule, IOPin pin, ResistorMode resistorMode, InterruptMode interruptMode)
     : base(parentModule, pin)
 {
     Resistor = resistorMode;
     Interrupt = interruptMode;
     EnableInterrupt();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Sets the Interrupt mode to IRQ.
 /// </summary>
 public void triggerIRQ()
 {
     if (interrupt_flag == 0)
     {
         interrupt = InterruptMode.IRQInterrupt;
     }
 }
Exemplo n.º 3
0
        public void Test_IM(int modeNumber, InterruptMode mode)
        {
            var rom = AssembleSource($@"
                org 00h
                IM {modeNumber}
                HALT
            ");

            var initialState = new CPUConfig()
            {
                InterruptsEnabled = false,
                InterruptsEnabledPreviousValue = false,
            };

            var cpu = new CPU(initialState);

            var state = Execute(rom, cpu);

            // Ensure the mode was set.
            Assert.Equal(mode, cpu.InterruptMode);

            // Setting mode does not enable interrupts.
            Assert.False(cpu.InterruptsEnabled);
            Assert.False(cpu.InterruptsEnabledPreviousValue);

            Assert.Equal(2, state.Iterations);
            Assert.Equal(4 + 8, state.Cycles);
            Assert.Equal(0x02, state.Registers.PC);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Z80RegisterState"/> class.
 /// </summary>
 /// <param name="generalPurposeRegisterState">State of the primary general purpose registers.</param>
 /// <param name="alternativeGeneralPurposeRegisterState">State of the alternative general purpose registers.</param>
 /// <param name="accumulatorAndFlagsRegisterState">State of the primary accumulator and flags registers.</param>
 /// <param name="alternativeAccumulatorAndFlagsRegisterState">State of the alternative accumulator and flags registers.</param>
 /// <param name="isGeneralPurposeAlternative">if set to <c>true</c> [the general purpose registers are set to their alternative values].</param>
 /// <param name="isAccumulatorAndFlagsAlternative">if set to <c>true</c> [the accumulator and flags registers are set to their alternative values].</param>
 /// <param name="ix">The IX register.</param>
 /// <param name="iy">The IY register.</param>
 /// <param name="i">The I (interrupt vector) register.</param>
 /// <param name="r">The R (memory refresh) register.</param>
 /// <param name="stackPointer">The SP (stack pointer) register.</param>
 /// <param name="programCounter">The PC (program counter) register.</param>
 /// <param name="interruptFlipFlop1">if set to <c>true</c> [interrupt flip flop 1 is set].</param>
 /// <param name="interruptFlipFlop2">if set to <c>true</c> [interrupt flip flop 2 is set].</param>
 /// <param name="interruptMode">The interrupt mode.</param>
 public Z80RegisterState(GeneralPurposeRegisterState generalPurposeRegisterState,
                         GeneralPurposeRegisterState alternativeGeneralPurposeRegisterState,
                         AccumulatorAndFlagsRegisterState accumulatorAndFlagsRegisterState,
                         AccumulatorAndFlagsRegisterState alternativeAccumulatorAndFlagsRegisterState,
                         bool isGeneralPurposeAlternative,
                         bool isAccumulatorAndFlagsAlternative,
                         ushort ix,
                         ushort iy,
                         byte i,
                         byte r,
                         ushort stackPointer,
                         ushort programCounter,
                         bool interruptFlipFlop1,
                         bool interruptFlipFlop2,
                         InterruptMode interruptMode)
     : base(
         generalPurposeRegisterState,
         accumulatorAndFlagsRegisterState,
         stackPointer,
         programCounter,
         interruptFlipFlop1,
         interruptFlipFlop2,
         interruptMode)
 {
     AlternativeGeneralPurposeRegisterState      = alternativeGeneralPurposeRegisterState;
     AlternativeAccumulatorAndFlagsRegisterState = alternativeAccumulatorAndFlagsRegisterState;
     IsGeneralPurposeAlternative      = isGeneralPurposeAlternative;
     IsAccumulatorAndFlagsAlternative = isAccumulatorAndFlagsAlternative;
     IX = ix;
     IY = iy;
     I  = i;
     R  = r;
 }
Exemplo n.º 5
0
 public InterruptPort(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interrupt)
     : base(portId, glitchFilter, resistor, interrupt)
 {
     m_threadSpawn = null;
     m_callbacks   = null;
     Interrupt     = interrupt;
 }
Exemplo n.º 6
0
 private static void SetInterruptMode(OpCode op, InterruptMode mode)
 {
     using (var fixture = new ExecuteFixture())
     {
         fixture.Operation.OpCode(op);
         fixture.Assert(c => c.MockRegisters.VerifySet(x => x.InterruptMode = mode));
     }
 }
Exemplo n.º 7
0
 public InterruptPort(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interrupt)
     : base(portId, glitchFilter, resistor, interrupt)
 {
     //m_threadSpawn = null;
     //m_callbacks = null;
     GPIOManager.Instance.SetPortType(portId, PortType.INTERRUPT);
     GPIOManager.Instance.SetEdge(portId, interrupt);
 }
Exemplo n.º 8
0
 public IDigitalInputPort CreateDigitalInputPort(IPin pin,
                                                 InterruptMode interruptMode   = InterruptMode.None,
                                                 ResistorMode resistorMode     = ResistorMode.Disabled,
                                                 double debounceDuration       = 0,
                                                 double glitchFilterCycleCount = 0)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eventInterruptModeIn">The interrupt mode</param>
 /// <param name="gpioIn">The GPIO this interrupt is on.
 /// <history>
 ///    28 Aug 14  Cynic - Originally written
 /// </history>
 public InterruptPortMM(GpioEnum gpioIn, InterruptMode eventInterruptModeIn) : base(gpioIn)
 {
     EventInterruptMode = eventInterruptModeIn;
     // setup for event detection
     SetEventMasks();
     // open the port and turn on event detection
     OpenPort();
 }
Exemplo n.º 10
0
 public DigitalFrequencyInput(Cpu.Pin pin, bool glitchFilter, ResistorMode resistorMode, InterruptMode interruptMode)
     : base(pin, glitchFilter, resistorMode, interruptMode)
 {
     dataPoints = new System.Collections.Hashtable(20);
     base.EnableInterrupt();
     base.OnInterrupt += new NativeEventHandler(DigitalFrequencyInput_OnInterrupt);
     loopThread = new Thread(new ThreadStart(ThreadLoop));
     loopThread.Start();
 }
Exemplo n.º 11
0
        public NativeInterruptInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module, Cpu.Pin cpuPin)
        {
            if (cpuPin == Cpu.Pin.GPIO_NONE)
            {
                // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
                throw Socket.InvalidSocketException.FunctionalityException(socket, "InterruptInput");
            }

            _port = new InterruptPort(cpuPin, glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode, (Port.InterruptMode)interruptMode);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a new DipSwitch connected to the specified switchPins, with the InterruptMode and ResisterMode specified by the type parameters.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="switchPins"></param>
        /// <param name="interruptMode"></param>
        /// <param name="resistorMode"></param>
        /// <param name="debounceDuration"></param>
        /// <param name="glitchFilterCycleCount"></param>
        public DipSwitch(IIODevice device, IPin[] switchPins, InterruptMode interruptMode, ResistorMode resistorMode, int debounceDuration = 20, int glitchFilterCycleCount = 0)
        {
            Switches = new ISwitch[switchPins.Length];

            for (int i = 0; i < switchPins.Length; i++)
            {
                Switches[i] = new SpstSwitch(device, switchPins[i], interruptMode, resistorMode, debounceDuration, glitchFilterCycleCount);
                int index = i;
                Switches[i].Changed += (s, e) => HandleSwitchChanged(index);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates an instance of <see cref="InterruptInput" /> for the given socket and pin number.
        /// </summary>
        /// <param name="socket">The socket for the interrupt input interface.</param>
        /// <param name="pin">The pin used by the interrupt input interface.</param>
        /// <param name="glitchFilterMode">
        ///  A value from the <see cref="GlitchFilterMode"/> enumeration that specifies 
        ///  whether to enable the glitch filter on this interrupt input interface.
        /// </param>
        /// <param name="resistorMode">
        ///  A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the interrupt input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself.
        /// </param>
        /// <param name="interruptMode">
        ///  A value from the <see cref="InterruptMode"/> enumeration that establishes the requisite conditions 
        ///  for the interface port to generate an interrupt.
        /// </param>
        /// <param name="module">The module using this interrupt input interface, which can be null if unspecified.</param>
        /// <returns>An instance of <see cref="InterruptInput" /> for the given socket and pin number.</returns>
        public static InterruptInput Create(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module)
        {
            Cpu.Pin reservedPin = socket.ReservePin(pin, module);

            // native implementation is preferred to an indirected one
            if (reservedPin == Cpu.Pin.GPIO_NONE && socket.InterruptIndirector != null)
                return socket.InterruptIndirector(socket, pin, glitchFilterMode, resistorMode, interruptMode, module);

            else
                return new NativeInterruptInput(socket, pin, glitchFilterMode, resistorMode, interruptMode, module, reservedPin);
        }
Exemplo n.º 14
0
        // TODO: all these can go away when we get interface implementation
        // support from C# 8 into the Meadow.Core project. It won't work today,
        // even though it's set to C# 8 because the project references the
        // .NET 4.7.2 runtime. After the latest Mono rebase we'll be able to
        // move it to Core 3.

        public IBiDirectionalPort CreateBiDirectionalPort(IPin pin,
                                                          bool initialState                  = false,
                                                          InterruptMode interruptMode        = InterruptMode.None,
                                                          ResistorMode resistorMode          = ResistorMode.Disabled,
                                                          PortDirectionType initialDirection = PortDirectionType.Input,
                                                          double debounceDuration            = 0.0, // 0 - 1000 msec in .1 increments
                                                          double glitchDuration              = 0.0, // 0 - 1000 msec in .1 increments
                                                          OutputType outputType              = OutputType.PushPull)
        {
            throw new NotImplementedException();
        }
Exemplo n.º 15
0
            public static IDigitalInterrupt Bind(Pin pin,
                                                 string name = null,
                                                 ResistorMode internalResistorMode = ResistorMode.Disabled,
                                                 InterruptMode interruptMode       = InterruptMode.InterruptNone,
                                                 int debounceMilliseconds          = DigitalInterupt.DebounceDefault)
            {
                var result = NewInstance(pin, name, internalResistorMode, interruptMode, debounceMilliseconds);

                Cache.Add(pin, result);
                return(result);
            }
Exemplo n.º 16
0
        /// <summary>
        /// Resets the registers to the specified state.
        /// </summary>
        /// <typeparam name="TRegisterState">The type of the register state.</typeparam>
        /// <param name="state">The state.</param>
        public void ResetToState <TRegisterState>(TRegisterState state) where TRegisterState : Intel8080RegisterState
        {
            GeneralPurposeRegisters.ResetToState(state.GeneralPurposeRegisterState);
            AccumulatorAndFlagsRegisters.ResetToState(state.AccumulatorAndFlagsRegisterState);

            StackPointer   = state.StackPointer;
            ProgramCounter = state.ProgramCounter;

            InterruptFlipFlop1 = state.InterruptFlipFlop1;
            InterruptFlipFlop2 = state.InterruptFlipFlop2;
            InterruptMode      = state.InterruptMode;
        }
Exemplo n.º 17
0
 // Called for all Port initialization
 // verify the library is inialized
 // store internal variables
 private void initPort(Cpu.Pin portId, bool initialState, bool glitchFilter, ResistorMode resistor, InterruptMode interruptMode)
 {
     if (wiringPiSetup() == -1)
     {
         throw new Exception("Unable to initialize libwiringPi.so library");
     }
     m_portId             = (uint)portId;
     m_initialState       = initialState;
     m_glitchFilterEnable = glitchFilter;
     m_resistorMode       = resistor;
     m_interruptMode      = interruptMode;
 }
Exemplo n.º 18
0
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socket">The socket for the interrupt input interface.</param>
        /// <param name="pin">The pin used by the interrupt input interface.</param>
        /// <param name="glitchFilterMode">
        ///  A value from the <see cref="GlitchFilterMode"/> enumeration that specifies 
        ///  whether to enable the glitch filter on this interrupt input interface.
        /// </param>
        /// <param name="resistorMode">
        ///  A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the interrupt input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself.
        /// </param>
        /// <param name="interruptMode">
        ///  A value from the <see cref="InterruptMode"/> enumeration that establishes the requisite conditions 
        ///  for the interface port to generate an interrupt.
        /// </param>
        /// <param name="module">The module using this interrupt input interface, which can be null if unspecified.</param>
        public InterruptInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module)
        {
            this.port = new InterruptPort(socket.ReservePin(pin, module), glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode, (Port.InterruptMode)interruptMode);

            if (this.port == null)
            {
                // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
                throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Interrupt Input functionality. Please try a different socket.");
            }

            this.SynchronousUnsafeEventInvocation = false;
            this.port.OnInterrupt += new NativeEventHandler(this._port_OnInterrupt);
        }
            }                                                   //Todo not currently used

            public DigitalInputPort(
                Mcp23x08 mcpController,
                IPin pin,
                InterruptMode interruptMode = InterruptMode.None)
                : base(pin, (IDigitalChannelInfo)pin.SupportedChannels[0], interruptMode)
            {
                _mcp = mcpController;
                _pin = pin;
                if (interruptMode != InterruptMode.None)
                {
                    _mcp.InputChanged += PinChanged;
                }
            }
Exemplo n.º 20
0
        // void attachInterrupt(uint8_t pin, void (*)(void), int mode);
        // private const int ATTACH_INTERRUPT = 503;
        public void attachInterrupt(int pin, Action <int, UInt32> f, InterruptMode mode)
        {
            if (InternalCallback(pin, f) != 0)
            {
                return;
            }

            if (GpioCommand(ATTACH_INTERRUPT, pin, (int)mode) != 0)
            {
                InternalCallbackCancel(pin);
                return;
            }
        }
Exemplo n.º 21
0
 /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="eventInterruptModeIn">The interrupt mode</param>
 /// <param name="gpioIn">The GPIO this interrupt is on.
 /// <param name="pullUpDownMode">The pull up or pull down mode</param>
 /// <history>
 ///    01 Dec 16  Cynic - Originally written
 /// </history>
 public InterruptPortMM(GpioEnum gpioIn, GPIOPullUpDownModeEnum pullUpDownMode, InterruptMode eventInterruptModeIn) : base(gpioIn)
 {
     EventInterruptMode = eventInterruptModeIn;
     // setup for event detection
     SetEventMasks();
     // open the port and turn on event detection
     OpenPort();
     // set the mode to disable pullUpDown
     MMDevMem.SetGPIOPullUpDownMode(GpioCfgObject, pullUpDownMode);
     // set up the interrupts
     MMDevMem.DisableAllInterruptsAtGPIOLevel(GpioCfgObject);
     MMDevMem.EnableInterruptsAtGPIOLevelAccordingToEnum(GpioCfgObject, EventInterruptMode);
 }
Exemplo n.º 22
0
        public void InterruptModeGetTest(InterruptMode expectedMode, byte registerValue)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(registerValue);

            InterruptMode actualMode = sensor.InterruptMode;

            Assert.Single(i2cDevice.DataWritten);
            // register address is expected two times: once for reading the current register value and once for writing the new one
            Assert.Equal((byte)Register.INTC, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(expectedMode, actualMode);
        }
Exemplo n.º 23
0
        public void InterruptModeSetTest(byte initialRegisterContent, InterruptMode targetMode, byte expectedRegisterContent)
        {
            I2cTestDevice i2cDevice = new I2cTestDevice();
            Amg88xx       sensor    = new Amg88xx(i2cDevice);

            i2cDevice.DataToRead.Enqueue(initialRegisterContent);

            sensor.InterruptMode = targetMode;

            Assert.Equal(3, i2cDevice.DataWritten.Count);
            // register address is expected two times: once for reading the current register value and once for writing the new one
            Assert.Equal((byte)Register.INTC, i2cDevice.DataWritten.Dequeue());
            Assert.Equal((byte)Register.INTC, i2cDevice.DataWritten.Dequeue());
            Assert.Equal(expectedRegisterContent, i2cDevice.DataWritten.Dequeue());
        }
Exemplo n.º 24
0
        /// <summary>
        ///     Turn interrupts on or off and set the conversion trigger count.
        /// </summary>
        /// <remarks>
        ///     The conversion count is the number of conversions that must be outside
        ///     of the upper and lower limits before and interrupt is generated.
        ///     See Interrupt Control Register on page 15 and 16 of the datasheet.
        /// </remarks>
        /// <param name="mode"></param>
        /// <param name="conversionCount">
        ///     Number of conversions that must be outside of the threshold before an interrupt is
        ///     generated.
        /// </param>
        /// <param name="pin">GPIO pin connected to the TSL2561 interrupt pin.  Set to null to use the previously supplied pin.</param>
        public void SetInterruptMode(InterruptMode mode, byte conversionCount, int pin = -1)
        {
            if (conversionCount > 15)
            {
                throw new ArgumentOutOfRangeException(nameof(conversionCount), "Conversion count must be in the range 0-15 inclusive.");
            }
            //
            //  Attach the interrupt event before we turn on interrupts.
            //
            if (pin > -1)
            {
                if (_interruptPin != null)
                {
                    //Port: TODO check  _interruptPin.Dispose();
                }
                //_interruptPin = device.CreateDigitalInputPort(pin, Hardware.InterruptMode.EdgeRising, ResistorMode.PullUp);
                //_interruptPin.Changed += InterruptPin_Changed;
                var gpio = GpioController.GetDefault();

                _interruptPin = gpio.OpenPin(pin);
                _interruptPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                _interruptPin.ValueChanged += _interruptPin_ValueChanged;
            }
            else
            {
                if (_interruptPin == null)
                {
                    throw new ArgumentException("Interrupt pin must be supplied");
                }
            }
            //
            // Put interrupt control in bits 4 & 5 of the Interrupt Control Register.
            // Using the enum above makes sure that mode is in the range 0-3 inclusive.
            //
            var registerValue = (byte)mode;

            registerValue <<= 4;
            //
            // conversionCount is known to be 0-15, put this in the lower four bits of
            // the Interrupt Control Register.
            //
            registerValue |= conversionCount;
            //
            //  Clear the interrupt bit before we turn them on.
            //
            ClearInterrupt();
            tsl2561.Write(new byte[] { Registers.InterruptControl, registerValue });
        }
Exemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Intel8080RegisterState"/> class.
 /// </summary>
 /// <param name="generalPurposeRegisterState">State of the primary general purpose registers.</param>
 /// <param name="accumulatorAndFlagsRegisterState">State of the primary accumulator and flags registers.</param>
 /// <param name="stackPointer">The SP (stack pointer) register.</param>
 /// <param name="programCounter">The PC (program counter) register.</param>
 /// <param name="interruptFlipFlop1">if set to <c>true</c> [interrupt flip flop 1 is set].</param>
 /// <param name="interruptFlipFlop2">if set to <c>true</c> [interrupt flip flop 2 is set].</param>
 /// <param name="interruptMode">The interrupt mode.</param>
 public Intel8080RegisterState(GeneralPurposeRegisterState generalPurposeRegisterState,
                               AccumulatorAndFlagsRegisterState accumulatorAndFlagsRegisterState,
                               ushort stackPointer,
                               ushort programCounter,
                               bool interruptFlipFlop1,
                               bool interruptFlipFlop2,
                               InterruptMode interruptMode)
 {
     GeneralPurposeRegisterState      = generalPurposeRegisterState;
     AccumulatorAndFlagsRegisterState = accumulatorAndFlagsRegisterState;
     StackPointer       = stackPointer;
     ProgramCounter     = programCounter;
     InterruptFlipFlop1 = interruptFlipFlop1;
     InterruptFlipFlop2 = interruptFlipFlop2;
     InterruptMode      = interruptMode;
 }
Exemplo n.º 26
0
        /// <summary>
        ///     Turn interrupts on or off and set the conversion trigger count.
        /// </summary>
        /// <remarks>
        ///     The conversion count is the number of conversions that must be outside
        ///     of the upper and lower limits before and interrupt is generated.
        ///     See Interrupt Control Register on page 15 and 16 of the datasheet.
        /// </remarks>
        /// <param name="mode"></param>
        /// <param name="conversionCount">
        ///     Number of conversions that must be outside of the threshold before an interrupt is
        ///     generated.
        /// </param>
        /// <param name="pin">GPIO pin connected to the TSL2561 interrupt pin.  Set to null to use the previously supplied pin.</param>
        public void SetInterruptMode(InterruptMode mode, byte conversionCount,
                                     Spot.Cpu.Pin pin = Spot.Cpu.Pin.GPIO_NONE)
        {
            if (conversionCount > 15)
            {
                throw new ArgumentOutOfRangeException("conversionCount",
                                                      "Conversion count must be in the range 0-15 inclusive.");
            }
            //
            //  Attach the interrupt event before we turn on interrupts.
            //
            if (pin != Spot.Cpu.Pin.GPIO_NONE)
            {
                if (_interruptPin != null)
                {
                    _interruptPin.Dispose();
                }
                _interruptPin = new Spot.InterruptPort(pin, false, Spot.Port.ResistorMode.PullUp,
                                                       Spot.Port.InterruptMode.InterruptEdgeLow);
                _interruptPin.OnInterrupt += _interruptPin_OnInterrupt;
            }
            else
            {
                if (_interruptPin == null)
                {
                    throw new ArgumentException("Interrupt pin must be supplied");
                }
            }
            //
            // Put interrupt control in bits 4 & 5 of the Interrupt Control Register.
            // Using the enum above makes sure that mode is in the range 0-3 inclusive.
            //
            var registerValue = (byte)mode;

            registerValue <<= 4;
            //
            // conversionCount is known to be 0-15, put this in the lower four bits of
            // the Interrupt Control Register.
            //
            registerValue |= conversionCount;
            //
            //  Clear the interrupt bit before we turn them on.
            //
            ClearInterrupt();
            _tsl2561.WriteRegister(Registers.InterruptControl, registerValue);
        }
Exemplo n.º 27
0
        public void ConfigureInputPort(IPin pin, bool enablePullUp = false, InterruptMode interruptMode = InterruptMode.None)
        {
            if (IsValidPin(pin))
            {
                // set the port direction
                this.SetPortDirection(pin, PortDirectionType.Input);

                _gppu = _mcpDevice.ReadRegister(RegisterAddresses.PullupResistorConfigurationRegister);
                _gppu = BitHelpers.SetBit(_gppu, (byte)pin.Key, enablePullUp);
                _mcpDevice.WriteRegister(RegisterAddresses.PullupResistorConfigurationRegister, _gppu);

                if (interruptMode != InterruptMode.None)
                {
                    // interrupt on change (whether or not we want to raise an interrupt on the interrupt pin on change)
                    byte gpinten = _mcpDevice.ReadRegister(RegisterAddresses.InterruptOnChangeRegister);
                    gpinten = BitHelpers.SetBit(gpinten, (byte)pin.Key, true);
                    _mcpDevice.WriteRegister(RegisterAddresses.InterruptOnChangeRegister, gpinten);

                    // Set the default value for the pin for interrupts.
                    var  interruptValue = interruptMode == InterruptMode.EdgeFalling;
                    byte defVal         = _mcpDevice.ReadRegister(RegisterAddresses.DefaultComparisonValueRegister);
                    defVal = BitHelpers.SetBit(defVal, (byte)pin.Key, interruptValue);
                    _mcpDevice.WriteRegister(RegisterAddresses.DefaultComparisonValueRegister, defVal);

                    // Set the input polarity of the pin. Basically if its normally high, we want to flip the polarity.
                    var pol = _mcpDevice.ReadRegister(RegisterAddresses.InputPolarityRegister);
                    pol = BitHelpers.SetBit(pol, (byte)pin.Key, !interruptValue);
                    _mcpDevice.WriteRegister(RegisterAddresses.InputPolarityRegister, pol);

                    // interrupt control register; whether or not the change is based
                    // on default comparison value, or if a change from previous. We
                    // want to raise on change, so we set it to 0, always.
                    var interruptControl = interruptMode != InterruptMode.EdgeBoth;
                    var intCon           = _mcpDevice.ReadRegister(RegisterAddresses.InterruptControlRegister);
                    intCon = BitHelpers.SetBit(intCon, (byte)pin.Key, interruptControl);
                    _mcpDevice.WriteRegister(RegisterAddresses.InterruptControlRegister, intCon);
                }
            }
            else
            {
                throw new Exception("Pin is out of range");
            }
        }
Exemplo n.º 28
0
        private void CPUControl_SetInterruptMode(InterruptMode interruptMode)
        {
            switch (interruptMode)
            {
            case InterruptMode.IM0:
                IM = 0;
                break;

            case InterruptMode.IM1:
                IM = 1;
                break;

            case InterruptMode.IM2:
                IM = 2;
                break;
            }
            if (TraceMicroInstructions)
            {
                TraceMicroInstruction(new MicroInstruction(Z80MicroInstructionTypes.CPUControlSetInterruptMode));
            }
        }
Exemplo n.º 29
0
 public IDigitalInputPort CreateDigitalInputPort(
     IPin pin,
     InterruptMode interruptMode   = InterruptMode.None,
     ResistorMode resistorMode     = ResistorMode.Disabled,
     double debounceDuration       = 0,
     double glitchFilterCycleCount = 0)
 {
     if (IsValidPin(pin))
     {
         if (resistorMode == ResistorMode.PullDown)
         {
             Console.WriteLine("Pull-down resistor mode is not supported.");
             throw new Exception("Pull-down resistor mode is not supported.");
         }
         var enablePullUp = resistorMode == ResistorMode.PullUp ? true : false;
         this.ConfigureInputPort(pin, enablePullUp, interruptMode);
         var port = new DigitalInputPort(this, pin, interruptMode);
         _inputPorts.Add(pin, port);
         return(port);
     }
     throw new Exception("Pin is out of range");
 }
Exemplo n.º 30
0
        public override void SetupInterrupt(InterruptMode mode)
        {
            // Really dont want to do it this way, but Wrapper.wiringPiISR derps
            new Thread(() =>
            {
                DigitalRead();
                int state = DigitalRead();

                while (true)
                {
                    int nstate = DigitalRead();
                    if (nstate != state)
                    {
                        if (mode == InterruptMode.Both || (mode == InterruptMode.RisingEdge && nstate == 1) || (mode == InterruptMode.FallingEdge && nstate == 0))
                        {
                            InterruptCallback();
                        }
                        state = nstate;
                    }
                    Wrapper.delayMicroseconds(1);
                }

            }).Start();
        }
Exemplo n.º 31
0
        //--//

        protected Port(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interruptMode)
        {
            this.Id = portId;
            GPIOManager.GetInstance().Export(portId);
        }
Exemplo n.º 32
0
 protected InputPort(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interruptMode)
     : base(portId, glitchFilter, resistor, interruptMode)
 {
     GPIOManager.GetInstance().SetPortType(portId, PortType.INPUT);
 }
Exemplo n.º 33
0
 public CamPositionSensor(Cpu.Pin pin, bool glitchFilter, ResistorMode resistorMode, InterruptMode interruptMode)
     : base(pin, glitchFilter, resistorMode, interruptMode)
 {
 }
Exemplo n.º 34
0
 public override void SetupInterrupt(InterruptMode mode)
 {
     Controller.SetupInterrupt(PinNum, mode);
 }
Exemplo n.º 35
0
 public RiscV32(IRiscVTimeProvider timeProvider, string cpuType, Machine machine, uint hartId = 0, PrivilegeArchitecture privilegeArchitecture = PrivilegeArchitecture.Priv1_11, Endianess endianness = Endianess.LittleEndian, ulong?nmiVectorAddress = null, uint?nmiVectorLength = null, bool allowUnalignedAccesses = false, InterruptMode interruptMode = InterruptMode.Auto)
     : base(timeProvider, hartId, cpuType, machine, privilegeArchitecture, endianness, CpuBitness.Bits32, nmiVectorAddress, nmiVectorLength, allowUnalignedAccesses, interruptMode)
 {
 }
Exemplo n.º 36
0
        //--//

        public InterruptPort(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interrupt)
            : base(portId, glitchFilter, resistor, interrupt)
        {
            m_threadSpawn = null;
            m_callbacks = null;
        }
Exemplo n.º 37
0
 public abstract void SetupInterrupt(InterruptMode mode);
Exemplo n.º 38
0
 public abstract void SetupInterrupt(int pin, InterruptMode mode);
Exemplo n.º 39
0
        //--//

        protected Port(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interruptMode)
        {
            this.Id = portId;
            GPIOManager.Instance.Export(portId);
        }
 private void CPUControl_SetInterruptMode(InterruptMode interruptMode)
 {
     switch (interruptMode)
     {
         case InterruptMode.IM0:
             IM = 0;
             break;
         case InterruptMode.IM1:
             IM = 1;
             break;
         case InterruptMode.IM2:
             IM = 2;
             break;
     }
     if (TraceMicroInstructions)
     {
         TraceMicroInstruction(new MicroInstruction(Z80MicroInstructionTypes.CPUControlSetInterruptMode));
     }
 }
Exemplo n.º 41
0
 public override void SetupInterrupt(int pin, InterruptMode mode)
 {
     InterruptModes[pin] = mode;
 }
Exemplo n.º 42
0
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <param name="socket">The socket for the interrupt input interface.</param>
        /// <param name="pin">The pin used by the interrupt input interface.</param>
        /// <param name="glitchFilterMode">
        ///  A value from the <see cref="GlitchFilterMode"/> enumeration that specifies
        ///  whether to enable the glitch filter on this interrupt input interface.
        /// </param>
        /// <param name="resistorMode">
        ///  A value from the <see cref="ResistorMode"/> enumeration that establishes a default state for the interrupt input interface. N.B. .NET Gadgeteer mainboards are only required to support ResistorMode.PullUp on interruptable GPIOs and are never required to support ResistorMode.PullDown; consider putting the resistor on the module itself.
        /// </param>
        /// <param name="interruptMode">
        ///  A value from the <see cref="InterruptMode"/> enumeration that establishes the requisite conditions
        ///  for the interface port to generate an interrupt.
        /// </param>
        /// <param name="module">The module using this interrupt input interface, which can be null if unspecified.</param>
        public InterruptInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module)
        {
            Cpu.Pin reservedPin = socket.ReservePin(pin, module);

            // native implementation is preferred to an indirected one
            if (reservedPin == Cpu.Pin.GPIO_NONE && socket.InterruptIndirector != null)
            {
                Interface = socket.InterruptIndirector(socket, pin, glitchFilterMode, resistorMode, interruptMode, module);
            }

            else
            {
                Interface = new NativeInterruptInput(socket, pin, glitchFilterMode, resistorMode, interruptMode, module, reservedPin);
            }
        }
Exemplo n.º 43
0
        public NativeInterruptInput(Socket socket, Socket.Pin pin, GlitchFilterMode glitchFilterMode, ResistorMode resistorMode, InterruptMode interruptMode, Module module, Cpu.Pin cpuPin)
        {
            if (cpuPin == Cpu.Pin.GPIO_NONE)
            {
                // this is a mainboard error but should not happen since we check for this, but it doesnt hurt to double-check
                throw Socket.InvalidSocketException.FunctionalityException(socket, "InterruptInput");
            }

            _port = new InterruptPort(cpuPin, glitchFilterMode == GlitchFilterMode.On, (Port.ResistorMode)resistorMode, (Port.InterruptMode)interruptMode);
        }
Exemplo n.º 44
0
 public Tachometer(Cpu.Pin pin, bool glitchFilter, ResistorMode resistorMode, InterruptMode interruptMode)
     : base(pin, glitchFilter, resistorMode, interruptMode)
 {
 }
Exemplo n.º 45
0
 extern protected Port(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interruptMode);
Exemplo n.º 46
0
 protected InputPort(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interruptMode)
     : base(portId, glitchFilter, resistor, interruptMode)
 {
     GPIOManager.Instance.SetPortType(portId, PortType.INPUT);
 }
Exemplo n.º 47
0
 protected InputPort(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interruptMode)
     : base(portId, glitchFilter, resistor, interruptMode)
 {
 }
Exemplo n.º 48
0
 public IBiDirectionalPort CreateBiDirectionalPort(IPin pin, bool initialState = false, bool glitchFilter = false, InterruptMode interruptMode = InterruptMode.None, ResistorMode resistorMode = ResistorMode.Disabled, PortDirectionType initialDirection = PortDirectionType.Input)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 49
0
 public InterruptPort(Cpu.Pin portId, bool glitchFilter, ResistorMode resistor, InterruptMode interrupt)
     : base(portId, glitchFilter, resistor, interrupt)
 {
     //m_threadSpawn = null;
     //m_callbacks = null;
     GPIOManager.Instance.SetPortType(portId, PortType.INTERRUPT);
     GPIOManager.Instance.SetEdge(portId, interrupt);
 }