예제 #1
0
파일: Connector.cs 프로젝트: rte-se/emul8
 public void DisconnectFromAll(IEmulationElement element)
 {
     var interestingKeys = connections.GetAllForRight(element);
     foreach(var external in interestingKeys)
     {
         Disconnect(external, element);
     }
 }
예제 #2
0
 public ClockEntry(ulong period, long ratio, Action handler, IEmulationElement owner, string localName, bool enabled = true, Direction direction = Direction.Ascending, WorkMode workMode = WorkMode.Periodic) : this()
 {
     this.Value     = direction == Direction.Ascending ? 0 : period;
     this.Ratio     = ratio;
     this.Period    = period;
     this.Handler   = handler;
     this.Enabled   = enabled;
     this.Direction = direction;
     this.WorkMode  = workMode;
     this.Owner     = owner;
     this.LocalName = localName;
 }
예제 #3
0
파일: Connector.cs 프로젝트: rte-se/emul8
 public void Disconnect(IConnectable connector, IEmulationElement connectee)
 {
     try
     {
         ((dynamic)connector).DetachFrom((dynamic)connectee);
         connections.RemovePair(connector, connectee);
     }
     catch(RuntimeBinderException)
     {
         ThrowConnectionException(connectee.GetType(), connector.GetType(), true);
     }
 }
예제 #4
0
 public void Disconnect(IConnectable connector, IEmulationElement connectee)
 {
     try
     {
         ((dynamic)connector).DetachFrom((dynamic)connectee);
         connections.RemovePair(connector, connectee);
     }
     catch (RuntimeBinderException)
     {
         ThrowConnectionException(connectee.GetType(), connector.GetType(), true);
     }
 }
예제 #5
0
 public void Connect(IEmulationElement connectee, IConnectable connector)
 {
     try
     {
         ((dynamic)connector).AttachTo((dynamic)connectee);
         connections.Add(connector, connectee);
     }
     catch (RuntimeBinderException)
     {
         ThrowConnectionException(connectee.GetType(), connector.GetType());
     }
 }
예제 #6
0
파일: Connector.cs 프로젝트: rte-se/emul8
 public void Connect(IEmulationElement connectee, IConnectable connector)
 {
     try
     {
         ((dynamic)connector).AttachTo((dynamic)connectee);
         connections.Add(connector, connectee);
     } 
     catch (RuntimeBinderException)
     {
         ThrowConnectionException(connectee.GetType(), connector.GetType());
     }
 }
예제 #7
0
 public ClockEntry(ulong period, long frequency, Action handler, IEmulationElement owner, string localName, bool enabled = true, Direction direction = Direction.Ascending, WorkMode workMode = WorkMode.Periodic, long step = 1) : this()
 {
     this.Value     = direction == Direction.Ascending ? 0 : period;
     this.Frequency = frequency;
     this.Step      = step;
     this.Period    = period;
     this.Handler   = handler;
     this.Enabled   = enabled;
     this.Direction = direction;
     this.WorkMode  = workMode;
     this.Owner     = owner;
     this.LocalName = localName;
     this.Ratio     = Step * FrequencyToRatio(owner, Frequency);
 }
예제 #8
0
파일: Utilities.cs 프로젝트: rte-se/emul8
 public static long HzToTicksSafe(long hz, IEmulationElement sender)
 {
     var result = (long)Math.Round(HzToTicks(hz));
     if(result == 0)
     {
         result = 1;
     }
     var againInHz = TicksToHz(result);
     if(Math.Abs(againInHz - hz) / hz > MaximalDifference)
     {
         sender.Log(LogLevel.Warning, "Significant difference between desired and actual frequency: {0}Hz={1}Hz vs {2}Hz={3}Hz,", 
                    Misc.NormalizeDecimal(hz), Misc.NormalizeDecimal(againInHz), hz, againInHz);
     }
     return result;
 }
