Skip to content

Commit 44de5a0

Browse files
committed
Add transmitter and receiver modules
1 parent 69e092c commit 44de5a0

File tree

8 files changed

+208
-0
lines changed

8 files changed

+208
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef IMG_RECEIVER_HPP
2+
#define IMG_RECEIVER_HPP
3+
4+
#include <systemc.h>
5+
#include "address_map.hpp"
6+
7+
SC_MODULE(img_receiver)
8+
{
9+
//Array for input image
10+
unsigned char* input_image;
11+
sc_dt::uint64 address_offset;
12+
13+
SC_CTOR(img_receiver)
14+
{
15+
input_image = new unsigned char[IMG_INPUT_SIZE];
16+
address_offset = IMG_INPUT_ADDRESS_LO;
17+
}
18+
19+
//Backdoor access to memory
20+
void backdoor_write(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address);
21+
void backdoor_read(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address);
22+
};
23+
24+
#endif // IMG_RECEIVER_HPP
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef IMG_RECEIVER_TLM_HPP
2+
#define IMG_RECEIVER_TLM_HPP
3+
4+
#include <systemc.h>
5+
#include "img_receiver.hpp"
6+
#include "../src/img_target.cpp"
7+
#include "address_map.hpp"
8+
9+
struct img_receiver_tlm: public img_receiver, public img_target
10+
{
11+
SC_CTOR(img_receiver_tlm): img_receiver(img_receiver::name()), img_target(img_target::name()) {
12+
set_mem_attributes(IMG_INPUT_ADDRESS_LO, IMG_INPUT_SIZE);
13+
}
14+
15+
//Override do_when_transaction functions
16+
virtual void do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
17+
virtual void do_when_write_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
18+
19+
};
20+
21+
#endif // IMG_RECEIVER_TLM_HPP
22+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef IMG_TRANSMITER_HPP
2+
#define IMG_TRANSMITER_HPP
3+
4+
#include <systemc.h>
5+
#include "address_map.hpp"
6+
7+
SC_MODULE(img_transmiter)
8+
{
9+
//Array for input image
10+
unsigned char* output_image;
11+
sc_dt::uint64 address_offset;
12+
13+
SC_CTOR(img_transmiter)
14+
{
15+
output_image = new unsigned char[IMG_INPUT_SIZE];
16+
address_offset = IMG_OUTPUT_ADDRESS_LO;
17+
}
18+
19+
//Backdoor access to memory
20+
void backdoor_write(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address);
21+
void backdoor_read(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address);
22+
};
23+
24+
#endif // IMG_TRANSMITER_HPP
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef IMG_TRANSMITER_TLM_HPP
2+
#define IMG_TRANSMITER_TLM_HPP
3+
4+
#include <systemc.h>
5+
#include "img_transmiter.hpp"
6+
#include "../src/img_target.cpp"
7+
#include "address_map.hpp"
8+
9+
struct img_transmiter_tlm: public img_transmiter, public img_target
10+
{
11+
SC_CTOR(img_transmiter_tlm): img_transmiter(img_transmiter::name()), img_target(img_target::name()) {
12+
set_mem_attributes(IMG_OUTPUT_ADDRESS_LO, IMG_OUTPUT_SIZE);
13+
}
14+
15+
//Override do_when_transaction functions
16+
virtual void do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
17+
virtual void do_when_write_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
18+
19+
};
20+
21+
#endif // IMG_TRANSMITER_TLM_HPP
22+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef IMG_RECEIVER_CPP
2+
#define IMG_RECEIVER_CPP
3+
4+
#include "img_receiver.hpp"
5+
#include "common_func.hpp"
6+
7+
//Backdoor write/read for debug purposes
8+
void img_receiver::backdoor_write(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
9+
{
10+
sc_dt::uint64 local_address = address - address_offset;
11+
memcpy((input_image + local_address), data, data_length);
12+
for (int i = 0; i < 10; i++) {
13+
dbgmodprint("Backdoor Writing: %0d\n", *(input_image + local_address+i));
14+
}
15+
}
16+
17+
void img_receiver::backdoor_read(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
18+
{
19+
sc_dt::uint64 local_address = address - address_offset;
20+
data = new unsigned char[data_length];
21+
memcpy(data, (input_image + local_address), data_length);
22+
for (int i = 0; i < 10; i++) {
23+
dbgmodprint("Backdoor Reading: %0d\n", *(input_image + local_address+i));
24+
}
25+
}
26+
27+
#endif // IMG_RECEIVER_CPP
28+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef IMG_RECEIVER_TLM_CPP
2+
#define IMG_RECEIVER_TLM_CPP
3+
4+
#include <systemc.h>
5+
using namespace sc_core;
6+
using namespace sc_dt;
7+
using namespace std;
8+
9+
#include <tlm.h>
10+
#include "img_receiver_tlm.hpp"
11+
#include "address_map.hpp"
12+
13+
#include "common_func.hpp"
14+
15+
void img_receiver_tlm::do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address)
16+
{
17+
for (int i = 0; i < data_length; i++){
18+
*(data+i) = *(input_image+address+i);
19+
}
20+
}
21+
22+
void img_receiver_tlm::do_when_write_transaction(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
23+
{
24+
for (int i = 0; i < data_length; i++){
25+
*(input_image+address+i) = *(data+i);
26+
}
27+
}
28+
29+
#endif // IMG_RECEIVER_TLM_CPP
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef IMG_TRANSMITER_CPP
2+
#define IMG_TRANSMITER_CPP
3+
4+
#include "img_transmiter.hpp"
5+
#include "common_func.hpp"
6+
7+
//Backdoor write/read for debug purposes
8+
void img_transmiter::backdoor_write(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
9+
{
10+
sc_dt::uint64 local_address = address - address_offset;
11+
memcpy((output_image + local_address), data, data_length);
12+
for (int i = 0; i < 10; i++) {
13+
dbgmodprint("Backdoor Writing: %0d\n", *(output_image + local_address+i));
14+
}
15+
}
16+
17+
void img_transmiter::backdoor_read(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
18+
{
19+
sc_dt::uint64 local_address = address - address_offset;
20+
data = new unsigned char[data_length];
21+
memcpy(data, (output_image + local_address), data_length);
22+
for (int i = 0; i < 10; i++) {
23+
dbgmodprint("Backdoor Reading: %0d\n", *(output_image + local_address+i));
24+
}
25+
}
26+
27+
#endif // IMG_TRANSMITER_CPP
28+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef IMG_TRANSMITER_TLM_CPP
2+
#define IMG_TRANSMITER_TLM_CPP
3+
4+
#include <systemc.h>
5+
using namespace sc_core;
6+
using namespace sc_dt;
7+
using namespace std;
8+
9+
#include <tlm.h>
10+
#include "img_transmiter_tlm.hpp"
11+
#include "address_map.hpp"
12+
13+
#include "common_func.hpp"
14+
15+
void img_transmiter_tlm::do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address)
16+
{
17+
for (int i = 0; i < data_length; i++){
18+
*(data+i) = *(output_image+address+i);
19+
}
20+
}
21+
22+
void img_transmiter_tlm::do_when_write_transaction(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
23+
{
24+
for (int i = 0; i < data_length; i++){
25+
*(output_image+address+i) = *(data+i);
26+
}
27+
}
28+
29+
#endif // IMG_TRANSMITER_TLM_CPP

0 commit comments

Comments
 (0)