Ver código fonte

Further cleanup of inline delays

Scott Lahteine 7 anos atrás
pai
commit
5ac226aa93
2 arquivos alterados com 47 adições e 36 exclusões
  1. 46
    33
      Marlin/src/core/macros.h
  2. 1
    3
      Marlin/src/module/temperature.cpp

+ 46
- 33
Marlin/src/core/macros.h Ver arquivo

@@ -50,45 +50,58 @@
50 50
   #define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20 on AVR
51 51
 #endif
52 52
 
53
-// Highly granular delays for step pulses, etc.
54
-#define DELAY_0_NOP NOOP
55
-#define DELAY_1_NOP __asm__("nop\n\t")
56
-#define DELAY_2_NOP do{ DELAY_1_NOP; DELAY_1_NOP; }while(0)
57
-#define DELAY_3_NOP do{ DELAY_1_NOP; DELAY_2_NOP; }while(0)
58
-#define DELAY_4_NOP do{ DELAY_1_NOP; DELAY_3_NOP; }while(0)
59
-#define DELAY_5_NOP do{ DELAY_1_NOP; DELAY_4_NOP; }while(0)
60
-
53
+// Processor-level delays for hardware interfaces
54
+#ifndef _NOP
55
+  #define _NOP() do { __asm__ volatile ("nop"); } while (0)
56
+#endif
61 57
 #define DELAY_NOPS(X) \
62 58
   switch (X) { \
63
-    case 20: DELAY_1_NOP; case 19: DELAY_1_NOP; \
64
-    case 18: DELAY_1_NOP; case 17: DELAY_1_NOP; \
65
-    case 16: DELAY_1_NOP; case 15: DELAY_1_NOP; \
66
-    case 14: DELAY_1_NOP; case 13: DELAY_1_NOP; \
67
-    case 12: DELAY_1_NOP; case 11: DELAY_1_NOP; \
68
-    case 10: DELAY_1_NOP; case 9:  DELAY_1_NOP; \
69
-    case 8:  DELAY_1_NOP; case 7:  DELAY_1_NOP; \
70
-    case 6:  DELAY_1_NOP; case 5:  DELAY_1_NOP; \
71
-    case 4:  DELAY_1_NOP; case 3:  DELAY_1_NOP; \
72
-    case 2:  DELAY_1_NOP; case 1:  DELAY_1_NOP; \
59
+    case 20: _NOP(); case 19: _NOP(); case 18: _NOP(); case 17: _NOP(); \
60
+    case 16: _NOP(); case 15: _NOP(); case 14: _NOP(); case 13: _NOP(); \
61
+    case 12: _NOP(); case 11: _NOP(); case 10: _NOP(); case  9: _NOP(); \
62
+    case  8: _NOP(); case  7: _NOP(); case  6: _NOP(); case  5: _NOP(); \
63
+    case  4: _NOP(); case  3: _NOP(); case  2: _NOP(); case  1: _NOP(); \
73 64
   }
65
+#define DELAY_0_NOP   NOOP
66
+#define DELAY_1_NOP   DELAY_NOPS( 1)
67
+#define DELAY_2_NOP   DELAY_NOPS( 2)
68
+#define DELAY_3_NOP   DELAY_NOPS( 3)
69
+#define DELAY_4_NOP   DELAY_NOPS( 4)
70
+#define DELAY_5_NOP   DELAY_NOPS( 5)
71
+#define DELAY_10_NOP  DELAY_NOPS(10)
72
+#define DELAY_20_NOP  DELAY_NOPS(20)
73
+
74
+#if CYCLES_PER_MICROSECOND <= 200
75
+  #define DELAY_100NS DELAY_NOPS((CYCLES_PER_MICROSECOND + 9) / 10)
76
+#else
77
+  #define DELAY_100NS DELAY_20_NOP
78
+#endif
74 79
 
