Browse Source

Add hex routine to print an address

Scott Lahteine 7 years ago
parent
commit
e05d050a1e
5 changed files with 38 additions and 33 deletions
  1. 13
    13
      Marlin/M100_Free_Mem_Chk.cpp
  2. 17
    14
      Marlin/hex_print_routines.cpp
  3. 2
    0
      Marlin/hex_print_routines.h
  4. 2
    2
      Marlin/ubl.cpp
  5. 4
    4
      Marlin/ubl_G29.cpp

+ 13
- 13
Marlin/M100_Free_Mem_Chk.cpp View File

86
   return -1;
86
   return -1;
87
 }
87
 }
88
 
88
 
89
-
90
 //
89
 //
91
 // M100 sub-commands
90
 // M100 sub-commands
92
 //
91
 //
172
       const uint16_t j = count_test_bytes(addr);
171
       const uint16_t j = count_test_bytes(addr);
173
       if (j > 8) {
172
       if (j > 8) {
174
         SERIAL_ECHOPAIR("Found ", j);
173
         SERIAL_ECHOPAIR("Found ", j);
175
-        SERIAL_ECHOLNPAIR(" bytes free at 0x", hex_word((uint16_t)addr));
174
+        SERIAL_ECHOLNPAIR(" bytes free at ", hex_address(addr));
176
         if (j > max_cnt) {
175
         if (j > max_cnt) {
177
           max_cnt  = j;
176
           max_cnt  = j;
178
           max_addr = addr;
177
           max_addr = addr;
185
   if (block_cnt > 1) {
184
   if (block_cnt > 1) {
186
     SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
185
     SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
187
     SERIAL_ECHOPAIR("\nLargest free block is ", max_cnt);
186
     SERIAL_ECHOPAIR("\nLargest free block is ", max_cnt);
188
-    SERIAL_ECHOLNPAIR(" bytes at 0x", hex_word((uint16_t)max_addr));
187
+    SERIAL_ECHOLNPAIR(" bytes at ", hex_address(max_addr));
189
   }
188
   }
190
   SERIAL_ECHOLNPAIR("check_for_free_memory_corruption() = ", check_for_free_memory_corruption("M100 F "));
189
   SERIAL_ECHOLNPAIR("check_for_free_memory_corruption() = ", check_for_free_memory_corruption("M100 F "));
191
 }
190
 }
206
       for (uint16_t i = 1; i <= size; i++) {
205
       for (uint16_t i = 1; i <= size; i++) {
207
         char * const addr = ptr + i * j;
206
         char * const addr = ptr + i * j;
208
         *addr = i;
207
         *addr = i;
209
-        SERIAL_ECHOPAIR("\nCorrupting address: 0x", hex_word((uint16_t)addr));
208
+        SERIAL_ECHOPAIR("\nCorrupting address: ", hex_address(addr));
210
       }
209
       }
211
       SERIAL_EOL;
210
       SERIAL_EOL;
212
     }
211
     }
235
 
234
 
236
   for (uint16_t i = 0; i < size; i++) {
235
   for (uint16_t i = 0; i < size; i++) {
237
     if (((char) ptr[i]) != TEST_BYTE) {
236
     if (((char) ptr[i]) != TEST_BYTE) {
238
-      SERIAL_ECHOPAIR("? address : 0x", hex_word((uint16_t)ptr + i));
239
-      SERIAL_ECHOLNPAIR("=", hex_byte(ptr[i]));
237
+      SERIAL_ECHOPAIR("? address : ", hex_address(ptr + i));
238
+      SERIAL_ECHOPAIR("=", hex_byte(ptr[i]));
239
+      SERIAL_EOL; SERIAL_EOL;
240
     }
240
     }
241
   }
241
   }
242
 }
242
 }
245
  * M100: Free Memory Check
245
  * M100: Free Memory Check
246
  */
246
  */
