sc_port / sc_interface / sc_export (part 1)

一个复杂的系统我们一般会将其分为很多个比较小的模块,对于SystemC建模,每个模块一般就是一个sc_module的子类。模块间有一些交互的信息 一般通过 port/interface/channel/export 来进行传递,传递的过程其实本质上就是调用了对方的接口函数(通过operator-> 和operator[] 来实现)。也就是说,port的主要作用是 做到了解耦,比如,Module A 和Module B通过port这套方法在顶层进行了bind,那么Module A本身不需要看到Module B的指针,就能调用Module B中的某些接口上的API。

Spec 有如下说明:

Ports provide the means by which a module can be written such that it is independent of the context in which it is instantiated. A port forwards interface method calls to the channel to which the port is bound. A port defines a set of services (as identified by the type of the port) that are required by the module containing the port.

端口提供了一种方法,通过这种方法可以编写模块,使其独立于实例化它的上下文。端口将接口方法调用转发到绑定端口的通道。端口定义了包含端口的模块所需的一组服务(由端口的类型标识)。

sc_port bind number define

sc_port<IF, N, port_policy> 是所有port (端口)的基类,它是一个模板类。IF 是interface (接口)类型, N是所连接的同一类型的interface的允许的最大数目,也就是最大接口数,它的缺省值是1;N如果为0,表示无穷大。 port_policy 默认值为SC_ONE_OR_MORE_BOUND,表示这个port必须最少绑定一个interface/channel,这也是 如果代码中有sc_port 实例没有bind,导致编译通道,而仿真报错的原因;如果我们将 这个port 类型的模板参数port_policy 改为SC_ZERO_OR_MORE_BOUND,则不绑定也不会报错。

继承关系: sc_port<IF, N>  public  sc_port_b<IF>  public  sc_port_base。

enum sc_port_policy
{
SC_ONE_OR_MORE_BOUND , // Default, 必须最少绑定一个interface/channel
SC_ZERO_OR_MORE_BOUND , // 最少 可以绑定0 个,也就是允许 不绑定
SC_ALL_BOUND   // 必须绑定sc_port模板第二个参数N 个interface/channel
};

class sc_port_base
: public sc_object { implementation-defined };

template <class IF>
class sc_port_b
: public sc_port_base

template <class IF, int N = 1, sc_port_policy P = SC_ONE_OR_MORE_BOUND>
class sc_port
: public sc_port_b<IF>
sc_port<IF> // Bound to exactly 1 channel instance
sc_port<IF,0> // Bound to 1 or more channel instances with no upper limit
sc_port<IF,3> // Bound to 1, 2, or 3 channel instances
sc_port<IF,0,SC_ZERO_OR_MORE_BOUND> // Bound to 0 or more channel instances with no upper limit
sc_port<IF,1,SC_ZERO_OR_MORE_BOUND> // Bound to 0 or 1 channel instances
sc_port<IF,3,SC_ZERO_OR_MORE_BOUND> // Bound to 0, 1, 2, or 3 channel instances
sc_port<IF,3,SC_ALL_BOUND> // Bound to exactly 3 channel instances

Ports shall only be instantiated during elaboration and only from within a module. It shall be an error to instantiate a port other than within a module. It shall be an error to instantiate a port during simulation.

也就是说sc_port类型的成员变量必须在一个sc_module子类中 定义和使用,比如在sc_main 中定义一个 sc_port类型的临时变量 是不被允许的。如果执行程序时报如下错误,有可能就是这个原因。

Error: (E100) port specified outside of module: port 'port_0' (sc_port_base)

In file: ../../../../src/sysc/communication/sc_port.cpp:231

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

123axj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值