当前位置:网站首页>State machine program framework
State machine program framework
2022-06-28 08:49:00 【DingUXiu】
state.h
#ifndef __STATE_H
#define __STATE_H
// Define state machine function pointers
typedef void (*state_func_p)(void);
#endif
state.c
#include "state.h"
// Record the current status , Implement state loop
static state_func_p g_state_cur = NULL;
//func: The state to jump to
void main_setState(state_func_p func){
g_state_cur = func;
}
// Get current status
state_func_p main_getState(void){
return g_state_funcCur;
}
Encapsulated into get、set Function for the upper layer to call
main.c
#include "state.h"
// Idle state
void main_stateIdle(void){
// Function realization
if( Began to run ){
main_setState(main_stateRun);
}
if( An error occurred ){
main_setState(main_stateError);
}
}
// Running state
void main_stateRun(void){
// Function realization
if( Stop running ){
main_setState(main_stateIdle);
}
if( An error occurred ){
main_setState(main_stateError);
}
}
// Error status
void main_stateError(void){
// Function realization
if( Error elimination ){
main_setState(main_stateIdle);
}
}
int main(void){
// Set to idle state initially
main_setState(main_stateIdle);
while(1){
(*(main_getState()))();
}
}
边栏推荐
- Login common test case
- 三体攻击(三维拆分加二分)
- Cloudcompare & PCL point cloud clipping (based on closed surfaces or polygons)
- Almost Union-Find(带权并查集)
- FatMouse and Cheese
- Selenium reptile
- Integer partition
- High rise building fire prevention
- Idea related issues
- Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
猜你喜欢

Large current and frequency range that can be measured by Rogowski coil

Mysql8.0 forgot the root password

Superimposed ladder diagram and line diagram and merged line diagram and needle diagram

【无标题】

Application of current limiting protector in preventing electrical fire in shopping malls

Comment supprimer le crosstalk SiC MOSFET?

第六届智能家居亚洲峰会暨精品展(Smart Home Asia 2022)将于10月在沪召开

广州:金融新活水 文企新机遇

Discussion on the practice of fire emergency lighting system in the field of building electrical design

【大案例】学成在线网站
随机推荐
Potential safety hazards in elderly care facilities
webrtc优势与模块拆分
叠加阶梯图和线图及合并线图和针状图
Force buckle 1884 Egg drop - two eggs
电子元器件销售ERP管理系统哪个比较好?
DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...
WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持
Redis deployment under Linux & redis startup
【Go ~ 0到1 】 第一天 6月24 变量,条件判断 循环语句
Power data
[go ~ 0 to 1] the third day June 27 slice, map and function
神殿
Using transform:scale causes the page mouse hover event to disappear
Selenium reptile
第六届智能家居亚洲峰会暨精品展(Smart Home Asia 2022)将于10月在沪召开
使用transform:scale之后导致页面鼠标悬浮事件消失
用Pytorch搭建第一个神经网络且进行优化
[introduction to SQL in 10 days] day5+6 consolidated table
[go ~ 0 to 1] on the first day, June 24, variables, conditional judgment cycle statement
RAC enable archive log