Инлайном лечится все, я проверял. Например, аналогичное под инлайном на высшей оптимизации под ИАРом ускоряется существенно. #pragma inline=forced
void StopMotor(char i)
{ switch (i)
{
#ifdef HTIM
case 1: OCR1AL=PWM_TOP+1; MOTOR1_STOP; break;
case 2: OCR1BL=PWM_TOP+1; MOTOR2_STOP; break;
#endif
#ifdef HTIT
case 1: OCR1AL=PWM_TOP+1; MOTOR1_STOP;; break;
#endif
#ifdef HTIP
case 1: OCR1AL=PWM_TOP+1; MOTOR1_STOP; break;
case 2: OCR1BL=PWM_TOP+1; MOTOR2_STOP; break;
case 3: OCR3AL=PWM_TOP+1; MOTOR3_STOP; break;
case 4: OCR3BL=PWM_TOP+1; MOTOR4_STOP; break;
#endif
}
}
#pragma inline=forced
void Forward(char i)
{ switch (i)
{ case 1: MOTOR1_FORWARD; break;
#ifdef HTIM
case 2: MOTOR2_FORWARD; break;
#endif
#ifdef HTIP
case 2: MOTOR2_FORWARD; break;
case 3: MOTOR3_FORWARD; break;
case 4: MOTOR4_FORWARD; break;
#endif
}
}
#pragma inline=forced
void Backward(char i)
{ switch (i)
{ case 1: MOTOR1_BACKWARD; break;
#ifdef HTIM
case 2: MOTOR2_BACKWARD; break;
#endif
#ifdef HTIP
case 2: MOTOR2_BACKWARD; break;
case 3: MOTOR3_BACKWARD; break;
case 4: MOTOR4_BACKWARD; break;
#endif
}
}
#pragma inline=forced
void SetPosPower(char i)
{
switch (i)
{ case 1: OCR1AL=PWM_TOP - moa.last_power; break;
#ifdef HTIM
case 2: OCR1BL=PWM_TOP - mob.last_power; break;
#endif
#ifdef HTIP
case 2: OCR1BL=PWM_TOP - mob.last_power; break;
case 3: OCR3AL=PWM_TOP - moc.last_power; break;
case 4: OCR3BL=PWM_TOP - mod.last_power; break;
#endif
}
}
#pragma inline=forced
void SetNegPower(char i)
{ switch (i)
{ case 1: OCR1AL=PWM_TOP + moa.last_power; break;
#ifdef HTIM
case 2: OCR1BL=PWM_TOP + mob.last_power; break;
#endif
#ifdef HTIP
case 2: OCR1BL=PWM_TOP + mob.last_power; break;
case 3: OCR3AL=PWM_TOP + moc.last_power; break;
case 4: OCR3BL=PWM_TOP + mod.last_power; break;
#endif
}
}
#pragma inline=forced
char Fault(char i)
{ switch (i)
{ case 1: return (char)FAULT1;
#ifdef HTIM
case 2: return (char)FAULT2;
#endif
#ifdef HTIP
case 2: return (char)FAULT2;
case 3: return (char)FAULT3;
case 4: return (char)FAULT4;
#endif
default: return 0;
}
}
#ifdef HTIM
#pragma inline=forced
char Sleep(char i)
{ switch (i)
{
case 1: return (char)SLEEP1;
case 2: return (char)SLEEP2;
default: return 0;
}
}
#endif
#pragma inline=forced
void MotorService( char i)
{ mo_type * mop=mo[i-1];
if (!mop->time)
{ StopMotor(i);
mop->state=moSTOPPED;
mop->last_power=0;
}
else
{ if (mop->power==0)
{ StopMotor(i);
mop->state=moSTOPPED;
mop->last_power=0;
}
else
{ if (mop->last_power<mop->power)
mop->last_power++;
else
{ if (mop->last_power>mop->power)
mop->last_power--;
}
if (mop->last_power>0)
{ SetPosPower(i);
Forward(i);
mop->state=moFORWARD;
}
else
{ SetNegPower(i);
Backward(i);
mop->state=moBACKWARD;
}
}
mop->time--;
}
#ifdef HTIM
if (Sleep(i))
mop->state=moSLEEP;
if (mop->current>OVERCURRENT_LIMIT)
{ if (mop->overcurrent_time<OVERCURRENT_DELAY)
mop->overcurrent_time++;
}
else mop->overcurrent_time=0;
if (mop->current>OVERCURRENT_LIMIT)
{ if (mop->overcurrent_time<OVERCURRENT_DELAY)
mop->overcurrent_time++;
}
else mop->overcurrent_time=0;
#else
if (Fault(i)) mop->state=moFAILURE;
#endif
}
void MotorsService(void)
{ MotorService(1);
#ifdef HTIM
MotorService(2);
#endif
#ifdef HTIP
MotorService(2);
MotorService(3);
MotorService(4);
#endif
}