示例#1
0
 public SynopsysEthernetMAC(Machine machine) : base(machine)
 {
     MAC  = EmulationManager.Instance.CurrentEmulation.MACRepository.GenerateUniqueMAC();
     IRQ  = new GPIO();
     Link = new NetworkLink(this);
     Reset();
 }
示例#2
0
 public SMC91X(Machine machine)
 {
     this.machine = machine;
     MAC          = EmulationManager.Instance.CurrentEmulation.MACRepository.GenerateUniqueMAC();
     IRQ          = new GPIO();
     Link         = new NetworkLink(this);
     Reset();
 }
示例#3
0
 public CadenceGEM(Machine machine) : base(machine)
 {
     registers = new regs();
     IRQ       = new GPIO();
     Link      = new NetworkLink(this);
     //crc = new Crc16();
     MAC  = EmulationManager.Instance.CurrentEmulation.MACRepository.GenerateUniqueMAC();
     sync = new object();
     Reset();
 }
示例#4
0
 public KS8851(Machine machine)
 {
     this.machine  = machine;
     MAC           = EmulationManager.Instance.CurrentEmulation.MACRepository.GenerateUniqueMAC();
     currentLength = 4;
     request       = new byte[10240];
     response      = new byte[10240];
     packetQueue   = new Queue <EthernetFrame>();
     IRQ           = new GPIO();
     Link          = new NetworkLink(this);
 }
 public GaislerEth(Machine machine) : base(machine)
 {
     IRQ  = new GPIO();
     Link = new NetworkLink(this);
     Reset();
 }
        public ENC28J60(Machine machine)
        {
            sync         = new object();
            this.machine = machine;
            ResetPointers();

            var econ1 = new ByteRegister(this).WithValueField(0, 2, out currentBank, name: "BSEL")
                        .WithFlag(2, out ethernetReceiveEnabled, name: "RXEN")
                        .WithFlag(3, FieldMode.Read, writeCallback: (_, value) => { if (value)
                                                                                    {
                                                                                        TransmitPacket();
                                                                                    }
                                  }, name: "TXRTS")
                        .WithFlag(7, name: "TXRST");

            var econ2 = new ByteRegister(this, 0x80).WithFlag(6, FieldMode.Read, writeCallback: delegate {
                waitingPacketCount = Math.Max(0, waitingPacketCount - 1);
                RefreshInterruptStatus();
            }, name: "PKTDEC")
                        .WithFlag(7, out autoIncrement, name: "AUTOINC");

            var estat = new ByteRegister(this, 1).WithReadCallback(delegate { transmitPacketInterrupt.Value = false; RefreshInterruptStatus(); }) // not sure
                        .WithFlag(0, FieldMode.Read, name: "CLKRDY");                                                                             // we're always ready, so the reset value is 1

            var eie = new ByteRegister(this).WithFlag(3, out transmitPacketInterruptEnabled, writeCallback: delegate { RefreshInterruptStatus(); }, name: "TXIE")
                      .WithFlag(6, out receivePacketInterruptEnabled, writeCallback: delegate { RefreshInterruptStatus(); }, name: "PKTIE")
                      .WithFlag(7, out interruptsEnabled, writeCallback: delegate { RefreshInterruptStatus(); }, name: "INTIE");

            var eir = new ByteRegister(this).WithFlag(0, name: "RXERIF")
                      .WithFlag(3, out transmitPacketInterrupt, writeCallback: delegate { RefreshInterruptStatus(); }, name: "TXIF")
                      .WithFlag(6, FieldMode.Read, valueProviderCallback: _ => IsReceiveInterruptActive(), name: "PKTIF");

            var bank0Map = new Dictionary <long, ByteRegister>
            {
                // ERDPTL
                { 0x00, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => GetLowByteOf(bufferReadPointer),
                                                              writeCallback: (_, value) => SetLowByteOf(ref bufferReadPointer, (byte)value)) },

                // ERDPTH
                { 0x01, new ByteRegister(this).WithValueField(0, 5, valueProviderCallback: _ => GetHighByteOf(bufferReadPointer),
                                                              writeCallback: (_, value) => SetHighByteOf(ref bufferReadPointer, (byte)value)) },

                // EWRPTL
                { 0x02, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => GetLowByteOf(bufferWritePointer),
                                                              writeCallback: (_, value) => SetLowByteOf(ref bufferWritePointer, (byte)value)) },

                // EWRPTH
                { 0x03, new ByteRegister(this).WithValueField(0, 5, valueProviderCallback: _ => GetHighByteOf(bufferWritePointer),
                                                              writeCallback: (_, value) => SetHighByteOf(ref bufferWritePointer, (byte)value)) },

                // ETXSTL
                { 0x04, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => GetLowByteOf(transmitBufferStart),
                                                              writeCallback: (_, value) => SetLowByteOf(ref transmitBufferStart, (byte)value)) },

                // ETXSTH
                { 0x05, new ByteRegister(this).WithValueField(0, 5, valueProviderCallback: _ => GetHighByteOf(transmitBufferStart),
                                                              writeCallback: (_, value) => SetHighByteOf(ref transmitBufferStart, (byte)value)) },

                // ETXNDL
                { 0x06, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => GetLowByteOf(transmitBufferEnd),
                                                              writeCallback: (_, value) => SetLowByteOf(ref transmitBufferEnd, (byte)value)) },

                // ETXNDH
                { 0x07, new ByteRegister(this).WithValueField(0, 5, valueProviderCallback: _ => GetHighByteOf(transmitBufferEnd),
                                                              writeCallback: (_, value) => SetHighByteOf(ref transmitBufferEnd, (byte)value)) },

                // ERXSTL
                { 0x08, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => GetLowByteOf(receiveBufferStart),
                                                              writeCallback: (_, value) => { SetLowByteOf(ref receiveBufferStart, (byte)value); currentReceiveWritePointer = receiveBufferStart; }) },

                // ERXSTH
                { 0x09, new ByteRegister(this).WithValueField(0, 5, valueProviderCallback: _ => GetHighByteOf(receiveBufferStart),
                                                              writeCallback: (_, value) => { SetHighByteOf(ref receiveBufferStart, (byte)value); currentReceiveWritePointer = receiveBufferStart; }) },

                // ERXNDL
                { 0x0A, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => GetLowByteOf(receiveBufferEnd),
                                                              writeCallback: (_, value) => SetLowByteOf(ref receiveBufferEnd, (byte)value)) },

                // ERXNDH
                { 0x0B, new ByteRegister(this).WithValueField(0, 5, valueProviderCallback: _ => GetHighByteOf(receiveBufferEnd),
                                                              writeCallback: (_, value) => SetHighByteOf(ref receiveBufferEnd, (byte)value)) },

                // ERXRDPTL
                { 0x0C, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => GetLowByteOf(receiveReadPointer),
                                                              writeCallback: (_, value) => bufferedLowByteOfReceiveReadPointer = (byte)value) },

                // ERXRDPTH
                { 0x0D, new ByteRegister(this).WithValueField(0, 5, valueProviderCallback: _ => GetHighByteOf(receiveReadPointer),
                                                              writeCallback: (_, value) => receiveReadPointer = (int)(bufferedLowByteOfReceiveReadPointer | ((value << 8)))) }
            };

            var bank1Map = new Dictionary <long, ByteRegister>
            {
                // ERXFCON
                { 0x18, new ByteRegister(this, 0xA1).WithFlag(5, out crcEnabled, name: "CRCEN") },

                // EPKTCNT
                { 0x19, new ByteRegister(this).WithValueField(0, 8, FieldMode.Read, valueProviderCallback: _ => (uint)waitingPacketCount) }
            };

            var bank2Map = new Dictionary <long, ByteRegister>
            {
                // MACON1
                // note that we currently ignore all the Pause Control Frame stuff
                { 0x00, new ByteRegister(this).WithFlag(0, out macReceiveEnabled, name: "MARXEN").WithFlag(2, name: "RXPAUS").WithFlag(3, name: "TXPAUS") },

                // MACON3
                { 0x02, new ByteRegister(this).WithFlag(0, name: "FULDPX") },

                // MABBIPG (too low level parameter for emulation)
                { 0x04, new ByteRegister(this).WithValueField(0, 7) },

                // MAIPGL (same as above)
                { 0x06, new ByteRegister(this).WithValueField(0, 7) },

                // MAIPGH (same as above)
                { 0x07, new ByteRegister(this).WithValueField(0, 7) },

                // MICMD
                { 0x12, new ByteRegister(this).WithFlag(0, writeCallback: (_, value) => { if (value)
                                                                                          {
                                                                                              ReadPhyRegister();
                                                                                          }
                                                        }, name: "MIIRD") },

                // MIREGADR
                { 0x14, new ByteRegister(this).WithValueField(0, 5, out miiRegisterAddress) },

                // MIWRL
                { 0x16, new ByteRegister(this).WithValueField(0, 8, out phyWriteLow) },

                // MIWRH
                { 0x17, new ByteRegister(this).WithValueField(0, 8, writeCallback: (_, value) => WritePhyRegister((ushort)(phyWriteLow.Value | (value << 8)))) },

                // MIRDL
                { 0x18, new ByteRegister(this).WithValueField(0, 8, FieldMode.Read, valueProviderCallback: _ => (byte)lastReadPhyRegisterValue) },

                // MIRDH
                { 0x19, new ByteRegister(this).WithValueField(0, 8, FieldMode.Read, valueProviderCallback: _ => (byte)(lastReadPhyRegisterValue >> 8)) }
            };

            var bank3Map = new Dictionary <long, ByteRegister>
            {
                // MAADR5
                { 0x00, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => MAC.E, writeCallback: (_, value) => MAC = MAC.WithNewOctets(e: (byte)value)) },

                // MADDR6
                { 0x01, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => MAC.F, writeCallback: (_, value) => MAC = MAC.WithNewOctets(f: (byte)value)) },

                // MADDR3
                { 0x02, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => MAC.C, writeCallback: (_, value) => MAC = MAC.WithNewOctets(c: (byte)value)) },

                // MADDR4
                { 0x03, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => MAC.D, writeCallback: (_, value) => MAC = MAC.WithNewOctets(d: (byte)value)) },

                // MADDR1
                { 0x04, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => MAC.A, writeCallback: (_, value) => MAC = MAC.WithNewOctets(a: (byte)value)) },

                // MADDR2
                { 0x05, new ByteRegister(this).WithValueField(0, 8, valueProviderCallback: _ => MAC.B, writeCallback: (_, value) => MAC = MAC.WithNewOctets(b: (byte)value)) },

                // MISTAT
                { 0x0A, new ByteRegister(this).WithFlag(0, FieldMode.Read, name: "BUSY") } // we're never busy
            };

            var maps = new[] { bank0Map, bank1Map, bank2Map, bank3Map };

            // registers below are available in all banks
            foreach (var map in maps)
            {
                map.Add(0x1B, eie);   // EIE
                map.Add(0x1C, eir);   // EIR
                map.Add(0x1D, estat); // ESTAT
                map.Add(0x1E, econ2); // ECON2
                map.Add(0x1F, econ1); // ECON1
            }
            registers = maps.Select(x => new ByteRegisterCollection(this, x)).ToArray();

            ethernetBuffer = new byte[8.KB()];

            phyRegisters = new WordRegisterCollection(this, new Dictionary <long, WordRegister>
            {
                // PHCON1
                { 0x00, new WordRegister(this).WithFlag(8, name: "PDPXMD") }, // full duplex stuff, ignored

                // PHCON2
                { 0x10, new WordRegister(this) }
            });
            IRQ = new GPIO();
            IRQ.Set(); // the interrupt output is negated
            Link = new NetworkLink(this);
        }