嵌入式设计模式:有限状态自动机的C语言实现

本文介绍了如何在嵌入式系统中利用C语言实现有限状态自动机的设计模式,展示了作者独特的编程思维和巧妙的指针操作技能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载自:https://www.cnblogs.com/autosar/archive/2012/06/22/2558604.html
很欣赏作者的编程思路,以及娴熟的指针使用技巧:
顺带再吧程序欣赏一遍。

typedef int State;
typedef int Condition;

#define STATES 3+1
#define STATES_1  0
#define STATES_2  1
#define STATES_3  2

#define STATES_TRAP 3
#define CONDITIONS 21
#define CONDITION_1  0
#define CONDITION_2  1

typedef void  (*ActionFunType)( State  state,  Condition conditon);
typedef struct
{
 State next;
ActionFunType  action;
}Trasition ,* pTrasition;

void  action_1 (  State  state,  Condition conditon );
void  action_2 (  State  state,  Condition conditon );
void  action_3 (  State  state,  Condition conditon );
Trastion t1={
STATE_2,
action_1,
};
Trastion t2={
STATE_3,
action_2,
};
Trastion t3={
STATE_2,
action_3,
};
Trastion tt={
STATE_TRAP,
action_trap,
};
void  action_1 (  State  state,  Condition conditon )
{
printf("Action 1 triggered  ! /r/n");
}
void  action_2 ( 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值