Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.2 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1993 - 1998
  3. Module Name:
  4. sppieee.c
  5. Abstract:
  6. This module contains code for the host to utilize an ieee version of
  7. compatibility mode
  8. Author:
  9. Robbie Harris (Hewlett-Packard) 29-July-1998
  10. Environment:
  11. Kernel mode
  12. Revision History :
  13. --*/
  14. #include "pch.h"
  15. NTSTATUS
  16. SppIeeeWrite(
  17. IN PPDO_EXTENSION Extension,
  18. IN PVOID Buffer,
  19. IN ULONG BytesToWrite,
  20. OUT PULONG BytesTransferred
  21. )
  22. /*++
  23. Routine Description:
  24. Arguments:
  25. Extension - Supplies the device extension.
  26. Return Value:
  27. None.
  28. --*/
  29. {
  30. NTSTATUS status = STATUS_SUCCESS;
  31. PUCHAR Controller = Extension->Controller;
  32. PUCHAR pPortDCR = Extension->Controller + OFFSET_DCR;
  33. PUCHAR pPortData = Extension->Controller + OFFSET_DATA;
  34. ULONG wByteCount = BytesToWrite;
  35. UCHAR bDCRstrobe; // Holds precomputed value for state 35
  36. UCHAR bDCRnormal; // Holds precomputed value for state 37
  37. PUCHAR lpsBufPtr = (PUCHAR)Buffer; // Pointer to buffer cast to desired data type
  38. // Make precomputed DCR values for strobe and periph ack
  39. bDCRstrobe = SET_DCR(DIR_WRITE, IRQEN_DISABLE, ACTIVE, ACTIVE, ACTIVE, INACTIVE);
  40. bDCRnormal = SET_DCR(DIR_WRITE, IRQEN_DISABLE, ACTIVE, ACTIVE, ACTIVE, ACTIVE);
  41. // Wait a bit to give nBusy a chance to settle, because
  42. // WriteComm will bail immediately if the device says busy
  43. if ( CHECK_DSR( Controller,
  44. INACTIVE, DONT_CARE, DONT_CARE, DONT_CARE, DONT_CARE,
  45. IEEE_MAXTIME_TL ) )
  46. {
  47. while (wByteCount)
  48. {
  49. // Place a data byte on the bus
  50. P5WritePortUchar(pPortData, *lpsBufPtr);
  51. // Start handshake by dropping strobe
  52. P5WritePortUchar(pPortDCR, bDCRstrobe);
  53. // Wait for Periph Busy Response
  54. if ( !CHECK_DSR(Controller, ACTIVE, DONT_CARE, DONT_CARE,
  55. DONT_CARE, DONT_CARE, IEEE_MAXTIME_TL) )
  56. {
  57. status = STATUS_DEVICE_BUSY;
  58. break;
  59. }
  60. // Printer responded by making Busy high -- the byte has
  61. // been accepted. Adjust the data pointer.
  62. lpsBufPtr++;
  63. // Finish handshake by raising strobe
  64. P5WritePortUchar(pPortDCR, bDCRnormal);
  65. // Adjust count while we're waiting for the peripheral
  66. // to respond with state 32
  67. wByteCount--;
  68. // Wait for PeriphAck and PeriphBusy response
  69. if ( !CHECK_DSR(Controller, INACTIVE, ACTIVE, DONT_CARE, DONT_CARE,
  70. DONT_CARE, IEEE_MAXTIME_TL) )
  71. {
  72. // Set appropriate error based on relaxed timeout.
  73. status = STATUS_DEVICE_BUSY;
  74. break;
  75. }
  76. } // while...
  77. *BytesTransferred = BytesToWrite - wByteCount; // Set current count.
  78. }
  79. return status;
  80. }