infineon4engineers Facebook

infineon@google+ Google+

infineon@linkedin linkedin

infineon4engi@twitter twitter

infineon@youtube youtube

Dave

+ Reply to Thread
Results 1 to 5 of 5

Thread: Get current system clock time

  1. #1
    New Member New Member kobi1 is on a distinguished road
    Join Date
    May 2017
    Posts
    4
    Points
    42.5

    Get current system clock time

    I am working on porting some piece of software for the Infineon Tricore TC29x. The software requires a function to return the current system clock time measured in system ticks.

    Can it be done using some iLLD framework functions?

    I know I can get the frequency of a system timer module with the function below.

    Code:
    IfxStm_getFrequency(&MODULE_STM0);

  2. #2
    Advanced Advanced cwunder is on a distinguished road
    Join Date
    Feb 2015
    Location
    USA
    Posts
    31
    Points
    705
    I am not sure if this answers your question.

    The STM has the following features:
    • Free-running 64-bit counter
    • All 64 bits can be read synchronously
    • Different 32-bit portions of the 64-bit counter can be read synchronously
    • Flexible service request generation based on compare match with partial STM content
    • Counting starts automatically after an Application Reset
    • STM registers are reset by an Application Reset if bit ARSTDIS.STMxDIS is cleared. If bit ARSTDIS.STMxDIS is set, the STM registers are not reset.

    The iLLD function IfxStm_get provides the 64-bit value of the STM. By reading this and knowing its frequency you know the number of system ticks that have occurred since it was reset.

  3. #3
    Hi,

    Quote Originally Posted by kobi1 View Post
    I am working on porting some piece of software for the Infineon Tricore TC29x. The software requires a function to return the current system clock time measured in system ticks.

    Can it be done using some iLLD framework functions?

    I know I can get the frequency of a system timer module with the function below.

    Code:
    IfxStm_getFrequency(&MODULE_STM0);
    You may want to take a look at the Time Demo. It installs a user handler derived from STM. To create this project you need to do the following:
    • Select File > New > Example
    • Press Next
    • Expand the TriCore Free Entre Toolchain tree
    • Expand the Time Demo tree
    • Select AppKit-TC297TFT
    • Press Finish

    In this example module timer.c implements everything related to STM. Its code is used in timerdemo.c to drive 4 LED's on your application kit. Note these two lines very early on in main:

    Code:
        /* initialise timer at SYSTIME_CLOCK rate */
        TimerInit(SYSTIME_CLOCK);
        /* add own handler for timer interrupts */
        TimerSetHandler(my_timer_handler);
    Variable runcount will now be incremented every 100 ms and is used to toggle each LED at specific time intervals. With some minor changes you can also use it to drive the ANSI-C clock() function. For this create a new module called times.c and add it to your the above example. Add the following code to this module:

    Code:
        #include <stddef.h>
        #include <sys/times.h>
        #include <sys/time.h>
    
        #include "bspconfig.h"
    
        extern volatile unsigned int runcount;
    
        clock_t times (struct tms *buf)
        {
            clock_t clk = (clock_t )runcount;
            if (buf != NULL) {
                buf->tms_utime = clk;
                buf->tms_stime = 0;
                buf->tms_cutime = 0;
                buf->tms_cstime = 0;
            }
            return clk;
        };
    Note that it makes a reference to runcount so you must make sure to remove the static keyword in its declaration in timerdemo.c. Now add the following global variables to timerdemo.c:

    Code:
        #include <time.h>
        volatile double dt;
        volatile clock_t t0;
    At the beginning of main add:

    Code:
       t0 = clock();
    And in the loop that counts down minutes add the following:

    Code:
        if (60 == ++Seconds)
        {
            dt = 1.0*(clock()-t1)/SYSTIME_CLOCK;
    If you now proceed to debug this application using the integrated UDE you can place a watch on dt and set a runtime refresh rate by right-clicking it in the watch window. Next let the target run free. At every beat of LED2 dt will now be updated with 60 seconds. Hope this helps.

    Best regards,

    Henk-Piet Glas
    Principal Technical Specialist

  4. #4
    New Member New Member kobi1 is on a distinguished road
    Join Date
    May 2017
    Posts
    4
    Points
    42.5
    Thank you for your thorough answer! It helped a lot.

  5. #5
    Quote Originally Posted by kobi1 View Post
    Thank you for your thorough answer! It helped a lot.
    Brilliant. Good to hear that. Happy developing.

    Best regards,

    Henk-Piet Glas
    Principal Technical Specialist

+ Reply to Thread

Tags for this Thread

Disclaimer

All content and materials on this site are provided “as is“. Infineon makes no warranties or representations with regard to this content and these materials of any kind, whether express or implied, including without limitation, warranties or representations of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, whether express or implied, is granted by Infineon. Use of the information on this site may require a license from a third party, or a license from Infineon.


Infineon accepts no liability for the content and materials on this site being accurate, complete or up- to-date or for the contents of external links. Infineon distances itself expressly from the contents of the linked pages, over the structure of which Infineon has no control.


Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Usage Terms of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Usage Terms of this site. Infineon reserves the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.