浏览代码

Move M100 to cpp

Scott Lahteine 7 年前
父节点
当前提交
5d2681a105
共有 3 个文件被更改,包括 23 次插入25 次删除
  1. 0
    8
      Marlin/src/Marlin.cpp
  2. 22
    13
      Marlin/src/gcode/calibrate/M100.cpp
  3. 1
    4
      Marlin/src/gcode/gcode.cpp

+ 0
- 8
Marlin/src/Marlin.cpp 查看文件

94
   #include "HAL/HAL_endstop_interrupts.h"
94
   #include "HAL/HAL_endstop_interrupts.h"
95
 #endif
95
 #endif
96
 
96
 
97
-#if ENABLED(M100_FREE_MEMORY_WATCHER)
98
-  void M100_dump_routine(const char * const title, const char *start, const char *end);
99
-#endif
100
-
101
 #if ENABLED(SDSUPPORT)
97
 #if ENABLED(SDSUPPORT)
102
   CardReader card;
98
   CardReader card;
103
 #endif
99
 #endif
359
   return false;
355
   return false;
360
 }
356
 }
361
 
357
 
362
-#if ENABLED(M100_FREE_MEMORY_WATCHER)
363
-  #include "gcode/calibrate/M100.h"
364
-#endif
365
-
366
 #include "gcode/host/M114.h"
358
 #include "gcode/host/M114.h"
367
 #include "gcode/host/M115.h"
359
 #include "gcode/host/M115.h"
368
 
360
 

Marlin/src/gcode/calibrate/M100.h → Marlin/src/gcode/calibrate/M100.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
+#include "../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(M100_FREE_MEMORY_WATCHER)
26
+
27
+#include "../gcode.h"
23
 #include "../../libs/hex_print_routines.h"
28
 #include "../../libs/hex_print_routines.h"
24
 
29
 
30
+#include "../../Marlin.h" // for idle()
31
+
25
 /**
32
 /**
26
  * M100 Free Memory Watcher
33
  * M100 Free Memory Watcher
27
  *
34
  *
72
 }
79
 }
73
 
80
 
74
 // Count the number of test bytes at the specified location.
81
 // Count the number of test bytes at the specified location.
75
-int16_t count_test_bytes(const char * const ptr) {
82
+inline int16_t count_test_bytes(const char * const ptr) {
76
   for (uint16_t i = 0; i < 32000; i++)
83
   for (uint16_t i = 0; i < 32000; i++)
77
     if (((char) ptr[i]) != TEST_BYTE)
84
     if (((char) ptr[i]) != TEST_BYTE)
78
       return i - 1;
85
       return i - 1;
94
    *  the block. If so, it may indicate memory corruption due to a bad pointer.
101
    *  the block. If so, it may indicate memory corruption due to a bad pointer.
95
    *  Unexpected bytes are flagged in the right column.
102
    *  Unexpected bytes are flagged in the right column.
96
    */
103
    */
