Skip to content

Commit 1941cbd

Browse files
committed
Fix VGA call of run task
1 parent a8d0397 commit 1941cbd

File tree

5 files changed

+78
-31
lines changed

5 files changed

+78
-31
lines changed

modules/router/include/vga_tlm.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ struct vga_tlm
3333
IPS_V_ACTIVE, IPS_V_FP, IPS_V_SYNC_PULSE, IPS_V_BP>((std::string(name) + "_HW_block").c_str()),
3434
img_target((std::string(name) + "_target").c_str())
3535
{
36+
#ifdef DISABLE_VGA_DEBUG
37+
this->use_prints = false;
38+
#endif // DISABLE_VGA_DEBUG
39+
checkprintenableimgtar(use_prints);
3640
}
3741

3842
// Override do_when_transaction functions

modules/router/run_all.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ case $1 in
55
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 all > output.log
66
;;
77
"save_log_no_dbg")
8-
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_PACKET_GENERATOR_DEBUG=1 DISABLE_TB_DEBUG=1 all > output.log
8+
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_VGA_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_PACKET_GENERATOR_DEBUG=1 DISABLE_TB_DEBUG=1 all > output.log
99
;;
1010
"print_all")
1111
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 print-all
1212
;;
1313
"compile")
14-
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_PACKET_GENERATOR_DEBUG=1 DISABLE_TB_DEBUG=1 compile
14+
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_VGA_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_PACKET_GENERATOR_DEBUG=1 DISABLE_TB_DEBUG=1 compile
1515
;;
1616
"router_tb")
1717
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_ROUTER_TB_EN=1 USING_TLM_TB_EN=1 all > output.log
@@ -20,6 +20,6 @@ case $1 in
2020
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_ROUTER_TB_EN=1 USING_TLM_TB_EN=1 all > output.log
2121
;;
2222
*)
23-
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_PACKET_GENERATOR_DEBUG=1 DISABLE_TB_DEBUG=1 all
23+
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_VGA_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_PACKET_GENERATOR_DEBUG=1 DISABLE_TB_DEBUG=1 all
2424
;;
2525
esac

modules/router/src/tb_edge_detector_tlm.cpp

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ SC_MODULE(Tb_top)
257257

258258
signed char* compression_results;
259259

260-
colorImage = imread("../../tools/datagen/src/imgs/car_rgb_noisy_image.jpg", IMREAD_UNCHANGED);
260+
/*colorImage = imread("../../tools/datagen/src/imgs/car_rgb_noisy_image.jpg", IMREAD_UNCHANGED);
261261
262262
if (colorImage.empty())
263263
{
@@ -315,36 +315,62 @@ SC_MODULE(Tb_top)
315315
}
316316
}
317317
318-
dbgprint("Saved image in memory");
318+
dbgprint("Saved image in memory");*/
319319

320-
dbgprint("Starting VGA to receive image");
321-
322-
unsigned char *vga_start = new unsigned char;
323-
*vga_start = 1;
324-
tb_initiator->write(vga_start, IMG_INPUT_START_ADDRESS_LO, sizeof(char));
325-
326-
for (int i = 0; i < IPS_TOTAL_VERTICAL; ++i)
327-
{
328-
for (int j = 0; j < IPS_TOTAL_HORIZONTAL; ++j)
329-
{
330-
this->vga_DUT->run();
331-
// Wait 40ns for conversions
332-
}
333-
}
334-
335-
dbgprint("Ending VGA");
336-
337320
Mat grayImagePrevMem(IMAG_ROWS, IMAG_COLS, CV_8UC1);
338321
Mat filteredImagePrevMem(IMAG_ROWS, IMAG_COLS, CV_8UC1);
339322
Mat detectedImagePrevMemX(IMAG_ROWS, IMAG_COLS, CV_8UC1);
340323
Mat detectedImagePrevMemY(IMAG_ROWS, IMAG_COLS, CV_8UC1);
341324
Mat detectedImagePrevMem(IMAG_ROWS, IMAG_COLS, CV_8UC1);
342325

