[Geekos-devel] timer munging
Status: Pre-Alpha
Brought to you by:
daveho
|
From: Parc <ne...@ri...> - 2002-01-12 05:17:30
|
I've munged together a couple lines to set the timer to 10ms jiffies,
and added a sleep(). Could somebody try these out for me? For some
reason I don't get the correct timing occasionally. This patch should
cause the kernel to loop saying "tick" once a second.
Thanks
Index: drivers/timer.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/geekos/drivers/timer.c,v
retrieving revision 1.2
diff -c -r1.2 timer.c
*** drivers/timer.c 2001/12/24 15:35:57 1.2
--- drivers/timer.c 2002/01/12 05:10:29
***************
*** 11,16 ****
--- 11,20 ----
#include "sys/geekos/kthread.h"
#include "sys/geekos/timer.h"
=20
+ #define TICKRATE 1193182
+ //#define FIND_RATE(hz) (((TICKRATE + hz) / 2) / hz)
+ #define FIND_RATE(hz) (((TICKRATE + hz) / 2) / hz)
+=20
// global tick counter
volatile unsigned long g_numTicks;
=20
***************
*** 56,61 ****
--- 60,72 ----
=20
Print( "Initializing timer...\n" );
=20
+ //Set the tick rate to 10ms
+ disable_interrupts();
+ out_byte(0x043, 0x34);
+ out_byte(0x040, FIND_RATE(100) & 0xff);
+ out_byte(0x040, FIND_RATE(100) >> 8);
+ enable_interrupts();
+=20
// Install an interrupt handler for the timer IRQ
install_irq( TIMER_IRQ, &timer_interrupt_handler );
=20
***************
*** 63,66 ****
--- 74,83 ----
irqMask =3D get_irq_mask();
irqMask &=3D ~(1 << TIMER_IRQ);
set_irq_mask( irqMask );
+ }
+=20
+ void sleep(int time) {
+ long start =3D g_numTicks + time +1;=20
+ Print("Sleeping from %x to %x\n",g_numTicks,start);
+ while((g_numTicks - start) > 0) ; //spin
}
Index: include/sys/geekos/timer.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/geekos/include/sys/geekos/timer.h,v
retrieving revision 1.2
diff -c -r1.2 timer.h
*** include/sys/geekos/timer.h 2001/12/24 15:35:57 1.2
--- include/sys/geekos/timer.h 2002/01/12 05:10:29
***************
*** 13,17 ****
--- 13,18 ----
extern volatile unsigned long g_numTicks;
=20
void init_timer( void );
+ void sleep( int time );
=20
#endif // TIMER_H
Index: kern/main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/geekos/kern/main.c,v
retrieving revision 1.6
diff -c -r1.6 main.c
*** kern/main.c 2001/12/24 15:35:57 1.6
--- kern/main.c 2002/01/12 05:10:30
***************
*** 51,56 ****
--- 53,62 ----
// Test Join() function
{
struct kernel_thread* child;
+ for(; ;) {
+ sleep(100);
+ Print("tick.\n");
+ }
Print( "Starting child...\n" );
child =3D start_kernel_thread( &test_join, 0, PRIORITY_NORMAL, FALSE );
Join( child );
|