Previous Section Next Section

9.5 Exercises

  1. Define a struct packet. Define the following elements in this struct.

    1. addr (2 bits) - physical field

    2. len (6 bits) - physical field

    3. payload (list of byte) - physical field

    4. len field equals the length of the payload (constraint)

    5. trailer (byte) - physical field

    6. Constrain each byte of payload to be equal to the index of that byte.

  2. Extend sys. Create an instance packet1 of type packet in sys. Create an instance packet2 of type packet in sys. Mark the packet2 instance as do-not-generate (!).

    1. Extend the run() method of sys.

    2. Declare a local variable packed_data as list of byte.

    3. Print packet1.

    4. Pack the packet1 instance to packed_data using packing.high.

    5. Print the value of packed_data.

    6. Unpack the packed_data to the packet2 instance.

    7. Print packet2.

  3. Extend sys.

    1. Extend the run() method of sys.

    2. Create a local variable diff that is of type list of string.

    3. Compare the physical fields of packet1 and packet2 and store the result in diff. (Hint: Use deep_compare_physical().)

    4. Check that diff is empty, otherwise print diff with dut_error(). (Hint: Use check that syntax and is_empty() method.)

    5. Compare all fields of packet1 and packet2 and store the result in diff. (Hint: Use deep_compare().)

    6. Check that diff is empty, otherwise print diff with dut_error(). (Hint: Use check that syntax and is_empty() method.)

  4. Extend sys. Extend the setup() method to set the check effect of all messages to WARNING.

  5. Write the expect struct members for the following scenarios. @p_clk is the sampling event.

    1. Declare events p_clk, req, ack, p_start, and p_end.

    2. If the @req event occurs, @ack should occur within 5 to 10 cycles after @req.

    3. If the @p_start event occurs, @ack should occur within 5 to 10 cycles after @p_start followed by @p_end within 25 to 100 cycles of @ack.

  6. Extend sys. Declare a count field in sys. Write the following on struct members within sys.

    1. On the occurrence of the req event, print the message "Request event occurred".

    2. On the occurrence of the p_start event, print the message "Packet started". Set the field count to the value 0.

Previous Section Next Section