Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenparallel.c
Go to the documentation of this file.
00001 /* $Id: parallel.c 54094 2011-10-12 12:24:19Z akhaldi $ 00002 * 00003 * COPYRIGHT: See COPYING in the top level directory 00004 * PROJECT: ReactOS kernel 00005 * FILE: services/parallel/parallel.c 00006 * PURPOSE: Parallel port driver 00007 * PROGRAMMER: David Welch (welch@mcmail.com) 00008 * UPDATE HISTORY: 00009 * ??/??/??: Created 00010 * 18/06/98: Made more NT like 00011 */ 00012 00013 /* FUNCTIONS **************************************************************/ 00014 00015 #include <wdm.h> 00016 00017 #include "parallel.h" 00018 00019 #define NDEBUG 00020 #include <debug.h> 00021 00022 00023 #define LP_B (0x378) 00024 #define LP_S (READ_PORT_UCHAR((PUCHAR)(LP_B+1))) 00025 #define LP_C (LP_B+2) 00026 00027 NTSTATUS NTAPI 00028 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath); 00029 00030 static void Parallel_Reset(void) 00031 /* 00032 * FUNCTION: Resets the device attached to the parallel port 00033 */ 00034 { 00035 int i; 00036 00037 WRITE_PORT_UCHAR((PUCHAR)LP_C,0); 00038 for (i=0;i<LP_DELAY;i++); 00039 WRITE_PORT_UCHAR((PUCHAR)LP_C,LP_PSELECP | LP_PINITP); 00040 } 00041 00042 static void Parallel_putchar(unsigned char ch) 00043 /* 00044 * FUNCTION: Writes a character to the parallel port 00045 * ARGUMENTS: 00046 * ch = character to write 00047 */ 00048 { 00049 00050 int count=0; 00051 int status; 00052 int wait=0; 00053 00054 do 00055 { 00056 status=LP_S; 00057 count++; 00058 } 00059 while ( count < 500000 && !(status & LP_PBUSY) ); 00060 00061 if (count==500000) 00062 { 00063 DPRINT("printer_putchar(): timed out\n"); 00064 return; 00065 } 00066 00067 WRITE_PORT_UCHAR((PUCHAR)LP_B,ch); 00068 while (wait != 10000) { wait++; } 00069 WRITE_PORT_UCHAR((PUCHAR)LP_C, (LP_PSELECP | LP_PINITP | LP_PSTROBE )); 00070 while (wait) { wait--; } 00071 WRITE_PORT_UCHAR((PUCHAR)LP_C, LP_PSELECP | LP_PINITP); 00072 } 00073 00074 static DRIVER_DISPATCH Dispatch; 00075 static NTSTATUS NTAPI 00076 Dispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp) 00077 /* 00078 * FUNCTION: Handles user mode requests 00079 * ARGUMENTS: 00080 * DeviceObject = Device for request 00081 * Irp = I/O request packet describing request 00082 * RETURNS: Success or failure 00083 */ 00084 { 00085 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp); 00086 NTSTATUS status; 00087 ULONG i; 00088 00089 switch (Stack->MajorFunction) 00090 { 00091 case IRP_MJ_CREATE: 00092 DPRINT("(Parallel Port Driver) Creating\n"); 00093 Parallel_Reset(); 00094 status = STATUS_SUCCESS; 00095 break; 00096 00097 case IRP_MJ_CLOSE: 00098 status = STATUS_SUCCESS; 00099 break; 00100 00101 case IRP_MJ_WRITE: 00102 DPRINT("(Parallel Port Driver) Writing %d bytes\n", 00103 Stack->Parameters.Write.Length); 00104 for (i=0;i<Stack->Parameters.Write.Length;i++) 00105 { 00106 Parallel_putchar(((char *)Irp->UserBuffer)[i]); 00107 } 00108 status = STATUS_SUCCESS; 00109 break; 00110 00111 default: 00112 status = STATUS_NOT_IMPLEMENTED; 00113 break; 00114 } 00115 00116 Irp->IoStatus.Status = status; 00117 Irp->IoStatus.Information = 0; 00118 00119 IoCompleteRequest(Irp, IO_NO_INCREMENT); 00120 return(status); 00121 } 00122 00123 NTSTATUS NTAPI 00124 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) 00125 /* 00126 * FUNCTION: Called by the system to initalize the driver 00127 * ARGUMENTS: 00128 * DriverObject = object describing this driver 00129 * RegistryPath = path to our configuration entries 00130 * RETURNS: Success or failure 00131 */ 00132 { 00133 PDEVICE_OBJECT DeviceObject; 00134 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\Parallel"); 00135 NTSTATUS Status; 00136 00137 DPRINT("Parallel Port Driver 0.0.1\n"); 00138 00139 Status = IoCreateDevice(DriverObject, 00140 0, 00141 &DeviceName, 00142 FILE_DEVICE_PARALLEL_PORT, 00143 0, 00144 FALSE, 00145 &DeviceObject); 00146 if (!NT_SUCCESS(Status)) 00147 { 00148 return(Status); 00149 } 00150 00151 DeviceObject->Flags=0; 00152 DriverObject->MajorFunction[IRP_MJ_CLOSE] = Dispatch; 00153 DriverObject->MajorFunction[IRP_MJ_CREATE] = Dispatch; 00154 DriverObject->MajorFunction[IRP_MJ_WRITE] = Dispatch; 00155 DriverObject->DriverUnload = NULL; 00156 00157 return(STATUS_SUCCESS); 00158 } 00159 00160 /* EOF */ Generated on Sat May 26 2012 04:26:41 for ReactOS by
1.7.6.1
|