2019-04-24 18:43:05 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
// //
|
|
|
|
// Desc: Interrupt related functions //
|
|
|
|
// //
|
|
|
|
// //
|
|
|
|
// Copyright © 2018-2019 The OS/K Team //
|
|
|
|
// //
|
|
|
|
// This file is part of OS/K. //
|
|
|
|
// //
|
|
|
|
// OS/K is free software: you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or //
|
|
|
|
// any later version. //
|
|
|
|
// //
|
|
|
|
// OS/K is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
#include <kernel/base.h>
|
|
|
|
#include <kernel/iomisc.h>
|
2019-04-24 21:08:44 +02:00
|
|
|
#include <extras/buf.h>
|
2019-04-24 18:43:05 +02:00
|
|
|
|
2019-04-24 21:08:44 +02:00
|
|
|
extern void RtcIsr(void);
|
|
|
|
|
|
|
|
ulong IoRtcTicks = 0;
|
|
|
|
|
|
|
|
void IoSetupRtc(void)
|
|
|
|
{
|
|
|
|
IdtRegisterIrq(RtcIsr, 0x28, 0x8E);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IoEnableRtc(void)
|
2019-04-24 18:43:05 +02:00
|
|
|
{
|
|
|
|
ulong flags = KePauseIRQs();
|
2019-04-24 21:08:44 +02:00
|
|
|
char readedInterruptConfig;
|
|
|
|
char readedRegister;
|
|
|
|
char readedIrqs;
|
|
|
|
uchar RtcRate;
|
|
|
|
|
|
|
|
// Setting up the register control and interrupt rates
|
|
|
|
RtcRate = 0x05;
|
|
|
|
|
2019-04-24 18:43:05 +02:00
|
|
|
IoWriteByteOnPort(0x70, 0x8B);
|
2019-04-24 21:08:44 +02:00
|
|
|
readedRegister = IoReadByteFromPort(0x71);
|
|
|
|
IoWriteByteOnPort(0x70, 0x8B); // Because reading flushes
|
|
|
|
IoWriteByteOnPort(0x71, readedRegister | 0x40);
|
|
|
|
|
|
|
|
IoWriteByteOnPort(0x70, 0x8A);
|
|
|
|
readedInterruptConfig = IoReadByteFromPort(0x71);
|
|
|
|
IoWriteByteOnPort(0x70, 0x8A); // Because reading flushes
|
|
|
|
IoWriteByteOnPort(0x71, (readedInterruptConfig & 0xF0) | RtcRate);
|
|
|
|
IoWriteByteOnPort(0x70, 0x0C);
|
|
|
|
IoReadByteFromPort(0x71); // Flush
|
|
|
|
|
|
|
|
// Setting up the IRQs
|
|
|
|
readedIrqs = IoReadByteFromPort(0xA1);
|
|
|
|
IoWriteByteOnPort(0xA1, 0xFE & readedIrqs); // Enables IRQ on PIC 2
|
|
|
|
readedIrqs = IoReadByteFromPort(0x21);
|
|
|
|
IoWriteByteOnPort(0x21, 0xFB & readedIrqs); // Enables IRQ on PIC 1
|
|
|
|
|
|
|
|
// clean-up
|
|
|
|
IoWriteByteOnPort(0x70, 0x0C); // Select status reg C
|
|
|
|
IoReadByteFromPort(0x71); // Flush
|
2019-04-24 18:43:05 +02:00
|
|
|
KeRestoreIRQs(flags);
|
2019-04-24 23:00:12 +02:00
|
|
|
IoEnableNMI();
|
2019-04-24 18:43:05 +02:00
|
|
|
}
|
2019-04-24 21:08:44 +02:00
|
|
|
|
|
|
|
void RtcHandler(void)
|
|
|
|
{
|
|
|
|
//bprintf(BStdOut, " *RTC - ");
|
|
|
|
IoWriteByteOnPort(0x70, 0x0C); // Selects status reg C
|
|
|
|
IoReadByteFromPort(0x71); // Flush
|
|
|
|
IoRtcTicks++;
|
2019-04-24 23:00:12 +02:00
|
|
|
IoSendEOItoPIC(0x28);
|
2019-04-24 21:08:44 +02:00
|
|
|
//bprintf(BStdOut, " - EOI* ");
|
|
|
|
}
|