Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue logging within an embedded C function

I'd like to generate logging messages from within a C function embedded in a DML method. Take the example code below where the fib() function is called from the write() method of the regs bank. The log methods available to C all require a pointer to the current device.

Is there a way to get the device that calls the embedded function? Do I need to pass the device pointer into fib()?

dml 1.2;
device simple_embedded;
parameter documentation = "Embedding C code example for"
    + " Model Builder User's Guide";
parameter desc = "example of C code";

extern int fib(int x);

bank regs {
    register r0 size 4 @0x0000 {
        parameter allocate = false;
        parameter configuration = "none";
        method write(val) {
            log "info": "Fibonacci(%d) = %d.", val, fib(val);
        }

        method read() -> (value) {
            // Must be implemented to compile            
        }
       
    }
}

header %{
int fib(int x);
%}

footer %{
int fib(int x) {
    SIM_LOG_INFO(1, mydev, 0, "Generating Fibonacci for %d", x); 
    if (x < 2) return 1;
    else return fib(x-1) + fib(x-2);
}
%}

I want to log from an embedded C function.

like image 518
kbrunham-intel Avatar asked Sep 07 '26 21:09

kbrunham-intel


1 Answers

I solved this by passing the Simics conf_object_t pointer along to C. Just like implied in the question.

So you would use:

int fib(conf_object_t *mydev, int x) {
    SIM_LOG_INFO(1, mydev, 0, "Generating Fibonacci for %d", x); 
}

And

        method write(val) {
            log "info": "Fibonacci(%d) = %d.", val, fib(dev.obj,val);
        }
like image 147
jakobengblom2 Avatar answered Sep 10 '26 10:09

jakobengblom2