75
-#define DELAY_10_NOP do{ DELAY_5_NOP;  DELAY_5_NOP;  }while(0)
76
-#define DELAY_20_NOP do{ DELAY_10_NOP; DELAY_10_NOP; }while(0)
77
-
78
-#if CYCLES_PER_MICROSECOND == 16
79
-  #define DELAY_1US do { DELAY_10_NOP; DELAY_5_NOP; DELAY_1_NOP; }while(0)
80
+// Microsecond delays for hardware interfaces
81
+#if CYCLES_PER_MICROSECOND <= 20
82
+  #define DELAY_1US DELAY_NOPS(CYCLES_PER_MICROSECOND)
83
+  #define DELAY_US(X) \
84
+    switch (X) { \
85
+      case 20: DELAY_1US; case 19: DELAY_1US; case 18: DELAY_1US; case 17: DELAY_1US; \
86
+      case 16: DELAY_1US; case 15: DELAY_1US; case 14: DELAY_1US; case 13: DELAY_1US; \
87
+      case 12: DELAY_1US; case 11: DELAY_1US; case 10: DELAY_1US; case  9: DELAY_1US; \
88
+      case  8: DELAY_1US; case  7: DELAY_1US; case  6: DELAY_1US; case  5: DELAY_1US; \
89
+      case  4: DELAY_1US; case  3: DELAY_1US; case  2: DELAY_1US; case  1: DELAY_1US; \
90
+    }
80 91
 #else
81
-  #define DELAY_1US DELAY_20_NOP
92
+  #define DELAY_US(X) delayMicroseconds(X) // May not be usable in CRITICAL_SECTION
93
+  #define DELAY_1US DELAY_US(1)
82 94
 #endif
83
-#define DELAY_2US  do{ DELAY_1US; DELAY_1US; }while(0)
84
-#define DELAY_3US  do{ DELAY_1US; DELAY_2US; }while(0)
85
-#define DELAY_4US  do{ DELAY_1US; DELAY_3US; }while(0)
86
-#define DELAY_5US  do{ DELAY_1US; DELAY_4US; }while(0)
87
-#define DELAY_6US  do{ DELAY_1US; DELAY_5US; }while(0)
88
-#define DELAY_7US  do{ DELAY_1US; DELAY_6US; }while(0)
89
-#define DELAY_8US  do{ DELAY_1US; DELAY_7US; }while(0)
90
-#define DELAY_9US  do{ DELAY_1US; DELAY_8US; }while(0)
91
-#define DELAY_10US do{ DELAY_1US; DELAY_9US; }while(0)
95
+#define DELAY_2US  DELAY_US( 2)
96
+#define DELAY_3US  DELAY_US( 3)
97
+#define DELAY_4US  DELAY_US( 4)
98
+#define DELAY_5US  DELAY_US( 5)
99
+#define DELAY_6US  DELAY_US( 6)
100
+#define DELAY_7US  DELAY_US( 7)
101
+#define DELAY_8US  DELAY_US( 8)
102
+#define DELAY_9US  DELAY_US( 9)
103
+#define DELAY_10US DELAY_US(10)
104
+#define DELAY_20US DELAY_US(20)
92 105
 
93 106
 // Remove compiler warning on an unused variable
94 107
 #define UNUSED(x) (void) (x)

+ 1
- 3
Marlin/src/module/temperature.cpp Ver arquivo

@@ -1632,9 +1632,7 @@ void Temperature::disable_all_heaters() {
1632 1632
 
1633 1633
     WRITE(MAX6675_SS, 0); // enable TT_MAX6675
1634 1634
 
1635
-    // ensure 100ns delay - a bit extra is fine
1636
-    asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz
1637
-    asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz
1635
+    DELAY_100NS;          // Ensure 100ns delay
1638 1636
 
1639 1637
     // Read a big-endian temperature value
1640 1638
     max6675_temp = 0;

Carregando…
Cancelar
Salvar