00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00023 /* ************************************************************************ 00024 00025 Copyright (c) 2006, Atmel Corporation All rights reserved. 00026 00027 Redistribution and use in source and binary forms, with or without 00028 modification, are permitted provided that the following conditions are met: 00029 00030 1. Redistributions of source code must retain the above copyright notice, 00031 this list of conditions and the 00032 following disclaimer. 00033 00034 2. Redistributions in binary form must reproduce the above copyright notice, 00035 this list of conditions and the following disclaimer in the documentation 00036 and/or other materials provided with the distribution. 00037 00038 3. The name of ATMEL may not be used to endorse or promote products 00039 derived from this software without specific prior written permission. 00040 00041 THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS 00042 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00043 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00044 PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY 00045 DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, 00046 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00047 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00048 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00049 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00050 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00051 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 00052 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00053 00054 POSSIBILITY OF SUCH DAMAGE. 00055 00056 ************************************************************************ */ 00057 00058 #include "pio.h" 00059 00060 volatile avr32_pio_t *pioGetHandle(int port) 00061 { 00062 switch (port) { 00063 case 0: 00064 return &AVR32_PIOA; 00065 case 1: 00066 return &AVR32_PIOB; 00067 case 2: 00068 return &AVR32_PIOC; 00069 case 3: 00070 return &AVR32_PIOD; 00071 case 4: 00072 return &AVR32_PIOE; 00073 default : 00074 break; 00075 } 00076 return (avr32_pio_t *) -1; 00077 } 00078 00079 int pio_setup_pin(int pin, int function) 00080 { 00081 volatile avr32_pio_t *pio = pioGetHandle(pin/32); 00082 00083 00084 /* Disable pio control */ 00085 pio->pdr |= (1<<(pin%32)); 00086 pio->pudr |= (1<<(pin%32)); 00087 00088 /* Enable the correct function */ 00089 switch(function){ 00090 case 0: 00091 pio->asr |= (1<<(pin%32)); 00092 break; 00093 case 1: 00094 pio->bsr |= (1<<(pin%32)); 00095 break; 00096 default: 00097 return PIO_INVALID_ARGUMENT; 00098 } 00099 return PIO_SUCCESS; 00100 } 00101 00102 void pio_enable_module(avr32_piomap_t piomap, int size) 00103 { 00104 int i; 00105 00106 for(i=0; i<size; i++){ 00107 pio_setup_pin(**piomap, *(*piomap+1) ); 00108 piomap++; 00109 } 00110 }
1.5.3-20071008