Skip to content

Commit a1001fc

Browse files
committed
Add ethernet TLM model to Virtual Prototype
1 parent 499cda3 commit a1001fc

24 files changed

+632
-167
lines changed

modules/VirtualPrototype/FreeRTOS/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ CC = riscv32-unknown-elf-gcc
66

77
# compiling flags here
88
CFLAGS = -Wall -I. -O0 -static -march=rv32gc -mabi=ilp32 --specs=nosys.specs
9-
CFLAGS+=-std=c++17
109

1110
LINKER = riscv32-unknown-elf-gcc
1211
# linking flags here

modules/VirtualPrototype/FreeRTOS/freertos_test.c

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ void obtain_gradients_sobel()
208208
{
209209
for (int j = 0; j < IMAG_COLS; j++)
210210
{
211-
transfer_window(i, j, IMG_COMPRESSED_ADDRESS_LO, SOBEL_INPUT_0_ADDRESS_LO);
211+
transfer_window(i, j, IMG_INPROCESS_D_ADDRESS_LO, SOBEL_INPUT_0_ADDRESS_LO);
212212
memcpy(sobel_results, sobel_output_ptr, 2 * sizeof(short int));
213213
*(output_image_X_ptr + ((i * IMAG_COLS) + j)) = sobel_results[0];
214214
*(output_image_Y_ptr + ((i * IMAG_COLS) + j)) = sobel_results[1];
215215

216216
if (current_progress == next_target * step)
217217
{
218-
printf("Current progress is at %0d%%\n", next_target * 10);
218+
printf("\tCurrent progress is at %0d%%\n", next_target * 10);
219219
next_target++;
220220
}
221221
current_progress++;
@@ -262,7 +262,7 @@ void convert_to_grayscale()
262262

263263
if (current_progress == next_target * step)
264264
{
265-
printf("Current progress is at %0d%%\n", next_target * 10);
265+
printf("\tCurrent progress is at %0d%%\n", next_target * 10);
266266
next_target++;
267267
}
268268
current_progress++;
@@ -275,7 +275,7 @@ void convert_to_grayscale()
275275
void filter_image()
276276
{
277277
unsigned char *filter_output_ptr = (unsigned char*) IMG_FILTER_OUTPUT_ADDRESS_LO;
278-
unsigned char *output_image_ptr = (unsigned char*) IMG_COMPRESSED_ADDRESS_LO;
278+
unsigned char *output_image_ptr = (unsigned char*) IMG_INPROCESS_D_ADDRESS_LO;
279279

280280
int final_target = IMAG_ROWS * IMAG_COLS;
281281
int current_progress = 0;
@@ -293,7 +293,7 @@ void filter_image()
293293

294294
if (current_progress == next_target * step)
295295
{
296-
printf("Current progress is at %0d%%\n", next_target * 10);
296+
printf("\tCurrent progress is at %0d%%\n", next_target * 10);
297297
next_target++;
298298
}
299299
current_progress++;
@@ -358,7 +358,7 @@ void unificate_img()
358358

359359
if (current_progress == next_target * step)
360360
{
361-
printf("Current progress is at %0d%%\n", next_target * 10);
361+
printf("\tCurrent progress is at %0d%%\n", next_target * 10);
362362
next_target++;
363363
}
364364
current_progress++;
@@ -367,14 +367,66 @@ void unificate_img()
367367
printf("Done IMG Unification Step: \n");
368368
}
369369

370+
void transmit_data(unsigned int data_length)
371+
{
372+
unsigned int *data_length_ptr = (unsigned int *) IMG_OUTPUT_SIZE_ADDRESS_LO;
373+
unsigned char *start_transmission = (unsigned char *) IMG_OUTPUT_DONE_ADDRESS_LO;
374+
unsigned char *send_status = (unsigned char *) IMG_OUTPUT_STATUS_ADDRESS_LO;
375+
unsigned char send_status_result;
376+
377+
const TickType_t xDelay = 200;
378+
379+
printf("Preparing to send %0d bytes\n", data_length);
380+
381+
*data_length_ptr = data_length;
382+
*start_transmission = 1;
383+
384+
printf("Sent start signal to transmiter\n");
385+
386+
memcpy(&send_status_result, send_status, sizeof(char));
387+
while(send_status_result == 1)
388+
{
389+
printf("\tTransmiter still sending data\n");
390+
vTaskDelay(xDelay);
391+
memcpy(&send_status_result, send_status, sizeof(char));
392+
}
393+
printf("Send process finished in the transmiter\n");
394+
}
395+
396+
void copy_data()
397+
{
398+
unsigned char *source_img = (unsigned char *) IMG_INPROCESS_A_ADDRESS_LO;
399+
unsigned char *output_img = (unsigned char *) IMG_OUTPUT_ADDRESS_LO;
400+
401+
memcpy(output_img, source_img, IMAG_ROWS * IMAG_COLS);
402+
}
403+
404+
void save_image_from_mem(int image_id)
405+
{
406+
int *img_id_ptr = (int *) IMG_SAVER_ID_ADDRESS_LO;
407+
unsigned char *save_img_ptr = (unsigned char *) IMG_SAVER_START_ADDRESS_LO;
408+
409+
*img_id_ptr = image_id;
410+
*save_img_ptr = 1;
411+
printf("Saved image with id %0d\n", image_id);
412+
}
413+
370414
static void testbench(void *pParameter) {
371-
convert_to_grayscale();
415+
// convert_to_grayscale();
372416

373-
filter_image();
417+
// filter_image();
374418

375-
obtain_gradients_sobel();
419+
// obtain_gradients_sobel();
376420

377421
unificate_img();
422+
423+
save_image_from_mem(4);
424+
425+
copy_data();
426+
427+
save_image_from_mem(5);
428+
429+
transmit_data(IMAG_ROWS * IMAG_COLS);
378430
}
379431

380432
int main( void )

modules/VirtualPrototype/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Include common Makefile
22
include ../Makefile
33

4+
LIBS+=-lsystemc-ams
5+
46
# Defining preprocessor directive for debug
57
ifdef IPS_DEBUG_EN
68
CFLAGS += -DIPS_DEBUG_EN

modules/VirtualPrototype/include/BusCtrl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ class BusCtrl: sc_core::sc_module {
7676
tlm_utils::simple_initiator_socket<BusCtrl> sobel_edge_detector_socket;
7777
tlm_utils::simple_initiator_socket<BusCtrl> receiver_socket; //VGA AMS socket
7878
tlm_utils::simple_initiator_socket<BusCtrl> transmiter_socket; //Ethernet AMS Socket
79+
tlm_utils::simple_initiator_socket<BusCtrl> image_saver_socket; //Component to save the temporal images
7980

8081
/**
8182
* @brief constructor
8283
* @param name module's name
8384
*/
84-
BusCtrl(sc_core::sc_module_name name);
85+
BusCtrl(sc_core::sc_module_name name, bool use_prints);
8586

8687
/**
8788
* @brief TLM-2 blocking mechanism
@@ -97,6 +98,8 @@ class BusCtrl: sc_core::sc_module {
9798
bool instr_direct_mem_ptr(tlm::tlm_generic_payload&,
9899
tlm::tlm_dmi &dmi_data);
99100
void invalidate_direct_mem_ptr(sc_dt::uint64 start, sc_dt::uint64 end);
101+
102+
bool use_prints;
100103
};
101104

102105
#endif

modules/VirtualPrototype/include/Memory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class Memory: sc_core::sc_module {
6565
void backdoor_write(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address);
6666
void backdoor_read(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address);
6767

68+
unsigned char *get_pointer_to_mem_region(sc_dt::uint64 address);
69+
6870
private:
6971

7072
/**

modules/VirtualPrototype/include/common_func.hpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,32 @@
22
#define COMMON_FUNC_HPP
33

44
#define dbgprint(FORMAT, ARGS...) \
5-
printf("%s(%0d) @%s: " FORMAT "\n", __FILE__, __LINE__, sc_time_stamp().to_string().c_str(), ##ARGS)
5+
printf("%s(%0d) @%s: " FORMAT "\n", __FILE__, __LINE__, sc_core::sc_time_stamp().to_string().c_str(), ##ARGS);
66

7-
#define dbgmodprint(FORMAT, ARGS...) \
8-
printf("%s(%0d) [%s] @%s : " FORMAT "\n", __FILE__, __LINE__, this->name(), sc_time_stamp().to_string().c_str(), ##ARGS)
7+
#define dbgmodprint(DBG_ACT, FORMAT, ARGS...) \
8+
if (DBG_ACT) printf("%s(%0d) [%s] @%s : " FORMAT "\n", __FILE__, __LINE__, this->name(), sc_core::sc_time_stamp().to_string().c_str(), ##ARGS)
99

10-
#define dbgimgtarmodprint(FORMAT, ARGS...) \
11-
printf("%s(%0d) [%s] @%s : " FORMAT "\n", __FILE__, __LINE__, img_target::name(), sc_time_stamp().to_string().c_str(), ##ARGS)
10+
#define dbgimgtarmodprint(DBG_ACT, FORMAT, ARGS...) \
11+
if (DBG_ACT) printf("%s(%0d) [%s] @%s : " FORMAT "\n", __FILE__, __LINE__, img_target::name(), sc_core::sc_time_stamp().to_string().c_str(), ##ARGS)
12+
13+
#define checkprintenable(DBG_ACT) \
14+
if (DBG_ACT) \
15+
{ \
16+
printf("%s(%0d) [%s] @%s : " "Prints enabled for this module" "\n", __FILE__, __LINE__, this->name(), sc_core::sc_time_stamp().to_string().c_str()); \
17+
} \
18+
else \
19+
{ \
20+
printf("%s(%0d) [%s] @%s : " "Prints are not enabled for this module" "\n", __FILE__, __LINE__, this->name(), sc_core::sc_time_stamp().to_string().c_str()); \
21+
}
22+
23+
#define checkprintenableimgtar(DBG_ACT) \
24+
if (DBG_ACT) \
25+
{ \
26+
printf("%s(%0d) [%s] @%s : " "Prints enabled for this module" "\n", __FILE__, __LINE__, img_target::name(), sc_core::sc_time_stamp().to_string().c_str()); \
27+
} \
28+
else \
29+
{ \
30+
printf("%s(%0d) [%s] @%s : " "Prints are not enabled for this module" "\n", __FILE__, __LINE__, img_target::name(), sc_core::sc_time_stamp().to_string().c_str()); \
31+
}
1232

1333
#endif // COMMON_FUNC_HPP
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef IMG_SAVER_TLM_HPP
2+
#define IMG_SAVER_TLM_HPP
3+
4+
#include <systemc.h>
5+
#include "../src/img_target.cpp"
6+
#include "address_map.hpp"
7+
8+
struct img_saver_tlm: public img_target
9+
{
10+
img_saver_tlm(sc_module_name name) : img_target((std::string(name) + "_target").c_str()) {
11+
set_mem_attributes(IMG_SAVER_ID_ADDRESS_LO, IMG_SAVER_ID_SIZE+IMG_SAVER_START_SIZE);
12+
}
13+
14+
//Override do_when_transaction functions
15+
virtual void do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
16+
virtual void do_when_write_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
17+
18+
int local_id;
19+
20+
unsigned char *img_input_ptr;
21+
unsigned char *img_inprocess_a_ptr;
22+
unsigned char *img_inprocess_b_ptr;
23+
unsigned char *img_inprocess_c_ptr;
24+
unsigned char *img_inprocess_d_ptr;
25+
unsigned char *img_output_ptr;
26+
};
27+
28+
#endif // IMG_SAVER_TLM_HPP
29+

modules/VirtualPrototype/include/img_transmiter.hpp

Lines changed: 0 additions & 25 deletions
This file was deleted.

modules/VirtualPrototype/include/img_transmiter_tlm.hpp

Lines changed: 0 additions & 22 deletions
This file was deleted.

modules/VirtualPrototype/include/ips_filter_tlm.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ using namespace std;
1515
struct ips_filter_tlm : public Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE>, public img_target
1616
{
1717

18-
ips_filter_tlm(sc_module_name name) : Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE>((std::string(name) + "_HW_block").c_str()), img_target((std::string(name) + "_target").c_str()) {
18+
ips_filter_tlm(sc_module_name name, bool use_prints_) : Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE>((std::string(name) + "_HW_block").c_str()), img_target((std::string(name) + "_target").c_str()) {
1919
set_mem_attributes(IMG_FILTER_KERNEL_ADDRESS_LO, IMG_FILTER_KERNEL_SIZE+IMG_FILTER_OUTPUT_SIZE);
20+
use_prints = use_prints_;
21+
checkprintenableimgtar(use_prints);
2022
}
2123

2224
//Override do_when_transaction functions

0 commit comments

Comments
 (0)