Skip to content

Commit

Permalink
rename 8253pit.c to timer.c
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Aug 28, 2007
1 parent eae0416 commit 9e82bfb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 51 deletions.
45 changes: 0 additions & 45 deletions 8253pit.c

This file was deleted.

6 changes: 3 additions & 3 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ struct proc;
struct spinlock;
struct stat;

// 8253pit.c
void pit8253_timerinit(void);

// bio.c
void binit(void);
struct buf* bread(uint, uint);
Expand Down Expand Up @@ -140,6 +137,9 @@ int fetchint(struct proc*, uint, int*);
int fetchstr(struct proc*, uint, char**);
void syscall(void);

// timer.c
void timer_init(void);

// trap.c
void idtinit(void);
extern int ticks;
Expand Down
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ main(void)
ide_init(); // disk
bootothers(); // boot other CPUs
if(!ismp)
pit8253_timerinit(); // uniprocessor timer
timer_init(); // uniprocessor timer
userinit(); // first user process

// enable interrupts on this processor.
Expand Down Expand Up @@ -74,7 +74,7 @@ mpmain(void)
scheduler();
}

void
static void
bootothers(void)
{
extern uchar _binary_bootother_start[], _binary_bootother_size[];
Expand Down
2 changes: 1 addition & 1 deletion runoff.list
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ picirq.c
kbd.h
kbd.c
console.c
8253pit.c
timer.c

# user-level
usys.S
Expand Down
32 changes: 32 additions & 0 deletions timer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Intel 8253/8254/82C54 Programmable Interval Timer (PIT).
// Only used on uniprocessors;
// SMP machines use the local APIC timer.

#include "types.h"
#include "defs.h"
#include "traps.h"
#include "x86.h"

#define IO_TIMER1 0x040 // 8253 Timer #1

// Frequency of all three count-down timers;
// (TIMER_FREQ/freq) is the appropriate count
// to generate a frequency of freq Hz.

#define TIMER_FREQ 1193182
#define TIMER_DIV(x) ((TIMER_FREQ+(x)/2)/(x))

#define TIMER_MODE (IO_TIMER1 + 3) // timer mode port
#define TIMER_SEL0 0x00 // select counter 0
#define TIMER_RATEGEN 0x04 // mode 2, rate generator
#define TIMER_16BIT 0x30 // r/w counter 16 bits, LSB first

void
timer_init(void)
{
// Interrupt 100 times/sec.
outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
outb(IO_TIMER1, TIMER_DIV(100) % 256);
outb(IO_TIMER1, TIMER_DIV(100) / 256);
irq_enable(IRQ_TIMER);
}

0 comments on commit 9e82bfb

Please sign in to comment.