PieterNuyts
PieterNuyts

Reputation: 579

Difference between sc_port and sc_export

Can someone clearly and intuitively explain what is the difference between an sc_port and an sc_export in SystemC? When does one use a port, and when an export?

I've been reading portions of the manual but I still fail to grasp the main conceptual difference between the two.

Upvotes: 4

Views: 2702

Answers (2)

ASICcoder
ASICcoder

Reputation: 99

SystemC requirement is that every port or export MUST be bound/connected to a channel (exception of unbound ports, but let us ignore them for now). Where this channel is instantiated is what differentiates ports and exports.

For an export, the channel instance MUST reside within the same module that has the export, or inside a submodule located inside it.

For a port, the channel instance MUST reside outside the module with the port.

Imagine a module top_module with two submodules sender and receiver instantiated inside it with a one-bit data connecting sender to receiver. If you choose to make the sender's output data to be of type sc_port<>, then you will need to instantiate the channel, say sc_signal<>, in the top_module and the bind statement would ideally be in the constructor of the top_module. But if you choose to make the sender's output data to be of type sc_export<>, then you will need to instantiate the channel inside the submodule sender. Because you are essentially "exporting" the functionality of the channel to the world outside of sender.

This is my intuitive understanding of ports and exports. Please take my "MUST" statement with a grain of salt as the Accellera implementation enforces no such rule but has more to do with binding order (top-down vs bottom-up) than anything else.

As a thumb-rule, I always use exports for outputs and ports for inputs for all my modules. My philosophy is, "you drive it, you own it".

Upvotes: 6

Jellybaby
Jellybaby

Reputation: 996

From IEEE Standard for Standard SystemC ® Language Reference Manual

Class sc_export allows a module to provide an interface to its parent module. An export forwards interface method calls to the channel to which the export is bound. An export defines a set of services (as identified by the type of the export) that are provided by the module containing the export.

Providing an interface through an export is an alternative to a module simply implementing the interface. The use of an explicit export allows a single module instance to provide multiple interfaces in a structured manner.

If a module is to call a member function belonging to a channel instance within a child module, that call should be made through an export of the child module.

The upshot of all this being that without sc_export one would need to create an sc_port in the parent module and connect it to the port of the child module in order to expose a child's port as a port of the parent module. Using sc_export allows one to directly expose a child port as port of the parent module. Simply create an instance of sc_export and bind it to a child port.

For a full description and class specification see section 5.13 of IEEE Standard for Standard SystemC ® Language Reference Manual

p.s. If you do not intend to convert your code to VHDL then there is no need to use sc_export. SystemC is just standard C++ and ports are just normal public members (you could have a private port but there hardly seems much point) so you can just take a reference to it and pretend that it's a member of its parent module or any other module that has access to it for that matter.

Upvotes: 1

Related Questions