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.

228 lines
5.6 KiB

  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 1997-1999 Microsoft Corporation
  4. *
  5. * @doc
  6. * @module TEKRAM.c | IrSIR NDIS Miniport Driver
  7. * @comm
  8. *
  9. *-----------------------------------------------------------------------------
  10. *
  11. * Author: Stan Adermann (stana)
  12. *
  13. * Date: 12/17/1997 (created)
  14. *
  15. * Contents: TEKRAM IR-210B dongle specific code for initialization,
  16. * deinit, and setting the baud rate of the device.
  17. *
  18. *****************************************************************************/
  19. #include "irsir.h"
  20. #include "dongle.h"
  21. #define TEKRAM_IRDA_SPEEDS ( \
  22. NDIS_IRDA_SPEED_2400 | \
  23. NDIS_IRDA_SPEED_9600 | \
  24. NDIS_IRDA_SPEED_19200 | \
  25. NDIS_IRDA_SPEED_38400 | \
  26. NDIS_IRDA_SPEED_57600 | \
  27. NDIS_IRDA_SPEED_115200 \
  28. )
  29. NDIS_STATUS
  30. TEKRAM_Reset(IN PDEVICE_OBJECT pSerialDevObj)
  31. {
  32. DEBUGMSG(DBG_FUNC, ("+TEKRAM_Reset\n"));
  33. (void)SerialClrDTR(pSerialDevObj);
  34. (void)SerialClrRTS(pSerialDevObj);
  35. NdisMSleep(50000);
  36. (void)SerialSetRTS(pSerialDevObj);
  37. NdisMSleep(50000);
  38. (void)SerialSetDTR(pSerialDevObj);
  39. NdisMSleep(50000);
  40. DEBUGMSG(DBG_FUNC, ("-TEKRAM_Reset\n"));
  41. return NDIS_STATUS_SUCCESS;
  42. }
  43. void
  44. TEKRAM_WriteCommand(
  45. IN PDEVICE_OBJECT pSerialDevObj,
  46. IN UCHAR Command)
  47. {
  48. ULONG BytesWritten;
  49. (void)SerialSetDTR(pSerialDevObj);
  50. (void)SerialClrRTS(pSerialDevObj);
  51. NdisMSleep(2000);
  52. (void)SerialSynchronousWrite(pSerialDevObj,
  53. &Command,
  54. 1,
  55. &BytesWritten);
  56. NdisMSleep(20000);
  57. (void)SerialSetDTR(pSerialDevObj);
  58. (void)SerialSetRTS(pSerialDevObj);
  59. NdisMSleep(5000);
  60. }
  61. NDIS_STATUS
  62. TEKRAM_QueryCaps(
  63. OUT PDONGLE_CAPABILITIES pDongleCaps
  64. )
  65. {
  66. DEBUGMSG(DBG_FUNC, ("+TEKRAM_Init\n"));
  67. ASSERT(pDongleCaps != NULL);
  68. pDongleCaps->supportedSpeedsMask = TEKRAM_IRDA_SPEEDS;
  69. pDongleCaps->turnAroundTime_usec = 100;
  70. pDongleCaps->extraBOFsRequired = 0;
  71. DEBUGMSG(DBG_FUNC, ("-TEKRAM_Init\n"));
  72. return NDIS_STATUS_SUCCESS;
  73. }
  74. /*****************************************************************************
  75. *
  76. * Function: TEKRAM_Init
  77. *
  78. * Synopsis: Initialize the TEKRAM dongle.
  79. *
  80. * Arguments:
  81. *
  82. * Returns: NDIS_STATUS_SUCCESS
  83. * DONGLE_CAPABILITIES
  84. *
  85. * Algorithm:
  86. *
  87. * History: dd-mm-yyyy Author Comment
  88. * 10/2/1996 sholden author
  89. *
  90. * Notes:
  91. *
  92. *****************************************************************************/
  93. NDIS_STATUS
  94. TEKRAM_Init(
  95. IN PDEVICE_OBJECT pSerialDevObj
  96. )
  97. {
  98. DEBUGMSG(DBG_FUNC, ("+TEKRAM_Init\n"));
  99. TEKRAM_SetSpeed(pSerialDevObj, 9600, 0); // This calls reset
  100. DEBUGMSG(DBG_FUNC, ("-TEKRAM_Init\n"));
  101. return NDIS_STATUS_SUCCESS;
  102. }
  103. /*****************************************************************************
  104. *
  105. * Function: TEKRAM_Deinit
  106. *
  107. * Synopsis: The TEKRAM dongle doesn't require any special deinit, but for
  108. * purposes of being symmetrical with other dongles...
  109. *
  110. * Arguments:
  111. *
  112. * Returns:
  113. *
  114. * Algorithm:
  115. *
  116. * History: dd-mm-yyyy Author Comment
  117. * 10/2/1996 sholden author
  118. *
  119. * Notes:
  120. *
  121. *
  122. *****************************************************************************/
  123. VOID
  124. TEKRAM_Deinit(
  125. IN PDEVICE_OBJECT pSerialDevObj
  126. )
  127. {
  128. DEBUGMSG(DBG_FUNC, ("+TEKRAM_Deinit\n"));
  129. (void)SerialClrDTR(pSerialDevObj);
  130. (void)SerialClrRTS(pSerialDevObj);
  131. DEBUGMSG(DBG_FUNC, ("-TEKRAM_Deinit\n"));
  132. return;
  133. }
  134. /*****************************************************************************
  135. *
  136. * Function: TEKRAM_SetSpeed
  137. *
  138. * Synopsis: set the baud rate of the TEKRAM dongle
  139. *
  140. * Arguments:
  141. *
  142. * Returns: NDIS_STATUS_SUCCESS if bitsPerSec = 9600 || 19200 || 115200
  143. * NDIS_STATUS_FAILURE otherwise
  144. *
  145. * Algorithm:
  146. *
  147. * History: dd-mm-yyyy Author Comment
  148. * 10/2/1996 sholden author
  149. *
  150. * Notes:
  151. * The caller of this function should set the baud rate of the
  152. * serial driver (UART) to 9600 first to ensure that dongle
  153. * receives the commands.
  154. *
  155. *
  156. *****************************************************************************/
  157. NDIS_STATUS
  158. TEKRAM_SetSpeed(
  159. IN PDEVICE_OBJECT pSerialDevObj,
  160. IN UINT bitsPerSec,
  161. IN UINT currentSpeed
  162. )
  163. {
  164. UCHAR ControlByte;
  165. ULONG BytesWritten;
  166. ULONG Baud9600 = 9600;
  167. DEBUGMSG(DBG_FUNC, ("+TEKRAM_SetSpeed\n"));
  168. if (bitsPerSec==currentSpeed)
  169. {
  170. return NDIS_STATUS_SUCCESS;
  171. }
  172. (void)SerialPurge(pSerialDevObj);
  173. (void)SerialSetBaudRate(pSerialDevObj, &Baud9600);
  174. NdisMSleep(10000);
  175. TEKRAM_Reset(pSerialDevObj);
  176. switch (bitsPerSec){
  177. case 2400: ControlByte = 0x18; break;
  178. case 9600: ControlByte = 0x14; break;
  179. case 19200: ControlByte = 0x13; break;
  180. case 38400: ControlByte = 0x12; break;
  181. case 57600: ControlByte = 0x11; break;
  182. case 115200: ControlByte = 0x10; break;
  183. default:
  184. /*
  185. * Illegal speed
  186. */
  187. return NDIS_STATUS_FAILURE;
  188. }
  189. TEKRAM_WriteCommand(pSerialDevObj, 0x14);
  190. TEKRAM_WriteCommand(pSerialDevObj, ControlByte);
  191. DEBUGMSG(DBG_FUNC, ("-TEKRAM_SetSpeed\n"));
  192. return NDIS_STATUS_SUCCESS;
  193. }