OpenCores
URL https://opencores.org/ocsvn/noc/noc/trunk

Subversion Repositories noc

[/] [noc/] [src/] [router.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 imori
#ifndef ROUTER_H
2
#define ROUTER_H
3
 
4
#include <systemc>
5
#include <iostream>
6
#include "define.h"
7
#include "packet_header.h"
8
#include "power_model.h"
9
using namespace sc_core;
10
using namespace sc_dt;
11
using namespace std;
12
 
13
#define CORE_ADDRESS    0
14
#define WEST_ADDRESS    3
15
#define EAST_ADDRESS    6
16
#define NORTH_ADDRESS   9
17
#define SOUTH_ADDRESS   12
18
#define OI_ADDRESS              15
19
 
20
#define WRITE_ADDRESS   0
21
#define READ_ADDRESS    3
22
 
23
extern double ei_energy;
24
extern double oi_energy;
25
extern double ei_delay;
26
extern double oi_delay;
27
 
28
typedef struct PORT{
29
        bool            set;
30
        bool            conn_type;
31
        sc_uint<4>      inport;
32
        sc_uint<4>      outport;
33
        sc_uint<2>      in_ch;
34
        sc_uint<2>      out_ch;
35
};
36
 
37
typedef struct OI_PORT{
38
        bool set;
39
        sc_uint<4> inport;
40
        sc_uint<4> outport;
41
};
42
 
43
class router : public sc_module{
44
public:
45
//-------------------------west----------------------------------------------------
46
        sc_in<bool>                     w_data_in;              //west input data port.
47
        sc_out<bool>            w_data_out;             //west output data port.
48
 
49
        sc_out<sc_uint<2> >     w_fifo_to_router_sel;   //west select signal.
50
        sc_out<sc_uint<2> >     w_router_to_fifo_sel;   //west select signal.
51
        sc_out<bool>            w_write_n;                              //left output data control pin.
52
        sc_out<bool>            w_read_n;               //left input data control pin.
53
        sc_in<sc_uint<3> >      w_empty;        //State of FIFO is full.
54
        sc_in<sc_uint<3> >      w_full;         //State of FIFO is empty.
55
//-----------------------east------------------------------------------------------
56
        sc_in<bool>                     e_data_in;              //east input data port.
57
        sc_out<bool>            e_data_out;             //east output data port.
58
 
59
        sc_out<sc_uint<2> >     e_fifo_to_router_sel;   //east select signal.
60
        sc_out<sc_uint<2> >     e_router_to_fifo_sel;   //east select signal.
61
        sc_out<bool>            e_write_n;              //right output data control pin.
62
        sc_out<bool>            e_read_n;               //right input data control pin.
63
        sc_in<sc_uint<3> >      e_empty;                //State of FIFO is full.
64
        sc_in<sc_uint<3> >      e_full;                 //State of FIFO is empty.
65
//-----------------------north-----------------------------------------------------
66
        sc_in<bool>                     n_data_in;              //north nput data port.
67
        sc_out<bool>            n_data_out;             //north output data port.
68
 
69
        sc_out<sc_uint<2> >     n_fifo_to_router_sel;   //north select signal.
70
        sc_out<sc_uint<2> >     n_router_to_fifo_sel;   //north select signal.
71
 
72
        sc_out<bool>            n_write_n;              //north output data control pin.
73
        sc_out<bool>            n_read_n;       //north input data control pin.
74
        sc_in<sc_uint<3> >      n_empty;        //State of FIFO is full.
75
        sc_in<sc_uint<3> >      n_full;         //State of FIFO is empty.
76
//-------------------------south---------------------------------------------------
77
        sc_in<bool>                     s_data_in;      //south input data port.
78
        sc_out<bool>            s_data_out;             //south output data port.
79
 
80
        sc_out<sc_uint<2> >     s_fifo_to_router_sel;   //north select signal.
81
        sc_out<sc_uint<2> >     s_router_to_fifo_sel;   //north select signal.
82
 
83
        sc_out<bool>            s_write_n;      //south output data control pin.
84
        sc_out<bool>            s_read_n;       //south input data control pin.
85
        sc_in<sc_uint<3> >      s_empty;        //State of FIFO is full.
86
        sc_in<sc_uint<3> >      s_full;         //State of FIFO is empty.
87
//-----------------------core------------------------------------------------------
88
        sc_in<bool>                     c_data_in;      //core input data port.
89
        sc_out<bool>            c_data_out;     //core output data port.
90
 
91
        sc_out<sc_uint<2> >     c_fifo_to_router_sel;   //north select signal.
92
        sc_out<sc_uint<2> >     c_router_to_fifo_sel;   //north select signal.
93
 
94
        sc_out<bool>            c_write_n;      //core output data control pin.
95
        sc_out<bool>            c_read_n;       //core input data control pin.
96
        sc_in<sc_uint<3> >      c_empty;        //State of FIFO is full.
97
        sc_in<sc_uint<3> >      c_full;         //State of FIFO is empty.
98
//---------------------------------------------------------------------------------
99
        sc_in<bool>                     reset_n;
100
        sc_in<bool>                     clk;
101
//--------------------Optical interconnects----------------------------------------
102
        sc_in<sc_logic>                 c_oi_in;
103
        sc_out<sc_logic>                c_oi_out;
104
        sc_out<sc_uint<16> >    oi_control;
105
 
106
        sc_signal<sc_uint<16> >         c_data;
107
        sc_signal<sc_uint<8> >          c_address;
108
 
109
 
110
        SC_HAS_PROCESS(router);
111
 
112
        router(sc_module_name nm, int id, int column_num, int row_num): sc_module(nm){
113
                router_id = id;
114
                x_num = column_num;
115
                y_num = row_num;
116
 
117
                SC_THREAD(core_receive_data);
118
                sensitive << clk.pos() << clk.neg();
119
                SC_THREAD(core_transfer_data);
120
                sensitive << clk.pos() << clk.neg();
121
 
122
                SC_THREAD(west_receive_data);
123
                sensitive << clk.pos() << clk.neg();
124
                SC_THREAD(west_transfer_data);
125
                sensitive << clk.pos() << clk.neg();
126
 
127
                SC_THREAD(east_receive_data);
128
                sensitive << clk.pos() << clk.neg();
129
                SC_THREAD(east_transfer_data);
130
                sensitive << clk.pos() << clk.neg();
131
 
132
                SC_THREAD(north_receive_data);
133
                sensitive << clk.pos() << clk.neg();
134
                SC_THREAD(north_transfer_data);
135
                sensitive << clk.pos() << clk.neg();
136
 
137
                SC_THREAD(south_receive_data);
138
                sensitive << clk.pos() << clk.neg();
139
                SC_THREAD(south_transfer_data);
140
                sensitive << clk.pos() << clk.neg();
141
 
142
                SC_THREAD(oi_receive_data);
143
                sensitive << clk.pos() << clk.neg();
144
                SC_THREAD(oi_transfer_data);
145
                sensitive << clk.pos() << clk.neg();
146
 
147
                SC_THREAD(direction_handle);
148
                sensitive << clk.pos();
149
        }
150
 
151
protected:
152
        //control register between input channel and outport channel. 
153
        //where num in port[num] is input channel.
154
        PORT                            port[16];                       //Electrical interconnects register.                    
155
        OI_PORT                         ois_port[5];            //Optical interconnects register.
156
        sc_uint<17>                     rbuffer[50];            //temporally store data from input channel.
157
        sc_uint<17>                     oi_rbuffer;                     //temporally store data from input channel.
158
        sc_uint<18>                     tbuffer[50];            //temporally store data for transmitter.
159
        sc_uint<18>                     oi_tbuffer;                     //temporally store data for transmitter.
160
        sc_uint<16>                     tbuffer_state;          //tbuffer present whether using or not using.
161
        sc_uint<6>                      router_id;                      //router identification.
162
        sc_uint<6>                      x_num;
163
        sc_uint<6>                      y_num;
164
 
165
        sc_uint<16>                     control_state;
166
 
167
        //function decode head flit.
168
        char header_decoder(sc_uint<8> addr);
169
 
170
#ifdef ROUTER_DEBUG
171
        void receive_data(sc_in<bool> *data_in, sc_out<sc_uint<2> > *fifo_to_router_sel,
172
                                          sc_out<bool> *read_n, sc_in<sc_uint<3> > *empty, sc_uint<8> address,
173
                                          char *debug_string, unsigned char debug_en);
174
 
175
        void transfer_data(sc_out<bool> *data_out, sc_out<sc_uint<2> > *router_to_fifo_sel,
176
                                           sc_out<bool> *write_n, sc_in<sc_uint<3> > *full, sc_uint<8> address,
177
                                           char *debug_string, unsigned char debug_en);
178
#else
179
        void receive_data(sc_in<bool> *data_in, sc_out<sc_uint<2> > *fifo_to_router_sel,
180
                                          sc_out<bool> *read_n, sc_in<sc_uint<3> > *empty, sc_uint<8> address);
181
 
182
        void transfer_data(sc_out<bool> *data_out, sc_out<sc_uint<2> > *router_to_fifo_sel,
183
                                           sc_out<bool> *write_n, sc_in<sc_uint<3> > *full, sc_uint<8> address);
184
#endif
185
        char direction_decision(char dst_x, char dst_y, char router_x, char router_y);
186
        void oi_receive_data();
187
        void oi_transfer_data();
188
 
189
        void core_receive_data();
190
        void core_transfer_data();
191
 
192
        void west_receive_data();
193
        void west_transfer_data();
194
 
195
        void east_receive_data();
196
        void east_transfer_data();
197
 
198
        void north_receive_data();
199
        void north_transfer_data();
200
 
201
        void south_receive_data();
202
        void south_transfer_data();
203
 
204
        void direction_handle();
205
 
206
        sc_uint<16> out_direction(sc_uint<8> out_going, sc_uint<16> go_a, sc_uint<16> go_b,
207
                                                          sc_uint<16> go_c, sc_uint<16> go_d, sc_uint<16> go_e);
208
        void optical_sw(sc_uint<8> ch);
209
 
210
};
211
 
212
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.