Source code of Windows XP (NT5)
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.

113 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. #include "readwrit.h"
  16. NTSTATUS
  17. SppIeeeWrite(
  18. IN PDEVICE_EXTENSION Extension,
  19. IN PVOID Buffer,
  20. IN ULONG BytesToWrite,
  21. OUT PULONG BytesTransferred
  22. )
  23. /*++
  24. Routine Description:
  25. Arguments:
  26. Extension - Supplies the device extension.
  27. Return Value:
  28. None.
  29. --*/
  30. {
  31. NTSTATUS status = STATUS_SUCCESS;
  32. PUCHAR Controller = Extension->Controller;
  33. PUCHAR pPortDSR = Extension->Controller + OFFSET_DSR;
  34. PUCHAR pPortDCR = Extension->Controller + OFFSET_DCR;
  35. PUCHAR pPortData = Extension->Controller + OFFSET_DATA;
  36. ULONG wByteCount = BytesToWrite;
  37. UCHAR bDCRstrobe; // Holds precomputed value for state 35
  38. UCHAR bDCRnormal; // Holds precomputed value for state 37
  39. PUCHAR lpsBufPtr = (PUCHAR)Buffer; // Pointer to buffer cast to desired data type
  40. // Make precomputed DCR values for strobe and periph ack
  41. bDCRstrobe = SET_DCR(DIR_WRITE, IRQEN_DISABLE, ACTIVE, ACTIVE, ACTIVE, INACTIVE);
  42. bDCRnormal = SET_DCR(DIR_WRITE, IRQEN_DISABLE, ACTIVE, ACTIVE, ACTIVE, ACTIVE);
  43. // Wait a bit to give nBusy a chance to settle, because
  44. // WriteComm will bail immediately if the device says busy
  45. if ( CHECK_DSR( Controller,
  46. INACTIVE, DONT_CARE, DONT_CARE, DONT_CARE, DONT_CARE,
  47. IEEE_MAXTIME_TL ) )
  48. {
  49. while (wByteCount)
  50. {
  51. // Place a data byte on the bus
  52. WRITE_PORT_UCHAR(pPortData, *lpsBufPtr);
  53. // Start handshake by dropping strobe
  54. WRITE_PORT_UCHAR(pPortDCR, bDCRstrobe);
  55. // Wait for Periph Busy Response
  56. if ( !CHECK_DSR(Controller, ACTIVE, DONT_CARE, DONT_CARE,
  57. DONT_CARE, DONT_CARE, IEEE_MAXTIME_TL) )
  58. {
  59. status = STATUS_DEVICE_BUSY;
  60. break;
  61. }
  62. // Printer responded by making Busy high -- the byte has
  63. // been accepted. Adjust the data pointer.
  64. lpsBufPtr++;
  65. // Finish handshake by raising strobe
  66. WRITE_PORT_UCHAR(pPortDCR, bDCRnormal);
  67. // Adjust count while we're waiting for the peripheral
  68. // to respond with state 32
  69. wByteCount--;
  70. // Wait for PeriphAck and PeriphBusy response
  71. if ( !CHECK_DSR(Controller, INACTIVE, ACTIVE, DONT_CARE, DONT_CARE,
  72. DONT_CARE, IEEE_MAXTIME_TL) )
  73. {
  74. // Set appropriate error based on relaxed timeout.
  75. status = STATUS_DEVICE_BUSY;
  76. break;
  77. }
  78. } // while...
  79. *BytesTransferred = BytesToWrite - wByteCount; // Set current count.
  80. }
  81. return status;
  82. }