ostimer.c File Reference

Go to the source code of this file.

Defines

#define NUT_TICK_NFREQ   1024L
 Nominal number of system ticks per second.
#define NUT_TIMER_CRYSTAL   32768L
#define NUT_TIMER_PRESCALE   1
#define OCR_VALUE   (((2 * NUT_TIMER_CRYSTAL / (NUT_TIMER_PRESCALE * NUT_TICK_NFREQ) + 1) / 2) - 1)
#define NUT_TICK_FREQ   ((2 * NUT_TIMER_CRYSTAL / (OCR_VALUE + 1) / NUT_TIMER_PRESCALE + 1) / 2)
#define TCCRx   TCCR0
#define TCNTx   TCNT0
#define OCRx   OCR0
#define TIFR_OCFx   _BV(OCF0)
#define TIFR_TOVx   _BV(TOV0)
#define sig_TIMER   sig_OUTPUT_COMPARE0

Functions

void NutDelay (u_char ms)
 Loop for a specified number of milliseconds.
void NutRegisterTimer (void(*handler)(void *))
 Initialize system timer hardware.
u_long NutGetCpuClock (void)
 Return the CPU clock in Hertz.
u_long NutGetTickClock (void)
 Return the number of system ticks per second.
u_long NutTimerMillisToTicks (u_long ms)
 Calculate system ticks for a given number of milliseconds.


Define Documentation

#define NUT_TICK_NFREQ   1024L

Nominal number of system ticks per second.

The actual frequency depends on the timer crystal.

Note:
Since version 3.9.8, the default frequency had been changed from 16 Hz to 1024 Hz, when the timer is running with an external 32 kHz clock crystal.

Definition at line 105 of file ostimer.c.

#define NUT_TIMER_CRYSTAL   32768L

Definition at line 118 of file ostimer.c.

#define NUT_TIMER_PRESCALE   1

Definition at line 121 of file ostimer.c.

#define OCR_VALUE   (((2 * NUT_TIMER_CRYSTAL / (NUT_TIMER_PRESCALE * NUT_TICK_NFREQ) + 1) / 2) - 1)

Definition at line 126 of file ostimer.c.

Referenced by NutRegisterTimer().

#define NUT_TICK_FREQ   ((2 * NUT_TIMER_CRYSTAL / (OCR_VALUE + 1) / NUT_TIMER_PRESCALE + 1) / 2)

Definition at line 129 of file ostimer.c.

Referenced by NutGetTickClock(), and NutRegisterTimer().

#define TCCRx   TCCR0

Definition at line 167 of file ostimer.c.

Referenced by NutRegisterTimer().

#define TCNTx   TCNT0

Definition at line 168 of file ostimer.c.

Referenced by NutRegisterTimer().

#define OCRx   OCR0

Definition at line 169 of file ostimer.c.

Referenced by NutRegisterTimer().

#define TIFR_OCFx   _BV(OCF0)

Definition at line 170 of file ostimer.c.

Referenced by NutRegisterTimer().

#define TIFR_TOVx   _BV(TOV0)

Definition at line 171 of file ostimer.c.

#define sig_TIMER   sig_OUTPUT_COMPARE0

Definition at line 172 of file ostimer.c.

Referenced by NutRegisterTimer().


Function Documentation

void NutDelay ( u_char  ms  ) 

Loop for a specified number of milliseconds.

This call will not release the CPU and will not switch to another thread. However, because of absent thread switching, this delay time is very exact.

If no exact timing is needed, use NutSleep() to avoid blocking the CPU,

Note:
The timing may not work as expected. A better implementation is urgently required.
Parameters:
ms Delay time in milliseconds, maximum is 255.

Definition at line 193 of file ostimer.c.

void NutRegisterTimer ( void(*)(void *)  handler  ) 

Initialize system timer hardware.

This function is automatically called by Nut/OS during system initialization.

Parameters:
handler System timer interrupt handler.

Definition at line 332 of file ostimer.c.

References inb, NUT_CPU_FREQ, NutDisableTimerIrq, NutRegisterIrqHandler(), OCR_VALUE, OCRx, outb, sbi, sig_TIMER, TCCRx, TCNTx, and TIFR_OCFx.

u_long NutGetCpuClock ( void   ) 

Return the CPU clock in Hertz.

Returns:
CPU clock frequency in Hertz.

Definition at line 377 of file ostimer.c.

u_long NutGetTickClock ( void   ) 

Return the number of system ticks per second.

Returns:
System tick frequency in Hertz.

Definition at line 387 of file ostimer.c.

References NUT_TICK_FREQ.

u_long NutTimerMillisToTicks ( u_long  ms  ) 

Calculate system ticks for a given number of milliseconds.

Definition at line 395 of file ostimer.c.

References NutGetTickClock().


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/