This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Get CPU's machine cicles from the C Scripting interface

Hi all,

Is it possible to get the CPU's machine cicles from a C script? I'm using the C Scripting feature of the uVision3, and I need to syncronise the scripts with the simulation. For example, i need to have a C script that will togle a pn after a specific number of machine cicles.... Is it possible?

Best regards,
Marius

  • i need to have a C script that will togle a pn after a specific number of machine cicles.... Is it possible?
    I have no idea what a "C script" is, but can tell you that anything "after a specific number of machine cycles" require coding in assembler.

    Erik

  • I'm using the C Scripting feature of the uVision3,

    You're being a little hard to understand there. That's the language of debugger functions you're talking about. Yes, it looks and works a lot like C. But it's not C, nor is it really a script language --- it's somewhere in between.

    For example, i need to have a C script that will togle a pn after a specific number of machine cicles.... Is it possible?

    Yes. See the debugger script help file about twatch() and swatch() and friends (GS51.pdf, "uVision Debugger functions"

  • The µVision3 Debugger incorporates a C script language you can use to create signal functions that simulate analog and digital input to the microcontroller. Signal functions run in the background while µVision3 simulates your target program.

    This is from the uVision3 brochure. I need to use this feature in order to have some regression tests on my code. I tryed it, and it works nice.
    The issue is that i need to have the C scripts syncronized with the simulation... and for this, i need a methode to read the simul. machine cycles from my signal functions.

  • Thanks Hans,

    I will check the GS51.pdf manual. Please see my previsios for a more detailed description of what i'm needed. It is difficult to explain my self when I have 40C and the boss is putting a big pressure on your shoulders. :)

    A nice day to you.

  • Hi all,

    I managed to find an answer to my problem; it is much simple than i was expected.

    µVision3 includes a number of predefined debug functions that are always available from the debuger's simulation function.
    Those are:
    - void rwatch (ulong address) -> Delay execution of signal function until read access to address
    - void swatch (float seconds) -> Delay execution of signal function for specified time
    - void twatch (ulong states) -> Delay execution of signal function for specified number of CPU states
    - void wwatch (ulong address) -> Delay execution of signal function until write access to address

    All of these are very useful to syncronize your debug function with the simulator.
    Moreover, the debuger provide system variables that are very usefull in case that you need the syncronization:
    - $ unsigned long represents the program counter. You may use $ to display and change the program counter. For example, $ = 0x4000sets the program counter to address 0x4000.
    - states unsigned long current value of the CPU instruction state counter; starts counting from 0 when your target program begins execution and increases for each instruction that is executed.

  • Hope this will help you.

    Configure a timer in auto reload mode and assign the source of the timer as sysclk/1. You can check the timer value to get a count on sysclk cycles. If your desired value exceeds the size of the timer then you have to handle the situatiuon using the ISR of the timer.

  • assign the source of the timer as sysclk/1

    HOW?

    since no derivative has been stated i doubt he is using a derivative where that is possible.

    Erik

  • Erik, if he is using such a derivative, he can make use of my post. Or even if he is using different system clock and timer clock, he can just calculate the ratio between the two clocks and use the same procedure to get the number of sysclks.

    Anyway, thanking for reminding me this point.

  • Hey!
    Be aware that when you are doing a regression test on a specific code, a MUST is that the test itself should not make any changes in the code. Using additional HW resources is not possible. Otherwise you will have big differences in the tests running on the simulator and on the silicon.

    The solution is a simple one, please review my prevision replies.