Im聲明sc_fifo爲sc_fifo_out <int> PacketTx;
並且Im試圖使用SC_THREAD
將20個樣本寫入此fifo。我在另一個SC_THREAD
閱讀了fifo的內容。我的問題是我需要在FIFO中寫入20個值,然後我才從FIFO中讀取任何內容,所以我使用sc_signal
來維護這個屬性。增加sc_fifo_out大小
下面是一個簡化的例子:
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
只讓我寫16個值的FIFO,但是我的應用我想將其提高到20,或者可能更。我試圖環顧四周,但沒有發現任何關於如何更改fifo的大小,而不是在Accellera上的論壇帖子,但這只是爲sc_fifo
,我不知道如何適應sc_fifo_out
。我試圖在我的PacketTx.h頭文件中執行sc_fifo_out<int> PacketTx(20);
,但它在語法上不合法。
我能做到這一點嗎?