Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
scClusterBusMemorySlow.h
Go to the documentation of this file.
1 
12  /* @author János Végh (jvegh)
13  * @bug No known bugs.
14  */
30 #ifndef scClusterBusMemorySlow_h
31 #define scClusterBusMemorySlow_h
32 
33 //#include <systemc.h>
34 //#include <string>
35 #include "Clustering.h"
36 class scGridPoint; class scProcessor;
37 
38 #include "scClusterBusSlave_if.h" //#include "ClusterBusTypes.h"
39 #include "scClusterBusMaster_blocking.h" // It can also be a master
40 
41 //#include "scIGPMessage.h"
42 
43 typedef struct {
44  sc_core::sc_time ReplyTime;
45  scIGPMessage* ReplyMessage;
46 } scMemoryMessageFIFO_t;
47 
48 class scMemoryMessagefifowrite_if : virtual public sc_interface
49 {
50  public:
51  virtual void write(scMemoryMessageFIFO_t*) = 0;
52  virtual void reset() = 0;
53 };
54 
55 class scMemoryMessagefiforead_if : virtual public sc_interface
56 {
57  public:
58  virtual void read(scMemoryMessageFIFO_t*&) = 0;
59  virtual int num_available() = 0;
60 };
61 
62 // This structure keeps track where the line containing the code at Address is
63 typedef struct {unsigned int Address; int Lineno; std::string Line;} AddressToLineRecord;
64 
65 
73 class scMemoryMessageFIFO : public sc_channel, public scMemoryMessagefifowrite_if, public scMemoryMessagefiforead_if
74 {
75  friend class scGridPoint;
76  friend class scClusterBusMemorySlow;
77  public:
78  scMemoryMessageFIFO(sc_module_name name) : sc_channel(name), num_elements(0), first(0) {}
79 
80  void write(scMemoryMessageFIFO_t* c) {
81  if (num_elements == max)
82  wait(scMemoryMessageFIFO_read_event);
83 
84  data[(first + num_elements) % max] = c;
85  ++ num_elements;
86 // wait(SCTIME_CLOCKTIME); // Avoid immediate notification
88  }
89 
90  void read(scMemoryMessageFIFO_t* &c){
91  if (num_elements == 0)
92  wait(scMemoryMessageFIFO_write_event);
93 
94  c = data[first];
95  -- num_elements;
96  first = (first + 1) % max;
97 // wait(SCTIME_CLOCKTIME); // Avoid immediate notification
99  }
100 
101  void reset() { num_elements = first = 0; }
102 
103  int num_available() { return num_elements;}
104 
105  private:
106  enum e { max = 8 };
107  scMemoryMessageFIFO_t* data[max];
108  uint16_t num_elements, first;
109  sc_event scMemoryMessageFIFO_write_event, scMemoryMessageFIFO_read_event;
110 };
111 
112 
126  : public scClusterBusSlave_if
127  , public sc_module
128 {
129  friend class scProcessor;
130 public:
131  // ports
132 /* ?? DO NOT USE CLOCK
133  * sc_in_clk
134  clock;
135  */
136 /* scClusterBusMaster_blocking*
137  mMaster_if;
138 */
139  SC_HAS_PROCESS(scClusterBusMemorySlow);
140 
141  // constructor
142  scClusterBusMemorySlow(sc_module_name name_
143  , unsigned int start_address
144  , unsigned int end_address
145  , unsigned int nr_wait_states);
146 /* , m_start_address(start_address)
147  , m_end_address(end_address)
148  , m_nr_wait_states(nr_wait_states)
149  , m_wait_count(-1)
150  {
151  // process declaration
152  SC_METHOD(wait_loop);
153  dont_initialize();
154  sensitive << clock.pos();
155 
156  sc_assert(m_start_address <= m_end_address);
157  sc_assert((m_end_address-m_start_address+1)%4 == 0);
158  m_size = (m_end_address-m_start_address+1)/4;
159  MEM = new int [m_size];
160  for (unsigned int i = 0; i < m_size; ++i)
161  MEM[i] = 0;
162  }*/
163 
164  // destructor
166 
167  // process
168  void wait_loop();
169  void ProcessFIFOMessages(void);
170  ClusterBusStatus
171  write(scIGPMessage* M);
172  // direct Slave Interface
173  bool direct_read(int *data, unsigned int address);
174  bool direct_write(int *data, unsigned int address);
175  bool direct_read(scIGPMessage*){return true;}
176  bool direct_write(scIGPMessage*){return true;}
177 
178  // Slave Interface
179  ClusterBusStatus read(int *data, unsigned int address);
180  ClusterBusStatus write(int *data, unsigned int address);
181  ClusterBusStatus read(scIGPMessage*){ return CLUSTER_BUS_ERROR;}
182 // ClusterBusStatus write(scIGPMessage*);
183  scIGPMessage*
184  CreateReadMessageReply(scMemoryMessageFIFO_t* M);
185  scIGPMessage*
186  CreateWriteMessage(scGridPoint* From, unsigned int Address, int Length);
187  std::string
188  StringOfClusterAddress_Get(void);
189 
190  void
191  ReadFIFO(scMemoryMessageFIFO_t *&M){ return MemoryMessagefifo->read(M);}
192  void
193  WriteFIFO(scMemoryMessageFIFO_t *&M){ return MemoryMessagefifo->write(M);}
194  scProcessor*
195  Processor_Get(void) { return m_processor;}
196  void
197  Processor_Set(scProcessor* Proc) { m_processor = Proc;}
198  string
199  PrologText_Get(void);
200  void
201  ReceiveClusterMessage(scIGPMessage* Message);
202  void
203  SendClusterMessage(scIGPMessage* Message);
204  void
205  ProcessMessage(scIGPMessage* M);
206  unsigned int
207  start_address() const;
208  unsigned int
209  end_address() const;
210  unsigned int
211  Size_Get(void){return m_size;}
212 /* inline uint32_t
213  LoadedBytes_Get(void) { return TotalBytes;}*/
214  inline uint8_t // Just for testing
215  Byte_Get(uint32_t Address){ return mem[Address];}
216  void
217  Byte_Set(uint32_t Address, uint8_t B){ mem[Address] = B;}
218  uint32_t // Just for testing
219  DWord_Get(uint32_t Address);//{ assert(!(Address%4)); return MEM[Address/4];}
220  void
221  DWord_Set(uint32_t Address, uint32_t C);//{ assert(!(Address%4)); MEM[Address/4] = C;}
222  int
223  findLinenoToAddress(SC_ADDRESS_TYPE A);
224  SC_ADDRESS_TYPE
225  findAddressToLineno(int32_t L);
226  string
227  getSourceLine(int L);
228  SC_ADDRESS_TYPE
229  StartAddress_Get(void){ return m_start_address; }
230  int
231  QueueLength_Get(void){ return MemoryMessagefifo->num_available(); }
232  void Reset(void);
233  private:
234  int *MEM;
235  unsigned int m_size;
236  scProcessor* m_processor;
237  unsigned int m_start_address;
238  unsigned int m_end_address;
239  unsigned int m_nr_wait_states;
240  int m_wait_count;
242  MemoryMessagefifo;
243  uint8_t *
244  mem;
248 //MM Log *log;
252 /* uint32_t program_counter;
253  uint32_t mInstructionAddress; ///< At which position the instruction found
254  uint32_t TotalBytes; ///< How many bytes were read
255  uint32_t TotalLines; ///< How many line are present in the object file
256 */ vector <AddressToLineRecord*> // The real data storage
257  AddressToLineMap;
258  string
259  mFileName;
260 }; // end class scClusterBusMemorySlow
261 
262 inline scClusterBusMemorySlow::~scClusterBusMemorySlow()
263 {
264  if (MEM) delete [] MEM;
265  MEM = (int *)0;
266 }
267 
268 inline void scClusterBusMemorySlow::wait_loop()
269 {
270  if (m_wait_count >= 0) m_wait_count--;
271 }
272 
273 inline bool scClusterBusMemorySlow::direct_read(int *data, unsigned int address)
274 {
275  assert((address - m_start_address)/4 < m_size);
276  *data = MEM[(address - m_start_address)/4];
277  return true;
278 }
279 
280 inline bool scClusterBusMemorySlow::direct_write(int *data, unsigned int address)
281 {
282  assert((address - m_start_address)/4 < m_size);
283  MEM[(address - m_start_address)/4] = *data;
284  return true;
285 }
286 
287 inline ClusterBusStatus scClusterBusMemorySlow::read(int *data
288  , unsigned int address)
289 {
290  assert((address - m_start_address)/4 < m_size);
291  // accept a new call if m_wait_count < 0)
292  if (m_wait_count < 0)
293  {
294  m_wait_count = m_nr_wait_states;
295  return CLUSTER_BUS_WAIT;
296  }
297  if (m_wait_count == 0)
298  {
299  *data = MEM[(address - m_start_address)/4];
300  return CLUSTER_BUS_OK;
301  }
302  return CLUSTER_BUS_WAIT;
303 }
304 
305 inline ClusterBusStatus scClusterBusMemorySlow::write(int *data
306  , unsigned int address)
307 {
308  assert((address - m_start_address)/4 < m_size);
309  // accept a new call if m_wait_count < 0)
310  if (m_wait_count < 0)
311  {
312  m_wait_count = m_nr_wait_states;
313  return CLUSTER_BUS_WAIT;
314  }
315  if (m_wait_count == 0)
316  {
317  MEM[(address - m_start_address)/4] = *data;
318  return CLUSTER_BUS_OK;
319  }
320  return CLUSTER_BUS_WAIT;
321 }
322 
323 inline unsigned int scClusterBusMemorySlow::start_address() const
324 {
325  return m_start_address;
326 }
327 
328 inline unsigned int scClusterBusMemorySlow::
329 end_address() const
330 {
331  return m_end_address;
332 }
333 
334 #endif // scClusterBusMemorySlow_h
Clustering.h
Topology information for the electronic modules arranged in a cluster.
scClusterBusMemorySlow::Processor_Get
scProcessor * Processor_Get(void)
Just remember processor for finding the cores.
Definition: scClusterBusMemorySlow.h:195
scClusterBusMemorySlow::Processor_Set
void Processor_Set(scProcessor *Proc)
Remember the processor for finding the cores.
Definition: scClusterBusMemorySlow.h:197
scIGPMessage
The scIGPMessage class.
Definition: scIGPMessage.h:97
scProcessor
Implements a module-name alias facility (i.e., user-provided names. Given that the basic units is scH...
Definition: scProcessor.h:130
scClusterBusMemorySlow
The 'far' memory of the processor.
Definition: scClusterBusMemorySlow.h:125
scMemoryMessageFIFO::write
void write(scMemoryMessageFIFO_t *c)
Definition: scClusterBusMemorySlow.h:80
scGridPoint
This class implements the autonomous grid point functionality: it is a communicating GridPoint....
Definition: scGridPoint.h:127
scMemoryMessageFIFO::read
void read(scMemoryMessageFIFO_t *&c)
Definition: scClusterBusMemorySlow.h:90
scClusterBusSlave_if.h
The inter-cluster bus states.
scMemoryMessageFIFO
Definition: scClusterBusMemorySlow.h:73