Hy,
I am newbe in the WINCE, and i want to use the spi driver of the BSP6.09 (<2/06/2009> 6.09.00) on WINCE6.0. I write the api in c# to use the spi driver. I viewed in the Microsoft Remote Tools Shell which drivers loaded and the spi1 was loaded. I use the following pinvokes:
[DllImport("coredll", SetLastError = true)] internal static extern int DeviceIoControl( UInt32 hDevice, UInt32 dwIoControlCode, IntPtr lpInBuffer, UInt32 nInBufferSize, IntPtr lpOutBuffer, UInt32 nOutBufferSize, UInt32 lpBytesReturned, IntPtr lpOverlapped );
[DllImport("coredll.dll", EntryPoint = "CreateFile", SetLastError = true)] private static extern IntPtr CreateFile( string lpFileName, // pointer to name of the file UInt32 dwDesiredAccess, // access (read-write) mode UInt32 dwShareMode, // share mode IntPtr lpSecurityAttributes, // pointer to security attributes UInt32 dwCreationDisposition, // how to create UInt32 dwFlagsAndAttributes, // file attributes IntPtr hTemplateFile // handle to file with attributes to copy );
And the fuction calls:
IntPtr hSPI = IntPtr.Zero; int error;
DEVICE_CONTEXT_SPI context = new DEVICE_CONTEXT_SPI();
try {
hSPI = CreateFile("SPI1:", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, CREATE_NEW, 1, IntPtr.Zero);
error = Marshal.GetLastWin32Error();
MessageBox.Show(" CreateFile error: " + error); } catch (Exception ex) { error = Marshal.GetLastWin32Error();
MessageBox.Show(ex.ToString() + " The last Win32 Error was: " + error); }
UInt32 IOCTL_DDK_GET_DRIVER_IFC = CTL_CODE(FILE_DEVICE_UNKNOWN, 0x0100, METHOD_BUFFERED, FILE_ANY_ACCESS); //new guid // {0FB30280-7D17-4e29-9245-9EFF57B1AA91}0xfb30280, 0x7d17, 0x4e29, 0x92, 0x45, 0x9e, 0xff, 0x57, 0xb1, 0xaa, 0x91 Guid DEVICE_IFC_SPI_GUID = new Guid((int)0x2e559225, unchecked((short)0xc95e), (short)0x4300, 0x86, 0xe9, 0x6a, 0x5c, 0xbc, 0x7, 0x32, 0x8f);
IntPtr p_DEVICE_IFC_SPI_GUID = Marshal.AllocHGlobal(Marshal.SizeOf(DEVICE_IFC_SPI_GUID)); Marshal.StructureToPtr(DEVICE_IFC_SPI_GUID, p_DEVICE_IFC_SPI_GUID, false);
IntPtr pContext_ifc = Marshal.AllocHGlobal(Marshal.SizeOf(context.ifc)); Marshal.StructureToPtr(context.ifc, pContext_ifc, false);
MessageBox.Show("pContext: " + pContext_ifc.ToString());
DeviceIoControl((UInt32)hSPI.ToInt32(), IOCTL_DDK_GET_DRIVER_IFC, p_DEVICE_IFC_SPI_GUID, (uint)sizeof(Guid), pContext_ifc, (uint)sizeof(DEVICE_IFC_SPI), 0, IntPtr.Zero);
MessageBox.Show(" DeviceIO error: " + error);
And the deviceIO error are always 5 which means ERROR_ACCESS_DENIED.
In the driver code:
if (GetCurrentProcessId() != (DWORD)GetCallerProcess()) { DEBUGMSG(ZONE_ERROR, (L"ERROR: SPI_IOControl: " L"IOCTL_DDK_GET_DRIVER_IFC can be called only from " L"device process (caller process id 0x%08x)\r\n", GetCallerProcess() )); SetLastError(ERROR_ACCESS_DENIED); goto clean;
I think this line send me this error. How can I fix it or handle the deviceIOControl in the right way? Is it possible that I can not use this driver because the kernel loaded it?
I will be grateful for any help. (sorry for my poor english).
Steve
Hi,
The below post on using SPI on WINCE6 might help:http://e2e.ti.com/support/embedded/wince/f/353/t/140090.aspxhttp://e2e.ti.com/support/embedded/wince/f/353/t/62885.aspx
Anthony