97
-  void dump_free_memory(const char *ptr, const char *sp) {
104
+  inline void dump_free_memory(const char *ptr, const char *sp) {
98
     //
105
     //
99
     // Start and end the dump on a nice 16 byte boundary
106
     // Start and end the dump on a nice 16 byte boundary
100
     // (even though the values are not 16-byte aligned).
107
     // (even though the values are not 16-byte aligned).
101
     //
108
     //
102
-    ptr = (char *)((uint16_t)ptr & 0xFFF0); // Align to 16-byte boundary
103
-    sp  = (char *)((uint16_t)sp  | 0x000F); // Align sp to the 15th byte (at or above sp)
109
+    ptr = (char*)((ptr_int_t)((uint32_t)ptr & 0xFFFFFFF0)); // Align to 16-byte boundary
110
+    sp  = (char*)((ptr_int_t)((uint32_t)sp  | 0x0000000F)); // Align sp to the 15th byte (at or above sp)
104
 
111
 
105
     // Dump command main loop
112
     // Dump command main loop
106
     while (ptr < sp) {
113
     while (ptr < sp) {
107
-      print_hex_word((uint16_t)ptr);      // Print the address
114
+      print_hex_address(ptr);             // Print the address
108
       SERIAL_CHAR(':');
115
       SERIAL_CHAR(':');
109
       for (uint8_t i = 0; i < 16; i++) {  // and 16 data bytes
116
       for (uint8_t i = 0; i < 16; i++) {  // and 16 data bytes
110
         if (i == 8) SERIAL_CHAR('-');
117
         if (i == 8) SERIAL_CHAR('-');
135
     //
142
     //
136
     // Round the start and end locations to produce full lines of output
143
     // Round the start and end locations to produce full lines of output
137
     //
144
     //
138
-    start = (char*)((uint16_t) start & 0xFFF0);
139
-    end   = (char*)((uint16_t) end   | 0x000F);
145
+    start = (char*)((ptr_int_t)((uint32_t)start & 0xFFFFFFF0)); // Align to 16-byte boundary
146
+    end   = (char*)((ptr_int_t)((uint32_t)end   | 0x0000000F)); // Align sp to the 15th byte (at or above sp)
140
     dump_free_memory(start, end);
147
     dump_free_memory(start, end);
141
   }
148
   }
142
 
149
 
143
 #endif // M100_FREE_MEMORY_DUMPER
150
 #endif // M100_FREE_MEMORY_DUMPER
144
 
151
 
145
-int check_for_free_memory_corruption(const char * const title) {
152
+inline int check_for_free_memory_corruption(const char * const title) {
146
   SERIAL_ECHO(title);
153
   SERIAL_ECHO(title);
147
 
154
 
148
   char *ptr = END_OF_HEAP(), *sp = top_of_stack();
155
   char *ptr = END_OF_HEAP(), *sp = top_of_stack();
187
   }
194
   }
188
   SERIAL_ECHOPAIR("  block_found=", block_cnt);
195
   SERIAL_ECHOPAIR("  block_found=", block_cnt);
189
 
196
 
190
-  if (block_cnt != 1 || __brkval != 0x0000)
197
+  if (block_cnt != 1 || __brkval != NULL)
191
     SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
198
     SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
192
 
199
 
193
   if (block_cnt == 0)       // Make sure the special case of no free blocks shows up as an
200
   if (block_cnt == 0)       // Make sure the special case of no free blocks shows up as an
208
  *  Return the number of free bytes in the memory pool,
215
  *  Return the number of free bytes in the memory pool,
209
  *  with other vital statistics defining the pool.
216
  *  with other vital statistics defining the pool.
210
  */
217
  */
211
-void free_memory_pool_report(char * const ptr, const int16_t size) {
218
+inline void free_memory_pool_report(char * const ptr, const int16_t size) {
212
   int16_t max_cnt = -1, block_cnt = 0;
219
   int16_t max_cnt = -1, block_cnt = 0;
213
   char *max_addr = NULL;
220
   char *max_addr = NULL;
214
   // Find the longest block of test bytes in the buffer
221
   // Find the longest block of test bytes in the buffer
242
    *  Corrupt <num> locations in the free memory pool and report the corrupt addresses.
249
    *  Corrupt <num> locations in the free memory pool and report the corrupt addresses.
243
    *  This is useful to check the correctness of the M100 D and the M100 F commands.
250
    *  This is useful to check the correctness of the M100 D and the M100 F commands.
244
    */
251
    */
245
-  void corrupt_free_memory(char *ptr, const uint16_t size) {
252
+  inline void corrupt_free_memory(char *ptr, const uint16_t size) {
246
     ptr += 8;
253
     ptr += 8;
247
     const uint16_t near_top = top_of_stack() - ptr - 250, // -250 to avoid interrupt activity that's altered the stack.
254
     const uint16_t near_top = top_of_stack() - ptr - 250, // -250 to avoid interrupt activity that's altered the stack.
248
                    j = near_top / (size + 1);
255
                    j = near_top / (size + 1);
261
  * M100 I
268
  * M100 I
262
  *  Init memory for the M100 tests. (Automatically applied on the first M100.)
269
  *  Init memory for the M100 tests. (Automatically applied on the first M100.)
263
  */
270
  */
264
-void init_free_memory(char *ptr, int16_t size) {
271
+inline void init_free_memory(char *ptr, int16_t size) {
265
   SERIAL_ECHOLNPGM("Initializing free memory block.\n\n");
272
   SERIAL_ECHOLNPGM("Initializing free memory block.\n\n");
266
 
273
 
267
   size -= 250;    // -250 to avoid interrupt activity that's altered the stack.
274
   size -= 250;    // -250 to avoid interrupt activity that's altered the stack.
289
 /**
296
 /**
290
  * M100: Free Memory Check
297
  * M100: Free Memory Check
291
  */
298
  */
292
-void gcode_M100() {
299
+void GcodeSuite::M100() {
293
   SERIAL_ECHOPAIR("\n__brkval : ", hex_address(__brkval));
300
   SERIAL_ECHOPAIR("\n__brkval : ", hex_address(__brkval));
294
   SERIAL_ECHOPAIR("\n__bss_end : ", hex_address(&__bss_end));
301
   SERIAL_ECHOPAIR("\n__bss_end : ", hex_address(&__bss_end));
295
 
302
 
320
 
327
 
321
   #endif
328
   #endif
322
 }
329
 }
330
+
331
+#endif // M100_FREE_MEMORY_WATCHER

+ 1
- 4
Marlin/src/gcode/gcode.cpp 查看文件

116
 //
116
 //
117
 // Placeholders for non-migrated codes
117
 // Placeholders for non-migrated codes
118
 //
118
 //
119
-extern void gcode_M100();
120
 extern void gcode_M114();
119
 extern void gcode_M114();
121
 extern void gcode_M115();
120
 extern void gcode_M115();
122
 extern void gcode_M117();
121
 extern void gcode_M117();
424
       #endif
423
       #endif
425
 
424
 
426
       #if ENABLED(M100_FREE_MEMORY_WATCHER)
425
       #if ENABLED(M100_FREE_MEMORY_WATCHER)
427
-        case 100: // M100: Free Memory Report
428
-          gcode_M100();
429
-          break;
426
+        case 100: M100(); break;  // M100: Free Memory Report
430
       #endif
427
       #endif
431
 
428
 
432
       case 104: M104(); break;    // M104: Set hot end temperature
429
       case 104: M104(); break;    // M104: Set hot end temperature

正在加载...
取消
保存