mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-20 04:48:53 +00:00
RTL driver changes.
Set size of packet to send. Initialize RxBuffer. Packet sending is still VERY unstable.
This commit is contained in:
parent
f4c9709932
commit
6d287c9681
6 changed files with 78 additions and 47 deletions
|
|
@ -20,9 +20,12 @@ namespace Cosmos.Driver.RTL8139
|
|||
body = data;
|
||||
}
|
||||
|
||||
public byte[] PacketBody()
|
||||
public byte[] PacketBody
|
||||
{
|
||||
return body;
|
||||
get
|
||||
{
|
||||
return body;
|
||||
}
|
||||
//return new byte[10]; //TODO: Redo this completely! Hardcoded to some bogus value now.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,16 +227,18 @@ namespace Cosmos.Driver.RTL8139
|
|||
/// Initialize the Receive Buffer. The RBSTART register consists of 4 bytes (0x30h to 0x33h) which should contain
|
||||
/// the address of a buffer to save incoming data to.
|
||||
/// </summary>
|
||||
private void InitReceiveBuffer()
|
||||
public void InitReceiveBuffer()
|
||||
{
|
||||
//TODO: Really unsure of the types and math here...
|
||||
//char[] rx_buffer = new char[8192+16]; //8k + header
|
||||
//pciCard.Write8(RTL8139Register.RxBuf, (byte)rx_buffer);
|
||||
//byte[] rxbuffer = new byte(
|
||||
|
||||
//Prepare a buffer area
|
||||
byte[] rxbuffer = new byte[2048];
|
||||
|
||||
UInt32 address = pciCard.BaseAddress1 + (byte)MainRegister.Bit.RxBuf;
|
||||
|
||||
//Write the address of the buffer area to the RBSTART
|
||||
WriteAddressToPCI(ref rxbuffer, address);
|
||||
|
||||
Console.WriteLine("RxBuffer contains address: " + IOSpace.Read32(address));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -245,20 +247,21 @@ namespace Cosmos.Driver.RTL8139
|
|||
/// </summary>
|
||||
/// <param name="bytearray"></param>
|
||||
/// <param name="address"></param>
|
||||
private unsafe void WriteBufferToPCI(byte[] bytearray, uint address)
|
||||
private unsafe void WriteAddressToPCI(ref byte[] bytearray, uint address)
|
||||
{
|
||||
/*fixed (byte* bodystart = &bytearray[0])
|
||||
{
|
||||
IOSpace.Write32(address, (uint)bodystart);
|
||||
}
|
||||
*/
|
||||
|
||||
/* The data in the bytearray contains the actual bytes we want to transfer to the network.
|
||||
* This bytearray must be in a continous memoryarea on the computer.
|
||||
* We then write the address of this memoryarea to the network card.
|
||||
* The address is stored in the Transmit Start Address which corresponds to the Transmit Status Descriptor we are currently using (0-3).
|
||||
*/
|
||||
|
||||
|
||||
fixed (byte* bodystart = &bytearray[0])
|
||||
{
|
||||
IntPtr bodyAddress = (IntPtr)bodystart;
|
||||
IOSpace.Write32(address, (uint)bodyAddress);
|
||||
Console.WriteLine("Address: + " + (uint)bodyAddress);
|
||||
Console.WriteLine("Address where packet body is stored: " + (uint)bodyAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -271,37 +274,27 @@ namespace Cosmos.Driver.RTL8139
|
|||
//Tell the PCI card the address of body of the Packet.
|
||||
UInt32 address =
|
||||
pciCard.BaseAddress1 +
|
||||
(byte)MainRegister.Bit.TSD0 +
|
||||
(byte)MainRegister.Bit.TSD0 + //I think this should be TSAD0, but then no packet is sent...
|
||||
TransmitStatusDescriptor.GetCurrentTSDescriptor();
|
||||
byte[] body = packet.PacketBody();
|
||||
Console.WriteLine("Address of TSAD0: " + address);
|
||||
|
||||
Console.WriteLine("Packet to send: ");
|
||||
foreach (byte item in body)
|
||||
{
|
||||
Console.Write(item + ":");
|
||||
}
|
||||
Console.WriteLine();
|
||||
byte[] body = packet.PacketBody;
|
||||
|
||||
this.WriteBufferToPCI(body, address);
|
||||
WriteAddressToPCI(ref body, address);
|
||||
|
||||
Console.WriteLine("Data in TSD0:");
|
||||
Console.Write("Data in Transmit Status Descriptor " + TransmitStatusDescriptor.GetCurrentTSDescriptor() + ":");
|
||||
Console.WriteLine(IOSpace.Read32(address));
|
||||
|
||||
//Console.WriteLine("Address of packet: " + (string)(&body[0]));
|
||||
//At this point the TSDA0 should contain the address of the data.
|
||||
Console.WriteLine("The Data pointed to: " + IOSpace.Read32(IOSpace.Read32(address)));
|
||||
|
||||
//Set the transmit status - which enables the transmit.
|
||||
TransmitStatusDescriptor tsd = TransmitStatusDescriptor.Load(pciCard);
|
||||
this.SetEarlyTxThreshold(1024);
|
||||
tsd.Size = body.Length;
|
||||
Console.WriteLine("Told NIC to send " + tsd.Size + " bytes.");
|
||||
SetEarlyTxThreshold(1024);
|
||||
Console.WriteLine("Sending...");
|
||||
tsd.ClearOWNBit();
|
||||
TransmitStatusDescriptor.IncrementTSDescriptor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,25 @@ namespace Cosmos.Driver.RTL8139.Register
|
|||
IOSpace.Write8(tdsAddress + offset, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The total size in bytes of the data in the descriptor. Must not be longer then 1792 bytes (0x700h), this
|
||||
/// will set Tx queue invalid.
|
||||
/// </summary>
|
||||
public int Size
|
||||
{
|
||||
get
|
||||
{
|
||||
byte offset = 0;
|
||||
return (int)IOSpace.Read8(tds + offset);
|
||||
}
|
||||
set
|
||||
{
|
||||
//TODO: Check this - the register contains 12 bits. We only write 8 bits here.
|
||||
byte offset = 0;
|
||||
IOSpace.Write8(tds + offset, (byte)value);
|
||||
}
|
||||
}
|
||||
|
||||
public UInt32 TSD()
|
||||
{
|
||||
return IOSpace.Read32(tdsAddress);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace FrodeTest
|
|||
//Test.SwitchTest.RunTest();
|
||||
Test.RTL8139Test.RunTest();
|
||||
//Test.BinaryHelperTest.RunTest();
|
||||
Test.TransmitStatusDescriptorTest.RunTest();
|
||||
//Test.TransmitStatusDescriptorTest.RunTest();
|
||||
//Test.PacketHeaderTest.RunTest();
|
||||
//Test.RAMBusTest.RunTest();
|
||||
//Test.BoolTest.RunTest();
|
||||
|
|
|
|||
|
|
@ -30,14 +30,32 @@ namespace FrodeTest.Shell
|
|||
nic.Enable();
|
||||
Console.WriteLine("Enabled Network card");
|
||||
}
|
||||
else if (command.Equals("timer"))
|
||||
else if (command.Equals("send"))
|
||||
{
|
||||
Console.WriteLine("NIC TimerCount: " + nic.TimerCount);
|
||||
//Console.WriteLine("NIC TimerCount: " + nic.TimerCount);
|
||||
//Cosmos.Hardware.PC.Bus.PCIDevice pciNic = Cosmos.Hardware.PC.Bus.PCIBus.GetPCIDevice(0, 3, 0);
|
||||
Cosmos.Driver.RTL8139.PacketHeader head = new Cosmos.Driver.RTL8139.PacketHeader(0xFF);
|
||||
byte[] data = FrodeTest.Test.Mock.FakeBroadcastPacket.GetFakePacketAllHigh();
|
||||
Cosmos.Driver.RTL8139.Packet packet = new Cosmos.Driver.RTL8139.Packet(head, data);
|
||||
|
||||
//nic = new Cosmos.Driver.RTL8139.RTL8139(pciNic);
|
||||
if (nic == null)
|
||||
{
|
||||
Console.WriteLine("Enable NIC with command nic first");
|
||||
return;
|
||||
}
|
||||
nic.Enable();
|
||||
nic.EnableRecieve();
|
||||
nic.EnableTransmit();
|
||||
nic.Transmit(packet);
|
||||
}
|
||||
else if (command.Equals("reset"))
|
||||
{
|
||||
nic.TimerCount = 1;
|
||||
Console.WriteLine("NIC TimerCount: " + nic.TimerCount);
|
||||
//nic.TimerCount = 1;
|
||||
nic.SoftReset();
|
||||
nic.EnableTransmit();
|
||||
nic.EnableRecieve();
|
||||
Console.WriteLine("NIC reset");
|
||||
}
|
||||
else
|
||||
Console.WriteLine("No such systemcommand or application: " + command);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace FrodeTest.Test
|
|||
|
||||
//Console.WriteLine("PCI Command: " + pciNic.Command);
|
||||
//pciNic.EnableDevice();
|
||||
Console.WriteLine("PCI Command: " + pciNic.Command);
|
||||
//Console.WriteLine("PCI Command: " + pciNic.Command);
|
||||
|
||||
if (!pciNic.DeviceExists)
|
||||
Console.WriteLine("Unable to find PCI device for Network card");
|
||||
|
|
@ -31,18 +31,16 @@ namespace FrodeTest.Test
|
|||
Console.WriteLine("BaseAddress1 is : " + pciNic.BaseAddress1);
|
||||
Console.WriteLine("Enabling card...");
|
||||
nic.Enable();
|
||||
|
||||
//nic.SoftReset();
|
||||
//nic.InitReceiveBuffer();
|
||||
nic.EnableRecieve();
|
||||
nic.EnableTransmit();
|
||||
Cosmos.Hardware.PC.Global.Sleep(50);
|
||||
Console.WriteLine("Timer: " + nic.TimerCount);
|
||||
//Cosmos.Hardware.PC.Global.Sleep(50);
|
||||
//Console.WriteLine("Timer: " + nic.TimerCount);
|
||||
|
||||
Cosmos.Driver.RTL8139.PacketHeader head = new Cosmos.Driver.RTL8139.PacketHeader(0x77);
|
||||
byte[] data = Mock.FakeBroadcastPacket.GetFakePacket();
|
||||
byte[] data = Mock.FakeBroadcastPacket.GetFakePacketAllHigh();
|
||||
Cosmos.Driver.RTL8139.Packet packet = new Cosmos.Driver.RTL8139.Packet(head, data);
|
||||
nic.Transmit(packet);
|
||||
Console.WriteLine("Transmit called");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue