pio_example3_pins_and_pio_connectivity.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00024 /* ************************************************************************
00025 
00026 Copyright (c) 2006, Atmel Corporation All rights reserved. 
00027 
00028 Redistribution and use in source and binary forms, with or without
00029 modification, are permitted provided that the following conditions are met:
00030 
00031 1. Redistributions of source code must retain the above copyright notice,
00032 this list of conditions and the 
00033 following disclaimer. 
00034 
00035 2. Redistributions in binary form must reproduce the above copyright notice,
00036 this list of conditions and the following disclaimer in the documentation
00037 and/or other materials provided with the distribution.
00038 
00039 3. The name of ATMEL may not be used to endorse or promote products 
00040 derived from this software without specific prior written permission.  
00041 
00042 THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS 
00043 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00044 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
00045 PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY 
00046 DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00047 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00048 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00049 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00050 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00051 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
00052 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
00053 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00054 
00055 POSSIBILITY OF SUCH DAMAGE. 
00056 
00057 ************************************************************************ */
00058 
00059 #include "pio.h"
00060 
00061 #ifdef __GNUC__
00062         #include <avr32/io.h>
00063 #elif __ICCAVR32__
00064         #include <avr32/ioap7000.h>
00065 #else
00066         #error No known compiler used
00067 #endif
00068 
00069 
00070 #define SUCCESS 0
00071 #define CPU_HZ 20000000
00072 
00073 #define PIN_MASK 0x000000ff
00074 
00075 /* Prototype */
00076 void delay( void );
00077 
00078 
00085 int main( void )
00086 {
00087   /*
00088     For this example to work, connect J15 to J1
00089   */
00090 
00091   volatile avr32_pio_t *piob = &AVR32_PIOB;
00092 
00093   /*
00094     The gcc header files contains pinout information. Each pin is numbered with a positive integer. 
00095     This number is between 0 and the number of pins of your chosen device. If you divide the it by 32,
00096     you will get the port number. I.e. 34 / 32 is 1. That means that pin 34 is part of port B. 
00097     Then, if the modulo 32 is calculted, you will get the pin number on the port. I.e. 34 % 32 is 2.
00098     Thus, the pin description 34 gives PORTB, pin 2.
00099 
00100     In addition each pin is connected to the PIO Controller. The actual pin can be driven by the PIO 
00101     Controller itself or by one of the two possible connected modules.
00102 
00103     Each I/O pin of a module is described in the header files in the following way;
00104     AVR32_{module}{instance}_{pin}_{mapping_instance}_PIN, i.e AVR32_USART1_RXD_0_PIN
00105 
00106     A specific I/O can be connected to one of the two possible connection, as is described in the header 
00107     files as:
00108     AVR32_{module}{instance}_{pin}_{mapping_instance}_FUNCTION, i.e AVR32_USART1_RXD_0_FUNCTION
00109 
00110     The FUNCTION definition of a pin can either be 0 or 1, which indicates if it is connected to module A or B of the 
00111     PIO Controller, respectively.
00112 
00113     This information can be used to enble the set of pins you need for I/O for module communication.
00114 
00115     Note: The mapping instance is used whenever a specific output is routed to several pins. When a single I/O from
00116     a module is routed to only one pin, 0 is always used.
00117 
00118   */
00119 
00120   /* bit 0..7 on port B is set as output */
00121   piob->per = PIN_MASK; /* Set pio enable for 16 LSBs of PORTB */
00122   piob->oer = PIN_MASK; /* Make them output ports */
00123   piob->idr = PIN_MASK; /* Disable interrupts on these pins */
00124   piob->puer = PIN_MASK; /* Enable pull-ups */
00125   piob->ower = PIN_MASK; /* Enable writing for the ODSR I/O line */
00126   piob->codr = PIN_MASK; /* Clear output */
00127 
00128   /* A list of pins to set under a module's control is generated */
00129   avr32_piomap_t test_piomap = {
00130    {32, 0}, /* port B, pin 0 */
00131    {33, 0} /* port B, pin 1 */
00132   };
00133 
00134  /* These pins are set under the module's control */
00135  pio_enable_module(test_piomap,2);
00136   
00137  /* We will toggle the leds */
00138  while(1){
00139    piob->odsr = ~(piob->odsr & PIN_MASK);
00140    delay();
00141    /* 
00142       Note: You will see that only LED[2..7] toggles, as LED[0..1] is put under module A's control.
00143       These data from the PIO controller is not pushed out the pin.
00144    */
00145  }
00146    
00147    return SUCCESS;
00148 }
00149 
00150 
00155 void delay ( void )
00156 {
00157   int i;
00158 
00159   for(i=0; i< (CPU_HZ/4); i++);
00160 
00161 }

Generated on Wed May 31 07:46:56 2006 for AVR32111 Using the AVR32 PIO Controller by  doxygen 1.4.6