How to use clock_t with time.h header file

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use clock_t with time.h header file

Jump to solution
3,049 Views
Geek19
Contributor III

Hi,

     I have Code Warrior 2.9 for MPC5566 and I try to use clock_t and clock with "time.h" header file and it is not recognized!!?? I wass wondering what would be the solution for this matter.

Thanks;

Labels (1)
Tags (3)
0 Kudos
1 Solution
1,490 Views
jorge_plascencia
NXP TechSupport
NXP TechSupport

Hi Reza,

The answer is valid for all platform/processor.

It's true for classic and eclipse tool version.

+++++++++++++++++++++++

The CodeWarrior libraries provide the time functions as are standard but these does not come with the low level functions for the operations, as stated on the MSL C reference manual:

      " Each platform must define four simple functions to provide MSL with low-level

      information from the platform hardware or operating system."

    

This is because there is no OS or driver providing the time from the MCU, so you need to write the below functions specific to your device:

      __get_clock

      __get_time

      __to_gm_time

      __to_local_time

All of these will be called by the library and with those set the functions will be fully functional.

For further information please refer to the MSL_C_Reference.pdf which you can find at:

      "\Help\PDF\MSL C Reference.pdf"

+++++++++++++++++++++++

For the MPC55xx/56xx, I've created an example on my V2.10 version.

To goal is that the library function calls the __get_clock() function you must implement.

To do that you must:

      - rebuild the MSL Lib.

            Edit the \PowerPC_EABI_Support\MSL\MSL_C\PPC_EABI\Include\ansi_prefix.PPCEABI.bare.h

            Define to 1 the macros:

/* Time Support Configuration Flags */

#ifndef _MSL_OS_TIME_SUPPORT

      #define _MSL_OS_TIME_SUPPORT  1

#endif

#ifndef _MSL_CLOCK_T_AVAILABLE

      #define _MSL_CLOCK_T_AVAILABLE      1

#endif

#ifndef _MSL_TIME_T_AVAILABLE

      #define _MSL_TIME_T_AVAILABLE 1

#endif

            Save new config and rebuild the lib.

      - in the example I've created, now when I build it with the preprocess option:

            #define _MSL_OS_TIME_SUPPORT 1

            #define _MSL_CLOCK_T_AVAILABLE 1

            #define _MSL_TIME_T_AVAILABLE 1

      I got the error:

            Link Error : undefined: '__get_clock'

            Referenced from 'clock' in MSL_C.PPCEABI.bare.VS.UC.a

Now the clock function of library is used and following the rule calls the __get_clock().

However this function must be implemented by user.

Attached you will find the example code I've created based on the MSL Example.

Rename it to test_clock.zip.

This project is using the MSL_C.PPCEABI.bare.VS.UC.a library.

To rebuild it you must open the project: \PowerPC_EABI_Support\EPPC_Build_All_VLE_Libs.mcp

      Then double click on MSL\MSL_C.VLE.bare.mcp

      Select the MSL_C.PPCEABI.bare.VS.UC

      Apply ansi_prefix.PPCEABI.bare.h modification

      Rebuild the lib

Now you will get the undefined: '__get_clock' linker error.

Hope this will help you.

View solution in original post

0 Kudos
2 Replies
1,491 Views
jorge_plascencia
NXP TechSupport
NXP TechSupport

Hi Reza,

The answer is valid for all platform/processor.

It's true for classic and eclipse tool version.

+++++++++++++++++++++++

The CodeWarrior libraries provide the time functions as are standard but these does not come with the low level functions for the operations, as stated on the MSL C reference manual:

      " Each platform must define four simple functions to provide MSL with low-level

      information from the platform hardware or operating system."

    

This is because there is no OS or driver providing the time from the MCU, so you need to write the below functions specific to your device:

      __get_clock

      __get_time

      __to_gm_time

      __to_local_time

All of these will be called by the library and with those set the functions will be fully functional.

For further information please refer to the MSL_C_Reference.pdf which you can find at:

      "\Help\PDF\MSL C Reference.pdf"

+++++++++++++++++++++++

For the MPC55xx/56xx, I've created an example on my V2.10 version.

To goal is that the library function calls the __get_clock() function you must implement.

To do that you must:

      - rebuild the MSL Lib.

            Edit the \PowerPC_EABI_Support\MSL\MSL_C\PPC_EABI\Include\ansi_prefix.PPCEABI.bare.h

            Define to 1 the macros:

/* Time Support Configuration Flags */

#ifndef _MSL_OS_TIME_SUPPORT

      #define _MSL_OS_TIME_SUPPORT  1

#endif

#ifndef _MSL_CLOCK_T_AVAILABLE

      #define _MSL_CLOCK_T_AVAILABLE      1

#endif

#ifndef _MSL_TIME_T_AVAILABLE

      #define _MSL_TIME_T_AVAILABLE 1

#endif

            Save new config and rebuild the lib.

      - in the example I've created, now when I build it with the preprocess option:

            #define _MSL_OS_TIME_SUPPORT 1

            #define _MSL_CLOCK_T_AVAILABLE 1

            #define _MSL_TIME_T_AVAILABLE 1

      I got the error:

            Link Error : undefined: '__get_clock'

            Referenced from 'clock' in MSL_C.PPCEABI.bare.VS.UC.a

Now the clock function of library is used and following the rule calls the __get_clock().

However this function must be implemented by user.

Attached you will find the example code I've created based on the MSL Example.

Rename it to test_clock.zip.

This project is using the MSL_C.PPCEABI.bare.VS.UC.a library.

To rebuild it you must open the project: \PowerPC_EABI_Support\EPPC_Build_All_VLE_Libs.mcp

      Then double click on MSL\MSL_C.VLE.bare.mcp

      Select the MSL_C.PPCEABI.bare.VS.UC

      Apply ansi_prefix.PPCEABI.bare.h modification

      Rebuild the lib

Now you will get the undefined: '__get_clock' linker error.

Hope this will help you.

0 Kudos
1,490 Views
vrushalitaklika
Contributor III

Can you please share the code? I am also trying to use clock() function without OS.

Thanks

Vrushali

0 Kudos