C
17
RTC.c
Guest on 4th July 2022 07:13:01 PM
/*
useful documentation:
http://www.geocities.com/SiliconValley/Campus/1671/docs/rtc.htm
function prototypes taken from, but re-written in C instead of asm:
Sample program #11 (sample11.c)
Demonstrates using the RTC periodic interrupt
Part of the PC Timing FAQ / Application notes
By K. Heidenstrom (kheidens@actrix.gen.nz)
*/
#pragma once
#include <windef.h>
#include "ports.h"
// EXTREEMLY undocumented function exported by the HAL
VOID WINAPI HalEnableSystemInterrupt(DWORD vector, DWORD unknown, DWORD nEdge_LevelTriggered);
// these should only be called when interrupts are disabled (cli)
UCHAR read_rtc_register(UCHAR reg_num)
{
outportb(0x70, reg_num);
return inportb(0x71);
}
void write_rtc_register(UCHAR reg_num, UCHAR value)
{
outportb(0x70, reg_num);
outportb(0x71, value);
}
void enable_rtc_int(UCHAR RTC_Vector)
{
write_rtc_register(0x0B, read_rtc_register(0x0B) | 0x40);
outportb(0xA1, inportb(0xA1) & 0xFE);
outportb(0x21, inportb(0x21) & 0xFB);
// make sure that the system doesn't try to disable this interrupt either...
HalEnableSystemInterrupt(RTC_Vector, 0, 0); // all built in interrupts should be Edge triggered
}