Keyboard firmwares for Atmel AVR and Cortex-M
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.

ArchitectureSpecific.h 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 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 disclaims 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() do { \
  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. } while (0)
  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() do { \
  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. } while (0)
  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) do { \
  114. if (!(Condition)) \
  115. JTAG_DEBUG_BREAK(); \
  116. } while (0)
  117. /** Macro for testing condition \c "x" and writing debug data to the stdout stream if \c false. The stdout stream
  118. * must be pre-initialized before this macro is run and linked to an output device, such as the microcontroller's
  119. * USART peripheral.
  120. *
  121. * The output takes the form "{FILENAME}: Function {FUNCTION NAME}, Line {LINE NUMBER}: Assertion {Condition} failed."
  122. *
  123. * \note This macro is not available for all architectures.
  124. *
  125. * \param[in] Condition Condition that will be evaluated,
  126. */
  127. #define STDOUT_ASSERT(Condition) do { \
  128. if (!(Condition)) \
  129. printf_P(PSTR("%s: Function \"%s\", Line %d: " \
  130. "Assertion \"%s\" failed.\r\n"), \
  131. __FILE__, __func__, __LINE__, #Condition); \
  132. } while (0)
  133. #if !defined(pgm_read_ptr) || defined(__DOXYGEN__)
  134. /** Reads a pointer out of PROGMEM space on the AVR8 architecture. This is a wrapper for the avr-libc
  135. * \c pgm_read_word() macro with a \c void* cast, so that its value can be assigned directly to a
  136. * pointer variable or used in pointer arithmetic without further casting in C.
  137. *
  138. * \note This macro is not available for all architectures.
  139. *
  140. * \param[in] Address Address of the pointer to read.
  141. *
  142. * \return Pointer retrieved from PROGMEM space.
  143. */
  144. #define pgm_read_ptr(Address) (void*)pgm_read_word(Address)
  145. #endif
  146. #elif (ARCH == ARCH_UC3)
  147. #define JTAG_DEBUG_POINT() __asm__ __volatile__ ("nop" ::)
  148. #define JTAG_DEBUG_BREAK() __asm__ __volatile__ ("breakpoint" ::)
  149. #define JTAG_ASSERT(Condition) do { \
  150. if (!(Condition)) \
  151. JTAG_DEBUG_BREAK(); \
  152. } while (0)
  153. #define STDOUT_ASSERT(Condition) do { \
  154. if (!(Condition)) \
  155. printf("%s: Function \"%s\", Line %d: " \
  156. "Assertion \"%s\" failed.\r\n", \
  157. __FILE__, __func__, __LINE__, #Condition); \
  158. } while (0)
  159. #endif
  160. /* Disable C linkage for C++ Compilers: */
  161. #if defined(__cplusplus)
  162. }
  163. #endif
  164. #endif
  165. /** @} */