00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00061
00062
00069 int KERN_ptint (void)
00070 {
00071
00072
00073
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
00087
00088
00089 _KERN_quantum_count = 0;
00090 return (1);
00091 }
00092 if (++_KERN_quantum_count == QUANTUM) {
00093 _KERN_quantum_count = 0;
00094 return (1);
00095 }
00096 return (0);
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
00113
00114
00115
00116
00117
00118
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);
00166 _time_ticks = 0;
00167 _time_seconds = val;
00168 writeshort (SIM_PITR, PTIMER_PITR_VAL);
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