Get timestamping from mii_lite_lld.S Topic is solved

New to XMOS and XCore? Get started here.
etori90
Active Member
Posts: 34
Joined: Thu Sep 05, 2019 6:49 am

Get timestamping from mii_lite_lld.S

Post by etori90 »

I want to get outgoing timestamped value when packet go out.

As far as I know, when using the mii lite version, I can't get the timestamp value of the transmitted packet.

I found these annotations.

Code: Select all

out_idle:

    // Get a pointer to the next packet
    ldw   r9, sp[out_channel]
    outct res[r9], 1            // Request the next packet
    testct r5, res[r9]
    bt    r5, state_done
    in    r7, res[r9]           // Read the pointer to the packet

    ldw   r5, cp[all_fives]

    // Obtain the timestamp

    ldw   r8, sp[the_timer]
    in    r8, res[r8]

    // Transmitting the preamble

    out   res[r2], r5
    ldw   r5, cp[Dall_fives]
    out   res[r2], r5
    out   res[r9], r8
    ldw   r9, cp[initial_crc]
<Obtain the timestamp>is this meaning what I am thinking?

If yes, is there any way to get this value returned?
View Solution
User avatar
akp
XCore Expert
Posts: 580
Joined: Thu Nov 26, 2015 11:47 pm

Post by akp »

I believe it is what you're thinking. It's returned on a channel to the mill_lite_out_packet() call. If you check the mii_lite_driver.h:

Code: Select all

/** Function that will cause a packet to be transmitted. It must get an
 * array with an index into the array, a length of the packet (in bytes),
 * and a channel to the low-level driver. The low level driver will append
 * a CRC around the packet. The function returns once the preamble is on
 * the wire. The function mii_output_packet_done() should be called to syncrhonise
 * with the end of the packet.
 *
 * \param c_out  Output channel to the Low-Level Driver.
 *
 * \param buf    Array that contains the message. That this is an array
 *               of words, that must contain the data in network order: fill
 *               it using (buf, unsigned char[]). The last three words
 *               beyond the end of the buffer will be modified.
 *
 * \param length Length of message in bytes, excluding CRC, which will be added
 *               upon transmission.
 *
 * \returns      The time at which the message went onto the wire, measured in
 *               reference clock periods
 *
 */
int mii_lite_out_packet(chanend c_out, int * unsafe buf, int length);
A deeper look at the code shows that the timestamp is taken at the beginning of the preamble and then the returned value is increased by 64 to shift to the beginning of the packet (there are 64 bits transmitted prior to the start of the packet and it takes 640 ns to do that, or 64 counts of the 100 MHz reference clock).
etori90
Active Member
Posts: 34
Joined: Thu Sep 05, 2019 6:49 am

Post by etori90 »

Thank you very much! I solved this problem. It's working now