Browse Source

Drop pgm_read_*_near and let headers choose (#12301)

- Drop `pgm_read_*_near` and let headers choose.
- Define `USE_EXECUTE_COMMANDS_IMMEDIATE` as a conditional.
- Add `process_subcommands_now` for SRAM-based commands.
Scott Lahteine 6 years ago
parent
commit
31c28d0dd2
No account linked to committer's email address

+ 31
- 23
Marlin/src/gcode/gcode.cpp View File

@@ -173,7 +173,7 @@ void GcodeSuite::dwell(millis_t time) {
173 173
  * Process the parsed command and dispatch it to its handler
174 174
  */
175 175
 void GcodeSuite::process_parsed_command(
176
-  #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
176
+  #if USE_EXECUTE_COMMANDS_IMMEDIATE
177 177
     const bool no_ok
178 178
   #endif
179 179
 ) {
@@ -698,7 +698,7 @@ void GcodeSuite::process_parsed_command(
698 698
 
699 699
   KEEPALIVE_STATE(NOT_BUSY);
700 700
 
701
-  #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
701
+  #if USE_EXECUTE_COMMANDS_IMMEDIATE
702 702
     if (!no_ok)
703 703
   #endif
704 704
       ok_to_send();
@@ -725,35 +725,43 @@ void GcodeSuite::process_next_command() {
725 725
   process_parsed_command();
726 726
 }
727 727
 
728
-#if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
728
+#if USE_EXECUTE_COMMANDS_IMMEDIATE
729
+
729 730
   /**
730 731
    * Run a series of commands, bypassing the command queue to allow
731 732
    * G-code "macros" to be called from within other G-code handlers.
732 733
    */
734
+
733 735
   void GcodeSuite::process_subcommands_now_P(PGM_P pgcode) {
734
-    // Save the parser state
735
-    char * const saved_cmd = parser.command_ptr;
736
-
737
-    // Process individual commands in string
738
-    while (pgm_read_byte_near(pgcode)) {
739
-      // Break up string at '\n' delimiters
740
-      PGM_P const delim = strchr_P(pgcode, '\n');
741
-      size_t len = delim ? delim - pgcode : strlen_P(pgcode);
742
-      char cmd[len + 1];
743
-      strncpy_P(cmd, pgcode, len);
744
-      cmd[len] = '\0';
745
-      pgcode += len;
746
-      if (delim) pgcode++;
747
-
748
-      // Parse the next command in the string
749
-      parser.parse(cmd);
750
-      process_parsed_command(true);
736
+    char * const saved_cmd = parser.command_ptr;        // Save the parser state
737
+    for (;;) {
738
+      PGM_P const delim = strchr_P(pgcode, '\n');       // Get address of next newline
739
+      const size_t len = delim ? delim - pgcode : strlen_P(pgcode); // Get the command length
740
+      char cmd[len + 1];                                // Allocate a stack buffer
741
+      strncpy_P(cmd, pgcode, len);                      // Copy the command to the stack
742
+      cmd[len] = '\0';                                  // End with a nul
743
+      parser.parse(cmd);                                // Parse the command
744
+      process_parsed_command(true);                     // Process it
745
+      if (!delim) break;                                // Last command?
746
+      pgcode = delim + 1;                               // Get the next command
751 747
     }
748
+    parser.parse(saved_cmd);                            // Restore the parser state
749
+  }
752 750
 
753
-    // Restore the parser state
754
-    parser.parse(saved_cmd);
751
+  void GcodeSuite::process_subcommands_now(char * gcode) {
752
+    char * const saved_cmd = parser.command_ptr;        // Save the parser state
753
+    for (;;) {
754
+      const char * const delim = strchr(gcode, '\n');   // Get address of next newline
755
+      if (delim) *delim = '\0';                         // Replace with nul
756
+      parser.parse(gcode);                              // Parse the current command
757
+      process_parsed_command(true);                     // Process it
758
+      if (!delim) break;                                // Last command?
759
+      gcode = delim + 1;                                // Get the next command
760
+    }
761
+    parser.parse(saved_cmd);                            // Restore the parser state
755 762
   }
756
-#endif
763
+
764
+#endif // USE_EXECUTE_COMMANDS_IMMEDIATE
757 765
 
758 766
 #if ENABLED(HOST_KEEPALIVE_FEATURE)
759 767
 

+ 3
- 2
Marlin/src/gcode/gcode.h View File

@@ -293,14 +293,15 @@ public:
293 293
   static bool get_target_extruder_from_command();
294 294
   static void get_destination_from_command();
295 295
   static void process_parsed_command(
296
-    #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
296
+    #if USE_EXECUTE_COMMANDS_IMMEDIATE
297 297
       const bool no_ok = false
298 298
     #endif
299 299
   );
300 300
   static void process_next_command();
301 301
 
302
-  #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
302
+  #if USE_EXECUTE_COMMANDS_IMMEDIATE
303 303
     static void process_subcommands_now_P(PGM_P pgcode);
304
+    static void process_subcommands_now(char * gcode);
304 305
   #endif
305 306
 
306 307
   FORCE_INLINE static void home_all_axes() { G28(true); }

+ 1
- 3
Marlin/src/inc/Conditionals_post.h View File

@@ -1626,9 +1626,7 @@
1626 1626
 // If platform requires early initialization of watchdog to properly boot
1627 1627
 #define EARLY_WATCHDOG (ENABLED(USE_WATCHDOG) && defined(ARDUINO_ARCH_SAM))
1628 1628
 
1629
-#if ENABLED(G29_RETRY_AND_RECOVER)
1630
-  #define USE_EXECUTE_COMMANDS_IMMEDIATE
1631
-#endif
1629
+#define USE_EXECUTE_COMMANDS_IMMEDIATE ENABLED(G29_RETRY_AND_RECOVER)
1632 1630
 
1633 1631
 #if ENABLED(Z_TRIPLE_STEPPER_DRIVERS)
1634 1632
   #define Z_STEPPER_COUNT 3

+ 5
- 5
Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp View File

@@ -96,7 +96,7 @@ void ST7920_Lite_Status_Screen::write_str(const char *str, uint8_t len) {
96 96
 
97 97
 void ST7920_Lite_Status_Screen::write_str_P(PGM_P const str) {
98 98
   PGM_P p_str = (PGM_P)str;
99
-  while (char c = pgm_read_byte_near(p_str++)) write_byte(c);
99
+  while (char c = pgm_read_byte(p_str++)) write_byte(c);
100 100
 }
101 101
 
102 102
 void ST7920_Lite_Status_Screen::write_str(progmem_str str) {
@@ -221,7 +221,7 @@ void ST7920_Lite_Status_Screen::load_cgram_icon(const uint16_t addr, const void
221 221
   set_cgram_address(addr);
222 222
   begin_data();
223 223
   for (uint8_t i = 16; i--;)
224
-    write_word(pgm_read_word_near(p_word++));
224
+    write_word(pgm_read_word(p_word++));
225 225
 }
226 226
 
227 227
 /**
@@ -239,7 +239,7 @@ void ST7920_Lite_Status_Screen::draw_gdram_icon(uint8_t x, uint8_t y, const void
239 239
   for (int i = 0; i < 16; i++) {
240 240
     set_gdram_address(x, i + y * 16);
241 241
     begin_data();
242
-    write_word(pgm_read_word_near(p_word++));
242
+    write_word(pgm_read_word(p_word++));
243 243
   }
244 244
 }
245 245
 
@@ -416,8 +416,8 @@ void ST7920_Lite_Status_Screen::draw_degree_symbol(uint8_t x, uint8_t y, bool dr
416 416
     const uint8_t y_top   = degree_symbol_y_top;
417 417
     const uint8_t y_bot   = y_top + sizeof(degree_symbol)/sizeof(degree_symbol[0]);
418 418
     for(uint8_t i = y_top; i < y_bot; i++) {
419
-      uint8_t byte = pgm_read_byte_near(p_bytes++);
420
-      set_gdram_address(x_word,i+y*16);
419
+      uint8_t byte = pgm_read_byte(p_bytes++);
420
+      set_gdram_address(x_word, i + y * 16);
421 421
       begin_data();
422 422
       if (draw) {
423 423
         write_byte(oddChar ? 0x00 : byte);

+ 1
- 1
Marlin/src/module/configuration_store.cpp View File

@@ -1803,7 +1803,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
1803 1803
   LOOP_XYZE_N(i) {
1804 1804
     planner.settings.axis_steps_per_mm[i]          = pgm_read_float(&tmp1[ALIM(i, tmp1)]);
1805 1805
     planner.settings.max_feedrate_mm_s[i]          = pgm_read_float(&tmp2[ALIM(i, tmp2)]);
1806
-    planner.settings.max_acceleration_mm_per_s2[i] = pgm_read_dword_near(&tmp3[ALIM(i, tmp3)]);
1806
+    planner.settings.max_acceleration_mm_per_s2[i] = pgm_read_dword(&tmp3[ALIM(i, tmp3)]);
1807 1807
   }
1808 1808
 
1809 1809
   planner.settings.min_segment_time_us = DEFAULT_MINSEGMENTTIME;

+ 2
- 2
Marlin/src/module/motion.h View File

@@ -95,8 +95,8 @@ extern int16_t feedrate_percentage;
95 95
 
96 96
 extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
97 97
 
98
-FORCE_INLINE float pgm_read_any(const float *p) { return pgm_read_float_near(p); }
99
-FORCE_INLINE signed char pgm_read_any(const signed char *p) { return pgm_read_byte_near(p); }
98
+FORCE_INLINE float pgm_read_any(const float *p) { return pgm_read_float(p); }
99
+FORCE_INLINE signed char pgm_read_any(const signed char *p) { return pgm_read_byte(p); }
100 100
 
101 101
 #define XYZ_DEFS(type, array, CONFIG) \
102 102
   extern const type array##_P[XYZ]; \

+ 4
- 4
Marlin/src/module/stepper.h View File

@@ -526,15 +526,15 @@ class Stepper {
526 526
         if (step_rate >= (8 * 256)) { // higher step rate
527 527
           const uint8_t tmp_step_rate = (step_rate & 0x00FF);
528 528
           const uint16_t table_address = (uint16_t)&speed_lookuptable_fast[(uint8_t)(step_rate >> 8)][0],
529
-                         gain = (uint16_t)pgm_read_word_near(table_address + 2);
529
+                         gain = (uint16_t)pgm_read_word(table_address + 2);
530 530
           timer = MultiU16X8toH16(tmp_step_rate, gain);
531
-          timer = (uint16_t)pgm_read_word_near(table_address) - timer;
531
+          timer = (uint16_t)pgm_read_word(table_address) - timer;
532 532
         }
533 533
         else { // lower step rates
534 534
           uint16_t table_address = (uint16_t)&speed_lookuptable_slow[0][0];
535 535
           table_address += ((step_rate) >> 1) & 0xFFFC;
536
-          timer = (uint16_t)pgm_read_word_near(table_address)
537
-                - (((uint16_t)pgm_read_word_near(table_address + 2) * (uint8_t)(step_rate & 0x0007)) >> 3);
536
+          timer = (uint16_t)pgm_read_word(table_address)
537
+                - (((uint16_t)pgm_read_word(table_address + 2) * (uint8_t)(step_rate & 0x0007)) >> 3);
538 538
         }
539 539
         // (there is no need to limit the timer value here. All limits have been
540 540
         // applied above, and AVR is able to keep up at 30khz Stepping ISR rate)

Loading…
Cancel
Save