Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

Clock Manager
[Kernel]


Data Structures

struct  timeout
 Timeout variable structure. More...


Defines

#define LATCH_COUNT   0x00
 To copy chip count.

#define TIMER0   0x40
 I/O port for timer channel 0.

#define TIMER2   0x42
 I/O port for timer channel 2.

#define TIMER_MODE   0x43
 I/O port for timer mode control.

#define SQUARE_WAVE   0x36
 The sqare-wave form.

#define TIMER_FREQ   1193182L
 Clock frequency for timer in PC.

#define TIMER_COUNT   (unsigned)(TIMER_FREQ/HZ)
 Value to initialize timer.

#define LATCH   ((TIMER_FREQ + HZ/2) / HZ)
 LATCH is used for the interval timer.

#define HZ   200
 Clock Frequancy (User settable, default=200Hz).

#define usleep(m)   delay(m)
 Macro equivalent to delay(dword millisec).


Typedefs

typedef timeout timeout_t
 Timeout variable structure.


Functions

void init_clock ()
 Initialize channel 0 of the 8253A timer.

void stop_clock ()
 Reset the clock for rebooting.

dword sys_get_ticks (void)
 Return the system ticks.
Returns:
The system ticks.


void delay (dword millisec)
 Delay some milliseconds
Parameters:
millisec  How many milliseconds you want to delay.


void set_timeout (timeout_t *t, unsigned int millisec)
 Initialize a timeout variable.
Parameters:
t  The timeout variable.
millisec  How many milliseconds have to elapse before the timeout occurs.


bool is_timeout (timeout_t *t)
 Check if a timeout has been elapsed.
Parameters:
t  The timeout variable.


void clock_thread ()
 This is a task that occurs at every clock tick.


Detailed Description

The system clock manager.

Define Documentation

#define HZ   200
 

Clock Frequancy (User settable, default=200Hz).

Definition at line 31 of file clock.h.

#define LATCH   ((TIMER_FREQ + HZ/2) / HZ)
 

LATCH is used for the interval timer.

Definition at line 28 of file clock.h.

#define LATCH_COUNT   0x00
 

To copy chip count.

Definition at line 17 of file clock.h.

#define SQUARE_WAVE   0x36
 

The sqare-wave form.

Definition at line 21 of file clock.h.

#define TIMER0   0x40
 

I/O port for timer channel 0.

Definition at line 18 of file clock.h.

#define TIMER2   0x42
 

I/O port for timer channel 2.

Definition at line 19 of file clock.h.

#define TIMER_COUNT   (unsigned)(TIMER_FREQ/HZ)
 

Value to initialize timer.

Definition at line 25 of file clock.h.

#define TIMER_FREQ   1193182L
 

Clock frequency for timer in PC.

Definition at line 22 of file clock.h.

#define TIMER_MODE   0x43
 

I/O port for timer mode control.

Definition at line 20 of file clock.h.

#define usleep      delay(m)
 

Macro equivalent to delay(dword millisec).

Definition at line 48 of file clock.h.


Typedef Documentation

typedef struct timeout timeout_t
 

Timeout variable structure.


Function Documentation

void clock_thread  
 

This is a task that occurs at every clock tick.

Into this routine you can put every periodical task.
You can change the frequency of the ticks changing the value of the HZ definition.
This thread is invoked at every clock tick by the dispatcher().

Definition at line 109 of file clock.c.

00110 {
00111         ticks++;
00112         floppy_thread();
00113 }

void delay dword    millisec
 

Delay some milliseconds

Parameters:
millisec  How many milliseconds you want to delay.

Definition at line 51 of file clock.c.

00052 {
00053         dword count, elapsed;
00054         dword IF = GET_IF();
00055 
00056         // Start timer //
00057         elapsed = 0;
00058 
00059         while (elapsed < millisec)
00060         {
00061                 // Poll ticks in memory //
00062                 count = ticks;
00063 
00064                 // Auto-sleep //
00065                 enable();
00066                 idle();
00067 
00068                 // Update elapsed time //
00069                 elapsed += (ticks - count)*1000/HZ;
00070         }
00071 
00072         SET_IF(IF);
00073 }

void init_clock  
 

Initialize channel 0 of the 8253A timer.

Definition at line 21 of file clock.c.

00022 {
00023         dword IF = GET_IF();
00024 
00025         disable();
00026 
00027         outportb(TIMER_MODE, SQUARE_WAVE);      // set timer on
00028         outportb(TIMER0, TIMER_COUNT & 0xFF);   // timer low byte
00029         outportb(TIMER0, TIMER_COUNT >> 8);     // timer high byte
00030 
00031         SET_IF(IF);
00032 }

bool is_timeout timeout_t   t
 

Check if a timeout has been elapsed.

Parameters:
t  The timeout variable.

Definition at line 87 of file clock.c.

00088 {
00089 // Check if a timeout has gone                                          //
00090         uint32_t elapsed;
00091         elapsed = ticks - t->start_ticks;
00092         return( elapsed >= t->ticks_to_wait );
00093 }

void set_timeout timeout_t   t,
unsigned int    millisec
 

Initialize a timeout variable.

Parameters:
t  The timeout variable.
millisec  How many milliseconds have to elapse before the timeout occurs.

Definition at line 79 of file clock.c.

00080 {
00081         t->start_ticks = ticks;
00082         t->ticks_to_wait = millisec * HZ / 1000;
00083 }

void stop_clock  
 

Reset the clock for rebooting.

Definition at line 35 of file clock.c.

00036 {
00037         dword IF = GET_IF();
00038 
00039 
00040         disable();
00041 
00042         outportb(TIMER_MODE, SQUARE_WAVE);      // set timer on
00043         outportb(TIMER0, 0);                    // timer low byte
00044         outportb(TIMER0, 0);                    // timer high byte
00045 
00046         SET_IF(IF);
00047 }

dword sys_get_ticks void   
 

Return the system ticks.

Returns:
The system ticks.

Definition at line 97 of file clock.c.

00098 {
00099         return(ticks);
00100 }


Generated on Fri Feb 20 15:32:22 2004 for Minirighi by doxygen1.2.18