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
|
/* Copyright 2019 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* USB State Machine Framework */
#ifndef __CROS_EC_USB_SM_H
#define __CROS_EC_USB_SM_H
#define SM_OBJ(smo) ((struct sm_obj *)&smo)
#define SUPER(r, sig, s) ((((r) == 0) || ((sig) == ENTRY_SIG) || \
((sig) == EXIT_SIG)) ? 0 : ((uintptr_t)(s)))
#define RUN_SUPER 1
/* Local state machine states */
enum sm_local_state {
SM_INIT,
SM_RUN,
SM_PAUSED
};
/* State Machine signals */
enum signal {
ENTRY_SIG = 0,
RUN_SIG,
EXIT_SIG,
SUPER_SIG,
};
typedef unsigned int (*state_sig)(int port);
typedef unsigned int (*sm_state)(int port, enum signal sig);
struct sm_obj {
sm_state task_state;
sm_state last_state;
};
/**
* Initialize a State Machine
*
* @param port USB-C port number
* @param obj State machine object
* @param target Initial state of state machine
*/
void init_state(int port, struct sm_obj *obj, sm_state target);
/**
* Changes a state machines state
*
* @param port USB-C port number
* @param obj State machine object
* @param target State to transition to
* @return 0
*/
int set_state(int port, struct sm_obj *obj, sm_state target);
/**
* Executes a state machine
*
* @param port USB-C port number
* @param obj State machine object
* @param sig State machine signal
*/
void exe_state(int port, struct sm_obj *obj, enum signal sig);
#endif /* __CROS_EC_USB_SM_H */
|