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

clock.c File Reference

The system clock manager. More...

#include <const.h>
#include <arch/i386.h>
#include <kernel/floppy.h>
#include <kernel/task.h>
#include <kernel/clock.h>

Go to the source code of this file.

Functions

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

void stop_clock ()
 Reset the clock for rebooting.

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.


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


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


Variables

volatile dword ticks = 0
 System ticks.


Detailed Description

The system clock manager.

Author:
Andrea Righi <drizzt@inwind.it>
Date:
Last update: 2003-08-23
Note:
Copyright (©) 2003 Andrea Righi

Definition in file clock.c.


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 }


Variable Documentation

volatile dword ticks = 0
 

System ticks.

Definition at line 18 of file clock.c.


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