Re: GPIO driver for pxa270
- From: "bluesphere" <ads_bx@xxxxxxxxxxx>
- Date: Tue, 2 Jan 2007 23:30:17 +0100
can i directly use the below code.
Only if you're working with Colibri'. The three IOCTLs
you see, are implemented in the OAL by Toradex.
<princyfrancis@xxxxxxxxx> wrote in message
news:1167716272.482603.310920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hi bluesphere ;
thank u very much..
while searching i got a wince gpio sample code from colibri toradex.
can i directly use the below code.
#include <windows.h>
// To test this sample code you'll have to connect GPIO37 to a Switch.
// GPIO37 can be found on X15, Pin47
#define GPIO_EDGE_RISING 1
#define GPIO_EDGE_FALLING 2
BOOL KernelIoControl(DWORD dwIoControlCode, LPVOID lpInBuf, DWORD
nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD
lpBytesReturned);
#define CTL_CODE( DeviceType, Function, Method, Access ) (((DeviceType)
<< 16) | ((Access) << 14) | ((Function) << 2) | (Method))
#define FILE_DEVICE_HAL 0x00000101
#define METHOD_BUFFERED 0
#define FILE_ANY_ACCESS 0
#define IOCTL_HAL_GPIO2IRQ CTL_CODE(FILE_DEVICE_HAL, 2048,
METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_HAL_IRQ2GPIO CTL_CODE(FILE_DEVICE_HAL, 2049,
METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_HAL_IRQEDGE CTL_CODE(FILE_DEVICE_HAL, 2050,
METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_HAL_REQUEST_SYSINTR CTL_CODE(FILE_DEVICE_HAL, 38,
METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_HAL_RELEASE_SYSINTR CTL_CODE(FILE_DEVICE_HAL, 54,
METHOD_BUFFERED, FILE_ANY_ACCESS)
BOOL InterruptInitialize(DWORD idInt, HANDLE hEvent, LPVOID pvData,
DWORD cbData);
void InterruptDone(DWORD idInt);
void InterruptDisable(DWORD idInt);
/*----------------------------------------------------------------------
| main
+---------------------------------------------------------------------*/
int WINAPI WinMain(HINSTANCE hInstance, // handle to current
instance
HINSTANCE hPrevInstance, // handle to previous
instance
LPWSTR lpCmdLine, // pointer to command
line
int nCmdShow) // show state of window
{
HANDLE hEvent;
DWORD dwEdge, dwGpio;
DWORD dwIrq, dwSysIntr;
//************************************
// GPIO Specific Section
// Get IRQ frm dwGpio
dwGpio=37;
if(!KernelIoControl(IOCTL_HAL_GPIO2IRQ, &dwGpio, 1, &dwIrq, 1, NULL))
goto leave_error;
// Set Edge to trigger (Rising, Falling or both)
//dwEdge=GPIO_EDGE_RISING | GPIO_EDGE_FALLING; // (rising & falling
edge)
dwEdge=GPIO_EDGE_RISING; // (rising)
if(!KernelIoControl(IOCTL_HAL_IRQEDGE, &dwIrq, 1, &dwEdge, 1, NULL))
goto leave_error;
//************************************
// General Interrupt Handling Section
// Create an Event to wait on
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if ( hEvent == NULL) goto leave_error;
// Get the SYSINTR that corresponds to dwIrq (non GPIO Irqs corresond
to the bit numbers of the PXA27x Interrupt resisters)
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwIrq, sizeof(DWORD),
&dwSysIntr, sizeof(DWORD), NULL)) goto leave_error;
// Link our Event with the SYSINTR
if ( !InterruptInitialize(dwSysIntr, hEvent, NULL, 0) ) goto
leave_error;
while(1)
{
// Wait for Event (Interrupt)
if (WaitForSingleObject(hEvent, INFINITE) == WAIT_OBJECT_0)
{
if(MessageBox(NULL, L"Interrupt Event Detected, continue Waiting?",
L"Interrupt", MB_YESNO) == IDNO) break;
InterruptDone(dwSysIntr);
}
}
InterruptDisable(dwSysIntr);
if (!KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &dwSysIntr,
sizeof(DWORD), NULL, 0, NULL)) goto leave_error;
leave_error:
return(TRUE);
}
bluesphere wrote:
Programming the controller is not the only issue.
Since the GPIO IRQ is shared by all the GPIOs
you never know what happens behind the scenes
unless you're the OEM. Also, race conditions might
arise in any case as the GPIO controller is one
and the drivers are many.
If you can put your hands into the OAL, you
have a chance handle the translation of the
IRQ in the OEMInterruptHandler:
if (IRQ_GPIOXX_2 == irq)
irq = DecodeAndTranslateTheIRQ(irq);
If you cannot put your hands into the OAL, you
still have a chance to do something thanks
to the fact that OEMInterruptHandler (for PXA)
should call "NKCallIntChain" and that you
can install an IISR.
For more information see
"Cats, Toast, and Interrupts on Windows CE .NET"
and look for "Shared Interrupts".
or
http://msdn2.microsoft.com/en-us/library/ms894020.aspx
Programming the controller is covered in "PXA27x processor
family - developer's manual - chapter 24"
hi bluesphere ,
how can i get the irq is it ipr (interrupt priority for gpio(gpio0->
8,gpio1->9,gpio_xx2->10.
bluesphere wrote:
There's a single IRQ for all the GPIOs (more or less)
and that's where the matter may get complex.
.
- Follow-Ups:
- Re: GPIO driver for pxa270
- From: princyfrancis
- Re: GPIO driver for pxa270
- References:
- Re: GPIO driver for pxa270
- From: princyfrancis
- Re: GPIO driver for pxa270
- From: bluesphere
- Re: GPIO driver for pxa270
- From: princyfrancis
- Re: GPIO driver for pxa270
- Prev by Date: Re: Windows CE 6.0 KITLOutputDebugString
- Next by Date: Re: How to passed arguments to CeCallUserProcUse when call MessageBox function of coredll.dll?
- Previous by thread: Re: GPIO driver for pxa270
- Next by thread: Re: GPIO driver for pxa270
- Index(es):
Relevant Pages
|