OpenCBM
lockunlock.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2006-2007 Spiro Trikaliotis
8  *
9  */
10 
19 #include <wdm.h>
20 #include "cbm_driver.h"
21 #include "iec.h"
22 
23 #include "version.h"
24 
38 NTSTATUS
39 cbm_lock_parport(IN PDEVICE_EXTENSION Pdx)
40 {
41  NTSTATUS ntStatus;
42 
43  FUNC_ENTER();
44 
45  DBG_PRINT((DBG_PREFIX "+++ LOCK PARPORT"));
46  DBG_ASSERT(Pdx->ParallelPortIsLocked == FALSE);
47 
48  ntStatus = ParPortAllocate(Pdx);
49 
50  // Set the appropriate mode of the parallel port
51  // Normally, this will be either BYTE MODE, or SPP
52 
53  if (NT_SUCCESS(ntStatus))
54  {
55  ntStatus = ParPortSetMode(Pdx);
56  }
57 
58  // Try to allocate the interrupt
59 
60  if (NT_SUCCESS(ntStatus))
61  {
68  // ntStatus =
70  }
71 
72  // Initialize the IEC serial port
73 
74  if (NT_SUCCESS(ntStatus))
75  {
76  Pdx->ParallelPortIsLocked = TRUE;
77 
78  // initialize cable type and try to detect the cable if necessary
79 
80  cbm_init_registry(NULL, Pdx);
81 
82  // initialize the IEC Bus
83 
84  cbmiec_init(Pdx);
85  }
86 
87  // Did we fail any call? If yes, free and release
88  // any resource we might happen to have allocated
89  // before we failed
90 
91 
92  if (!NT_SUCCESS(ntStatus))
93  {
94  // The functions themselves test if the resource
95  // is allocated, thus, we do not need to protect
96  // against freeing non-allocated resources here.
97 
99  ParPortUnsetMode(Pdx);
100  ParPortFree(Pdx);
101  }
102 
103  // release the bus (to be able to share it with other
104  // controllers
105 
106  if (NT_SUCCESS(ntStatus) && !Pdx->DoNotReleaseBus)
107  {
108  cbmiec_release_bus(Pdx);
109  }
110 
111  FUNC_LEAVE_NTSTATUS(ntStatus);
112 }
113 
127 NTSTATUS
128 cbm_unlock_parport(IN PDEVICE_EXTENSION Pdx)
129 {
130  FUNC_ENTER();
131 
132  DBG_PRINT((DBG_PREFIX "--- UNLOCK PARPORT"));
133  DBG_ASSERT(Pdx->ParallelPortIsLocked == TRUE);
134 
135  Pdx->ParallelPortIsLocked = FALSE;
136 
137  // release the bus (to be able to share it with other controllers)
138 
139  if (!Pdx->DoNotReleaseBus)
140  {
141  cbmiec_release_bus(Pdx);
142  }
143 
144  // release all resources we have previously allocated
145 
147  ParPortUnsetMode(Pdx);
148  ParPortFree(Pdx);
149 
150  FUNC_LEAVE_NTSTATUS_CONST(STATUS_SUCCESS);
151 }
152 
178 NTSTATUS
179 cbm_lock(IN PDEVICE_EXTENSION Pdx)
180 {
181  FUNC_ENTER();
182 
183  DBG_PRINT((DBG_PREFIX "*** LOCK"));
184  Pdx->ParallelPortLock = TRUE;
185 
186  FUNC_LEAVE_NTSTATUS_CONST(STATUS_SUCCESS);
187 }
188 
207 NTSTATUS
208 cbm_unlock(IN PDEVICE_EXTENSION Pdx)
209 {
210  FUNC_ENTER();
211 
212  DBG_PRINT((DBG_PREFIX "*** UNLOCK"));
213  Pdx->ParallelPortLock = FALSE;
214 
215  FUNC_LEAVE_NTSTATUS_CONST(STATUS_SUCCESS);
216 }
BOOLEAN cbm_isr(IN PKINTERRUPT Interrupt, IN PVOID Pdx)
Interrupt Service Routine (ISR)
Definition: isr.c:38
NTSTATUS cbm_unlock_parport(IN PDEVICE_EXTENSION Pdx)
Unlock the parallel port for the driver.
Definition: lockunlock.c:128
NTSTATUS cbm_lock(IN PDEVICE_EXTENSION Pdx)
Lock the parallel port for the driver.
Definition: lockunlock.c:179
NTSTATUS ParPortSetMode(PDEVICE_EXTENSION Pdx)
Set the operational mode of the parallel port.
NTSTATUS cbm_lock_parport(IN PDEVICE_EXTENSION Pdx)
Lock the parallel port for the driver.
Definition: lockunlock.c:39
NTSTATUS cbmiec_init(IN PDEVICE_EXTENSION Pdx)
Initialize the IEC bus.
Definition: libiec/init.c:199
Definitions for the libiec library.
NTSTATUS cbm_unlock(IN PDEVICE_EXTENSION Pdx)
Unlock the parallel port for the driver.
Definition: lockunlock.c:208
VOID cbmiec_release_bus(IN PDEVICE_EXTENSION Pdx)
Release the IEC bus.
Definition: releasebus.c:38
#define DBG_ASSERT(_xxx)
Definition: debug.h:401
NTSTATUS ParPortFree(PDEVICE_EXTENSION Pdx)
Free a parallel port after using it.
Definition: PortAccess.c:195
NTSTATUS ParPortUnsetMode(PDEVICE_EXTENSION Pdx)
Unset the operational mode of the parallel port.
VOID cbm_init_registry(IN PUNICODE_STRING RegistryPath, IN PDEVICE_EXTENSION Pdx)
Initialize from registry.
Defining OpenCBM version.
#define FUNC_ENTER()
Definition: debug.h:347
Definitions for the opencbm driver.
#define DBG_PREFIX
Definition: debug.h:320
NTSTATUS ParPortAllocate(PDEVICE_EXTENSION Pdx)
Allocate a parallel port for using it.
Definition: PortAccess.c:157
NTSTATUS ParPortAllocInterrupt(PDEVICE_EXTENSION Pdx, PKSERVICE_ROUTINE Isr)
Allocate an interrupt routine for a parallel port.
Definition: PortAccess.c:628
NTSTATUS ParPortFreeInterrupt(PDEVICE_EXTENSION Pdx)
Free an interrupt routine for a parallel port after using it.
Definition: PortAccess.c:680
#define DBG_PRINT(_xxx)
Definition: debug.h:403