Skip to content

Commit 429f5a1

Browse files
raiden00plxiaoxiang781216
authored andcommitted
examples/foc: terminate the control thread if no work to do
1 parent 420da45 commit 429f5a1

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

examples/foc/foc_fixed16_thr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp)
352352
PRINTF("ERROR: foc_dev_params_set failed %d!\n", ret);
353353
goto errout;
354354
}
355+
356+
/* Terminate control thread */
357+
358+
if (motor.ctrl_state == FOC_CTRL_STATE_TERMINATE)
359+
{
360+
PRINTF("TERMINATE CTRL THREAD\n");
361+
goto errout;
362+
}
355363
}
356364
else
357365
{

examples/foc/foc_float_thr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,14 @@ int foc_float_thr(FAR struct foc_ctrl_env_s *envp)
353353
PRINTF("ERROR: foc_dev_prams_set failed %d!\n", ret);
354354
goto errout;
355355
}
356+
357+
/* Terminate control thread */
358+
359+
if (motor.ctrl_state == FOC_CTRL_STATE_TERMINATE)
360+
{
361+
PRINTF("TERMINATE CTRL THREAD\n");
362+
goto errout;
363+
}
356364
}
357365
else
358366
{

examples/foc/foc_motor_b16.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,13 @@ int foc_motor_control(FAR struct foc_motor_b16_s *motor)
11201120
break;
11211121
}
11221122

1123+
case FOC_CTRL_STATE_TERMINATE:
1124+
{
1125+
/* Do nothing */
1126+
1127+
break;
1128+
}
1129+
11231130
default:
11241131
{
11251132
PRINTF("ERROR: invalid ctrl_state=%d\n", motor->ctrl_state);

examples/foc/foc_motor_f32.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,19 @@ int foc_motor_control(FAR struct foc_motor_f32_s *motor)
11121112
{
11131113
motor->foc_mode = FOC_HANDLER_MODE_IDLE;
11141114

1115+
#ifndef CONFIG_EXAMPLES_FOC_HAVE_RUN
1116+
/* Terminate */
1117+
1118+
motor->ctrl_state += 1;
1119+
#endif
1120+
1121+
break;
1122+
}
1123+
1124+
case FOC_CTRL_STATE_TERMINATE:
1125+
{
1126+
/* Do nothing */
1127+
11151128
break;
11161129
}
11171130

examples/foc/foc_thr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ enum foc_controller_state_e
8888
FOC_CTRL_STATE_RUN_INIT,
8989
FOC_CTRL_STATE_RUN,
9090
#endif
91-
FOC_CTRL_STATE_IDLE
91+
FOC_CTRL_STATE_IDLE,
92+
FOC_CTRL_STATE_TERMINATE
9293
};
9394

9495
/* FOC thread data */

0 commit comments

Comments
 (0)