ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

portio.c
Go to the documentation of this file.
00001 /*
00002  *
00003  * COPYRIGHT:            See COPYING in the top level directory
00004  * PROJECT:              ReactOS kernel
00005  * FILE:                 drivers/dd/sndblst/portio.c (see also sndblst.h)
00006  * PURPOSE:              Sound Blaster port I/O helper
00007  * PROGRAMMER:           Andrew Greenwood
00008  * UPDATE HISTORY:
00009  *                       Sept 28, 2003: Created
00010  */
00011 
00012 #include <ntddk.h>
00013 #include "sndblst.h"
00014 
00015 BOOLEAN WaitToSend(ULONG BasePort)
00016 {
00017     int TimeOut;
00018 
00019     DPRINT("WaitToSend ");
00020 
00021     // Check if it's OK to send
00022     for (TimeOut = SB_TIMEOUT;
00023          ! SB_READY_TO_SEND(BasePort) && TimeOut > 0;
00024          TimeOut --);
00025 
00026     // If a time-out occurs, we report failure
00027     if (! TimeOut)
00028     {
00029         DPRINT("FAILED\n");
00030         return FALSE;
00031     }
00032 
00033     DPRINT("SUCCEEDED\n");
00034 
00035     return TRUE;
00036 }
00037 
00038 BOOLEAN WaitToReceive(ULONG BasePort)
00039 {
00040     int TimeOut;
00041 
00042     DPRINT("WaitToReceive ");
00043 
00044     // Check if it's OK to receive
00045     for (TimeOut = SB_TIMEOUT;
00046          ! SB_READY_TO_RECEIVE(BasePort) && TimeOut > 0;
00047          TimeOut --);
00048 
00049     // If a time-out occurs, we report failure
00050     if (! TimeOut)
00051     {
00052         DPRINT("FAILED\n");
00053         return FALSE;
00054     }
00055 
00056     DPRINT("SUCCEEDED\n");
00057 
00058     return TRUE;
00059 }
00060 
00061 
00062 USHORT InitSoundCard(ULONG BasePort)
00063 {
00064     ULONG TimeOut;
00065     BOOLEAN Status;
00066     UCHAR DSP_Major, DSP_Minor;
00067 
00068     DPRINT("InitSoundCard() called\n");
00069 
00070     DPRINT("Resetting sound card\n");
00071 //    if (!WaitToSend(BasePort))
00072 //        return FALSE;
00073 
00074     SB_WRITE_RESET(BasePort, 0x01);
00075     for (TimeOut = 0; TimeOut < 30000; TimeOut ++); // Wait a while
00076     SB_WRITE_RESET(BasePort, 0x00);
00077 
00078     // Check if it's OK to receive (some cards will ignore the above reset
00079     // command and so will not issue an ACK, so time out is NOT an error)
00080     DPRINT("Waiting for an ACK\n");
00081     if (WaitToReceive(BasePort))
00082     {
00083         // Check to make sure the reset was acknowledged:
00084         for (TimeOut = SB_TIMEOUT;
00085              (Status = (SB_READ_DATA(BasePort) != SB_DSP_READY) && (TimeOut > 0));
00086              TimeOut --);
00087     }
00088 
00089     DPRINT("Querying DSP version\n");
00090     if (! WaitToSend(BasePort))
00091         return FALSE;
00092 
00093     SB_WRITE_DATA(BasePort, SB_GET_DSP_VERSION);
00094 
00095     if (! WaitToReceive(BasePort))
00096         return FALSE;
00097 
00098     DSP_Major = SB_READ_DATA(BasePort);
00099     DSP_Minor = SB_READ_DATA(BasePort);
00100 
00101     DPRINT("DSP v%d.%d\n", DSP_Major, DSP_Minor);
00102 
00103     // if audio is disabled,
00104     // version tests return 0xFF everywhere
00105     if (DSP_Major == 0xFF && DSP_Minor == 0xFF)
00106         return FALSE;
00107 
00108     DPRINT("Sound card initialized!\n");
00109 
00110     return (DSP_Major * 256) + DSP_Minor;
00111 }

Generated on Fri May 25 2012 04:26:06 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.