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.

128 lines
3.2 KiB

  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 1996-1999 Microsoft Corporation
  4. *
  5. * @doc
  6. * @module comm.c | IrSIR NDIS Miniport Driver
  7. * @comm
  8. *
  9. *-----------------------------------------------------------------------------
  10. *
  11. * Author: Scott Holden (sholden)
  12. *
  13. * Date: 10/1/1996 (created)
  14. *
  15. * Contents:
  16. *
  17. *****************************************************************************/
  18. #include "irsir.h"
  19. /*****************************************************************************
  20. *
  21. * Function: SetSpeed
  22. *
  23. * Synopsis: Set the baud rate of the uart and the dongle.
  24. *
  25. * Arguments: pThisDev - pointer to ir device to set the link speed
  26. *
  27. * Returns: STATUS_SUCCESS
  28. * STATUS_UNSUCCESSFUL
  29. *
  30. * Algorithm:
  31. *
  32. * History: dd-mm-yyyy Author Comment
  33. * 10/2/1996 sholden author
  34. *
  35. * Notes:
  36. * This function will only be called once we know that all
  37. * outstanding receives and sends to the serial port have
  38. * been completed.
  39. *
  40. * This routine must be called from IRQL PASSIVE_LEVEL.
  41. *
  42. *****************************************************************************/
  43. NTSTATUS
  44. SetSpeed(
  45. PIR_DEVICE pThisDev
  46. )
  47. {
  48. ULONG bitsPerSec, dwNotUsed;
  49. NTSTATUS status;
  50. UCHAR c[2];
  51. DEBUGMSG(DBG_FUNC, ("+SetSpeed\n"));
  52. if (pThisDev->linkSpeedInfo)
  53. {
  54. bitsPerSec = (ULONG)pThisDev->linkSpeedInfo->bitsPerSec;
  55. }
  56. else
  57. {
  58. bitsPerSec = 9600;
  59. DEBUGMSG(DBG_ERROR, ("IRSIR: pThisDev->linkSpeedInfo not set\n"));
  60. }
  61. DEBUGMSG(DBG_STAT, (" Requested speed = %d\n", bitsPerSec));
  62. ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
  63. // We need to be certain any data sent previously was flushed.
  64. // Since there are so many serial devices out there, and they
  65. // seem to handle flushing differently, send a little extra
  66. // data out to act as a plunger.
  67. c[0] = c[1] = SLOW_IR_EXTRA_BOF;
  68. (void)SerialSynchronousWrite(pThisDev->pSerialDevObj,
  69. c, sizeof(c), &dwNotUsed);
  70. // And just for good measure.
  71. NdisMSleep(50000);
  72. //
  73. // The dongle is responsible for performing the SerialSetBaudRate
  74. // to set the UART to the correct speed it requires for
  75. // performing commands and changing the rate of the dongle.
  76. //
  77. //
  78. // Set the speed of the dongle to the requested speed.
  79. //
  80. status = pThisDev->dongle.SetSpeed(
  81. pThisDev->pSerialDevObj,
  82. bitsPerSec,
  83. pThisDev->currentSpeed
  84. );
  85. if (status != STATUS_SUCCESS)
  86. {
  87. goto done;
  88. }
  89. //
  90. // Set the speed of the UART to the requested speed.
  91. //
  92. status = SerialSetBaudRate(
  93. pThisDev->pSerialDevObj,
  94. &bitsPerSec
  95. );
  96. if (status != STATUS_SUCCESS)
  97. {
  98. goto done;
  99. }
  100. //
  101. // Update our current speed.
  102. //
  103. pThisDev->currentSpeed = bitsPerSec;
  104. done:
  105. DEBUGMSG(DBG_FUNC, ("-SetSpeed\n"));
  106. return status;
  107. }