source: trunk/IPs/systemC/Environment/src/Environment.cpp @ 88

Last change on this file since 88 was 88, checked in by rosiere, 15 years ago

Almost complete design
with Test and test platform

  • Property svn:keywords set to Id
File size: 16.0 KB
Line 
1#include "../include/Environment.h"
2
3using namespace morpheo;
4
5namespace environment {
6
7  Environment::Environment (sc_module_name name, Parameters * param) :
8    name (name)
9  {
10    this->param = param;
11
12    component_cache       = new cache::Cache     ("cache", param->param_cache);
13
14    component_tty         = new tty::TTY * [param->nb_component_tty];
15    for (uint32_t i=0; i<param->nb_component_tty; i++)
16    component_tty     [i] = new tty::TTY         ("tty_"+i    ,param->param_tty     [i]);
17   
18    component_ramlock     = new ramlock::RamLock * [param->nb_component_ramlock];
19    for (uint32_t i=0; i<param->nb_component_ramlock; i++)
20    component_ramlock [i] = new ramlock::RamLock ("ramlock_"+i,param->param_ramlock [i]);
21
22    component_sim2os      = new sim2os::Sim2OS   ("sim2os" ,param->param_sim2os );
23    component_data        = new data::Data       ("data"   ,param->param_data   );
24
25    component_buffer_irsp = new queue::Sort_Queue<irsp_t*> * [param->nb_entity];
26    component_buffer_drsp = new queue::Sort_Queue<drsp_t*> * [param->nb_entity];
27
28    for (uint32_t i=0; i<param->nb_component_tty; i++)
29      {
30        uint32_t tty_size = param->param_tty[i]->nb_tty * 16;
31
32        data::Entity entity = component_data->entity(param->tty_address[i], tty_size);
33        if (entity.present == false)
34          {
35            std::cerr << "<Environnement::Environnement> The tty [" << i << "] have not a segment in the segment table" << std::endl;
36            exit (1);
37          }
38        entity.segment->define_target(data::TYPE_TARGET_TTY,i);
39      } 
40
41    for (uint32_t i=0; i<param->nb_component_ramlock; i++)
42      {
43        uint32_t ramlock_size = param->param_ramlock[i]->_size;
44        data::Entity entity = component_data->entity(param->ramlock_address[i], ramlock_size);
45        if (entity.present == false)
46          {
47            std::cerr << "<Environnement::Environnement> The ramlock [" << i << "] have not a segment in the segment table" << std::endl;
48            exit (1);
49          }
50        entity.segment->define_target(data::TYPE_TARGET_RAMLOCK,i);
51      } 
52
53      {
54        data::Entity entity = component_data->entity(param->sim2os_address, param->sim2os_size);
55        if (entity.present == false)
56          {
57            std::cerr << "<Environnement::Environnement> The sim2os  have not a segment in the segment table" << std::endl;
58            exit (1);
59          }
60        entity.segment->define_target(data::TYPE_TARGET_SIM2OS,0);
61      } 
62
63
64    for (uint32_t i=0; i<param->nb_entity; i++)
65      {
66        component_buffer_irsp [i] = new queue::Sort_Queue<irsp_t*> ("buffer_irsp_"+i,param->param_buffer_irsp [i]);
67        component_buffer_drsp [i] = new queue::Sort_Queue<drsp_t*> ("buffer_drsp_"+i,param->param_buffer_drsp [i]);
68      }
69
70    uint32_t max_nb_instruction   = morpheo::max<uint32_t>(param->iaccess_nb_instruction  ,param->nb_entity);
71    uint32_t max_instruction_size = morpheo::max<uint32_t>(param->iaccess_size_instruction,param->nb_entity);
72    uint32_t max_data_size        = morpheo::max<uint32_t>(param->daccess_size_data       ,param->nb_entity);
73   
74    read_iram  = new char * [max_nb_instruction];
75    for (uint32_t i=0; i<max_nb_instruction; i++)
76      read_iram [i] = new char [max_instruction_size];
77
78    read_dram    = new char * [1];
79    read_dram[0] = new char [max_data_size/8];
80    write_dram   = new char [max_data_size/8];
81    context_stop = new bool [param->nb_entity];
82    for (uint32_t i=0; i<param->nb_entity; ++i)
83      context_stop [i] = false;
84    nb_context_stop = 0;
85
86    // Port
87    CLOCK                 = new sc_in_clk   ("CLOCK ");
88    NRESET                = new sc_in<bool> ("NRESET");
89
90    ICACHE_REQ_VAL        = new sc_in <Tcontrol_t           >  ** [param->nb_entity];
91    ICACHE_REQ_ACK        = new sc_out<Tcontrol_t           >  ** [param->nb_entity];
92    ICACHE_REQ_CONTEXT_ID = new sc_in <Ticache_context_t    >  ** [param->nb_entity];
93    ICACHE_REQ_PACKET_ID  = new sc_in <Ticache_packet_t     >  ** [param->nb_entity];
94    ICACHE_REQ_ADDRESS    = new sc_in <Ticache_address_t    >  ** [param->nb_entity];
95    ICACHE_REQ_TYPE       = new sc_in <Ticache_type_t       >  ** [param->nb_entity];
96
97    ICACHE_RSP_VAL        = new sc_out<Tcontrol_t           >  ** [param->nb_entity];
98    ICACHE_RSP_ACK        = new sc_in <Tcontrol_t           >  ** [param->nb_entity];
99    ICACHE_RSP_CONTEXT_ID = new sc_out<Ticache_context_t    >  ** [param->nb_entity];
100    ICACHE_RSP_PACKET_ID  = new sc_out<Ticache_packet_t     >  ** [param->nb_entity];
101
102    ICACHE_RSP_INSTRUCTION= new sc_out<Ticache_instruction_t> *** [param->nb_entity];//[nb_instruction]
103    ICACHE_RSP_ERROR      = new sc_out<Ticache_error_t      >  ** [param->nb_entity];
104
105    DCACHE_REQ_VAL        = new sc_in <Tcontrol_t           >  ** [param->nb_entity];
106    DCACHE_REQ_ACK        = new sc_out<Tcontrol_t           >  ** [param->nb_entity];
107    DCACHE_REQ_CONTEXT_ID = new sc_in <Tdcache_context_t    >  ** [param->nb_entity];
108    DCACHE_REQ_PACKET_ID  = new sc_in <Tdcache_packet_t     >  ** [param->nb_entity];
109    DCACHE_REQ_ADDRESS    = new sc_in <Tdcache_address_t    >  ** [param->nb_entity];
110    DCACHE_REQ_TYPE       = new sc_in <Tdcache_type_t       >  ** [param->nb_entity];
111    DCACHE_REQ_WDATA      = new sc_in <Tdcache_data_t       >  ** [param->nb_entity];
112
113    DCACHE_RSP_VAL        = new sc_out<Tcontrol_t           >  ** [param->nb_entity];
114    DCACHE_RSP_ACK        = new sc_in <Tcontrol_t           >  ** [param->nb_entity];
115    DCACHE_RSP_CONTEXT_ID = new sc_out<Tdcache_context_t    >  ** [param->nb_entity];
116    DCACHE_RSP_PACKET_ID  = new sc_out<Tdcache_packet_t     >  ** [param->nb_entity];
117    DCACHE_RSP_RDATA      = new sc_out<Tdcache_data_t       >  ** [param->nb_entity];
118    DCACHE_RSP_ERROR      = new sc_out<Tdcache_error_t      >  ** [param->nb_entity];
119
120    for (uint32_t i=0; i<param->nb_entity; i++)
121      {
122        ICACHE_REQ_VAL        [i] = new sc_in <Tcontrol_t           >  * [param->icache_dedicated_nb_port[i]];
123        ICACHE_REQ_ACK        [i] = new sc_out<Tcontrol_t           >  * [param->icache_dedicated_nb_port[i]];
124        ICACHE_REQ_CONTEXT_ID [i] = new sc_in <Ticache_context_t    >  * [param->icache_dedicated_nb_port[i]];
125        ICACHE_REQ_PACKET_ID  [i] = new sc_in <Ticache_packet_t     >  * [param->icache_dedicated_nb_port[i]];
126        ICACHE_REQ_ADDRESS    [i] = new sc_in <Ticache_address_t    >  * [param->icache_dedicated_nb_port[i]];
127        ICACHE_REQ_TYPE       [i] = new sc_in <Ticache_type_t       >  * [param->icache_dedicated_nb_port[i]];
128
129        ICACHE_RSP_VAL        [i] = new sc_out<Tcontrol_t           >  * [param->icache_dedicated_nb_port[i]];
130        ICACHE_RSP_ACK        [i] = new sc_in <Tcontrol_t           >  * [param->icache_dedicated_nb_port[i]];
131        ICACHE_RSP_CONTEXT_ID [i] = new sc_out<Ticache_context_t    >  * [param->icache_dedicated_nb_port[i]];
132        ICACHE_RSP_PACKET_ID  [i] = new sc_out<Ticache_packet_t     >  * [param->icache_dedicated_nb_port[i]];
133        ICACHE_RSP_INSTRUCTION[i] = new sc_out<Ticache_instruction_t> ** [param->icache_dedicated_nb_port[i]];//[nb_instruction]
134        ICACHE_RSP_ERROR      [i] = new sc_out<Ticache_error_t      >  * [param->icache_dedicated_nb_port[i]];
135       
136        for (uint32_t j=0; j<param->icache_dedicated_nb_port[i]; j++)
137          {
138            ICACHE_REQ_VAL         [i][j] = new sc_in <Tcontrol_t           > ("");
139            ICACHE_REQ_ACK         [i][j] = new sc_out<Tcontrol_t           > ("");
140            ICACHE_REQ_CONTEXT_ID  [i][j] = new sc_in <Ticache_context_t    > ("");
141            ICACHE_REQ_PACKET_ID   [i][j] = new sc_in <Ticache_packet_t     > ("");
142            ICACHE_REQ_ADDRESS     [i][j] = new sc_in <Ticache_address_t    > ("");
143            ICACHE_REQ_TYPE        [i][j] = new sc_in <Ticache_type_t       > ("");
144           
145            ICACHE_RSP_VAL         [i][j] = new sc_out<Tcontrol_t           > ("");
146            ICACHE_RSP_ACK         [i][j] = new sc_in <Tcontrol_t           > ("");
147            ICACHE_RSP_CONTEXT_ID  [i][j] = new sc_out<Ticache_context_t    > ("");
148            ICACHE_RSP_PACKET_ID   [i][j] = new sc_out<Ticache_packet_t     > ("");
149            ICACHE_RSP_ERROR       [i][j] = new sc_out<Ticache_error_t      > ("");
150           
151            ICACHE_RSP_INSTRUCTION [i][j] = new sc_out<Ticache_instruction_t> * [param->iaccess_nb_instruction[i]];
152           
153            for (uint32_t k=0; k<param->iaccess_nb_instruction[i]; k++)
154              ICACHE_RSP_INSTRUCTION [i][j][k] = new sc_out<Ticache_instruction_t> ("");
155          }
156       
157        DCACHE_REQ_VAL        [i] = new sc_in <Tcontrol_t           >  * [param->dcache_dedicated_nb_port[i]];
158        DCACHE_REQ_ACK        [i] = new sc_out<Tcontrol_t           >  * [param->dcache_dedicated_nb_port[i]];
159        DCACHE_REQ_CONTEXT_ID [i] = new sc_in <Tdcache_context_t    >  * [param->dcache_dedicated_nb_port[i]];
160        DCACHE_REQ_PACKET_ID  [i] = new sc_in <Tdcache_packet_t     >  * [param->dcache_dedicated_nb_port[i]];
161        DCACHE_REQ_ADDRESS    [i] = new sc_in <Tdcache_address_t    >  * [param->dcache_dedicated_nb_port[i]];
162        DCACHE_REQ_TYPE       [i] = new sc_in <Tdcache_type_t       >  * [param->dcache_dedicated_nb_port[i]];
163        DCACHE_REQ_WDATA      [i] = new sc_in <Tdcache_data_t       >  * [param->dcache_dedicated_nb_port[i]];
164
165        DCACHE_RSP_VAL        [i] = new sc_out<Tcontrol_t           >  * [param->dcache_dedicated_nb_port[i]];
166        DCACHE_RSP_ACK        [i] = new sc_in <Tcontrol_t           >  * [param->dcache_dedicated_nb_port[i]];
167        DCACHE_RSP_CONTEXT_ID [i] = new sc_out<Tdcache_context_t    >  * [param->dcache_dedicated_nb_port[i]];
168        DCACHE_RSP_PACKET_ID  [i] = new sc_out<Tdcache_packet_t     >  * [param->dcache_dedicated_nb_port[i]];
169        DCACHE_RSP_RDATA      [i] = new sc_out<Tdcache_data_t       >  * [param->dcache_dedicated_nb_port[i]];
170        DCACHE_RSP_ERROR      [i] = new sc_out<Tdcache_error_t      >  * [param->dcache_dedicated_nb_port[i]];
171       
172        for (uint32_t j=0; j<param->dcache_dedicated_nb_port[i]; j++)
173          {
174            DCACHE_REQ_VAL        [i][j] = new sc_in <Tcontrol_t           > ("");
175            DCACHE_REQ_ACK        [i][j] = new sc_out<Tcontrol_t           > ("");
176            DCACHE_REQ_CONTEXT_ID [i][j] = new sc_in <Tdcache_context_t    > ("");
177            DCACHE_REQ_PACKET_ID  [i][j] = new sc_in <Tdcache_packet_t     > ("");
178            DCACHE_REQ_ADDRESS    [i][j] = new sc_in <Tdcache_address_t    > ("");
179            DCACHE_REQ_TYPE       [i][j] = new sc_in <Tdcache_type_t       > ("");
180            DCACHE_REQ_WDATA      [i][j] = new sc_in <Tdcache_data_t       > ("");
181           
182            DCACHE_RSP_VAL        [i][j] = new sc_out<Tcontrol_t           > ("");
183            DCACHE_RSP_ACK        [i][j] = new sc_in <Tcontrol_t           > ("");
184            DCACHE_RSP_CONTEXT_ID [i][j] = new sc_out<Tdcache_context_t    > ("");
185            DCACHE_RSP_PACKET_ID  [i][j] = new sc_out<Tdcache_packet_t     > ("");
186            DCACHE_RSP_RDATA      [i][j] = new sc_out<Tdcache_data_t       > ("");
187            DCACHE_RSP_ERROR      [i][j] = new sc_out<Tdcache_error_t      > ("");
188          }
189      }
190
191    icache_req_ack = new Tcontrol_t * [param->nb_entity];
192    icache_rsp_val = new Tcontrol_t * [param->nb_entity];
193    dcache_req_ack = new Tcontrol_t * [param->nb_entity];
194    dcache_rsp_val = new Tcontrol_t * [param->nb_entity];
195
196    for (uint32_t i=0; i<param->nb_entity; i++)
197      {
198        icache_req_ack [i] = new Tcontrol_t [param->icache_dedicated_nb_port[i]];
199        icache_rsp_val [i] = new Tcontrol_t [param->icache_dedicated_nb_port[i]];
200        dcache_req_ack [i] = new Tcontrol_t [param->dcache_dedicated_nb_port[i]];
201        dcache_rsp_val [i] = new Tcontrol_t [param->dcache_dedicated_nb_port[i]];
202      }
203    // *****[ Definition of method ]*****
204    SC_METHOD (transition);
205    dont_initialize ();
206    sensitive << (*(CLOCK)).pos();
207   
208    SC_METHOD (genMoore);
209    dont_initialize ();
210    sensitive << (*(CLOCK)).neg();
211  }
212
213  Environment::~Environment (void)
214  {
215    for (uint32_t i=0; i<param->nb_entity; i++)
216      {
217        delete [] icache_req_ack [i];
218        delete [] icache_rsp_val [i];
219        delete [] dcache_req_ack [i];
220        delete [] dcache_rsp_val [i];
221      }
222
223    delete [] icache_req_ack;
224    delete [] icache_rsp_val;
225    delete [] dcache_req_ack;
226    delete [] dcache_rsp_val;
227
228    delete CLOCK ;
229    delete NRESET;
230   
231    for (uint32_t i=0; i<param->nb_entity; i++)
232      {
233        for (uint32_t j=0; j<param->icache_dedicated_nb_port[i]; j++)
234          {
235            delete ICACHE_REQ_VAL         [i][j];
236            delete ICACHE_REQ_ACK         [i][j];
237            delete ICACHE_REQ_CONTEXT_ID  [i][j];
238            delete ICACHE_REQ_PACKET_ID   [i][j];
239            delete ICACHE_REQ_ADDRESS     [i][j];
240            delete ICACHE_REQ_TYPE        [i][j];
241            delete ICACHE_RSP_VAL         [i][j];
242            delete ICACHE_RSP_ACK         [i][j];
243            delete ICACHE_RSP_CONTEXT_ID  [i][j];
244            delete ICACHE_RSP_PACKET_ID   [i][j];
245            delete ICACHE_RSP_ERROR       [i][j];
246
247            for (uint32_t k=0; k<param->iaccess_nb_instruction[i]; k++)
248              delete ICACHE_RSP_INSTRUCTION [i][j][k];
249
250            delete [] ICACHE_RSP_INSTRUCTION [i][j];
251          }
252        delete [] ICACHE_REQ_VAL         [i];
253        delete [] ICACHE_REQ_ACK         [i];
254        delete [] ICACHE_REQ_CONTEXT_ID  [i];
255        delete [] ICACHE_REQ_PACKET_ID   [i];
256        delete [] ICACHE_REQ_ADDRESS     [i];
257        delete [] ICACHE_REQ_TYPE        [i];
258        delete [] ICACHE_RSP_VAL         [i];
259        delete [] ICACHE_RSP_ACK         [i];
260        delete [] ICACHE_RSP_CONTEXT_ID  [i];
261        delete [] ICACHE_RSP_PACKET_ID   [i];
262        delete [] ICACHE_RSP_ERROR       [i];
263        delete [] ICACHE_RSP_INSTRUCTION [i];
264      }
265   
266    delete [] ICACHE_REQ_VAL        ;
267    delete [] ICACHE_REQ_ACK        ;
268    delete [] ICACHE_REQ_CONTEXT_ID ;
269    delete [] ICACHE_REQ_PACKET_ID  ;
270    delete [] ICACHE_REQ_ADDRESS    ;
271    delete [] ICACHE_REQ_TYPE       ;
272    delete [] ICACHE_RSP_VAL        ;
273    delete [] ICACHE_RSP_ACK        ;
274    delete [] ICACHE_RSP_CONTEXT_ID ;
275    delete [] ICACHE_RSP_PACKET_ID  ;
276    delete [] ICACHE_RSP_INSTRUCTION;
277    delete [] ICACHE_RSP_ERROR      ;
278   
279    for (uint32_t i=0; i<param->nb_entity; i++)
280      {
281        for (uint32_t j=0; j<param->icache_dedicated_nb_port[i]; j++)
282          {
283            delete DCACHE_REQ_VAL        [i][j];
284            delete DCACHE_REQ_ACK        [i][j];
285            delete DCACHE_REQ_CONTEXT_ID [i][j];
286            delete DCACHE_REQ_PACKET_ID  [i][j];
287            delete DCACHE_REQ_ADDRESS    [i][j];
288            delete DCACHE_REQ_TYPE       [i][j];
289            delete DCACHE_REQ_WDATA      [i][j];
290            delete DCACHE_RSP_VAL        [i][j];
291            delete DCACHE_RSP_ACK        [i][j];
292            delete DCACHE_RSP_CONTEXT_ID [i][j];
293            delete DCACHE_RSP_PACKET_ID  [i][j];
294            delete DCACHE_RSP_RDATA      [i][j];
295            delete DCACHE_RSP_ERROR      [i][j];
296          }
297
298        delete [] DCACHE_REQ_VAL        [i];
299        delete [] DCACHE_REQ_ACK        [i];
300        delete [] DCACHE_REQ_CONTEXT_ID [i];
301        delete [] DCACHE_REQ_PACKET_ID  [i];
302        delete [] DCACHE_REQ_ADDRESS    [i];
303        delete [] DCACHE_REQ_TYPE       [i];
304        delete [] DCACHE_REQ_WDATA      [i];
305        delete [] DCACHE_RSP_VAL        [i];
306        delete [] DCACHE_RSP_ACK        [i];
307        delete [] DCACHE_RSP_CONTEXT_ID [i];
308        delete [] DCACHE_RSP_PACKET_ID  [i];
309        delete [] DCACHE_RSP_RDATA      [i];
310        delete [] DCACHE_RSP_ERROR      [i];
311      }
312
313    delete [] DCACHE_REQ_VAL        ;
314    delete [] DCACHE_REQ_ACK        ;
315    delete [] DCACHE_REQ_CONTEXT_ID ;
316    delete [] DCACHE_REQ_PACKET_ID  ;
317    delete [] DCACHE_REQ_ADDRESS    ;
318    delete [] DCACHE_REQ_TYPE       ;
319    delete [] DCACHE_REQ_WDATA      ;
320    delete [] DCACHE_RSP_VAL        ;
321    delete [] DCACHE_RSP_ACK        ;
322    delete [] DCACHE_RSP_CONTEXT_ID ;
323    delete [] DCACHE_RSP_PACKET_ID  ;
324    delete [] DCACHE_RSP_RDATA      ;
325    delete [] DCACHE_RSP_ERROR      ;
326
327    delete [] write_dram;
328    delete [] read_dram [0];
329    delete [] read_dram;
330
331    uint32_t max_nb_instruction   = morpheo::max<uint32_t>(param->iaccess_nb_instruction,param->nb_entity);
332    for (uint32_t i=0; i<max_nb_instruction; i++)
333      delete [] read_iram [i];
334    delete [] read_iram;
335
336    for (uint32_t i=0; i<param->nb_entity; i++)
337      {
338        while (not component_buffer_irsp [i]->empty())
339          {
340            delete component_buffer_irsp [i]->read(0)._data;
341            component_buffer_irsp [i]->pop();
342          }
343        while (not component_buffer_drsp [i]->empty())
344          {
345            delete component_buffer_drsp [i]->read(0)._data;
346            component_buffer_drsp [i]->pop();
347          }
348
349        delete component_buffer_irsp [i];
350        delete component_buffer_drsp [i];
351      }
352    delete [] component_buffer_irsp;
353    delete [] component_buffer_drsp;
354
355    delete    component_data;
356    delete    component_sim2os;
357    for (uint32_t i=0; i<param->nb_component_ramlock; i++)
358    delete    component_ramlock [i];
359    delete [] component_ramlock;
360    for (uint32_t i=0; i<param->nb_component_tty; i++)
361    delete    component_tty [i];
362    delete [] component_tty;
363    delete    component_cache;
364
365  }
366
367};
Note: See TracBrowser for help on using the repository browser.