Tux
Communication
Mailing lists
Documentation
User Manual
Target board info.
Target chip info.
Support
Linux support
Bugzilla
Downloads
STLinux
Updates
Search
Google


The web
stlinux.com
Distribution Guide
Device drivers
PIO drivers
ST Logo
Previous   Contents   Next

Introduction

Since PIO pins are so widely used for various functions, there is an API available within the kernel to control their function. PIO pins can be used in two modes:

  1. as an IO pin - the pin can be driven as an output, or read as an input under software control.
  2. connected to internal hardware - functions of the chip are brought out on the PIO pins. This is referred to as the alternative function mode of the PIO pin. There may actually be several mutually exclusive alternative functions selectable on the PIO pins.
The reason this is done is to allow maximum flexibility on the chip without vastly increasing the pin count of the chip. For example, as one external interrupt line.

API functions

struct stpio_pin* stpio_request_pin(unsigned portno, unsigned pinno,
                                    const char* name, int direction);

Allocates a specific pinno on a PIO portno. Returns a pointer to a struct stpio_pin which is used as a handle for other functions. Returns NULL on failure.

The name field associates a string with the pin, and the direction flag controls how the pin is configured,possible values are shown below.

  • STPIO_NONPIO - Non PIO function
  • STPIO_BIDIR_Z1 - Input weak pull-up
  • STPIO_OUT - Output push-pull
  • STPIO_IN - Input Hi-Z
  • STPIO_ALT_OUT - Alt output push-pull
  • STPIO_ALT_BIDIR - Alt bidir open drain

Refer to the datasheet for the board for details of what the alternate functions are for a particular chip.

void stpio_free_pin(struct stpio_pin* pin);

Releases a specfied PIO pin. Changes the pin to the STPIO_IN state.

void stpio_set_pin(struct stpio_pin* pin, unsigned int value)

Sets a specified pio pin to logic value

unsigned int stpio_get_pin(struct stpio_pin* pin)

Returns the logic value present on the specified PIO pin

void stpio_request_irq(struct stpio_pin* pin, int comp,
		       void (*handler)(struct stpio_pin *pin, void *dev),
		       void *dev)

Submits the callback function handler on the specified pin which must already have been allocated by means of stpio_request_pin. Every time the input value logic level on the pin differs from the comp value the callback function will be called.

void stpio_free_irq(struct stpio_pin* pin)

Unsubmits and disables the callback function on the specified pin.

void stpio_enable_irq(struct stpio_pin* pin, int comp)

Enables the callback notification on the logic compare input value comp. This is useful for implementing a pseudo edge-triggered response. If comp is zero the IRQ callback will be done on rising edge. The IRQ callback function can then use this function to set comp to zero so that it will next be called on the falling edge.

void stpio_disable_irq(struct stpio_pin* pin)

Disables the IRQ callback function for pin.

Example usage

struct stpio_pin * led;

/* PIO port 3 pin 5 connected to LED */
led=stpio_request_pin(3,5,"LED",STPIO_OUT);

/* Switch LED on */
stpio_set_pin(led,0);
....... Do something 
/* Switch LED off */
stpio_set_pin(led,1);
Previous   Contents   Next
Valid HTML 4.01! Last updated: 2006/03/10 12:55:38
© Copyright STMicroelectronics Limited, 2005
Printer