Xmega IEC60730 Class B Library  1.0
 All Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
error_handler.h
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 /**
3  * \file
4  *
5  * \brief Macros and definitions for handling errors and other configurable actions.
6  *
7  * \par Application note:
8  * AVR1610: Guide to IEC60730 Class B compliance with XMEGA
9  *
10  * \par Documentation
11  * For comprehensive code documentation, supported compilers, compiler
12  * settings and supported devices see readme.html
13  *
14  * \author
15  * Atmel Corporation: http://www.atmel.com \n
16  * Support email: avr@atmel.com
17  *
18  * Copyright (C) 2012 Atmel Corporation. All rights reserved.
19  *
20  * \page License
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions are met:
24  *
25  * 1. Redistributions of source code must retain the above copyright notice,
26  * this list of conditions and the following disclaimer.
27  *
28  * 2. Redistributions in binary form must reproduce the above copyright notice,
29  * this list of conditions and the following disclaimer in the documentation
30  * and/or other materials provided with the distribution.
31  *
32  * 3. The name of Atmel may not be used to endorse or promote products derived
33  * from this software without specific prior written permission.
34  *
35  * 4. This software may only be redistributed and used in connection with an
36  * Atmel AVR product.
37  *
38  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
40  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
41  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
42  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
45  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
48  * DAMAGE.
49  */
50 
51 #ifndef CLASSB_ERROR_HANDLER_H
52 #define CLASSB_ERROR_HANDLER_H
53 
54 #include "avr_compiler.h"
55 
56 
57 //! \defgroup error_handler Error Handling
58 //! \brief Definitions related to error handling for Class B tests.
59 //!
60 //! In order to make the library as flexible as possible, the user can configure
61 //! the response to the different errors that can appear during the tests. Therefore,
62 //! the user is responsible to handle the errors in a way such that the application
63 //! is safe and reliable.
64 //@{
65 
66 //! \name Global variables defined in the main application.
67 //@{
68 //! \brief The global error flag in the examples
69 NO_INIT extern volatile uint8_t classb_error;
70 //@}
71 
72 //! \name Functions prototypes
73 //! \brief Declare functions that are called by the error handlers.
74 //! Those functions should be defined in an application file.
75 //@{
76 
77 //@}
78 
79 //! \name Error handlers for Class B tests.
80 //! These are the statements that should be run if a test fails.
81 //! \note The statements need to be declared as:
82 //! - <tt>do{<statements>}while(0)</tt> or similar.
83 //! - Example: in order to hang the device it is possible to set <tt>do{}while(1)</tt>.
84 //!
85 //@{
86 //! Error handler for the ADC, DAC and analog multiplexer test
87 #define CLASSB_ERROR_HANDLER_ANALOG() do{classb_error = 1;}while(0)
88 //! Error handler for the CRC test
89 #define CLASSB_ERROR_HANDLER_CRC() do{classb_error = 1;}while(0)
90 //! Error handler for the CPU frequency test
91 #define CLASSB_ERROR_HANDLER_FREQ() do{classb_error = 1;}while(0)
92 //! Error handler for the interrupt monitor
93 #define CLASSB_ERROR_HANDLER_INTERRUPT() do{classb_error = 1;}while(0)
94 //! Error handler for the CPU registers test
95 #define CLASSB_ERROR_HANDLER_REGISTERS() do{classb_error = 1;}while(0)
96 //! Error handler for the SRAM test
97 #define CLASSB_ERROR_HANDLER_SRAM() do{classb_error = 1;}while(0)
98 //! Error handler for watchdog timer test
99 #define CLASSB_ERROR_HANDLER_WDT() do{}while(1)
100 //@}
101 
102 //! \name Configurable actions and conditions for Class B tests.
103 //! Some test have a configurable behavior.
104 //! \note
105 //! - The conditions should be declared as: <tt>(<condition>)</tt>.
106 //! - Statements need to be declared as: <tt>do{<statements>}while(0)</tt> or similar.
107 //! - Example: in order to hang the device it is possible to set: <tt>do{}while(1)</tt>.
108 //@{
109 
110 
111 //! Condition to assign a new state
112 #define CLASSB_CONDITION1_INTERRUPT (!classb_error)
113 
114 //! Condition to stop checking interrupts within the monitor
115 #define CLASSB_CONDITION2_INTERRUPT (classb_error)
116 
117 
118 //! Configurable actions in the RTC interrupt.
119 #define CLASSB_ACTIONS_RTC() ;
120 
121 //! First group of configurable actions in the watchdog timer test.
122 #define CLASSB_ACTIONS_WDT_RUNTIME_FAILURE() \
123  do{\
124  /* In our example application we set the error variable and \
125  re-enable watchdog timer.*/ \
126  classb_error = 1;\
127  /* WDT configuration for the main application: WDT in normal mode */\
128  CCP = CCP_IOREG_gc;\
129  WDT.CTRL = WDT_ENABLE_bm | CLASSB_WDT_PER | WDT_CEN_bm ;\
130  /* Wait until WDT Synchronized */\
131  while( WDT.STATUS & WDT_SYNCBUSY_bm );\
132  /* Set Closed period (when WDT cannot be reset) */\
133  CCP = CCP_IOREG_gc;\
134  WDT.WINCTRL = WDT_WEN_bm | CLASSB_WDT_WPER | WDT_WCEN_bm;\
135  /* Wait until WDT Synchronized */\
136  while( WDT.STATUS & WDT_SYNCBUSY_bm );\
137  }while(0)
138 
139 //! \brief Second group of configurable actions in the watchdog timer test.
140 #define CLASSB_ACTIONS_WDT_OTHER_FAILURE() do{}while(0)
141 //@}
142 
143 
144 //@}
145 
146 #endif //CLASSB_ERROR_HANDLER_H