8259.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002-2004 The UbixOS Project
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without modification, are
00006  permitted provided that the following conditions are met:
00007 
00008  Redistributions of source code must retain the above copyright notice, this list of
00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
00010  form must reproduce the above copyright notice, this list of conditions, the following
00011  disclaimer and the list of authors in the documentation and/or other materials provided
00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
00013  contributors may be used to endorse or promote products derived from this software
00014  without specific prior written permission.
00015 
00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026  $Id$
00027 
00028 *****************************************************************************************/
00029 
00030 #include <sys/io.h>
00031 #include <isa/8259.h>
00032 #include <ubixos/types.h>
00033 #include <lib/kprintf.h>
00034 
00035 static unsigned int irqMask = 0xFFFF;
00036 
00037 /************************************************************************
00038 
00039  Function: int 8259_init()
00040 
00041  Description: This function will initialize both PICs for all of our IRQs
00042 
00043  Notes:
00044 
00045 ************************************************************************/
00046 int i8259_init() {
00047   outportByte(mPic,   icw1); /* Initialize Master PIC           */
00048   outportByte(sPic,   icw1); /* Initialize Seconary PIC         */
00049   outportByte(mPic+1, mVec); /* Master Interrup Vector          */
00050   outportByte(sPic+1, sVec); /* Secondary Interrupt Vector      */
00051   outportByte(mPic+1, 1<<2); /* Bitmask for cascade on IRQ 2    */
00052   outportByte(sPic+1, 2);    /* Cascade on IRQ 2                */
00053   outportByte(mPic+1, icw4); /* Finish Primary Initialization   */
00054   outportByte(sPic+1, icw4); /* Finish Seconary Initialization  */
00055   outportByte(mImr,   0xff); /* Mask All Primary Interrupts     */
00056   outportByte(sImr,   0xff); /* Mask All Seconary Interrupts    */
00057 
00058   /* Print out the system info for this */
00059   kprintf("pic0 - Port: [0x%X]\n",mPic);
00060   kprintf("pic1 - Port: [0x%X]\n",sPic);
00061 
00062   /* Return so the system knows it went well */
00063   return(0x0);
00064   }
00065 
00066 /************************************************************************
00067 
00068  Function: int irqEnable()
00069 
00070  Description: This function is used to turn on an IRQ
00071 
00072  Notes:
00073 
00074 ************************************************************************/
00075 void irqEnable(uInt16 irqNo) {
00076   irqMask &= ~(1 << irqNo);
00077   if (irqNo >= 8) {
00078     irqMask &= ~(1 << 2);
00079     }
00080   outportByte(mPic+1, irqMask & 0xFF);
00081   outportByte(sPic+1, (irqMask >> 8) & 0xFF);
00082   }
00083 
00084 /************************************************************************
00085 
00086  Function: int irqDisable()
00087 
00088  Description: This function is used to turn off an IRQ
00089 
00090  Notes:
00091 
00092 ************************************************************************/
00093 void irqDisable(uInt16 irqNo) {
00094   irqMask |= (1 << irqNo);
00095   if ((irqMask & 0xFF00)==0xFF00) {
00096     irqMask |= (1 << 2);
00097     }
00098   outportByte(mPic+1, irqMask & 0xFF);
00099   outportByte(sPic+1, (irqMask >> 8) & 0xFF);
00100   }
00101 
00102 /***
00103  $Log$
00104  Revision 1.1.1.1  2006/06/01 12:46:12  reddawg
00105  ubix2
00106 
00107  Revision 1.2  2005/10/12 00:13:37  reddawg
00108  Removed
00109 
00110  Revision 1.1.1.1  2005/09/26 17:23:59  reddawg
00111  no message
00112 
00113  Revision 1.5  2004/07/09 13:20:08  reddawg
00114  Oh yeah duh you can not name functions with numbers
00115 
00116  Revision 1.4  2004/07/09 13:14:29  reddawg
00117  8259: changed init8259 to 8259_init
00118  Adjusted Startup Routines
00119 
00120  Revision 1.3  2004/05/20 22:51:09  reddawg
00121  Cleaned Up Warnings
00122 
00123  Revision 1.2  2004/05/10 02:23:24  reddawg
00124  Minor Changes To Source Code To Prepare It For Open Source Release
00125 
00126  END
00127  ***/
00128 

Generated on Sun Dec 3 02:38:03 2006 for UbixOS V2 by  doxygen 1.4.7