ReactOS 0.4.15-dev-7924-g5949c20
mpu401.h File Reference
#include "../../../dll/win32/mmdrv/mmdef.h"
Include dependency graph for mpu401.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DEVICE_EXTENSION
 
struct  _DEVICE_INSTANCE
 

Macros

#define DEFAULT_PORT   0x330
 
#define DEFAULT_IRQ   9
 
#define DEVICE_SUBKEY   L"Devices"
 
#define PARMS_SUBKEY   L"Parameters"
 
#define REGISTRY_PORT   L"Port"
 
#define MPU401_PORT   DEFAULT_PORT
 
#define MPU401_IRQ   DEFAULT_IRQ
 
#define MPU401_TIMEOUT   10000
 
#define MPU401_WRITE_DATA(bp, x)   WRITE_PORT_UCHAR((PUCHAR) bp, x)
 
#define MPU401_READ_DATA(bp)   READ_PORT_UCHAR((PUCHAR) bp)
 
#define MPU401_WRITE_COMMAND(bp, x)   WRITE_PORT_UCHAR((PUCHAR) bp+1, x)
 
#define MPU401_READ_STATUS(bp)   READ_PORT_UCHAR((PUCHAR) bp+1)
 
#define MPU401_READY_TO_SEND(bp)    MPU401_READ_STATUS(bp) & 0x80
 
#define MPU401_READY_TO_RECEIVE(bp)    MPU401_READ_STATUS(bp) & 0x40
 
#define MPU401_WRITE_BYTE(bp, x)    if (WaitToSend(bp)) MPU401_WRITE_DATA(bp, x)
 
#define MPU401_WRITE_MESSAGE(bp, status, da, db)
 

Typedefs

typedef struct _DEVICE_EXTENSION DEVICE_EXTENSION
 
typedef struct _DEVICE_EXTENSIONPDEVICE_EXTENSION
 
typedef struct _DEVICE_INSTANCE DEVICE_INSTANCE
 
typedef struct _DEVICE_INSTANCEPDEVICE_INSTANCE
 
typedef NTSTATUS REGISTRY_CALLBACK_ROUTINE(PWSTR RegistryPath, PVOID Context)
 
typedef REGISTRY_CALLBACK_ROUTINEPREGISTRY_CALLBACK_ROUTINE
 

Functions

BOOLEAN WaitToSend (ULONG BasePort)
 
BOOLEAN WaitToReceive (ULONG BasePort)
 
BOOLEAN InitUARTMode (ULONG BasePort)
 
NTSTATUS NTAPI EnumDeviceKeys (IN PUNICODE_STRING RegistryPath, IN PWSTR SubKey, IN PREGISTRY_CALLBACK_ROUTINE Callback, IN PVOID Context)
 
NTSTATUS NTAPI LoadSettings (IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 

Macro Definition Documentation

◆ DEFAULT_IRQ

#define DEFAULT_IRQ   9

Definition at line 20 of file mpu401.h.

◆ DEFAULT_PORT

#define DEFAULT_PORT   0x330

Definition at line 19 of file mpu401.h.

◆ DEVICE_SUBKEY

#define DEVICE_SUBKEY   L"Devices"

Definition at line 22 of file mpu401.h.

◆ MPU401_IRQ

#define MPU401_IRQ   DEFAULT_IRQ

Definition at line 29 of file mpu401.h.

◆ MPU401_PORT

#define MPU401_PORT   DEFAULT_PORT

Definition at line 28 of file mpu401.h.

◆ MPU401_READ_DATA

#define MPU401_READ_DATA (   bp)    READ_PORT_UCHAR((PUCHAR) bp)

Definition at line 54 of file mpu401.h.

◆ MPU401_READ_STATUS

#define MPU401_READ_STATUS (   bp)    READ_PORT_UCHAR((PUCHAR) bp+1)

Definition at line 56 of file mpu401.h.

◆ MPU401_READY_TO_RECEIVE

#define MPU401_READY_TO_RECEIVE (   bp)     MPU401_READ_STATUS(bp) & 0x40

Definition at line 64 of file mpu401.h.

◆ MPU401_READY_TO_SEND

#define MPU401_READY_TO_SEND (   bp)     MPU401_READ_STATUS(bp) & 0x80

Definition at line 61 of file mpu401.h.

◆ MPU401_TIMEOUT

#define MPU401_TIMEOUT   10000

Definition at line 31 of file mpu401.h.

◆ MPU401_WRITE_BYTE

#define MPU401_WRITE_BYTE (   bp,
  x 
)     if (WaitToSend(bp)) MPU401_WRITE_DATA(bp, x)

Definition at line 68 of file mpu401.h.

◆ MPU401_WRITE_COMMAND

#define MPU401_WRITE_COMMAND (   bp,
  x 
)    WRITE_PORT_UCHAR((PUCHAR) bp+1, x)

Definition at line 55 of file mpu401.h.

◆ MPU401_WRITE_DATA

#define MPU401_WRITE_DATA (   bp,
  x 
)    WRITE_PORT_UCHAR((PUCHAR) bp, x)

Definition at line 53 of file mpu401.h.

