Open FFBoard
Open source force feedback firmware
ohci.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_OHCI_H_
28#define _TUSB_OHCI_H_
29
30#ifdef __cplusplus
31 extern "C" {
32#endif
33
34//--------------------------------------------------------------------+
35// OHCI CONFIGURATION & CONSTANTS
36//--------------------------------------------------------------------+
37#define HOST_HCD_XFER_INTERRUPT // TODO interrupt is used widely, should always be enabled
38#define OHCI_PERIODIC_LIST (defined HOST_HCD_XFER_INTERRUPT || defined HOST_HCD_XFER_ISOCHRONOUS)
39
40// TODO merge OHCI with EHCI
41enum {
42 OHCI_MAX_ITD = 4
43};
44
45#define ED_MAX (CFG_TUH_DEVICE_MAX*CFG_TUH_ENDPOINT_MAX)
46#define GTD_MAX ED_MAX
47
48// tinyUSB's OHCI implementation caps number of EDs to 8 bits
49TU_VERIFY_STATIC (ED_MAX <= 256, "Reduce CFG_TUH_DEVICE_MAX or CFG_TUH_ENDPOINT_MAX");
50
51//--------------------------------------------------------------------+
52// OHCI Data Structure
53//--------------------------------------------------------------------+
54typedef struct {
55 uint32_t interrupt_table[32];
56 volatile uint16_t frame_number;
57 volatile uint16_t frame_pad;
58 volatile uint32_t done_head;
59 uint8_t reserved[116+4]; // TODO try to make use of this area if possible, extra 4 byte to make the whole struct size = 256
60}ohci_hcca_t; // TU_ATTR_ALIGNED(256)
61
62TU_VERIFY_STATIC( sizeof(ohci_hcca_t) == 256, "size is not correct" );
63
64// common link item for gtd and itd for list travel
65// use as pointer only
66typedef struct TU_ATTR_ALIGNED(16) {
67 uint32_t reserved[2];
68 volatile uint32_t next;
69 uint32_t reserved2;
71
72typedef struct TU_ATTR_ALIGNED(16)
73{
74 // Word 0
75 uint32_t used : 1;
76 uint32_t index : 8; // endpoint index the gtd belongs to, or device address in case of control xfer
77 uint32_t : 9; // can be used
78 uint32_t buffer_rounding : 1;
79 uint32_t pid : 2;
80 uint32_t delay_interrupt : 3;
81 volatile uint32_t data_toggle : 2;
82 volatile uint32_t error_count : 2;
83 volatile uint32_t condition_code : 4;
84
85 // Word 1
86 uint8_t* volatile current_buffer_pointer;
87
88 // Word 2 : next TD
89 volatile uint32_t next;
90
91 // Word 3
92 uint8_t* buffer_end;
94
95TU_VERIFY_STATIC( sizeof(ohci_gtd_t) == 16, "size is not correct" );
96
97typedef struct TU_ATTR_ALIGNED(16)
98{
99 // Word 0
100 uint32_t dev_addr : 7;
101 uint32_t ep_number : 4;
102 uint32_t pid : 2;
103 uint32_t speed : 1;
104 uint32_t skip : 1;
105 uint32_t is_iso : 1;
106 uint32_t max_packet_size : 11;
107 // HCD: make use of 5 reserved bits
108 uint32_t used : 1;
109 uint32_t is_interrupt_xfer : 1;
110 uint32_t is_stalled : 1;
111 uint32_t : 2;
112
113 // Word 1
114 uint32_t td_tail;
115
116 // Word 2
117 volatile union {
118 uint32_t address;
119 struct {
120 uint32_t halted : 1;
121 uint32_t toggle : 1;
122 uint32_t : 30;
123 };
124 }td_head;
125
126 // Word 3: next ED
127 uint32_t next;
129
130TU_VERIFY_STATIC( sizeof(ohci_ed_t) == 16, "size is not correct" );
131
132typedef struct TU_ATTR_ALIGNED(32)
133{
134 /*---------- Word 1 ----------*/
135 uint32_t starting_frame : 16;
136 uint32_t : 5; // can be used
137 uint32_t delay_interrupt : 3;
138 uint32_t frame_count : 3;
139 uint32_t : 1; // can be used
140 volatile uint32_t condition_code : 4;
141
142 /*---------- Word 2 ----------*/
143 uint32_t buffer_page0; // 12 lsb bits can be used
144
145 /*---------- Word 3 ----------*/
146 volatile uint32_t next;
147
148 /*---------- Word 4 ----------*/
149 uint32_t buffer_end;
150
151 /*---------- Word 5-8 ----------*/
152 volatile uint16_t offset_packetstatus[8];
154
155TU_VERIFY_STATIC( sizeof(ochi_itd_t) == 32, "size is not correct" );
156
157typedef struct {
158 uint16_t expected_bytes; // up to 8192 bytes so max is 13 bits
160
161// structure with member alignment required from large to small
162typedef struct TU_ATTR_ALIGNED(256) {
163 ohci_hcca_t hcca;
164
165 ohci_ed_t bulk_head_ed; // static bulk head (dummy)
166 ohci_ed_t period_head_ed; // static periodic list head (dummy)
167
168 // control endpoints has reserved resources
169 struct {
170 ohci_ed_t ed;
171 ohci_gtd_t gtd;
172 } control[CFG_TUH_DEVICE_MAX + CFG_TUH_HUB + 1];
173
174 // ochi_itd_t itd[OHCI_MAX_ITD]; // itd requires alignment of 32
175 ohci_ed_t ed_pool[ED_MAX];
176 ohci_gtd_t gtd_pool[GTD_MAX];
177
178 // extra data needed by TDs that can't fit in the TD struct
179 gtd_extra_data_t gtd_extra_control[CFG_TUH_DEVICE_MAX + CFG_TUH_HUB + 1];
180 gtd_extra_data_t gtd_extra[GTD_MAX];
181
182 volatile uint16_t frame_number_hi;
184
185//--------------------------------------------------------------------+
186// OHCI Operational Register
187//--------------------------------------------------------------------+
188
189
190//--------------------------------------------------------------------+
191// OHCI Data Organization
192//--------------------------------------------------------------------+
193typedef volatile struct
194{
195 uint32_t revision;
196
197 union {
198 uint32_t control;
199 struct {
202 uint32_t isochronous_enable : 1;
204 uint32_t bulk_list_enable : 1;
206 uint32_t interrupt_routing : 1;
209 uint32_t TU_RESERVED : 21;
210 }control_bit;
211 };
212
213 union {
215 struct {
216 uint32_t controller_reset : 1;
218 uint32_t bulk_list_filled : 1;
220 uint32_t : 12;
222 }command_status_bit;
223 };
224
228
229 uint32_t hcca;
233 uint32_t bulk_head_ed;
235 uint32_t done_head;
236
239 uint32_t frame_number;
242
243 union {
245 struct {
248 uint32_t no_power_switching : 1;
249 uint32_t device_type : 1;
252 uint32_t reserved : 11;
254 } rh_descriptorA_bit;
255 };
256
257 union {
259 struct {
260 uint32_t device_removable : 16;
262 } rh_descriptorB_bit;
263 };
264
265 union {
266 uint32_t rh_status;
267 struct {
268 uint32_t local_power_status : 1; // read Local Power Status; write: Clear Global Power
270 uint32_t : 13;
274 uint32_t : 13;
276 }rh_status_bit;
277 };
278
279 union {
280 uint32_t rhport_status[TUP_OHCI_RHPORTS];
281 struct {
283 uint32_t port_enable_status : 1;
286 uint32_t port_reset_status : 1;
287 uint32_t : 3;
288 uint32_t port_power_status : 1;
290 uint32_t : 6;
296 uint32_t TU_RESERVED : 11;
297 }rhport_status_bit[TUP_OHCI_RHPORTS];
298 };
300
301TU_VERIFY_STATIC( sizeof(ohci_registers_t) == (0x54 + (4 * TUP_OHCI_RHPORTS)), "size is not correct");
302
303#ifdef __cplusplus
304 }
305#endif
306
307#endif /* _TUSB_OHCI_H_ */
uint8_t dev_addr
Definition: dcd_pic32mz.c:81
ohci_gtd_t
Definition: ohci.h:93
ohci_ed_t
Definition: ohci.h:128
TU_VERIFY_STATIC(ED_MAX<=256, "Reduce CFG_TUH_DEVICE_MAX or CFG_TUH_ENDPOINT_MAX")
struct TU_ATTR_ALIGNED(16)
Definition: ohci.h:66
ohci_data_t
Definition: ohci.h:183
ohci_td_item_t
Definition: ohci.h:70
ochi_itd_t
Definition: ohci.h:153
uint16_t expected_bytes
Definition: ohci.h:158
volatile uint32_t done_head
Definition: ohci.h:58
volatile uint16_t frame_number
Definition: ohci.h:56
volatile uint16_t frame_pad
Definition: ohci.h:57
uint32_t number_downstream_ports
Definition: ohci.h:246
uint32_t periodic_list_enable
Definition: ohci.h:201
uint32_t port_suspend_status_change
Definition: ohci.h:293
uint32_t rh_descriptorA
Definition: ohci.h:244
uint32_t command_status
Definition: ohci.h:214
uint32_t frame_remaining
Definition: ohci.h:238
uint32_t interrupt_disable
Definition: ohci.h:227
uint32_t no_over_current_protection
Definition: ohci.h:251
uint32_t port_enable_status
Definition: ohci.h:283
uint32_t port_reset_status_change
Definition: ohci.h:295
uint32_t periodic_start
Definition: ohci.h:240
uint32_t control_bulk_service_ratio
Definition: ohci.h:200
uint32_t interrupt_enable
Definition: ohci.h:226
uint32_t port_enable_status_change
Definition: ohci.h:292
uint32_t interrupt_routing
Definition: ohci.h:206
uint32_t device_remote_wakeup_enable
Definition: ohci.h:271
uint32_t no_power_switching
Definition: ohci.h:248
uint32_t local_power_status
Definition: ohci.h:268
uint32_t port_over_current_indicator_change
Definition: ohci.h:294
uint32_t rh_descriptorB
Definition: ohci.h:258
uint32_t device_type
Definition: ohci.h:249
uint32_t current_connect_status
Definition: ohci.h:282
uint32_t control_current_ed
Definition: ohci.h:232
uint32_t port_suspend_status
Definition: ohci.h:284
uint32_t port_power_status
Definition: ohci.h:288
uint32_t control_list_filled
Definition: ohci.h:217
uint32_t control
Definition: ohci.h:198
uint32_t rh_status
Definition: ohci.h:266
uint32_t over_current_indicator_change
Definition: ohci.h:273
uint32_t port_over_current_indicator
Definition: ohci.h:285
uint32_t ownership_change_request
Definition: ohci.h:219
uint32_t control_list_enable
Definition: ohci.h:203
uint32_t bulk_list_enable
Definition: ohci.h:204
uint32_t low_speed_device_attached
Definition: ohci.h:289
uint32_t power_on_to_good_time
Definition: ohci.h:253
uint32_t control_head_ed
Definition: ohci.h:231
uint32_t clear_remote_wakeup_enable
Definition: ohci.h:275
uint32_t lowspeed_threshold
Definition: ohci.h:241
uint32_t isochronous_enable
Definition: ohci.h:202
uint32_t bulk_head_ed
Definition: ohci.h:233
uint32_t over_current_indicator
Definition: ohci.h:269
uint32_t port_power_control_mask
Definition: ohci.h:261
uint32_t scheduling_overrun_count
Definition: ohci.h:221
uint32_t connect_status_change
Definition: ohci.h:291
uint32_t device_removable
Definition: ohci.h:260
uint32_t revision
Definition: ohci.h:195
uint32_t reserved
Definition: ohci.h:252
uint32_t period_current_ed
Definition: ohci.h:230
uint32_t remote_wakeup_enale
Definition: ohci.h:208
uint32_t bulk_list_filled
Definition: ohci.h:218
uint32_t local_power_status_change
Definition: ohci.h:272
uint32_t hcca
Definition: ohci.h:229
uint32_t power_switching_mode
Definition: ohci.h:247
uint32_t overcurrent_protection_mode
Definition: ohci.h:250
uint32_t hc_functional_state
Definition: ohci.h:205
uint32_t done_head
Definition: ohci.h:235
uint32_t interrupt_status
Definition: ohci.h:225
uint32_t frame_interval
Definition: ohci.h:237
uint32_t bulk_current_ed
Definition: ohci.h:234
uint32_t TU_RESERVED
Definition: ohci.h:209
uint32_t frame_number
Definition: ohci.h:239
uint32_t controller_reset
Definition: ohci.h:216
uint32_t remote_wakeup_connected
Definition: ohci.h:207
uint32_t port_reset_status
Definition: ohci.h:286