How to use GPIO on a PXA270

Last post 04-18-2008 3:37 by srue. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 03-31-2008 1:30

    • srue
    • Top 150 Contributor
    • Joined on 03-30-2008
    • Posts 3

    How to use GPIO on a PXA270

    Hello

    I'm writing an C# application on a PXA270. I'd like to read the value a GPIO Pin and raise an event if the state is changing.

     Thanks for your help

    Filed under:
  • 03-31-2008 2:44 In reply to

    • neil
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-30-2007
    • North Wales
    • Posts 1,132

    Re: How to use GPIO on a PXA270

    Check out the PhysicalAddressPointer class in the OpenNETCF.IO namespace of the Smart Device Framework. You can find an example of its use on Chris' blog and by searching these forums. Also, you can read the documentation online.

  • 03-31-2008 9:50 In reply to

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 1,889

    Re: How to use GPIO on a PXA270

    Be aware that the PhysicalAddressPointer is *only* for CE 5.0 and earlier.  If you are using, or will be migrating to CE 6.0, it will not work. 

  • 04-10-2008 3:37 In reply to

    • srue
    • Top 150 Contributor
    • Joined on 03-30-2008
    • Posts 3

    Re: How to use GPIO on a PXA270

    Hi Neil

     Thanks a lot. Now I know how read the state of the input pins.

    How do I create an interrupt driven event in C#, when a input pin change its state (raising or falling edge). I found an example here in C that works on my board, but how does it work in C# ?

     Any help is much appreciated.

    Filed under: ,
  • 04-10-2008 10:25 In reply to

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 1,889

    Re: How to use GPIO on a PXA270

    Simple - P/Invoke InterruptInitialize, InterruptConnect and InterruptDone.  P/Invoke CreateEvent to get a handle to pass into the initialize function and P/Invoke WaitForSingleObject to wait on the event (both are encapsulated in the OpenNETCF.Threading.EventWaitHandle) .  Do that in a worker thread (essentially an IST) and have it raise a managed event when the Wait unblocks.

    Again, none of this will likely work under 6.0.

    A more portable alternative is to create a GPIO driver in native code and P/Invoke into it. The OpenNETCF.IO.StreamInterfaceDriver base class would be the place to start there.
     

  • 04-18-2008 3:37 In reply to

    • srue
    • Top 150 Contributor
    • Joined on 03-30-2008
    • Posts 3

    Re: How to use GPIO on a PXA270

    Hello

    This is how I set it up. It works without problems when I debug it with breakpoints, otherwise it crashes usually. Do you have an idea why?

     thanks for your help.

    //Private Methods

    private uint CTL_CODE( uint DeviceType, uint Function, uint Method, uint Access )

    {

    return (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method));

    }

    private uint IOCTL_HAL_GPIO2IRQ()

    {

    return CTL_CODE(FILE_DEVICE_HAL, 2048, METHOD_BUFFERED, FILE_ANY_ACCESS);

    }

    private uint IOCTL_HAL_IRQ2GPIO()

    {

    return CTL_CODE(FILE_DEVICE_HAL, 2049, METHOD_BUFFERED, FILE_ANY_ACCESS);

    }

    private uint IOCTL_HAL_IRQEDGE()

    {

    return CTL_CODE(FILE_DEVICE_HAL, 2050, METHOD_BUFFERED, FILE_ANY_ACCESS);

    }

    private uint IOCTL_HAL_REQUEST_SYSINTR()

    {

    return CTL_CODE(FILE_DEVICE_HAL, 38, METHOD_BUFFERED, FILE_ANY_ACCESS);

    }

    private uint IOCTL_HAL_RELEASE_SYSINTR()

    {

    return CTL_CODE(FILE_DEVICE_HAL, 54, METHOD_BUFFERED, FILE_ANY_ACCESS);

    }

    private bool SetupInterrupt()

    {

    bool ret = false ;

     

    hEvent =
    new EventWaitHandle(false, EventResetMode.ManualReset );

    // Get IRQ frm dwGpio

    dwGpio = 19;

    ret = KernelIoControl(IOCTL_HAL_GPIO2IRQ(),
    ref dwGpio, 1, ref dwIrq, 1, IntPtr.Zero);

    // Set Edge to trigger (Rising, Falling or both)

    dwEdge = GPIO_EDGE_RISING | GPIO_EDGE_FALLING; // (rising & falling edge)

    ret = KernelIoControl(IOCTL_HAL_IRQEDGE(), ref dwIrq, 1, ref dwEdge, 1, IntPtr.Zero);

    hEvent.Handle = CreateEvent(IntPtr.Zero, false, false, IntPtr.Zero);

    // Get the SYSINTR that corresponds to dwIrq (non GPIO Irqs corresond to the bit numbers of the PXA27x Interrupt resisters)

    ret = KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR(), ref dwIrq, sizeof(uint), ref dwSysIntr, sizeof(uint), IntPtr.Zero);

    // Link our Event with the SYSINTR

    ret = InterruptInitialize(dwSysIntr, hEvent.Handle, IntPtr.Zero, 0);

    return ret;

    }

Page 1 of 1 (6 items)