24.03.2013 Views

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

UM-212 7 - Mixed-language simulation<br />

Example of parameter use<br />

<strong>ModelSim</strong> <strong>SE</strong> User’s <strong>Manual</strong><br />

Here is a complete example, ring buffer, including all files necessary for simulation.<br />

// ringbuf.h<br />

#ifndef INCLUDED_RINGBUF<br />

#define INCLUDED_RINGBUF<br />

class ringbuf : public sc_foreign_module {<br />

public:<br />

sc_in clk;<br />

...<br />

counter(sc_midule_name nm, char* hdl_name<br />

int num_generics, const char* generic_list)<br />

: sc_foreign_module(nm, hdl_name, num_generics,<br />

generic_list),<br />

{}<br />

};<br />

#endif<br />

---------------------------------------------------------------------------<br />

// test_ringbuf.h<br />

#ifndef INCLUDED_TEST_RINGBUF<br />

#define INCLUDED_TEST_RINGBUF<br />

#include "ringbuf.h"<br />

#include "string.h"<br />

SC_MODULE(test_ringbuf)<br />

{<br />

sc_signal iclock;<br />

...<br />

...<br />

// Verilog module instance<br />

ringbuf* chip;<br />

SC_CTOR(test_ringbuf)<br />

: iclock("iclock"),<br />

...<br />

...<br />

{<br />

const char* generic_list[3];<br />

generic_list[0] = strdup("int_param=4");<br />

generic_list[1] = strdup("real_param=2.6");<br />

generic_list[2] = strdup("str_param=\"Hello\"");<br />

// Enclose the string<br />

// in double quotes<br />

// Cleanup the memory allocated for theh generic list<br />

for (int i = 0; i < 3; i++;)<br />

free((char*)generic_list[i]);<br />

// Create Verilog module instance.<br />

chip = new ringbuf("chip", "ringbuf", 3, generic_list);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!