예제 #9
0
        public bool TryGetEmulationElementByName(string name, object context, out IEmulationElement element)
        {
            if (name == null)
            {
                element = null;
                return(false);
            }
            var machineContext = context as Machine;

            if (machineContext != null)
            {
                IPeripheral outputPeripheral;
                if ((machineContext.TryGetByName(name, out outputPeripheral) || machineContext.TryGetByName(string.Format("sysbus.{0}", name), out outputPeripheral)))
                {
                    element = outputPeripheral;
                    return(true);
                }
            }

            Machine machine;

            if (TryGetMachineByName(name, out machine))
            {
                element = machine;
                return(true);
            }

            IExternal external;

            if (ExternalsManager.TryGetByName(name, out external))
            {
                element = external;
                return(true);
            }

            IHostMachineElement hostMachineElement;

            if (name.StartsWith(string.Format("{0}.", HostMachine.HostMachineName)) &&
                HostMachine.TryGetByName(name.Substring(HostMachine.HostMachineName.Length + 1), out hostMachineElement))
            {
                element = hostMachineElement;
                return(true);
            }

            element = null;
            return(false);
        }
예제 #10
0
        private static string GetName(IEmulationElement element, IEmulationElement nextElement = null)
        {
            string elementName;
            var    emulation = EmulationManager.Instance.CurrentEmulation;

            emulation.TryGetEmulationElementName(element, out elementName);

            if (nextElement != null)
            {
                string nextElementName;
                emulation.TryGetEmulationElementName(nextElement, out nextElementName);
                nextElementName = nextElementName.Replace(':', '-').Replace('.', '-');
                return("{0}-{1}-{2}".FormatWith(WiresharkExternalPrefix, elementName, nextElementName));
            }

            return("{0}-{1}".FormatWith(WiresharkExternalPrefix, elementName));
        }
