This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Accurate MSP430 function max instruction cycle prediction?

Hello,

MSP430 CPUs are used without external memory, both instruction and data are contained in internal RAM/flash, and there is usually no data/instruction cache nor multicore pipeline/optimization.

If our purpose is to guarantee real-time response for some function, then is there a way to calculate maximum cycles for the function to return?

We generally assume no other interrupts will be invoked during call of the function, and the control flow of the function is well-defined and code is well written (no syntax error, size overflow, incorrect address access, etc.).

The function’s internal might have if/else/switch/while, which translates to JMP etc. instructions. We make sure no bugs like infinite loop, etc. exist.

Using TI tools like cg_xml, we can calculate max stack depth for each function; Similarly, is there a way to get the maximum instructions needed for the function? For example, can the compiler calculate linear (count instruction) length of each switch branches, they use the max of all branches as the max instruction cycle length, at least for the switch statement?

 

This should be basic problems for real-time system design and TI should have extensive experience with it. Please advise us of any tools/solutions available.

 

 

John

  • >The function’s internal might have if/else/switch/while, which translates to JMP etc. instructions.
    If your code flow depends on data then there's no such tool which could count cycles needed.
  • Analysis of maximum runlength is only possible for 'pure' functions, that is, functions that do not rely on any internal state or external influence other than the passed parameters, and functions that do not contain any loops.
    But for a pure function with loops, it is still difficult to do a worst-case analysis.

    If a maximum execution time needs to be obeyed, sometimes a state machine can be used. Here the function will simply pass-through without any loops. Any looping would be reflected in a state change and the function needs to be called again later.
    I use this for an asynchronous bus communication: the function has an internal state and returns 'call_later' if it needs to be called again. Or returns 'succeed' or 'failure' if it is done. For the result, a pointer to a result storage is passed to the function. In my case, it is a multi-ping-pong communication with maybe long delays, but one call is always done in a few hundred CPU clock cycles. A similar setup is used for initializing an SD card.

    It doesn't help, however, if you require the final result in a defined time.

**Attention** This is a public forum