Quellcode durchsuchen

🎨 Minor HAL cleanup

Scott Lahteine vor 3 Jahren
Ursprung
Commit
12da2e9288

+ 4
- 0
Marlin/src/HAL/AVR/HAL.cpp Datei anzeigen

@@ -88,6 +88,10 @@ void MarlinHAL::reboot() {
88 88
   #endif
89 89
 }
90 90
 
91
+// ------------------------
92
+// Free Memory Accessor
93
+// ------------------------
94
+
91 95
 #if ENABLED(SDSUPPORT)
92 96
 
93 97
   #include "../../sd/SdFatUtil.h"

+ 1
- 1
Marlin/src/HAL/AVR/HAL.h Datei anzeigen

@@ -167,7 +167,7 @@ typedef Servo hal_servo_t;
167 167
 #define strtof strtod
168 168
 
169 169
 // ------------------------
170
-// Class Utilities
170
+// Free Memory Accessor
171 171
 // ------------------------
172 172
 
173 173
 #pragma GCC diagnostic push

+ 12
- 3
Marlin/src/HAL/DUE/HAL.cpp Datei anzeigen

@@ -40,14 +40,15 @@ uint16_t MarlinHAL::adc_result;
40 40
 // Public functions
41 41
 // ------------------------
42 42
 
43
-TERN_(POSTMORTEM_DEBUGGING, extern void install_min_serial());
43
+#if ENABLED(POSTMORTEM_DEBUGGING)
44
+  extern void install_min_serial();
45
+#endif
44 46
 
45 47
 void MarlinHAL::init() {
46
-  // Initialize the USB stack
47 48
   #if ENABLED(SDSUPPORT)
48 49
     OUT_WRITE(SDSS, HIGH);  // Try to set SDSS inactive before any other SPI users start up
49 50
   #endif
50
-  usb_task_init();
51
+  usb_task_init();          // Initialize the USB stack
51 52
   TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler
52 53
 }
53 54
 