247
 void gcode_M100() {
247
 void gcode_M100() {
248
-  SERIAL_ECHOPAIR("\n__brkval : 0x", hex_word((uint16_t)__brkval));
249
-  SERIAL_ECHOPAIR("\n__bss_end: 0x", hex_word((uint16_t)&__bss_end));
248
+  SERIAL_ECHOPAIR("\n__brkval : ", hex_address(__brkval));
249
+  SERIAL_ECHOPAIR("\n__bss_end : ", hex_address(&__bss_end));
250
 
250
 
251
   uint8_t *ptr = END_OF_HEAP(), *sp = top_of_stack();
251
   uint8_t *ptr = END_OF_HEAP(), *sp = top_of_stack();
252
 
252
 
253
-  SERIAL_ECHOPAIR("\nstart of free space : 0x", hex_word((uint16_t)ptr));
254
-  SERIAL_ECHOLNPAIR("\nStack Pointer : 0x", hex_word((uint16_t)sp));
253
+  SERIAL_ECHOPAIR("\nstart of free space : ", hex_address(ptr));
254
+  SERIAL_ECHOLNPAIR("\nStack Pointer : ", hex_address(sp));
255
 
255
 
256
   // Always init on the first invocation of M100
256
   // Always init on the first invocation of M100
257
   static bool m100_not_initialized = true;
257
   static bool m100_not_initialized = true;
287
 
287
 
288
     n = sp - ptr;
288
     n = sp - ptr;
289
     SERIAL_ECHOPAIR("\nfmc() n=", n);
289
     SERIAL_ECHOPAIR("\nfmc() n=", n);
290
-    SERIAL_ECHOPAIR("\n&__brkval: 0x", hex_word((uint16_t)&__brkval));
291
-    SERIAL_ECHOPAIR("=0x",             hex_word((uint16_t)__brkval));
292
-    SERIAL_ECHOPAIR("\n__bss_end: 0x", hex_word((uint16_t)&__bss_end));
290
+    SERIAL_ECHOPAIR("\n&__brkval: ", hex_address(&__brkval));
291
+    SERIAL_ECHOPAIR("=",             hex_address(__brkval));
292
+    SERIAL_ECHOPAIR("\n__bss_end: ", hex_address(&__bss_end));
293
     SERIAL_ECHOPAIR(" sp=", hex_word(sp));
293
     SERIAL_ECHOPAIR(" sp=", hex_word(sp));
294
 
294
 
295
     if (sp < ptr)  {
295
     if (sp < ptr)  {

+ 17
- 14
Marlin/hex_print_routines.cpp View File

19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
  *
20
  *
21
  */
21
  */
22
-
23
-
24
 #include "Marlin.h"
22
 #include "Marlin.h"
25
 #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(M100_FREE_MEMORY_WATCHER)
23
 #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(M100_FREE_MEMORY_WATCHER)
26
 
24
 
27
 #include "hex_print_routines.h"
25
 #include "hex_print_routines.h"
28
 
26
 
29
-static char _hex[5] = { 0 };
27
+static char _hex[7] = "0x0000";
30
 
28
 
31
 char* hex_byte(const uint8_t b) {
29
 char* hex_byte(const uint8_t b) {
32
-  _hex[0] = hex_nybble(b >> 4);
33
-  _hex[1] = hex_nybble(b);
34
-  _hex[2] = '\0';
35
-  return _hex;
30
+  _hex[4] = hex_nybble(b >> 4);
31
+  _hex[5] = hex_nybble(b);
32
+  return &_hex[4];
36
 }
33
 }
37
 
34
 
38
 char* hex_word(const uint16_t w) {
35
 char* hex_word(const uint16_t w) {
39
-  _hex[0] = hex_nybble(w >> 12);
40
-  _hex[1] = hex_nybble(w >> 8);
41
-  _hex[2] = hex_nybble(w >> 4);
42
-  _hex[3] = hex_nybble(w);
36
+  _hex[2] = hex_nybble(w >> 12);
37
+  _hex[3] = hex_nybble(w >> 8);
38
+  _hex[4] = hex_nybble(w >> 4);
39
+  _hex[5] = hex_nybble(w);
40
+  return &_hex[2];
41
+}
42
+
43
+char* hex_address(const void * const w) {
44
+  (void)hex_word((uint16_t)w);
43
   return _hex;
45
   return _hex;
44
 }
46
 }
45
 
47
 
46
-void print_hex_nybble(const uint8_t n) { SERIAL_CHAR(hex_nybble(n)); }
47
-void print_hex_byte(const uint8_t b)   { SERIAL_ECHO(hex_byte(b)); }
48
-void print_hex_word(const uint16_t w)  { SERIAL_ECHO(hex_word(w)); }
48
+void print_hex_nybble(const uint8_t n)       { SERIAL_CHAR(hex_nybble(n));  }
49
+void print_hex_byte(const uint8_t b)         { SERIAL_ECHO(hex_byte(b));    }
50
+void print_hex_word(const uint16_t w)        { SERIAL_ECHO(hex_word(w));    }
51
+void print_hex_address(const void * const w) { SERIAL_ECHO(hex_address(w)); }
49
 
52
 
50
 #endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER
53
 #endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER

+ 2
- 0
Marlin/hex_print_routines.h View File

36
 }
36
 }
37
 char* hex_byte(const uint8_t b);
37
 char* hex_byte(const uint8_t b);
38
 char* hex_word(const uint16_t w);
38
 char* hex_word(const uint16_t w);
39
+char* hex_address(const void * const w);
39
 
40
 
40
 void print_hex_nybble(const uint8_t n);
41
 void print_hex_nybble(const uint8_t n);
41
 void print_hex_byte(const uint8_t b);
42
 void print_hex_byte(const uint8_t b);
42
 void print_hex_word(const uint16_t w);
43
 void print_hex_word(const uint16_t w);
44
+void print_hex_address(const void * const w);
43
 
45
 
44
 #endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER
46
 #endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER
45
 #endif // HEX_PRINT_ROUTINES_H
47
 #endif // HEX_PRINT_ROUTINES_H

+ 2
- 2
Marlin/ubl.cpp View File

118
     eeprom_read_block((void *)&z_values, (void *)j, sizeof(z_values));
118
     eeprom_read_block((void *)&z_values, (void *)j, sizeof(z_values));
119
 
119
 
120
     SERIAL_PROTOCOLPAIR("Mesh loaded from slot ", m);
120
     SERIAL_PROTOCOLPAIR("Mesh loaded from slot ", m);
121
-    SERIAL_PROTOCOLLNPAIR(" at offset 0x", hex_word(j));
121
+    SERIAL_PROTOCOLLNPAIR(" at offset ", hex_address((void*)j));
122
   }
122
   }
