嵌入式导论练习题2
Introduction to Embedded Systems
Exercise 2 MOC-stateChartStatechart
- Advantages of StateCharts
What are the most important extensions of the StateChart model in
comparison to an ordinary Finite state machine (FSM)?
状态图可以对层次结构和并发进行建模。可以警戒(有条件地启用)转换。此外,转换可以与操作相关联。 操作可以与操作相关联。 操作可以对变量执行计算,并生成新事件。状态图(Statechart Diagram)是描述一个实体基于事件反应的动态行为,显示了该实体如何根据当前所处的状态对不同的事件做出反应。
- Disadvantages of StateCharts
What are the disadvantages of the StateChart formalism?
虽然StateChart比普通的FSM更好,但是它们在大型系统中的规模越来越大,往往很难理解。 重复使用的潜力是有限的。 与转换相关的操作提供了强大的扩展,但另一方面,广泛使用的操作将部分系统状态信息从状态本身移动到变量。 这种隐藏状态使系统分析困难。
- Tree of states for StateChart
Given the StateChart in Figure 1. Draw the state space of the StateChart
as a tree, which shows the hierarchy of states anddenotes the state types
(basic state, sequential states, and parallel states).
ex1.jpg
image.png
- Formal computation of state space
How would you formally compute the set of states? Compute the set of
states for the hierarchical automata which is defined bythe StateChart from
Fig.1
image.png
- Analysis
The automaton defined by the StateChart from Fig. 1 passes through a
number of states, when external events are applied.Show the sequence of
state that are passed through, starting from the initial state, for the
following sequence of events:
image.png
- Conversion of StateChart to a finite state machine (FSM)
Draw a finite state machine which is equivalent to the StateChart from
Fig. 1. Minimize the number of states.
image.png
image.png
- StateChart model of a vending machine
The StateChart model of a simplified vending machine is shown in Figure
2.
- Describe the trace of transitions occurring when the user inserts a coin and orders a tea.
image.png
-
The control of the vending machine has a bug that allows the user to cheat.
Describe the trace of transitions that illustratethe bug.
image.png
-
Draw the corresponding StateChart that fixes the bug.
Bug:
ex2.jpg
Correct:
image.png
Simulated:
设置一个人想要喝咖啡的状态:
输入事件:
coin_in=1;
cancel=0;
drink_ready=1
req_tea=0;
req_coffee=0;
image.png
仿真结果为:
输出事件
start_coffee=1;
start_tea=0;
coin_out=0;
验证模型是正确的,输出为
image.png