Skip to content

Commit a4c31a9

Browse files
jgavillalobosErickOF
authored andcommitted
Copy work from communication module
1 parent 1f37f25 commit a4c31a9

10 files changed

+1093
-0
lines changed

modules/router/Makefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Include common Makefile
2+
include ../Makefile
3+
4+
# Defining preprocessor directive for debug
5+
ifdef IPS_DEBUG_EN
6+
CFLAGS += -DIPS_DEBUG_EN
7+
LFLAGS += -DIPS_DEBUG_EN
8+
endif # IPS_DEBUG_EN
9+
10+
# Defining preprocessor directive for dumping enable
11+
ifdef IPS_DUMP_EN
12+
CFLAGS += -DIPS_DUMP_EN
13+
LFLAGS += -DIPS_DUMP_EN
14+
endif # IPS_DUMP_EN
15+
16+
# Defining preprocessor directive for normalizing the resulting magnitude
17+
ifdef TEST_NORMALIZE_MAGNITUDE
18+
CFLAGS += -DTEST_NORMALIZE_MAGNITUDE
19+
LFLAGS += -DTEST_NORMALIZE_MAGNITUDE
20+
endif # TEST_NORMALIZE_MAGNITUDE
21+
22+
# Defining preprocessor directive for using PV model
23+
ifdef EDGE_DETECTOR_PV_EN
24+
CFLAGS += -DEDGE_DETECTOR_PV_EN
25+
LFLAGS += -DEDGE_DETECTOR_PV_EN
26+
endif # EDGE_DETECTOR_PV_EN
27+
28+
# Defining preprocessor directive for using PV model
29+
ifdef EDGE_DETECTOR_LT_EN
30+
CFLAGS += -DEDGE_DETECTOR_LT_EN
31+
LFLAGS += -DEDGE_DETECTOR_LT_EN
32+
endif # EDGE_DETECTOR_LT_EN
33+
34+
# Defining preprocessor directive for using PV model
35+
ifdef EDGE_DETECTOR_AT_EN
36+
CFLAGS += -DEDGE_DETECTOR_AT_EN
37+
LFLAGS += -DEDGE_DETECTOR_AT_EN
38+
endif # EDGE_DETECTOR_AT_EN
39+
40+
# Run the compiled file
41+
run:
42+
@./test
43+
44+
# Show waveform
45+
waveform:
46+
@gtkwave edge_detector.vcd