예제 #11
0
        public static long HzToTicksSafe(long hz, IEmulationElement sender)
        {
            var result = (long)Math.Round(HzToTicks(hz));

            if (result == 0)
            {
                result = 1;
            }
            var againInHz = TicksToHz(result);

            if (Math.Abs(againInHz - hz) / hz > MaximalDifference)
            {
                sender.Log(LogLevel.Warning, "Significant difference between desired and actual frequency: {0}Hz={1}Hz vs {2}Hz={3}Hz,",
                           Misc.NormalizeDecimal(hz), Misc.NormalizeDecimal(againInHz), hz, againInHz);
            }
            return(result);
        }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Emul8.Utilities.Runtime.NativeBinder"/> class
 /// and performs binding between the class and given library.
 /// </summary>
 /// <param name='classToBind'>
 /// Class to bind.
 /// </param>
 /// <param name='libraryFile'>
 /// Library file to bind.
 /// </param>
 /// <remarks>
 /// Please note that:
 /// <list type="bullet">
 /// <item><description>
 /// This works now only with ELF libraries.
 /// </description></item>
 /// <item><description>
 /// You have to hold the reference to created native binder as long as the native functions
 /// can call managed one.
 /// </description></item>
 /// <item><description>
 /// You should dispose native binder after use to free memory taken by the native library.
 /// </description></item>
 /// </list>
 /// </remarks>
 public NativeBinder(IEmulationElement classToBind, string libraryFile)
 {
     delegateStore = new object[0];
     this.classToBind = classToBind;
     libraryAddress = SharedLibraries.LoadLibrary(libraryFile);
     libraryFileName = libraryFile;
     try
     {
         ResolveCallsToNative();
         ResolveCallsToManaged();
     }
     catch
     {
         Dispose();
         throw;
     }
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Emul8.Utilities.Runtime.NativeBinder"/> class
 /// and performs binding between the class and given library.
 /// </summary>
 /// <param name='classToBind'>
 /// Class to bind.
 /// </param>
 /// <param name='libraryFile'>
 /// Library file to bind.
 /// </param>
 /// <remarks>
 /// Please note that:
 /// <list type="bullet">
 /// <item><description>
 /// This works now only with ELF libraries.
 /// </description></item>
 /// <item><description>
 /// You have to hold the reference to created native binder as long as the native functions
 /// can call managed one.
 /// </description></item>
 /// <item><description>
 /// You should dispose native binder after use to free memory taken by the native library.
 /// </description></item>
 /// </list>
 /// </remarks>
 public NativeBinder(IEmulationElement classToBind, string libraryFile)
 {
     delegateStore    = new object[0];
     handles          = new GCHandle[0];
     this.classToBind = classToBind;
     libraryAddress   = SharedLibraries.LoadLibrary(libraryFile);
     libraryFileName  = libraryFile;
     try
     {
         ResolveCallsToNative();
         ResolveCallsToManaged();
     }
     catch
     {
         Dispose();
         throw;
     }
 }
예제 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Antmicro.Renode.Utilities.Runtime.NativeBinder"/> class
        /// and performs binding between the class and given library.
        /// </summary>
        /// <param name='classToBind'>
        /// Class to bind.
        /// </param>
        /// <param name='libraryFile'>
        /// Library file to bind.
        /// </param>
        /// <remarks>
        /// Please note that:
        /// <list type="bullet">
        /// <item><description>
        /// This works now only with ELF libraries.
        /// </description></item>
        /// <item><description>
        /// You have to hold the reference to created native binder as long as the native functions
        /// can call managed one.
        /// </description></item>
        /// <item><description>
        /// You should dispose native binder after use to free memory taken by the native library.
        /// </description></item>
        /// </list>
        /// </remarks>
        public NativeBinder(IEmulationElement classToBind, string libraryFile)
        {
            delegateStore = new object[0];
#if !PLATFORM_WINDOWS
            handles = new GCHandle[0];
#endif
            this.classToBind = classToBind;
            libraryAddress   = SharedLibraries.LoadLibrary(libraryFile);
            libraryFileName  = libraryFile;
            var importFields = classToBind.GetType().GetAllFields().Where(x => x.IsDefined(typeof(ImportAttribute), false)).ToList();
            EnsureWrappersType(importFields);
            wrappersObj = CreateWrappersObject();
            try
            {
                ResolveCallsToNative(importFields);
                ResolveCallsToManaged();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
        private bool SetLogLevel(LogLevel level, string backendName = null, string peripheralName = null)
        {
            IEmulationElement emulationElement = null;

            if (peripheralName != null &&
                !EmulationManager.Instance.CurrentEmulation.TryGetEmulationElementByName(peripheralName, monitor.Machine, out emulationElement))
            {
                return(false);
            }

            int  id = (emulationElement == null) ? -1 : EmulationManager.Instance.CurrentEmulation.CurrentLogger.GetOrCreateSourceId(emulationElement);
            bool somethingWasSet = false;

            foreach (var b in Logger.GetBackends())
            {
                if ((backendName == null || b.Key == backendName) && b.Value.IsControllable)
                {
                    b.Value.SetLogLevel(level, id);
                    somethingWasSet = true;
                }
            }

            return(somethingWasSet);
        }
예제 #16
0
 public void Disconnect(IEmulationElement connectee, IConnectable connector)
 {
     Disconnect(connector, connectee);
 }
예제 #17
0
 public static void NoisyLog(this IEmulationElement e, string message)
 {
     Log(e, LogLevel.Noisy, message);
 }
예제 #18
0
 public static void DebugLog(this IEmulationElement e, string message, params object[] args)
 {
     DebugLog(e, string.Format(message, args));
 }
예제 #19
0
 public static void DebugLog(this IEmulationElement e, string message)
 {
     Log(e, LogLevel.Debug, message);
 }
예제 #20
0
 public static void Log(this IEmulationElement e, LogLevel type, string message, params object[] args)
 {
     LogAs(e, type, message, args);
 }
예제 #21
0
 public static void Log(this IEmulationElement e, LogLevel type, string message)
 {
     LogAs(e, type, message, null);
 }
예제 #22
0
 public Packer(IEmulationElement parent)
 {
     this.parent = parent;
     byteQueue   = new Queue <byte>();
     queueLock   = new object();
 }
예제 #23
0
 public IEnumerable <IConnectable <IEmulationElement> > GetConnectionsFor(IEmulationElement obj)
 {
     return(connections.GetAllForRight(obj).Cast <IConnectable <IEmulationElement> >());
 }
예제 #24
0
 // TODO: think about delayed resolution of message generator
 public static void DebugLog(this IEmulationElement e, Func <string> messageGenerator)
 {
     DebugLog(e, messageGenerator());
 }
예제 #25
0
 public Encoder(int width, IEmulationElement loggingParent = null)
 {
     this.loggingParent = loggingParent;
     buffer             = new bool[width];
     Reset();
 }
예제 #26
0
파일: Connector.cs 프로젝트: rte-se/emul8
 public IEnumerable<IConnectable<IEmulationElement>> GetConnectionsFor(IEmulationElement obj)
 {
     return connections.GetAllForRight(obj).Cast<IConnectable<IEmulationElement>>();
 }
예제 #27
0
파일: Connector.cs 프로젝트: rte-se/emul8
 public void Disconnect(IEmulationElement connectee, IConnectable connector)
 {
     Disconnect(connector, connectee);
 }