1 /****************************************************************************
3 * SciTech OS Portability Manager Library
5 * ========================================================================
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
25 * Environment: 32-bit Windows NT device drivers.
27 * Description: Implementation for the NT driver IRQ management functions
30 ****************************************************************************/
34 #include "drvlib/os/os.h"
35 #include "sdd/sddhelp.h"
39 /*--------------------------- Global variables ----------------------------*/
41 static int globalDataStart;
42 static uchar _PM_oldCMOSRegA;
43 static uchar _PM_oldCMOSRegB;
44 static uchar _PM_oldRTCPIC2;
45 static ulong RTC_idtEntry;
46 PM_intHandler _PM_rtcHandler = NULL;
47 PMFARPTR _VARAPI _PM_prevRTC = PMNULL;
49 /*----------------------------- Implementation ----------------------------*/
51 /* Functions to read and write CMOS registers */
53 uchar _ASMAPI _PM_readCMOS(int index);
54 void _ASMAPI _PM_writeCMOS(int index,uchar value);
55 void _ASMAPI _PM_rtcISR(void);
56 void _ASMAPI _PM_getISR(int irq,PMFARPTR *handler);
57 void _ASMAPI _PM_setISR(int irq,void *handler);
58 void _ASMAPI _PM_restoreISR(int irq,PMFARPTR *handler);
59 void _ASMAPI _PM_irqCodeStart(void);
60 void _ASMAPI _PM_irqCodeEnd(void);
62 /****************************************************************************
64 Set the real time clock frequency (for stereo modes).
65 ****************************************************************************/
66 void PMAPI PM_setRealTimeClockFrequency(
69 static short convert[] = {
87 /* First clear any pending RTC timeout if not cleared */
90 /* Disable RTC timout */
91 _PM_writeCMOS(0x0A,(uchar)_PM_oldCMOSRegA);
92 _PM_writeCMOS(0x0B,(uchar)(_PM_oldCMOSRegB & 0x0F));
95 /* Convert frequency value to RTC clock indexes */
96 for (i = 0; convert[i] != -1; i++) {
97 if (convert[i] == frequency)
101 /* Set RTC timout value and enable timeout */
102 _PM_writeCMOS(0x0A,(uchar)(0x20 | (i+3)));
103 _PM_writeCMOS(0x0B,(uchar)((_PM_oldCMOSRegB & 0x0F) | 0x40));
107 ibool PMAPI PM_setRealTimeClockHandler(PM_intHandler th,int frequency)
109 static ibool locked = false;
111 /* Save the old CMOS real time clock values */
112 _PM_oldCMOSRegA = _PM_readCMOS(0x0A);
113 _PM_oldCMOSRegB = _PM_readCMOS(0x0B);
115 /* Install the interrupt handler */
117 _PM_getISR(RTC_idtEntry, &_PM_prevRTC);
119 _PM_setISR(RTC_idtEntry, _PM_rtcISR);
121 /* Program the real time clock default frequency */
122 PM_setRealTimeClockFrequency(frequency);
124 /* Unmask IRQ8 in the PIC2 */
125 _PM_oldRTCPIC2 = PM_inpb(0xA1);
126 PM_outpb(0xA1,(uchar)(_PM_oldRTCPIC2 & 0xFE));
130 void PMAPI PM_restoreRealTimeClockHandler(void)
132 if (_PM_rtcHandler) {
133 /* Restore CMOS registers and mask RTC clock */
134 _PM_writeCMOS(0x0A,_PM_oldCMOSRegA);
135 _PM_writeCMOS(0x0B,_PM_oldCMOSRegB);
136 PM_outpb(0xA1,(uchar)((PM_inpb(0xA1) & 0xFE) | (_PM_oldRTCPIC2 & ~0xFE)));
138 /* Restore the interrupt vector */
139 _PM_restoreISR(RTC_idtEntry, &_PM_prevRTC);
140 _PM_rtcHandler = NULL;