@@ -29,9 +29,10 @@ using namespace std;
2929#include " ImportantDefines.h"
3030
3131#include " memory_tlm.hpp"
32- #include " rgb2gray_tlm .hpp"
32+ #include " rgb2gray_pv_model .hpp"
3333#include " ips_filter_tlm.hpp"
3434#include " sobel_edge_detector_tlm.hpp"
35+ #include " unification_pv_model.hpp"
3536#include " img_initiator.cpp"
3637
3738#if !defined(RGB2GRAY_PV_EN) || !defined(EDGE_DETECTOR_AT_EN)
@@ -47,6 +48,7 @@ SC_MODULE(Tb_top)
4748 memory_tlm *memory_DUT;
4849 img_initiator *filter_initiator;
4950 ips_filter_tlm *filter_DUT;
51+ img_unification_module* unification_DUT;
5052
5153 SC_CTOR (Tb_top)
5254 {
@@ -57,6 +59,7 @@ SC_MODULE(Tb_top)
5759 memory_DUT = new memory_tlm (" memory_DUT" );
5860 filter_initiator = new img_initiator (" filter_initiator" );
5961 filter_DUT = new ips_filter_tlm (" filter_DUT" );
62+ unification_DUT = new img_unification_module (" unification_DUT" );
6063
6164 sobel_initiator->start_img_initiators ();
6265 sobel_initiator->set_delays (sc_time (10 , SC_NS), sc_time (10 , SC_NS));
@@ -83,6 +86,7 @@ SC_MODULE(Tb_top)
8386 unsigned char localR, localG, localB;
8487 unsigned short int localResult;
8588 unsigned char * local_results;
89+ unsigned char * local_read;
8690 int local_count = 0 ;
8791
8892 short int localGradientX, localGradientY;
@@ -178,7 +182,7 @@ SC_MODULE(Tb_top)
178182 rgb2gray_DUT->set_rgb_pixel (localR, localG, localB);
179183 localResult = (unsigned short int )rgb2gray_DUT->obtain_gray_value ();
180184
181- dbgprint (" Data_returned: %0d" , localResult);
185+ dbgprint (" Data_returned gray_result : %0d" , localResult);
182186
183187 grayImagePrevMem.at <uchar>(i, j) = (unsigned char )localResult;
184188
@@ -194,6 +198,7 @@ SC_MODULE(Tb_top)
194198 if (local_count == 8 )
195199 {
196200 dbgprint (" Before doing a write in TB" );
201+ sanity_check_address (IMG_INPROCESS_A + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof (char ))), IMG_INPROCESS_A, IMG_INPROCESS_A + IMG_INPROCESS_A_SZ);
197202 memory_initiator->write (local_results, IMG_INPROCESS_A + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof (char ))), 8 * sizeof (char ));
198203 dbgprint (" After doing a write in TB" );
199204 local_count = 0 ;
@@ -246,7 +251,7 @@ SC_MODULE(Tb_top)
246251 filter_initiator->read (read_ptr, IMG_FILTER_KERNEL, sizeof (IPS_OUT_TYPE_TB));
247252 dbgprint (" After doing a read in TB" );
248253 data_returned_ptr = reinterpret_cast <IPS_OUT_TYPE_TB*>(read_ptr);
249- dbgprint (" Data_returned: %f\n " , *data_returned_ptr);
254+ dbgprint (" Data_returned filtered_result : %f" , *data_returned_ptr);
250255
251256 data_returned = *data_returned_ptr;
252257
@@ -274,6 +279,7 @@ SC_MODULE(Tb_top)
274279 if (local_count == 8 )
275280 {
276281 dbgprint (" Before doing a write in TB" );
282+ sanity_check_address (IMG_COMPRESSED + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof (char ))), IMG_COMPRESSED, IMG_COMPRESSED + IMG_COMPRESSED_SZ);
277283 memory_initiator->write (local_results, IMG_COMPRESSED + ((i * IMAG_COLS) + (local_group_count * 8 * sizeof (char ))), 8 * sizeof (char ));
278284 dbgprint (" After doing a write in TB" );
279285 local_count = 0 ;
@@ -333,8 +339,8 @@ SC_MODULE(Tb_top)
333339 sobel_initiator->read (read_ptr, SOBEL_OUTPUT, 8 * sizeof (char ));
334340 dbgprint (" After doing a read in TB" );
335341 data_returned_ptr = reinterpret_cast <short int *>(read_ptr);
336- dbgprint (" Data_returned: %0d\n " , *data_returned_ptr);
337- dbgprint (" Data_returned: %0d\n " , *(data_returned_ptr+1 ));
342+ dbgprint (" Data_returned localGradientX : %0d" , *data_returned_ptr);
343+ dbgprint (" Data_returned localGradientY : %0d" , *(data_returned_ptr+1 ));
338344
339345 localGradientX = *data_returned_ptr;
340346 localGradientY = *(data_returned_ptr+1 );
@@ -357,16 +363,6 @@ SC_MODULE(Tb_top)
357363 else {
358364 detectedImagePrevMemY.at <uchar>(i, j) = (unsigned char )localGradientY;
359365 }
360-
361- localResult = (unsigned short int )sqrt ((float )(pow (localGradientX, 2 )) + (float )(pow (localGradientY, 2 )));
362- if (localResult > 255 )
363- {
364- detectedImagePrevMem.at <uchar>(i, j) = 255 ;
365- }
366- else
367- {
368- detectedImagePrevMem.at <uchar>(i, j) = (unsigned char )localResult;
369- }
370366
371367 if (local_count == 0 )
372368 {
@@ -381,10 +377,12 @@ SC_MODULE(Tb_top)
381377 {
382378 write_ptr = local_results;
383379 dbgprint (" Before doing a write in TB" );
380+ sanity_check_address (IMG_INPROCESS_B + ((i * IMAG_COLS * sizeof (short int )) + (local_group_count * 4 * sizeof (short int ))), IMG_INPROCESS_B, IMG_INPROCESS_B + IMG_INPROCESS_B_SZ);
384381 memory_initiator->write (write_ptr, IMG_INPROCESS_B + ((i * IMAG_COLS * sizeof (short int )) + (local_group_count * 4 * sizeof (short int ))), 4 * sizeof (short int ));
385382 dbgprint (" After doing a write in TB" );
386383 write_ptr = (local_results + 8 );
387384 dbgprint (" Before doing a write in TB" );
385+ sanity_check_address (IMG_INPROCESS_C + ((i * IMAG_COLS * sizeof (short int )) + (local_group_count * 4 * sizeof (short int ))), IMG_INPROCESS_C, IMG_INPROCESS_C + IMG_INPROCESS_C_SZ);
388386 memory_initiator->write (write_ptr, IMG_INPROCESS_C + ((i * IMAG_COLS * sizeof (short int )) + (local_group_count * 4 * sizeof (short int ))), 4 * sizeof (short int ));
389387 dbgprint (" After doing a write in TB" );
390388 local_count = 0 ;
@@ -435,6 +433,78 @@ SC_MODULE(Tb_top)
435433 }
436434 }
437435
436+ for (int i = 0 ; i < IMAG_ROWS; i++)
437+ {
438+ int local_group_count = 0 ;
439+ for (int j = 0 ; j < IMAG_COLS; j++)
440+ {
441+ unsigned char * read_ptr;
442+ short int * gradients_ptr;
443+ unsigned char unification_result;
444+
445+ if (local_count == 0 )
446+ {
447+ local_read = new unsigned char [16 ];
448+
449+ dbgprint (" Before doing a read in TB" );
450+ memory_initiator->read (read_ptr, IMG_INPROCESS_B + ((i * IMAG_COLS * sizeof (short int )) + (local_group_count * 4 * sizeof (short int ))), 4 * sizeof (short int ));
451+ dbgprint (" After doing a read in TB" );
452+ memcpy ((local_read ), read_ptr, 4 * sizeof (short int ));
453+ dbgprint (" Before doing a read in TB" );
454+ memory_initiator->read (read_ptr, IMG_INPROCESS_C + ((i * IMAG_COLS * sizeof (short int )) + (local_group_count * 4 * sizeof (short int ))), 4 * sizeof (short int ));
455+ dbgprint (" After doing a read in TB" );
456+ memcpy ((local_read + (4 * sizeof (short int ))), read_ptr, 4 * sizeof (short int ));
457+ }
458+
459+ gradients_ptr = reinterpret_cast <short int *>(local_read);
460+ localGradientX = *(gradients_ptr + local_count);
461+ gradients_ptr = reinterpret_cast <short int *>(local_read + (4 * sizeof (short int )));
462+ localGradientY = *(gradients_ptr + local_count);
463+
464+ unification_DUT->unificate_pixel ((int )localGradientX, (int )localGradientY, &unification_result);
465+
466+ dbgprint (" Data_returned unification_result: %0d" , unification_result);
467+
468+ detectedImagePrevMem.at <uchar>(i, j) = unification_result;
469+
470+ if (local_count == 0 )
471+ {
472+ local_results = new unsigned char [4 ];
473+ }
474+
475+ *(local_results + local_count) = unification_result;
476+
477+ local_count++;
478+
479+ if (local_count == 4 )
480+ {
481+ dbgprint (" Before doing a write in TB" );
482+ sanity_check_address (IMG_INPROCESS_A + ((i * IMAG_COLS) + j), IMG_INPROCESS_A, IMG_INPROCESS_A + IMG_INPROCESS_A_SZ);
483+ memory_initiator->write (local_results, IMG_INPROCESS_A + ((i * IMAG_COLS) + (local_group_count * 4 * sizeof (char ))), 4 * sizeof (char ));
484+ dbgprint (" After doing a write in TB" );
485+ local_count = 0 ;
486+ local_group_count++;
487+ }
488+
489+ current_number_of_pixels++;
490+ if (((((float )(current_number_of_pixels)) / ((float )(total_number_of_pixels))) * 100.0 ) >= next_target_of_completion) {
491+ dbgprint (" Image processing completed at %f" , next_target_of_completion);
492+ next_target_of_completion += 10.0 ;
493+ }
494+ }
495+ }
496+
497+ // Sanity check that the image was written in memory as expected
498+ for (int i = 0 ; i < IMAG_ROWS; i++)
499+ {
500+ for (int j = 0 ; j < IMAG_COLS; j++)
501+ {
502+ unsigned char * read_ptr;
503+ memory_DUT->backdoor_read (read_ptr, 1 * sizeof (char ), IMG_INPROCESS_A + ((i * IMAG_COLS) + j));
504+ detectedImageAfterMem.at <uchar>(i, j) = *read_ptr;
505+ }
506+ }
507+
438508 imwrite (" grayImagePrevMem.jpg" , grayImagePrevMem);
439509 imwrite (" grayImageAfterMem.jpg" , grayImageAfterMem);
440510 imwrite (" filteredImagePrevMem.jpg" , filteredImagePrevMem);
@@ -649,6 +719,14 @@ SC_MODULE(Tb_top)
649719 *(local_window_ptr + 8 ) = *(read_ptr + 2 );
650720 }
651721 }
722+
723+ void sanity_check_address (unsigned int address, unsigned int lower_address_limit, unsigned int upper_address_limit)
724+ {
725+ if (((lower_address_limit != 0 ) && (address < lower_address_limit)) || (address > upper_address_limit))
726+ {
727+ SC_REPORT_FATAL (" TB MEM" , " Access to memory crossing boundary" );
728+ }
729+ }
652730};
653731
654732int sc_main (int , char *[])
0 commit comments