2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/parallel/parallel.c
5 * PURPOSE: Parallel port driver
6 * PROGRAMMER: David Welch (welch@mcmail.com)
9 * 18/06/98: Made more NT like
12 /* FUNCTIONS **************************************************************/
23 #define LP_S (READ_PORT_UCHAR((PUCHAR)(LP_B+1)))
27 DriverEntry(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING RegistryPath
);
29 static void Parallel_Reset(void)
31 * FUNCTION: Resets the device attached to the parallel port
36 WRITE_PORT_UCHAR((PUCHAR
)LP_C
,0);
37 for (i
=0;i
<LP_DELAY
;i
++);
38 WRITE_PORT_UCHAR((PUCHAR
)LP_C
,LP_PSELECP
| LP_PINITP
);
41 static void Parallel_putchar(unsigned char ch
)
43 * FUNCTION: Writes a character to the parallel port
45 * ch = character to write
58 while ( count
< 500000 && !(status
& LP_PBUSY
) );
62 DPRINT("printer_putchar(): timed out\n");
66 WRITE_PORT_UCHAR((PUCHAR
)LP_B
,ch
);
67 while (wait
!= 10000) { wait
++; }
68 WRITE_PORT_UCHAR((PUCHAR
)LP_C
, (LP_PSELECP
| LP_PINITP
| LP_PSTROBE
));
69 while (wait
) { wait
--; }
70 WRITE_PORT_UCHAR((PUCHAR
)LP_C
, LP_PSELECP
| LP_PINITP
);
73 static DRIVER_DISPATCH Dispatch
;
75 Dispatch(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
77 * FUNCTION: Handles user mode requests
79 * DeviceObject = Device for request
80 * Irp = I/O request packet describing request
81 * RETURNS: Success or failure
84 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
88 switch (Stack
->MajorFunction
)
91 DPRINT("(Parallel Port Driver) Creating\n");
93 status
= STATUS_SUCCESS
;
97 status
= STATUS_SUCCESS
;
101 DPRINT("(Parallel Port Driver) Writing %d bytes\n",
102 Stack
->Parameters
.Write
.Length
);
103 for (i
=0;i
<Stack
->Parameters
.Write
.Length
;i
++)
105 Parallel_putchar(((char *)Irp
->UserBuffer
)[i
]);
107 status
= STATUS_SUCCESS
;
111 status
= STATUS_NOT_IMPLEMENTED
;
115 Irp
->IoStatus
.Status
= status
;
116 Irp
->IoStatus
.Information
= 0;
118 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
123 DriverEntry(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING RegistryPath
)
125 * FUNCTION: Called by the system to initalize the driver
127 * DriverObject = object describing this driver
128 * RegistryPath = path to our configuration entries
129 * RETURNS: Success or failure
132 PDEVICE_OBJECT DeviceObject
;
133 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\Device\\Parallel");
136 DPRINT("Parallel Port Driver 0.0.1\n");
138 Status
= IoCreateDevice(DriverObject
,
141 FILE_DEVICE_PARALLEL_PORT
,
145 if (!NT_SUCCESS(Status
))
150 DeviceObject
->Flags
=0;
151 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = Dispatch
;
152 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = Dispatch
;
153 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = Dispatch
;
154 DriverObject
->DriverUnload
= NULL
;
156 return(STATUS_SUCCESS
);