3      Copyright (C) Dean Camera, 2014. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2014  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  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. 
  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 
  32  *  \brief Architecture specific definitions relating to specific processor architectures. 
  34  *  \copydetails Group_ArchitectureSpecific 
  36  *  \note Do not include this file directly, rather include the Common.h header file instead to gain this file's 
  40 /** \ingroup Group_Common 
  41  *  \defgroup Group_ArchitectureSpecific Architecture Specific Definitions 
  42  *  \brief Architecture specific definitions relating to specific processor architectures. 
  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. 
  51 #ifndef __LUFA_ARCHSPEC_H__ 
  52 #define __LUFA_ARCHSPEC_H__ 
  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. 
  59         /* Enable C linkage for C++ Compilers: */ 
  60                 #if defined(__cplusplus) 
  64         /* Public Interface - May be used in end-application: */ 
  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(). 
  71                                          *  \note This macro is not available for all architectures. 
  73                                         #define JTAG_ENABLE()                  MACROS{                                       \ 
  74                                                                                                                                         __asm__ __volatile__ (               \ 
  75                                                                                                                                         "in __tmp_reg__,__SREG__" "\n\t"     \ 
  78                                                                                                                                         "out __SREG__, __tmp_reg__" "\n\t"   \ 
  81                                                                                                                                         : "r" (MCUCR & ~(1 << JTD)),         \ 
  82                                                                                                                                           "M" (_SFR_IO_ADDR(MCUCR))          \ 
  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 
  90                                          *  \note This macro is not available for all architectures. 
  92                                         #define JTAG_DISABLE()                  MACROS{                                      \ 
  93                                                                                                                                         __asm__ __volatile__ (               \ 
  94                                                                                                                                         "in __tmp_reg__,__SREG__" "\n\t"     \ 
  97                                                                                                                                         "out __SREG__, __tmp_reg__" "\n\t"   \ 
 100                                                                                                                                         : "r" (MCUCR | (1 << JTD)),          \ 
 101                                                                                                                                           "M" (_SFR_IO_ADDR(MCUCR))          \ 
 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. 
 110                                  *  \note This macro is not available for all architectures. 
 112                                 #define JTAG_DEBUG_POINT()              __asm__ __volatile__ ("nop" ::) 
 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. 
 117                                  *  \note This macro is not available for all architectures. 
 119                                 #define JTAG_DEBUG_BREAK()              __asm__ __volatile__ ("break" ::) 
 121                                 /** Macro for testing condition "x" and breaking via \ref JTAG_DEBUG_BREAK() if the condition is false. 
 123                                  *  \note This macro is not available for all architectures. 
 125                                  *  \param[in] Condition  Condition that will be evaluated. 
 127                                 #define JTAG_ASSERT(Condition)          MACROS{ if (!(Condition)) { JTAG_DEBUG_BREAK(); } }MACROE 
 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 
 133                                  *  The output takes the form "{FILENAME}: Function {FUNCTION NAME}, Line {LINE NUMBER}: Assertion {Condition} failed." 
 135                                  *  \note This macro is not available for all architectures. 
 137                                  *  \param[in] Condition  Condition that will be evaluated, 
 139                                 #define STDOUT_ASSERT(Condition)        MACROS{ if (!(Condition)) {                                     \ 
 140                                                                                      printf_P(PSTR("%s: Function \"%s\", Line %d: "     \ 
 141                                                                                                    "Assertion \"%s\" failed.\r\n"),     \ 
 142                                                                                                    __FILE__, __func__, __LINE__, #Condition); } }MACROE 
 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_word() 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 
 151                                          *  \note This macro is not available for all architectures. 
 153                                          *  \param[in] Address  Address of the pointer to read. 
 155                                          *  \return Pointer retrieved from PROGMEM space. 
 157                                         #define pgm_read_ptr(Address)        (void*)pgm_read_word(Address) 
 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 (!(Condition)) {                              \ 
 164                                                                                      printf("%s: Function \"%s\", Line %d: "     \ 
 165                                                                                             "Assertion \"%s\" failed.\r\n"),     \ 
 166                                                                                             __FILE__, __func__, __LINE__, #Condition); } }MACROE 
 169         /* Disable C linkage for C++ Compilers: */ 
 170                 #if defined(__cplusplus)