Browse Source

Timing functions 'micros' and 'delay' replaced in whole source with 'micros2' and 'delay2'

Robert Pelnar 5 years ago
parent
commit
434a723151

+ 25 - 25
Firmware/Marlin_main.cpp

@@ -912,7 +912,7 @@ void update_sec_lang_from_external_flash()
 		{
 			fputs_P(PSTR(ESC_H(1,3) "Language update."), lcdout);
 			for (uint8_t i = 0; i < state; i++) fputc('.', lcdout);
-			delay(100);
+			delay2(100);
 			boot_reserved = (state + 1) | (lang << 4);
 			if ((state * LANGBOOT_BLOCKSIZE) < header.size)
 			{
@@ -1310,9 +1310,9 @@ void setup()
     for (uint16_t phase = (tmc2130_rd_MSCNT(Z_AXIS) + 8) >> 4; phase > 0; -- phase) {
       // Until the phase counter is reset to zero.
       WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
-      delay(2);
+      delay2(2);
       WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN);
-      delay(2);
+      delay2(2);
     }
   }
 #endif //TMC2130
@@ -1358,16 +1358,16 @@ void setup()
 		uint32_t sumw = 0;
 		for (int i = 0; i < 1024; i++)
 		{
-			uint32_t u = micros();
+			uint32_t u = micros2();
 			bool res = card.card.readBlock(i, buff);
-			u = micros() - u;
+			u = micros2() - u;
 			if (res)
 			{
 				printf_P(PSTR("readBlock %4d 512 bytes %lu us\n"), i, u);
 				sumr += u;
-				u = micros();
+				u = micros2();
 				res = card.card.writeBlock(i, buff);
-				u = micros() - u;
+				u = micros2() - u;
 				if (res)
 				{
 					printf_P(PSTR("writeBlock %4d 512 bytes %lu us\n"), i, u);
@@ -2317,9 +2317,9 @@ void refresh_cmd_timeout(void)
 void trace() {
 //if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
     tone(BEEPER, 440);
-    delay(25);
+    delay2(25);
     noTone(BEEPER);
-    delay(20);
+    delay2(20);
 }
 /*
 void ramming() {
@@ -2380,7 +2380,7 @@ void ramming() {
 		//plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600/60, active_extruder); //delay
 		//current_position[X_AXIS] -= 23; //delay
 		//plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600/60, active_extruder); //delay
-		delay(4700);
+		delay2(4700);
 		max_feedrate[E_AXIS] = 80;
 		current_position[E_AXIS] -= 92;
 		plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 9900 / 60, active_extruder);
@@ -3176,9 +3176,9 @@ static void gcode_PRUSA_SN()
 #if 0
         for (int b = 0; b < 3; b++) {
             tone(BEEPER, 110);
-            delay(50);
+            delay2(50);
             noTone(BEEPER);
-            delay(50);
+            delay2(50);
         }
 #endif
     } else {
@@ -3611,7 +3611,7 @@ void process_commands()
                         disable_e0();
                         disable_e1();
                         disable_e2();
-                        delay(100);
+                        delay2(100);
                         
                         //LCD_ALERTMESSAGEPGM(_T(MSG_FILAMENTCHANGE));
                         uint8_t cnt=0;
@@ -5379,7 +5379,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
 
 	}
 
-	delay(1000);
+	delay2(1000);
 
     clean_up_after_endstop_move(l_feedmultiply);
 
@@ -5668,7 +5668,7 @@ Sigma_Exit:
         disable_e2();
         finishAndDisableSteppers();
         fanSpeed = 0;
-        delay(1000); // Wait a little before to switch off
+        delay2(1000); // Wait a little before to switch off
       #if defined(SUICIDE_PIN) && SUICIDE_PIN > -1
         st_synchronize();
         suicide();
@@ -6221,7 +6221,7 @@ Sigma_Exit:
 #endif
             servos[servo_index].write(servo_position);
 #if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
-              delay(PROBE_SERVO_DEACTIVATION_DELAY);
+              delay2(PROBE_SERVO_DEACTIVATION_DELAY);
               servos[servo_index].detach();
 #endif
           }
@@ -6254,13 +6254,13 @@ Sigma_Exit:
         #if BEEPER > 0
 if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
           tone(BEEPER, beepS);
-          delay(beepP);
+          delay2(beepP);
           noTone(BEEPER);
         #endif
       }
       else
       {
-        delay(beepP);
+        delay2(beepP);
       }
     }
     break;
@@ -6333,7 +6333,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
         WRITE(PHOTOGRAPH_PIN, LOW);
         _delay_ms(PULSE_LENGTH);
         }
-        delay(7.33);
+        delay2(7.33);
         for(int i=0; i < NUM_PULSES; i++) {
         WRITE(PHOTOGRAPH_PIN, HIGH);
         _delay_ms(PULSE_LENGTH);
@@ -6982,7 +6982,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
               mmu_extruder = tmp_extruder;
 
 
-              delay(100);
+              delay2(100);
 
               disable_e0();
               disable_e1();
@@ -6991,7 +6991,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
               pinMode(E_MUX0_PIN, OUTPUT);
               pinMode(E_MUX1_PIN, OUTPUT);
 
-              delay(100);
+              delay2(100);
               SERIAL_ECHO_START;
               SERIAL_ECHO("T:");
               SERIAL_ECHOLN((int)tmp_extruder);
@@ -7017,7 +7017,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
 
                   break;
               }
-              delay(100);
+              delay2(100);
 
 #else //SNMM
               if (tmp_extruder >= EXTRUDERS) {
@@ -7621,7 +7621,7 @@ void kill(const char *full_screen_message, unsigned char id)
   sei();   // enable interrupts
   for ( int i=5; i--; lcd_update(0))
   {
-     delay(200);	
+     delay2(200);	
   }
   cli();   // disable interrupts
   suicide();
@@ -8028,8 +8028,8 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_
 
 		
 		//MYSERIAL.println(data_wldsd);
-		//delay(1000);
-		//delay(3000);
+		//delay2(1000);
+		//delay2(3000);
 		//t1 = millis();
 		
 		//while (digitalRead(D_DATACLOCK) == LOW) {}

+ 1 - 1
Firmware/cardreader.cpp

@@ -954,7 +954,7 @@ void CardReader::presort() {
 		lcd_set_cursor(column, 2);
 		lcd_print('\x01'); //simple progress bar
 	}
-	delay(300);
+	delay2(300);
 	lcd_set_degree();
 	lcd_clear();
 #endif

+ 2 - 2
Firmware/mmu.cpp

@@ -815,7 +815,7 @@ void change_extr(int
         ) { //switches multiplexer for extruders
 #ifdef SNMM
 	st_synchronize();
-	delay(100);
+	delay2(100);
 
 	disable_e0();
 	disable_e1();
@@ -848,7 +848,7 @@ void change_extr(int
 		
 		break;
 	}
-	delay(100);
+	delay2(100);
 #endif
 }
 

+ 1 - 1
Firmware/stepper.cpp

@@ -1537,7 +1537,7 @@ void digitalPotWrite(int address, int value) // From Arduino DigitalPotControl e
     SPI.transfer(address); //  send in the address and value via SPI:
     SPI.transfer(value);
     digitalWrite(DIGIPOTSS_PIN,HIGH); // take the SS pin high to de-select the chip:
-    //delay(10);
+    //delay2(10);
 }
 #endif
 

+ 1 - 1
Firmware/temperature.cpp

@@ -1086,7 +1086,7 @@ void tp_init()
   TIMSK2 |= (1<<OCIE2B);  
   
   // Wait for temperature measurement to settle
-  delay(250);
+  delay2(250);
 
 #ifdef HEATER_0_MINTEMP
   minttemp[0] = HEATER_0_MINTEMP;

+ 2 - 2
Firmware/tmc2130.cpp

@@ -697,9 +697,9 @@ uint16_t tmc2130_get_res(uint8_t axis)
 void tmc2130_set_res(uint8_t axis, uint16_t res)
 {
 	tmc2130_mres[axis] = tmc2130_usteps2mres(res);
-//	uint32_t u = micros();
+//	uint32_t u = micros2();
 	tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
-//	u = micros() - u;
+//	u = micros2() - u;
 //	printf_P(PSTR("tmc2130_setup_chopper %c %lu us"), "XYZE"[axis], u);
 }
 

+ 36 - 36
Firmware/ultralcd.cpp

@@ -281,8 +281,8 @@ static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, char* longF
 				j = 0;
 				break;
             }else{
-				if (j == 1) delay(3);	//wait around 1.2 s to start scrolling text
-				delay(1);				//then scroll with redrawing every 300 ms 
+				if (j == 1) delay2(3);	//wait around 1.2 s to start scrolling text
+				delay2(1);				//then scroll with redrawing every 300 ms 
             }
 
           }
@@ -2365,7 +2365,7 @@ void lcd_loading_filament() {
       manage_heater();
       manage_inactivity(true);
 
-      delay(153);
+      delay2(153);
     }
 
 
@@ -2445,7 +2445,7 @@ void lcd_alright() {
         lcd_set_cursor(0, cursor_pos);
         lcd_print(">");
         enc_dif = lcd_encoder_diff;
-        delay(100);
+        delay2(100);
       }
 
     }
@@ -2454,7 +2454,7 @@ void lcd_alright() {
     if (lcd_clicked()) {
 
       lcd_change_fil_state = cursor_pos;
-      delay(500);
+      delay2(500);
 
     }
 
@@ -2475,7 +2475,7 @@ void show_preheat_nozzle_warning()
     lcd_puts_P(_T(MSG_ERROR));
     lcd_set_cursor(0, 2);
     lcd_puts_P(_T(MSG_PREHEAT_NOZZLE));
-    delay(2000);
+    delay2(2000);
     lcd_clear();
 }
 
@@ -2608,7 +2608,7 @@ void lcd_menu_statistics()
 		{
 			manage_heater();
 			manage_inactivity(true);
-			delay(100);
+			delay2(100);
 		}
 		KEEPALIVE_STATE(NOT_BUSY);
 		lcd_quick_feedback();
@@ -2866,7 +2866,7 @@ static void _lcd_babystep(int axis, const char *msg)
 			}
 		}
 		_md->babystepMemMM[axis] = _md->babystepMem[axis]/cs.axis_steps_per_unit[axis]; 
-		delay(50);
+		delay2(50);
 		lcd_encoder = 0;
 		lcd_draw_update = 1;
 	}
@@ -3029,7 +3029,7 @@ void lcd_adjust_z() {
         lcd_set_cursor(0, cursor_pos);
         lcd_print(">");
         enc_dif = lcd_encoder_diff;
-        delay(100);
+        delay2(100);
       }
 
     }
@@ -3049,7 +3049,7 @@ void lcd_adjust_z() {
         EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
         EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
       }
-      delay(500);
+      delay2(500);
     }
   };
 
@@ -3151,7 +3151,7 @@ bool lcd_calibrate_z_end_stop_manual(bool only_z)
             manage_heater();
             manage_inactivity(true);
             if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) {
-                delay(50);
+                delay2(50);
                 previous_millis_cmd = millis();
                 lcd_encoder += abs(lcd_encoder_diff / ENCODER_PULSES_PER_STEP);
                 lcd_encoder_diff = 0;
@@ -3166,7 +3166,7 @@ bool lcd_calibrate_z_end_stop_manual(bool only_z)
                 // Abort a move if in progress.
                 planner_abort_hard();
                 while (lcd_clicked()) ;
-                delay(10);
+                delay2(10);
                 while (lcd_clicked()) ;
                 break;
             }
@@ -3983,7 +3983,7 @@ void lcd_pick_babystep(){
                 
    
                 enc_dif = lcd_encoder_diff;
-                delay(100);
+                delay2(100);
             }
             
         }
@@ -3994,7 +3994,7 @@ void lcd_pick_babystep(){
             EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
             EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
             calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
-            delay(500);
+            delay2(500);
             
         }
     };
@@ -4448,7 +4448,7 @@ void lcd_language()
 	lcd_draw_update = 2;
 	while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
 	{
-		delay(50);
+		delay2(50);
 		lcd_update(0);
 		manage_heater();
 		manage_inactivity(true);
@@ -5111,7 +5111,7 @@ void bowden_menu() {
 				lcd_print(">");
 
 				enc_dif = lcd_encoder_diff;
-				delay(100);
+				delay2(100);
 		}
 
 		if (lcd_clicked()) {
@@ -5144,7 +5144,7 @@ void bowden_menu() {
 							enc_dif = lcd_encoder_diff;
 						}
 				}
-				delay(100);
+				delay2(100);
 				if (lcd_clicked()) {
 					EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
 					if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
@@ -5203,7 +5203,7 @@ static char snmm_stop_print_menu() { //menu for choosing which filaments will be
 				lcd_set_cursor(0, cursor_pos);
 				lcd_print(">");
 				enc_dif = lcd_encoder_diff;
-				delay(100);
+				delay2(100);
 			}
 		}
 		if (lcd_clicked()) {
@@ -5304,7 +5304,7 @@ uint8_t choose_menu_P(const char *header, const char *item, const char *last_ite
         lcd_set_cursor(0, cursor_pos);
         lcd_print(">");
 
-        delay(100);
+        delay2(100);
 
 		if (lcd_clicked())
 		{
@@ -5386,7 +5386,7 @@ char reset_menu() {
 				lcd_set_cursor(0, cursor_pos);
 				lcd_print(">");
 				enc_dif = lcd_encoder_diff;
-				delay(100);
+				delay2(100);
 			}
 
 		}
@@ -5509,7 +5509,7 @@ void unload_filament()
 	disable_e0();
 	disable_e1();
 	disable_e2();
-	delay(100);
+	delay2(100);
 
 	Sound_MakeSound(e_SOUND_TYPE_StandardPrompt);
 	uint8_t counterBeep = 0;
@@ -5574,11 +5574,11 @@ static void lcd_farm_no()
 
 		lcd_set_cursor(step, 3);
 		lcd_print("^");
-		delay(100);
+		delay2(100);
 
 		if (lcd_clicked())
 		{
-			delay(200);
+			delay2(200);
 			step++;
 			if(step == 3) {
 				_ret = 1;
@@ -5659,7 +5659,7 @@ unsigned char lcd_choose_color() {
 				lcd_set_cursor(0, cursor_pos);
 				lcd_print(">");
 				enc_dif = lcd_encoder_diff;
-				delay(100);
+				delay2(100);
 
 		}
 
@@ -5713,7 +5713,7 @@ void lcd_confirm_print()
 		lcd_puts_P(_T(MSG_NO));
 		lcd_set_cursor(0, 1 + cursor_pos);
 		lcd_print(">");
-		delay(100);
+		delay2(100);
 
 		_t = _t + 1;
 		if (_t>100)
@@ -5806,7 +5806,7 @@ static void lcd_main_menu()
     
         int tempScrool = 0;
         if (lcd_draw_update == 0 && LCD_CLICKED == 0)
-            //delay(100);
+            //delay2(100);
             return; // nothing to do (so don't thrash the SD card)
         uint16_t fileCnt = card.getnrfilenames();
         
@@ -5969,7 +5969,7 @@ void stack_error() {
 	SET_OUTPUT(BEEPER);
 if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
 	WRITE(BEEPER, HIGH);
-	delay(1000);
+	delay2(1000);
 	WRITE(BEEPER, LOW);
 	lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4
 	//err_triggered = 1;
@@ -6228,7 +6228,7 @@ void lcd_sdcard_menu()
 	  card.presort();
   }
   if (lcd_draw_update == 0 && LCD_CLICKED == 0)
-    //delay(100);
+    //delay2(100);
     return; // nothing to do (so don't thrash the SD card)
   uint16_t fileCnt = card.getnrfilenames();
 
@@ -6292,7 +6292,7 @@ bool lcd_selftest()
 	#ifdef TMC2130
 	  FORCE_HIGH_POWER_START;
 	#endif // TMC2130
-	delay(2000);
+	delay2(2000);
 	KEEPALIVE_STATE(IN_HANDLER);
 
 	_progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
@@ -6670,7 +6670,7 @@ static bool lcd_selfcheck_axis(int _axis, int _travel)
 		manage_heater();
 		manage_inactivity(true);
 
-		//delay(100);
+		//delay2(100);
 		(_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
 
 	} while (!_stepdone);
@@ -6788,7 +6788,7 @@ static bool lcd_selfcheck_endstops()
 		if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
 	}
 	plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[0] / 60, active_extruder);
-	delay(500);
+	delay2(500);
 
 	if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
 		((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
@@ -6983,11 +6983,11 @@ static void lcd_selftest_error(int _error_no, const char *_error_1, const char *
 		break;
 	}
 
-	delay(1000);
+	delay2(1000);
 	lcd_beeper_quick_feedback();
 
 	do {
-		delay(100);
+		delay2(100);
 		manage_heater();
 		manage_inactivity();
 	} while (!lcd_clicked());
@@ -7100,7 +7100,7 @@ static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
 		analogWrite(FAN_PIN, 255);
 		break;
 	}
-	delay(500);
+	delay2(500);
 
 	lcd_set_cursor(1, 2); lcd_puts_P(_T(MSG_SELFTEST_FAN_YES));
 	lcd_set_cursor(0, 3); lcd_print(">");
@@ -7148,7 +7148,7 @@ static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
 
 
 		manage_heater();
-		delay(100);
+		delay2(100);
 
 	} while (!lcd_clicked());
 	KEEPALIVE_STATE(IN_HANDLER);
@@ -7175,7 +7175,7 @@ static bool lcd_selftest_fan_dialog(int _fan)
 		fanSpeed = 0;
 		manage_heater();			//turn off fan
 		setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
-		delay(2000);				//delay_keep_alive would turn off extruder fan, because temerature is too low
+		delay2(2000);				//delay_keep_alive would turn off extruder fan, because temerature is too low
 		manage_heater();			//count average fan speed from 2s delay and turn off fans
 		if (!fan_speed[0]) _result = false;
 		//SERIAL_ECHOPGM("Extruder fan speed: ");

+ 2 - 2
Firmware/xyzcal.cpp

@@ -152,9 +152,9 @@ bool xyzcal_lineXYZ_to(int16_t x, int16_t y, int16_t z, uint16_t delay_us, int8_
 	sm4_set_dir_bits(xyzcal_dm);
 	sm4_stop_cb = check_pinda?((check_pinda<0)?check_pinda_0:check_pinda_1):0;
 	xyzcal_sm4_delay = delay_us;
-//	uint32_t u = micros();
+//	uint32_t u = micros2();
 	bool ret = sm4_line_xyze_ui(abs(x), abs(y), abs(z), 0)?true:false;
-//	u = micros() - u;
+//	u = micros2() - u;
 	return ret;
 }