◆ MPU401_WRITE_MESSAGE

#define MPU401_WRITE_MESSAGE (   bp,
  status,
  da,
  db 
)
Value:
MPU401_WRITE(bp, status); \
MPU401_WRITE(bp, da); \
MPU401_WRITE(bp, db)
Definition: ps.c:97

Definition at line 71 of file mpu401.h.

◆ PARMS_SUBKEY

#define PARMS_SUBKEY   L"Parameters"

Definition at line 23 of file mpu401.h.

◆ REGISTRY_PORT

#define REGISTRY_PORT   L"Port"

Definition at line 25 of file mpu401.h.

Typedef Documentation

◆ DEVICE_EXTENSION

◆ DEVICE_INSTANCE

◆ PDEVICE_EXTENSION

◆ PDEVICE_INSTANCE

◆ PREGISTRY_CALLBACK_ROUTINE

Definition at line 121 of file mpu401.h.

◆ REGISTRY_CALLBACK_ROUTINE

typedef NTSTATUS REGISTRY_CALLBACK_ROUTINE(PWSTR RegistryPath, PVOID Context)

Definition at line 120 of file mpu401.h.

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 16 of file battc.c.

18{
19 DPRINT("Battery class driver initialized\n");
20
21 return STATUS_SUCCESS;
22}
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

◆ EnumDeviceKeys()

NTSTATUS NTAPI EnumDeviceKeys ( IN PUNICODE_STRING  RegistryPath,
IN PWSTR  SubKey,
IN PREGISTRY_CALLBACK_ROUTINE  Callback,
IN PVOID  Context 
)

Definition at line 73 of file settings.c.

92{
93 NTSTATUS s;
95 HANDLE hKey, hSubKey;
97 ULONG i;
98
99 // Attempt to open the key
100
103
104 s = ZwOpenKey(&hKey, KEY_READ, &oa);
105
106 TEST_STATUS(s); // debugging
107
108 if (! NT_SUCCESS(s))
109 return s; // Problem
110
112
113 DPRINT("Subkey: %wZ\n", &SubkeyName);
114
117
118 s = ZwOpenKey(&hSubKey, KEY_ENUMERATE_SUB_KEYS, &oa);
119
120 ZwClose(hKey);
121
122 TEST_STATUS(s); // debugging
123
124 if (! NT_SUCCESS(s))
125 return s;
126
127
128 // And now, the enumeration
129
130 for (i = 0;; i ++)
131 {
135 ULONG Size = 0;
136 PWSTR Pos;
137 PWSTR Name;
138
139 // Find the length of the subkey data
140
141// Info.NameLength = 0; // TEMPORARY!
142
143 s = ZwEnumerateKey(hSubKey, i, KeyBasicInformation, &Info,
144 sizeof(Info), &ResultLength);
145
147 break;
148
149 DPRINT("Found an entry, allocating memory...\n");
150
151// Size = Info.NameLength + FIELD_OFFSET(KEY_BASIC_INFORMATION, Name[0]);
153
154 DPRINT("Size is %d\n", Size);
155
157
158 if (pInfo == NULL)
159 {
160 DPRINT("INSUFFICIENT RESOURCES!\n");
162 break;
163 }
164
165 DPRINT("Re-enumerating...\n");
166
167 s = ZwEnumerateKey(hSubKey, i, KeyBasicInformation, pInfo, Size,
168 &ResultLength);
169
170// TEST_STATUS(s); // debugging
171
172 if (! NT_SUCCESS(s))
173 {
174 ExFreePool((PVOID) pInfo);
176 break;
177 }
178
179 DPRINT("Allocating memory for name...\n");
180
182 RegistryPath->Length + sizeof(WCHAR) +
183 SubkeyName.Length + sizeof(WCHAR) +
184 pInfo->NameLength + sizeof(UNICODE_NULL));
185
186 if (Name == NULL)
187 {
188 DPRINT("INSUFFICIENT RESOURCES!");
189 ExFreePool((PVOID) pInfo);
191 }
192
193 // Copy the key name
195 Pos = Name + (RegistryPath->Length / sizeof(WCHAR));
196 Pos[0] = '\\';
197 Pos++;
198
199 // Copy the parameters sub key name
200 RtlCopyMemory((PVOID)Pos, (PVOID)SubKey, SubkeyName.Length); //SubkeyName?
201 Pos += SubkeyName.Length / sizeof(WCHAR);
202 Pos[0] = '\\';
203 Pos ++;
204
205 // Copy the device sub key name
206 RtlCopyMemory((PVOID)Pos, (PVOID)pInfo->Name, pInfo->NameLength);
207 Pos += pInfo->NameLength / sizeof(WCHAR);
208 Pos[0] = UNICODE_NULL;
209
210 ExFreePool((PVOID)pInfo);
211
212 DPRINT("Calling callback...\n");
213
214 s = (*Callback)(Name, Context);
215
216 if (! NT_SUCCESS(s))
217 { DPRINT("Callback FAILED\n");
218 break;}
219 }
220
221 ZwClose(hSubKey);
222
223 DPRINT("%d device registry keys found\n", i);
224
225 if ((i == 0) && (s == STATUS_NO_MORE_ENTRIES))
227
229}
struct NameRec_ * Name
Definition: cdprocs.h:460
LONG NTSTATUS
Definition: precomp.h:26
_In_opt_ PWSTR SubkeyName
Definition: cdrom.h:960
ush Pos
Definition: deflate.h:92
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
FxAutoRegKey hKey
GLdouble s
Definition: gl.h:2039
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define TEST_STATUS(s)
Definition: sbdebug.h:2
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyBasicInformation
Definition: nt_native.h:1131
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct _KEY_BASIC_INFORMATION * PKEY_BASIC_INFORMATION
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define UNICODE_NULL
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:619
uint16_t * PWSTR
Definition: typedefs.h:56
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ InitUARTMode()

