当前位置:网站首页>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()))();
}
}
边栏推荐
- Quickly understand JVM structure and working principle
- 三体攻击(三维拆分加二分)
- 【云原生 | Kubernetes篇】深入了解Pod(六)
- AWS builds a virtual infrastructure including servers and networks (2)
- Three body attack (three-dimensional split plus two points)
- High rise building fire prevention
- Webrtc advantages and module splitting
- How do people over 40 allocate annuity insurance? Which product is more suitable?
- MATLAB小技巧(20)矩阵分析--主成分回归
- Operating principle of Rogowski coil
猜你喜欢

What is the bandwidth of the Tiktok server that can be used by hundreds of millions of people at the same time?

containerd1.5.5的安装

Kubernetes notes and the latest k3s installation introduction

Application of energy management system in iron and steel enterprises

罗氏线圈可以测量的大电流和频率范围

Discussion on the practice of fire emergency lighting system in the field of building electrical design
![[untitled]](/img/bb/213f213c695795daecb81a4cf2adcd.jpg)
[untitled]

AWS saves data on the cloud (3)

High rise building fire prevention

Explain observer mode
随机推荐
Not so Mobile
Copy & Deepcopy
【转载】STM32 GPIO类型
[cloud native | kubernetes] in depth understanding of pod (VI)
Characteristics and prevention of electrical fire
Quickly understand JVM structure and working principle
Key points of building fire protection design
Power data
【云原生 | Kubernetes篇】深入了解Pod(六)
Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...
【Go ~ 0到1 】 第二天 6月25 Switch语句,数组的声明与遍历
Construire le premier réseau neuronal avec pytorch et optimiser
Selenium reptile
AVFrame内存管理api
STL - inverter
【Go ~ 0到1 】 第三天 6月27 slice,map 与 函数
Webrtc advantages and module splitting
抖音服務器帶寬有多大,才能供上億人同時刷?
A - 深海探险
[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service