Пример #1
0
        public IManagedThread ObtainManagedThread(Action action, int frequency)
        {
            var ce = new ClockEntry(1, ClockEntry.FrequencyToRatio(this, frequency), action, false);

            ClockSource.AddClockEntry(ce);
            return(new ManagedThreadWrappingClockEntry(ClockSource, action));
        }
Пример #2
0
        public void Reset()
        {
            var clockEntry = new ClockEntry((1 << 29) - 1, 1000000, OnLimitReached, this, string.Empty, enabled: false)
            {
                Value = 0
            };

            clockSource.ExchangeClockEntryWith(OnLimitReached, x => clockEntry, () => clockEntry);
        }
Пример #3
0
 public PowerPc(string cpuType, Machine machine, Endianess endianness = Endianess.BigEndian) : base(cpuType, machine,
                                                                                                    /* hardcoded to big endian, controlable via TlibSetLittleEndianMode */ Endianess.BigEndian)
 {
     initialEndianess = endianness;
     irqSync          = new object();
     machine.ClockSource.AddClockEntry(
         new ClockEntry(long.MaxValue / 2, ClockEntry.FrequencyToRatio(this, 128000000), DecrementerHandler, this, String.Empty, false, Direction.Descending));
     TlibSetLittleEndianMode(initialEndianess == Endianess.LittleEndian ? 1u : 0u);
 }
Пример #4
0
        public void Reset()
        {
            var clockEntry = new ClockEntry((1 << 29) - 1, ClockEntry.FrequencyToRatio(this, 1000000), OnLimitReached, false)
            {
                Value = 0
            };

            clockSource.ExchangeClockEntryWith(OnLimitReached, x => clockEntry, () => clockEntry);
        }
Пример #5
0
        public static void ExecutePythonEvery(this Machine machine, string name, int milliseconds, string script)
        {
            var engine     = new ExecutorPythonEngine(machine, script);
            var clockEntry = new ClockEntry(milliseconds, ClockEntry.FrequencyToRatio(machine, 1000), engine.Action);

            machine.ObtainClockSource().AddClockEntry(clockEntry);

            events.Add(machine, name, engine.Action);
            machine.StateChanged += (m, s) => UnregisterEvent(m, name, s);
        }
        public static void ExecutePythonEvery(this Machine machine, string name, int milliseconds, string script)
        {
            var engine     = new ExecutorPythonEngine(machine, script);
            var clockEntry = new ClockEntry((ulong)milliseconds, 1000, engine.Action, machine, name);

            machine.ClockSource.AddClockEntry(clockEntry);

            events.Add(machine, name, engine.Action);
            machine.StateChanged += (m, s) => UnregisterEvent(m, name, s);
        }
Пример #7
0
        private void InternalReset()
        {
            var clockEntry = new ClockEntry(initialCompare, ClockEntry.FrequencyToRatio(this, initialFrequency), CompareReached, initialEnabled, initialDirection, initialWorkMode)
            {
                Value = initialDirection == Direction.Ascending ? 0 : initialLimit
            };

            clockSource.ExchangeClockEntryWith(CompareReached, entry => clockEntry, () => clockEntry);
            valueAccumulatedSoFar = 0;
            compareValue          = initialCompare;
        }
Пример #8
0
 public ComparingTimer(Machine machine, long frequency, long compare, long limit)
 {
     if (compare > limit || compare < 0)
     {
         throw new ConstructionException(string.Format(CompareHigherThanLimitMessage, compare, limit));
     }
     this.limit     = limit;
     initialCompare = compare;
     clockSource    = machine.ObtainClockSource();
     clockSource.AddClockEntry(new ClockEntry(compare, ClockEntry.FrequencyToRatio(this, frequency), CompareReached, false, workMode: WorkMode.OneShot));
 }
Пример #9
0
        private void InternalReset()
        {
            frequency = initialFrequency;

            var clockEntry = new ClockEntry(initialLimit, ClockEntry.FrequencyToRatio(this, frequency), OnLimitReached, initialEnabled, initialDirection, initialWorkMode)
            {
                Value = initialDirection == Direction.Ascending ? 0 : initialLimit
            };

            clockSource.ExchangeClockEntryWith(OnLimitReached, x => clockEntry, () => clockEntry);
            divider      = 1;
            EventEnabled = false;
        }
