CM-X300: WinCE: GPIOs Programming

From Compulab Mediawiki
Revision as of 11:46, 15 March 2010 by Shai (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

GPIO Sample Application

Overview

This GPIOSample application demonstrates basic functionality of CM-X300 GPIOs under Windows CE:

  • How to configure a GPIO pin as output and manipulate it.
  • How to configure a GPIO pin as input and respond to changes in signal level.
  • How to setup an edge triggered event.

Application Behavior

The GPIOSample manipulates the following GPIOs:

  • GPIO 122 (pin 12 of connector P13 on the SB-X300) - Set as output
  • GPIO 124 (pin 14 of connector P13 on the SB-X300) - Set as input
  • GPIO 128 (Pin 24 of connector P11 on the SB-X300) - Set as input. (pin 0 on GPIO extender 0)

GPIO122 voltage level may be monitored with a DVM or an oscilloscope. GPIO124 and GPIO128 may be controlled by an external switch or button.

The GPIOSample performs the following actions:

  • Edge detection on GPIO124 (cpu GPIO). Event handler is registered with GPIORegisterInterrupt. The handler calls GPIOInterruptDone to indicate interrupt completion.
  • Edge detection on GPIO128 (GPIO extender). Event handler is registered with GPIORegisterInterrupt. The handler calls GPIOInterruptDone to indicate interrupt completion.
  • Clock simulation on GPIO122 with a period of 3 seconds.
  • Input voltage level monitoring on GPIO122.

GPIO Driver API

Data Types

GPIO_VALUE

GPIO state enumeration

Values
GPIO_LOW
GPIO_HIGH


GPIO_EDGE_SETTINGS

Values
GPIO_REACT_ON_FALLING
GPIO_REACT_ON_RISING
GPIO_REACT_ON_BOTH
GPIO_DONT_REACT


GPIO_INTERRUPT

Fields
Name
Description
DWORD dwGpioNum
GPIO_EDGE_SETTINGS Edge
HANDLE Event




Functions

HANDLE GPIOOpen()

Opens an instance of the GPIO Driver.

Return Values
Returns a handle that should be used to access the driver. Nonzero indicates success.


void GPIOClose(HANDLE hDevice)

Closes the driver handle

Parameters
  • hDevice - Handle to an open driver instance



BOOL GPIOSetValue(HANDLE hDevice,DWORD num, GPIO_VALUE val)

Sets the state of a GPIO.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
  • val - The desired logical state.
Return Values
TRUE - indicates success
FALSE - indicates failure
Remarks
Make sure the GPIO direction is setup as output.


BOOL GPIOGetValue(HANDLE hDevice,DWORD num,GPIO_VALUE *gpioVal)

Return the logical state of a GPIO.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
  • gpioVal - pointer to the GPIO state variable
Return Values
TRUE - indicates success
FALSE - indicates failure
Remarks
Make sure the GPIO direction is setup as input. Returned value for an output GPIO is undefined


BOOL GPIOSetAsInput(HANDLE hDevice, DWORD num)

Configures a GPIO as an input.

Parameters
  • hDevice - Handle to an open driver instance.
  • num - GPIO number.
Return Values
TRUE - indicates success
FALSE - indicates failure


BOOL GPIOSetAsOutput(HANDLE hDevice,DWORD num, GPIO_VALUE val)

Configures a GPIO as an output and sets its logical state.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
  • val - The initial GPIO value
Return Values
TRUE - indicates success
FALSE - indicates failure


BOOL GPIORegisterInterrupt(HANDLE hDevice,GPIO_INTERRUPT interrupt)

Registers a GPIO as an interrupt source. The interrupt is triggered according to the configuration in GPIO_INTERRUPT.Edge member settings.

Parameters
  • hDevice - Handle to an open driver instance
  • interrupt- data structure that defines parameters for the interrupt registration
Return Values
TRUE - indicates success.
FALSE - indicates failure
Remarks


VOID GPIOInterruptDone(HANDLE hDevice, DWORD num)

Signals to the kernel that GPIO interrupt processing is complete.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
Remarks
A program calls GPIOInterruptDone when it has completed the interrupt processing and is ready for another interrupt.


BOOL GPIOUnRegisterInterrupt(HANDLE hDevice, DWORD num)

Disables the GPIO hardware interrupt.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
Return Values
TRUE - indicates success.
FALSE - indicates failure
Remarks
A program calls GPIOUnRegisterInterrupt to disable the hardware interrupt and to unregister the event that was registered by GPIOInterruptInitialize.