Beispiel #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));
        }
Beispiel #2
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);
 }
        public void Reset()
        {
            var clockEntry = new ClockEntry((1 << 29) - 1, ClockEntry.FrequencyToRatio(this, 1000000), OnLimitReached, false)
            {
                Value = 0
            };

            clockSource.ExchangeClockEntryWith(OnLimitReached, x => clockEntry, () => clockEntry);
        }
Beispiel #4
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);
        }
Beispiel #5
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));
 }
        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;
        }
Beispiel #7
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;
        }
        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;
        }
        private void InternalReset()
        {
            frequency = initialFrequency;
            divider   = initialDivider;

            var clockEntry = new ClockEntry(initialLimit, ClockEntry.FrequencyToRatio(this, 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;
        }
Beispiel #10
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));
 }
Beispiel #11
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();
 }
Beispiel #12
0
        public SimpleTicker(long periodInMs, Machine machine)
        {
            var clockSource = machine.ObtainClockSource();

            clockSource.AddClockEntry(new ClockEntry(periodInMs, ClockEntry.FrequencyToRatio(this, 1000), OnTick));
        }
Beispiel #13
0
 public SimpleTicker(ulong periodInMs, Machine machine)
 {
     machine.ClockSource.AddClockEntry(new ClockEntry(periodInMs, ClockEntry.FrequencyToRatio(this, 1000), OnTick));
 }
Beispiel #14
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();
        }