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.
pull/1/head
Scott Lahteine 6 years ago
committed by GitHub
parent
commit
31c28d0dd2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 54
      Marlin/src/gcode/gcode.cpp
  2. 5
      Marlin/src/gcode/gcode.h
  3. 4
      Marlin/src/inc/Conditionals_post.h
  4. 10
      Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp
  5. 2
      Marlin/src/module/configuration_store.cpp
  6. 4
      Marlin/src/module/motion.h
  7. 8
      Marlin/src/module/stepper.h

54
Marlin/src/gcode/gcode.cpp

@ -173,7 +173,7 @@ void GcodeSuite::dwell(millis_t time) {
* Process the parsed command and dispatch it to its handler * Process the parsed command and dispatch it to its handler
*/ */
void GcodeSuite::process_parsed_command( void GcodeSuite::process_parsed_command(
#if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE) #if USE_EXECUTE_COMMANDS_IMMEDIATE
const bool no_ok const bool no_ok
#endif #endif
) { ) {
@ -698,7 +698,7 @@ void GcodeSuite::process_parsed_command(
KEEPALIVE_STATE(NOT_BUSY); KEEPALIVE_STATE(NOT_BUSY);
#if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE) #if USE_EXECUTE_COMMANDS_IMMEDIATE
if (!no_ok) if (!no_ok)
#endif #endif
ok_to_send(); ok_to_send();
@ -725,35 +725,43 @@ void GcodeSuite::process_next_command() {
process_parsed_command(); process_parsed_command();
} }
#if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE) #if USE_EXECUTE_COMMANDS_IMMEDIATE
/** /**
* Run a series of commands, bypassing the command queue to allow * Run a series of commands, bypassing the command queue to allow
* G-code "macros" to be called from within other G-code handlers. * G-code "macros" to be called from within other G-code handlers.
*/ */
void GcodeSuite::process_subcommands_now_P(PGM_P pgcode) { void GcodeSuite::process_subcommands_now_P(PGM_P pgcode) {
// Save the parser state char * const saved_cmd = parser.command_ptr; // Save the parser state
char * const saved_cmd = parser.command_ptr; for (;;) {
PGM_P const delim = strchr_P(pgcode, '\n'); // Get address of next newline
// Process individual commands in string const size_t len = delim ? delim - pgcode : strlen_P(pgcode); // Get the command length
while (pgm_read_byte_near(pgcode)) { char cmd[len + 1]; // Allocate a stack buffer
// Break up string at '\n' delimiters strncpy_P(cmd, pgcode, len); // Copy the command to the stack
PGM_P const delim = strchr_P(pgcode, '\n'); cmd[len] = '\0'; // End with a nul
size_t len = delim ? delim - pgcode : strlen_P(pgcode); parser.parse(cmd); // Parse the command
char cmd[len + 1]; process_parsed_command(true); // Process it
strncpy_P(cmd, pgcode, len); if (!delim) break; // Last command?
cmd[len] = '\0'; pgcode = delim + 1; // Get the next command
pgcode += len;
if (delim) pgcode++;
// Parse the next command in the string
parser.parse(cmd);
process_parsed_command(true);
} }
parser.parse(saved_cmd); // Restore the parser state
}
// Restore the parser state void GcodeSuite::process_subcommands_now(char * gcode) {
parser.parse(saved_cmd); char * const saved_cmd = parser.command_ptr; // Save the parser state
for (;;) {
const char * const delim = strchr(gcode, '\n'); // Get address of next newline
if (delim) *delim = '\0'; // Replace with nul
parser.parse(gcode); // Parse the current command
process_parsed_command(true); // Process it
if (!delim) break; // Last command?
gcode = delim + 1; // Get the next command
}
parser.parse(saved_cmd); // Restore the parser state
} }
#endif
#endif // USE_EXECUTE_COMMANDS_IMMEDIATE
#if ENABLED(HOST_KEEPALIVE_FEATURE) #if ENABLED(HOST_KEEPALIVE_FEATURE)

5
Marlin/src/gcode/gcode.h

@ -293,14 +293,15 @@ public:
static bool get_target_extruder_from_command(); static bool get_target_extruder_from_command();
static void get_destination_from_command(); static void get_destination_from_command();
static void process_parsed_command( static void process_parsed_command(
#if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE) #if USE_EXECUTE_COMMANDS_IMMEDIATE
const bool no_ok = false const bool no_ok = false
#endif #endif
); );
static void process_next_command(); static void process_next_command();
#if ENABLED(USE_EXECUTE_COMMANDS_IMMEDIATE) #if USE_EXECUTE_COMMANDS_IMMEDIATE
static void process_subcommands_now_P(PGM_P pgcode); static void process_subcommands_now_P(PGM_P pgcode);
static void process_subcommands_now(char * gcode);
#endif #endif
FORCE_INLINE static void home_all_axes() { G28(true); } FORCE_INLINE static void home_all_axes() { G28(true); }

4
Marlin/src/inc/Conditionals_post.h

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

10
Marlin/src/lcd/dogm/status_screen_lite_ST7920.cpp

@ -96,7 +96,7 @@ void ST7920_Lite_Status_Screen::write_str(const char *str, uint8_t len) {
void ST7920_Lite_Status_Screen::write_str_P(PGM_P const str) { void ST7920_Lite_Status_Screen::write_str_P(PGM_P const str) {
PGM_P p_str = (PGM_P)str; PGM_P p_str = (PGM_P)str;
while (char c = pgm_read_byte_near(p_str++)) write_byte(c); while (char c = pgm_read_byte(p_str++)) write_byte(c);
} }
void ST7920_Lite_Status_Screen::write_str(progmem_str str) { 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
set_cgram_address(addr); set_cgram_address(addr);
begin_data(); begin_data();
for (uint8_t i = 16; i--;) for (uint8_t i = 16; i--;)
write_word(pgm_read_word_near(p_word++)); write_word(pgm_read_word(p_word++));
} }
/** /**
@ -239,7 +239,7 @@ void ST7920_Lite_Status_Screen::draw_gdram_icon(uint8_t x, uint8_t y, const void
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
set_gdram_address(x, i + y * 16); set_gdram_address(x, i + y * 16);
begin_data(); begin_data();
write_word(pgm_read_word_near(p_word++)); write_word(pgm_read_word(p_word++));
} }
} }
@ -416,8 +416,8 @@ void ST7920_Lite_Status_Screen::draw_degree_symbol(uint8_t x, uint8_t y, bool dr
const uint8_t y_top = degree_symbol_y_top; const uint8_t y_top = degree_symbol_y_top;
const uint8_t y_bot = y_top + sizeof(degree_symbol)/sizeof(degree_symbol[0]); const uint8_t y_bot = y_top + sizeof(degree_symbol)/sizeof(degree_symbol[0]);
for(uint8_t i = y_top; i < y_bot; i++) { for(uint8_t i = y_top; i < y_bot; i++) {
uint8_t byte = pgm_read_byte_near(p_bytes++); uint8_t byte = pgm_read_byte(p_bytes++);
set_gdram_address(x_word,i+y*16); set_gdram_address(x_word, i + y * 16);
begin_data(); begin_data();
if (draw) { if (draw) {
write_byte(oddChar ? 0x00 : byte); write_byte(oddChar ? 0x00 : byte);

2
Marlin/src/module/configuration_store.cpp

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

4
Marlin/src/module/motion.h

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

8
Marlin/src/module/stepper.h

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

Loading…
Cancel
Save