This section shows the requirements and e code for the driver object.
The driver object (sbt_driver) follows the specification described in "DUT Input Protocol" on page 225. Requirements for the driver object are as follows:
Since the driver object is expected to be static, it should be defined as a unit.
Define a field cur_packet of the sbt_packet type that holds the values for the current packet being injected into the DUT. Do not generate the field in the generation phase.
Define a field delay of type uint that specifies the number of cycles to delay between consecutive packets. Set a soft constraint for the delay field to be between 1 and 10.
Define a field no_of_pkts of type uint that specifies the number of packets to be injected. Set a soft constraint for the no_of_pkts field to be between 5 and 20.
Define an event clk_fall that is emitted at the falling edge of the DUT clock.
Define a packet_started event that is emitted explicitly by the driver object at the beginning of packet transmission.
Define a packet_ended event that is emitted explicitly by the driver object at the end of packet transmission.
The method gen_and_drive() is the master TCM that generates many packets and injects them into the DUT. While generating packets, uid field should contain the serial number of the packet being generated.
The method drive_packet() injects exactly one packet into the DUT according to "DUT Input Protocol" on page 225.
Example 13-2 presents e code for the driver object.
File contains e code for the driver object. Since this object is modeled as a unit, all references to HDL signals assume that an hdl_path() has been defined at a higher level. <' import sbt_packet; unit sbt_driver { -- Define the driver as a unit !cur_packet : sbt_packet; -- Packet that will be -- generated -- on the fly !sent_packets : list of sbt_packet;-- History list of all packets -- Good debug aid !delay : uint; -- Generated on the fly -- for each packet keep soft delay in [1..10]; -- Default range no_of_pkts : uint; -- Field to control number of packets generated keep soft no_of_pkts in [5..20]; -- Soft constraint event clk_fall is fall('clock')@sim; -- Clock event event packet_started; -- Emitted manually at start of packet event packet_ended; -- Emitted manually at end of packet -- Event to check that FIFOs for router are not full event suspend_data_off is true('suspend_data_in' == 0)@clk_fall; -- gen_and_drive() -- -- Drive packets to the DUT input port. -- Packets are generated on the fly, each packet generated -- just before being sent. gen_and_drive() @clk_fall is { -- Loop through the number of packets to be generated for i from 0 to no_of_pkts - 1 { -- Generate and wait a delay before driving the packet gen delay; wait [delay]; -- Generate the packet keeping the uid equal to the index gen cur_packet keeping { .uid == i; }; -- Pass the generated packet to the drive_packet() TCM drive_packet(cur_packet); }; wait [500]; -- Arbitrary amount of wait to flush out packets stop_run(); -- Stop the simulation }; -- end gen_and_drive() drive_packet(packet : sbt_packet) @clk_fall is { var pkt_packed: list of byte; -- List of bytes that will be -- driven to the DUT -- Break the packet down into a list of bytes -- Hint: Make sure the relevant fields are marked as physical pkt_packed = pack(packing.low, packet); emit packet_started; out(sys.time, " : Starting to drive packet to port ", packet.addr); -- Start sending -- Loop through the list of bytes and drive each byte to the -- data signal for each (pkt_byte) in pkt_packed { while 'suspend_data_in' == 1 { wait cycle; }; -- Alternate (elegant) solution of the while loop above: -- sync @suspend_data_off; -- Drive the packet_valid signal to '1' 'packet_valid' = 1 ; 'data[7:0]' = pkt_byte; -- Current byte in -- pkt_packed -- Drive the packet_valid signal back to 0 -- after the last data byte (payload) was driven and -- before the parity byte is driven (according to the -- protocol spec) if (index == (pkt_packed.size() - 1)) { 'packet_valid' = 0; }; -- Wait a cycle wait [1]; }; -- end for each emit packet_ended; -- Add the sent packet to the history list sent_packets.add(cur_packet); }; -- end drive_packet() run() is also { start gen_and_drive(); -- Start the main TCM at -- the start of simulation }; }; -- end struct sbt_driver '>