326+
Mat originalImageAfterMem(IMAG_ROWS, IMAG_COLS, CV_8UC3);
343327
Mat grayImageAfterMem(IMAG_ROWS, IMAG_COLS, CV_8UC1);
344328
Mat filteredImageAfterMem(IMAG_ROWS, IMAG_COLS, CV_8UC1);
345329
Mat detectedImageAfterMemX(IMAG_ROWS, IMAG_COLS, CV_8UC1);
346330
Mat detectedImageAfterMemY(IMAG_ROWS, IMAG_COLS, CV_8UC1);
347331
Mat detectedImageAfterMem(IMAG_ROWS, IMAG_COLS, CV_8UC1);
332+
333+
dbgprint("Starting VGA to receive image");
334+
335+
unsigned char *vga_start = new unsigned char;
336+
unsigned char *vga_done;
337+
*vga_start = 1;
338+
tb_initiator->write(vga_start, IMG_INPUT_START_ADDRESS_LO, sizeof(char));
339+
340+
// for (int i = 0; i < IPS_TOTAL_VERTICAL; ++i)
341+
// {
342+
// for (int j = 0; j < IPS_TOTAL_HORIZONTAL; ++j)
343+
// {
344+
// // this->vga_DUT->run();
345+
// // Wait 40ns for conversions
346+
347+
// }
348+
// }
349+
tb_initiator->read(vga_done, IMG_INPUT_DONE_ADDRESS_LO, sizeof(char));
350+
while (*vga_done == 0)
351+
{
352+
delete[] vga_done;
353+
wait(10, SC_US);
354+
tb_initiator->read(vga_done, IMG_INPUT_DONE_ADDRESS_LO, sizeof(char));
355+
}
356+
delete[] vga_done;
357+
358+
dbgprint("Ending VGA");
359+
360+
tb_initiator->read(local_results, IMG_INPUT_ADDRESS_LO, IMAG_ROWS * IMAG_COLS * 3);
361+
362+
// Sanity check that the image was written in memory as expected
363+
for (int i = 0; i < IMAG_ROWS; i++)
364+
{
365+
for (int j = 0; j < IMAG_COLS; j++)
366+
{
367+
originalImageAfterMem.at<cv::Vec3b>(i, j)[2] = local_results[(i * IMAG_COLS * 3) + (j * 3) + 2];
368+
originalImageAfterMem.at<cv::Vec3b>(i, j)[1] = local_results[(i * IMAG_COLS * 3) + (j * 3) + 1];
369+
originalImageAfterMem.at<cv::Vec3b>(i, j)[0] = local_results[(i * IMAG_COLS * 3) + (j * 3) ];
370+
}
371+
}
372+
373+
/*
348374
349375
total_number_of_pixels = IMAG_ROWS * IMAG_COLS;
350376
@@ -818,7 +844,10 @@ SC_MODULE(Tb_top)
818844
}
819845
820846
dbgprint("Finished with the transmision of the image");
847+
*/
821848

849+
imwrite("originalImageAfterMem.jpg", originalImageAfterMem);
850+
/*
822851
imwrite("grayImagePrevMem.jpg", grayImagePrevMem);
823852
imwrite("grayImageAfterMem.jpg", grayImageAfterMem);
824853
imwrite("filteredImagePrevMem.jpg", filteredImagePrevMem);
@@ -828,7 +857,7 @@ SC_MODULE(Tb_top)
828857
imwrite("detectedImagePrevMemY.jpg", detectedImagePrevMemY);
829858
imwrite("detectedImageAfterMemY.jpg", detectedImageAfterMemY);
830859
imwrite("detectedImagePrevMem.jpg", detectedImagePrevMem);
831-
imwrite("detectedImageAfterMem.jpg", detectedImageAfterMem);
860+
imwrite("detectedImageAfterMem.jpg", detectedImageAfterMem);*/
832861

833862
sc_stop();
834863
}

