瀏覽代碼

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 年之前
父節點
當前提交
31c28d0dd2
沒有連結到貢獻者的電子郵件帳戶。

+ 31
- 23
Marlin/src/gcode/gcode.cpp 查看文件

173
  * Process the parsed command and dispatch it to its handler
173
  * Process the parsed command and dispatch it to its handler
174
  */
174
  */
175
 void GcodeSuite::process_parsed_command(
175
 void GcodeSuite::process_parsed_command(
176
-  #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
176
+  #if USE_EXECUTE_COMMANDS_IMMEDIATE
177
     const bool no_ok
177
     const bool no_ok
178
   #endif
178
   #endif
179
 ) {
179
 ) {
698
 
698
 
699
   KEEPALIVE_STATE(NOT_BUSY);
699
   KEEPALIVE_STATE(NOT_BUSY);
700
 
700
 
701
-  #if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE)
701
+  #if USE_EXECUTE_COMMANDS_IMMEDIATE
702
     if (!no_ok)
702
     if (!no_ok)
703
   #endif
703
   #endif
704
       ok_to_send();
704
       ok_to_send();
725
   process_parsed_command();
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
    * Run a series of commands, bypassing the command queue to allow
731
    * Run a series of commands, bypassing the command queue to allow
731
    * G-code "macros" to be called from within other G-code handlers.
732
    * G-code "macros" to be called from within other G-code handlers.
732
    */
733
    */
734
+
733
   void GcodeSuite::process_subcommands_now_P(PGM_P pgcode) {
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
 #if ENABLED(HOST_KEEPALIVE_FEATURE)
766
 #if ENABLED(HOST_KEEPALIVE_FEATURE)
759
 
767
 

+ 3
- 2
Marlin/src/gcode/gcode.h 查看文件

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

+ 1
- 3
Marlin/src/inc/Conditionals_post.h 查看文件

1626
 // If platform requires early initialization of watchdog to properly boot
1626
 // If platform requires early initialization of watchdog to properly boot
1627
 #define EARLY_WATCHDOG (ENABLED(USE_WATCHDOG) && defined(ARDUINO_ARCH_SAM))
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
 #if ENABLED(Z_TRIPLE_STEPPER_DRIVERS)
1631
 #if ENABLED(Z_TRIPLE_STEPPER_DRIVERS)
1634
   #define Z_STEPPER_COUNT 3
1632
   #define Z_STEPPER_COUNT 3

+ 5
- 5
Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp 查看文件

96
 
96
 
97
 void ST7920_Lite_Status_Screen::write_str_P(PGM_P const str) {
97
 void ST7920_Lite_Status_Screen::write_str_P(PGM_P const str) {
98
   PGM_P p_str = (PGM_P)str;
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
 void ST7920_Lite_Status_Screen::write_str(progmem_str str) {
102
 void ST7920_Lite_Status_Screen::write_str(progmem_str str) {
221
   set_cgram_address(addr);
221
   set_cgram_address(addr);
222
   begin_data();
222
   begin_data();
223
   for (uint8_t i = 16; i--;)
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
   for (int i = 0; i < 16; i++) {
239
   for (int i = 0; i < 16; i++) {
240
     set_gdram_address(x, i + y * 16);
240
     set_gdram_address(x, i + y * 16);
241
     begin_data();
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
     const uint8_t y_top   = degree_symbol_y_top;
416
     const uint8_t y_top   = degree_symbol_y_top;
417
     const uint8_t y_bot   = y_top + sizeof(degree_symbol)/sizeof(degree_symbol[0]);
417
     const uint8_t y_bot   = y_top + sizeof(degree_symbol)/sizeof(degree_symbol[0]);
418
     for(uint8_t i = y_top; i < y_bot; i++) {
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
       begin_data();
421
       begin_data();
422
       if (draw) {
422
       if (draw) {
423
         write_byte(oddChar ? 0x00 : byte);
423
         write_byte(oddChar ? 0x00 : byte);

+ 1
- 1
Marlin/src/module/configuration_store.cpp 查看文件

1803
   LOOP_XYZE_N(i) {
1803
   LOOP_XYZE_N(i) {
1804
     planner.settings.axis_steps_per_mm[i]          = pgm_read_float(&tmp1[ALIM(i, tmp1)]);
1804
     planner.settings.axis_steps_per_mm[i]          = pgm_read_float(&tmp1[ALIM(i, tmp1)]);
1805
     planner.settings.max_feedrate_mm_s[i]          = pgm_read_float(&tmp2[ALIM(i, tmp2)]);
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
   planner.settings.min_segment_time_us = DEFAULT_MINSEGMENTTIME;
1809
   planner.settings.min_segment_time_us = DEFAULT_MINSEGMENTTIME;

+ 2
- 2
Marlin/src/module/motion.h 查看文件

95
 
95
 
96
 extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
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
 #define XYZ_DEFS(type, array, CONFIG) \
101
 #define XYZ_DEFS(type, array, CONFIG) \
102
   extern const type array##_P[XYZ]; \
102
   extern const type array##_P[XYZ]; \

+ 4
- 4
Marlin/src/module/stepper.h 查看文件

526
         if (step_rate >= (8 * 256)) { // higher step rate
526
         if (step_rate >= (8 * 256)) { // higher step rate
527
           const uint8_t tmp_step_rate = (step_rate & 0x00FF);
527
           const uint8_t tmp_step_rate = (step_rate & 0x00FF);
528
           const uint16_t table_address = (uint16_t)&speed_lookuptable_fast[(uint8_t)(step_rate >> 8)][0],
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
           timer = MultiU16X8toH16(tmp_step_rate, gain);
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
         else { // lower step rates
533
         else { // lower step rates
534
           uint16_t table_address = (uint16_t)&speed_lookuptable_slow[0][0];
534
           uint16_t table_address = (uint16_t)&speed_lookuptable_slow[0][0];
535
           table_address += ((step_rate) >> 1) & 0xFFFC;
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
         // (there is no need to limit the timer value here. All limits have been
539
         // (there is no need to limit the timer value here. All limits have been
540
         // applied above, and AVR is able to keep up at 30khz Stepping ISR rate)
540
         // applied above, and AVR is able to keep up at 30khz Stepping ISR rate)

Loading…
取消
儲存