Nut/OS  4.10.3
API Reference
gpio.h
Go to the documentation of this file.
00001 
00037 /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
00038 
00039 /*This file has been prepared for Doxygen automatic documentation generation.*/
00055 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
00056  *
00057  * Redistribution and use in source and binary forms, with or without
00058  * modification, are permitted provided that the following conditions are met:
00059  *
00060  * 1. Redistributions of source code must retain the above copyright notice, this
00061  * list of conditions and the following disclaimer.
00062  *
00063  * 2. Redistributions in binary form must reproduce the above copyright notice,
00064  * this list of conditions and the following disclaimer in the documentation
00065  * and/or other materials provided with the distribution.
00066  *
00067  * 3. The name of Atmel may not be used to endorse or promote products derived
00068  * from this software without specific prior written permission.
00069  *
00070  * 4. This software may only be redistributed and used in connection with an Atmel
00071  * AVR product.
00072  *
00073  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00074  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00075  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00076  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
00077  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00078  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00079  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00080  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00081  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00082  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00083  *
00084  */
00085 
00086 #ifndef _GPIO_H_
00087 #define _GPIO_H_
00088 
00089 #include <arch/avr32.h>
00090 #include <avr32/io.h>
00091 
00092 
00095 
00096 #define GPIO_SUCCESS            0 //!< Function successfully completed.
00097 #define GPIO_INVALID_ARGUMENT   1 //!< Input parameters are out of range.
00098 
00099 
00100 
00103 
00104 #define GPIO_PIN_CHANGE         0 //!< Interrupt triggered upon pin change.
00105 #define GPIO_RISING_EDGE        1 //!< Interrupt triggered upon rising edge.
00106 #define GPIO_FALLING_EDGE       2 //!< Interrupt triggered upon falling edge.
00107 
00108 
00109 
00111 typedef struct
00112 {
00113   unsigned char pin;              
00114   unsigned char function;         
00115 } gpio_map_t[];
00116 
00117 
00129 
00130 
00138 extern int gpio_enable_module(const gpio_map_t gpiomap, unsigned int size);
00139 
00155 extern int gpio_enable_module_pin(unsigned int pin, unsigned int function);
00156 
00162 extern void gpio_enable_gpio(const gpio_map_t gpiomap, unsigned int size);
00163 
00173 extern void gpio_enable_gpio_pin(unsigned int pin);
00174 
00175 // The open-drain mode is not synthesized on the current AVR32 products.
00176 // If one day some AVR32 products have this feature, the corresponding part
00177 // numbers should be listed in the #if below.
00178 // Note that other functions are available in this driver to use pins with open
00179 // drain in GPIO mode. The advantage of the open-drain mode functions over these
00180 // other functions is that they can be used not only in GPIO mode but also in
00181 // module mode.
00182 #if 0
00183 
00188 extern void gpio_enable_pin_open_drain(unsigned int pin);
00189 
00194 extern void gpio_disable_pin_open_drain(unsigned int pin);
00195 
00196 #endif
00197 
00202 extern void gpio_enable_pin_pull_up(unsigned int pin);
00203 
00208 extern void gpio_disable_pin_pull_up(unsigned int pin);
00209 
00210 #if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
00211 // Added support of Pull-up Resistor, Pull-down Resistor and Buskeeper Control.
00212 
00217 extern void gpio_enable_pin_pull_down(unsigned int pin);
00218 
00223 extern void gpio_disable_pin_pull_down(unsigned int pin);
00224 
00229 extern void gpio_enable_pin_buskeeper(unsigned int pin);
00230 
00235 extern void gpio_disable_pin_buskeeper(unsigned int pin);
00236 
00237 #endif
00238 
00245 extern int gpio_get_pin_value(unsigned int pin);
00246 
00256 extern int gpio_get_gpio_pin_output_value(unsigned int pin);
00257 
00268 extern int gpio_get_gpio_open_drain_pin_output_value(unsigned int pin);
00269 
00274 extern void gpio_set_gpio_pin(unsigned int pin);
00275 
00280 extern void gpio_clr_gpio_pin(unsigned int pin);
00281 
00286 extern void gpio_tgl_gpio_pin(unsigned int pin);
00287 
00292 extern void gpio_set_gpio_open_drain_pin(unsigned int pin);
00293 
00298 extern void gpio_clr_gpio_open_drain_pin(unsigned int pin);
00299 
00304 extern void gpio_tgl_gpio_open_drain_pin(unsigned int pin);
00305 
00319 extern void gpio_enable_pin_glitch_filter(unsigned int pin);
00320 
00325 extern void gpio_disable_pin_glitch_filter(unsigned int pin);
00326 
00335 extern int gpio_enable_pin_interrupt(unsigned int pin, unsigned int mode);
00336 
00341 extern void gpio_disable_pin_interrupt(unsigned int pin);
00342 
00349 extern int gpio_get_pin_interrupt_flag(unsigned int pin);
00350 
00355 extern void gpio_clear_pin_interrupt_flag(unsigned int pin);
00356 
00358 
00359 
00360 #if (defined AVR32_GPIO_LOCAL_ADDRESS)
00361 
00375 
00376 
00382 #if (defined __GNUC__)
00383 __attribute__((__always_inline__))
00384 #endif
00385 extern __inline__ void gpio_local_init(void)
00386 {
00387   Set_system_register(AVR32_CPUCR,
00388                       Get_system_register(AVR32_CPUCR) | AVR32_CPUCR_LOCEN_MASK);
00389 }
00390 
00400 #if (defined __GNUC__)
00401 __attribute__((__always_inline__))
00402 #endif
00403 extern __inline__ void gpio_local_enable_pin_output_driver(unsigned int pin)
00404 {
00405   AVR32_GPIO_LOCAL.port[pin >> 5].oders = 1 << (pin & 0x1F);
00406 }
00407 
00414 #if (defined __GNUC__)
00415 __attribute__((__always_inline__))
00416 #endif
00417 extern __inline__ void gpio_local_disable_pin_output_driver(unsigned int pin)
00418 {
00419   AVR32_GPIO_LOCAL.port[pin >> 5].oderc = 1 << (pin & 0x1F);
00420 }
00421 
00430 #if (defined __GNUC__)
00431 __attribute__((__always_inline__))
00432 #endif
00433 extern __inline__ int gpio_local_get_pin_value(unsigned int pin)
00434 {
00435   return (AVR32_GPIO_LOCAL.port[pin >> 5].pvr >> (pin & 0x1F)) & 1;
00436 }
00437 
00449 #if (defined __GNUC__)
00450 __attribute__((__always_inline__))
00451 #endif
00452 extern __inline__ void gpio_local_set_gpio_pin(unsigned int pin)
00453 {
00454   AVR32_GPIO_LOCAL.port[pin >> 5].ovrs = 1 << (pin & 0x1F);
00455 }
00456 
00468 #if (defined __GNUC__)
00469 __attribute__((__always_inline__))
00470 #endif
00471 extern __inline__ void gpio_local_clr_gpio_pin(unsigned int pin)
00472 {
00473   AVR32_GPIO_LOCAL.port[pin >> 5].ovrc = 1 << (pin & 0x1F);
00474 }
00475 
00487 #if (defined __GNUC__)
00488 __attribute__((__always_inline__))
00489 #endif
00490 extern __inline__ void gpio_local_tgl_gpio_pin(unsigned int pin)
00491 {
00492   AVR32_GPIO_LOCAL.port[pin >> 5].ovrt = 1 << (pin & 0x1F);
00493 }
00494 
00503 #if (defined __GNUC__)
00504 __attribute__((__always_inline__))
00505 #endif
00506 extern __inline__ void gpio_local_init_gpio_open_drain_pin(unsigned int pin)
00507 {
00508   AVR32_GPIO_LOCAL.port[pin >> 5].ovrc = 1 << (pin & 0x1F);
00509 }
00510 
00521 #if (defined __GNUC__)
00522 __attribute__((__always_inline__))
00523 #endif
00524 extern __inline__ void gpio_local_set_gpio_open_drain_pin(unsigned int pin)
00525 {
00526   AVR32_GPIO_LOCAL.port[pin >> 5].oderc = 1 << (pin & 0x1F);
00527 }
00528 
00539 #if (defined __GNUC__)
00540 __attribute__((__always_inline__))
00541 #endif
00542 extern __inline__ void gpio_local_clr_gpio_open_drain_pin(unsigned int pin)
00543 {
00544   AVR32_GPIO_LOCAL.port[pin >> 5].oders = 1 << (pin & 0x1F);
00545 }
00546 
00557 #if (defined __GNUC__)
00558 __attribute__((__always_inline__))
00559 #endif
00560 extern __inline__ void gpio_local_tgl_gpio_open_drain_pin(unsigned int pin)
00561 {
00562   AVR32_GPIO_LOCAL.port[pin >> 5].odert = 1 << (pin & 0x1F);
00563 }
00564 
00566 #endif // AVR32_GPIO_LOCAL_ADDRESS
00567 
00568 #if UC3L
00569 
00570 
00583 #if (defined __GNUC__)
00584 __attribute__((__always_inline__))
00585 #endif
00586 extern __inline__ void gpio_enable_pin_periph_event(unsigned int pin)
00587 {
00588   AVR32_GPIO.port[pin >> 5].oderc = 1 << (pin & 0x1F); // The GPIO output driver is disabled for that pin.
00589   AVR32_GPIO.port[pin >> 5].evers = 1 << (pin & 0x1F);
00590 }
00591 
00597 #if (defined __GNUC__)
00598 __attribute__((__always_inline__))
00599 #endif
00600 extern __inline__ void gpio_disable_pin_periph_event(unsigned int pin)
00601 {
00602   AVR32_GPIO.port[pin >> 5].everc = 1 << (pin & 0x1F);
00603 }
00604 
00614 extern int gpio_configure_pin_periph_event_mode(unsigned int pin, unsigned int mode, unsigned int use_igf);
00615 
00617 #endif // UC3L
00618 
00619 #endif  // _GPIO_H_