modules/router/src/vga_tlm.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ void vga_tlm::do_when_read_transaction(unsigned char *&data, unsigned int data_l
1313
else
1414
{
1515
*data = 0;
16+
dbgimgtarmodprint(true, "VGA is still in progress");
1617
}
1718
}
1819
else if ((address >= IMG_INPUT_ADDRESS_LO) && (address < IMG_INPUT_ADDRESS_HI))
1920
{
20-
if (vga::done == true)
21-
{
22-
memcpy(data, vga::tmp_img, IMG_INPUT_SIZE);
23-
}
21+
memcpy(data, (vga::tmp_img + address - IMG_INPUT_ADDRESS_LOW), data_length);
2422
}
2523
}
2624

@@ -31,5 +29,6 @@ void vga_tlm::do_when_write_transaction(unsigned char *&data, unsigned int data_
3129
if ((address >= IMG_INPUT_START_ADDRESS_LO) && (address < IMG_INPUT_START_ADDRESS_HI))
3230
{
3331
vga::start = (*data == 1);
32+
vga::done = !vga::start;
3433
}
3534
}

modules/vga/include/vga.hpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#define IPS_VGA_ACTIVE true
1010
#define IPS_VGA_INACTIVE false
1111

12+
// Main clock frequency in Hz - 25.175 MHz
13+
#define CLK_FREQ 25175000
14+
1215
/**
1316
* @brief VGA representation class
1417
*
@@ -48,6 +51,11 @@ SC_MODULE(vga)
4851
#ifndef USING_TLM_TB_EN
4952
// Input clock
5053
sc_core::sc_in<bool> clk;
54+
#else
55+
// Compute the clock time in seconds
56+
const double CLK_TIME = 1.0 / static_cast<double>(CLK_FREQ);
57+
// Internal clock
58+
sc_core::sc_clock clk;
5159
#endif // USING_TLM_TB_EN
5260
// Input pixel
5361
sc_core::sc_in<sc_uint<BITS> > red;
@@ -73,14 +81,18 @@ SC_MODULE(vga)
7381

7482
SC_CTOR(vga)
7583
: o_hsync("o_hsync"), o_vsync("o_vsync")
84+
#ifdef USING_TLM_TB_EN
85+
, clk("clk", CLK_TIME, sc_core::SC_SEC)
86+
#endif
7687
{
7788
this->h_count = 0;
7889
this->v_count = 0;
7990

80-
#ifndef USING_TLM_TB_EN
8191
SC_METHOD(run);
92+
#ifndef USING_TLM_TB_EN
8293
sensitive << clk.pos();
8394
#else
95+
sensitive << clk;
8496
this->tmp_img = new unsigned char[H_ACTIVE * V_ACTIVE * 3];
8597
this->start = false;
8698
this->done = false;
@@ -94,12 +106,12 @@ SC_MODULE(vga)
94106
*/
95107
void run()
96108
{
97-
#ifndef USING_TLM_TB_EN
98109
if (this->clk.read())
99-
#else
110+
{
111+
#ifdef USING_TLM_TB_EN
100112
if (this->start)
101-
#endif // USING_TLM_TB_EN
102113
{
114+
#endif // USING_TLM_TB_EN
103115
#ifdef IPS_DEBUG_EN
104116
std::cout << "@" << sc_core::sc_time_stamp().to_seconds() * 1e6 << "us" << std::endl;
105117
#endif // IPS_DEBUG_EN
@@ -150,6 +162,8 @@ SC_MODULE(vga)
150162
{
151163
this->o_vsync.write(IPS_VGA_INACTIVE);
152164
this->v_count = 0;
165+
this->done = true;
166+
this->start = false;
153167
}
154168
}
155169

@@ -171,6 +185,7 @@ SC_MODULE(vga)
171185
this->tmp_img[INDEX + 1] = this->green.read();
172186
this->tmp_img[INDEX + 2] = this->blue.read();
173187
}
188+
}
174189
#endif // USING_TLM_TB_EN
175190
}
176191
}

0 commit comments

Comments
 (0)