增加 sc_fifo_out 大小
Increase sc_fifo_out size
我将 sc_fifo 声明为 sc_fifo_out <int> PacketTx;
并且我正在尝试使用 SC_THREAD
将 20 个样本写入此 fifo。我在另一个 SC_THREAD
中读取了 fifo 的内容。我遇到的问题是我需要在从 fifo 读取任何内容之前将 20 个值写入 fifo,所以我使用 sc_signal
来维护这个 属性.
这是一个简化的例子:
Transmit.h
SC_MODULE(Transmit){
sc_fifo_out<int> PacketTx;
sc_inout<bool> busy;
void Tx();
SC_CTOR(Transmit){
SC_THREAD(Tx){}
}
};
Transmit.cpp
void Transmit::Tx(){
int i=0;
while(1){
if(busy == 0){
while(i!=20){
busy = 1; //Flag that specifies fifo is being used
PacketTx.write(rand()%1+10)); //Random number between 1-10;
i++;
}
busy = 0; //Done writing to fifo. Deassert flag
i = 0; //Reset counter
}
else{
wait(rand()%1+10, SC_NS);
}
}
}
Receive.h
SC_MODULE(Receive){
sc_fifo_in<int> PacketRx;
sc_inout<bool> busy;
void Rx();
SC_CTOR(Receive){
SC_THREAD(Rx){}
}
};
Receive.cpp
void Receive::Rx(){
int i=0;
while(1){
if(busy == 0){ //Check if fifo is being used
while(i!=20){
busy = 1;
PacketRx.read(); //Read 20 samples from fifo
i++;
}
busy = 0; //Done reading; Deassert flag
i = 0; //Reset counter
}
else{
wait(rand()%1+10, SC_NS); //Wait random NS duration and try again
}
}
}
Main.cpp
#include "Receive.h"
#include "Transmit.h"
int _tmain(int argc, _TCHAR* arg[]){
//Signal/Port declarations
sc_fifo<int> Packet;
sc_signal<bool> busy;
//Module Instantiation
Receive r1("Receive");
r1.busy(busy);
r1.PacketRx(Packet);
Transmit t1("Transmit);
t1.busy(busy);
t1.PacketTx(Packet);
sc_start();
return 0;
}
我 运行 遇到的问题是 sc_fifo_out
只允许我向 fifo 写入 16 个值,但是对于我的应用程序,我想将其增加到 20 个,或者可能更多。我试着环顾四周,但除了 Accellera 上的论坛 post 之外,没有找到任何关于如何更改 fifo 大小的信息,但这仅适用于 sc_fifo
,我不确定如何适应这到 sc_fifo_out
。我试图在我的 PacketTx.h header 中执行 sc_fifo_out<int> PacketTx(20);
但它在语法上无效。
有什么方法可以做到这一点?
您需要指定fifo通道的大小,即Packet
。您可以执行以下操作:
sc_fifo<int> Packet(20);
我将 sc_fifo 声明为 sc_fifo_out <int> PacketTx;
并且我正在尝试使用 SC_THREAD
将 20 个样本写入此 fifo。我在另一个 SC_THREAD
中读取了 fifo 的内容。我遇到的问题是我需要在从 fifo 读取任何内容之前将 20 个值写入 fifo,所以我使用 sc_signal
来维护这个 属性.
这是一个简化的例子:
Transmit.h
SC_MODULE(Transmit){
sc_fifo_out<int> PacketTx;
sc_inout<bool> busy;
void Tx();
SC_CTOR(Transmit){
SC_THREAD(Tx){}
}
};
Transmit.cpp
void Transmit::Tx(){
int i=0;
while(1){
if(busy == 0){
while(i!=20){
busy = 1; //Flag that specifies fifo is being used
PacketTx.write(rand()%1+10)); //Random number between 1-10;
i++;
}
busy = 0; //Done writing to fifo. Deassert flag
i = 0; //Reset counter
}
else{
wait(rand()%1+10, SC_NS);
}
}
}
Receive.h
SC_MODULE(Receive){
sc_fifo_in<int> PacketRx;
sc_inout<bool> busy;
void Rx();
SC_CTOR(Receive){
SC_THREAD(Rx){}
}
};
Receive.cpp
void Receive::Rx(){
int i=0;
while(1){
if(busy == 0){ //Check if fifo is being used
while(i!=20){
busy = 1;
PacketRx.read(); //Read 20 samples from fifo
i++;
}
busy = 0; //Done reading; Deassert flag
i = 0; //Reset counter
}
else{
wait(rand()%1+10, SC_NS); //Wait random NS duration and try again
}
}
}
Main.cpp
#include "Receive.h"
#include "Transmit.h"
int _tmain(int argc, _TCHAR* arg[]){
//Signal/Port declarations
sc_fifo<int> Packet;
sc_signal<bool> busy;
//Module Instantiation
Receive r1("Receive");
r1.busy(busy);
r1.PacketRx(Packet);
Transmit t1("Transmit);
t1.busy(busy);
t1.PacketTx(Packet);
sc_start();
return 0;
}
我 运行 遇到的问题是 sc_fifo_out
只允许我向 fifo 写入 16 个值,但是对于我的应用程序,我想将其增加到 20 个,或者可能更多。我试着环顾四周,但除了 Accellera 上的论坛 post 之外,没有找到任何关于如何更改 fifo 大小的信息,但这仅适用于 sc_fifo
,我不确定如何适应这到 sc_fifo_out
。我试图在我的 PacketTx.h header 中执行 sc_fifo_out<int> PacketTx(20);
但它在语法上无效。
有什么方法可以做到这一点?
您需要指定fifo通道的大小,即Packet
。您可以执行以下操作:
sc_fifo<int> Packet(20);