BOOLEAN InitUARTMode ( ULONG  BasePort)

Definition at line 64 of file portio.c.

65{
66 ULONG TimeOut;
67 UCHAR Status = 0;
68
69 DbgPrint("InitUARTMode() called\n");
70
71 // Check if it's OK to send
72 if (! WaitToSend(BasePort))
73 return FALSE;
74
75 DbgPrint("Resetting MPU401\n");
76
77 // Send an MPU reset:
78 MPU401_WRITE_COMMAND(BasePort, 0xff);
79
80 // Check if it's OK to receive (some cards will ignore the above reset
81 // command and so will not issue an ACK, so time out is NOT an error)
82 DbgPrint("Waiting for an ACK\n");
83 if (WaitToReceive(BasePort))
84 {
85 // Check to make sure the reset was acknowledged:
86 for (TimeOut = MPU401_TIMEOUT;
87 (Status = (MPU401_READ_DATA(BasePort) & 0xfe) && TimeOut > 0);
88 TimeOut --);
89 }
90
91 DbgPrint("Entering UART mode\n");
92 // Now we kick the MPU401 into UART ("dumb") mode
93 MPU401_WRITE_COMMAND(BasePort, 0x3f);
94
95 return TRUE;
96}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOLEAN WaitToReceive(ULONG BasePort)
Definition: portio.c:40
BOOLEAN WaitToSend(ULONG BasePort)
Definition: portio.c:16
Status
Definition: gdiplustypes.h:25
#define DbgPrint
Definition: hal.h:12
#define MPU401_WRITE_COMMAND(bp, x)
Definition: mpu401.h:55
#define MPU401_TIMEOUT
Definition: mpu401.h:31
#define MPU401_READ_DATA(bp)
Definition: mpu401.h:54
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by InitDevice().

◆ LoadSettings()

NTSTATUS NTAPI LoadSettings ( IN PWSTR  ValueName,
IN ULONG  ValueType,
IN PVOID  ValueData,
IN ULONG  ValueLength,
IN PVOID  Context,
IN PVOID  EntryContext 
)

Definition at line 233 of file settings.c.

255{
257
258 if (ValueType == REG_DWORD)
259 {
261 {
262 DeviceInfo->Port = *(PULONG) ValueData;
263 DPRINT("Registry port = 0x%x\n", DeviceInfo->Port);
264 }
265
266 // More to come... (config.c)
267 }
268
269 else
270 {
271 // ?
272 }
273
274 return STATUS_SUCCESS;
275}
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
#define REGISTRY_PORT
Definition: mpu401.h:25
#define REG_DWORD
Definition: sdbapi.c:596
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
uint32_t * PULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243

◆ WaitToReceive()

BOOLEAN WaitToReceive ( ULONG  BasePort)

Definition at line 40 of file portio.c.

41{
42 int TimeOut;
43
44 DbgPrint("WaitToSend ");
45
46 // Check if it's OK to receive
47 for (TimeOut = MPU401_TIMEOUT;
48 ! MPU401_READY_TO_RECEIVE(BasePort) && TimeOut > 0;
49 TimeOut --);
50
51 // If a time-out occurs, we report failure
52 if (! TimeOut)
53 {
54 DbgPrint("FAILED\n");
55 return FALSE;
56 }
57
58 DbgPrint("SUCCEEDED\n");
59
60 return TRUE;
61}
#define MPU401_READY_TO_RECEIVE(bp)
Definition: mpu401.h:64

Referenced by IsSpeakerEnabled().

◆ WaitToSend()

BOOLEAN WaitToSend ( ULONG  BasePort)

Definition at line 16 of file portio.c.

17{
18 int TimeOut;
19
20 DbgPrint("WaitToSend ");
21
22 // Check if it's OK to send
23 for (TimeOut = MPU401_TIMEOUT;
24 ! MPU401_READY_TO_SEND(BasePort) && TimeOut > 0;
25 TimeOut --);
26
27 // If a time-out occurs, we report failure
28 if (! TimeOut)
29 {
30 DbgPrint("FAILED\n");
31 return FALSE;
32 }
33
34 DbgPrint("SUCCEEDED\n");
35
36 return TRUE;
37}
#define MPU401_READY_TO_SEND(bp)
Definition: mpu401.h:61

Referenced by MPU401Create().