ITek_util.c
上传用户:cnfair
上传日期:2007-01-07
资源大小:32k
文件大小:3k
源码类别:

驱动编程

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////////////
  2. // atm_util.c
  3. //  any utility routines
  4. //to use the following functions from standard c-library directly
  5. #include  <string.h>
  6. #pragma intrinsic(memcpy, memcmp, memset, strcat, strcmp, strcpy, strlen)
  7. #pragma warning(disable:4201 4514 4100 4127)
  8. //to include Windows95 DDK header files
  9. //
  10. #define WANTVXDWRAPS
  11. #include  <basedef.h>
  12. #include  <vmm.h>
  13. #include  <vxdwraps.h>
  14. #include  <debug.h>
  15. // copied from Miniport.h for NT3.51
  16. #define FIELD_OFFSET(type, field)    ((LONG)&(((type *)0)->field))
  17. #include  <ndis.h>
  18. #include  <vwin32.h>
  19. #include  <efilter.h>
  20. #include "ITek_type.h"
  21. #include    "ITek_init.h"
  22. #include    "ITek_util.h"
  23. #pragma VxD_LOCKED_CODE_SEG
  24. #pragma VxD_LOCKED_DATA_SEG
  25. #ifdef ITEK_TIMER
  26. VOID NDIS_API
  27. ITekTimerFunction(
  28. IN PVOID SystemSpecific1,
  29. IN PVOID FunctionContext,
  30. IN PVOID SystemSpecific2,
  31. IN PVOID SystemSpecific3
  32. )
  33. {
  34. PITEK_ADAPTER pITekAdapter = (PITEK_ADAPTER)FunctionContext;
  35. #ifdef DEBUG
  36. Debug_Printf("ITEK:ITekTimerFunction() Entryn");
  37. #endif
  38. NdisSetTimer(
  39. &pITekAdapter->NdisTimer,
  40. ITEK_TIMEOUT_MSEC);
  41. #ifdef DEBUG
  42. Debug_Printf("ITEK:ITekTimerFunction() Returnn");
  43. #endif
  44. return;
  45. }
  46. #endif //ITEK_TIMER
  47. VOID NDIS_API
  48. ITekAllocateSharedMemory(
  49. IN NDIS_HANDLE NdisAdapterHandle,
  50. IN ULONG Length,
  51. IN ULONG AlignMask,
  52. OUT PVOID *VirtualAddress,
  53. OUT PNDIS_PHYSICAL_ADDRESS PhysicalAddress
  54. )
  55. {
  56. ULONG nPages;
  57. PVOID VirtualAddressLocal;
  58. PVOID PhysicalAddressLocal;
  59. nPages = (Length+4095)/4096;
  60. VirtualAddressLocal = (PVOID)_PageAllocate(
  61. nPages, //nPages
  62. PG_SYS, //nType
  63. (ULONG) 0, //VM 
  64. AlignMask, //AignMask
  65. (ULONG) 1, //minPhys 
  66. (ULONG)0x0000FFFF, //maxPhys
  67. (PVOID *)&PhysicalAddressLocal, //
  68. (ULONG)(PAGECONTIG | PAGEFIXED | PAGEUSEALIGN) //flags
  69. );
  70. *VirtualAddress = VirtualAddressLocal;
  71. *PhysicalAddress = (NDIS_PHYSICAL_ADDRESS)PhysicalAddressLocal;
  72. return;
  73. }
  74. VOID NDIS_API
  75. ITekFreeSharedMemory(
  76. IN NDIS_HANDLE NdisAdapterHandle,
  77. IN PVOID VirtualAddress
  78. )
  79. {
  80. _PageFree(VirtualAddress, 0);
  81. return;
  82. }
  83. VOID NDIS_API
  84. ITekAllocateMemory(
  85. OUT PVOID *VirtualMemory,
  86. IN ULONG nBytes
  87. )
  88. {
  89. PVOID VirtualMemoryLocal;
  90. VirtualMemoryLocal = (PVOID)_HeapAllocate(
  91. nBytes,
  92. (ULONG)(HEAPLOCKEDIFDP|HEAPZEROINIT));
  93. *VirtualMemory = VirtualMemoryLocal;
  94. return;
  95. }
  96. VOID NDIS_API
  97. ITekFreeMemory(
  98. IN PVOID VirtualMemory
  99. )
  100. {
  101. (void)_HeapFree(VirtualMemory, 0);
  102. return;
  103. }