Xmega IEC60730 Class B Library  1.0
 All Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sram/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  * Example application for the SRAM test.
7  *
8  * This example shows how the SRAM test can be embedded in an application.
9  * The application lights up an LED that signals correct behavior of the
10  * system. Then it enters the main loop, where the SRAM test is called
11  * periodically. This test is based on March X and it checks a segment of
12  * SRAM memory at a time. After the SRAM test, a second LED is toggled in
13  * order to visualize when the partial tests are finished. If errors were
14  * found, the global error flag would be set by the test. This would lead
15  * to the application leaving the main loop and switching off the first LED.
16  *
17  * The configuration for memory size, amount of segments, buffer size, etc.
18  * can bet set up in classb_sram.h. Note that if GCC is used and the size of
19  * the test buffer changes (as a result of a change in the number of segments
20  * or the amount of segment overlap), the new buffer size must be configured
21  * in the linker as well. See \ref classb_sram for more details.
22  *
23  * \par Application note:
24  * AVR1610: Guide to IEC60730 Class B compliance with XMEGA
25  *
26  * \par Documentation
27  * For comprehensive code documentation, supported compilers, compiler
28  * settings and supported devices see readme.html
29  *
30  * \author
31  * Atmel Corporation: http://www.atmel.com \n
32  * Support email: avr@atmel.com
33  *
34  * Copyright (C) 2012 Atmel Corporation. All rights reserved.
35  *
36  * \page License
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions are met:
40  *
41  * 1. Redistributions of source code must retain the above copyright notice,
42  * this list of conditions and the following disclaimer.
43  *
44  * 2. Redistributions in binary form must reproduce the above copyright notice,
45  * this list of conditions and the following disclaimer in the documentation
46  * and/or other materials provided with the distribution.
47  *
48  * 3. The name of Atmel may not be used to endorse or promote products derived
49  * from this software without specific prior written permission.
50  *
51  * 4. This software may only be redistributed and used in connection with an
52  * Atmel AVR product.
53  *
54  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
55  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
56  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
57  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
58  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
60  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
61  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
64  * DAMAGE.
65  */
66 
67 #include "avr_compiler.h"
68 #include "classb_sram.h"
69 
70 #if __AVR_ATxmega256A3BU__ | __ATxmega256A3BU__
71 # define LEDPORT PORTR
72 # define SWITCHPORT PORTE
73 # define SWITCH_INT0_vect PORTE_INT0_vect
74 # define XPLAIN_PULLUP 0x00
75 #elif defined(__AVR_ATxmega128A1__) | defined(__ATxmega128A1__)
76 # define LEDPORT PORTE
77 # define SWITCHPORT PORTF
78 # define SWITCH_INT0_vect PORTF_INT0_vect
79 # define XPLAIN_PULLUP PORT_OPC_PULLUP_gc
80 #endif
81 
82 void setup_led_switches() {
83 
84  // Set direction and state of LED pins
85  LEDPORT.DIRSET = PIN0_bm | PIN1_bm;
86  PORTCFG.MPCMASK = PIN0_bm | PIN1_bm;
87  LEDPORT.PIN0CTRL |= PORT_INVEN_bm;
88 
89  // Set sensitivity, polarity and pull-up for button PIN
90  SWITCHPORT.PIN5CTRL = PORT_ISC_FALLING_gc | PORT_INVEN_bm | XPLAIN_PULLUP;
91  SWITCHPORT.INT0MASK |= PIN5_bm;
92  SWITCHPORT.INTCTRL |= PORT_INT0LVL_LO_gc;
93 
94  // Enable LOW level interrupts in the INT controller
95  PMIC.CTRL |= PMIC_LOLVLEN_bm;
96 
97  // Turn on LED that signals correct operation
98  LEDPORT.OUTSET = PIN0_bm;
99 }
100 
101 
102 /** \brief Global error variable */
103 NO_INIT volatile uint8_t classb_error;
104 
105 
106 /*! \brief
107  * Main entry point of the application. Sets up board hardware,
108  * and waits until an error has occurred.
109  * \callgraph
110  */
111 int main(void)
112 {
113 
115  // Turn on interrupts globally.
116  sei();
117  while(!classb_error) {
118  cli();
120  sei();
121  //Toggle the second LED when test is ready.
122  LEDPORT.OUTTGL = PIN1_bm;
123  };
124 
125  // If this is executed there has been an error.
126  // Disable interrupts
127  cli();
128  // Turn off LED to indicate error.
129  LEDPORT.OUTCLR = PIN0_bm;
130 
131 }
132 
133 /*! \brief
134  * Button press interrupt.
135  * \callgraph
136  */
137  ISR(SWITCH_INT0_vect)
138 {
139 
140 }