// Construct a new Exchange.
        public MessageExchange(string shellOrTitleId, string name, string masterSN)
        {
            Shell s = Shell.GetShell(shellOrTitleId);

            if (s == null)
            {
                s = Shell.GetShell(Shell.ConsoleShellId);
            }
            if (s != null)
            {
                Interrupter = s.Interrupter;
                ShellId     = s.ShellId;
            }
            Id             = name;
            IsClosing      = false;
            ParameterTable = new DeviceParameterTable();
            ParameterTabelInit(masterSN);
            Manager = new NetIfManager(ShellId, masterSN, Interrupter);
            Manager.AddDriver(new MediatorNetIf(Manager, this));

            OutgoingQueue     = new LinkedBlockingCollection <MessageBinder>();
            IncomingQueue     = new LinkedBlockingCollection <BabelMessage>();
            IncomingListeners = new List <MessageBinder>();
            WaitingForReply   = new List <MessageBinder>();

            DispatcherThread = new MessageDispatcherThread(this);
            DispatcherThread.Start();
            ReceiverThread = new MessageReceiverThread(this);
            ReceiverThread.Start();

            Manager.Start();
        }
Exemple #2
0
        protected bool RestartFromInterrupt(InterruptSource intSource)
        {
            // https://github.com/Gekkio/mooneye-gb/blob/ca7ff30/tests/acceptance/interrupts/ie_push.s

            var address      = (ushort)(0x0040 + (byte)((int)intSource << 3));
            var intSourceBit = (byte)(1 << (byte)intSource);

            WriteMemory8(--sp, (byte)(pc >> 8));

            var newIntEnable    = memoryReadDelegate(0xFFFF);
            var continueRestart = (newIntEnable & intSourceBit) != 0;

            WriteMemory8(--sp, (byte)(pc & 0xFF));

            if (continueRestart)
            {
                pc = address;
                memoryWriteDelegate(0xFF0F, (byte)(memoryReadDelegate(0xFF0F) & (byte)~intSourceBit));
            }
            else
            {
                pc = 0x0000;
            }

            return(continueRestart);
        }
Exemple #3
0
 public EventReporter(string componentIdPattern, InterruptSource interrupt)
 {
     FullInfo           = true;
     ShowInHex          = true;
     Interrupt          = interrupt;
     ComponentIdPattern = componentIdPattern;
     EventReportQueue   = new BlockingCollection <string>();
 }
Exemple #4
0
        /// <summary>
        /// Return the Global interrupts status
        /// </summary>
        /// <param name="source">The Global interrupt source(s) to be checked</param>
        /// <returns>The checked Global interrupt source status.</returns>
        public InterruptSource ReadGlobalInterruptStatus(InterruptSource source = InterruptSource.All)
        {
            byte[] buffer = new byte[1];

            // Get the current register value
            _touchController.WriteReadPartial(new byte[] { REGISTER_INT_STA }, buffer);

            return((InterruptSource)(buffer[0] & (byte)source));
        }
Exemple #5
0
        /// <summary>
        ///  Check the selected Global interrupt source pending bit
        /// </summary>
        /// <param name="source">The Global interrupt source(s) to be checked.</param>
        /// <returns>The checked Global interrupt source status.</returns>
        public bool GlobalInterruptStatus(InterruptSource source)
        {
            byte[] buffer = new byte[1];

            // Get the current register value
            _touchController.WriteReadPartial(new byte[] { REGISTER_INT_STA }, buffer);

            return(((InterruptSource)buffer[0] & source) == source);
        }
Exemple #6
0
        /// <summary>
        /// Disable the interrupt mode for the selected IT source.
        /// </summary>
        /// <param name="source">The interrupt source to be configured</param>
        public void DisableInterruptSource(InterruptSource source)
        {
            byte[] buffer = new byte[1];

            // Get the current value of the INT_EN register
            _touchController.WriteReadPartial(new byte[] { REGISTER_INT_EN }, buffer);

            // Set the interrupts to be Enabled
            buffer[0] &= (byte)(~(byte)source);

            // Write Back the Interrupt Control register
            _touchController.WritePartial(new byte[] { REGISTER_INT_EN, buffer[0] });
        }
Exemple #7
0
        public static void TouchScreenInterruptRequest(object sender, GpioPinValueChangedEventArgs e)
        {
            // get interrupt status from touch controller
            InterruptSource interruptStatus = _touchController.ReadGlobalInterruptStatus();

            if ((interruptStatus & InterruptSource.Touch) == InterruptSource.Touch)
            {
                // set the touch event
                _touchEvent.Set();
            }

            // clear interrupt flags
            _touchController.ClearGlobalInterrupt(interruptStatus);
        }
Exemple #8
0
 public NetIfManager(string shellId, string masterSN, InterruptSource interrupt)
 {
     ShellId           = shellId;
     Interrupt         = interrupt;
     IoBuffersFreeHeap = new TokenAllocator(IoBuffersHeapSize);
     IoBuffers         = new PacketBuffer[IoBuffersHeapSize];
     for (int k = 0; k < IoBuffersHeapSize; ++k)
     {
         IoBuffers[k] = new PacketBuffer(MaxPacketSize);
     }
     IoNetIfs            = new Dictionary <int, LinkDriver>();
     Factory             = new PacketFactory(this);
     SerialNumberManager = new SerialNumbers(this, masterSN);
 }
Exemple #9
0
        private bool ServiceInterrupt(InterruptSource intSource, byte intEnable, byte intFlags)
        {
            var intSourceBit = (byte)(1 << (byte)intSource);

            if (((intEnable & intSourceBit) == intSourceBit) && ((intFlags & intSourceBit) == intSourceBit))
            {
                ime = false;

                currentCycles += 20;

                return(RestartFromInterrupt(intSource));
            }

            return(false);
        }
Exemple #10
0
 protected LinkDevice()
 {
     Interrupt       = new InterruptSource();
     IsClosing       = false;
     IsReading       = false;
     IsWriting       = false;
     IsInterrupted   = false;
     EnableListeners = true;
     ReadsCount      = 0;
     WritesCount     = 0;
     DeviceLock      = new Object();
     SuspendGate     = new Gate(true);
     WriteQueue      = new LinkedBlockingCollection <byte[]>();
     ReadQueue       = new BlockingCollection <byte[]>();
     ReadThread      = null;
     WriteThread     = null;
     ListenerThread  = null;
 }
Exemple #11
0
 /// <summary>
 /// Clear the selected Global interrupt pending bit(s).
 /// </summary>
 /// <param name="source">The Global interrupt source(s) to be cleared</param>
 public void ClearGlobalInterrupt(InterruptSource source)
 {
     // Write 1 to the bits that have to be cleared
     _touchController.WritePartial(new byte[] { REGISTER_INT_STA, (byte)source });
 }
Exemple #12
0
 public SerialPort(InterruptSource intSource)
 {
     interruptSource = intSource;
 }
Exemple #13
0
 public void RequestInterrupt(InterruptSource source)
 {
     memoryWriteDelegate(0xFF0F, (byte)(memoryReadDelegate(0xFF0F) | (byte)(1 << (byte)source)));
 }