Browse Source

Minor M100 cleanup

Scott Lahteine 5 years ago
parent
commit
04715e04ee
2 changed files with 24 additions and 33 deletions
  1. 23
    32
      Marlin/src/gcode/calibrate/M100.cpp
  2. 1
    1
      Marlin/src/gcode/gcode.cpp

+ 23
- 32
Marlin/src/gcode/calibrate/M100.cpp View File

51
  * Also, there are two support functions that can be called from a developer's C code.
51
  * Also, there are two support functions that can be called from a developer's C code.
52
  *
52
  *
53
  *    uint16_t check_for_free_memory_corruption(PGM_P const free_memory_start);
53
  *    uint16_t check_for_free_memory_corruption(PGM_P const free_memory_start);
54
- *    void M100_dump_routine(PGM_P const title, const char *start, const char *end);
54
+ *    void M100_dump_routine(PGM_P const title, char *start, char *end);
55
  *
55
  *
56
  * Initial version by Roxy-3D
56
  * Initial version by Roxy-3D
57
  */
57
  */
63
 #if defined(__AVR__) || IS_32BIT_TEENSY
63
 #if defined(__AVR__) || IS_32BIT_TEENSY
64
 
64
 
65
   extern char __bss_end;
65
   extern char __bss_end;
66
-  char* end_bss =  &__bss_end;
67
-  char* free_memory_start = end_bss;
68
-
69
-
70
-  char* free_memory_end = 0;
71
-  char* stacklimit = 0;
72
-  char* heaplimit = 0;
66
+  char *end_bss = &__bss_end,
67
+       *free_memory_start = end_bss, *free_memory_end = 0,
68
+       *stacklimit = 0, *heaplimit = 0;
73
 
69
 
74
   #define MEMORY_END_CORRECTION 0
70
   #define MEMORY_END_CORRECTION 0
75
 
71
 
76
 #elif defined(TARGET_LPC1768)
72
 #elif defined(TARGET_LPC1768)
77
 
73
 
78
-  extern char   __bss_end__;
79
-  extern char   __StackLimit;
80
-  extern char   __HeapLimit;
74
+  extern char __bss_end__, __StackLimit, __HeapLimit;
81
 
75
 
82
-  char* end_bss =  &__bss_end__;
83
-  char* stacklimit =  &__StackLimit;
84
-  char* heaplimit =  &__HeapLimit ;
76
+  char *end_bss = &__bss_end__,
77
+       *stacklimit = &__StackLimit,
78
+       *heaplimit = &__HeapLimit ;
85
 
79
 
86
   #define MEMORY_END_CORRECTION 0x200
80
   #define MEMORY_END_CORRECTION 0x200
87
 
81
 
88
-  char* free_memory_start = heaplimit;
89
-  char* free_memory_end = stacklimit - MEMORY_END_CORRECTION;
90
-
82
+  char *free_memory_start = heaplimit,
83
+       *free_memory_end = stacklimit - MEMORY_END_CORRECTION;
91
 
84
 
92
 #elif defined(__SAM3X8E__)
85
 #elif defined(__SAM3X8E__)
93
 
86
 
94
-  extern char   _ebss;
95
-
96
-  char* end_bss = &_ebss;
97
-
98
-  char* free_memory_start = end_bss;
87
+  extern char _ebss;
99
 
88
 
100
-  char* free_memory_end = 0;
101
-  char* stacklimit = 0;
102
-  char* heaplimit = 0;
89
+  char *end_bss = &_ebss,
90
+       *free_memory_start = end_bss,
91
+       *free_memory_end = 0,
92
+       *stacklimit = 0,
93
+       *heaplimit = 0;
103
 
94
 
104
   #define MEMORY_END_CORRECTION 0x10000  // need to stay well below 0x20080000 or M100 F crashes
95
   #define MEMORY_END_CORRECTION 0x10000  // need to stay well below 0x20080000 or M100 F crashes
105
 
96
 
141
    *  the block. If so, it may indicate memory corruption due to a bad pointer.
132
    *  the block. If so, it may indicate memory corruption due to a bad pointer.
142
    *  Unexpected bytes are flagged in the right column.
133
    *  Unexpected bytes are flagged in the right column.
143
    */
134
    */
