Code: Select all
if(taskOrder>4) taskOrder-=5;
switch (taskOrder) {
case 0:
taskOrder++;
#if MAG
if (Mag_getADC() != 0 ) break; // 320 µs
#endif
case 1:
taskOrder++;
#if BARO
if (Baro_update() != 0 ) break; // for MS baro: I2C set and get: 220 us - presure and temperature computation 160 us
#endif
case 2:
taskOrder++;
#if BARO
if (getEstimatedAltitude() !=0) break; // 280 us
#endif
case 3:
taskOrder++;
#if GPS
if(GPS_Enable) GPS_NewData(); // I2C GPS: 160 us with no new data / 1250us! with new data
break;
#endif
case 4:
taskOrder++;
#if SONAR
Sonar_update(); //debug[2] = sonarAlt;
#endif
#ifdef LANDING_LIGHTS_DDR
auto_switch_landing_lights();
#endif
#ifdef VARIOMETER
if (f.VARIO_MODE) vario_signaling();
#endif
break;
}
}
questions...
- why is the taskOrder variable increment statement redundantly included within each case block of the switch statement? It only needs to be coded once, either before or after the switch/case statement. It actually unnecessarily bloats the generated assembly code and simply looks ugly...
- why THE HELL is a subtraction op performed on the taskOrder variable in order to keep it within the range of 0-4:
Code: Select all
if(taskOrder>4) taskOrder-=5;
That does nothing for code clarity and only adds more overhead to the resultant machine code...
All that needs to be done is to set the variable to '0' and be done with it... Stuff like this can actually cause some pretty nasty bugs too.
I'd really like to know who wrote that, because this is just plain bad coding, and it hurts my eyes every time I look at it... Now that I'm diving more into the MWC code, I'm seeing a lot of bad coding practices, some small & others pretty big/dangerous...
Anyway, what I personally did was make the following changes...
Code: Select all
static uint8_t taskOrder=0; // never call all functions in the same loop, to avoid high delay spikes
switch (taskOrder) {
case 0:
#if MAG
if (Mag_getADC() != 0 ) break; // 320 µs
#endif
case 1:
...
}
taskOrder = (++taskOrder > 4) ? 0 : taskOrder;
one line of code takes care of everything; no more redundant, nested increment statements, no more subtraction.
Anyway, perhaps one of the MWC code maintainers might want to consider cleaning up that section of code...