URL
https://opencores.org/ocsvn/gfir/gfir/trunk
Subversion Repositories gfir
Compare Revisions
- This comparison shows the changes necessary to convert path
/gfir
- from Rev 2 to Rev 3
- ↔ Reverse comparison
Rev 2 → Rev 3
/trunk/sc/firTF.h
0,0 → 1,128
#include "systemc.h" |
|
#define order 18 // Filter Length |
|
/** This function exports the internal signals of the transposed-form FIR filter into a text file. |
* The text file entitled "fir_output.txt", which can be changed within this function. |
* The function inputs are the three internal signals between multiplier -> adder, delay -> adder, and adder_delay respectively. |
* Then there is the filter order defined by count, and finally the number of clock cycles defined by c. |
* P.S. Delete the text file before you re-simulate the design. |
*/ |
void text( sc_signal<sc_int<15> > _multi_add[order], sc_signal<sc_int<15> > _delay_add[order], sc_signal<sc_int<15> > _add_delay[order], unsigned int count, unsigned int c ) |
{ |
FILE *myFile; |
myFile = fopen("fir_output.txt", "a"); // Text file name |
|
|
if (c == 0) |
{ |
fprintf(myFile, "CLK \t MU-AD \t \t \t DL-AD \t \t \t AD-DL \t \n"); |
fprintf(myFile, "-------------------------------------------------------------------------\n"); |
for (unsigned int i = 0; i < count; i++) |
{ |
fprintf(myFile, "%d \t multi_add[%d] \t %d \t delay_add[%d] \t %d \t add_delay[%d] \t %d \n", c, i, _multi_add[i].read().to_int(), i, _delay_add[i].read().to_int(), i, _add_delay[i].read().to_int()); |
} |
} |
else |
{ |
for (unsigned int i = 0; i < count; i++) |
{ |
fprintf(myFile, "%d \t multi_add[%d] \t %d \t delay_add[%d] \t %d \t add_delay[%d] \t %d \n", c, i, _multi_add[i].read().to_int(), i, _delay_add[i].read().to_int(), i, _add_delay[i].read().to_int()); |
} |
} |
|
fprintf(myFile, "\n"); |
|
fclose(myFile); |
} |
|
SC_MODULE(firTF) |
{ |
// Entity Ports |
sc_in<bool > fir_clr; // RESET |
sc_in<bool > fir_clk; // CLOCK |
sc_in<sc_uint<1> > fir_in; // INPUT |
sc_out<sc_int<15> > fir_out; // OUTPUT |
|
// Internal Signals |
sc_signal<sc_int<15> > multi_add[order]; // multiplier's output |
sc_signal<sc_int<15> > add_delay[order]; // adder's output and delay's input |
sc_signal<sc_int<15> > delay_add[order]; // delay's output and adder's input |
|
// Constructor Process Sensitivity |
SC_CTOR(firTF) |
{ |
// combinational, not clocked |
SC_METHOD(multipliers); |
sensitive << fir_in; |
|
fir_out.initialize(0); |
|
SC_METHOD(delays); |
sensitive << fir_clk.pos() ; |
|
// combinationl |
SC_METHOD(adders); |
for (unsigned int i = 0; i< order; i++) |
{ |
sensitive << multi_add[i]; |
sensitive << delay_add[i]; |
} |
|
SC_METHOD(output) |
sensitive << add_delay[0]; |
} |
|
void multipliers() |
{ |
// Filter Coefficients |
static const sc_int<12> fir_coeff[order] = {-51,25,128,77,-203,-372,70,1122,2047,2047,1122,70,-372,-203,77,128,25,-51}; |
|
// COEFFMULTIs |
for (unsigned int i = 0; i < order; i++) |
{ |
{ |
multi_add[i].write(fir_in.read() * fir_coeff[i]); |
} |
} |
} |
|
void delays() |
{ |
// COEFFDELAY |
for (unsigned int i = 0; i < order-1; i++) |
{ |
delay_add[i].write(add_delay[i+1].read()); |
} |
} |
|
void adders() |
{ |
// COEFFADD |
for (unsigned int i = 0; i < order; i++) |
{ |
if (i < order-1) |
{ |
add_delay[i].write(multi_add[i].read() + delay_add[i].read()); |
} |
else |
{ |
add_delay[i].write(multi_add[i].read()); |
} |
} |
} |
|
void output() |
{ |
// Internal variables |
static unsigned int clkCount = 0; |
|
// Output assignment |
fir_out.write(add_delay[0].read()); |
|
// Exporting data into text file |
text(multi_add, delay_add, add_delay, order, clkCount); |
clkCount++; |
} |
|
}; |
/trunk/sc/sc.tcl
0,0 → 1,4
g++ -I$SYSTEMC_HOME/include -L$SYSTEMC_HOME/lib-linux firTF.cpp -lsystemc -o firTF.o |
./firTF.o |
gtkwave wave.vcd & |
gedit fir_output.txt & |
/trunk/sc/firTF.o
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
trunk/sc/firTF.o
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/sc/firTF.cpp
===================================================================
--- trunk/sc/firTF.cpp (nonexistent)
+++ trunk/sc/firTF.cpp (revision 3)
@@ -0,0 +1,53 @@
+#include "systemc.h" // for systemc
+#include // for io interfacing with c
+#include // for executing linux command within c code
+#include "firTF.h"
+#include "stimuli.h"
+
+int sc_main(int argc, char* argv[])
+{
+ // Testing Internal Signal
+ sc_clock fir_clk("fir_clk", 10, SC_NS); // CLOCK
+ sc_signal fir_clr; // RESET
+ sc_signal > fir_in; // INPUT
+ sc_signal > fir_out; // OUTPUT
+
+ firTF DUT("firTF");
+ DUT.fir_clr(fir_clr);
+ DUT.fir_clk(fir_clk);
+ DUT.fir_in(fir_in);
+ DUT.fir_out(fir_out);
+
+ stimuli inputVector("stimuli");
+ inputVector.clr(fir_clr);
+ inputVector.clk(fir_clk);
+ inputVector.streamout(fir_in);
+
+ sc_trace_file *fp;
+ fp = sc_create_vcd_trace_file("wave");
+ fp -> set_time_unit(100, SC_PS);
+
+ sc_trace(fp, fir_clr, "fir_clr");
+ sc_trace(fp, fir_clk, "fir_clk");
+ sc_trace(fp, fir_in, "fir_in");
+ sc_trace(fp, fir_out, "fir_out");
+ //sc_trace(fp, DUT.multi_add[0], "multi_add[0]");
+ //sc_trace(fp, DUT.multi_add[1], "multi_add[1]");
+ //sc_trace(fp, DUT.multi_add[2], "multi_add[2]");
+ //sc_trace(fp, DUT.add_delay[0], "add_delay[0]");
+ //sc_trace(fp, DUT.add_delay[1], "add_delay[1]");
+ //sc_trace(fp, DUT.delay_add[0], "delay_add[0]");
+ //sc_trace(fp, DUT.delay_add[1], "delay_add[1]");
+
+ fir_clr = true;
+ sc_start(20, SC_NS);
+ fir_clr = false;
+ sc_start(410, SC_NS);
+
+ sc_close_vcd_trace_file(fp);
+
+ //system("more fir_output.txt");
+ //system("rm fir_output.txt");
+
+ return 0;
+}
Index: trunk/sc/myfile.dat
===================================================================
--- trunk/sc/myfile.dat (nonexistent)
+++ trunk/sc/myfile.dat (revision 3)
@@ -0,0 +1,40 @@
+1
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
Index: trunk/sc/stimuli.h
===================================================================
--- trunk/sc/stimuli.h (nonexistent)
+++ trunk/sc/stimuli.h (revision 3)
@@ -0,0 +1,80 @@
+#include "systemc.h"
+#include
+#include
+
+#define textLength 40 //The length of the bit-stream in the stimuli file
+
+/** This function read in a text file into a local variable and export it
+ in array format */
+int* ReafFileData()
+{
+ int *values = new int[textLength];
+ int numValuesRead = 0;
+
+ // open the file
+ FILE* pFile = fopen("myfile.dat","r+t");
+
+ while( ! feof( pFile ) )
+ {
+ int currentInt = 0;
+ fscanf( pFile, "%d", ¤tInt);
+ values[numValuesRead] = currentInt ;
+ numValuesRead++;
+ }
+
+ fclose(pFile);
+
+ return values;
+
+ delete pFile;
+}
+
+/** Read in the text file using the developed previous function
+ and store the content into the arry called data */
+static int *data = ReafFileData();
+
+/** This module/block start reading the data from the array data
+ when the clear signal is set to zero and at each rising edge of the clock */
+SC_MODULE(stimuli) {
+ // Input and Output Ports
+ sc_in_clk clk;
+ sc_in clr;
+ sc_out > streamout;
+
+ // Internal variable
+ unsigned int count;
+
+ // Constructor
+ SC_CTOR(stimuli)
+ {
+ SC_METHOD(bitstream);
+ sensitive << clr << clk.pos();
+ }
+
+ // Process
+ void bitstream()
+ {
+ if (clr == true)
+ {
+ count = 0;
+ streamout.write(0);
+ }
+ else
+ {
+ if (clk.posedge())
+ {
+ if (count < textLength)
+ {
+ streamout.write(data[count]);
+ count = count + 1;
+ }
+ else
+ {
+ count = 0;
+ }
+ }
+ }
+ }
+
+
+};