Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

timer.h

Go to the documentation of this file.
00001 // See the end of this file for license information.
00002 
00003 #ifndef TORSION_TIMER_H
00004 #define TORSION_TIMER_H
00005 
00006 #include "asm.h"
00007 #include "irq.h"
00008 #include "list.h"
00009 
00010 class Timer;
00011 extern Timer timer;
00012 
00013 typedef enum {
00014   TIMER_COMMAND_LATCH_COUNT          = 0,
00015   TIMER_COMMAND_BINARY_CODED_DECIMAL = (1 << 0),
00016   TIMER_COMMAND_READ_WRITE_LSB       = (1 << 4),
00017   TIMER_COMMAND_READ_WRITE_MSB       = (1 << 5),
00018   TIMER_COMMAND_COUNTER_0            = (0 << 6),
00019   TIMER_COMMAND_COUNTER_1            = (1 << 6),
00020   TIMER_COMMAND_COUNTER_2            = (2 << 6)
00021 } Timer_command;
00022 
00023 typedef enum {
00024   TIMER_MODE_ALARM          = (0 << 1),
00025   TIMER_MODE_ONE_SHOT       = (1 << 1),
00026   TIMER_MODE_RATE_GENERATOR = (2 << 1),
00027   TIMER_MODE_SQUARE_WAVE    = (3 << 1),
00028   TIMER_MODE_SOFTWARE_PULSE = (4 << 1),
00029   TIMER_MODE_HARDWARE_PULSE = (5 << 1)
00030 } Timer_mode;
00031 
00032 typedef enum {
00033   TIMER_REGISTER_COUNTER_0 = 0x40,
00034   TIMER_REGISTER_COUNTER_1 = 0x41,
00035   TIMER_REGISTER_COUNTER_2 = 0x42,
00036   TIMER_REGISTER_COMMAND   = 0x43
00037 } Timer_register;
00038 
00039 typedef bool (*Timer_callback_func)(void* argument);
00040 
00048 
00049 class Timer_callback : public List_node {
00050 public:
00051   Timer_callback_func function;   
00052   unsigned period;      
00053   unsigned call_time;     
00054   unsigned cycles;      
00055   void* argument;     
00056   bool scheduled;     
00057 
00058   void
00059   init(Timer_callback_func callback_function);
00060 
00062   void
00063   print();
00064 };
00065 
00068 
00069 class Timer {
00070 public:
00071   Int_handler handler;      
00072   static const unsigned TIMER_HZ = 1000;
00073   List<Timer_callback> callbacks; 
00074   unsigned volatile cycles_per_millisecond; 
00075 
00077   void
00078   init();
00079 
00083   void
00084   schedule(Timer_callback& callback, unsigned milliseconds,
00085            void* argument = NULL);
00086   
00088   void
00089   unschedule(Timer_callback& callback);
00090   
00093   void
00094   reschedule(Timer_callback& callback, unsigned milliseconds);
00095 
00097   unsigned
00098   system_time();
00099 
00101   void
00102   print();
00103 };
00104 
00107 bool
00108 timer_handler();
00109 
00110 bool
00111 bootstrap_timer_handler();
00112 
00113 #endif
00114 
00115 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman
00116  *
00117  * This program is free software; you can redistribute it and/or modify it
00118  * under the terms of the GNU General Public License as published by the
00119  * Free Software Foundation; either version 2 of the License, or (at your
00120  * option) any later version.
00121  * 
00122  * This program is distributed in the hope that it will be useful, but
00123  * WITHOUT ANY WARRANTY; without even the implied warranty of
00124  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00125  * General Public License for more details (in the COPYING file).
00126  * 
00127  * You should have received a copy of the GNU General Public License along
00128  * with this program; if not, write to the Free Software Foundation, Inc.,
00129  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00130  */

Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman