Jump to content

Access properties of calling Module in Interface


Recommended Posts

Hi there,

i'm currently building a host-compiled cpu/os simulator in systemC.

I therefore have defined an OS interface like this:

class OS_API : virtual public sc_core::sc_interface
{
public:
    virtual void task_create() = 0;
    virtual void task_end() = 0;
    virtual void CPU_WAIT_TIME(double t) = 0;
};

And implemented it using:

class RTOS : public sc_core::sc_module, public OS_API
{
public:
    sc_core::sc_export<OS_API> os_export{"os_export"};

    RTOS() : sc_core::sc_module(sc_core::sc_gen_unique_name("RTOS"))
    {
        os_export.bind(*this);
    }
private:
    // from OS API
    void task_create() override;
    void task_end() override;
    void CPU_WAIT_TIME(double t) override;
};

 

So i use this whole interface / channel design in the Tasks, that are supposed to be scheduled.

I defined the abstract task like this:


enum State
{
    waiting,
    ready,
    running
};

struct TCB
{
    sc_core::sc_event wakeup_event;
    int pid;
    State state;
};

class OS_Task : public sc_core::sc_module
{
public:
    SC_HAS_PROCESS(OS_Task);
    OS_Task(sc_core::sc_module_name name_);

    sc_core::sc_port<OS_API> os{"os"};

    struct TCB tcb;

    virtual void run() = 0;
};

and then i have a subclass that actually implements the task:

class Hello1 : public OS_Task
{
public:
    Hello1() : OS_Task("Hello1"){};

    virtual void run()
    {
        cout << "running Task Hello1 \n";
        os->task_create();
        for (size_t i = 0; i < 20; i++)
        {
            os->CPU_WAIT_TIME(120);
            cout << "hello from 1: " << i << "\n";
        }
        os->task_end();
    }
};

 

My question is, how can I access the callers information (OS_Task or its subclass Hello1) in the RTOS that implements the interface?

Specifically i need access to the callers TCB struct so i can put it to sleep, and the be able to wake it up later (from the RTOS)

Link to comment
Share on other sites

The simplest solution would be to pass a pointer (or reference) to OS_Task or the TCB with task_create() and task_end(). A forward declaration alogn with the OS_API class should be sufficient.

I don't know your requirements but it seems to me that your use of sc_module is sub-optimal for the purpose of modeling OS tasks. The reason is simple: you cannot create or delete sc_module after the elaboration phase. And OS tasks tend to be dynamic... So sc_object and sc_spawn might be a better solution.

I assume that task_create() and task_end() always surround the behavior of a task. So why not move them into the OS_Task itself? If you pass then the TCB as pointer or by reference you could encapsulate the entire stuff of task handling in the OS_task class...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...