144
-  inline void dump_free_memory(const char *start_free_memory, const char *end_free_memory) {
135
+  inline void dump_free_memory(char *start_free_memory, char *end_free_memory) {
145
     //
136
     //
146
     // Start and end the dump on a nice 16 byte boundary
137
     // Start and end the dump on a nice 16 byte boundary
147
     // (even though the values are not 16-byte aligned).
138
     // (even though the values are not 16-byte aligned).
162
       SERIAL_CHAR('|');                   // Point out non test bytes
153
       SERIAL_CHAR('|');                   // Point out non test bytes
163
       for (uint8_t i = 0; i < 16; i++) {
154
       for (uint8_t i = 0; i < 16; i++) {
164
         char ccc = (char)start_free_memory[i]; // cast to char before automatically casting to char on assignment, in case the compiler is broken
155
         char ccc = (char)start_free_memory[i]; // cast to char before automatically casting to char on assignment, in case the compiler is broken
165
-        if (&start_free_memory[i] >= (const char*)command_queue && &start_free_memory[i] < (const char*)(command_queue + sizeof(command_queue))) { // Print out ASCII in the command buffer area
156
+        if (&start_free_memory[i] >= (char*)command_queue && &start_free_memory[i] < (char*)command_queue + sizeof(command_queue)) { // Print out ASCII in the command buffer area
166
           if (!WITHIN(ccc, ' ', 0x7E)) ccc = ' ';
157
           if (!WITHIN(ccc, ' ', 0x7E)) ccc = ' ';
167
         }
158
         }
168
         else { // If not in the command buffer area, flag bytes that don't match the test byte
159
         else { // If not in the command buffer area, flag bytes that don't match the test byte
177
     }
168
     }
178
   }
169
   }
179
 
170
 
180
-  void M100_dump_routine(PGM_P const title, const char *start, const char *end) {
171
+  void M100_dump_routine(PGM_P const title, char *start, char *end) {
181
     serialprintPGM(title);
172
     serialprintPGM(title);
182
     SERIAL_EOL();
173
     SERIAL_EOL();
183
     //
174
     //
198
 
189
 
199
   SERIAL_ECHOPAIR("\nfmc() n=", n);
190
   SERIAL_ECHOPAIR("\nfmc() n=", n);
200
   SERIAL_ECHOPAIR("\nfree_memory_start=", hex_address(free_memory_start));
191
   SERIAL_ECHOPAIR("\nfree_memory_start=", hex_address(free_memory_start));
201
-  SERIAL_ECHOLNPAIR("  end_free_memory=",          hex_address(end_free_memory));
192
+  SERIAL_ECHOLNPAIR("  end_free_memory=", hex_address(end_free_memory));
202
 
193
 
203
   if (end_free_memory < start_free_memory)  {
194
   if (end_free_memory < start_free_memory)  {
204
     SERIAL_ECHOPGM(" end_free_memory < Heap ");
195
     SERIAL_ECHOPGM(" end_free_memory < Heap ");
340
   char *sp = top_of_stack();
331
   char *sp = top_of_stack();
341
   if (!free_memory_end) free_memory_end = sp - MEMORY_END_CORRECTION;
332
   if (!free_memory_end) free_memory_end = sp - MEMORY_END_CORRECTION;
342
   SERIAL_ECHOPAIR("\nbss_end               : ", hex_address(end_bss));
333
   SERIAL_ECHOPAIR("\nbss_end               : ", hex_address(end_bss));
343
-  if (heaplimit) SERIAL_ECHOPAIR("\n__heaplimit           : ", hex_address(heaplimit ));
334
+  if (heaplimit) SERIAL_ECHOPAIR("\n__heaplimit           : ", hex_address(heaplimit));
344
   SERIAL_ECHOPAIR("\nfree_memory_start     : ", hex_address(free_memory_start));
335
   SERIAL_ECHOPAIR("\nfree_memory_start     : ", hex_address(free_memory_start));
345
   if (stacklimit) SERIAL_ECHOPAIR("\n__stacklimit          : ", hex_address(stacklimit));
336
   if (stacklimit) SERIAL_ECHOPAIR("\n__stacklimit          : ", hex_address(stacklimit));
346
-  SERIAL_ECHOPAIR("\nfree_memory_end       : ", hex_address(free_memory_end  ));
347
-  if (MEMORY_END_CORRECTION)  SERIAL_ECHOPAIR("\nMEMORY_END_CORRECTION: ", MEMORY_END_CORRECTION );
337
+  SERIAL_ECHOPAIR("\nfree_memory_end       : ", hex_address(free_memory_end));
338
+  if (MEMORY_END_CORRECTION)  SERIAL_ECHOPAIR("\nMEMORY_END_CORRECTION: ", MEMORY_END_CORRECTION);
348
   SERIAL_ECHOLNPAIR("\nStack Pointer         : ", hex_address(sp));
339
   SERIAL_ECHOLNPAIR("\nStack Pointer         : ", hex_address(sp));
349
 
340
 
350
   // Always init on the first invocation of M100
341
   // Always init on the first invocation of M100

+ 1
- 1
Marlin/src/gcode/gcode.cpp View File

181
 // Placeholders for non-migrated codes
181
 // Placeholders for non-migrated codes
182
 //
182
 //
183
 #if ENABLED(M100_FREE_MEMORY_WATCHER)
183
 #if ENABLED(M100_FREE_MEMORY_WATCHER)
184
-  extern void M100_dump_routine(PGM_P const title, const char *start, const char *end);
184
+  extern void M100_dump_routine(PGM_P const title, char *start, char *end);
185
 #endif
185
 #endif
186
 
186
 
187
 /**
187
 /**

Loading…
Cancel
Save