PKUOS - Pintos
Pintos source browser for PKU Operating System course
Macros | Functions
pit.c File Reference
#include "devices/pit.h"
#include <debug.h>
#include <stdint.h>
#include "threads/interrupt.h"
#include "threads/io.h"
Include dependency graph for pit.c:

Go to the source code of this file.

Macros

#define PIT_PORT_CONTROL   0x43
 Interface to 8254 Programmable Interrupt Timer (PIT). More...
 
#define PIT_PORT_COUNTER(CHANNEL)   (0x40 + (CHANNEL))
 Counter port. More...
 
#define PIT_HZ   1193180
 PIT cycles per second. More...
 

Functions

void pit_configure_channel (int channel, int mode, int frequency)
 Configure the given CHANNEL in the PIT. More...
 

Macro Definition Documentation

◆ PIT_HZ

#define PIT_HZ   1193180

PIT cycles per second.

Definition at line 15 of file pit.c.

◆ PIT_PORT_CONTROL

#define PIT_PORT_CONTROL   0x43

Interface to 8254 Programmable Interrupt Timer (PIT).

Refer to [8254] for details. 8254 registers. Control port.

Definition at line 11 of file pit.c.

◆ PIT_PORT_COUNTER

#define PIT_PORT_COUNTER (   CHANNEL)    (0x40 + (CHANNEL))

Counter port.

Definition at line 12 of file pit.c.

Function Documentation

◆ pit_configure_channel()

void pit_configure_channel ( int  channel,
int  mode,
int  frequency 
)

Configure the given CHANNEL in the PIT.

devices/pit.h

In a PC, the PIT's three output channels are hooked up like this:

  • Channel 0 is connected to interrupt line 0, so that it can be used as a periodic timer interrupt, as implemented in Pintos in devices/timer.c.
  • Channel 1 is used for dynamic RAM refresh (in older PCs). No good can come of messing with this.
  • Channel 2 is connected to the PC speaker, so that it can be used to play a tone, as implemented in Pintos in devices/speaker.c.

MODE specifies the form of output:

  • Mode 2 is a periodic pulse: the channel's output is 1 for most of the period, but drops to 0 briefly toward the end of the period. This is useful for hooking up to an interrupt controller to generate a periodic interrupt.
  • Mode 3 is a square wave: for the first half of the period it is 1, for the second half it is 0. This is useful for generating a tone on a speaker.
  • Other modes are less useful.

FREQUENCY is the number of periods per second, in Hz.

Definition at line 46 of file pit.c.

References ASSERT, intr_disable(), intr_set_level(), mode, outb(), PIT_HZ, PIT_PORT_CONTROL, and PIT_PORT_COUNTER.

Referenced by speaker_on(), and timer_init().

Here is the call graph for this function:
Here is the caller graph for this function: