Author Topic: '_gettimeofday' compiler error when try to set RTC time using GCC compiler func  (Read 2435 times)

0 Members and 1 Guest are viewing this topic.

Offline muthukural001Topic starter

  • Regular Contributor
  • *
  • Posts: 211
  • Country: in
Hello all,

I am using Atmel studio with GCC compiler for our project. In this,I want to set RTC time using compiler time functions instead setting them manually. The below code is that what I am using to get this.

main.c
Code: [Select]
#include "samd11.h"
#include "hal_gpio.h"
#include "i2c_master.h"
#include "ISL29029.h"
#include "ISL29029_regs.h"
#include "MCP79410.h"
if(MCP79410_IsRunning())                    //If clock is already running stop it
{
   MCP79410_DisableOscillator();
}
MCP79410_Initialize();                     //Initialize RTCC with system time and date */

MCP79410.c
Code: [Select]
#include <time.h>
#include "i2c_master.h"
#include "MCP79410.h"
void MCP79410_Initialize(void)
 {
     MCP79410_SetHourFormat(H24);                //Set hour format to military time standard
     MCP79410_EnableVbat();                      //Enable battery backup
     time_t t = time(NULL);
struct tm tm1 = *localtime(&t);
     RTCC_Struct curr_time = {tm1.tm_sec,tm1.tm_min,tm1.tm_hour,tm1.tm_wday,tm1.tm_mday,tm1.tm_mon+1, ((tm1.tm_year+1900)-2000)};
     MCP79410_SetTime(&curr_time);
     MCP79410_EnableOscillator();                //Start clock by enabling oscillator
 }


When I compile the above code, I am getting "undefined reference to '_gettimeofday'. Please suggest.

Regards,
Muthu


« Last Edit: December 11, 2017, 08:47:22 am by muthukural001 »
 

Online hli

  • Frequent Contributor
  • **
  • Posts: 255
  • Country: de
time() gets the current time. What do you think where this comes from? These functions are part of the C time library, and assume a regular OS environment (read: Linux or something similar).
You need to get your tm values from the user running the program.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4196
  • Country: us
The time library from time.h/etc has all sorts of functions for manipulating time values, but YOU must provide the core _gettimeofday() function for it to use, since that's hardware-dependent.  (For example, you might choose to read the RTC chip each time, or you might read the RTC at system startup, and then increment it based on a system-level timer.)
(Your code seems to be setting the RTC time based on the system time.  Isn't that ... backward?)
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
The libraries ended up calling _gettimeofday and did not find it. In UNIX this is a syscall the kernel would provide responding with the current time in the system RTC, but here in embedded world you need to provide your own. Beware don't create a circular reference though, as it is likely you are writing a driver for the RTC.
« Last Edit: December 13, 2017, 11:07:16 am by technix »
 

Offline CM800

  • Frequent Contributor
  • **
  • Posts: 882
  • Country: 00
I guess you could say that the compiler just isn't giving you the time of day....

 :-DD

Sorry.. that's all I can contribute here.
 

Offline muthukural001Topic starter

  • Regular Contributor
  • *
  • Posts: 211
  • Country: in
Hello,


From what you said, I understood that one should set RTC time with current time values directly rather than compiler as it not support that feature.

I came up with push button switch input idea. This is to match clock with real time world signal When I press push button, it will write time values to RTC and start oscillator.


Please let me know


Regards,
Muthu
« Last Edit: December 14, 2017, 10:01:31 am by muthukural001 »
 

Offline shawty

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
ok, so when you want to use particular functions in ANY libraries that you include in your project, the library definition you include will set these up for you.

Taking the first bit of code you posed as an example:

Code: [Select]
#include "samd11.h"
#include "hal_gpio.h"
#include "i2c_master.h"
#include "ISL29029.h"
#include "ISL29029_regs.h"
#include "MCP79410.h"
if(MCP79410_IsRunning())                    //If clock is already running stop it
{
   MCP79410_DisableOscillator();
}
MCP79410_Initialize();               

See all those lines that start with "#include"? well what your doing there, is asking the compiler to go and fetch, then set up it's libraries that it has by those names.

That will then make the functions available in those libraries, available for you to call in your own code, and use the tasks that they perform.

Some of these libraries need help for m you to know what to do, and they need this help because the C language cannot always know the differences in the systems that it's running on.

When the libraries that you include, need some help, they usually want your help using something called, call backs.

A call back is similar to you, calling a function in a library, but it works the other way, and it's the library that calls YOUR CODE to get the tasks it needs doing, performed.

In your case, it appears that the libraries your using, want YOU to create a function called "_gettimeofday" so that it can get the actual time from your RTC (Or in fact anywhere you decide to get it from) and then feed it into it's own library code, so that you can then further make use of it with the other functions it provides.

Now the problem I/WE on the forum have with your request for help, is we do not know the exact library and/or functions that you are including that are making the request for this call back, so we are unable to provide much help.

What I will say however, is you'll find the answer in the documentation for the time library your using.

If the time library is the generic Linux/Gnu library, then do some googling for "The Linux Documentation Project" aka (TLDP)

The LDP, contains docs for just about every GNU C/C++ standard function (Most of it derived from the man pages available)

The bottom line however is this:

One of the libraries your using wants you to define a function for it to use in order to read the time source, and since that source is dependent on your project on the hardware your using, it cannot know in advance what the source is, and thus requires your help to define it.

Shawty
Meh....
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Hello,


From what you said, I understood that one should set RTC time with current time values directly rather than compiler as it not support that feature.

I came up with push button switch input idea. This is to match clock with real time world signal When I press push button, it will write time values to RTC and start oscillator.


Please let me know


Regards,
Muthu

You would be creating a circular reference for this. One way I have been using is to let the code default to either a fixed date, or the time of compilation of the file, if the RTC is missing contents. Then after the system is up ask the user for the accurate time.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3233
  • Country: gb
Hello,


From what you said, I understood that one should set RTC time with current time values directly rather than compiler as it not support that feature.

I came up with push button switch input idea. This is to match clock with real time world signal When I press push button, it will write time values to RTC and start oscillator.


Please let me know


Regards,
Muthu

Where are you getting your "real time world signal" from?  e.g. GPS, MSF receiver etc?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf