My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

dyn_SWI.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * File: dyn_SWI.h
  3. * Author: xxxajk@gmail.com
  4. *
  5. * Created on December 5, 2014, 9:12 AM
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef DYN_SWI_H
  21. #define DYN_SWI_H
  22. #if defined(__arm__) || defined(ARDUINO_ARCH_PIC32)
  23. #ifdef ARDUINO_ARCH_PIC32
  24. #include <p32xxxx.h>
  25. #endif
  26. #ifdef __cplusplus
  27. #ifdef true
  28. #undef true
  29. #endif
  30. #ifdef false
  31. #undef false
  32. #endif
  33. #endif
  34. #ifdef ARDUINO_spresense_ast
  35. #define SWI_IRQ_NUM 666 // because this board is totally evil.
  36. #elif defined(ARDUINO_ARCH_PIC32)
  37. #ifndef SWI_IRQ_NUM
  38. #ifdef _DSPI0_IPL_ISR
  39. #define SWI_IPL _DSPI0_IPL_ISR
  40. #define SWI_VECTOR _DSPI0_ERR_IRQ
  41. #define SWI_IRQ_NUM _DSPI0_ERR_IRQ
  42. #elif defined(_PMP_ERROR_IRQ)
  43. #define SWI_IRQ_NUM _PMP_ERROR_IRQ
  44. #define SWI_VECTOR _PMP_VECTOR
  45. #else
  46. #error SWI_IRQ_NUM and SWI_VECTOR need a definition
  47. #endif
  48. #ifdef __cplusplus
  49. extern "C"
  50. {
  51. void
  52. #ifdef __PIC32MZXX__
  53. __attribute__((nomips16,at_vector(SWI_VECTOR),interrupt(SWI_IPL)))
  54. #else
  55. __attribute__((interrupt(),nomips16))
  56. #endif
  57. softISR();
  58. }
  59. #endif
  60. #endif
  61. #elif !defined(NVIC_NUM_INTERRUPTS)
  62. // Assume CMSIS
  63. #define __USE_CMSIS_VECTORS__
  64. #ifdef NUMBER_OF_INT_VECTORS
  65. #define NVIC_NUM_INTERRUPTS (NUMBER_OF_INT_VECTORS-16)
  66. #else
  67. #define NVIC_NUM_INTERRUPTS ((int)PERIPH_COUNT_IRQn)
  68. #endif
  69. #define VECTORTABLE_SIZE (NVIC_NUM_INTERRUPTS+16)
  70. #define VECTORTABLE_ALIGNMENT (0x100UL)
  71. #define NVIC_GET_ACTIVE(n) NVIC_GetActive((IRQn_Type)n)
  72. #define NVIC_GET_PENDING(n) NVIC_GetPendingIRQ((IRQn_Type)n)
  73. #define NVIC_SET_PENDING(n) NVIC_SetPendingIRQ((IRQn_Type)n)
  74. #define NVIC_ENABLE_IRQ(n) NVIC_EnableIRQ((IRQn_Type)n)
  75. #define NVIC_SET_PRIORITY(n ,p) NVIC_SetPriority((IRQn_Type)n, (uint32_t) p)
  76. //extern "C" {
  77. // extern uint32_t _VectorsRam[VECTORTABLE_SIZE] __attribute__((aligned(VECTORTABLE_ALIGNMENT)));
  78. //}
  79. #ifndef SWI_IRQ_NUM
  80. #if defined(__SAM3X8E__) && defined(_VARIANT_ARDUINO_DUE_X_)
  81. // DUE
  82. // Choices available:
  83. // HSMCI_IRQn Multimedia Card Interface (HSMCI)
  84. // EMAC_IRQn Ethernet MAC (EMAC)
  85. // EMAC is not broken out on the official DUE, but is on clones.
  86. // SPI0_IRQn Serial Peripheral Interface (SPI0)
  87. // SPI0_IRQn seems to be the best choice, as long as nobody uses an ISR based master
  88. #define SWI_IRQ_NUM SPI0_IRQn
  89. #elif defined(ARDUINO_SAMD_ZERO)
  90. // Just use sercom4's unused IRQ vector.
  91. #define SWI_IRQ_NUM I2S_IRQn
  92. //#define SWI_IRQ_NUM SERCOM4_IRQn
  93. #endif
  94. #endif
  95. #ifndef SWI_IRQ_NUM
  96. #error SWI_IRQ_NUM not defined (CMSIS)
  97. #endif
  98. #elif defined(CORE_TEENSY)
  99. #ifndef NVIC_GET_ACTIVE
  100. #define NVIC_GET_ACTIVE(n) (*((volatile uint32_t *)0xE000E300 + ((n) >> 5)) & (1 << ((n) & 31)))
  101. #endif
  102. #ifndef NVIC_GET_PENDING
  103. #define NVIC_GET_PENDING(n) (*((volatile uint32_t *)0xE000E200 + ((n) >> 5)) & (1 << ((n) & 31)))
  104. #ifndef SWI_IRQ_NUM
  105. #ifdef __MK20DX256__
  106. #define SWI_IRQ_NUM 17
  107. #elif defined(__MK20DX128__)
  108. #define SWI_IRQ_NUM 5
  109. #elif defined(__MKL26Z64__)
  110. #define SWI_IRQ_NUM 4
  111. #elif defined(__MK66FX1M0__)
  112. #define SWI_IRQ_NUM 30
  113. #elif defined(__MK64FX512__)
  114. #define SWI_IRQ_NUM 30
  115. #elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
  116. #define SWI_IRQ_NUM 71
  117. #else
  118. #error Do not know how to relocate IRQ vectors for this pjrc product
  119. #endif
  120. #endif
  121. #endif
  122. #else // Not CMSIS or PJRC CORE_TEENSY or PIC32 or SPRESENSE
  123. #error Do not know how to relocate IRQ vectors or perform SWI
  124. #endif // SWI_IRQ_NUM
  125. #ifndef SWI_IRQ_NUM
  126. #error SWI_IRQ_NUM not defined
  127. #else
  128. /**
  129. * Use this class to extend your class, in order to provide
  130. * a C++ context callable SWI.
  131. */
  132. class dyn_SWI {
  133. public:
  134. /**
  135. * Override this method with your code.
  136. */
  137. virtual void dyn_SWISR() {
  138. };
  139. };
  140. extern int exec_SWI(const dyn_SWI* klass);
  141. #include "SWI_INLINE.h"
  142. // IMPORTANT! Define this so that you do NOT end up with a NULL stub!
  143. #define SWI_NO_STUB
  144. #endif /* SWI_IRQ_NUM */
  145. #endif /* __arm__ */
  146. // if no SWI for CPU (e.g. AVR) make a void stub.
  147. #ifndef SWI_NO_STUB
  148. #define Init_dyn_SWI() (void(0))
  149. #ifndef DDSB
  150. #define DDSB() (void(0))
  151. #endif
  152. #endif
  153. #endif /* DYN_SWI_H */