RTEMS  5.1
Data Structures | Macros | Typedefs | Functions
pio.h File Reference
#include "chip.h"
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  _Pin
 

Macros

#define PIO_PERIPH_A   0
 
#define PIO_PERIPH_B   1
 
#define PIO_PERIPH_C   2
 
#define PIO_PERIPH_D   3
 
#define PIO_INPUT   4
 
#define PIO_OUTPUT_0   5
 
#define PIO_OUTPUT_1   6
 
#define PIO_DEFAULT   (0 << 0)
 
#define PIO_PULLUP   (1 << 0)
 
#define PIO_DEGLITCH   (1 << 1)
 
#define PIO_OPENDRAIN   (1 << 2)
 
#define PIO_DEBOUNCE   (1 << 3)
 
#define PIO_IT_AIME   (1 << 4)
 
#define PIO_IT_RE_OR_HL   (1 << 5)
 
#define PIO_IT_EDGE   (1 << 6)
 
#define PIO_IT_LOW_LEVEL   (0 | 0 | PIO_IT_AIME)
 
#define PIO_IT_HIGH_LEVEL   (PIO_IT_RE_OR_HL | 0 | PIO_IT_AIME)
 
#define PIO_IT_FALL_EDGE   (0 | PIO_IT_EDGE | PIO_IT_AIME)
 
#define PIO_IT_RISE_EDGE   (PIO_IT_RE_OR_HL | PIO_IT_EDGE | PIO_IT_AIME)
 
#define PIO_WPMR_WPEN_EN   (0x01 << 0)
 
#define PIO_WPMR_WPEN_DIS   (0x00 << 0)
 
#define PIO_WPMR_WPKEY_VALID   (0x50494F << 8)
 
#define PIO_LISTSIZE(pPins)   (sizeof(pPins) / sizeof(Pin))
 

Typedefs

typedef struct _Pin Pin
 

Functions

uint8_t PIO_Configure (const Pin *list, uint32_t size)
 Configures a list of Pin instances, each of which can either hold a single pin or a group of pins, depending on the mask value; all pins are configured by this function. The size of the array must also be provided and is easily computed using PIO_LISTSIZE whenever its length is not known in advance. More...
 
void PIO_Set (const Pin *pin)
 Sets a high output level on all the PIOs defined in the given Pin instance. This has no immediate effects on PIOs that are not output, but the PIO controller will memorize the value they are changed to outputs. More...
 
void PIO_Clear (const Pin *pin)
 Sets a low output level on all the PIOs defined in the given Pin instance. This has no immediate effects on PIOs that are not output, but the PIO controller will memorize the value they are changed to outputs. More...
 
uint8_t PIO_Get (const Pin *pin)
 Returns 1 if one or more PIO of the given Pin instance currently have a high level; otherwise returns 0. This method returns the actual value that is being read on the pin. To return the supposed output value of a pin, use PIO_GetOutputDataStatus() instead. More...
 
uint8_t PIO_GetOutputDataStatus (const Pin *pin)
 Returns 1 if one or more PIO of the given Pin are configured to output a high level (even if they are not output). To get the actual value of the pin, use PIO_Get() instead. More...
 
void PIO_SetDebounceFilter (const Pin *pin, uint32_t cuttoff)
 Configures Glitch or Denouncing filter for input. More...
 
void PIO_EnableWriteProtect (const Pin *pin)
 Enable write protect. More...
 
void PIO_DisableWriteProtect (const Pin *pin)
 Disable write protect. More...
 
void PIO_SetPinType (Pin *pin, uint8_t pinType)
 Set pin type the pin is controlled by the corresponding peripheral (A, B, C, D,E) More...
 
uint32_t PIO_GetWriteProtectViolationInfo (const Pin *pin)
 Get write protect violation information. More...
 
void PIO_SetDriveStrength (const Pin *pin, uint8_t strength)
 Set the drive strength of the pin. More...
 

Detailed Description

Purpose

