CTAOS v3
This commit is contained in:
18
SysCore/hal/pit/compile.bat
Normal file
18
SysCore/hal/pit/compile.bat
Normal file
@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/pit.o pit.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
56
SysCore/hal/pit/pit.c
Normal file
56
SysCore/hal/pit/pit.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include <system.h>
|
||||
#include <time.h>
|
||||
#include "../irq/irq.h"
|
||||
#include "pit.h"
|
||||
|
||||
volatile unsigned int _pit_ticks = 0;
|
||||
volatile unsigned int _pit_frequency = 0;
|
||||
unsigned char _pit_init = 0;
|
||||
volatile TIME _internal_clock;
|
||||
|
||||
|
||||
void i86_pit_set_frequency(int frequency)
|
||||
{
|
||||
int divisor = 1193180/frequency; // Calculate the divisor
|
||||
outportb(0x43, 0x36); // Set our command byte 0x36
|
||||
outportb(0x40, divisor&0xFF); // Set low byte
|
||||
outportb(0x40, divisor>>8); // Set high byte
|
||||
_pit_frequency = frequency;
|
||||
}
|
||||
|
||||
void i86_pit_handler(ISR_stack_regs *r)
|
||||
{
|
||||
_pit_ticks++; // count tick
|
||||
if (_pit_ticks % _pit_frequency == 0)
|
||||
_CLOCK_INC((TIME*)&_internal_clock); // update internal clock
|
||||
}
|
||||
|
||||
unsigned int i86_pit_set_tick_count(unsigned int i)
|
||||
{
|
||||
unsigned int r = _pit_ticks;
|
||||
_pit_ticks = i;
|
||||
return r;
|
||||
}
|
||||
|
||||
unsigned int i86_pit_get_tick_count()
|
||||
{
|
||||
return _pit_ticks;
|
||||
}
|
||||
unsigned int i86_pit_get_frequency()
|
||||
{
|
||||
return _pit_frequency;
|
||||
}
|
||||
|
||||
void i86_pit_install(int freq)
|
||||
{
|
||||
i86_irq_install_handler(0, i86_pit_handler);
|
||||
i86_pit_set_frequency(freq);
|
||||
_pit_ticks = 0;
|
||||
_pit_init = 1;
|
||||
|
||||
}
|
||||
|
||||
unsigned char i86_pit_is_initialized()
|
||||
{
|
||||
return _pit_init;
|
||||
}
|
17
SysCore/hal/pit/pit.h
Normal file
17
SysCore/hal/pit/pit.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef __PIT_H
|
||||
#define __PIT_H
|
||||
|
||||
#include<regs.h>
|
||||
extern volatile unsigned int _pit_ticks;
|
||||
extern volatile unsigned int _pit_frequency;
|
||||
extern volatile TIME _internal_clock;
|
||||
|
||||
extern void i86_pit_handler(ISR_stack_regs *r);
|
||||
extern void i86_pit_set_frequency(int frequency);
|
||||
extern unsigned int i86_pit_set_tick_count(unsigned int i);
|
||||
extern unsigned int i86_pit_get_tick_count();
|
||||
extern unsigned int i86_pit_get_frequency();
|
||||
extern void i86_pit_install(int freq);
|
||||
extern unsigned char i86_pit_is_initialized();
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user