|
|
1 //-----------------------------------------------------
2 // Design Name : up_counter
3 // File Name : up_counter.cpp
4 // Function : Up counter
5 // Coder : Deepak Kumar Tala
6 //-----------------------------------------------------
7 #include "systemc.h"
8
9 SC_MODULE (up_down_counter) {
10 //-----------Input Ports---------------
11 sc_in <bool> enable, clk, reset;
12 //-----------Output Ports---------------
13 sc_out <sc_uint<8> > out;
14 //------------Internal Variables--------
15 sc_uint<8> count;
16
17 //-------------Code Starts Here---------
18 void counter () {
19 if (reset.read()) {
20 count = 0 ;
21 } else if (enable.read()) {
22 count = count + 1;
23 }
24 out.write(count);
25 }
26
27 SC_CTOR(up_down_counter) {
28 SC_METHOD (counter);
29 sensitive << clk.pos();
30 }
31
32 };
You could download file sc_examples here
|
|
|
1 //-----------------------------------------------------
2 // Design Name : up_counter_load
3 // File Name : up_counter_load.cpp
4 // Function : Up counter with load
5 // Coder : Deepak Kumar Tala
6 //-----------------------------------------------------
7 #include "systemc.h"
8
9 SC_MODULE (up_counter_load) {
10 //-----------Input Ports---------------
11 sc_in <sc_uint<8> > data;
12 sc_in <bool> load, enable, clk, reset;
13 //-----------Output Ports---------------
14 sc_out <sc_uint<8> > out;
15 //------------Internal Variables--------
16 sc_uint<8> count;
17
18 void counter () {
19 if (reset.read()) {
20 count = 0 ;
21 } else if (enable.read()) {
22 if (load.read()) {
23 count = data.read();
24 } else {
25 count = count + 1;
26 }
27 }
28 out.write(count);
29 }
30
31 SC_CTOR(up_counter_load) {
32 SC_METHOD (counter);
33 sensitive << clk.pos();
34 }
35 };
You could download file sc_examples here
|