Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

lockunlock.c

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or
00003  *  modify it under the terms of the GNU General Public License
00004  *  as published by the Free Software Foundation; either version
00005  *  2 of the License, or (at your option) any later version.
00006  *
00007  *  Copyright 2006 Spiro Trikaliotis
00008  *
00009  */
00010 
00020 #include <wdm.h>
00021 #include "cbm_driver.h"
00022 #include "iec.h"
00023 
00024 #include "version.h"
00025 
00039 NTSTATUS
00040 cbm_lock_parport(IN PDEVICE_EXTENSION Pdx)
00041 {
00042     NTSTATUS ntStatus;
00043 
00044     FUNC_ENTER();
00045 
00046     DBG_PRINT((DBG_PREFIX "+++ LOCK PARPORT"));
00047     DBG_ASSERT(Pdx->ParallelPortIsLocked == FALSE);
00048 
00049     ntStatus = ParPortAllocate(Pdx);
00050 
00051     // Set the appropriate mode of the parallel port
00052     // Normally, this will be either BYTE MODE, or SPP
00053 
00054     if (NT_SUCCESS(ntStatus))
00055     {
00056         ntStatus = ParPortSetMode(Pdx);
00057     }
00058 
00059     // Try to allocate the interrupt
00060 
00061     if (NT_SUCCESS(ntStatus))
00062     {
00069         // ntStatus =
00070         ParPortAllocInterrupt(Pdx, cbm_isr);
00071     }
00072 
00073     // Initialize the IEC serial port
00074 
00075     if (NT_SUCCESS(ntStatus))
00076     {
00077         Pdx->ParallelPortIsLocked = TRUE;
00078 
00079         cbmiec_init(Pdx);
00080     }
00081 
00082     // Did we fail any call? If yes, free and release
00083     // any resource we might happen to have allocated
00084     // before we failed
00085 
00086 
00087     if (!NT_SUCCESS(ntStatus))
00088     {
00089         // The functions themselves test if the resource
00090         // is allocated, thus, we do not need to protect
00091         // against freeing non-allocated resources here.
00092 
00093         ParPortFreeInterrupt(Pdx);
00094         ParPortUnsetMode(Pdx);
00095         ParPortFree(Pdx);
00096     }
00097 
00098     // release the bus (to be able to share it with other
00099     // controllers
00100 
00101     if (NT_SUCCESS(ntStatus) && !Pdx->DoNotReleaseBus)
00102     {
00103         cbmiec_release_bus(Pdx);
00104     }
00105 
00106     FUNC_LEAVE_NTSTATUS(ntStatus);
00107 }
00108 
00122 NTSTATUS
00123 cbm_unlock_parport(IN PDEVICE_EXTENSION Pdx)
00124 {
00125     FUNC_ENTER();
00126 
00127     DBG_PRINT((DBG_PREFIX "--- UNLOCK PARPORT"));
00128     DBG_ASSERT(Pdx->ParallelPortIsLocked == TRUE);
00129 
00130     Pdx->ParallelPortIsLocked = FALSE;
00131 
00132     // release the bus (to be able to share it with other controllers)
00133 
00134     if (!Pdx->DoNotReleaseBus)
00135     {
00136         cbmiec_release_bus(Pdx);
00137     }
00138 
00139     // release all resources we have previously allocated
00140 
00141     ParPortFreeInterrupt(Pdx);
00142     ParPortUnsetMode(Pdx);
00143     ParPortFree(Pdx);
00144 
00145     FUNC_LEAVE_NTSTATUS_CONST(STATUS_SUCCESS);
00146 }
00147 
00173 NTSTATUS
00174 cbm_lock(IN PDEVICE_EXTENSION Pdx)
00175 {
00176     FUNC_ENTER();
00177 
00178     DBG_PRINT((DBG_PREFIX "*** LOCK"));
00179     Pdx->ParallelPortLock = TRUE;
00180 
00181     FUNC_LEAVE_NTSTATUS_CONST(STATUS_SUCCESS);
00182 }
00183 
00202 NTSTATUS
00203 cbm_unlock(IN PDEVICE_EXTENSION Pdx)
00204 {
00205     FUNC_ENTER();
00206 
00207     DBG_PRINT((DBG_PREFIX "*** UNLOCK"));
00208     Pdx->ParallelPortLock = FALSE;
00209 
00210     FUNC_LEAVE_NTSTATUS_CONST(STATUS_SUCCESS);
00211 }

Generated on Sun Apr 30 18:45:54 2006 for opencbm by  doxygen 1.4.2