- Main Page
- Data Structures
- Files

# pio.c

Go to the documentation of this file.

    00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
    00019 /* Copyright (C) 2006-2008, Atmel Corporation All rights reserved.
    00020  *
    00021  * Redistribution and use in source and binary forms, with or without
    00022  * modification, are permitted provided that the following conditions are met:
    00023  *
    00024  * 1. Redistributions of source code must retain the above copyright notice,
    00025  * this list of conditions and the following disclaimer.
    00026  *
    00027  * 2. Redistributions in binary form must reproduce the above copyright notice,
    00028  * this list of conditions and the following disclaimer in the documentation
    00029  * and/or other materials provided with the distribution.
    00030  *
    00031  * 3. The name of ATMEL may not be used to endorse or promote products derived
    00032  * from this software without specific prior written permission.
    00033  *
    00034  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
    00035  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00036  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
    00037  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00038  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00039  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00040  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00041  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00042  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00043  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00044  */
    00045
    00090 #include "pio.h"
    00091
    00092 volatile avr32_pio_t *pioGetHandle(int port)
    00093 {
    00094   switch (port) {
    00095     case 0:
    00096       return &AVR32_PIOA;
    00097     case 1:
    00098       return &AVR32_PIOB;
    00099     case 2:
    00100       return &AVR32_PIOC;
    00101     case 3:
    00102       return &AVR32_PIOD;
    00103     case 4:
    00104       return &AVR32_PIOE;
    00105     default :
    00106       break;
    00107   }
    00108         return (avr32_pio_t *) -1;
    00109 }
    00110
    00111 int gpio_enable_module_pin(int pin, int function)
    00112 {
    00113   return pio_setup_pin(pin, function);
    00114 }
    00115
    00116
    00117 int pio_setup_pin(int pin, int function)
    00118 {
    00119   volatile avr32_pio_t *pio = pioGetHandle(pin/32);
    00120
    00121
    00122   /* Disable pio control */
    00123   pio->pdr |= (1<<(pin%32));
    00124   pio->pudr |= (1<<(pin%32));
    00125
    00126   /* Enable the correct function */
    00127   switch(function){
    00128     case 0:
    00129       pio->asr |= (1<<(pin%32));
    00130       break;
    00131     case 1:
    00132       pio->bsr |= (1<<(pin%32));
    00133       break;
    00134     default:
    00135       return PIO_INVALID_ARGUMENT;
    00136   }
    00137   return PIO_SUCCESS;
    00138 }
    00139
    00140 void pio_enable_module(const gpio_map_t piomap, int size)
    00141 {
    00142   int i;
    00143
    00144   for(i=0; i<size; i++){
    00145     pio_setup_pin(piomap->pin, piomap->function );
    00146     piomap++;
    00147   }
    00148 }
    00149
    00150 void gpio_enable_module(const gpio_map_t piomap, int size)
    00151 {
    00152   pio_enable_module(piomap, size);
    00153 }