Add missing SVN eol-style property to ensure that source code line endings and conver...
[pub/USBasp.git] / LUFA / Common / ArchitectureSpecific.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2011.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2011 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) || defined(__DOXYGEN__)
67 /** Disables the AVR's JTAG bus in software, until a system reset. This will override the current JTAG
68 * status as set by the JTAGEN fuse, disabling JTAG debugging and reverting the JTAG pins back to GPIO
69 * mode.
70 *
71 * \note This macro is not available for all architectures.
72 */
73 #define JTAG_DISABLE() 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" (1 << JTD), \
82 "M" (_SFR_IO_ADDR(MCUCR)) \
83 : "r0"); \
84 }MACROE
85
86 /** Defines a volatile \c NOP statement which cannot be optimized out by the compiler, and thus can always
87 * be set as a breakpoint in the resulting code. Useful for debugging purposes, where the optimizer
88 * removes/reorders code to the point where break points cannot reliably be set.
89 *
90 * \note This macro is not available for all architectures.
91 */
92 #define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::)
93
94 /** Defines an explicit JTAG break point in the resulting binary via the assembly \c BREAK statement. When
95 * a JTAG is used, this causes the program execution to halt when reached until manually resumed.
96 *
97 * \note This macro is not available for all architectures.
98 */
99 #define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("break" ::)
100
101 /** Macro for testing condition "x" and breaking via \ref JTAG_DEBUG_BREAK() if the condition is false.
102 *
103 * \note This macro is not available for all architectures.
104 *
105 * \param[in] Condition Condition that will be evaluated.
106 */
107 #define JTAG_ASSERT(Condition) MACROS{ if (!(Condition)) { JTAG_DEBUG_BREAK(); } }MACROE
108
109 /** Macro for testing condition \c "x" and writing debug data to the stdout stream if \c false. The stdout stream
110 * must be pre-initialized before this macro is run and linked to an output device, such as the microcontroller's
111 * USART peripheral.
112 *
113 * The output takes the form "{FILENAME}: Function {FUNCTION NAME}, Line {LINE NUMBER}: Assertion {Condition} failed."
114 *
115 * \note This macro is not available for all architectures.
116 *
117 * \param[in] Condition Condition that will be evaluated,
118 */
119 #define STDOUT_ASSERT(Condition) MACROS{ if (!(x)) { printf_P(PSTR("%s: Function \"%s\", Line %d: " \
120 "Assertion \"%s\" failed.\r\n"), \
121 __FILE__, __func__, __LINE__, #Condition); } }MACROE
122
123 #if !defined(pgm_read_ptr) || defined(__DOXYGEN__)
124 /** Reads a pointer out of PROGMEM space on the AVR8 architecture. This is currently a wrapper for the
125 * avr-libc \c pgm_read_ptr() macro with a \c void* cast, so that its value can be assigned directly
126 * to a pointer variable or used in pointer arithmetic without further casting in C. In a future
127 * avr-libc distribution this will be part of the standard API and will be implemented in a more formal
128 * manner.
129 *
130 * \note This macro is not available for all architectures.
131 *
132 * \param[in] Address Address of the pointer to read.
133 *
134 * \return Pointer retrieved from PROGMEM space.
135 */
136 #define pgm_read_ptr(Address) (void*)pgm_read_word(Address)
137 #endif
138 #endif
139
140 /* Disable C linkage for C++ Compilers: */
141 #if defined(__cplusplus)
142 }
143 #endif
144
145 #endif
146
147 /** @} */
148