Пример #10
0
        private void InternalReset()
        {
            frequency = initialFrequency;
            divider   = initialDivider;

            var clockEntry = new ClockEntry(initialLimit, frequency / divider, OnLimitReached, owner, localName, initialEnabled, initialDirection, initialWorkMode)
            {
                Value = initialDirection == Direction.Ascending ? 0 : initialLimit
            };

            clockSource.ExchangeClockEntryWith(OnLimitReached, x => clockEntry, () => clockEntry);
            EventEnabled = initialEventEnabled;
            AutoUpdate   = initialAutoUpdate;
            rawInterrupt = false;
        }
        private void InternalReset()
        {
            frequency = initialFrequency;
            divider   = initialDivider;

            var clockEntry = new ClockEntry(initialCompare, ClockEntry.FrequencyToRatio(this, initialFrequency / divider), CompareReachedInternal, owner, localName, initialEnabled, initialDirection, initialWorkMode)
            {
                Value = initialDirection == Direction.Ascending ? 0 : initialLimit
            };

            clockSource.ExchangeClockEntryWith(CompareReachedInternal, entry => clockEntry, () => clockEntry);
            valueAccumulatedSoFar = 0;
            compareValue          = initialCompare;
            EventEnabled          = initialEventEnabled;
        }
Пример #12
0
        public void ShouldObserveShorterPeriodClockAfterAdd()
        {
            var        clockSource = new BaseClockSource();
            var        counterA    = 0;
            var        counterB    = 0;
            Action     handlerA    = () => counterA++;
            Action     handlerB    = () => counterB++;
            ClockEntry entryA      = new ClockEntry(1000, 1, handlerA, null, String.Empty)
            {
                Value = 0
            };
            ClockEntry entryB = new ClockEntry(100, 1, handlerB, null, String.Empty)
            {
                Value = 0
            };

            clockSource.AddClockEntry(entryA);
            clockSource.Advance(TimeInterval.FromSeconds(500));
            clockSource.AddClockEntry(entryB);
            entryA = clockSource.GetClockEntry(handlerA);
            entryB = clockSource.GetClockEntry(handlerB);
            Assert.AreEqual(entryA.Value, 500);
            Assert.AreEqual(entryA.Period, 1000);
            Assert.AreEqual(entryB.Value, 0);
            Assert.AreEqual(entryB.Period, 100);

            clockSource.Advance(TimeInterval.FromSeconds(50));
            entryA = clockSource.GetClockEntry(handlerA);
            entryB = clockSource.GetClockEntry(handlerB);
            Assert.AreEqual(counterA, 0);
            Assert.AreEqual(counterB, 0);
            Assert.AreEqual(entryA.Value, 550);
            Assert.AreEqual(entryA.Period, 1000);
            Assert.AreEqual(entryB.Value, 50);
            Assert.AreEqual(entryB.Period, 100);

            clockSource.Advance(TimeInterval.FromSeconds(50));
            entryA = clockSource.GetClockEntry(handlerA);
            entryB = clockSource.GetClockEntry(handlerB);
            Assert.AreEqual(counterA, 0);
            Assert.AreEqual(counterB, 1);
            Assert.AreEqual(entryA.Value, 600);
            Assert.AreEqual(entryA.Period, 1000);
            Assert.AreEqual(entryB.Value, 0);
            Assert.AreEqual(entryB.Period, 100);
        }
Пример #13
0
 public PowerPc(string cpuType, Machine machine, Endianess endianness = Endianess.BigEndian) : base(cpuType, machine, endianness)
 {
     irqSync = new object();
     machine.ObtainClockSource().AddClockEntry(
         new ClockEntry(long.MaxValue / 2, ClockEntry.FrequencyToRatio(this, 128000000), DecrementerHandler, false, Direction.Descending));
 }
Пример #14
0
 public TickTimer(Machine machine, ulong periodInMs) : base(machine)
 {
     machine.ClockSource.AddClockEntry(new ClockEntry(periodInMs, ClockEntry.FrequencyToRatio(this, 1000), OnTick, this, "TickTimer"));
     this.IRQ = new GPIO();
     DefineRegisters();
 }
Пример #15
0
        public SimpleTicker(long periodInMs, Machine machine)
        {
            var clockSource = machine.ObtainClockSource();

            clockSource.AddClockEntry(new ClockEntry(periodInMs, ClockEntry.FrequencyToRatio(this, 1000), OnTick));
        }
