MatchLib
All Classes Namespaces Files Functions Modules Pages
CombinationalBufferedPorts.h
1/*
2 * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16//========================================================================
17// CombinationalBufferedPorts.h
18//========================================================================
19
20
21#ifndef COMBINATIONAL_BUFFERED_PORTS_H_
22#define COMBINATIONAL_BUFFERED_PORTS_H_
23
24#include <nvhls_connections.h>
25
26namespace Connections {
27
28 template <typename Message, int BufferSizeRead = 1, int BufferSizeWrite = 1>
29 class CombinationalBufferedPorts : public Combinational<Message> {
33
34 public:
36 : Combinational<Message>(),
37 fifo_read(),
38 fifo_write()
39 {}
40
41 explicit CombinationalBufferedPorts(const char* name)
42 : Combinational<Message>(name),
43 fifo_read(),
44 fifo_write()
45 {}
46
47 void ResetRead() {
48 Combinational<Message>::ResetRead();
49 fifo_read.reset();
50 }
51
52 void ResetWrite() {
53 Combinational<Message>::ResetWrite();
54 fifo_write.reset();
55 }
56
57 // Empty
58 bool EmptyRead() { return fifo_read.isEmpty(); }
59
60 Message Pop() { return fifo_read.pop(); }
61
62 void IncrHeadRead() { fifo_read.incrHead(); }
63
64 Message PeekRead() { return fifo_read.peek(); }
65
66 void TransferNBRead() {
67 if (!fifo_read.isFull()) {
68 Message msg;
69 if (Combinational<Message>::PopNB(msg)) {
70 fifo_read.push(msg);
71 }
72 }
73 }
74
75 // Full
76 bool FullWrite() { return fifo_write.isFull(); }
77 // Empty
78 bool EmptyWrite() { return fifo_write.isEmpty(); }
79
80 AddressPlusOne NumAvailableWrite() { return fifo_write.NumAvailable(); }
81
82 void Push(const Message& msg) { fifo_write.push(msg); }
83
84 void TransferNBWrite() {
85 if (!fifo_write.isEmpty()) {
86 Message msg = fifo_write.peek();
87 if (Combinational<Message>::PushNB(msg)) {
88 fifo_write.pop();
89 }
90 }
91 }
92
93 // Overload these so we don't accidently call them
94 virtual bool PopNB(Message& data) { NVHLS_ASSERT_MSG(0,"Calling PopNB on Buffered port is not valid"); return false; }
95 virtual bool PushNB(const Message& m) { NVHLS_ASSERT_MSG(0,"Calling PushNB on Buffered port is not valid"); return false; }
96 };
97
98
99 template <typename Message, int BufferSizeRead>
100 class CombinationalBufferedPorts <Message,BufferSizeRead,0> : public Combinational<Message> {
102
103 public:
105 : Combinational<Message>(),
106 fifo_read()
107 {}
108
109 explicit CombinationalBufferedPorts(const char* name)
110 : Combinational<Message>(name),
111 fifo_read()
112 {}
113
114 void ResetRead() {
115 Combinational<Message>::ResetRead();
116 fifo_read.reset();
117 }
118
119 // Empty
120 bool EmptyRead() { return fifo_read.isEmpty(); }
121
122 Message Pop() { return fifo_read.pop(); }
123
124 void IncrHeadRead() { fifo_read.incrHead(); }
125
126 Message PeekRead() { return fifo_read.peek(); }
127
128 void TransferNBRead() {
129 if (!fifo_read.isFull()) {
130 Message msg;
131 if (Combinational<Message>::PopNB(msg)) {
132 fifo_read.push(msg);
133 }
134 }
135 }
136
137 // Overload these so we don't accidently call them
138 virtual bool PopNB(Message& data) { NVHLS_ASSERT_MSG(0,"Calling PopNB on Buffered port is not valid"); return false; }
139 };
140
141 template <typename Message, int BufferSizeWrite>
142 class CombinationalBufferedPorts<Message,0,BufferSizeWrite> : public Combinational<Message> {
145
146 public:
148 : Combinational<Message>(),
149 fifo_write()
150 {}
151
152 explicit CombinationalBufferedPorts(const char* name)
153 : Combinational<Message>(name),
154 fifo_write()
155 {}
156
157 void ResetWrite() {
158 Combinational<Message>::ResetWrite();
159 fifo_write.reset();
160 }
161
162 // Full
163 bool FullWrite() { return fifo_write.isFull(); }
164 // Empty
165 bool EmptyWrite() { return fifo_write.isEmpty(); }
166
167 AddressPlusOne NumAvailableWrite() { return fifo_write.NumAvailable(); }
168
169 void Push(const Message& msg) { fifo_write.push(msg); }
170
171 void TransferNBWrite() {
172 if (!fifo_write.isEmpty()) {
173 Message msg = fifo_write.peek();
174 if (Combinational<Message>::PushNB(msg)) {
175 fifo_write.pop();
176 }
177 }
178 }
179
180 // Overload these so we don't accidently call them
181 virtual bool PushNB(const Message& m) { NVHLS_ASSERT_MSG(0,"Calling PushNB on Buffered port is not valid"); return false; }
182 };
183
184};
185#endif // COMBINATIONAL_BUFFERED_PORTS_H_
Configurable FIFO class.
Definition fifo.h:65
#define NVHLS_ASSERT_MSG(X, MSG)
#define NVUINTW(width)
Definition nvhls_types.h:35
Compute index width of a constant.
Definition nvhls_int.h:285