Previous Section Next Section

13.2 Driver Object

This section shows the requirements and e code for the driver object.

13.2.1 Requirements 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:

Example 13-2 presents e code for the driver object.

13.2.2 e Code for the Driver Object

Example 13-2 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

'>
Previous Section Next Section