-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusbctrl.h
More file actions
142 lines (111 loc) · 5.28 KB
/
usbctrl.h
File metadata and controls
142 lines (111 loc) · 5.28 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
/*
*
* 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_H_
#define USBCTRL_H_
#include "libc/types.h"
#include "libc/stdio.h"
#include "api/libusbctrl.h"
#include "libc/sanhandlers.h"
#ifndef __FRAMAC__
/*
* Here, we handle the case of differenciated FW/DFU mode.
* Is set (and only if set) we redefine unified macro value from the currently being
* compiled mode. If not, nothing is to be done here.
*/
#if defined(CONFIG_USR_LIB_USBCTRL_DIFFERENCIATE_DFU_FW_BUILD)
/* in that case, unified DEBUG, MAX_CFG and MAX_CTX are not defined, let's define them
* here. To differenciate DFU from FW mode, -DMODE_DFU is passed for DFU profile
* compilation units */
# if defined(MODE_DFU)
# define CONFIG_USBCTRL_MAX_CFG CONFIG_USBCTRL_DFU_MAX_CFG
# define CONFIG_USBCTRL_MAX_CTX CONFIG_USBCTRL_DFU_MAX_CTX
# define CONFIG_USR_LIB_USBCTRL_DEBUG CONFIG_USR_LIB_USBCTRL_DFU_DEBUG
# define CONFIG_USR_LIB_USBCTRL_DEV_PRODUCTID CONFIG_USR_LIB_USBCTRL_DFU_DEV_PRODUCTID
# else
# define CONFIG_USBCTRL_MAX_CFG CONFIG_USBCTRL_FW_MAX_CFG
# define CONFIG_USBCTRL_MAX_CTX CONFIG_USBCTRL_FW_MAX_CTX
# define CONFIG_USR_LIB_USBCTRL_DEBUG CONFIG_USR_LIB_USBCTRL_FW_DEBUG
# define CONFIG_USR_LIB_USBCTRL_DEV_PRODUCTID CONFIG_USR_LIB_USBCTRL_FW_DEV_PRODUCTID
# endif
#else
# define CONFIG_USR_LIB_USBCTRL_DEV_PRODUCTID CONFIG_USR_LIB_USBCTRL_DFU_DEV_PRODUCTID
#endif
#endif
/*********************************************************
* General tooling
*/
#if CONFIG_USR_LIB_USBCTRL_DEBUG
# define log_printf(...) printf(__VA_ARGS__)
#else
# define log_printf(...)
#endif
/************************************************
* about libctrl context
***********************************************/
#define MAX_INTERFACES_PER_DEVICE 4
typedef struct {
uint8_t first_free_epid; /* first free EP identifier (starting with 1, as 0 is control) */
uint8_t interface_num; /*< Number of interfaces registered */
usbctrl_interface_t interfaces[MAX_INTERFACES_PER_DEVICE]; /*< For each registered interface */
} usbctrl_configuration_t;
typedef enum {
USB_CTRL_RCV_FIFO_SATE_NOSTORAGE, /*< No receive FIFO set yet */
USB_CTRL_RCV_FIFO_SATE_FREE, /*< Receive FIFO is free (no active content in it) */
USB_CTRL_RCV_FIFO_SATE_BUSY, /*< Receive FIFO is locked. A provider is writing
data in it (DMA, trigger...) */
USB_CTRL_RCV_FIFO_SATE_READY /*< Receive FIFO is ready. There is content to get from
it, no provider is accessing it */
} ctrl_plane_rx_fifo_state_t;
typedef struct usbctrl_context {
/* first, about device driver interactions */
uint32_t dev_id; /*< device id, from the USB device driver */
uint16_t address; /*< device address, to be set by std req */
/* then current context state, associated to the USB standard state automaton */
uint8_t num_cfg; /*< number of different onfigurations */
uint8_t curr_cfg; /*< current configuration */
usbctrl_configuration_t cfg[CONFIG_USBCTRL_MAX_CFG]; /* configurations list */
uint8_t state; /*< USB state machine current state */
uint8_t ctrl_fifo[CONFIG_USBCTRL_EP0_FIFO_SIZE]; /* RECV FIFO for EP0 */
ctrl_plane_rx_fifo_state_t ctrl_fifo_state; /*< RECV FIFO of control plane state */
bool ctrl_req_processing; /* a control level request is being processed */
} usbctrl_context_t;
#if defined(__FRAMAC__)
/* library-private globals and symbols */
# include "usbctrl_framac.h"
/* all-level exported callbacks & prototypes */
# include "framac/entrypoint.h"
#endif
/*********************************************************
* Core API
*/
mbed_error_t usbctrl_get_context(uint32_t device_id,
usbctrl_context_t **ctx);
bool usbctrl_is_endpoint_exists(usbctrl_context_t *ctx, uint8_t ep);
bool usbctrl_is_endpoint_halted(usbctrl_context_t *ctx, uint8_t ep);
usb_ep_dir_t usbctrl_get_endpoint_direction(usbctrl_context_t *ctx, uint8_t ep);
bool usbctrl_is_interface_exists(usbctrl_context_t *ctx, uint8_t iface);
usbctrl_interface_t* usbctrl_get_interface(usbctrl_context_t *ctx, uint8_t iface);
mbed_error_t usbctrl_get_handler(usbctrl_context_t *ctx,
uint32_t *handler);
#endif/*!USBCTRL_H_*/