This file provides a basic API for PIO configuration and usage of user-controlled pins. Please refer to the board.h file for a list of available pin definitions.

Usage

  1. Define a constant pin description array such as the following one, using the existing definitions provided by the board.h file if possible:
    const Pin pPins[] = {PIN_USART0_TXD, PIN_USART0_RXD};
    Alternatively, it is possible to add new pins by provided the full Pin structure:
    // Pin instance to configure PA10 & PA11 as inputs with the internal
    // pull-up enabled.
    const Pin pPins = {
    (1 << 10) | (1 << 11),
    REG_PIOA,
    };
  2. Configure a pin array by calling PIO_Configure() with a pointer to the array and its size (which is computed using the PIO_LISTSIZE macro).
  3. Change and get the value of a user-controlled pin using the PIO_Set, PIO_Clear and PIO_Get methods.
  4. Get the level being currently output by a user-controlled pin configured as an output using PIO_GetOutputDataStatus().

Macro Definition Documentation

◆ PIO_DEBOUNCE

#define PIO_DEBOUNCE   (1 << 3)

The internal debouncing filter is active.

◆ PIO_DEFAULT

#define PIO_DEFAULT   (0 << 0)

Default pin configuration (no attribute).

◆ PIO_DEGLITCH

#define PIO_DEGLITCH   (1 << 1)

The internal glitch filter is active.

◆ PIO_INPUT

#define PIO_INPUT   4

The pin is an input.

◆ PIO_IT_AIME

#define PIO_IT_AIME   (1 << 4)

Enable additional interrupt modes.

◆ PIO_IT_EDGE

#define PIO_IT_EDGE   (1 << 6)

Interrupt Edge detection is active.

◆ PIO_IT_FALL_EDGE

#define PIO_IT_FALL_EDGE   (0 | PIO_IT_EDGE | PIO_IT_AIME)

Falling edge interrupt is active

◆ PIO_IT_HIGH_LEVEL

#define PIO_IT_HIGH_LEVEL   (PIO_IT_RE_OR_HL | 0 | PIO_IT_AIME)

High level interrupt is active

◆ PIO_IT_LOW_LEVEL

#define PIO_IT_LOW_LEVEL   (0 | 0 | PIO_IT_AIME)

Low level interrupt is active

◆ PIO_IT_RE_OR_HL

#define PIO_IT_RE_OR_HL   (1 << 5)

Interrupt High Level/Rising Edge detection is active.

◆ PIO_IT_RISE_EDGE

#define PIO_IT_RISE_EDGE   (PIO_IT_RE_OR_HL | PIO_IT_EDGE | PIO_IT_AIME)

Rising edge interrupt is active

◆ PIO_LISTSIZE

#define PIO_LISTSIZE (   pPins)    (sizeof(pPins) / sizeof(Pin))

Calculates the size of an array of Pin instances. The array must be defined locally (i.e. not a pointer), otherwise the computation will not be correct.

Parameters
pPinsLocal array of Pin instances.
Returns
Number of elements in array.

◆ PIO_OPENDRAIN

#define PIO_OPENDRAIN   (1 << 2)

The pin is open-drain.

◆ PIO_OUTPUT_0

#define PIO_OUTPUT_0   5

The pin is an output and has a default level of 0.

◆ PIO_OUTPUT_1

#define PIO_OUTPUT_1   6

The pin is an output and has a default level of 1.

◆ PIO_PERIPH_A

#define PIO_PERIPH_A   0

The pin is controlled by the associated signal of peripheral A.

◆ PIO_PERIPH_B

#define PIO_PERIPH_B   1

The pin is controlled by the associated signal of peripheral B.

◆ PIO_PERIPH_C

#define PIO_PERIPH_C   2

The pin is controlled by the associated signal of peripheral C.

◆ PIO_PERIPH_D

#define PIO_PERIPH_D   3

The pin is controlled by the associated signal of peripheral D.

◆ PIO_PULLUP

#define PIO_PULLUP   (1 << 0)

The internal pin pull-up is active.

◆ PIO_WPMR_WPEN_DIS

