C   17

RTC.c

Guest on 4th July 2022 07:13:01 PM

  1. /*
  2.         useful documentation:
  3.                 http://www.geocities.com/SiliconValley/Campus/1671/docs/rtc.htm
  4.  
  5.         function prototypes taken from, but re-written in C instead of asm:
  6.                 Sample program #11 (sample11.c)
  7.                 Demonstrates using the RTC periodic interrupt
  8.                 Part of the PC Timing FAQ / Application notes
  9.                 By K. Heidenstrom (kheidens@actrix.gen.nz)
  10. */
  11.  
  12. #pragma once
  13. #include <windef.h>
  14. #include "ports.h"
  15.  
  16. // EXTREEMLY undocumented function exported by the HAL
  17. VOID WINAPI HalEnableSystemInterrupt(DWORD vector, DWORD unknown, DWORD nEdge_LevelTriggered);
  18.  
  19. // these should only be called when interrupts are disabled (cli)
  20. UCHAR read_rtc_register(UCHAR reg_num)
  21. {
  22.         outportb(0x70, reg_num);
  23.         return inportb(0x71);
  24. }
  25.  
  26. void write_rtc_register(UCHAR reg_num, UCHAR value)
  27. {
  28.         outportb(0x70, reg_num);
  29.         outportb(0x71, value);
  30. }
  31.  
  32. void enable_rtc_int(UCHAR RTC_Vector)
  33. {
  34.         write_rtc_register(0x0B, read_rtc_register(0x0B) | 0x40);
  35.         outportb(0xA1, inportb(0xA1) & 0xFE);
  36.         outportb(0x21, inportb(0x21) & 0xFB);
  37.  
  38.         // make sure that the system doesn't try to disable this interrupt either...
  39.         HalEnableSystemInterrupt(RTC_Vector, 0, 0); // all built in interrupts should be Edge triggered
  40. }

Raw Paste


Login or Register to edit or fork this paste. It's free.