Xmega IEC60730 Class B Library  1.0
 All Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
analog/UserApplication.c
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 /**
3  * \file
4  *
5  * \brief
6  * This in an demo application for the ADC and DAC tests.
7  *
8  * \par Application note:
9  * AVR1610: Guide to IEC60730 Class B compliance with XMEGA
10  *
11  * \par Documentation
12  * For comprehensive code documentation, supported compilers, compiler
13  * settings and supported devices see readme.html
14  *
15  * \author
16  * Atmel Corporation: http://www.atmel.com \n
17  * Support email: avr@atmel.com
18  *
19  * Copyright (C) 2012 Atmel Corporation. All rights reserved.
20  *
21  * \page License
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions are met:
25  *
26  * 1. Redistributions of source code must retain the above copyright notice,
27  * this list of conditions and the following disclaimer.
28  *
29  * 2. Redistributions in binary form must reproduce the above copyright notice,
30  * this list of conditions and the following disclaimer in the documentation
31  * and/or other materials provided with the distribution.
32  *
33  * 3. The name of Atmel may not be used to endorse or promote products derived
34  * from this software without specific prior written permission.
35  *
36  * 4. This software may only be redistributed and used in connection with an
37  * Atmel AVR product.
38  *
39  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
41  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
42  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
43  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
46  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
49  * DAMAGE.
50  */
51 
52 #include "avr_compiler.h"
53 #include "classb_analog.h"
54 
55 //! \brief Global error flag
56 NO_INIT volatile uint8_t classb_error;
57 
58 //! \name Board configuration
59 //@{
60 #if __AVR_ATxmega256A3BU__ | __ATxmega256A3BU__ | __DOXYGEN__
61  # define LEDPORT PORTR
62  # define SWITCHPORT0 PORTE
63  # define SWITCHPORT1 PORTF
64  # define SWITCH0_INT0_vect PORTE_INT0_vect
65  # define SWITCH1_INT0_vect PORTF_INT0_vect
66  # define XPLAIN_PULLUP 0x00
67 #elif defined(__AVR_ATxmega128A1__) | defined(__ATxmega128A1__)
68  # define LEDPORT PORTE
69  # define SWITCHPORT0 PORTF
70  # define SWITCHPORT0 PORTF
71  # define SWITCH_INT0_vect PORTF_INT0_vect
72  # define XPLAIN_PULLUP PORT_OPC_PULLUP_gc
73 #endif
74 //@}
75 
76 //! \brief Setup LEDs and button.
78 
79  // Set direction and state of LEDs
80  LEDPORT.DIRSET = PIN0_bm|PIN1_bm;
81  PORTCFG.MPCMASK = PIN0_bm|PIN1_bm;
82  LEDPORT.PIN0CTRL |= PORT_INVEN_bm;
83 
84  // Set sensitivity, polarity and pullup for button SW0
85  SWITCHPORT0.PIN5CTRL |= PORT_ISC_FALLING_gc | PORT_INVEN_bm;
86  SWITCHPORT0.INT0MASK |= PIN5_bm;
87  SWITCHPORT0.INTCTRL |= PORT_INT0LVL_LO_gc;
88 
89  // Enable LOW level interrupts in the INT controller
90  PMIC.CTRL |= PMIC_LOLVLEN_bm;
91 
92  // Turn on LED that signals correct operation.
93  LEDPORT.OUTSET = PIN0_bm;
94 }
95 
96 
97 int main(void)
98 {
99  // Initial setup
101 
102  // Interrupts enabled in the system
103  sei();
104 
105  while(!classb_error)
106  {
107  // Do nothing
108  };
109 
110  // If this is executed there has been an error.
111  // Turn off LED
112  LEDPORT.OUTCLR = PIN0_bm;
113 }
114 
115 
116 /*! \brief Interrupt for SW0 press
117  *
118  */
119 ISR(SWITCH0_INT0_vect)
120 {
121  cli();
122  // Test DAC and first ADC module
123  classb_analog_io_test(&DACB, &ADCA);
124  // Test DAC and second ADC module
125  classb_analog_io_test(&DACB, &ADCB);
126  sei();
127 }
128 
129