Skip to content

Interrupt Approach

The usage of the interrupt-approach follows the same procedure described in the Streaming. However, the fcapi configuration and ports is different. The following example shows a one way communication, where the SystemC code sends a byte array to FERAL. These example intents to point out the difference between the two approaches.

At the same with the Streaming approach, you need to create a directory that contains the SystemC code and the C-fcapi-client configuration file. In this case the configuration file is called {"ExampleInterrupt.cpp"},

External SystemC component

The external SystemC Module must include the systemc library and only an initiatior-socket header.

SystemCModule.h
#include <systemc.h>
#include "tlm_utils/simple_initiator_socket.h"

SC_MODULE(SystemCModule) {
public:
    // Declare communication sockets
    tlm_utils::simple_initiator_socket<SystemCModule> iSocket;

    SC_CTOR(SystemCModule) {
        SC_METHOD(ISR);
        SC_THREAD(process);
        sensitive << IRQ;
        dont_initialize();
    }

    ~SystemCModule() {
    }
    void ISR () {
        sc_time delay = SC_ZERO_TIME;
        uint32_t data;
        tlm::tlm_generic_payload trans;

        // Read until buffer in LTDataPort is empty,
        // which is signalized by returning TLM_INCOMPLETE_RESPONSE
        do {
            trans.set_address(0);
            trans.set_data_length(4);
            trans.set_streaming_width(4);
            trans.set_command(tlm::TLM_READ_COMMAND);
            trans.set_data_ptr(reinterpret_cast<unsigned char*>(&data));
            trans.set_response_status( tlm::TLM_INCOMPLETE_RESPONSE );

            iSocket->b_transport(trans, delay);

        } while (trans.get_response_status() == tlm::TLM_OK_RESPONSE);
    }

    void process() {
        wait(200,SC_US);
        sc_stop();

The special part in this SystemC module is the inclusion of the ISR method that handle the Interrupt process.

FCAPI-C Client

The following cpp file contains the FERAL connection setup.

ExampleInterrupt.cpp
#include <systemc.h>
#include "systemcferal.h"
#include "feralcapi.h"

#include "SystemCModule.h" // This is the user specific SystemC code

int sc_main(int __attribute__((unused)) argc, char __attribute__((unused)) *argv[])
{

    fcapi_init();
    fcapi_logAllToStdOut();

    {
        // Setup FERAL Connection:
        Connection_t conn;
        fcapi_connectionInit(&conn, UDP, NULL, 44444, NULL, 0);

        sc_time stepSize = sc_time(10, SC_US); // Define the time step for the events

        FERALControl ctrl("Sync", &conn, stepSize); //

        // Setup SystemC Side:
        SystemCModule module("module"); 

        Connection_t txConn; // Send port
        fcapi_connectionInit(&txConn, UDP, NULL, 44444, NULL, 0);
        Connection_t rxConn; // Receive port
        fcapi_connectionInit(&rxConn, UDP, NULL, 44444, NULL, 0);

        uint32_t dataInputSize = stoi(argv[1]);

        LTDataPort dp("dataport", &rxConn, "apple", "banana", dataSize);

        // Connect all components:
        sc_signal<bool> IRQ("IRQ_Signal");

        module.IRQ.bind(IRQ);
        dp.IRQ.bind(IRQ);

        ctrl.syncPort.bind(dp);
        dp.tSocket.bind(module.iSocket);

        sc_start();

    fcapi_terminate();
    return 0;
}
As is shown in the above configuration, for the interrupt-approach, it is only necessary to create one Port using the LTDataPort class and the synchronization controls the IRQ signal.

Simulation scenario

Here also the gateway scenario is a nested class of our example class.

ExampleInterrupt.java
class Interrupt {
    static class ScenarioWithGateway extends GatewayExampleBaseScript implements Runnable {

        public ScenarioWithGateway() {
            // Simulation setup
            // - create scenario
            scenario = new SimulationScenario();
            // - create root
            director = new DiscreteEventMOCC(scenario);

            // Gateway setup
            // - Create FERAL gateway for a given backend message protocol
            createGatewayFERAL(director, TransmissionBackend.UDP, 1, 44444);

            // - create ports for TX, RX, and synchronization
            createFERALGatewayPorts(gateway, "banana", "apple", "Sync");

            // - Create receiver
            ByteArrayReceiver receiver = new ByteArrayReceiver(director);

            // - Setup links from/to SystemC modul
            new Link(gateway.getOutputPort("apple"), gateway.getInputPort("banana"));
            new Link(gateway.getOutputPort("banana"), receiver.getInputPort("input"));
        }

        // Initialize simulation scenario
        @Override
        public void run() {
            scenario.startSimulation(SimulationDuration.us (100));
        }
    }
    public static void main{
        ScenarioWithGateway scenario = new ScenarioWithGateway();
        new Thread(scenario).start();

        dataSize = "4";
        List<String> inputs = new ArrayList<>(Arrays.asList(dataSize));
        // launch system c
        List<String> stdOut = new ArrayList<>();
        final int exitCode = ExecutableRunner.runExecutableSync("target/path_to_the_compiled/C-fcapi-client_file/ExampleInterrupt", inputs, stdOut, false);

Note

ByteArrayReceiver has to be defined as is indicated in the Create a Simulation section.