New macros InitializeUnicodeString(), RtlInitUnicodeStringFromLiteral() and UNICODE_S...
[reactos.git] / reactos / drivers / dd / parallel / parallel.c
1 /* $Id: parallel.c,v 1.8 2002/08/20 20:37:05 hyperion Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/parallel/parallel.c
6 * PURPOSE: Parallel port driver
7 * PROGRAMMER: David Welch (welch@mcmail.com)
8 * UPDATE HISTORY:
9 * ??/??/??: Created
10 * 18/06/98: Made more NT like
11 */
12
13 /* FUNCTIONS **************************************************************/
14
15 #include <ddk/ntddk.h>
16
17 #include "parallel.h"
18
19 #define NDEBUG
20 #include <debug.h>
21
22
23 #define LP_B (0x378)
24 #define LP_S (READ_PORT_UCHAR((PUCHAR)(LP_B+1)))
25 #define LP_C (LP_B+2)
26
27 static void Parallel_Reset(void)
28 /*
29 * FUNCTION: Resets the device attached to the parallel port
30 */
31 {
32 int i;
33
34 WRITE_PORT_UCHAR((PUCHAR)LP_C,0);
35 for (i=0;i<LP_DELAY;i++);
36 WRITE_PORT_UCHAR((PUCHAR)LP_C,LP_PSELECP | LP_PINITP);
37 }
38
39 static void Parallel_putchar(unsigned char ch)
40 /*
41 * FUNCTION: Writes a character to the parallel port
42 * ARGUMENTS:
43 * ch = character to write
44 */
45 {
46
47 int count=0;
48 int status;
49 int wait=0;
50
51 do
52 {
53 status=LP_S;
54 count++;
55 }
56 while ( count < 500000 && !(status & LP_PBUSY) );
57
58 if (count==500000)
59 {
60 DPRINT("printer_putchar(): timed out\n");
61 return;
62 }
63
64 WRITE_PORT_UCHAR((PUCHAR)LP_B,ch);
65 while (wait != 10000) { wait++; }
66 WRITE_PORT_UCHAR((PUCHAR)LP_C, (LP_PSELECP | LP_PINITP | LP_PSTROBE ));
67 while (wait) { wait--; }
68 WRITE_PORT_UCHAR((PUCHAR)LP_C, LP_PSELECP | LP_PINITP);
69 }
70
71 NTSTATUS STDCALL
72 Dispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
73 /*
74 * FUNCTION: Handles user mode requests
75 * ARGUMENTS:
76 * DeviceObject = Device for request
77 * Irp = I/O request packet describing request
78 * RETURNS: Success or failure
79 */
80 {
81 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
82 NTSTATUS status;
83 int i;
84
85 switch (Stack->MajorFunction)
86 {
87 case IRP_MJ_CREATE:
88 DPRINT("(Parallel Port Driver) Creating\n");
89 Parallel_Reset();
90 status = STATUS_SUCCESS;
91 break;
92
93 case IRP_MJ_CLOSE:
94 status = STATUS_SUCCESS;
95 break;
96
97 case IRP_MJ_WRITE:
98 DPRINT("(Parallel Port Driver) Writing %d bytes\n",
99 Stack->Parameters.Write.Length);
100 for (i=0;i<Stack->Parameters.Write.Length;i++)
101 {
102 Parallel_putchar(((char *)Irp->UserBuffer)[i]);
103 }
104 status = STATUS_SUCCESS;
105 break;
106
107 default:
108 status = STATUS_NOT_IMPLEMENTED;
109 break;
110 }
111
112 Irp->IoStatus.Status = status;
113 Irp->IoStatus.Information = 0;
114
115 IoCompleteRequest(Irp, IO_NO_INCREMENT);
116 return(status);
117 }
118
119 NTSTATUS STDCALL
120 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
121 /*
122 * FUNCTION: Called by the system to initalize the driver
123 * ARGUMENTS:
124 * DriverObject = object describing this driver
125 * RegistryPath = path to our configuration entries
126 * RETURNS: Success or failure
127 */
128 {
129 PDEVICE_OBJECT DeviceObject;
130 UNICODE_STRING DeviceName = UNICODE_STRING_INITIALIZER(L"\\Device\\Parallel");
131 NTSTATUS Status;
132
133 DPRINT("Parallel Port Driver 0.0.1\n");
134
135 Status = IoCreateDevice(DriverObject,
136 0,
137 &DeviceName,
138 FILE_DEVICE_PARALLEL_PORT,
139 0,
140 FALSE,
141 &DeviceObject);
142 if (!NT_SUCCESS(Status))
143 {
144 return(Status);
145 }
146
147 DeviceObject->Flags=0;
148 DriverObject->MajorFunction[IRP_MJ_CLOSE] = Dispatch;
149 DriverObject->MajorFunction[IRP_MJ_CREATE] = Dispatch;
150 DriverObject->MajorFunction[IRP_MJ_WRITE] = Dispatch;
151 DriverObject->DriverUnload = NULL;
152
153 return(STATUS_SUCCESS);
154 }
155
156 /* EOF */