#define PIO_WPMR_WPEN_DIS   (0x00 << 0)

The WP is disable

◆ PIO_WPMR_WPEN_EN

#define PIO_WPMR_WPEN_EN   (0x01 << 0)

The WP is enable

◆ PIO_WPMR_WPKEY_VALID

#define PIO_WPMR_WPKEY_VALID   (0x50494F << 8)

Valid WP key

Function Documentation

◆ PIO_Clear()

void PIO_Clear ( const Pin pin)

Sets a low output level on all the PIOs defined in the given Pin instance. This has no immediate effects on PIOs that are not output, but the PIO controller will memorize the value they are changed to outputs.

Parameters
pinPointer to a Pin instance describing one or more pins.

◆ PIO_Configure()

uint8_t PIO_Configure ( const Pin list,
uint32_t  size 
)

Configures a list of Pin instances, each of which can either hold a single pin or a group of pins, depending on the mask value; all pins are configured by this function. The size of the array must also be provided and is easily computed using PIO_LISTSIZE whenever its length is not known in advance.

Parameters
listPointer to a list of Pin instances.
sizeSize of the Pin list (calculated using PIO_LISTSIZE).
Returns
1 if the pins have been configured properly; otherwise 0.

◆ PIO_DisableWriteProtect()

void PIO_DisableWriteProtect ( const Pin pin)

Disable write protect.

Parameters
pinPointer to a Pin instance describing one or more pins.

◆ PIO_EnableWriteProtect()

void PIO_EnableWriteProtect ( const Pin pin)

Enable write protect.

Parameters
pinPointer to a Pin instance describing one or more pins.

◆ PIO_Get()

uint8_t PIO_Get ( const Pin pin)

Returns 1 if one or more PIO of the given Pin instance currently have a high level; otherwise returns 0. This method returns the actual value that is being read on the pin. To return the supposed output value of a pin, use PIO_GetOutputDataStatus() instead.

Parameters
pinPointer to a Pin instance describing one or more pins.
Returns
1 if the Pin instance contains at least one PIO that currently has a high level; otherwise 0.

◆ PIO_GetOutputDataStatus()

uint8_t PIO_GetOutputDataStatus ( const Pin pin)

Returns 1 if one or more PIO of the given Pin are configured to output a high level (even if they are not output). To get the actual value of the pin, use PIO_Get() instead.

Parameters
pinPointer to a Pin instance describing one or more pins.
Returns
1 if the Pin instance contains at least one PIO that is configured to output a high level; otherwise 0.

◆ PIO_GetWriteProtectViolationInfo()

uint32_t PIO_GetWriteProtectViolationInfo ( const Pin pin)

Get write protect violation information.

Parameters
pinPointer to a Pin instance describing one or more pins.

◆ PIO_Set()

void PIO_Set ( const Pin pin)

Sets a high output level on all the PIOs defined in the given Pin instance. This has no immediate effects on PIOs that are not output, but the PIO controller will memorize the value they are changed to outputs.

Parameters
pinPointer to a Pin instance describing one or more pins.

◆ PIO_SetDebounceFilter()

void PIO_SetDebounceFilter ( const Pin pin,
uint32_t  cuttoff 
)

Configures Glitch or Denouncing filter for input.

Parameters
pinPointer to a Pin instance describing one or more pins.
cuttoffCut off frequency for denounce filter.

◆ PIO_SetDriveStrength()

void PIO_SetDriveStrength ( const Pin pin,
uint8_t  strength 
)

Set the drive strength of the pin.

Parameters
pinPointer to a Pin instance describing one or more pins.
strength0 for low drive strength or 1 for high drive strength.

◆ PIO_SetPinType()

void PIO_SetPinType ( Pin pin,
uint8_t  pinType 
)

Set pin type the pin is controlled by the corresponding peripheral (A, B, C, D,E)

Parameters
pinPointer to a Pin instance describing one or more pins.
pinTypePIO_PERIPH_A, PIO_PERIPH_B, ...