Switch on/off LED on AT91SAM9260

This forum is for users of Atmel's SAM Series and who are interested in using WinCE OS.

Moderator: nferre

Noufele
Posts: 4
Joined: Tue Oct 27, 2009 6:10 am

Switch on/off LED on AT91SAM9260

Mon Nov 09, 2009 4:58 pm

Hello,
I am trying to run the folloeing code. CreateFile returns INVALID_HANDLE_VALUE. How can I fix that?

Thanks

Regards


int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
// Variables
HANDLE hGPIO = NULL;
HANDLE hDev = NULL;
BOOL bSuccessDevIOC = FALSE;
TCHAR strFileName[10] = TEXT("PIO1:");


// Open GPIO driver
hGPIO = CreateFile(strFileName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

if (hGPIO != INVALID_HANDLE_VALUE)
{
const struct pio_desc hw_pio[] =
{
{"LED1", AT91C_PIN_PA(13), 0, PIO_DEFAULT, PIO_OUTPUT},
{"LED2", AT91C_PIN_PA(14), 0, PIO_DEFAULT, PIO_OUTPUT},
};
T_GPIOIOCTL_STATE * pSetState;
T_GPIOIOCTL_STATE * pGetState;

// Configure PIOs
bSuccessDevIOC = DeviceIoControl(hGPIO, IOCTL_GPIO_CONFIGURE, (LPBYTE*)hw_pio,
sizeof(hw_pio), NULL, 0, NULL, NULL);
if (!bSuccessDevIOC)
{
RETAILMSG(1, (TEXT("DeviceIoControl : IOCTL_GPIO_CONFIGURE failed")));
}

// Set PIO state
pSetState = (T_GPIOIOCTL_STATE*)LocalAlloc(LMEM_ZEROINIT|LMEM_FIXED,
sizeof(T_GPIOIOCTL_STATE));
pSetState->PinNo = AT91C_PIN_PA(14);
pSetState->PinState = 1;
bSuccessDevIOC = DeviceIoControl(hGPIO, IOCTL_GPIO_SETSTATE, pSetState,
sizeof(*pSetState), NULL, 0, NULL, NULL);
LocalFree(pSetState);
if (!bSuccessDevIOC)
{
RETAILMSG(1, (TEXT("DeviceIoControl : IOCTL_GPIO_SETSTATE failed")));
}

// Get PIO state
pGetState = (T_GPIOIOCTL_STATE*)LocalAlloc(LMEM_ZEROINIT|LMEM_FIXED,
sizeof(T_GPIOIOCTL_STATE));
pGetState->PinNo = AT91C_PIN_PA(13);
bSuccessDevIOC = DeviceIoControl(hGPIO, IOCTL_GPIO_GETSTATE, pGetState,
sizeof(*pGetState), pGetState, sizeof(*pGetState), NULL, NULL);
if (!bSuccessDevIOC)
{
RETAILMSG(1, (TEXT("DeviceIoControl : IOCTL_GPIO_GETSTATE failed")));
}
else
{
RETAILMSG(1,(TEXT("DeviceIoControl : IOCTL_GPIO_GETSTATE returned PinNo=%d,
PinState=%d"),pGetState->PinNo,pGetState->PinState));
}
LocalFree(pGetState);

// Close GPIO driver
if (!CloseHandle(hGPIO))
{
RETAILMSG(1, (TEXT("CloseHandle failed")));
}
}
else
{
RETAILMSG(1, (TEXT("hGPIO == INVALID_HANDLE_VALUE")));
}

return 0;
}
guangyu.ren
Posts: 23
Joined: Tue Mar 31, 2009 7:22 am

Re: Switch on/off LED on AT91SAM9260

Mon Jan 18, 2010 5:30 am

Please make sure that you have included item "GPIO driver" in the catalog setting

Return to “WinCE”

Who is online

Users browsing this forum: No registered users and 1 guest