Pretest DEBUG_X constants for non-zero and && the test with all existing

& tests of the debug_flags. Currently the compiler is able to eliminate
the block and the & operation when the constant is zero, but since
the debug_flags variable is a volatile the compiler does not eliminate
the load of the variable. By pretesting and shortcutting the load is
eliminated. Saves a small number of bytes when the debug build is
disabled and costs nothing when it is enabled.
This commit is contained in:
Jim McGee 2011-05-08 22:18:12 -07:00 committed by Michael Moon
parent f22e691fee
commit 85a9f63dfb
6 changed files with 31 additions and 31 deletions

View File

@ -36,7 +36,7 @@ void clock_250ms() {
} }
ifclock(clock_flag_1s) { ifclock(clock_flag_1s) {
if (debug_flags & DEBUG_POSITION) { if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION)) {
// current position // current position
sersendf_P(PSTR("Pos: %ld,%ld,%ld,%ld,%lu\n"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F); sersendf_P(PSTR("Pos: %ld,%ld,%ld,%ld,%lu\n"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F);

20
dda.c
View File

@ -177,7 +177,7 @@ void dda_create(DDA *dda, TARGET *target) {
// initialise DDA to a known state // initialise DDA to a known state
dda->allflags = 0; dda->allflags = 0;
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
serial_writestr_P(PSTR("\n{DDA_CREATE: [")); serial_writestr_P(PSTR("\n{DDA_CREATE: ["));
// we end at the passed target // we end at the passed target
@ -193,7 +193,7 @@ void dda_create(DDA *dda, TARGET *target) {
dda->z_direction = (target->Z >= startpoint.Z)?1:0; dda->z_direction = (target->Z >= startpoint.Z)?1:0;
dda->e_direction = (target->E >= startpoint.E)?1:0; dda->e_direction = (target->E >= startpoint.E)?1:0;
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
sersendf_P(PSTR("%ld,%ld,%ld,%ld] ["), target->X - startpoint.X, target->Y - startpoint.Y, target->Z - startpoint.Z, target->E - startpoint.E); sersendf_P(PSTR("%ld,%ld,%ld,%ld] ["), target->X - startpoint.X, target->Y - startpoint.Y, target->Z - startpoint.Z, target->E - startpoint.E);
dda->total_steps = dda->x_delta; dda->total_steps = dda->x_delta;
@ -204,7 +204,7 @@ void dda_create(DDA *dda, TARGET *target) {
if (dda->e_delta > dda->total_steps) if (dda->e_delta > dda->total_steps)
dda->total_steps = dda->e_delta; dda->total_steps = dda->e_delta;
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
sersendf_P(PSTR("ts:%lu"), dda->total_steps); sersendf_P(PSTR("ts:%lu"), dda->total_steps);
if (dda->total_steps == 0) { if (dda->total_steps == 0) {
@ -230,7 +230,7 @@ void dda_create(DDA *dda, TARGET *target) {
if (distance < 2) if (distance < 2)
distance = dda->e_delta * UM_PER_STEP_E; distance = dda->e_delta * UM_PER_STEP_E;
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
sersendf_P(PSTR(",ds:%lu"), distance); sersendf_P(PSTR(",ds:%lu"), distance);
#ifdef ACCELERATION_TEMPORAL #ifdef ACCELERATION_TEMPORAL
@ -287,7 +287,7 @@ void dda_create(DDA *dda, TARGET *target) {
if (dda->end_c < c_limit) if (dda->end_c < c_limit)
dda->end_c = c_limit; dda->end_c = c_limit;
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
sersendf_P(PSTR(",md:%lu,c:%lu"), move_duration, dda->c >> 8); sersendf_P(PSTR(",md:%lu,c:%lu"), move_duration, dda->c >> 8);
if (dda->c != dda->end_c) { if (dda->c != dda->end_c) {
@ -307,24 +307,24 @@ void dda_create(DDA *dda, TARGET *target) {
// we'll have to do it a few different ways depending on the msb locations of each // we'll have to do it a few different ways depending on the msb locations of each
if ((msb_tot + msb_ssq) <= 30) { if ((msb_tot + msb_ssq) <= 30) {
// we have room to do all the multiplies first // we have room to do all the multiplies first
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
serial_writechar('A'); serial_writechar('A');
dda->n = ((int32_t) (dda->total_steps * ssq) / dsq) + 1; dda->n = ((int32_t) (dda->total_steps * ssq) / dsq) + 1;
} }
else if (msb_tot >= msb_ssq) { else if (msb_tot >= msb_ssq) {
// total steps has more precision // total steps has more precision
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
serial_writechar('B'); serial_writechar('B');
dda->n = (((int32_t) dda->total_steps / dsq) * (int32_t) ssq) + 1; dda->n = (((int32_t) dda->total_steps / dsq) * (int32_t) ssq) + 1;
} }
else { else {
// otherwise // otherwise
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
serial_writechar('C'); serial_writechar('C');
dda->n = (((int32_t) ssq / dsq) * (int32_t) dda->total_steps) + 1; dda->n = (((int32_t) ssq / dsq) * (int32_t) dda->total_steps) + 1;
} }
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
sersendf_P(PSTR("\n{DDA:CA end_c:%lu, n:%ld, md:%lu, ssq:%lu, esq:%lu, dsq:%lu, msbssq:%u, msbtot:%u}\n"), dda->end_c >> 8, dda->n, move_duration, ssq, esq, dsq, msb_ssq, msb_tot); sersendf_P(PSTR("\n{DDA:CA end_c:%lu, n:%ld, md:%lu, ssq:%lu, esq:%lu, dsq:%lu, msbssq:%u, msbtot:%u}\n"), dda->end_c >> 8, dda->n, move_duration, ssq, esq, dsq, msb_ssq, msb_tot);
dda->accel = 1; dda->accel = 1;
@ -349,7 +349,7 @@ void dda_create(DDA *dda, TARGET *target) {
#endif #endif
} }
if (debug_flags & DEBUG_DDA) if (DEBUG_DDA && (debug_flags & DEBUG_DDA))
serial_writestr_P(PSTR("] }\n")); serial_writestr_P(PSTR("] }\n"));
// next dda starts where we finish // next dda starts where we finish

View File

@ -127,12 +127,12 @@ void gcode_parse_char(uint8_t c) {
switch (last_field) { switch (last_field) {
case 'G': case 'G':
next_target.G = read_digit.mantissa; next_target.G = read_digit.mantissa;
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_uint8(next_target.G); serwrite_uint8(next_target.G);
break; break;
case 'M': case 'M':
next_target.M = read_digit.mantissa; next_target.M = read_digit.mantissa;
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_uint8(next_target.M); serwrite_uint8(next_target.M);
break; break;
case 'X': case 'X':
@ -140,7 +140,7 @@ void gcode_parse_char(uint8_t c) {
next_target.target.X = decfloat_to_int(&read_digit, STEPS_PER_IN_X, 0); next_target.target.X = decfloat_to_int(&read_digit, STEPS_PER_IN_X, 0);
else else
next_target.target.X = decfloat_to_int(&read_digit, STEPS_PER_M_X, 1); next_target.target.X = decfloat_to_int(&read_digit, STEPS_PER_M_X, 1);
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_int32(next_target.target.X); serwrite_int32(next_target.target.X);
break; break;
case 'Y': case 'Y':
@ -148,7 +148,7 @@ void gcode_parse_char(uint8_t c) {
next_target.target.Y = decfloat_to_int(&read_digit, STEPS_PER_IN_Y, 0); next_target.target.Y = decfloat_to_int(&read_digit, STEPS_PER_IN_Y, 0);
else else
next_target.target.Y = decfloat_to_int(&read_digit, STEPS_PER_M_Y, 1); next_target.target.Y = decfloat_to_int(&read_digit, STEPS_PER_M_Y, 1);
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_int32(next_target.target.Y); serwrite_int32(next_target.target.Y);
break; break;
case 'Z': case 'Z':
@ -156,7 +156,7 @@ void gcode_parse_char(uint8_t c) {
next_target.target.Z = decfloat_to_int(&read_digit, STEPS_PER_IN_Z, 0); next_target.target.Z = decfloat_to_int(&read_digit, STEPS_PER_IN_Z, 0);
else else
next_target.target.Z = decfloat_to_int(&read_digit, STEPS_PER_M_Z, 1); next_target.target.Z = decfloat_to_int(&read_digit, STEPS_PER_M_Z, 1);
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_int32(next_target.target.Z); serwrite_int32(next_target.target.Z);
break; break;
case 'E': case 'E':
@ -164,7 +164,7 @@ void gcode_parse_char(uint8_t c) {
next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_IN_E, 0); next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_IN_E, 0);
else else
next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_M_E, 1); next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_M_E, 1);
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_uint32(next_target.target.E); serwrite_uint32(next_target.target.E);
break; break;
case 'F': case 'F':
@ -173,7 +173,7 @@ void gcode_parse_char(uint8_t c) {
next_target.target.F = decfloat_to_int(&read_digit, 25400, 1); next_target.target.F = decfloat_to_int(&read_digit, 25400, 1);
else else
next_target.target.F = decfloat_to_int(&read_digit, 1, 0); next_target.target.F = decfloat_to_int(&read_digit, 1, 0);
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_uint32(next_target.target.F); serwrite_uint32(next_target.target.F);
break; break;
case 'S': case 'S':
@ -187,27 +187,27 @@ void gcode_parse_char(uint8_t c) {
next_target.S = decfloat_to_int(&read_digit, PID_SCALE, 0); next_target.S = decfloat_to_int(&read_digit, PID_SCALE, 0);
else else
next_target.S = decfloat_to_int(&read_digit, 1, 0); next_target.S = decfloat_to_int(&read_digit, 1, 0);
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_uint16(next_target.S); serwrite_uint16(next_target.S);
break; break;
case 'P': case 'P':
next_target.P = decfloat_to_int(&read_digit, 1, 0); next_target.P = decfloat_to_int(&read_digit, 1, 0);
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_uint16(next_target.P); serwrite_uint16(next_target.P);
break; break;
case 'T': case 'T':
next_target.T = read_digit.mantissa; next_target.T = read_digit.mantissa;
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_uint8(next_target.T); serwrite_uint8(next_target.T);
break; break;
case 'N': case 'N':
next_target.N = decfloat_to_int(&read_digit, 1, 0); next_target.N = decfloat_to_int(&read_digit, 1, 0);
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_uint32(next_target.N); serwrite_uint32(next_target.N);
break; break;
case '*': case '*':
next_target.checksum_read = decfloat_to_int(&read_digit, 1, 0); next_target.checksum_read = decfloat_to_int(&read_digit, 1, 0);
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serwrite_uint8(next_target.checksum_read); serwrite_uint8(next_target.checksum_read);
break; break;
} }
@ -222,7 +222,7 @@ void gcode_parse_char(uint8_t c) {
// new field? // new field?
if ((c >= 'A' && c <= 'Z') || c == '*') { if ((c >= 'A' && c <= 'Z') || c == '*') {
last_field = c; last_field = c;
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serial_writechar(c); serial_writechar(c);
} }
@ -331,7 +331,7 @@ void gcode_parse_char(uint8_t c) {
// end of line // end of line
if ((c == 10) || (c == 13)) { if ((c == 10) || (c == 13)) {
if (debug_flags & DEBUG_ECHO) if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO))
serial_writechar(c); serial_writechar(c);
if ( if (

View File

@ -273,7 +273,7 @@ void process_gcode_command() {
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
if (debug_flags & DEBUG_POSITION) if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION))
print_queue(); print_queue();
#endif #endif
} }

View File

@ -240,7 +240,7 @@ void heater_tick(heater_t h, temp_sensor_t t, uint16_t current_temp, uint16_t ta
pid_output = pid_output_intermed & 0xFF; pid_output = pid_output_intermed & 0xFF;
#ifdef DEBUG #ifdef DEBUG
if (debug_flags & DEBUG_PID) if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR("T{E:%d, P:%d * %ld = %ld / I:%d * %ld = %ld / D:%d * %ld = %ld # O: %ld = %u}\n"), t_error, heater_p, heaters_pid[h].p_factor, (int32_t) heater_p * heaters_pid[h].p_factor / PID_SCALE, heaters_runtime[h].heater_i, heaters_pid[h].i_factor, (int32_t) heaters_runtime[h].heater_i * heaters_pid[h].i_factor / PID_SCALE, heater_d, heaters_pid[h].d_factor, (int32_t) heater_d * heaters_pid[h].d_factor / PID_SCALE, pid_output_intermed, pid_output); sersendf_P(PSTR("T{E:%d, P:%d * %ld = %ld / I:%d * %ld = %ld / D:%d * %ld = %ld # O: %ld = %u}\n"), t_error, heater_p, heaters_pid[h].p_factor, (int32_t) heater_p * heaters_pid[h].p_factor / PID_SCALE, heaters_runtime[h].heater_i, heaters_pid[h].i_factor, (int32_t) heaters_runtime[h].heater_i * heaters_pid[h].i_factor / PID_SCALE, heater_d, heaters_pid[h].d_factor, (int32_t) heater_d * heaters_pid[h].d_factor / PID_SCALE, pid_output_intermed, pid_output);
#endif #endif
#else #else
@ -324,7 +324,7 @@ void heater_set(heater_t index, uint8_t value) {
if (heaters[index].heater_pwm) { if (heaters[index].heater_pwm) {
*(heaters[index].heater_pwm) = value; *(heaters[index].heater_pwm) = value;
#ifdef DEBUG #ifdef DEBUG
if (debug_flags & DEBUG_PID) if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR("PWM{%u = %u}\n"), index, OCR0A); sersendf_P(PSTR("PWM{%u = %u}\n"), index, OCR0A);
#endif #endif
} }

6
temp.c
View File

@ -177,7 +177,7 @@ void temp_sensor_tick() {
if (pgm_read_word(&(temptable[table_num][j][0])) > temp) { if (pgm_read_word(&(temptable[table_num][j][0])) > temp) {
// Thermistor table is already in 14.2 fixed point // Thermistor table is already in 14.2 fixed point
#ifndef EXTRUDER #ifndef EXTRUDER
if (debug_flags & DEBUG_PID) if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR("pin:%d Raw ADC:%d table entry: %d"),temp_sensors[i].temp_pin,temp,j); sersendf_P(PSTR("pin:%d Raw ADC:%d table entry: %d"),temp_sensors[i].temp_pin,temp,j);
#endif #endif
// Linear interpolating temperature value // Linear interpolating temperature value
@ -204,14 +204,14 @@ void temp_sensor_tick() {
// (x₁ - x₀) // (x₁ - x₀)
(pgm_read_word(&(temptable[table_num][j][0])) - pgm_read_word(&(temptable[table_num][j-1][0]))); (pgm_read_word(&(temptable[table_num][j][0])) - pgm_read_word(&(temptable[table_num][j-1][0])));
#ifndef EXTRUDER #ifndef EXTRUDER
if (debug_flags & DEBUG_PID) if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR(" temp:%d.%d"),temp/4,(temp%4)*25); sersendf_P(PSTR(" temp:%d.%d"),temp/4,(temp%4)*25);
#endif #endif
break; break;
} }
} }
#ifndef EXTRUDER #ifndef EXTRUDER
if (debug_flags & DEBUG_PID) if (DEBUG_PID && (debug_flags & DEBUG_PID))
sersendf_P(PSTR(" Sensor:%d\n"),i); sersendf_P(PSTR(" Sensor:%d\n"),i);
#endif #endif