Пример #16
0
        public BetrustedI2C(Machine machine) : base(machine)
        {
            dataToSlave   = new Queue <byte>();
            dataFromSlave = new Queue <byte>();
            IRQ           = new GPIO();

            irqTimeoutCallback = new ClockEntry((ulong)5, ClockEntry.FrequencyToRatio(machine, 1000), this.FinishTransaction, machine, "Irq Scheduler");

            var registersMap = new Dictionary <long, DoubleWordRegister>()
            {
                { (long)Registers.ClockPrescale, new DoubleWordRegister(this)
                  .WithValueField(0, 16, FieldMode.Read | FieldMode.Write) },

                { (long)Registers.Control, new DoubleWordRegister(this)
                  .WithFlag(7, out enabled)
                  .WithTag("Interrupt enable", 6, 1)
                  .WithReservedBits(0, 6) },

                { (long)Registers.Transmit, new DoubleWordRegister(this)
                  .WithValueField(0, 8, out transmitBuffer, FieldMode.Write) },

                { (long)Registers.Receive, new DoubleWordRegister(this)
                  .WithValueField(0, 8, out receiveBuffer, FieldMode.Read) },

                { (long)Registers.Status, new DoubleWordRegister(this)
                  .WithFlag(7, out receivedAckFromSlaveNegated, FieldMode.Read)
                  .WithFlag(6, FieldMode.Read, valueProviderCallback: _ => false, name: "Busy")
                  .WithFlag(5, FieldMode.Read, valueProviderCallback: _ => false, name: "Arbitration lost")
                  .WithReservedBits(2, 3)
                  .WithFlag(1, FieldMode.Read, valueProviderCallback: _ => false, name: "Transfer in progress")
                  .WithFlag(0, out i2cIntIrqStatus, FieldMode.Read) },

                { (long)Registers.EventStatus, new DoubleWordRegister(this)
                  .WithFlag(1, FieldMode.Read, name: "TX_RX_DONE_STATUS", valueProviderCallback: _ => txRxDoneIrqStatus)
                  .WithFlag(0, FieldMode.Read, name: "I2C_INT_STATUS", valueProviderCallback: _ => i2cIntIrqStatus.Value) },

                { (long)Registers.EventPending, new DoubleWordRegister(this)
                  .WithFlag(1, out txRxDoneIrqPending, FieldMode.Read | FieldMode.WriteOneToClear, name: "TX_RX_DONE_PENDING", changeCallback: (_, __) => UpdateInterrupts())
                  .WithFlag(0, out i2cIntIrqPending, FieldMode.Read | FieldMode.WriteOneToClear, name: "I2C_INT_PENDING", changeCallback: (_, __) => UpdateInterrupts()) },

                { (long)Registers.EventEnable, new DoubleWordRegister(this)
                  .WithFlag(1, out txRxDoneIrqEnabled, name: "TX_RX_DONE_ENABLE", changeCallback: (_, __) => UpdateInterrupts())
                  .WithFlag(0, out i2cIntIrqEnabled, name: "I2C_INT_ENABLE", changeCallback: (_, __) => UpdateInterrupts()) },

                { (long)Registers.Command, new DoubleWordRegister(this)
                  .WithFlag(7, out generateStartCondition, FieldMode.Write)
                  .WithFlag(6, out generateStopCondition, FieldMode.Write)
                  .WithFlag(5, out readFromSlave, FieldMode.Write)
                  .WithFlag(4, out writeToSlave, FieldMode.Write)
                  .WithFlag(3, FieldMode.Read, name: "ACK", valueProviderCallback: _ => true)
                  // .WithTag("ACK", 3, 1)
                  .WithReservedBits(1, 2)
                  .WithFlag(0, FieldMode.Write, writeCallback: (_, __) => i2cIntIrqStatus.Value = false)
                  .WithWriteCallback((_, __) =>
                    {
                        if (!enabled.Value)
                        {
                            return;
                        }

                        if (generateStartCondition.Value)
                        {
                            generateStartCondition.Value = false;
                            if (transactionInProgress)
                            {
                                // repeated start - finish previous transaction first
                                SendDataToSlave();
                            }
                            else
                            {
                                transactionInProgress = true;
                            }

                            dataFromSlave.Clear();
                            if (selectedSlave != null)
                            {
                                selectedSlave.FinishTransmission();
                            }

                            if (!TryResolveSelectedSlave(out selectedSlave))
                            {
                                return;
                            }
                        }

                        if (writeToSlave.Value)
                        {
                            writeToSlave.Value = false;
                            HandleWriteToSlaveCommand();
                        }

                        if (readFromSlave.Value)
                        {
                            readFromSlave.Value = false;
                            HandleReadFromSlaveCommand();
                        }

                        if (transactionInProgress)
                        {
                            machine.ClockSource.AddClockEntry(irqTimeoutCallback);
                        }

                        if (generateStopCondition.Value)
                        {
                            selectedSlave.FinishTransmission();

                            generateStopCondition.Value = false;
                            if (!transactionInProgress)
                            {
                                return;
                            }

                            SendDataToSlave();
                            transactionInProgress = false;
                        }

                        shouldSendTxRxIrq = true;
                    }) }
            };

            registers = new DoubleWordRegisterCollection(this, registersMap);
            UpdateInterrupts();
        }
Пример #17
0
 public SimpleTicker(ulong periodInMs, Machine machine)
 {
     machine.ClockSource.AddClockEntry(new ClockEntry(periodInMs, ClockEntry.FrequencyToRatio(this, 1000), OnTick));
 }