/// <summary> /// Sends the packet. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public bool SendPacket(byte[] data) { uint txd = nextTXDesc++; if (nextTXDesc >= 16) { nextTXDesc = 0; } uint offset = txd * 4; // check if (oldest) descriptor is available (Bit 31/OWN = 0 available) if ((txDescriptor.Read32(offset + 1) & 0x80000000) == 0) { for (uint i = 0; i < data.Length; i++) { buffers.Write8((txd * bufferSize) + i, data[i]); } ushort length = (ushort)(~data.Length); length++; // Set bits 31/OWN, 25/STP (start of packet), 24/ENP (end of packet) and two's compliment of the buffer length txDescriptor.Write32(offset + 1, (length & (uint)(0x0FFF)) | (uint)(0x8300F000)); return(true); } return(false); }
/// <summary> /// Retrieves the packets. /// </summary> protected void RetrievePackets() { // Check all descriptors for (uint rxd = 0; rxd < 16; rxd++) { uint offset = rxd * 4; uint status = rxDescriptor.Read32(offset + 1); // Check is 31/OWN bit is not set if ((status & 0x80000000) == 0) { ushort length = (ushort)(rxDescriptor.Read16(offset + 0) & 0xFFF); var data = new byte[length]; for (uint i = 0; i < data.Length; i++) { data[i] = buffers.Read8((rxd * bufferSize) + i); } // if queue fails because it is already full, the packet is discarded packetBuffer.QueuePacketForStack(data); // Clear 31/OWN bit rxDescriptor.Write32(offset + 1, status | 0x80000000); } } }
/// <summary> /// Gets the fifo. /// </summary> /// <param name="index">The index.</param> /// <returns></returns> protected uint GetFifo(uint index) { return(fifo.Read32(index * 4)); }