Some code interacts with net-level interfaces and precise clock-cycle prescription is needed.
// This method describes the operations required to rx an Ethernet frame from the PHY/MAC.
static public int ReceivePacket()
{
rx_dst_rdy_n = !true;
Kiwi.Pause();
bool start = !rx_sof_n && !rx_src_rdy_n; // The start condition
int i;
bool doneReading;
if (true) // Process one packet
{
// Wait for SOF and SRC_RDY
while (!start)
{
Kiwi.Pause(); // Wait for a clock tick
start = !rx_sof_n && !rx_src_rdy_n; // Check for start of frame
}
// Read in the entire frame
i = 0;
doneReading = false;
// Read the remaining bytes
while (!doneReading)
{
if (!rx_src_rdy_n)
{
rx_buffer[i] = rx_data;
Console.WriteLine("EtherLink RX byte {0} {1}", i, rx_data);
i++;
}
doneReading = !rx_eof_n;
Kiwi.Pause();
}
}
rx_dst_rdy_n = !false; // No longer ready to receive.
start = false; // No longer at start of frame
return i;
}