Title: Control de tiempo bsico
1Control de tiempobásico
2Variables 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) -
3Ejemplo 1
- define N 10000
- main() timeit()
- nodebug timeit()
- unsigned long int T0
- float T2,T1
- int x,y
- int i
- T0 MS_TIMER
- for(i0iltNi)
- // T1 gives empty loop time
- T1(MS_TIMER-T0)
- T0 MS_TIMER
- for(i0iltNi) xy
- // 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",T21000.0)
4Ejemplo 2
-
- void msDelay(unsigned int delay)
-
- unsigned long done_time
- done_time MS_TIMER delay
- while( (long) (MS_TIMER - done_time) lt 0 )
-
5Variables RTC
- Unsigned long tiempo segundos desde el 1 de
enero de 1980 - struct tm char tm_sec // seconds 0-59char
tm_min // 0-59char tm_hour // 0-23char
tm_mday // 1-31char tm_mon // 1-12char
tm_year // 80-147 (1980-2047)char
tm_wday // 0-6 0Sunday -
6Funciones RTC
- tiempo
- struct tm
- SEC_TIMER
-
read_rtc( void )
RTC
int tm_rd( struct tm t )
Inicio
7Funciones RTC
- tiempo
- struct tm
- SEC_TIMER
-
void write_rtc( unsigned long int time )
RTC
int tm_wr( struct tm t )
8Funciones RTC
- tiempo
- struct tm
- SEC_TIMER
-
unsigned long mktime( struct tm timeptr )
unsigned int mktm( struct tm timeptr, unsigned
long time )
int tm_rd( struct tm t )
9Funciones 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.