You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
8.3 KiB

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