Skip to content

Commit 450dd04

Browse files
committed
Add Unification module and tb (not compiled locally yet)
1 parent cd37879 commit 450dd04

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//-----------------------------------------------------
2+
//Module: Unification (PV)
3+
//By: Roger Morales Monge
4+
//Description: Programmer's View Model of unification
5+
//process for two pixel values (magnitude)
6+
//-----------------------------------------------------
7+
#include "systemc.h"
8+
#include "math.h"
9+
10+
//NORM SELECTION MACROS
11+
//#define USE_L1_NORM
12+
#define USE_L2_NORM //default
13+
//#define USE_INF_NORM
14+
15+
SC_MODULE (unification_module) {
16+
17+
//-----------Internal variables-------------------
18+
int x, y;
19+
int *magnitude;
20+
21+
//-----------Constructor-------------------
22+
SC_CTOR(unification_module) {
23+
} // End of Constructor
24+
25+
//------------Code Starts Here-------------------------
26+
void unificate(int x, int y, int* magnitude) {
27+
this->x = x;
28+
this->y = y;
29+
this->magnitude = magnitude;
30+
31+
//Get the Norm
32+
*(this->magnitude) = norm(this->x, this->y);
33+
34+
//Values are 1byte -> 0 to 255
35+
*(this->magnitude) = min(255,*(this->magnitude));
36+
}
37+
38+
int norm(int a, int b) {
39+
int norm_result = 0;
40+
41+
//L1 Norm
42+
#ifdef USE_L1_NORM
43+
norm_result = abs(a) + abs(b);
44+
#endif
45+
46+
//L2 Norm
47+
#ifdef USE_L2_NORM
48+
norm_result = sqrt(pow(a, 2) + pow(b, 2));
49+
#endif
50+
51+
//INFINITY Norm
52+
#ifdef USE_INF_NORM
53+
norm_result = max(a, b);
54+
#endif
55+
56+
return norm_result;
57+
}
58+
59+
//maximum and minimum functions
60+
int max(int a, int b){
61+
return (a > b ? a : b);
62+
}
63+
int min(int a, int b){
64+
return (a < b ? a : b);
65+
}
66+
};
67+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//--------------------------------------------------------
2+
//Testbench: Unification
3+
//By: Roger Morales Monge
4+
//Description: Simple TB for pixel unification modules
5+
//--------------------------------------------------------
6+
#include <systemc.h>
7+
#include "unification_pv_model.cpp"
8+
//#include "unification_lt_model.cpp"
9+
//#include "unification_at_model.cpp"
10+
11+
12+
int sc_main (int argc, char* argv[]) {
13+
14+
int pixel_x, pixel_y;
15+
int pixel_magnitude;
16+
17+
unification_module unification_U1 ("unification_U1");
18+
19+
// Open VCD file
20+
sc_trace_file *wf = sc_create_vcd_trace_file("unification_U1");
21+
wf->set_time_unit(1, SC_NS);
22+
23+
// Dump the desired signals
24+
sc_trace(wf, pixel_x, "pixel_x");
25+
sc_trace(wf, pixel_y, "pixel_y");
26+
sc_trace(wf, pixel_magnitude, "pixel_magnitude");
27+
28+
sc_start();
29+
cout << "@" << sc_time_stamp()<< endl;
30+
31+
printf("Writing in zero time\n");
32+
33+
pixel_x = 212;
34+
pixel_y = 95;
35+
printf("Operands: pixel_x = %0d, pixel_y = %0d\n", pixel_x, pixel_y);
36+
unification_U1.unificate(pixel_x, pixel_y, &pixel_magnitude);
37+
printf("RESULT: pixel_magnitude = %d\n", pixel_magnitude);
38+
39+
//FIXME: ADD more cases here -> img
40+
41+
cout << "@" << sc_time_stamp() <<" Terminating simulation\n" << endl;
42+
sc_close_vcd_trace_file(wf);
43+
return 0;// Terminate simulation
44+
45+
}

0 commit comments

Comments
 (0)