time () does nothing

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

time () does nothing

1,027 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by abaxor on Mon Jul 29 00:38:01 MST 2013
Hi,

I'm using the LPC1769 with a real time clock. Just now I want to use the time function of time.h to read the RTC. But time does nothing. How can I add some meaningful stuff to time?

Thanks,

tom
0 Kudos
5 Replies

771 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Thu Aug 01 09:05:31 MST 2013
Redlib's time() call's the function __sys_time(), which when you link with the semihosted variant of the library will call up to the host to get the time value.

http://support.code-red-tech.com/CodeRedWiki/WhatIsSemiHosting

Thus if you want to get time() to use the RTC on your system, you will need to provide your own implementation of __sys_time() that carries out the necessary accesses to the RTC to work out the time_t value to return.

unsigned int __sys_time(void);

Note that Redlib does not implement timezone support.

Regards,
LPCXpresso Support
0 Kudos

771 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Thu Aug 01 06:27:19 MST 2013
If you are using Newlib, the time functions call _gettimeofday to actually get the time.

If you provide _gettimeofday in your project (and make sure it gets linked before th system library), then you can use the RTC to get your clock values and use time() as normal.

Here is a simple example of _gettimeofday:

int
_gettimeofday (struct timeval * tp, void * tzvp)
{
  struct timezone *tzp = tzvp;
  if (tp)
    {
      tp->tv_sec = <get_seconds> ; // get the seconds from a clock source
      tp->tv_usec = <get usecs>; // get the microsconds from a clock source
    }

  /* Return fixed data for the timezone.  */
  if (tzp)
    {
      tzp->tz_minuteswest = 0;
      tzp->tz_dsttime = 0;
    }

  return 0;
}
0 Kudos

771 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by abaxor on Thu Aug 01 05:07:57 MST 2013
My problem is not to access the RTC, this works. Instead of using my own function to read the RTC I want to use the time () function of time.h. But I haven't any imagination how to adopt this function to my needs.

tom
0 Kudos

771 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cfb on Mon Jul 29 15:05:27 MST 2013
Read Chapter 27 of the LPC1769 User Manual (UM10360) for all the details of how to access the Real-Time Clock. In particular Section 27.6.3.1 describes how the Secs:Mins:Hrs:Day information is stored in the CTIME0 register.

We supply a library module called Clock and an example LPC1769 program called ShowTime with our Astrobe development system. Clock includes the following Oberon-language procedure:

<code>
PROCEDURE* GetHMS*(VAR hh, mm, ss: INTEGER);
VAR
  ctime: INTEGER;
BEGIN
  SYSTEM.GET(MCU.CTIME0, ctime);
  ss := ctime MOD 40H;
  mm := LSR(ctime, 8 ) MOD 40H;
  hh := LSR(ctime, 16 ) MOD 20H
END GetHMS;
</code>

If you want to translate this to C:

CTIME0 = 0x40024014
MOD is equivalent to %
LSR is equivalent to >>
40H is equivalent to 0x40
0 Kudos

771 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Mon Jul 29 06:02:15 MST 2013
I suggest you start off by looking at RTC example code for the part. This subject has come up several times before on the LPCXpresso forums. Thus a good place to start would be to do a forum search for "RTC LPC17".

http://www.lpcware.com/search/gss/RTC%20LPC17%20inurl%3Aforum

Regards,
LPCXpresso Support
0 Kudos