modules/router/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# **Communication Module**
2+
3+
Add compilation instructions
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifdef EDGE_DETECTOR_LT_EN
2+
#ifndef SOBEL_EDGE_DETECTOR_HPP
3+
#define SOBEL_EDGE_DETECTOR_HPP
4+
5+
#include <systemc.h>
6+
7+
SC_MODULE(Edge_Detector)
8+
{
9+
10+
int localWindow[3][3];
11+
12+
const int sobelGradientX[3][3] = {{-1, 0, 1},
13+
{-2, 0, 2},
14+
{-1, 0, 1}};
15+
const int sobelGradientY[3][3] = {{-1, -2, -1},
16+
{ 0, 0, 0},
17+
{ 1, 2, 1}};
18+
19+
int resultSobelGradientX;
20+
int resultSobelGradientY;
21+
22+
sc_event gotLocalWindow, finishedSobelGradientX, finishedSobelGradientY;
23+
24+
SC_CTOR(Edge_Detector)
25+
{
26+
SC_THREAD(compute_sobel_gradient_x);
27+
SC_THREAD(compute_sobel_gradient_y);
28+
}
29+
30+
void set_local_window(int window[3][3]);
31+
32+
void compute_sobel_gradient_x();
33+
34+
void compute_sobel_gradient_y();
35+
36+
int obtain_sobel_gradient_x();
37+
38+
int obtain_sobel_gradient_y();
39+
40+
};
41+
42+
#endif // SOBEL_EDGE_DETECTOR_HPP
43+
#endif // EDGE_DETECTOR_LT_EN
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef SOBEL_EDGE_DETECTOR_TLM_HPP
2+
#define SOBEL_EDGE_DETECTOR_TLM_HPP
3+
#include "systemc.h"
4+
using namespace sc_core;
5+
using namespace sc_dt;
6+
using namespace std;
7+
8+
#include "tlm.h"
9+
#include "tlm_utils/simple_initiator_socket.h"
10+
#include "tlm_utils/simple_target_socket.h"
11+
#include "tlm_utils/peq_with_cb_and_phase.h"
12+
13+
#include "sobel_edge_detector_lt_model.hpp"
14+
#include "../src/img_target.cpp"
15+
16+
//Extended Unification TLM
17+
struct sobel_edge_detector_tlm : public Edge_Detector, public img_target
18+
{
19+
20+
SC_CTOR(sobel_edge_detector_tlm): Edge_Detector(Edge_Detector::name()), img_target(img_target::name()) {
21+
}
22+
23+
//Override do_when_transaction functions
24+
virtual void do_when_read_transaction(unsigned char*& data);
25+
virtual void do_when_write_transaction(unsigned char*& data);
26+
27+
};
28+
#endif
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
2+
3+
#ifndef IMG_INITIATOR_CPP
4+
#define IMG_INITIATOR_CPP
5+
6+
// #include "tlm_transaction.cpp"
7+
#include "transaction_memory_manager.cpp"
8+
9+
#include "systemc.h"
10+
using namespace sc_core;
11+
using namespace sc_dt;
12+
using namespace std;
13+
14+
#include "tlm.h"
15+
#include "tlm_utils/simple_initiator_socket.h"
16+
#include "tlm_utils/simple_target_socket.h"
17+
#include "tlm_utils/peq_with_cb_and_phase.h"
18+
19+
//const char* tlm_enum_names[] = {"TLM_ACCEPTED", "TLM_UPDATED", "TLM_COMPLETED"};
20+
21+
// Initiator module generating generic payload transactions
22+
struct img_initiator: sc_module
23+
{
24+
// TLM2.0 Socket
25+
tlm_utils::simple_initiator_socket<img_initiator> socket;
26+
27+
//Memory Manager for transaction memory allocation
28+
mm memory_manager;
29+
30+
//Address for this Initiator
31+
unsigned int address;
32+
unsigned char* data;
33+
unsigned int data_length;
34+
35+
//Pointer to transaction in progress
36+
tlm::tlm_generic_payload* pending_transaction;
37+
38+
//Payload event queue with callback and phase
39+
tlm_utils::peq_with_cb_and_phase<img_initiator> m_peq;
40+
41+
//Events
42+
sc_event transaction_received_e;
43+
44+
//Delay
45+
sc_time write_delay = sc_time(10, SC_NS);
46+
sc_time read_delay = sc_time(10,SC_NS);
47+
48+
//Constructor
49+
SC_CTOR(img_initiator)
50+
: socket("socket"), pending_transaction(0), m_peq(this, &img_initiator::peq_cb) // Construct and name socket
51+
{
52+
// Register callbacks for incoming interface method calls
53+
socket.register_nb_transport_bw(this, &img_initiator::nb_transport_bw);
54+
}
55+
56+
//Method to send_reading transaction and wait for response
57+
void read (int*& data, unsigned int address, unsigned int data_length){
58+
59+
//Create transaction and allocate it
60+
tlm::tlm_generic_payload* transaction = memory_manager.allocate();
61+
62+
//Set transaction fields
63+
transaction->set_command(tlm::TLM_READ_COMMAND);
64+
transaction->set_address(address);
65+
transaction->set_data_ptr(reinterpret_cast<unsigned char*>(data));
66+
transaction->set_data_length(data_length); //In Bytes
67+
transaction->set_streaming_width(data_length);
68+
transaction->set_byte_enable_ptr(0);
69+
transaction->set_dmi_allowed(false); //Mandatory Initial Value
70+
transaction->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); //Mandatory Initial Value
71+
72+
//Send transaction
73+
this->send_transaction(transaction);
74+
75+
data = reinterpret_cast<int*>(this->data);
76+
//-----------DEBUG-----------
77+
printf("[DEBUG] Reading at Initiator: ");
78+
for (int i = 0; i < this->pending_transaction->get_data_length()/sizeof(int); ++i){
79+
printf("%02x", *(reinterpret_cast<int*>(this->data)+i));
80+
}
81+
printf("\n");
82+
//-----------DEBUG-----------
83+
}
84+
85+
void write (int*& data, unsigned int address, unsigned int data_length){
86+
87+
//Create transaction and allocate it
88+
tlm::tlm_generic_payload* transaction = memory_manager.allocate();
89+
90+
//Set transaction fields
91+
transaction->set_command(tlm::TLM_WRITE_COMMAND);
92+
transaction->set_address(address);
93+
transaction->set_data_ptr(reinterpret_cast<unsigned char*>(data));
94+
transaction->set_data_length(data_length); //In Bytes
95+
transaction->set_streaming_width(data_length);
96+
transaction->set_byte_enable_ptr(0);
97+
transaction->set_dmi_allowed(false); //Mandatory Initial Value
98+
transaction->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); //Mandatory Initial Value
99+
100+
//-----------DEBUG-----------
101+
printf("[DEBUG] Writing: ");
102+
for (int i = 0; i < data_length/sizeof(int); ++i){
103+
printf("%02x", *(data+i));
104+
}
105+
printf("\n");
106+
//-----------DEBUG-----------
107+
108+
//Set transaction
109+
this->send_transaction(transaction);
110+
}
111+
112+
void send_transaction(tlm::tlm_generic_payload*& transaction) {
113+
114+
//Transaction Management Variables
115+
tlm::tlm_phase phase;
116+
tlm::tlm_sync_enum status;
117+
118+
//Begin Request
119+
phase = tlm::BEGIN_REQ;
120+
transaction->acquire();
121+
cout << name() << " BEGIN_REQ SENT" << " TRANS ID " << 0 << " at time " << sc_time_stamp() << endl;
122+
pending_transaction = transaction;
123+
status = socket->nb_transport_fw(*transaction, phase, this->write_delay); // Non-blocking transport call
124+
125+
// Check request status returned by target
126+
switch (status) {
127+
//Case 1: Transaction was accepted
128+
case tlm::TLM_ACCEPTED: {
129+
printf("%s:\t %s received -> Transaction ID %d at time %s\n", name(), "TLM_ACCEPTED", 0, sc_time_stamp());
130+
//cout << name() << " TLM_ACCEPTED RECEIVED " << " TRANS ID " << transaction->transaction_id << " at time " << sc_time_stamp() << endl;
131+
check_transaction(*transaction);
132+
transaction->release();
133+
pending_transaction = 0;
134+
//Initiator only cares about sending the transaction, doesnt need to wait for response (non-blocking)
135+
break;
136+
}
137+
138+
//Not implementing Updated and Completed Status
139+
default: {
140+
printf("%s:\t [ERROR] Invalid status received at initiator", name());
141+
break;
142+
}
143+
}
144+
145+
//Wait for response transaction
146+
wait(transaction_received_e);
147+
//-----------DEBUG-----------
148+
printf("[DEBUG1] Reading at Initiator: ");
149+
for (int i = 0; i < this->data_length/sizeof(int); ++i){
150+
printf("%02x", *(reinterpret_cast<int*>(this->data)+i));
151+
}
152+
printf("\n");
153+
//-----------DEBUG-----------
154+
155+
//Increment transaction ID
156+
}
157+
158+
159+
// TLM2 backward path non-blocking transport method
160+
virtual tlm::tlm_sync_enum nb_transport_bw(tlm::tlm_generic_payload& trans,
161+
tlm::tlm_phase& phase, sc_time& delay )
162+
{
163+
//Call event queue
164+
m_peq.notify(trans, phase, delay);
165+
cout<<"HERE"<<endl;
166+
return tlm::TLM_ACCEPTED;
167+
}
168+
169+
//Payload event and queue callback to handle transactions received from target
170+
void peq_cb(tlm::tlm_generic_payload& trans, const tlm::tlm_phase& phase)
171+
{
172+
173+
//printf("%s:\t %s received -> Transaction ID %d from address %x at time %s\n", name(), phase, this->id_extension->transaction_id, trans.get_address(), sc_time_stamp());
174+
//cout << name() << " " <<hex << trans.get_address() << " BEGIN_RESP RECEIVED at " << sc_time_stamp() << endl;
175+
switch (phase) {
176+
case tlm::BEGIN_RESP: {
177+
178+
cout<<"HERE3"<<endl;
179+
180+
trans.acquire();
181+
this->data_length = trans.get_data_length();
182+
this->data = new unsigned char[this->data_length];
183+
memcpy(this->data, trans.get_data_ptr(), this->data_length);
184+
185+
this->pending_transaction = &trans; //Set response transaction to return
186+
check_transaction(trans);
187+
188+
//Initiator dont care about confirming resp transaction. So nothing else to do.
189+
190+
//-----------DEBUG-----------
191+
printf("[DEBUG] Reading at Initiator: ");
192+
for (int i = 0; i < trans.get_data_length()/sizeof(int); ++i){
193+
printf("%02x", *(reinterpret_cast<int*>(trans.get_data_ptr())+i));
194+
}
195+
printf("\n");
196+
//-----------DEBUG-----------
197+
198+
cout<<"HERE3"<<endl;
199+
200+
transaction_received_e.notify();
201+
//-----------DEBUG-----------
202+
printf("[DEBUG] Reading at Initiator: ");
203+
for (int i = 0; i < this->data_length/sizeof(int); ++i){
204+
printf("%02x", *(reinterpret_cast<int*>(this->data)+i));
205+
}
206+
printf("\n");
207+
//-----------DEBUG-----------
208+
cout<<"HERE10"<<endl;
209+
break;
210+
}
211+
default: {
212+
SC_REPORT_FATAL("TLM-2", "Illegal transaction phase received by initiator");
213+
break;
214+
}
215+
}
216+
}
217+
218+
//Function to check transaction integrity
219+
void check_transaction(tlm::tlm_generic_payload& trans)
220+
{
221+
//Check transaction if here
222+
223+
// tlm::tlm_command command = trans.get_command();
224+
// sc_dt::uint64 address = trans.get_address();
225+
// unsigned char* data_ptr = reinterpret_cast<unsigned char*>(trans.get_data_ptr());
226+
227+
// Allow the memory manager to free the transaction object
228+
//trans.release();
229+
}
230+
} ;
231+
232+
#endif

0 commit comments

Comments
 (0)