@@ -72,6 +73,10 @@ uint8_t MarlinHAL::get_reset_source() {
72 73
 
73 74
 void MarlinHAL::reboot() { rstc_start_software_reset(RSTC); }
74 75
 
76
+// ------------------------
77
+// Free Memory Accessor
78
+// ------------------------
79
+
75 80
 extern "C" {
76 81
   extern unsigned int _ebss; // end of bss section
77 82
 }
@@ -82,6 +87,10 @@ int freeMemory() {
82 87
   return (int)&free_memory - (heap_end ?: (int)&_ebss);
83 88
 }
84 89
 
90
+// ------------------------
91
+// Serial Ports
92
+// ------------------------
93
+
85 94
 // Forward the default serial ports
86 95
 #if USING_HW_SERIAL0
87 96
   DefaultSerial1 MSerial0(false, Serial);

+ 0
- 2
Marlin/src/HAL/DUE/HAL_SPI.cpp Datei anzeigen

@@ -31,8 +31,6 @@
31 31
 
32 32
 /**
33 33
  * HAL for Arduino Due and compatible (SAM3X8E)
34
- *
35
- * For ARDUINO_ARCH_SAM
36 34
  */
37 35
 
38 36
 #ifdef ARDUINO_ARCH_SAM

+ 1
- 0
Marlin/src/HAL/HAL.h Datei anzeigen

@@ -28,6 +28,7 @@
28 28
 #endif
29 29
 
30 30
 #include HAL_PATH(.,HAL.h)
31
+extern MarlinHAL hal;
31 32
 
32 33
 #define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
33 34
 

+ 1
- 1
Marlin/src/HAL/LPC1768/HAL.h Datei anzeigen

@@ -177,7 +177,7 @@ void flashFirmware(const int16_t);
177 177
 #define CPU_ST7920_DELAY_3 750
178 178
 
179 179
 // ------------------------
180
-// Class Utilities
180
+// Free Memory Accessor
181 181
 // ------------------------
182 182
 
183 183
 #pragma GCC diagnostic push

+ 1
- 1
Marlin/src/HAL/NATIVE_SIM/HAL.h Datei anzeigen

@@ -186,7 +186,7 @@ constexpr inline char* strstr_constexpr(char* str, const char* target) {
186 186
 }
187 187
 
188 188
 // ------------------------
189
-// Class Utilities
189
+// Free Memory Accessor
190 190
 // ------------------------
191 191
 
192 192
 #pragma GCC diagnostic push

+ 2
- 3
Marlin/src/HAL/STM32/HAL.cpp Datei anzeigen

@@ -24,12 +24,11 @@
24 24
 
25 25
 #ifdef HAL_STM32
26 26
 
27
-#include "HAL.h"
28
-#include "usb_serial.h"
29
-
30 27
 #include "../../inc/MarlinConfig.h"
31 28
 #include "../shared/Delay.h"
32 29
 
30
+#include "usb_serial.h"
31
+
33 32
 #ifdef USBCON
34 33
   DefaultSerial1 MSerialUSB(false, SerialUSB);
35 34
 #endif

+ 7
- 2
Marlin/src/HAL/STM32F1/HAL.cpp Datei anzeigen

@@ -83,6 +83,7 @@
83 83
 // ------------------------
84 84
 
85 85
 #if defined(SERIAL_USB) && !HAS_SD_HOST_DRIVE
86
+
86 87
   USBSerial SerialUSB;
87 88
   DefaultSerial1 MSerial0(true, SerialUSB);
88 89
 
@@ -211,6 +212,10 @@ void MarlinHAL::idletask() {
211 212
 
212 213
 void MarlinHAL::reboot() { nvic_sys_reset(); }
213 214
 
215
+// ------------------------
216
+// Free Memory Accessor
217
+// ------------------------
218
+
214 219
 extern "C" {
215 220
   extern unsigned int _ebss; // end of bss section
216 221
 }
@@ -243,9 +248,9 @@ extern "C" {
243 248
 }
244 249
 */
245 250
 
246
-//
251
+// ------------------------
247 252
 // ADC
248
-//
253
+// ------------------------
249 254
 
250 255
 enum ADCIndex : uint8_t {
251 256
   OPTITEM(HAS_TEMP_ADC_0, TEMP_0)

+ 21
- 19
Marlin/src/HAL/TEENSY31_32/HAL.cpp Datei anzeigen

@@ -45,25 +45,6 @@
45 45
 USBSerialType USBSerial(false, SerialUSB);
46 46
 
47 47
 // ------------------------
48
-// Class Utilities
49
-// ------------------------
50
-
51
-extern "C" {
52
-  extern char __bss_end;
53
-  extern char __heap_start;
54
-  extern void* __brkval;
55
-
56
-  int freeMemory() {
57
-    int free_memory;
58
-    if ((int)__brkval == 0)
59
-      free_memory = ((int)&free_memory) - ((int)&__bss_end);
60
-    else
61
-      free_memory = ((int)&free_memory) - ((int)__brkval);
62
-    return free_memory;
63
-  }
64
-}
65
-
66
-// ------------------------
67 48
 // MarlinHAL Class
68 49
 // ------------------------
69 50
 
@@ -81,7 +62,9 @@ uint8_t MarlinHAL::get_reset_source() {
81 62
   return 0;
82 63
 }
83 64
 
65
+// ------------------------
84 66
 // ADC
67
+// ------------------------
85 68
 
86 69
 void MarlinHAL::adc_init() {
87 70
   analog_init();
@@ -102,4 +85,23 @@ void MarlinHAL::adc_start(const pin_t pin) {
102 85
 
103 86
 uint16_t MarlinHAL::adc_value() { return ADC0_RA; }
104 87
 
88
+// ------------------------
89
+// Free Memory Accessor
90
+// ------------------------
91
+
92
+extern "C" {
93
+  extern char __bss_end;
94
+  extern char __heap_start;
95
+  extern void* __brkval;
96
+
97
+  int freeMemory() {
98
+    int free_memory;
99
+    if ((int)__brkval == 0)
100
+      free_memory = ((int)&free_memory) - ((int)&__bss_end);
101
+    else
102
+      free_memory = ((int)&free_memory) - ((int)__brkval);
103
+    return free_memory;
104
+  }
105
+}
106
+
105 107
 #endif // __MK20DX256__

+ 21
- 21
Marlin/src/HAL/TEENSY35_36/HAL.cpp Datei anzeigen

@@ -44,32 +44,11 @@
44 44
 USBSerialType USBSerial(false, SerialUSB);
45 45
 
46 46
 // ------------------------
47
-// Class Utilities
48
-// ------------------------
49
-
50
-extern "C" {
51
-  extern char __bss_end;
52
-  extern char __heap_start;
53
-  extern void* __brkval;
54
-
55
-  int freeMemory() {
56
-    int free_memory;
57
-    if ((int)__brkval == 0)
58
-      free_memory = ((int)&free_memory) - ((int)&__bss_end);
59
-    else
60
-      free_memory = ((int)&free_memory) - ((int)__brkval);
61
-    return free_memory;
62
-  }
63
-}
64
-
65
-// ------------------------
66 47
 // MarlinHAL Class
67 48
 // ------------------------
68 49
 
69 50
 void MarlinHAL::reboot() { _reboot_Teensyduino_(); }
70 51
 
71
-// Reset
72
-
73 52
 uint8_t MarlinHAL::get_reset_source() {
74 53
   switch (RCM_SRS0) {
75 54
     case 128: return RST_POWER_ON; break;
@@ -82,7 +61,9 @@ uint8_t MarlinHAL::get_reset_source() {
82 61
   return 0;
83 62
 }
84 63
 
64
+// ------------------------
85 65
 // ADC
66
+// ------------------------
86 67
 
87 68
 int8_t MarlinHAL::adc_select;
88 69
 
@@ -131,4 +112,23 @@ uint16_t MarlinHAL::adc_value() {
131 112
   return 0;
132 113
 }
133 114
 
115
+// ------------------------
116
+// Free Memory Accessor
117
+// ------------------------
118
+
119
+extern "C" {
120
+  extern char __bss_end;
121
+  extern char __heap_start;
122
+  extern void* __brkval;
123
+
124
+  int freeMemory() {
125
+    int free_memory;
126
+    if ((int)__brkval == 0)
127
+      free_memory = ((int)&free_memory) - ((int)&__bss_end);
128
+    else
129
+      free_memory = ((int)&free_memory) - ((int)__brkval);
130
+    return free_memory;
131
+  }
132
+}
133
+
134 134
 #endif // __MK64FX512__ || __MK66FX1M0__

+ 1
- 1
Marlin/src/HAL/TEENSY35_36/HAL.h Datei anzeigen

@@ -118,7 +118,7 @@ typedef int8_t pin_t;
118 118
 #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
119 119
 
120 120
 // ------------------------
121
-// Class Utilities
121
+// Free Memory Accessor
122 122
 // ------------------------
123 123
 
124 124
 #pragma GCC diagnostic push

+ 21
- 19
Marlin/src/HAL/TEENSY40_41/HAL.cpp Datei anzeigen

@@ -45,25 +45,6 @@
45 45
 USBSerialType USBSerial(false, SerialUSB);
46 46
 
47 47
 // ------------------------
48
-// Class Utilities
49
-// ------------------------
50
-
51
-#define __bss_end _ebss
52
-
53
-extern "C" {
54
-  extern char __bss_end;
55
-  extern char __heap_start;
56
-  extern void* __brkval;
57
-
58
-  // Doesn't work on Teensy 4.x
59
-  uint32_t freeMemory() {
60
-    uint32_t free_memory;
61
-    free_memory = ((uint32_t)&free_memory) - (((uint32_t)__brkval) ?: ((uint32_t)&__bss_end));
62
-    return free_memory;
63
-  }
64
-}
65
-
66
-// ------------------------
67 48
 // FastIO
68 49
 // ------------------------
69 50
 
@@ -97,7 +78,9 @@ void MarlinHAL::clear_reset_source() {
97 78
   SRC_SRSR = reset_source;
98 79
 }
99 80
 
81
+// ------------------------
100 82
 // ADC
83
+// ------------------------
101 84
 
102 85
 int8_t MarlinHAL::adc_select;
103 86
 
@@ -180,4 +163,23 @@ uint16_t MarlinHAL::adc_value() {
180 163
   return 0;
181 164
 }
182 165
 
166
+// ------------------------
167
+// Free Memory Accessor
168
+// ------------------------
169
+
170
+#define __bss_end _ebss
171
+
172
+extern "C" {
173
+  extern char __bss_end;
174
+  extern char __heap_start;
175
+  extern void* __brkval;
176
+
177
+  // Doesn't work on Teensy 4.x
178
+  uint32_t freeMemory() {
179
+    uint32_t free_memory;
180
+    free_memory = ((uint32_t)&free_memory) - (((uint32_t)__brkval) ?: ((uint32_t)&__bss_end));
181
+    return free_memory;
182
+  }
183
+}
184
+
183 185
 #endif // __IMXRT1062__

+ 1
- 1
Marlin/src/HAL/TEENSY40_41/HAL.h Datei anzeigen

@@ -140,7 +140,7 @@ typedef int8_t pin_t;
140 140
 bool is_output(pin_t pin);
141 141
 
142 142
 // ------------------------
143
-// Class Utilities
143
+// Free Memory Accessor
144 144
 // ------------------------
145 145
 
146 146
 #pragma GCC diagnostic push

+ 0
- 1
Marlin/src/inc/MarlinConfig.h Datei anzeigen

@@ -29,7 +29,6 @@
29 29
 
30 30
 #ifndef __MARLIN_DEPS__
31 31
   #include "../HAL/HAL.h"
32
-  extern MarlinHAL hal;
33 32
 #endif
34 33
 
35 34
 #include "../pins/pins.h"

Laden…
Abbrechen
Speichern