]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-120730/LUFA/Common/ArchitectureSpecific.h
Squashed 'tmk_core/' content from commit 05caacc
[tmk_keyboard.git] / protocol / lufa / LUFA-120730 / 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 /** Re-enables the AVR's JTAG bus in software, until a system reset. This will re-enable JTAG debugging
69 * interface after is has been disabled in software via \ref JTAG_DISABLE().
70 *
71 * \note This macro is not available for all architectures.
72 */
73 #define JTAG_ENABLE() MACROS{ \
74 __asm__ __volatile__ ( \
75 "in __tmp_reg__,__SREG__" "\n\t" \
76 "cli" "\n\t" \
77 "out %1, %0" "\n\t" \
78 "out __SREG__, __tmp_reg__" "\n\t" \
79 "out %1, %0" "\n\t" \
80 : \
81 : "r" (MCUCR & ~(1 << JTD)), \
82 "M" (_SFR_IO_ADDR(MCUCR)) \
83 : "r0"); \
84 }MACROE
85
86 /** Disables the AVR's JTAG bus in software, until a system reset. This will override the current JTAG
87 * status as set by the JTAGEN fuse, disabling JTAG debugging and reverting the JTAG pins back to GPIO
88 * mode.
89 *
90 * \note This macro is not available for all architectures.
91 */
92 #define JTAG_DISABLE() MACROS{ \
93 __asm__ __volatile__ ( \
94 "in __tmp_reg__,__SREG__" "\n\t" \
95 "cli" "\n\t" \
96 "out %1, %0" "\n\t" \
97 "out __SREG__, __tmp_reg__" "\n\t" \
98 "out %1, %0" "\n\t" \
99 : \
100 : "r" (MCUCR | (1 << JTD)), \
101 "M" (_SFR_IO_ADDR(MCUCR)) \
102 : "r0"); \
103 }MACROE
104 #endif
105
106 /** Defines a volatile \c NOP statement which cannot be optimized out by the compiler, and thus can always
107 * be set as a breakpoint in the resulting code. Useful for debugging purposes, where the optimizer
108 * removes/reorders code to the point where break points cannot reliably be set.
109 *
110 * \note This macro is not available for all architectures.
111 */
112 #define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::)
113
114 /** Defines an explicit JTAG break point in the resulting binary via the assembly \c BREAK statement. When
115 * a JTAG is used, this causes the program execution to halt when reached until manually resumed.
116 *
117 * \note This macro is not available for all architectures.
118 */
119 #define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("break" ::)
120
121 /** Macro for testing condition "x" and breaking via \ref JTAG_DEBUG_BREAK() if the condition is false.
122 *
123 * \note This macro is not available for all architectures.
124 *
125 * \param[in] Condition Condition that will be evaluated.
126 */
127 #define JTAG_ASSERT(Condition) MACROS{ if (!(Condition)) { JTAG_DEBUG_BREAK(); } }MACROE
128
129 /** Macro for testing condition \c "x" and writing debug data to the stdout stream if \c false. The stdout stream
130 * must be pre-initialized before this macro is run and linked to an output device, such as the microcontroller's
131 * USART peripheral.
132 *
133 * The output takes the form "{FILENAME}: Function {FUNCTION NAME}, Line {LINE NUMBER}: Assertion {Condition} failed."
134 *
135 * \note This macro is not available for all architectures.
136 *
137 * \param[in] Condition Condition that will be evaluated,
138 */
139 #define STDOUT_ASSERT(Condition) MACROS{ if (!(x)) { \
140 printf_P(PSTR("%s: Function \"%s\", Line %d: " \
141 "Assertion \"%s\" failed.\r\n"), \
142 __FILE__, __func__, __LINE__, #Condition); } }MACROE
143
144 #if !defined(pgm_read_ptr) || defined(__DOXYGEN__)
145 /** Reads a pointer out of PROGMEM space on the AVR8 architecture. This is currently a wrapper for the
146 * avr-libc \c pgm_read_ptr() macro with a \c void* cast, so that its value can be assigned directly
147 * to a pointer variable or used in pointer arithmetic without further casting in C. In a future
148 * avr-libc distribution this will be part of the standard API and will be implemented in a more formal
149 * manner.
150 *
151 * \note This macro is not available for all architectures.
152 *
153 * \param[in] Address Address of the pointer to read.
154 *
155 * \return Pointer retrieved from PROGMEM space.
156 */
157 #define pgm_read_ptr(Address) (void*)pgm_read_word(Address)
158 #endif
159 #elif (ARCH == ARCH_UC3)
160 #define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::)
161 #define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("breakpoint" ::)
162 #define JTAG_ASSERT(Condition) MACROS{ if (!(Condition)) { JTAG_DEBUG_BREAK(); } }MACROE
163 #define STDOUT_ASSERT(Condition) MACROS{ if (!(x)) { \
164 printf("%s: Function \"%s\", Line %d: " \
165 "Assertion \"%s\" failed.\r\n"), \
166 __FILE__, __func__, __LINE__, #Condition); } }MACROE
167 #endif
168
169 /* Disable C linkage for C++ Compilers: */
170 #if defined(__cplusplus)
171 }
172 #endif
173
174 #endif
175
176 /** @} */
177
Imprint / Impressum