• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Embedded Software » WinCE » WinCE forum » omap3530 spi driver usage from c# on wince6.0 with BSP6.09
Share
WinCE
  • Forum
Options
  • Subscribe via RSS

omap3530 spi driver usage from c# on wince6.0 with BSP6.09

omap3530 spi driver usage from c# on wince6.0 with BSP6.09

This question is answered
Istvan Magashegyi
Posted by Istvan Magashegyi
on Aug 06 2012 07:23 AM
Prodigy10 points

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);

error = Marshal.GetLastWin32Error();

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

Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • AnBer
    Posted by AnBer
    on Aug 08 2012 06:39 AM
    Verified Answer
    Verified by Adeneo Embedded support team
    Genius9595 points

    Hi,

    The below post on using SPI on WINCE6 might help:
    http://e2e.ti.com/support/embedded/wince/f/353/t/140090.aspx
    http://e2e.ti.com/support/embedded/wince/f/353/t/62885.aspx

    Anthony

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use