optimisation: inline functions to reduce size

Change in memory:
Flash: -394 bytes
SRAM: 0 bytes

Breakdown:
|------------------------------------------------------------|
| Function name                            | Flash reduction |
|------------------------------------------| ----------------|
|CommandBase::FinishedOK                   | 182 bytes       |
|MovableBase::InitMovementNoReinitAxis     | 60 bytes        |
|TMC2130::CheckForErrors                   | 36 bytes        |
|Protocol::UInt16ToHex                     | 32 bytes        |
|AddErrorAxisBit                           | 24 bytes        |
|Application::CheckManualOperation         | 22 bytes        |
|CommandBase::GoToErrEngagingIdler         | 12 bytes        |
|Application::PlanCommand                  | 12 bytes        |
|Pulley::FinishHomingAndPlanMoveToParkPos  | 8 bytes         |
|Pulley::InitAxis                          | 4 bytes         |
|------------------------------------------------------------|
pull/245/head
Guðni Már Gilbert 2022-11-19 09:53:31 +00:00
parent c0189d81af
commit 74fbdb5149
6 changed files with 10 additions and 10 deletions

View File

@ -35,7 +35,7 @@ Application::Application()
, currentCommand(&logic::noCommand) , currentCommand(&logic::noCommand)
, currentCommandRq(mp::RequestMsgCodes::Reset, 0) {} , currentCommandRq(mp::RequestMsgCodes::Reset, 0) {}
void Application::CheckManualOperation() { void __attribute__((noinline)) Application::CheckManualOperation() {
uint16_t ms = mt::timebase.Millis(); uint16_t ms = mt::timebase.Millis();
constexpr uint16_t idleDelay = 1000U; constexpr uint16_t idleDelay = 1000U;
if (ms - lastCommandProcessedMs < idleDelay) { if (ms - lastCommandProcessedMs < idleDelay) {
@ -102,7 +102,7 @@ void Application::ReportCommandAccepted(const mp::RequestMsg &rq, mp::ResponseMs
modules::serial::WriteToUSART(tmp, len); modules::serial::WriteToUSART(tmp, len);
} }
void Application::PlanCommand(const modules::protocol::RequestMsg &rq) { void __attribute__((noinline)) Application::PlanCommand(const modules::protocol::RequestMsg &rq) {
if (currentCommand->State() == ProgressCode::OK) { if (currentCommand->State() == ProgressCode::OK) {
// We are allowed to start a new command as the previous one is in the OK finished state // We are allowed to start a new command as the previous one is in the OK finished state
// The previous command may be in an error state, but as long as it is in ProgressCode::OK (aka finished) // The previous command may be in an error state, but as long as it is in ProgressCode::OK (aka finished)

View File

@ -108,7 +108,7 @@ void TMC2130::SetEnabled(const MotorParams &params, bool enabled) {
this->enabled = enabled; this->enabled = enabled;
} }
bool TMC2130::CheckForErrors(const MotorParams &params) { bool __attribute__((noinline)) TMC2130::CheckForErrors(const MotorParams &params) {
if (!initialized) if (!initialized)
return false; return false;

View File

@ -39,7 +39,7 @@ static ErrorCode TMC2130ToErrorCode(const hal::tmc2130::ErrorFlags &ef) {
return e; return e;
} }
static ErrorCode AddErrorAxisBit(ErrorCode ec, uint8_t tmcIndex) { static ErrorCode __attribute__((noinline)) AddErrorAxisBit(ErrorCode ec, uint8_t tmcIndex) {
switch (tmcIndex) { switch (tmcIndex) {
case config::Axis::Pulley: case config::Axis::Pulley:
ec |= ErrorCode::TMC_PULLEY_BIT; ec |= ErrorCode::TMC_PULLEY_BIT;
@ -205,13 +205,13 @@ void CommandBase::GoToErrDisengagingIdler(ErrorCode deferredEC) {
mi::idler.Disengage(); mi::idler.Disengage();
} }
void CommandBase::GoToErrEngagingIdler() { void __attribute__((noinline)) CommandBase::GoToErrEngagingIdler() {
state = ProgressCode::ERREngagingIdler; state = ProgressCode::ERREngagingIdler;
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
mi::idler.Engage(mg::globals.ActiveSlot()); mi::idler.Engage(mg::globals.ActiveSlot());
} }
void CommandBase::FinishedOK() { void __attribute__((noinline)) CommandBase::FinishedOK() {
state = ProgressCode::OK; state = ProgressCode::OK;
error = ErrorCode::OK; error = ErrorCode::OK;
application.CommandFinishedCorrectly(); application.CommandFinishedCorrectly();

View File

@ -32,7 +32,7 @@ MovableBase::OperationResult MovableBase::InitMovement() {
} }
} }
MovableBase::OperationResult MovableBase::InitMovementNoReinitAxis() { MovableBase::OperationResult __attribute__((noinline)) MovableBase::InitMovementNoReinitAxis() {
PrepareMoveToPlannedSlot(); PrepareMoveToPlannedSlot();
state = Moving; state = Moving;
return OperationResult::Accepted; return OperationResult::Accepted;

View File

@ -327,7 +327,7 @@ uint8_t Protocol::UInt8ToHex(uint8_t value, uint8_t *dst) {
return charsOut; return charsOut;
} }
uint8_t Protocol::UInt16ToHex(uint16_t value, uint8_t *dst) { uint8_t __attribute__((noinline)) Protocol::UInt16ToHex(uint16_t value, uint8_t *dst) {
constexpr uint16_t topNibbleMask = 0xf000; constexpr uint16_t topNibbleMask = 0xf000;
if (value == 0) { if (value == 0) {
*dst = '0'; *dst = '0';

View File

@ -11,7 +11,7 @@ namespace pulley {
Pulley pulley; Pulley pulley;
bool Pulley::FinishHomingAndPlanMoveToParkPos() { bool __attribute__((noinline)) Pulley::FinishHomingAndPlanMoveToParkPos() {
mm::motion.SetPosition(mm::Pulley, 0); mm::motion.SetPosition(mm::Pulley, 0);
return true; return true;
} }
@ -46,7 +46,7 @@ int32_t Pulley::CurrentPosition_mm() {
return mm::axisUnitToTruncatedUnit<config::U_mm>(mm::motion.CurPosition<mm::Pulley>()); return mm::axisUnitToTruncatedUnit<config::U_mm>(mm::motion.CurPosition<mm::Pulley>());
} }
void Pulley::InitAxis() { void __attribute__((noinline)) Pulley::InitAxis() {
mm::motion.InitAxis(mm::Pulley); mm::motion.InitAxis(mm::Pulley);
} }