Wednesday, April 23, 2008

Reusable Channel using Parameterized class

Let's consider the example of generic channel using paramerized class,


class channel #(type T = integer);

    T          queue[$];
    semaphore  sem;
    
    task put_data(T t);
        sem.get(1);
        queue.push_back(t);
        sem.put(1);
    endtask
    
    task get_data(ref T t);
        sem.get(1);
        t = queue.pop_back(t);
        sem.put(1);
    endtask

endclass

Using above mentioned code, you can create any type of customized channel between two components.
Like,
Channel passing integer data between two components using,
channel #(integer) int_channel = new();
Channel passing class object of type 'data_class' between two component using,
channel #(data_class) data_class_channel = new();

Next: Reusable Channel using Define Macro




No comments:

Post a Comment