You are on page 1of 9

Control de tiempo

básico
Variables globales
SEC_TIMER, MS_TIMER y TICK_TIMER (1/1024 segundos) son
variables shared del sistema.

Son unsigned long

Se leen tras el reset del RTC (real time clock), pero


después son mantenidas por el sistema.

No modificarlas (las usa TCP/IP, cofunciones, etc…)


Ejemplo 1
#define N 10000
main(){ timeit(); }
nodebug timeit(){
unsigned long int T0;
float T2,T1;
int x,y;
int i;
T0 = MS_TIMER;
for(i=0;i<N;i++) { }
// T1 gives empty loop time
T1=(MS_TIMER-T0);
T0 = MS_TIMER;
for(i=0;i<N;i++){ x+y;}
// T2 gives test code execution time
T2=(MS_TIMER-T0);
// subtract empty loop time and convert to time for single pass
T2=(T2-T1)/(float)N;
// multiply by 1000 to convert milliseconds to microseconds.
printf("time to execute test code = %f us\n",T2*1000.0);
}
Ejemplo 2

void msDelay(unsigned int delay)


{
unsigned long done_time;

done_time = MS_TIMER + delay;


while( (long) (MS_TIMER - done_time) < 0 );
}
Variables RTC
Unsigned long tiempo: segundos desde el 1 de enero de
1980

struct tm {
char tm_sec;     // seconds 0-59
char tm_min;     // 0-59
char tm_hour;    // 0-23
char tm_mday;    // 1-31
char tm_mon;     // 1-12
char tm_year;    // 80-147 (1980-2047)
char tm_wday;    // 0-6 0==Sunday
};
Funciones RTC
tiempo

read_rtc( void );

int tm_rd( struct tm *t );


struct tm RTC

Inicio
SEC_TIMER
Funciones RTC
tiempo void write_rtc( unsigned long int time );

struct tm
int tm_wr( struct tm *t );
RTC

SEC_TIMER
Funciones RTC
tiempo

unsigned int mktm( unsigned long mktime(


struct tm *timeptr, struct tm *timeptr );
unsigned long time );
struct tm

int tm_rd( struct tm *t );

SEC_TIMER
Funciones RTC

int rtc_timezone( long * seconds, char * tzname );

Description
This function returns the timezone offset as known by the library.
The timezone is obtained from the following sources, in order of
preference:

1. The DHCP server. This can only be used if the TCP/IP stack is in
use, and USE_DHCP is defined.
2. The TIMEZONE macro. This should be defined by the program
to an _hour_ offset - may be floating point.

You might also like