diff options
Diffstat (limited to 'lib/lufa/LUFA/Common/ArchitectureSpecific.h')
| -rw-r--r-- | lib/lufa/LUFA/Common/ArchitectureSpecific.h | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/lib/lufa/LUFA/Common/ArchitectureSpecific.h b/lib/lufa/LUFA/Common/ArchitectureSpecific.h new file mode 100644 index 000000000..28f2900b9 --- /dev/null +++ b/lib/lufa/LUFA/Common/ArchitectureSpecific.h | |||
| @@ -0,0 +1,185 @@ | |||
| 1 | /* | ||
| 2 | LUFA Library | ||
| 3 | Copyright (C) Dean Camera, 2017. | ||
| 4 | |||
| 5 | dean [at] fourwalledcubicle [dot] com | ||
| 6 | www.lufa-lib.org | ||
| 7 | */ | ||
| 8 | |||
| 9 | /* | ||
| 10 | Copyright 2017 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 disclaims 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() do { \ | ||
| 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 | } while (0) | ||
| 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() do { \ | ||
| 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 | } while (0) | ||
| 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) do { \ | ||
| 128 | if (!(Condition)) \ | ||
| 129 | JTAG_DEBUG_BREAK(); \ | ||
| 130 | } while (0) | ||
| 131 | |||
| 132 | /** Macro for testing condition \c "x" and writing debug data to the stdout stream if \c false. The stdout stream | ||
| 133 | * must be pre-initialized before this macro is run and linked to an output device, such as the microcontroller's | ||
| 134 | * USART peripheral. | ||
| 135 | * | ||
| 136 | * The output takes the form "{FILENAME}: Function {FUNCTION NAME}, Line {LINE NUMBER}: Assertion {Condition} failed." | ||
| 137 | * | ||
| 138 | * \note This macro is not available for all architectures. | ||
| 139 | * | ||
| 140 | * \param[in] Condition Condition that will be evaluated, | ||
| 141 | */ | ||
| 142 | #define STDOUT_ASSERT(Condition) do { \ | ||
| 143 | if (!(Condition)) \ | ||
| 144 | printf_P(PSTR("%s: Function \"%s\", Line %d: " \ | ||
| 145 | "Assertion \"%s\" failed.\r\n"), \ | ||
| 146 | __FILE__, __func__, __LINE__, #Condition); \ | ||
| 147 | } while (0) | ||
| 148 | |||
| 149 | #if !defined(pgm_read_ptr) || defined(__DOXYGEN__) | ||
| 150 | /** Reads a pointer out of PROGMEM space on the AVR8 architecture. This is a wrapper for the avr-libc | ||
| 151 | * \c pgm_read_word() macro with a \c void* cast, so that its value can be assigned directly to a | ||
| 152 | * pointer variable or used in pointer arithmetic without further casting in C. | ||
| 153 | * | ||
| 154 | * \note This macro is not available for all architectures. | ||
| 155 | * | ||
| 156 | * \param[in] Address Address of the pointer to read. | ||
| 157 | * | ||
| 158 | * \return Pointer retrieved from PROGMEM space. | ||
| 159 | */ | ||
| 160 | #define pgm_read_ptr(Address) (void*)pgm_read_word(Address) | ||
| 161 | #endif | ||
| 162 | #elif (ARCH == ARCH_UC3) | ||
| 163 | #define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::) | ||
| 164 | #define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("breakpoint" ::) | ||
| 165 | #define JTAG_ASSERT(Condition) do { \ | ||
| 166 | if (!(Condition)) \ | ||
| 167 | JTAG_DEBUG_BREAK(); \ | ||
| 168 | } while (0) | ||
| 169 | #define STDOUT_ASSERT(Condition) do { \ | ||
| 170 | if (!(Condition)) \ | ||
| 171 | printf("%s: Function \"%s\", Line %d: " \ | ||
| 172 | "Assertion \"%s\" failed.\r\n", \ | ||
| 173 | __FILE__, __func__, __LINE__, #Condition); \ | ||
| 174 | } while (0) | ||
| 175 | #endif | ||
| 176 | |||
| 177 | /* Disable C linkage for C++ Compilers: */ | ||
| 178 | #if defined(__cplusplus) | ||
| 179 | } | ||
| 180 | #endif | ||
| 181 | |||
| 182 | #endif | ||
| 183 | |||
| 184 | /** @} */ | ||
| 185 | |||
