-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsm.c
137 lines (106 loc) · 4.62 KB
/
fsm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//****************************************************************************//
// MSP430 state machine
// fsm.c
//
// Describtion:
// A simple state machine for the MSP430
// Do not change code in here!!!
//
// Generated with Excel Table
// Date: 06/10/2021 Time: 14:34:34
//
//****************************************************************************//
#include <stdint.h>
#include <stdio.h>
#include "fsm.h"
//****************************************************************************//
// Global variables
//****************************************************************************//
uint8_t ActState;
const FSM_STATE_TABLE StateTable [NR_STATES][NR_EVENTS] =
{
NULL, ESPERA, NULL, ESPERA, NULL, ESPERA, NULL, ESPERA, FSM_SEC_ESPERA, ESPERASEC, NULL, ESPERA, NULL, ESPERA, NULL, ESPERA,
NULL, ESPERASEC, NULL, ESPERASEC, NULL, ESPERASEC, NULL, ESPERASEC, FSM_INICIA_JUEGO, DIGITA_SEC, NULL, ESPERASEC, NULL, ESPERASEC, NULL, ESPERASEC,
FSM_REVISA, DIGITA_SEC, FSM_REVISA, DIGITA_SEC, FSM_REVISA, DIGITA_SEC, FSM_REVISA, DIGITA_SEC, NULL, DIGITA_SEC, FSM_DESPLIEGA, DIGITA_SEC, FSM_PERDISTE, GAME_OVER, FSM_GANASTE, GAME_OVER,
NULL, GAME_OVER, NULL, GAME_OVER, NULL, GAME_OVER, NULL, GAME_OVER, FSM_LIMPIA, ESPERA, NULL, GAME_OVER, NULL, GAME_OVER, NULL, GAME_OVER
};
//****************************************************************************//
// Initialize state machine
//****************************************************************************//
void FSM_Init (void)
{
ActState = ESPERA;
}
//****************************************************************************//
// Event function "BTNR"
//****************************************************************************//
void FSM_BTNR (void)
{
if (StateTable[ActState][BTNR].ptrFunct != NULL)
StateTable[ActState][BTNR].ptrFunct();
ActState = StateTable[ActState][BTNR].NextState;
}
//****************************************************************************//
// Event function "BTNA"
//****************************************************************************//
void FSM_BTNA (void)
{
if (StateTable[ActState][BTNA].ptrFunct != NULL)
StateTable[ActState][BTNA].ptrFunct();
ActState = StateTable[ActState][BTNA].NextState;
}
//****************************************************************************//
// Event function "BTNV"
//****************************************************************************//
void FSM_BTNV (void)
{
if (StateTable[ActState][BTNV].ptrFunct != NULL)
StateTable[ActState][BTNV].ptrFunct();
ActState = StateTable[ActState][BTNV].NextState;
}
//****************************************************************************//
// Event function "BTNB"
//****************************************************************************//
void FSM_BTNB (void)
{
if (StateTable[ActState][BTNB].ptrFunct != NULL)
StateTable[ActState][BTNB].ptrFunct();
ActState = StateTable[ActState][BTNB].NextState;
}
//****************************************************************************//
// Event function "INICIO_RST"
//****************************************************************************//
void FSM_INICIO_RST (void)
{
if (StateTable[ActState][INICIO_RST].ptrFunct != NULL)
StateTable[ActState][INICIO_RST].ptrFunct();
ActState = StateTable[ActState][INICIO_RST].NextState;
}
//****************************************************************************//
// Event function "SEC_GOOD"
//****************************************************************************//
void FSM_SEC_GOOD (void)
{
if (StateTable[ActState][SEC_GOOD].ptrFunct != NULL)
StateTable[ActState][SEC_GOOD].ptrFunct();
ActState = StateTable[ActState][SEC_GOOD].NextState;
}
//****************************************************************************//
// Event function "SEC_BAD"
//****************************************************************************//
void FSM_SEC_BAD (void)
{
if (StateTable[ActState][SEC_BAD].ptrFunct != NULL)
StateTable[ActState][SEC_BAD].ptrFunct();
ActState = StateTable[ActState][SEC_BAD].NextState;
}
//****************************************************************************//
// Event function "SEC_WIN"
//****************************************************************************//
void FSM_SEC_WIN (void)
{
if (StateTable[ActState][SEC_WIN].ptrFunct != NULL)
StateTable[ActState][SEC_WIN].ptrFunct();
ActState = StateTable[ActState][SEC_WIN].NextState;
}
//****************************************************************************//