mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-10 18:21:20 +00:00
RTL - several Transmit Status Descriptor changes
This commit is contained in:
parent
d14afa3988
commit
4ebc8e2c76
5 changed files with 155 additions and 101 deletions
|
|
@ -4,6 +4,7 @@ using System.Text;
|
|||
using Cosmos.Hardware.Network;
|
||||
using Cosmos.Hardware.PC.Bus;
|
||||
using Cosmos.Hardware;
|
||||
using Cosmos.Hardware.Extension.NumberSystem;
|
||||
|
||||
namespace Cosmos.Hardware.Network.Devices.RTL8139
|
||||
{
|
||||
|
|
@ -312,6 +313,8 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
Console.WriteLine("Rx Configuration: " + Register.ReceiveConfigurationRegister.Load(mem).ToString());
|
||||
Console.WriteLine("Tx Configuration: " + Register.TransmitConfigurationRegister.Load(mem).ToString());
|
||||
Console.WriteLine("Tx Status Descr.: " + Register.TransmitStatusDescriptor.Load(mem).ToString());
|
||||
Console.WriteLine("Tx Start Address: " + valueReg.TransmitStartAddress);
|
||||
Console.WriteLine("Current Descrip.: " + Register.TransmitStatusDescriptor.GetCurrentTSDescriptor());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -420,31 +423,31 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
/// Transmits the given Packet
|
||||
/// </summary>
|
||||
/// <param name="packet"></param>
|
||||
[Obsolete]
|
||||
public bool Transmit(Packet packet)
|
||||
{
|
||||
if (packet == null)
|
||||
return false;
|
||||
//Put the packet into the correct TxBuffer
|
||||
//[Obsolete]
|
||||
//public bool Transmit(Packet packet)
|
||||
//{
|
||||
// if (packet == null)
|
||||
// return false;
|
||||
// //Put the packet into the correct TxBuffer
|
||||
|
||||
//TODO: Do NOT set all registers! This works, but is not efficient!
|
||||
TxBuffer0 = packet.PacketBody;
|
||||
TxBuffer1 = packet.PacketBody;
|
||||
TxBuffer2 = packet.PacketBody;
|
||||
TxBuffer3 = packet.PacketBody;
|
||||
WriteAddressToPCI(ref TxBuffer0, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD0);
|
||||
WriteAddressToPCI(ref TxBuffer1, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD1);
|
||||
WriteAddressToPCI(ref TxBuffer2, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD2);
|
||||
WriteAddressToPCI(ref TxBuffer3, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD3);
|
||||
// //TODO: Do NOT set all registers! This works, but is not efficient!
|
||||
// TxBuffer0 = packet.PacketBody;
|
||||
// TxBuffer1 = packet.PacketBody;
|
||||
// TxBuffer2 = packet.PacketBody;
|
||||
// TxBuffer3 = packet.PacketBody;
|
||||
// WriteAddressToPCI(ref TxBuffer0, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD0);
|
||||
// WriteAddressToPCI(ref TxBuffer1, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD1);
|
||||
// WriteAddressToPCI(ref TxBuffer2, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD2);
|
||||
// WriteAddressToPCI(ref TxBuffer3, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD3);
|
||||
|
||||
var tsd = Register.TransmitStatusDescriptor.Load(mem);
|
||||
tsd.Size = packet.PacketBody.Length;
|
||||
Console.WriteLine("Told NIC to send " + tsd.Size + " bytes.");
|
||||
tsd.OWN = false; //Begins sending
|
||||
Register.TransmitStatusDescriptor.IncrementTSDescriptor();
|
||||
// var tsd = Register.TransmitStatusDescriptor.Load(mem);
|
||||
// tsd.Size = packet.PacketBody.Length;
|
||||
// Console.WriteLine("Told NIC to send " + tsd.Size + " bytes.");
|
||||
// tsd.OWN = false; //Begins sending
|
||||
// Register.TransmitStatusDescriptor.IncrementTSDescriptor();
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
//}
|
||||
|
||||
public bool TransmitBytes(byte[] aData)
|
||||
{
|
||||
|
|
@ -459,9 +462,12 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139
|
|||
WriteAddressToPCI(ref TxBuffer3, pciCard.BaseAddress1 + (byte)Register.MainRegister.Bit.TSAD3);
|
||||
|
||||
var tsd = Register.TransmitStatusDescriptor.Load(mem);
|
||||
Console.WriteLine("Telling NIC to send " + aData.Length + " bytes.");
|
||||
tsd.Size = aData.Length;
|
||||
Console.WriteLine("Told NIC to send " + tsd.Size + " bytes.");
|
||||
Console.WriteLine("TransmitStatusDescriptor contains size of" + tsd.Size + " bytes.");
|
||||
Console.WriteLine("TDS : " + tsd.ToString());
|
||||
tsd.OWN = false; //Begins sending
|
||||
Console.WriteLine("TDS : " + tsd.ToString());
|
||||
Register.TransmitStatusDescriptor.IncrementTSDescriptor();
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -17,36 +17,8 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
{
|
||||
#region Constructor
|
||||
|
||||
// private PCIDevice pci;
|
||||
// private UInt32 tsdAddress;
|
||||
private byte descriptorID = 0;
|
||||
private MemoryAddressSpace xMem;
|
||||
//public static TransmitStatusDescriptor Load(PCIDevice pciCard) {
|
||||
// //Retrieve the 32 bits from the PCI card
|
||||
// //and create a TSD object
|
||||
// UInt32 address = 0;
|
||||
// switch (GetCurrentTSDescriptor())
|
||||
// {
|
||||
// case 0:
|
||||
// address = pciCard.BaseAddress1 + (byte)MainRegister.Bit.TSD0;
|
||||
// break;
|
||||
// case 1:
|
||||
// address = pciCard.BaseAddress1 + (byte)MainRegister.Bit.TSD1;
|
||||
// break;
|
||||
// case 2:
|
||||
// address = pciCard.BaseAddress1 + (byte)MainRegister.Bit.TSD2;
|
||||
// break;
|
||||
// case 3:
|
||||
// address = pciCard.BaseAddress1 + (byte)MainRegister.Bit.TSD3;
|
||||
// break;
|
||||
// default:
|
||||
// Console.WriteLine("Illegal TSDescriptor in RTL driver!");
|
||||
// break;
|
||||
// }
|
||||
|
||||
// return new TransmitStatusDescriptor(pciCard, address);
|
||||
//}
|
||||
|
||||
|
||||
public static TransmitStatusDescriptor Load(MemoryAddressSpace aMem)
|
||||
{
|
||||
return new TransmitStatusDescriptor(aMem);
|
||||
|
|
@ -57,12 +29,6 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
xMem = aMem;
|
||||
}
|
||||
|
||||
//private TransmitStatusDescriptor(PCIDevice hw, UInt32 adr)
|
||||
//{
|
||||
// pci = hw;
|
||||
// tsdAddress = adr;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Used to get the 32 bit value stored in the TransmitStatusDescriptor.
|
||||
/// </summary>
|
||||
|
|
@ -70,12 +36,50 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
{
|
||||
get
|
||||
{
|
||||
//TODO: Use all FOUR Descriptors!
|
||||
return xMem.Read32((UInt32)Register.MainRegister.Bit.TSD0);
|
||||
UInt32 address;
|
||||
switch (GetCurrentTSDescriptor())
|
||||
{
|
||||
case 0:
|
||||
address = (UInt32)Register.MainRegister.Bit.TSD0;
|
||||
break;
|
||||
case 1:
|
||||
address = (UInt32)Register.MainRegister.Bit.TSD1;
|
||||
break;
|
||||
case 2:
|
||||
address = (UInt32)Register.MainRegister.Bit.TSD2;
|
||||
break;
|
||||
case 3:
|
||||
address = (UInt32)Register.MainRegister.Bit.TSD3;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Problem with Transmit Status Descriptor");
|
||||
|
||||
}
|
||||
|
||||
return xMem.Read32(address);
|
||||
}
|
||||
set
|
||||
{
|
||||
xMem.Write32((UInt32)Register.MainRegister.Bit.TSD0, value);
|
||||
UInt32 address;
|
||||
switch (GetCurrentTSDescriptor())
|
||||
{
|
||||
case 0:
|
||||
address = (UInt32)Register.MainRegister.Bit.TSD0;
|
||||
break;
|
||||
case 1:
|
||||
address = (UInt32)Register.MainRegister.Bit.TSD1;
|
||||
break;
|
||||
case 2:
|
||||
address = (UInt32)Register.MainRegister.Bit.TSD2;
|
||||
break;
|
||||
case 3:
|
||||
address = (UInt32)Register.MainRegister.Bit.TSD3;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Problem with Transmit Status Descriptor");
|
||||
}
|
||||
|
||||
xMem.Write32(address, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
{
|
||||
|
||||
/// <summary>
|
||||
/// The registers in the RTL 8139 can be divided in two types. The first type is the registers where each bit has
|
||||
/// a meaning, and it is common to change specific bits. F.instance the CommandRegister where you have a Reset bit.
|
||||
/// The registers in the RTL 8139 can be divided in two types. The first type are the registers where each bit has
|
||||
/// a meaning, and where it is common to change specific bits. F.instance the CommandRegister where you have a Reset bit.
|
||||
///
|
||||
/// The other type of registers are the ones who contain values. Like a 32-bit pointer to an address, or a counter
|
||||
/// of some sort. Here we never set individual bits, but treat the entire 8, 16 or 32 bits as one logical unit.
|
||||
|
|
@ -85,6 +85,48 @@ namespace Cosmos.Hardware.Network.Devices.RTL8139.Register
|
|||
|
||||
|
||||
//TSAD
|
||||
#region Transmit Start Address of Descriptors
|
||||
|
||||
//public static byte CurrentDescriptor
|
||||
//{
|
||||
// get { ;}
|
||||
// set { ;}
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the actual address in the current
|
||||
/// </summary>
|
||||
public UInt32 TransmitStartAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
UInt32 address = 0;
|
||||
switch (Register.TransmitStatusDescriptor.GetCurrentTSDescriptor())
|
||||
{
|
||||
case 0:
|
||||
address = (UInt32)MainRegister.Bit.TSAD0;
|
||||
break;
|
||||
case 1:
|
||||
address = (UInt32)MainRegister.Bit.TSAD1;
|
||||
break;
|
||||
case 2:
|
||||
address = (UInt32)MainRegister.Bit.TSAD2;
|
||||
break;
|
||||
case 3:
|
||||
address = (UInt32)MainRegister.Bit.TSAD3;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Illegal Transmit Status Descriptor");
|
||||
break;
|
||||
}
|
||||
|
||||
return xMem.Read32(address);
|
||||
}
|
||||
private set { ;}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//RBSTART
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,9 @@ namespace FrodeTest.Shell
|
|||
var head = new PacketHeader(0xFF);
|
||||
byte[] data = FrodeTest.Test.Mock.FakeBroadcastPacket.GetFakePacket();
|
||||
var packet = new Packet(head, data);
|
||||
nic.Transmit(packet);
|
||||
//nic.Transmit(packet);
|
||||
nic.TransmitBytes(data); //TODO: Wrap data in physical packet with header.
|
||||
//nic.TransmitBytes(data);
|
||||
}
|
||||
}
|
||||
else if (command.Equals("read"))
|
||||
|
|
|
|||
|
|
@ -1,43 +1,43 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Cosmos.Hardware.Network.Devices.RTL8139;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Cosmos.Hardware.Network.Devices.RTL8139;
|
||||
|
||||
namespace FrodeTest.Test
|
||||
{
|
||||
public class RTL8139Test
|
||||
{
|
||||
[Obsolete]
|
||||
public static void RunTest()
|
||||
{
|
||||
// Testing RTL8139 PCI networkcard
|
||||
//Load card
|
||||
var nics = RTL8139.FindAll();
|
||||
//namespace FrodeTest.Test
|
||||
//{
|
||||
// public class RTL8139Test
|
||||
// {
|
||||
// [Obsolete]
|
||||
// public static void RunTest()
|
||||
// {
|
||||
// // Testing RTL8139 PCI networkcard
|
||||
// //Load card
|
||||
// var nics = RTL8139.FindAll();
|
||||
|
||||
if (nics.Count == 0)
|
||||
{
|
||||
Console.WriteLine("No Realtek 8139 network card found!!");
|
||||
return;
|
||||
}
|
||||
// if (nics.Count == 0)
|
||||
// {
|
||||
// Console.WriteLine("No Realtek 8139 network card found!!");
|
||||
// return;
|
||||
// }
|
||||
|
||||
Console.WriteLine(nics.Count + " network cards found");
|
||||
var nic = (RTL8139)nics[0];
|
||||
// Console.WriteLine(nics.Count + " network cards found");
|
||||
// var nic = (RTL8139)nics[0];
|
||||
|
||||
Console.WriteLine("Network card: " + nic.Name);
|
||||
Console.WriteLine("HW Revision: " + nic.HardwareRevision);
|
||||
Console.WriteLine("MAC address: " + nic.MACAddress.ToString());
|
||||
// Console.WriteLine("Network card: " + nic.Name);
|
||||
// Console.WriteLine("HW Revision: " + nic.HardwareRevision);
|
||||
// Console.WriteLine("MAC address: " + nic.MACAddress.ToString());
|
||||
|
||||
//Console.WriteLine("BaseAddress0 is : " + pciNic.BaseAddress0);
|
||||
Console.WriteLine("BaseAddress1 is : " + nic.PCICard.BaseAddress1);
|
||||
Console.WriteLine("Enabling card...");
|
||||
nic.Enable();
|
||||
Console.WriteLine("Initializing driver...");
|
||||
nic.InitializeDriver();
|
||||
// //Console.WriteLine("BaseAddress0 is : " + pciNic.BaseAddress0);
|
||||
// Console.WriteLine("BaseAddress1 is : " + nic.PCICard.BaseAddress1);
|
||||
// Console.WriteLine("Enabling card...");
|
||||
// nic.Enable();
|
||||
// Console.WriteLine("Initializing driver...");
|
||||
// nic.InitializeDriver();
|
||||
|
||||
var head = new PacketHeader(0xFF);
|
||||
byte[] data = Mock.FakeBroadcastPacket.GetFakePacketAllHigh();
|
||||
var packet = new Packet(head, data);
|
||||
nic.Transmit(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
// var head = new PacketHeader(0xFF);
|
||||
// byte[] data = Mock.FakeBroadcastPacket.GetFakePacketAllHigh();
|
||||
// var packet = new Packet(head, data);
|
||||
// nic.Transmit(packet);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
|||
Loading…
Reference in a new issue