123
 
123
 
124
   void unified_bed_leveling::store_mesh(const int16_t m) {
124
   void unified_bed_leveling::store_mesh(const int16_t m) {
140
     eeprom_write_block((const void *)&z_values, (void *)j, sizeof(z_values));
140
     eeprom_write_block((const void *)&z_values, (void *)j, sizeof(z_values));
141
 
141
 
142
     SERIAL_PROTOCOLPAIR("Mesh saved in slot ", m);
142
     SERIAL_PROTOCOLPAIR("Mesh saved in slot ", m);
143
-    SERIAL_PROTOCOLLNPAIR(" at offset 0x", hex_word(j));
143
+    SERIAL_PROTOCOLLNPAIR(" at offset ", hex_address((void*)j));
144
   }
144
   }
145
 
145
 
146
   void unified_bed_leveling::reset() {
146
   void unified_bed_leveling::reset() {

+ 4
- 4
Marlin/ubl_G29.cpp View File

1206
     SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1206
     SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1207
     SERIAL_EOL;
1207
     SERIAL_EOL;
1208
     safe_delay(50);
1208
     safe_delay(50);
1209
-    SERIAL_PROTOCOLLNPAIR("Free EEPROM space starts at: 0x", hex_word(ubl.eeprom_start));
1209
+    SERIAL_PROTOCOLLNPAIR("Free EEPROM space starts at: ", hex_address((void*)ubl.eeprom_start));
1210
 
1210
 
1211
-    SERIAL_PROTOCOLLNPAIR("end of EEPROM              : 0x", hex_word(E2END));
1211
+    SERIAL_PROTOCOLLNPAIR("end of EEPROM              : ", hex_address((void*)E2END));
1212
     safe_delay(50);
1212
     safe_delay(50);
1213
 
1213
 
1214
     SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
1214
     SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
1217
     SERIAL_EOL;
1217
     SERIAL_EOL;
1218
     safe_delay(50);
1218
     safe_delay(50);
1219
 
1219
 
1220
-    SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: 0x", hex_word(k));
1220
+    SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)k));
1221
     safe_delay(50);
1221
     safe_delay(50);
1222
 
1222
 
1223
     SERIAL_PROTOCOLPAIR("EEPROM can hold ", k / sizeof(ubl.z_values));
1223
     SERIAL_PROTOCOLPAIR("EEPROM can hold ", k / sizeof(ubl.z_values));
1295
     eeprom_read_block((void *)&tmp_z_values, (void *)j, sizeof(tmp_z_values));
1295
     eeprom_read_block((void *)&tmp_z_values, (void *)j, sizeof(tmp_z_values));
1296
 
1296
 
1297
     SERIAL_ECHOPAIR("Subtracting Mesh ", storage_slot);
1297
     SERIAL_ECHOPAIR("Subtracting Mesh ", storage_slot);
1298
-    SERIAL_PROTOCOLLNPAIR(" loaded from EEPROM address 0x", hex_word(j)); // Soon, we can remove the extra clutter of printing
1298
+    SERIAL_PROTOCOLLNPAIR(" loaded from EEPROM address ", hex_address((void*)j)); // Soon, we can remove the extra clutter of printing
1299
                                                                         // the address in the EEPROM where the Mesh is stored.
1299
                                                                         // the address in the EEPROM where the Mesh is stored.
1300
 
1300
 
1301
     for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
1301
     for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)

Loading…
Cancel
Save