Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

/projects/cubeos/src_current/kernel/ptimer.c

Go to the documentation of this file.
00001 /*  src/kernel/ptimer.c
00002    CubeOS Version 0.4.90
00003    Copyright (C) 1999,2000 Holger Kenn
00004 
00005    CubeOS is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or any later version.
00009 
00010    CubeOS is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015  */
00020 #include <ptimer.h>
00021 #include <cubeos.h>
00022 #include <sys_var.h>
00023 #include <io_duart.h>
00024 #include <schedule.h>
00025 #include <sys/time.h>
00026 
00027 
00028 void (*_KERN_call_dispatcher) ();
00029 
00034 int KERN_installdispatcher(void (*dispatcher) ())
00035 {
00036 if (_KERN_call_dispatcher)
00037         return (-1);
00038 disable();
00039 _KERN_call_dispatcher = dispatcher;
00040 enable();
00041 return(0);
00042 }
00043 
00048 int KERN_removedispatcher()
00049 {
00050 if (!_KERN_call_dispatcher)
00051         return(-1);
00052 disable();
00053 _KERN_call_dispatcher = NULL;
00054 enable();
00055 return (0);
00056 }
00057 
00058 
00059 /*
00060  * The periodic timer is a internal device of the 68332
00061  */
00062 
00069 int KERN_ptint (void)
00070 {
00071 
00072 
00073         /* Advance the system clock */
00074         if ((++_time_ticks) == TICKS_PER_SECOND) {
00075                 _time_seconds++;
00076                 _time_ticks = 0;
00077         }
00078 #ifdef DUART_BASE
00079         if ((DUART_BASE) != 0)
00080                 _DUART_duart_bugfix ();
00081 #endif
00082         if (_KERN_call_dispatcher)
00083                 _KERN_call_dispatcher ();
00084 
00085         if (KERN_delta_handler ()) {
00086                 /* time has run out for at least one thread, 
00087                    delta_handler has woken up the threads, we need to call the
00088                    scheduler immediately */
00089                 _KERN_quantum_count = 0;        /* abort the current quantum! */
00090                 return (1);
00091         }
00092         if (++_KERN_quantum_count == QUANTUM) {
00093                 _KERN_quantum_count = 0;
00094                 return (1);     /* and call scheduler */
00095         }
00096         return (0);             /* don't call scheduler */
00097 }
00098 
00103 void KERN_init_ptimer (void)
00104 {
00105         _time_seconds = 0;
00106         _time_ticks = 0;
00107         writeshort (SIM_PITR, PTIMER_PITR_VAL);
00108 
00109         writeshortpos (SIM_PICR, PTIMER_VECTOR, 0xff, 0x0);
00110         writeshortpos (SIM_PICR, PTIMER_IRQ_LEVEL, 0x7, 0x8);
00111 
00112 //      ptimer_clears_wdt = 1; /* clear WDT on timer int */
00113 
00114 
00115 // the software watchdog timeout period is determined by 
00116         //      XTAL_FREQ: The clock frequency of the VCO/external clock source
00117         //      SIM_SYPCR.SWP: Clock Prescaler, 1: div 512 2: no prescaler
00118         //      SIM_SYPCR.SWT0/1
00119 
00120 
00121 
00122 
00123 
00124 }
00125 
00130 unsigned long _getseconds ()
00131 {
00132         return _time_seconds;
00133 }
00134 
00135 
00141 int _gettimeofday (struct timeval *tp, struct timezone *ignore)
00142 {
00143 
00144         tp->tv_sec = _time_seconds;
00145 
00146         tp->tv_usec = (_time_ticks * 1000 / TICKS_PER_SECOND);
00147         return 0;
00148 }
00149 
00150 int gettimeofday (struct timeval *tp, struct timezone *ignore)
00151 {
00152 
00153         tp->tv_sec = _time_seconds;
00154 
00155         tp->tv_usec = (_time_ticks * 1000 / TICKS_PER_SECOND);
00156         return 0;
00157 }
00158 
00163 unsigned long _settimeofday (unsigned long val)
00164 {
00165         writeshort (SIM_PITR, 0);       /* Disable timer interrupt */
00166         _time_ticks = 0;
00167         _time_seconds = val;    /* set clock */
00168         writeshort (SIM_PITR, PTIMER_PITR_VAL);         /* and return it */
00169         return _time_seconds;
00170 }
00171 
00172 
00173 int settimeofday(const struct timeval* tp,const struct timezone* ignore)
00174 {
00175  writeshort (SIM_PITR, 0);
00176  _time_ticks = 0;
00177  _time_seconds = tp->tv_sec;
00178  writeshort (SIM_PITR, PTIMER_PITR_VAL);
00179  return 0;
00180 }
00181 

Generated on Thu Feb 20 15:38:44 2003 for cubeOS by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002