-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusbctrl_state.h
More file actions
257 lines (232 loc) · 8.97 KB
/
usbctrl_state.h
File metadata and controls
257 lines (232 loc) · 8.97 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
*
* Copyright 2018 The wookey project team <wookey@ssi.gouv.fr>
* - Ryad Benadjila
* - Arnauld Michelizza
* - Mathieu Renard
* - Philippe Thierry
* - Philippe Trebuchet
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* the Free Software Foundation; either version 3 of the License, or (at
* ur option) any later version.
*
* This package is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this package; if not, write to the Free Software Foundation, Inc., 51
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef USBCTRL_STATE_H_
#define USBCTRL_STATE_H_
#include "api/libusbctrl.h"
#include "usbctrl.h"
#include "usbctrl_requests.h"
/*
* USB device standard automaton. This automaton is described in USB 2.0 standard,
* Figure 9.1
*/
#ifndef __FRAMAC__
/* this enumerate is declared in libusbctrl_framac.h to handle specs usage
* of libusbctrl proof
*/
typedef enum {
USB_DEVICE_STATE_ATTACHED = 0, /* Attached but not powered. Should never be reached from device side */
USB_DEVICE_STATE_POWERED = 1, /* Attached and powered, first reset not received yet */
USB_DEVICE_STATE_SUSPENDED_POWER = 2, /* Suspended, from the Power state */
USB_DEVICE_STATE_SUSPENDED_DEFAULT = 3, /* Suspended, from the default state */
USB_DEVICE_STATE_SUSPENDED_ADDRESS = 4, /* Suspended, from the address state */
USB_DEVICE_STATE_SUSPENDED_CONFIGURED = 5, /* Suspended, from the configured state */
USB_DEVICE_STATE_DEFAULT = 6, /* First reset received, unique address not yet assigned */
USB_DEVICE_STATE_ADDRESS = 7, /* First reset received, address asigned, not yet configured */
USB_DEVICE_STATE_CONFIGURED = 8, /* First reset received, address asigned, configured, functions provided by the device can now be used */
USB_DEVICE_STATE_INVALID = 9 /* Not defined in the USB standard. exists as an INVALID case. Should not be reached */
} usb_device_state_t;
#endif/*!__FRAMAC__*/
/*
* device standard transitions (USB 2.0 standard, figure 9.1)
*/
typedef enum {
USB_DEVICE_TRANS_POWER_INTERRUPT = 0,
USB_DEVICE_TRANS_RESET,
USB_DEVICE_TRANS_BUS_INACTIVE,
USB_DEVICE_TRANS_BUS_ACTIVE,
USB_DEVICE_TRANS_HUB_CONFIGURED,
USB_DEVICE_TRANS_HUB_DECONFIGURED,
USB_DEVICE_TRANS_HUB_RESET,
USB_DEVICE_TRANS_ADDRESS_ASSIGNED,
USB_DEVICE_TRANS_DEV_CONFIGURED,
USB_DEVICE_TRANS_DEV_DECONFIGURED,
} usb_device_trans_t;
/*@ predicate is_valid_transition(usb_device_trans_t i) =
i == USB_DEVICE_TRANS_POWER_INTERRUPT ||
i == USB_DEVICE_TRANS_RESET ||
i == USB_DEVICE_TRANS_BUS_INACTIVE ||
i == USB_DEVICE_TRANS_BUS_ACTIVE ||
i == USB_DEVICE_TRANS_HUB_CONFIGURED ||
i == USB_DEVICE_TRANS_HUB_DECONFIGURED ||
i == USB_DEVICE_TRANS_HUB_RESET ||
i == USB_DEVICE_TRANS_ADDRESS_ASSIGNED ||
i == USB_DEVICE_TRANS_DEV_CONFIGURED ||
i == USB_DEVICE_TRANS_DEV_DECONFIGURED ;
*/
#if defined(__FRAMAC__)
#define MAX_TRANSITION_STATE 10
typedef struct usb_operation_code_transition {
uint8_t request;
uint8_t target_state;
} usb_request_code_transition_t;
static const struct {
usb_device_state_t state;
usb_request_code_transition_t req_trans[MAX_TRANSITION_STATE];
} usb_automaton[] = {
{USB_DEVICE_STATE_ATTACHED, {
{USB_DEVICE_TRANS_HUB_CONFIGURED, USB_DEVICE_STATE_POWERED},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
}
},
{USB_DEVICE_STATE_POWERED, {
{USB_DEVICE_TRANS_BUS_INACTIVE, USB_DEVICE_STATE_SUSPENDED_POWER},
{USB_DEVICE_TRANS_HUB_RESET, USB_DEVICE_STATE_ATTACHED},
{USB_DEVICE_TRANS_HUB_DECONFIGURED, USB_DEVICE_STATE_ATTACHED},
{USB_DEVICE_TRANS_RESET, USB_DEVICE_STATE_DEFAULT},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
}
},
{USB_DEVICE_STATE_SUSPENDED_POWER, {
{USB_DEVICE_TRANS_BUS_ACTIVE, USB_DEVICE_STATE_POWERED},
{USB_DEVICE_TRANS_RESET, USB_DEVICE_STATE_DEFAULT},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
}
},
{USB_DEVICE_STATE_SUSPENDED_DEFAULT, {
{USB_DEVICE_TRANS_BUS_ACTIVE, USB_DEVICE_STATE_DEFAULT},
{USB_DEVICE_TRANS_RESET, USB_DEVICE_STATE_DEFAULT},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
}
},
{USB_DEVICE_STATE_SUSPENDED_ADDRESS, {
{USB_DEVICE_TRANS_BUS_ACTIVE, USB_DEVICE_STATE_ADDRESS},
{USB_DEVICE_TRANS_RESET, USB_DEVICE_STATE_DEFAULT},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
}
},
{USB_DEVICE_STATE_SUSPENDED_CONFIGURED, {
{USB_DEVICE_TRANS_BUS_ACTIVE, USB_DEVICE_STATE_CONFIGURED},
{USB_DEVICE_TRANS_RESET, USB_DEVICE_STATE_DEFAULT},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
}
},
{USB_DEVICE_STATE_DEFAULT, {
{USB_DEVICE_TRANS_ADDRESS_ASSIGNED, USB_DEVICE_STATE_ADDRESS},
{USB_DEVICE_TRANS_BUS_INACTIVE, USB_DEVICE_STATE_SUSPENDED_DEFAULT},
{USB_DEVICE_TRANS_RESET, USB_DEVICE_STATE_DEFAULT},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
},
},
{USB_DEVICE_STATE_ADDRESS, {
{USB_DEVICE_TRANS_DEV_CONFIGURED, USB_DEVICE_STATE_CONFIGURED},
{USB_DEVICE_TRANS_BUS_INACTIVE, USB_DEVICE_STATE_SUSPENDED_ADDRESS},
{USB_DEVICE_TRANS_RESET, USB_DEVICE_STATE_DEFAULT},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
},
},
{USB_DEVICE_STATE_CONFIGURED, {
{USB_DEVICE_TRANS_DEV_DECONFIGURED, USB_DEVICE_STATE_ADDRESS},
{USB_DEVICE_TRANS_BUS_INACTIVE, USB_DEVICE_STATE_SUSPENDED_CONFIGURED},
{USB_DEVICE_TRANS_RESET, USB_DEVICE_STATE_DEFAULT},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
},
},
{USB_DEVICE_STATE_INVALID, {
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
{0xff, 0xff},
},
},
};
#endif/*__FRAMAC__*/
/*
* Return the current state of the USB device
*/
usb_device_state_t usbctrl_get_state(const usbctrl_context_t *ctx);
/*
* set the current state of the USB device
*/
mbed_error_t usbctrl_set_state(__out usbctrl_context_t *ctx,
__in usb_device_state_t newstate);
uint8_t usbctrl_next_state(usb_device_state_t current_state,
usb_device_trans_t request);
bool usbctrl_is_valid_transition(usb_device_state_t current_state,
usb_device_trans_t transition);
#endif/*!USBCTRL_STATE_H_*/