Pārlūkot izejas kodu

Add hex routine to print an address

Scott Lahteine 7 gadus atpakaļ
vecāks
revīzija
e05d050a1e

+ 13
- 13
Marlin/M100_Free_Mem_Chk.cpp Parādīt failu

@@ -86,7 +86,6 @@ int16_t count_test_bytes(const uint8_t * const ptr) {
86 86
   return -1;
87 87
 }
88 88
 
89
-
90 89
 //
91 90
 // M100 sub-commands
92 91
 //
@@ -172,7 +171,7 @@ void free_memory_pool_report(const char * const ptr, const uint16_t size) {
172 171
       const uint16_t j = count_test_bytes(addr);
173 172
       if (j > 8) {
174 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 175
         if (j > max_cnt) {
177 176
           max_cnt  = j;
178 177
           max_addr = addr;
@@ -185,7 +184,7 @@ void free_memory_pool_report(const char * const ptr, const uint16_t size) {
185 184
   if (block_cnt > 1) {
186 185
     SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area.");
187 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 189
   SERIAL_ECHOLNPAIR("check_for_free_memory_corruption() = ", check_for_free_memory_corruption("M100 F "));
191 190
 }
@@ -206,7 +205,7 @@ void free_memory_pool_report(const char * const ptr, const uint16_t size) {
206 205
       for (uint16_t i = 1; i <= size; i++) {
207 206
         char * const addr = ptr + i * j;
208 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 210
       SERIAL_EOL;
212 211
     }
@@ -235,8 +234,9 @@ void init_free_memory(uint8_t *ptr, int16_t size) {
235 234
 
236 235
   for (uint16_t i = 0; i < size; i++) {
237 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,13 +245,13 @@ void init_free_memory(uint8_t *ptr, int16_t size) {
245 245
  * M100: Free Memory Check
246 246
  */
247 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 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 256
   // Always init on the first invocation of M100
257 257
   static bool m100_not_initialized = true;
@@ -287,9 +287,9 @@ int check_for_free_memory_corruption(char *title) {
287 287
 
288 288
     n = sp - ptr;
289 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 293
     SERIAL_ECHOPAIR(" sp=", hex_word(sp));
294 294
 
295 295
     if (sp < ptr)  {

+ 17
- 14
Marlin/hex_print_routines.cpp Parādīt failu

@@ -19,32 +19,35 @@
19 19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 20
  *
21 21
  */
22
-
23
-
24 22
 #include "Marlin.h"
25 23
 #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(M100_FREE_MEMORY_WATCHER)
26 24
 
27 25
 #include "hex_print_routines.h"
28 26
 
29
-static char _hex[5] = { 0 };
27
+static char _hex[7] = "0x0000";
30 28
 
31 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 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 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 53
 #endif // AUTO_BED_LEVELING_UBL || M100_FREE_MEMORY_WATCHER

+ 2
- 0
Marlin/hex_print_routines.h Parādīt failu

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

+ 2
- 2
Marlin/ubl.cpp Parādīt failu

@@ -118,7 +118,7 @@
118 118
     eeprom_read_block((void *)&z_values, (void *)j, sizeof(z_values));
119 119
 
120 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 124
   void unified_bed_leveling::store_mesh(const int16_t m) {
@@ -140,7 +140,7 @@
140 140
     eeprom_write_block((const void *)&z_values, (void *)j, sizeof(z_values));
141 141
 
142 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 146
   void unified_bed_leveling::reset() {

+ 4
- 4
Marlin/ubl_G29.cpp Parādīt failu

@@ -1206,9 +1206,9 @@
1206 1206
     SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1207 1207
     SERIAL_EOL;
1208 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 1212
     safe_delay(50);
1213 1213
 
1214 1214
     SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
@@ -1217,7 +1217,7 @@
1217 1217
     SERIAL_EOL;
1218 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 1221
     safe_delay(50);
1222 1222
 
1223 1223
     SERIAL_PROTOCOLPAIR("EEPROM can hold ", k / sizeof(ubl.z_values));
@@ -1295,7 +1295,7 @@
1295 1295
     eeprom_read_block((void *)&tmp_z_values, (void *)j, sizeof(tmp_z_values));
1296 1296
 
1297 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 1299
                                                                         // the address in the EEPROM where the Mesh is stored.
1300 1300
 
1301 1301
     for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)

Notiek ielāde…
Atcelt
Saglabāt