AppConfigHeaders: Add missing AppConfig.h file includes.
[pub/USBasp.git] / LUFA / Common / ArchitectureSpecific.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 * \brief Architecture specific definitions relating to specific processor architectures.
33 *
34 * \copydetails Group_ArchitectureSpecific
35 *
36 * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's
37 * functionality.
38 */
39
40 /** \ingroup Group_Common
41 * \defgroup Group_ArchitectureSpecific Architecture Specific Definitions
42 * \brief Architecture specific definitions relating to specific processor architectures.
43 *
44 * Architecture specific macros, functions and other definitions, which relate to specific architectures. This
45 * definitions may or may not be available in some form on other architectures, and thus should be protected by
46 * preprocessor checks in portable code to prevent compile errors.
47 *
48 * @{
49 */
50
51 #ifndef __LUFA_ARCHSPEC_H__
52 #define __LUFA_ARCHSPEC_H__
53
54 /* Preprocessor Checks: */
55 #if !defined(__INCLUDE_FROM_COMMON_H)
56 #error Do not include this file directly. Include LUFA/Common/Common.h instead to gain this functionality.
57 #endif
58
59 /* Enable C linkage for C++ Compilers: */
60 #if defined(__cplusplus)
61 extern "C" {
62 #endif
63
64 /* Public Interface - May be used in end-application: */
65 /* Macros: */
66 #if (ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA) || defined(__DOXYGEN__)
67 #if (ARCH == ARCH_AVR8) || defined(__DOXYGEN__)
68 /** Disables the AVR's JTAG bus in software, until a system reset. This will override the current JTAG
69 * status as set by the JTAGEN fuse, disabling JTAG debugging and reverting the JTAG pins back to GPIO
70 * mode.
71 *
72 * \note This macro is not available for all architectures.
73 */
74 #define JTAG_DISABLE() MACROS{ \
75 __asm__ __volatile__ ( \
76 "in __tmp_reg__,__SREG__" "\n\t" \
77 "cli" "\n\t" \
78 "out %1, %0" "\n\t" \
79 "out __SREG__, __tmp_reg__" "\n\t" \
80 "out %1, %0" "\n\t" \
81 : \
82 : "r" (1 << JTD), \
83 "M" (_SFR_IO_ADDR(MCUCR)) \
84 : "r0"); \
85 }MACROE
86 #endif
87
88 /** Defines a volatile \c NOP statement which cannot be optimized out by the compiler, and thus can always
89 * be set as a breakpoint in the resulting code. Useful for debugging purposes, where the optimizer
90 * removes/reorders code to the point where break points cannot reliably be set.
91 *
92 * \note This macro is not available for all architectures.
93 */
94 #define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::)
95
96 /** Defines an explicit JTAG break point in the resulting binary via the assembly \c BREAK statement. When
97 * a JTAG is used, this causes the program execution to halt when reached until manually resumed.
98 *
99 * \note This macro is not available for all architectures.
100 */
101 #define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("break" ::)
102
103 /** Macro for testing condition "x" and breaking via \ref JTAG_DEBUG_BREAK() if the condition is false.
104 *
105 * \note This macro is not available for all architectures.
106 *
107 * \param[in] Condition Condition that will be evaluated.
108 */
109 #define JTAG_ASSERT(Condition) MACROS{ if (!(Condition)) { JTAG_DEBUG_BREAK(); } }MACROE
110
111 /** Macro for testing condition \c "x" and writing debug data to the stdout stream if \c false. The stdout stream
112 * must be pre-initialized before this macro is run and linked to an output device, such as the microcontroller's
113 * USART peripheral.
114 *
115 * The output takes the form "{FILENAME}: Function {FUNCTION NAME}, Line {LINE NUMBER}: Assertion {Condition} failed."
116 *
117 * \note This macro is not available for all architectures.
118 *
119 * \param[in] Condition Condition that will be evaluated,
120 */
121 #define STDOUT_ASSERT(Condition) MACROS{ if (!(x)) { \
122 printf_P(PSTR("%s: Function \"%s\", Line %d: " \
123 "Assertion \"%s\" failed.\r\n"), \
124 __FILE__, __func__, __LINE__, #Condition); } }MACROE
125
126 #if !defined(pgm_read_ptr) || defined(__DOXYGEN__)
127 /** Reads a pointer out of PROGMEM space on the AVR8 architecture. This is currently a wrapper for the
128 * avr-libc \c pgm_read_ptr() macro with a \c void* cast, so that its value can be assigned directly
129 * to a pointer variable or used in pointer arithmetic without further casting in C. In a future
130 * avr-libc distribution this will be part of the standard API and will be implemented in a more formal
131 * manner.
132 *
133 * \note This macro is not available for all architectures.
134 *
135 * \param[in] Address Address of the pointer to read.
136 *
137 * \return Pointer retrieved from PROGMEM space.
138 */
139 #define pgm_read_ptr(Address) (void*)pgm_read_word(Address)
140 #endif
141 #elif (ARCH == ARCH_UC3)
142 #define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::)
143 #define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("breakpoint" ::)
144 #define JTAG_ASSERT(Condition) MACROS{ if (!(Condition)) { JTAG_DEBUG_BREAK(); } }MACROE
145 #define STDOUT_ASSERT(Condition) MACROS{ if (!(x)) { \
146 printf("%s: Function \"%s\", Line %d: " \
147 "Assertion \"%s\" failed.\r\n"), \
148 __FILE__, __func__, __LINE__, #Condition); } }MACROE
149 #endif
150
151 /* Disable C linkage for C++ Compilers: */
152 #if defined(__cplusplus)
153 }
154 #endif
155
156 #endif
157
158 /** @} */
159