orca-sim
DmaNetif.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * This file is part of project ORCA. More information on the project
3  * can be found at the following repositories at GitHub's website.
4  *
5  * http://https://github.com/andersondomingues/orca-sim
6  * http://https://github.com/andersondomingues/orca-software
7  * http://https://github.com/andersondomingues/orca-mpsoc
8  * http://https://github.com/andersondomingues/orca-tools
9  *
10  * Copyright (C) 2018-2020 Anderson Domingues, <ti.andersondomingues@gmail.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 ******************************************************************************/
26 #ifndef MODELS_ORCA_NETWORK_INTERFACE_INCLUDE_DMANETIF_HPP_
27 #define MODELS_ORCA_NETWORK_INTERFACE_INCLUDE_DMANETIF_HPP_
28 
29 // usually equals to routers' buffer len
30 #ifndef NI_BUFFER_LEN
31 #define NI_BUFFER_LEN 16
32 #pragma message "NI buffer length undefined, defaulting to 16"
33 #endif
34 
35 // std API
36 #include <iostream>
37 #include <string>
38 
39 // simulator API
40 #include "TimedModel.hpp"
41 #include "Buffer.hpp"
42 #include "Memory.hpp"
43 #include "Signal.hpp"
44 
50 
52 
57 // @todo(ad): maybe make it generic<T>
58 typedef uint16_t FlitType;
59 
64 enum class DmaNetifRecvState{
65 
66  RELOAD_WAIT, // wait for a flit to "wake up" the ni
67  RELOAD_SIZE, // wait for the size of the burst
68  RELOAD_COPY, // copy raw payload into memory
69  RELOAD_FLUSH, // ?
70 
71  WAIT_ADDR_FLIT, // wait some flit to arrive at the local port
72  WAIT_SIZE_FLIT, // read size flit to determine how many will come next
73  WAIT_PAYLOAD, // wait for remaining flits to arrive, and interrupt
74  WAIT_CONFIG_STALL, // wait for the cpu to configure the dma
75  COPY_RELEASE, // stalls cpu, copy data, and release
76  FLUSH // waits for the CPU to lower the recv signal
77 };
78 
83 enum class DmaNetifSendState{
84  WAIT_CONFIG_STALL, // wait cpt to configure and raise _sig_send, stall
85  COPY_AND_RELEASE, // copy content from memory, release cpu
86  SEND_DATA_TO_NOC, // write data to the network, raise _send_status
87  FLUSH // wait for the cpu to lower the send signal (ack)
88 };
89 
98 class DmaNetif: public TimedModel{
99  private:
100  // Pointer to main memory, recv mem, and send mem
102  Memory* _mem1; // recv_mem
103  Memory* _mem2; // send_mem
104 
105  // States for send and recv processes
108 
109  // store temporary flits
110  FlitType _recv_reg;
111  FlitType _send_reg;
112 
113  // CPU interface
120 
124 
126 
127  // recv specific vars
128  uint32_t _recv_payload_size; // total size of the payload (flits)
129  uint32_t _recv_payload_remaining; // number of flits received or sent
130  uint32_t _recv_address; // memory position to which to write to
131 
132  // send specific vars
133  uint32_t _send_payload_size; // total size of the payload (flits)
134  uint32_t _send_payload_remaining; // number of flits to copy to the noc
135  uint32_t _send_address; // memory position to which to read from
136 
137  // NoC router interface. Both the NI and Router have buffers at the input
140 
141  public:
142  // state getters
143  DmaNetifRecvState GetRecvState();
144  DmaNetifSendState GetSendState();
145 
146  // getters
147  Signal<uint8_t>* GetSignalStall();
148  Signal<uint8_t>* GetSignalIntr();
149  Signal<uint8_t>* GetSignalProgSend();
150  Signal<uint8_t>* GetSignalProgRecv();
151  Signal<uint8_t>* GetSignalRecvReload();
152  Signal<uint8_t>* GetSignalSendStatus();
153 
154  Signal<uint32_t>* GetSignalRecvStatus();
155  Signal<uint32_t>* GetSignalProgAddr();
156  Signal<uint32_t>* GetSignalProgSize();
157 
158  Signal<uint16_t>* GetSignalProgDest();
159 
160  // setters
161  void SetSignalStall(Signal<uint8_t>*);
162  void SetSignalIntr(Signal<uint8_t>*);
163  void SetSignalSendStatus(Signal<uint8_t>*);
164  void SetSignalProgSend(Signal<uint8_t>*);
165  void SetSignalProgRecv(Signal<uint8_t>*);
166  void SetSignalRecvReload(Signal <uint8_t>*);
167 
168  void SetSignalRecvStatus(Signal<uint32_t>*);
169  void SetSignalProgAddr(Signal<uint32_t>*);
170  void SetSignalProgSize(Signal<uint32_t>*);
171 
172  void SetSignalProgDest(Signal<uint16_t>*);
173 
174  // internal processes
175  void sendProcess();
176  void recvProcess();
177 
178  // other
179  SimulationTime Run();
180  void Reset();
181 
182  // memories
183  void SetMem0(Memory*);
184  void SetMem1(Memory*);
185  void SetMem2(Memory*);
186 
187  // buffers
188  void SetOutputBuffer(Buffer<FlitType>* ob); // packets go to router
189  Buffer<FlitType>* GetInputBuffer(); // packets come from router
190 
191  // ctor./dtor.
192  explicit DmaNetif(std::string name);
193  ~DmaNetif();
194 };
195 
196 
197 } // namespace orcasim::models::orca
198 #endif // MODELS_ORCA_NETWORK_INTERFACE_INCLUDE_DMANETIF_HPP_
Signal< uint32_t > * _sig_prog_size
Definition: DmaNetif.hpp:123
The Signal class models a generic bus of width equals to the sizeof(T)
Definition: Signal.hpp:45
Signal< uint8_t > * _sig_stall
Definition: DmaNetif.hpp:114
Signal< uint8_t > * _sig_send_status
Definition: DmaNetif.hpp:119
This class models a TimedModel.
Definition: TimedModel.hpp:42
Signal< uint16_t > * _sig_prog_dest
Definition: DmaNetif.hpp:125
Signal< uint8_t > * _sig_prog_send
Definition: DmaNetif.hpp:117
DmaNetifRecvState _recv_state
Definition: DmaNetif.hpp:106
Signal< uint8_t > * _sig_recv_reload
Definition: DmaNetif.hpp:116
Signal< uint8_t > * _sig_intr
Definition: DmaNetif.hpp:115
Buffer< FlitType > * _ib
Definition: DmaNetif.hpp:138
Buffer< FlitType > * _ob
Definition: DmaNetif.hpp:139
uint32_t SimulationTime
Signal< uint32_t > * _sig_recv_status
Definition: DmaNetif.hpp:121
uint16_t FlitType
flit
Definition: DmaNetif.hpp:58
DmaNetifSendState _send_state
Definition: DmaNetif.hpp:107
Signal< uint32_t > * _sig_prog_addr
Definition: DmaNetif.hpp:122
This class models a memory module.
Definition: Memory.hpp:55
Signal< uint8_t > * _sig_prog_recv
Definition: DmaNetif.hpp:118