Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for wrapping timers #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions module_ethernet/src/full/mii_master.xc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
#include <syscall.h>
#include "ethernet_server_def.h"
#include <xclib.h>
#include <hwtimer.h>
#include <xscope.h>

#define QUOTEAUX(x) #x
#define QUOTE(x) QUOTEAUX(x)

#undef crc32
#define crc32(a, b, c) {__builtin_crc32(a, b, c); asm volatile (""::"r"(a):"memory");}

Expand Down Expand Up @@ -405,7 +409,7 @@ int g_mii_idle_slope[NUM_ETHERNET_PORTS];


// Do the real-time pin wiggling for a single packet
unsigned mii_transmit_packet(unsigned buf, out buffered port:32 p_mii_txd, timer tmr, unsigned ifg_time)
unsigned mii_transmit_packet(unsigned buf, out buffered port:32 p_mii_txd, hwtimer_t tmr, unsigned ifg_time)
{
register const unsigned poly = 0xEDB88320;
unsigned int crc = 0;
Expand All @@ -423,7 +427,9 @@ unsigned mii_transmit_packet(unsigned buf, out buffered port:32 p_mii_txd, timer
wrap_ptr = mii_packet_get_wrap_ptr(buf);

// Check that we are out of the inter-frame gap
tmr when timerafter(ifg_time) :> ifg_time;
asm volatile ("in %0, res[%1]"
: "=r" (ifg_time)
: "r" (tmr));

#pragma xta endpoint "mii_tx_sof"
p_mii_txd <: 0x55555555;
Expand Down Expand Up @@ -511,12 +517,15 @@ void mii_tx_pins(
#if (ETHERNET_TX_HP_QUEUE) && (ETHERNET_TRAFFIC_SHAPER)
int credit = 0;
int credit_time;
// Need one timer to be able to read at any time for the shaper
timer credit_tmr;
#endif
timer tmr;
// And a second timer to be enforcing the IFG gap
hwtimer_t tmr;
unsigned ifg_time;

#if (ETHERNET_TX_HP_QUEUE) && (ETHERNET_TRAFFIC_SHAPER)
tmr :> credit_time;
credit_tmr :> credit_time;
#endif
tmr :> ifg_time;
while (1) {
Expand Down Expand Up @@ -556,7 +565,7 @@ void mii_tx_pins(

#if (ETHERNET_TRAFFIC_SHAPER)
prev_credit_time = credit_time;
tmr :> credit_time;
credit_tmr :> credit_time;

elapsed = credit_time - prev_credit_time;
credit += elapsed * idle_slope;
Expand Down Expand Up @@ -615,6 +624,12 @@ void mii_tx_pins(

ifg_time = prev_eof_time + ETHERNET_IFS_AS_REF_CLOCK_COUNT;
ifg_time += (mii_packet_get_length(buf) & 0x3) * 8;
asm volatile ("setd res[%0], %1"
: // No dests
: "r" (tmr), "r" (ifg_time));
asm volatile ("setc res[%0], " QUOTE(XS1_SETC_COND_AFTER)
: // No dests
: "r" (tmr));

#if (ETHERNET_TRAFFIC_SHAPER)
if (packet_is_high_priority) {
Expand Down