CoCalc Public Filessyscfund / ex6 / bus.hOpen with one click!
Authors: Harpreet Bhatia, eileen hickey
Views : 59
Compute Environment: Ubuntu 20.04 (Default)
1
#ifndef BUS_H
2
#define BUS_H
3
4
// bus.h
5
//
6
#include "master_if.h"
7
#include "slave_if.h"
8
#include "defs.h"
9
10
struct reqT
11
{
12
bool request;
13
sc_event proceed;
14
//default constructor
15
reqT():request(false) {}
16
};
17
18
// Hierarchical channel
19
20
class Bus : public sc_module, public master_if
21
{
22
public:
23
// clock port - bus will operate on negative edge
24
sc_in<bool> clock;
25
26
// a port to connect slave(s)
27
sc_port<slave_if, 2> slave_port;
28
29
// an export to connect master(s)
30
sc_export<master_if> master_export;
31
32
SC_HAS_PROCESS(Bus);
33
34
// constructor
35
Bus(sc_module_name name)
36
: sc_module(name)
37
, n_masters(0)
38
, request_array(0)
39
, request_count(0)
40
, mem_status(0)
41
{
42
master_export (*this);
43
SC_THREAD(control_bus);
44
sensitive << clock.neg();
45
}
46
47
// destructor
48
~Bus() {
49
if (request_array) delete [] request_array;
50
if (request_count) delete [] request_count;
51
if (mem_status) delete [] mem_status;
52
}
53
54
// bus public methods
55
void write(BusT::addressT address, BusT::dataT data, int id);
56
void read (BusT::addressT address, BusT::dataT &data, int id);
57
58
private:
59
// data fields
60
unsigned n_masters;
61
reqT* request_array;
62
int* request_count;
63
unsigned int *starts, *sizes;
64
bool* mem_status;
65
66
// private methods
67
void control_bus();
68
int find_interface(BusT::addressT address);
69
void end_of_elaboration();
70
void register_port(sc_port_base &port_, const char* if_typename_);
71
BusT::dataT get_mem_status(int id);
72
void set_mem_status(BusT::MEM_STATUS, int id=0);
73
int n_pending();
74
75
};
76
77
#endif
78