My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * InterruptVectors_Due.cpp - This module relocates the Interrupt vector table to SRAM,
  24. * allowing to register new interrupt handlers at runtime. Specially valuable and needed
  25. * because Arduino runtime allocates some interrupt handlers that we NEED to override to
  26. * properly support extended functionality, as for example, USB host or USB device (MSD, MTP)
  27. * and custom serial port handlers, and we don't actually want to modify and/or recompile the
  28. * Arduino runtime. We just want to run as much as possible on Stock Arduino
  29. *
  30. * Copyright (c) 2017 Eduardo José Tagle. All right reserved
  31. */
  32. #ifdef ARDUINO_ARCH_SAM
  33. #include "../../inc/MarlinConfig.h"
  34. #include "HAL.h"
  35. #include "InterruptVectors.h"
  36. /* The relocated Exception/Interrupt Table - According to the ARM
  37. reference manual, alignment to 128 bytes should suffice, but in
  38. practice, we need alignment to 256 bytes to make this work in all
  39. cases */
  40. __attribute__ ((aligned(256)))
  41. static DeviceVectors ram_tab = { nullptr };
  42. /**
  43. * This function checks if the exception/interrupt table is already in SRAM or not.
  44. * If it is not, then it copies the ROM table to the SRAM and relocates the table
  45. * by reprogramming the NVIC registers
  46. */
  47. static pfnISR_Handler* get_relocated_table_addr() {
  48. // Get the address of the interrupt/exception table
  49. uint32_t isrtab = SCB->VTOR;
  50. // If already relocated, we are done!
  51. if (isrtab >= IRAM0_ADDR)
  52. return (pfnISR_Handler*)isrtab;
  53. // Get the address of the table stored in FLASH
  54. const pfnISR_Handler* romtab = (const pfnISR_Handler*)isrtab;
  55. // Copy it to SRAM
  56. memcpy(&ram_tab, romtab, sizeof(ram_tab));
  57. // Disable global interrupts
  58. CRITICAL_SECTION_START;
  59. // Set the vector table base address to the SRAM copy
  60. SCB->VTOR = (uint32_t)(&ram_tab);
  61. // Reenable interrupts
  62. CRITICAL_SECTION_END;
  63. // Return the address of the table
  64. return (pfnISR_Handler*)(&ram_tab);
  65. }
  66. pfnISR_Handler install_isr(IRQn_Type irq, pfnISR_Handler newHandler) {
  67. // Get the address of the relocated table
  68. pfnISR_Handler *isrtab = get_relocated_table_addr();
  69. // Disable global interrupts
  70. CRITICAL_SECTION_START;
  71. // Get the original handler
  72. pfnISR_Handler oldHandler = isrtab[irq + 16];
  73. // Install the new one
  74. isrtab[irq + 16] = newHandler;
  75. // Reenable interrupts
  76. CRITICAL_SECTION_END;
  77. // Return the original one
  78. return oldHandler;
  79. }
  80. #endif