Commented the PIT-initialization code to make it easier to understand.
This commit is contained in:
parent
698759df75
commit
4e53aa6f95
1 changed files with 22 additions and 12 deletions
|
@ -127,6 +127,9 @@ int timer_wait(unsigned int ticks)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LATCH(f) ((CLOCK_TICK_RATE + f/2) / f)
|
#define LATCH(f) ((CLOCK_TICK_RATE + f/2) / f)
|
||||||
|
#define WAIT_SOME_TIME() do { uint64_t start = rdtsc(); \
|
||||||
|
while(rdtsc() - start < 1000000) ; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sets up the system clock by installing the timer handler
|
* Sets up the system clock by installing the timer handler
|
||||||
|
@ -134,10 +137,6 @@ int timer_wait(unsigned int ticks)
|
||||||
*/
|
*/
|
||||||
int timer_init(void)
|
int timer_init(void)
|
||||||
{
|
{
|
||||||
#ifndef CONFIG_ROCKCREEK
|
|
||||||
uint64_t start;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Installs 'timer_handler' for the PIC and APIC timer,
|
* Installs 'timer_handler' for the PIC and APIC timer,
|
||||||
* only one handler will be later used.
|
* only one handler will be later used.
|
||||||
|
@ -150,16 +149,27 @@ int timer_init(void)
|
||||||
* Therefore, we have not to configure the PIC timer.
|
* Therefore, we have not to configure the PIC timer.
|
||||||
*/
|
*/
|
||||||
#ifndef CONFIG_ROCKCREEK
|
#ifndef CONFIG_ROCKCREEK
|
||||||
|
/*
|
||||||
|
* Port 0x43 is for initializing the PIT:
|
||||||
|
*
|
||||||
|
* 0x34 means the following:
|
||||||
|
* 0b... (step-by-step binary representation)
|
||||||
|
* ... 00 - channel 0
|
||||||
|
* ... 11 - write two values to counter register:
|
||||||
|
* first low-, then high-byte
|
||||||
|
* ... 010 - mode number 2: "rate generator" / frequency divider
|
||||||
|
* ... 0 - binary counter (the alternative is BCD)
|
||||||
|
*/
|
||||||
outportb(0x43, 0x34);
|
outportb(0x43, 0x34);
|
||||||
/* before we write to 0x40, we wait some time */
|
|
||||||
start = rdtsc();
|
WAIT_SOME_TIME();
|
||||||
while(rdtsc() - start < 1000000)
|
|
||||||
;
|
/* Port 0x40 is for the counter register of channel 0 */
|
||||||
|
|
||||||
outportb(0x40, LATCH(TIMER_FREQ) & 0xFF); /* low byte */
|
outportb(0x40, LATCH(TIMER_FREQ) & 0xFF); /* low byte */
|
||||||
/* before we write to 0x40, we wait some time */
|
|
||||||
start = rdtsc();
|
WAIT_SOME_TIME();
|
||||||
while(rdtsc() - start < 1000000)
|
|
||||||
;
|
|
||||||
outportb(0x40, LATCH(TIMER_FREQ) >> 8); /* high byte */
|
outportb(0x40, LATCH(TIMER_FREQ) >> 8); /* high byte */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue