Sc_inout<bool> 不改变值

Sc_inout<bool> Not changing value

我正在尝试调试我编写的一个更大的程序,我提取了一个线程,该线程基本上是将 24 个值的数组写入 fifo,另一端是另一个线程,它应该只读取数据全部写完后

Transmit.h

#include "stdafx.h"
#include <iostream>
SC_MODULE(Transmit){
    sc_inout <bool> ServerTx;
    sc_fifo_out<int> PacketTx;

    void Tx();

    SC_CTOR(Transmit){
        sc_fifo<int> PacketTx(24);
        SC_THREAD(Tx){}
    }
};

Transmit.cpp

#include "stdafx.h"
#include "Transmit.h"

void Transmit::Tx(){
    int imageInfo[24] = { 1, 3, 2, 4, 1, 200, 600, 400, 800, 2, 400, 200, 600, 400, 3, 600, 400, 800, 600, 4, 800, 600, 1000, 800 };
    while (1){
        if (ServerTx == 0){
            cout << "ServerTx Before Write: " << ServerTx << endl;
            for (int i = 0; i < 24; i++){
                cout << "Transmit Value: " << imageInfo[i] << endl;
                PacketTx.write(imageInfo[i]);
            }
            ServerTx = 1;
            cout << "ServerTx After Write: " << ServerTx << endl;
        }
        else{
            cout << "Done Transmitting Packet." << endl;
        }
    }
}

Main.cpp

#include "stdafx.h"
#include "Transmit.h"

int _tmain(int argc, _TCHAR* argv[])
{
    sc_signal <bool> ServerTx;
    sc_fifo<int> Packet(24);

    Transmit t1("Transmit");
    t1.PacketTx(Packet);
    t1.ServerTx(ServerTx);

    ServerTx = 0;
    sc_start();
    return 0;
}

我看到的是,无论我声明信号的类型如何 ServerTx它从不更新它的值。我不知道 systemC 是否有更新信号值的延迟,但我不知道从这里该做什么。我将这个简单的握手扩展到我编写的更大的程序中,如果这不起作用,那么我可能不得不放弃整个程序。

这是我所看到的调试打印输出。我希望 ServerTx 等于 1,因为我只是设置了它的值,但它保持为 0。不知道发生了什么,或者我是否误解了 SystemC 中的某些内容。

更新:

在 while 循环后添加 wait(SC_ZERO_TIME); 可以更改 ServerTx 的值,但现在当我添加接收代码时,出现以下错误:

这是我的接收码:

#include "stdafx.h"
#include "Receive.h"

    void Receive::Rx(){
        while (1){
            if (ServerTx == 1){
                cout << "ServerTx before Read: " << ServerTx << endl;
                for (int i = 0; i < 24; i++){
                    imageInfo[i] = PacketRx.read();
                    cout << "Receive Value: " << imageInfo[i] << endl;
                }
                ServerTx = 0; //Done reading server packet data
                cout << "ServerTx after Read: " << ServerTx << endl;
            }
            else{
                wait(10, SC_NS);
            }
            wait(SC_ZERO_TIME);
        }
    }

我将 Main.cpp 更改为以下内容:

#include "stdafx.h"
#include "Receive.h"
#include "Transmit.h"

int _tmain(int argc, _TCHAR* argv[])
{
    sc_signal <bool> ServerTx;
    sc_fifo<int> Packet(24);

    Receive r1("Receive");
    r1.PacketRx(Packet);
    r1.ServerTx(ServerTx);

    Transmit t1("Transmit");
    t1.PacketTx(Packet);
    t1.ServerTx(ServerTx);

    ServerTx = 0;
    sc_start();


    return 0;
}

在您的 Transmit::Tx 线程中,您不允许将控制权交还给 SystemC 内核。

SystemC 是一个协作式多任务模拟环境。这意味着您需要定期将模拟状态与 SystemC 内核同步。

尝试在 Transmit.cpp 中进行此修改以在您的模拟中添加增量延迟:

#include "stdafx.h"
#include "Transmit.h"

void Transmit::Tx(){
  int imageInfo[24] = { 1, 3, 2, 4, 1, 200, 600, 400, 800, 2, 400, 200, 600, 400, 3, 600, 400, 800, 600, 4, 800, 600, 1000, 800 };
  while (1){
    if (ServerTx == 0){
      cout << "ServerTx Before Write: " << ServerTx << endl;
      for (int i = 0; i < 24; i++){
          cout << "Transmit Value: " << imageInfo[i] << endl;
          PacketTx.write(imageInfo[i]);
      }
      ServerTx = 1;
      cout << "ServerTx After Write: " << ServerTx << endl;
    }
    else{
      cout << "Done Transmitting Packet." << endl;
    }
    wait(SC_ZERO_TIME); //< Delta Delay
  }
}

备注:

  1. 为了更好地理解 SystemC 标准,您可以参考 SystemC LRM
  2. 如果您可以从 Ground Up(第 2 版)访问 SystemC 的硬拷贝。

参考:Chapter 2 section 2.4 page: 29关于SystemC模拟内核。 (或查看 google 图书快照 here)。