Using Simulink Coder - Atomic Change of Multidimensional Parameters (Matrix, Vector)

I am using Simulink and Simulink Coder to create arbitrary model dlls. My C application is using mathworks CAPI. It runs arbitrary models (hard real time below 1ms) and is capable of changing any model parameters (via tunable parameters).

For scalar simlpe values, I get the address of the value.

pseudocode:

void* simplegain = rtwCAPI_GetSignalAddrIdx()
*simplegain=42;

      

Everything works fine. However, this approach cannot be applied if I want to atomic change the total vector and matrix.

For multidimensional data, I used memcopy to write all values ​​from the destination to the result GetSignalAddIdx()

. Measurements have shown that using memcopy should slow down. Analysis of the generated code reveals various callsrt_Lookup

real_T rt_Lookup(const real_T *x, int_T xlen, real_T u, const real_T *y)
// x is the pointer the matrix The Adress of the matrix is declared in a global structure  `rtDataAddrMap` statically. I can read it out, but do not know how to change.

      

What I like is:

  • Define a second card in my application (same size).
  • Write down the entire new value of this second card.
  • Change only the pointer in rtDataAddrMap

    to activate the second card.

General question: How can I achieve multidimensional change of multidimensional parameters? What's the usual way to do this? (Code generation options, etc.)

Specific question: (if my approach was correct) What are the sane solutions to change the matrix data pointer?

+3


source to share


1 answer


Atomic in the sense of invoking an instruction that does its job in one clock cycle (and therefore cannot be interrupted) is impossible to achieve when it comes to this kind of multidimensional arrays. Instead, you will need some kind of real-time mechanism like a mutex or semaphore to protect your data. Mutexes and semaphores are based on atomic operations, which ensure that no two processes can use the same resource at the same time.



Your ping-pong buffering approach of your data area will likely improve performance. Unfortunately, I don't have enough experience with the code generated by Mathworks to tell you how to implement it.

0


source







All Articles