2011年5月21日 星期六

一個兩個function的SC_Module

#include "systemc.h"

SC_MODULE (first_counter) {
sc_in_clk clock ; // Clock input of the design
sc_in reset ; // active high, synchronous Reset input
sc_in enable; // Active high enable signal for counter
sc_out(sc_uint<4>); counter_out; // 4 bit vector output of the counter

//------------Local Variables Here---------------------
sc_uint<4> count;

//第一個function
// Below function implements actual counter logic
void incr_count () {
if (reset.read() == 1) {
count = 0;
counter_out.write(count);
// If enable is active, then we increment the counter
}
else if (enable.read() == 1) {
count = count + 1;
counter_out.write(count);
}
} // End of function incr_count

// Below functions prints value of count when ever it changes
void print_count () {
cout << "@" << sc_time_stamp() <<
" :: Counter Value " << counter_out.read() << endl;
}

SC_CTOR(first_counter) {
// Edge and level sensitive
SC_METHOD(incr_count);
sensitive << reset;
sensitive << clock.pos();

// Level Sensitive method
SC_METHOD(print_count);
sensitive << counter_out;
} // End of Constructor

}; // End of Module counter




沒有留言: