interrupt_example_gcc.c

Go to the documentation of this file.
00001 /* ************************************************************************
00002 
00003 Copyright (c) 2006, Atmel Corporation All rights reserved. 
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008 1. Redistributions of source code must retain the above copyright notice,
00009 this list of conditions and the 
00010 following disclaimer. 
00011 
00012 2. Redistributions in binary form must reproduce the above copyright notice,
00013 this list of conditions and the following disclaimer in the documentation
00014 and/or other materials provided with the distribution.
00015 
00016 3. The name of ATMEL may not be used to endorse or promote products 
00017 derived from this software without specific prior written permission.  
00018 
00019 THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS 
00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00021 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
00022 PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY 
00023 DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00024 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00025 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00026 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00027 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00028 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
00029 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
00030 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00031 
00032 POSSIBILITY OF SUCH DAMAGE. 
00033 ************************************************************************ */
00034 
00035 
00036 /* NOTE:
00037     To get this example to work on your stk1000, connect J6 to J15 and J3 to 
00038     J25. You can then press the switches to generate an interrupt. The 
00039     corresponding led will be lit to indicate that the interrupt has triggered.
00040 
00041     This appnote uses the PIO controller. The settings and configuration of the 
00042     PIO controller is not a part of this appnote. Please read the appnote "Using 
00043     the AVR32 pio controller" for further information.
00044 
00045 
00046 */
00047 
00048 #include <avr32/io.h>
00049 #include <sys/interrupts.h>
00050 
00051 #define SUCCESS 0;
00052 #define FAILURE -1;
00053 
00054 #define INPUT_MASK 0x000000ff
00055 #define OUTPUT_MASK 0x0000ff00
00056 
00062 __int_handler *pioc_int_handler()
00063 {
00064   volatile struct avr32_pio_t *pioc = &AVR32_PIOC;
00065   int status;
00066 
00067   status = pioc->isr;
00068   status = pioc->pdsr;
00069 
00070   pioc->odsr =~(status&INPUT_MASK)<<8; /* set led */
00071 
00072   return (void *) 0;
00073 }
00074 
00082 int main( void )
00083 {
00084   volatile struct avr32_pio_t *pioc = &AVR32_PIOC;
00085 
00086   /* 
00087   Setup the PIO controller. Set PIOC[8..15] as output, PIOC[0..7] as input.
00088   To get this to work on your stk1000, connect J6 to J15 and J3 to J25
00089   */
00090 
00091   pioc->odr= INPUT_MASK;
00092   pioc->per = OUTPUT_MASK;
00093   pioc->oer = OUTPUT_MASK;
00094   pioc->codr = INPUT_MASK & OUTPUT_MASK;
00095   pioc->puer = INPUT_MASK & OUTPUT_MASK;
00096   pioc->idr &= ~INPUT_MASK;
00097   pioc->ier = INPUT_MASK;
00098   pioc->ower = OUTPUT_MASK;
00099 
00100 
00101   /* Setup the interrupt handler, handled by newlib */
00102   set_interrupts_base( (void *) AVR32_INTC_ADDRESS );
00103   /* register_intterupt( (__int_handler) {func}, {GROUP}, {LINE}, {LEVEL} ); */ 
00104   register_interrupt( (__int_handler) (pioc_int_handler), AVR32_PIOC_IRQ/32, AVR32_PIOC_IRQ % 32, INT0);
00105   init_interrupts();
00106 
00107   while(1);
00108 
00109   return 0;
00110 }
00111 

Generated on Wed May 10 15:23:22 2006 for AVR32101 The AVR32 Interrupt Controller by  doxygen 1.4.6