Access PIO on AT91SAM9260 under WinCE 6.0

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

Moderator: nferre

T.Schaefer
Posts: 1
Joined: Fri May 11, 2007 11:49 am

Access PIO on AT91SAM9260 under WinCE 6.0

Fri May 11, 2007 12:10 pm

Hello,
i have just started with the AT91SAM9260-EK & WinCE 6.0 and I wont to access PB3, PB4 & LED on the dev kit.
How can I access the driver "gpio.dll" from the BSP in a user space application ?

Many thanks
Thomas Schäfer
Adeneo
Contact:
Location: France - USA
Posts: 183
Joined: Fri May 14, 2004 9:58 am

Tue May 15, 2007 2:15 pm

You can't make access to "gpio.dll" functions in a user space application. It's possible to load the "gpio.dll" by the LoadKernelLibrary function but it's impossible to export functions.
If you want to access PB3, PB4 and LED you must make a driver.

You can see the post at the URL :
http://groups.google.fr/group/microsoft ... 9cd0bfbcd7
Mezon
Posts: 3
Joined: Thu Mar 27, 2008 10:28 am

Re: Access PIO on AT91SAM9260 under WinCE 6.0

Thu Jan 29, 2009 5:20 pm

Hello,
i have an evaluation board AT91SAM9263-EK.
Whether I can use a driver at91sam9263ek_gpio.dll to set value or to get value of a pin?
If yes that as?

Many thanks
Adeneo
Contact:
Location: France - USA
Posts: 183
Joined: Fri May 14, 2004 9:58 am

Re: Access PIO on AT91SAM9260 under WinCE 6.0

Fri Jan 30, 2009 12:07 pm

Hi,

Yes you can use the PIO driver to get or set the value of a pin. Here is an example that shown how to use it:
//-----------------------------------------------------------------------------
//! MAIN
//-----------------------------------------------------------------------------
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;
}
Mezon
Posts: 3
Joined: Thu Mar 27, 2008 10:28 am

Re: Access PIO on AT91SAM9260 under WinCE 6.0

Wed Feb 04, 2009 11:53 pm

Many thanks for the help.
I could set value and get value of pins PB15,PB16,PB19,PB21,PB23 etc,
but I couldn't set value of pins PB20,PB22,PB24,PB26,PB28,PB30.
These pins are not used on evaluation board for peripheral devices.
In what there can be a problem?
johnbeckster@gmail.com
Posts: 1
Joined: Thu Mar 12, 2009 11:33 pm

Re: Access PIO on AT91SAM9260 under WinCE 6.0

Thu Mar 26, 2009 10:44 pm

I have the AT91SAM9261-EK board, and I downloaded the WinCE 6 BSP, compiled it, and downloaded it onto the EK. I see a gpio.dll in a few WINCE600 directories, but I don't see any PIO or GIO prefixes under \Drivers in the Registry. Does the 9261 BSP have a GPIO driver? Can I use the 9263 example code (in prior post) with it?

Thanks for any help

John
FmcBm
Posts: 4
Joined: Thu Aug 05, 2010 2:21 pm

Re: Access PIO on AT91SAM9260 under WinCE 6.0

Mon Oct 18, 2010 12:12 pm

I also use the AT91SAM9261-EK BSP and don't find something like at91sam9261ek_gpio.dll.
I only have a gpio.dll but can't call it in user mode. It's too difficult for me to write an own driver to access it in kernel mode, so may the at91sam9263ek_gpio.dll work for a at91sam921 controller too?

Thanks for help
GDV
Posts: 12
Joined: Wed Jul 21, 2010 5:09 pm

Re: Access PIO on AT91SAM9260 under WinCE 6.0

Mon Feb 07, 2011 10:52 am

Hi,

I'm trying to get the GPIO example provided by Adeneo to run on my 9260ek board without success. It seems that there is a problem when tyring to configure the PIO ports, by calling DeviceIoControl, which causes WinCE to hangup, requiring a board reset to recover.

I never see printf("3"); being called (see code below)!

I've provided the headers and a snippet from the code I'm trying to run. I'm using VS2005, the GPIO driver is selected in my OS catalogue.

Any assistance appreciated.

#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include "stdio.h"

#include <ceddk.h>
#include "C:\WINCE600\PUBLIC\COMMON\OAK\INC\windev.h"
#include "C:\WINCE600\PLATFORM\COMMON\SRC\SOC\ATMEL\COMMON\DRIVERS\GPIO\GPIO.h"
#include "C:\WINCE600\PLATFORM\COMMON\SRC\SOC\ATMEL\AT91SAM9260\INC\AT91SAM9260.h"

/* these pin numbers double as IRQ numbers, like AT91C_ID_* values */
#define PIO_NB_IO 32 /* Number of IO handled by one PIO controller */
#define AT91C_PIN_PA(io) (0 * PIO_NB_IO + io)
#define AT91C_PIN_PB(io) (1 * PIO_NB_IO + io)
#define AT91C_PIN_PC(io) (2 * PIO_NB_IO + io)

/* I/O attributes */
#define PIO_DEFAULT (0 << 0)
#define PIO_PULLUP (1 << 0)
#define PIO_DEGLITCH (1 << 1)
#define PIO_OPENDRAIN (1 << 2)

#define GPIO_CONFIGURE_CMD (2048 + 1)
#define GPIO_SETSTATE_CMD (2048 + 2)
#define GPIO_GETSTATE_CMD (2048 + 3)

#define IOCTL_GPIO_CONFIGURE CTL_CODE(FILE_DEVICE_UNKNOWN, GPIO_CONFIGURE_CMD, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define IOCTL_GPIO_SETSTATE CTL_CODE(FILE_DEVICE_UNKNOWN, GPIO_SETSTATE_CMD, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define IOCTL_GPIO_GETSTATE CTL_CODE(FILE_DEVICE_UNKNOWN, GPIO_GETSTATE_CMD, METHOD_BUFFERED, FILE_READ_ACCESS)

// Struct
typedef struct
{
DWORD PinNo; // Pin number
DWORD PinState; // Pin value (0 or 1)
} T_GPIOIOCTL_STATE;

struct pio_desc
{
const char *pin_name; /* Pin Name */
unsigned int pin_num; /* Pin number */
unsigned int dft_value; /* Default value for outputs */
unsigned char attribute;
enum pio_type type;
};

/* I/O type */
enum pio_type
{
PIO_PERIPH_A,
PIO_PERIPH_B,
PIO_INPUT,
PIO_OUTPUT,
PIO_UNDEFINED
};

int _tmain(int argc, _TCHAR* argv[])
{
printf("Hello World!");

// Variables
HANDLE hGPIO = NULL;
HANDLE hDev = NULL;
BOOL bSuccessDevIOC = FALSE;
TCHAR strFileName[10] = TEXT("PIO1:");

printf("1\n\r");

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

printf("2\n\r");

// 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")));
printf("DeviceIoControl : IOCTL_GPIO_CONFIGURE failed");
}

printf("3\n\r");

CloseHandle(hGPIO);

etc...

Return to “WinCE”

Who is online

Users browsing this forum: No registered users and 1 guest