RTEMS: bsps/arm/atsam/include/libchip/include/pio.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
pio.h
Go to the documentation of this file.
1/* ---------------------------------------------------------------------------- */
2/* Atmel Microcontroller Software Support */
3/* SAM Software Package License */
4/* ---------------------------------------------------------------------------- */
5/* Copyright (c) 2015, Atmel Corporation */
6/* */
7/* All rights reserved. */
8/* */
9/* Redistribution and use in source and binary forms, with or without */
10/* modification, are permitted provided that the following condition is met: */
11/* */
12/* - Redistributions of source code must retain the above copyright notice, */
13/* this list of conditions and the disclaimer below. */
14/* */
15/* Atmel's name may not be used to endorse or promote products derived from */
16/* this software without specific prior written permission. */
17/* */
18/* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */
19/* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
20/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */
21/* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */
22/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
23/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
24/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
25/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
26/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
27/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28/* ---------------------------------------------------------------------------- */
29
67#ifndef _PIO_
68#define _PIO_
69
70/*
71 * Headers
72 */
73
74#include "chip.h"
75
76#include <stdint.h>
77
78/*
79 * Global Definitions
80 */
81
83#define PIO_PERIPH_A 0
85#define PIO_PERIPH_B 1
87#define PIO_PERIPH_C 2
89#define PIO_PERIPH_D 3
91#define PIO_INPUT 4
93#define PIO_OUTPUT_0 5
95#define PIO_OUTPUT_1 6
96
98#define PIO_DEFAULT (0 << 0)
100#define PIO_PULLUP (1 << 0)
102#define PIO_DEGLITCH (1 << 1)
104#define PIO_OPENDRAIN (1 << 2)
105
107#define PIO_DEBOUNCE (1 << 3)
108
110#define PIO_IT_AIME (1 << 4)
111
113#define PIO_IT_RE_OR_HL (1 << 5)
115#define PIO_IT_EDGE (1 << 6)
116
118#define PIO_IT_LOW_LEVEL (0 | 0 | PIO_IT_AIME)
120#define PIO_IT_HIGH_LEVEL (PIO_IT_RE_OR_HL | 0 | PIO_IT_AIME)
122#define PIO_IT_FALL_EDGE (0 | PIO_IT_EDGE | PIO_IT_AIME)
124#define PIO_IT_RISE_EDGE (PIO_IT_RE_OR_HL | PIO_IT_EDGE | PIO_IT_AIME)
126#define PIO_WPMR_WPEN_EN (0x01 << 0)
128#define PIO_WPMR_WPEN_DIS (0x00 << 0)
130#define PIO_WPMR_WPKEY_VALID (0x50494F << 8)
131#ifdef __cplusplus
132extern "C" {
133#endif
134
135/*
136 * Global Macros
137 */
138
145#define PIO_LISTSIZE(pPins) (sizeof(pPins) / sizeof(Pin))
146
147/*
148 * Global Types
149 */
150
151
152/*
153 * Describes the type and attribute of one PIO pin or a group of similar pins.
154 * The #type# field can have the following values:
155 * - PIO_PERIPH_A
156 * - PIO_PERIPH_B
157 * - PIO_OUTPUT_0
158 * - PIO_OUTPUT_1
159 * - PIO_INPUT
160 *
161 * The #attribute# field is a bitmask that can either be set to PIO_DEFAULt,
162 * or combine (using bitwise OR '|') any number of the following constants:
163 * - PIO_PULLUP
164 * - PIO_DEGLITCH
165 * - PIO_DEBOUNCE
166 * - PIO_OPENDRAIN
167 * - PIO_IT_LOW_LEVEL
168 * - PIO_IT_HIGH_LEVEL
169 * - PIO_IT_FALL_EDGE
170 * - PIO_IT_RISE_EDGE
171 */
172 typedef struct _Pin {
173 /* Bitmask indicating which pin(s) to configure. */
174 uint32_t mask;
175 /* Pointer to the PIO controller which has the pin(s). */
176 Pio *pio;
177 /* Peripheral ID of the PIO controller which has the pin(s). */
178 uint8_t id;
179 /* Pin type. */
180 uint8_t type;
181 /* Pin attribute. */
182 uint8_t attribute;
183} Pin;
184
185/*
186 * Global Access Macros
187 */
188
189/*
190 * Global Functions
191 */
192
193extern uint8_t PIO_Configure(const Pin *list, uint32_t size);
194
195extern void PIO_Set(const Pin *pin);
196
197extern void PIO_Clear(const Pin *pin);
198
199extern uint8_t PIO_Get(const Pin *pin);
200
201extern uint8_t PIO_GetOutputDataStatus(const Pin *pin);
202
203extern void PIO_SetDebounceFilter(const Pin *pin, uint32_t cuttoff);
204
205extern void PIO_EnableWriteProtect(const Pin *pin);
206
207extern void PIO_DisableWriteProtect(const Pin *pin);
208
209extern void PIO_SetPinType(Pin *pin, uint8_t pinType);
210
211extern uint32_t PIO_GetWriteProtectViolationInfo(const Pin *pin);
212
213extern void PIO_SetDriveStrength(const Pin *pin, uint8_t strength);
214#ifdef __cplusplus
215}
216#endif
217
218#endif /* #ifndef _PIO_ */
219
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,...
Definition: pio.c:295
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...
Definition: pio.c:389
PIO_DisableWriteProtect
void PIO_DisableWriteProtect(const Pin *pin)
Disable write protect.
Definition: pio.c:455
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 effe...
Definition: pio.c:373
PIO_EnableWriteProtect
void PIO_EnableWriteProtect(const Pin *pin)
Enable write protect.
Definition: pio.c:442
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)
Definition: pio.c:479
PIO_SetDebounceFilter
void PIO_SetDebounceFilter(const Pin *pin, uint32_t cuttoff)
Configures Glitch or Denouncing filter for input.
Definition: pio.c:428
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...
Definition: pio.c:414
PIO_GetWriteProtectViolationInfo
uint32_t PIO_GetWriteProtectViolationInfo(const Pin *pin)
Get write protect violation information.
Definition: pio.c:467
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 eff...
Definition: pio.c:360
PIO_SetDriveStrength
void PIO_SetDriveStrength(const Pin *pin, uint8_t strength)
Set the drive strength of the pin.
Definition: pio.c:490
Pio
Pio hardware registers.
Definition: component_pio.h:41
_Pin
Definition: pio.h:172