Skip to content

Commit df81d92

Browse files
committed
Integrate new modules in the RISV-TLM
1 parent ea81459 commit df81d92

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

VirtualPrototype/src/BusCtrl.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// SPDX-License-Identifier: GPL-3.0-or-later
88

99
#include "BusCtrl.h"
10+
#include "address_map.hpp"
1011

1112
SC_HAS_PROCESS(BusCtrl);
1213
BusCtrl::BusCtrl(sc_core::sc_module_name const name) :
@@ -29,6 +30,10 @@ void BusCtrl::b_transport(tlm::tlm_generic_payload &trans,
2930
sc_core::sc_time &delay) {
3031

3132
sc_dt::uint64 adr = trans.get_address() / 4;
33+
printf("[DEBUG] Address is %0d\n", (int) trans.get_address());
34+
printf("[DEBUG] Addr is %0d\n", (int) adr);
35+
printf("[DEBUG] Target Address is %0d\n", IMG_INPUT_ADDRESS_LO);
36+
printf("[DEBUG] Target Addr is %0d\n", IMG_INPUT_ADDRESS_LO / 4);
3237

3338
switch (adr) {
3439
case TIMER_MEMORY_ADDRESS_HI / 4:
@@ -47,21 +52,21 @@ void BusCtrl::b_transport(tlm::tlm_generic_payload &trans,
4752
std::cout << "Writing/Reading to Filter!" << std::endl;
4853
filter_socket->b_transport(trans, delay);
4954
}
50-
else if ((SOBEL_INPUT_0_ADDRESS_LO / 4 <= adr && adr <= SOBEL_INPUT_0_ADDRESS_HI / 4) ||
51-
(SOBEL_INPUT_1_ADDRESS_LO / 4 <= adr && adr <= SOBEL_INPUT_1_ADDRESS_HI / 4) ||
52-
(SOBEL_OUTPUT_ADDRESS_LO / 4 <= adr && adr <= SOBEL_OUTPUT_ADDRESS_HI / 4))
55+
else if ((SOBEL_INPUT_0_ADDRESS_LO / 4 <= adr && adr < SOBEL_INPUT_0_ADDRESS_HI / 4) ||
56+
(SOBEL_INPUT_1_ADDRESS_LO / 4 <= adr && adr < SOBEL_INPUT_1_ADDRESS_HI / 4) ||
57+
(SOBEL_OUTPUT_ADDRESS_LO / 4 <= adr && adr < SOBEL_OUTPUT_ADDRESS_HI / 4))
5358
{
5459
std::cout << "Writing/Reading to Sobel!" << std::endl;
5560
sobel_edge_detector_socket->b_transport(trans, delay);
5661
}
57-
else if ((IMG_INPUT_ADDRESS_LO / 4 <= adr && adr <= IMG_INPUT_ADDRESS_HI / 4))
62+
else if ((IMG_INPUT_ADDRESS_LO / 4 <= adr && adr < IMG_INPUT_ADDRESS_HI / 4))
5863
{
59-
std::cout << "Writing/Reading to Sobel!" << std::endl;
64+
std::cout << "Writing/Reading to Receiver!" << std::endl;
6065
receiver_socket->b_transport(trans, delay);
6166
}
62-
else if ((IMG_OUTPUT_ADDRESS_LO / 4 <= adr && adr <= IMG_OUTPUT_ADDRESS_HI / 4))
67+
else if ((IMG_OUTPUT_ADDRESS_LO / 4 <= adr && adr < IMG_OUTPUT_ADDRESS_HI / 4))
6368
{
64-
std::cout << "Writing/Reading to Sobel!" << std::endl;
69+
std::cout << "Writing/Reading to Transmiter!" << std::endl;
6570
transmiter_socket->b_transport(trans, delay);
6671
}
6772
else {

VirtualPrototype/src/Simulator.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <csignal>
1616
#include <unistd.h>
1717
#include <chrono>
18-
19-
#include "address_map.hpp"
2018
#include "CPU.h"
2119
#include "Memory.h"
2220
#include "BusCtrl.h"
@@ -31,8 +29,11 @@
3129
#include "inc/stb_image_write.h"
3230

3331
//Our modules
32+
#include "address_map.hpp"
3433
#include "ips_filter_tlm.hpp"
35-
#include "sobel_edge_detector_tlm.cpp"
34+
#include "sobel_edge_detector_tlm.hpp"
35+
#include "img_receiver_tlm.hpp"
36+
#include "img_transmiter_tlm.hpp"
3637

3738
std::string filename;
3839
bool debug_session = false;
@@ -53,6 +54,9 @@ SC_MODULE(Simulator) {
5354

5455
//Our modules
5556
ips_filter_tlm *filter_DUT;
57+
sobel_edge_detector_tlm *sobel_edge_detector_DUT;
58+
img_receiver_tlm *receiver_DUT;
59+
img_transmiter_tlm *transmiter_DUT;
5660

5761

5862
SC_CTOR(Simulator) {
@@ -69,7 +73,9 @@ SC_MODULE(Simulator) {
6973

7074
//Our modules
7175
filter_DUT = new ips_filter_tlm("filter_DUT");
72-
76+
sobel_edge_detector_DUT = new sobel_edge_detector_tlm("sobel_edge_detector_DUT");
77+
receiver_DUT = new img_receiver_tlm("receiver_DUT");
78+
transmiter_DUT = new img_transmiter_tlm("transmiter_DUT");
7379

7480
cpu->instr_bus.bind(Bus->cpu_instr_socket);
7581
cpu->mem_intf->data_bus.bind(Bus->cpu_data_socket);
@@ -81,13 +87,15 @@ SC_MODULE(Simulator) {
8187
timer->irq_line.bind(cpu->irq_line_socket);
8288

8389
//Our modules
84-
Bus->filter_socket.bind(filter_DUT->socket);
90+
Bus->filter_socket.bind(filter_DUT->socket);
91+
Bus->sobel_edge_detector_socket.bind(sobel_edge_detector_DUT->socket);
92+
93+
Bus->receiver_socket.bind(receiver_DUT->socket);
94+
Bus->transmiter_socket.bind(transmiter_DUT->socket);
8595

8696
if (debug_session) {
8797
Debug debug(cpu, MainMemory);
8898
}
89-
90-
pre_load_memory();
9199
}
92100

93101
~Simulator() {
@@ -98,19 +106,16 @@ SC_MODULE(Simulator) {
98106
delete timer;
99107
}
100108

101-
void pre_load_memory()
109+
void load_img_from_memory()
102110
{
103111
int width, height, channels, pixel_count;
104112
unsigned char *noisy_img, *noisy_img2;
105113

106114
noisy_img = stbi_load("inputs/car_noisy_image.png", &width, &height, &channels, 0);
107115
pixel_count = width * height * channels;
108116
printf("Pixel Count %0d, Width: %0d, Height: %0d \n", pixel_count, width, height);
109-
110-
noisy_img2 = new unsigned char [pixel_count];
111117

112-
MainMemory->backdoor_write(noisy_img, pixel_count, INPUT_IMG_MEMORY_LO);
113-
//stbi_write_png("outputs/car_filtered_image.png", width, height, channels, noisy_img, width*channels);
118+
receiver_DUT->backdoor_write(noisy_img, pixel_count, IMG_INPUT_ADDRESS_LO);
114119
}
115120

116121
void save_img_from_memory()
@@ -122,7 +127,7 @@ SC_MODULE(Simulator) {
122127
width = 640;
123128
height = 452;
124129
pixel_count = width * height * channels;
125-
MainMemory->backdoor_read(img_ptr, pixel_count, OUTPUT_IMG_MEMORY_LO);
130+
transmiter_DUT->backdoor_read(img_ptr, pixel_count, IMG_OUTPUT_ADDRESS_LO);
126131

127132
stbi_write_png("outputs/car_filtered_image.png", width, height, channels, img_ptr, width*channels);
128133
}
@@ -209,6 +214,8 @@ int sc_main(int argc, char *argv[]) {
209214

210215
top = new Simulator("top");
211216

217+
top->load_img_from_memory();
218+
212219
auto start = std::chrono::steady_clock::now();
213220
sc_core::sc_start();
214221
auto end = std::chrono::steady_clock::now();

0 commit comments

Comments
 (0)