Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
dwcotg.h
Go to the documentation of this file.
1/*
2 * This file is part of the Ultibo project, https://ultibo.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2026 Garry Wood <garry@softoz.com.au>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26#ifndef _ULTIBO_DWCOTG_H
27#define _ULTIBO_DWCOTG_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "ultibo/threads.h"
34#include "ultibo/usb.h"
35
37#define DWCOTG_USBHOST_DESCRIPTION "DWCOTG USB Host"
38
39#define DWC_MAX_CHANNELS 16
40
41#define DWC_SCHEDULER_MAILSLOT_SIZE SIZE_1K
42
43#define DWC_SCHEDULER_THREAD_STACK_SIZE SIZE_32K
44#define DWC_SCHEDULER_THREAD_PRIORITY THREAD_PRIORITY_HIGHEST
45
46#define DWC_SCHEDULER_THREAD_NAME "DWC Transfer Scheduler"
47
48#define DWC_COMPLETION_THREAD_STACK_SIZE SIZE_32K
49#define DWC_COMPLETION_THREAD_PRIORITY THREAD_PRIORITY_HIGHEST
50
51#define DWC_COMPLETION_THREAD_NAME "DWC Transfer Completion"
52
53#define DWC_RESUBMIT_THREAD_STACK_SIZE SIZE_32K
54#define DWC_RESUBMIT_THREAD_PRIORITY THREAD_PRIORITY_CRITICAL
55
56#define DWC_RESUBMIT_THREAD_NAME "DWC Transfer Resubmit"
57
59#define DWC_USB_PID_DATA0 0
60#define DWC_USB_PID_DATA1 2
61#define DWC_USB_PID_DATA2 1
62#define DWC_USB_PID_SETUP 3
63#define DWC_USB_PID_MDATA 3
64
66#define DWC_RECEIVE_WORDS 1024
67#define DWC_TRANSMIT_WORDS 1024
68#define DWC_PERIODIC_TRANSMIT_WORDS 1024
69
71#define DWC_STATUS_SUCCESS 0
72#define DWC_STATUS_STALLED 1
73#define DWC_STATUS_FAILED 2
74#define DWC_STATUS_TRANSFER_RESUBMIT 3
75#define DWC_STATUS_TRANSFER_RESTART 4
76#define DWC_STATUS_TRANSACTION_RESTART 5
77#define DWC_STATUS_HOST_PORT_CHANGE 6
78#define DWC_STATUS_ROOT_HUB_REQUEST 7
79#define DWC_STATUS_INVALID 8
80#define DWC_STATUS_CANCELLED 9
81
83#define DWC_SPLIT_ERROR_RETRIES 3
84#define DWC_COMPLETE_SPLIT_RETRIES 10
85
88#define DWC_OTG_CTRL_HST_SET_HNP_EN (1 << 10)
89
92#define DWC_AHB_INTERRUPT_ENABLE (1 << 0)
95#define BCM_DWC_AHB_AXI_BURST_MASK (3 << 1)
97#define BCM_DWC_AHB_AXI_WAIT (1 << 4)
99#define DWC_AHB_DMA_ENABLE (1 << 5)
101#define DWC_AHB_MASTER_IDLE (1 << 31)
102
104#define DWC_USB_CFG_TOUTCAL_MASK (7 << 0)
105#define DWC_USB_CFG_TOUTCAL_LIMIT (7 << 0)
106#define DWC_USB_CFG_PHYIF16 (1 << 3)
107#define DWC_USB_CFG_ULPI_UTMI_SEL (1 << 4)
108#define DWC_USB_CFG_FS_INTF (1 << 5)
109#define DWC_USB_CFG_PHY_SEL (1 << 6)
110#define DWC_USB_CFG_DDR_SEL (1 << 7)
111#define DWC_USB_CFG_SRP_CAPABLE (1 << 8)
112#define DWC_USB_CFG_HNP_CAPABLE (1 << 9)
113#define DWC_USB_CFG_USB_TRDTIM_MASK (0xF << 10)
114#define DWC_USB_CFG_RESERVED14 (1 << 14)
115#define DWC_USB_CFG_PHY_LOW_PWR_CLK_SEL (1 << 15)
116#define DWC_USB_CFG_OTG_UTMI_FS_SEL (1 << 16)
117#define DWC_USB_CFG_ULPI_FSLS (1 << 17)
118#define DWC_USB_CFG_ULPI_AUTO_RES (1 << 18)
119#define DWC_USB_CFG_ULPI_CLK_SUS_M (1 << 19)
120#define DWC_USB_CFG_ULPI_EXT_VBUS_DRV (1 << 20)
121#define DWC_USB_CFG_ULPI_INT_VBUS_INDICATOR (1 << 21)
122#define DWC_USB_CFG_TERM_SEL_DL_PULSE (1 << 22)
123#define DWC_USB_CFG_INDICATOR_COMPLEMENT (1 << 23)
124#define DWC_USB_CFG_INDICATOR_PASS_THROUGH (1 << 24)
125#define DWC_USB_CFG_ULPI_INT_PROT_DIS (1 << 25)
126#define DWC_USB_CFG_IC_USB_CAP (1 << 26)
127#define DWC_USB_CFG_IC_TRAFFIC_PULL_REMOVE (1 << 27)
128#define DWC_USB_CFG_TX_END_DELAY (1 << 28)
129#define DWC_USB_CFG_FORCE_HOST_MODE (1 << 29)
130#define DWC_USB_CFG_FORCE_DEV_MODE (1 << 30)
131#define DWC_USB_CFG_RESERVED31 (1 << 31)
132
135#define DWC_SOFT_RESET (1 << 0)
136
141#define DWC_CORE_INTERRUPTS_SOF_INTR (1 << 3)
144#define DWC_CORE_INTERRUPTS_PORT_INTR (1 << 24)
147#define DWC_CORE_INTERRUPTS_HOST_CHANNEL_INTR (1 << 25)
149#define DWC_CORE_INTERRUPTS_DISCONNECT (1 << 29)
150
152#define DWC_VENDOR_ID_OTG2 0x4f542000
153#define DWC_VENDOR_ID_OTG3 0x4f543000
154
155#define DWC_VENDOR_ID_MASK 0xfffff000
156
158#define DWC_HWCFG2_OP_MODE_MASK (7 << 0)
159#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG (0 << 0)
160#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG (1 << 0)
161#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG (2 << 0)
162#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE (3 << 0)
163#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE (4 << 0)
164#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST (5 << 0)
165#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST (6 << 0)
166
167#define DWC_HWCFG2_ARCHITECTURE_MASK (3 << 3)
168#define DWC_HWCFG2_ARCHITECTURE_SLAVE_ONLY (0 << 3)
169#define DWC_HWCFG2_ARCHITECTURE_EXT_DMA (1 << 3)
170#define DWC_HWCFG2_ARCHITECTURE_INT_DMA (2 << 3)
171
172#define DWC_HWCFG2_POINT2POINT (1 << 5)
173
174#define DWC_HWCFG2_HS_PHY_TYPE_MASK (3 << 6)
175#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED (0 << 6)
176#define DWC_HWCFG2_HS_PHY_TYPE_UTMI (1 << 6)
177#define DWC_HWCFG2_HS_PHY_TYPE_ULPI (2 << 6)
178#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI (3 << 6)
179
180#define DWC_HWCFG2_FS_PHY_TYPE_MASK (3 << 8)
181#define DWC_HWCFG2_FS_PHY_TYPE_NOT_SUPPORTED (0 << 8)
182#define DWC_HWCFG2_FS_PHY_TYPE_DEDICATED (1 << 8)
183#define DWC_HWCFG2_FS_PHY_TYPE_SHARED_UTMI (2 << 8)
184#define DWC_HWCFG2_FS_PHY_TYPE_SHARED_ULPI (3 << 8)
185
186#define DWC_HWCFG2_NUM_DEV_ENDPOINTS (0xF << 10)
187#define DWC_HWCFG2_NUM_HOST_CHANNELS (0xF << 14)
188
189#define DWC_HWCFG2_PERIODIC_ENDPOINT_SUPPORTED (1 << 18)
190#define DWC_HWCFG2_DYNAMIC_FIFO (1 << 19)
191#define DWC_HWCFG2_MULTI_PROC_INT (1 << 20)
192#define DWC_HWCFG2_RESERVED21 (1 << 21)
193#define DWC_HWCFG2_NON_PERIODIC_TX_QUEUE_DEPTH (3 << 22)
194#define DWC_HWCFG2_HOST_PERIODIC_TX_QUEUE_DEPTH (3 << 24)
195#define DWC_HWCFG2_DEV_TOKEN_QUEUE_DEPTH (0x1F << 26)
196#define DWC_HWCFG2_OTG_ENABLE_IC_USB (1 << 31)
197
199#define DWC_HCFG_FS_LS_PHY_CLK_SEL_MASK (3 << 0)
200#define DWC_HCFG_FS_LS_PHY_CLK_SEL_SHIFT 0
201#define DWC_HCFG_FS_LS_PHY_CLK_SEL_30_60_MHZ 0
202#define DWC_HCFG_FS_LS_PHY_CLK_SEL_48_MHZ 1
203#define DWC_HCFG_FS_LS_PHY_CLK_SEL_6_MHZ 2
204
205#define DWC_HCFG_FS_LS_SUPPORT_ONLY (1 << 2)
206
207#define DWC_HCFG_ENABLE_32KHZ (1 << 7)
208
209#define DWC_HCFG_RESUME_VALID_MASK (0xFF << 8)
210#define DWC_HCFG_RESUME_VALID_SHIFT 8
211
212#define DWC_HCFG_DESC_DMA (1 << 23)
213
214#define DWC_HCFG_FRAME_LIST_ENTRIES_MASK (3 << 24)
215#define DWC_HCFG_FRAME_LIST_ENTRIES_SHIFT 24
216#define DWC_HCFG_FRAME_LIST_ENTRIES_8 (0 << 24)
217#define DWC_HCFG_FRAME_LIST_ENTRIES_8_SIZE 8
218#define DWC_HCFG_FRAME_LIST_ENTRIES_16 (1 << 24)
219#define DWC_HCFG_FRAME_LIST_ENTRIES_16_SIZE 16
220#define DWC_HCFG_FRAME_LIST_ENTRIES_32 (3 << 24)
221#define DWC_HCFG_FRAME_LIST_ENTRIES_32_SIZE 32
222#define DWC_HCFG_FRAME_LIST_ENTRIES_64 (3 << 24)
223#define DWC_HCFG_FRAME_LIST_ENTRIES_64_SIZE 64
224
225#define DWC_HCFG_PERSCHED_ENA (1 << 26)
226#define DWC_HCFG_MODE_CH_TIM_EN (1 << 31)
227
229#define DWC_HFIR_FRAME_INTERVAL_MASK (0xFFFF << 0)
230#define DWC_HFIR_FRAME_INT_RELOAD_CTL (1 << 16)
231#define DWC_HFIR_RESERVED1 (0xFFFE << 17)
232
234#define DWC_HFNUM_FRAME_NUMBER_MASK 0xFFFF
235
241#define DWC_HOST_PORT_CTRLSTATUS_CONNECTED (1 << 0)
244#define DWC_HOST_PORT_CTRLSTATUS_CONNECTED_CHANGED (1 << 1)
246#define DWC_HOST_PORT_CTRLSTATUS_ENABLED (1 << 2)
249#define DWC_HOST_PORT_CTRLSTATUS_ENABLED_CHANGED (1 << 3)
251#define DWC_HOST_PORT_CTRLSTATUS_OVERCURRENT (1 << 4)
254#define DWC_HOST_PORT_CTRLSTATUS_OVERCURRENT_CHANGED (1 << 5)
256#define DWC_HOST_PORT_CTRLSTATUS_RESUME (1 << 6)
258#define DWC_HOST_PORT_CTRLSTATUS_SUSPENDED (1 << 7)
260#define DWC_HOST_PORT_CTRLSTATUS_RESET (1 << 8)
261#define DWC_HOST_PORT_CTRLSTATUS_RESERVED (1 << 9)
263#define DWC_HOST_PORT_CTRLSTATUS_LINE_STATUS (3 << 10)
265#define DWC_HOST_PORT_CTRLSTATUS_POWERED (1 << 12)
266#define DWC_HOST_PORT_CTRLSTATUS_TEST_CONTROL (0x0F << 13)
268#define DWC_HOST_PORT_CTRLSTATUS_SPEED (3 << 17)
269#define DWC_HOST_PORT_CTRLSTATUS_RESERVED2 (0x1FFF << 19)
270
276#define DWC_HOST_CHANNEL_CHARACTERISTICS_MAX_PACKET_SIZE (0x7FF << 0)
278#define DWC_HOST_CHANNEL_CHARACTERISTICS_ENDPOINT_NUMBER (0x0F << 11)
280#define DWC_HOST_CHANNEL_CHARACTERISTICS_ENDPOINT_DIRECTION (1 << 15)
281#define DWC_HOST_CHANNEL_CHARACTERISTICS_RESERVED (1 << 16)
283#define DWC_HOST_CHANNEL_CHARACTERISTICS_LOWSPEED (1 << 17)
285#define DWC_HOST_CHANNEL_CHARACTERISTICS_ENDPOINT_TYPE (3 << 18)
288#define DWC_HOST_CHANNEL_CHARACTERISTICS_PACKETS_PER_FRAME (3 << 20)
290#define DWC_HOST_CHANNEL_CHARACTERISTICS_DEVICE_ADDRESS (0x7F << 22)
293#define DWC_HOST_CHANNEL_CHARACTERISTICS_ODD_FRAME (1 << 29)
295#define DWC_HOST_CHANNEL_CHARACTERISTICS_CHANNEL_DISABLE (1 << 30)
298#define DWC_HOST_CHANNEL_CHARACTERISTICS_CHANNEL_ENABLE (1 << 31)
299
305#define DWC_HOST_CHANNEL_SPLIT_CONTROL_PORT_ADDRESS (0x7F << 0)
309#define DWC_HOST_CHANNEL_SPLIT_CONTROL_HUB_ADDRESS (0x7F << 7)
311#define DWC_HOST_CHANNEL_SPLIT_CONTROL_TRANSACTION_POSITION (3 << 14)
314#define DWC_HOST_CHANNEL_SPLIT_CONTROL_COMPLETE_SPLIT (1 << 16)
315#define DWC_HOST_CHANNEL_SPLIT_CONTROL_RESERVED (0x3FFF << 17)
317#define DWC_HOST_CHANNEL_SPLIT_CONTROL_SPLIT_ENABLE (1 << 31)
318
331#define DWC_HOST_CHANNEL_INTERRUPTS_TRANSFER_COMPLETED (1 << 0)
342#define DWC_HOST_CHANNEL_INTERRUPTS_CHANNEL_HALTED (1 << 1)
344#define DWC_HOST_CHANNEL_INTERRUPTS_AHB_ERROR (1 << 2)
346#define DWC_HOST_CHANNEL_INTERRUPTS_STALL_RESPONSE_RECEIVED (1 << 3)
351#define DWC_HOST_CHANNEL_INTERRUPTS_NAK_RESPONSE_RECEIVED (1 << 4)
353#define DWC_HOST_CHANNEL_INTERRUPTS_ACK_RESPONSE_RECEIVED (1 << 5)
355#define DWC_HOST_CHANNEL_INTERRUPTS_NYET_RESPONSE_RECEIVED (1 << 6)
357#define DWC_HOST_CHANNEL_INTERRUPTS_TRANSACTION_ERROR (1 << 7)
359#define DWC_HOST_CHANNEL_INTERRUPTS_BABBLE_ERROR (1 << 8)
361#define DWC_HOST_CHANNEL_INTERRUPTS_FRAME_OVERRUN (1 << 9)
363#define DWC_HOST_CHANNEL_INTERRUPTS_DATA_TOGGLE_ERROR (1 << 10)
364#define DWC_HOST_CHANNEL_INTERRUPTS_BUFFER_NOT_AVAILABLE (1 << 11)
365#define DWC_HOST_CHANNEL_INTERRUPTS_EXCESS_TRANSACTION_ERROR (1 << 12)
366#define DWC_HOST_CHANNEL_INTERRUPTS_FRAME_LIST_ROLLOVER (1 << 13)
367#define DWC_HOST_CHANNEL_INTERRUPTS_RESERVED (0x3FFFF << 14)
368
371#define DWC_HOST_CHANNEL_INTERRUPT_MASK_TRANSFER_COMPLETED DWC_HOST_CHANNEL_INTERRUPTS_TRANSFER_COMPLETED
372#define DWC_HOST_CHANNEL_INTERRUPT_MASK_CHANNEL_HALTED DWC_HOST_CHANNEL_INTERRUPTS_CHANNEL_HALTED
373#define DWC_HOST_CHANNEL_INTERRUPT_MASK_AHB_ERROR DWC_HOST_CHANNEL_INTERRUPTS_AHB_ERROR
374#define DWC_HOST_CHANNEL_INTERRUPT_MASK_STALL_RESPONSE_RECEIVED DWC_HOST_CHANNEL_INTERRUPTS_STALL_RESPONSE_RECEIVED
375#define DWC_HOST_CHANNEL_INTERRUPT_MASK_NAK_RESPONSE_RECEIVED DWC_HOST_CHANNEL_INTERRUPTS_NAK_RESPONSE_RECEIVED
376#define DWC_HOST_CHANNEL_INTERRUPT_MASK_ACK_RESPONSE_RECEIVED DWC_HOST_CHANNEL_INTERRUPTS_ACK_RESPONSE_RECEIVED
377#define DWC_HOST_CHANNEL_INTERRUPT_MASK_NYET_RESPONSE_RECEIVED DWC_HOST_CHANNEL_INTERRUPTS_NYET_RESPONSE_RECEIVED
378#define DWC_HOST_CHANNEL_INTERRUPT_MASK_TRANSACTION_ERROR DWC_HOST_CHANNEL_INTERRUPTS_TRANSACTION_ERROR
379#define DWC_HOST_CHANNEL_INTERRUPT_MASK_BABBLE_ERROR DWC_HOST_CHANNEL_INTERRUPTS_BABBLE_ERROR
380#define DWC_HOST_CHANNEL_INTERRUPT_MASK_FRAME_OVERRUN DWC_HOST_CHANNEL_INTERRUPTS_FRAME_OVERRUN
381#define DWC_HOST_CHANNEL_INTERRUPT_MASK_DATA_TOGGLE_ERROR DWC_HOST_CHANNEL_INTERRUPTS_DATA_TOGGLE_ERROR
382#define DWC_HOST_CHANNEL_INTERRUPT_MASK_BUFFER_NOT_AVAILABLE DWC_HOST_CHANNEL_INTERRUPTS_BUFFER_NOT_AVAILABLE
383#define DWC_HOST_CHANNEL_INTERRUPT_MASK_EXCESS_TRANSACTION_ERROR DWC_HOST_CHANNEL_INTERRUPTS_EXCESS_TRANSACTION_ERROR
384#define DWC_HOST_CHANNEL_INTERRUPT_MASK_FRAME_LIST_ROLLOVER DWC_HOST_CHANNEL_INTERRUPTS_FRAME_LIST_ROLLOVER
385#define DWC_HOST_CHANNEL_INTERRUPT_MASK_RESERVED DWC_HOST_CHANNEL_INTERRUPTS_RESERVED
386
397#define DWC_HOST_CHANNEL_TRANSFER_SIZE (0x7FFFF << 0)
402#define DWC_HOST_CHANNEL_TRANSFER_PACKET_COUNT (0x3FF << 19)
410#define DWC_HOST_CHANNEL_TRANSFER_PACKET_ID (0x03 << 29)
412#define DWC_HOST_CHANNEL_TRANSFER_DO_PING (1 << 31)
413
415
424{
425 // 0x0000 : Channel Characteristics
426 // Contains various fields that must be set to prepare this channel for a transfer to or from a particular endpoint on a particular USB device
427 // This register only needs to be programmed one time when doing a transfer, regardless of how many packets it consists of, unless the channel is
428 // re-programmed for a different transfer or the transfer is moved to a different channel}
430 // 0x0004 : Channel Split Control
431 // This register is used to set up Split Transactions for communicating with low or full-speed devices attached to a high-speed hub. When doing so, set split_enable to 1 and
432 // the other fields as documented. Otherwise, software must clear this register before starting the transfer}
433 // Like the Channel Characteristics register, this register only needs to be programmed one time if the channel is enabled multiple times to send all the packets of a single transfer
434 uint32_t splitcontrol;
435 // 0x0008 : Channel Interrupts
436 // Bitmask of status conditions that have occurred on this channel
437 // These bits can be used with or without "real" interrupts. To have the CPU get a real interrupt when one of these bits gets set, set the appropriate bit in the interrupt_mask,
438 // and also ensure that interrupts from the channel are enabled in the host_channels_interrupt_mask register, channel interrupts overall are enabled in the core_interrupt_mask register,
439 // and interrupts from the DWC hardware overall are enabled in the ahb_configuration register and by any system-specific interrupt controller}
440 uint32_t interrupts;
441 // 0x000c : Channel Interrupts Mask
442 // This has the same format as the Channel Interrupts Register, but software uses this to enable (1) or disable (0) the corresponding interrupt. Defaults to all 0's after a reset
444 // 0x0010 : Channel Transfer
445 // Used to store additional information about the transfer. This must be programmed before beginning the transfer
446 uint32_t transfer;
447 // 0x0014 : Channel DMA Address
448 // Word-aligned address at which the hardware will read or write data using Direct Memory Access. This must be programmed before beginning the transfer, unless the size of the data
449 // to send or receive is 0. The hardware will increment this address by the number of bytes successfully received or sent, which will correspond to the size decrease in transfer.size}
450 // Note: DMA must be enabled in the AHB Configuration Register before this register can be used. Otherwise, the hardware is considered to be in Slave mode and must be controlled a
451 // different way, which we do not use in our driver and do not attempt to document}
452 // BCM2835-specific note: Addresses written to this register must be bus addresses, not ARM physical addresses
453 uint32_t dmaaddress;
454 // 0x0018 : Reserved
456 // 0x001C : Reserved
458};
459
460
478{
479 // Core registers
480 // 0x0000 : OTG Control and Status
481 uint32_t otgcontrol;
482 // 0x0004 : OTG Interrupt
483 uint32_t otginterrupt;
484 // 0x0008 : Core AHB Configuration
485 // This register configures some of the interactions the DWC has with the rest of the system
487 // 0x000c : Core USB Configuration
489 // 0x0010 : Core Reset
490 // Software can use this register to cause the DWC to reset itself
491 uint32_t corereset;
492 // 0x0014 : Core Interrupt
493 // This register contains the state of pending top-level DWC interrupts. 1 means interrupt pending while 0 means no interrupt pending
494 // Note that at least for port_intr and host_channel_intr, software must clear the interrupt somewhere else rather than by writing to this register
496 // 0x0018 : Core Interrupt Mask
497 // This register has the same format as the Core Interrupt Register and configures whether the corresponding interrupt is enabled (1) or disabled (0). Initial state after reset is all 0's
499 // 0x001c : Receive Status Queue Read (Read Only)
501 // 0x0020 : Receive Status Queue Read & POP (Read Only)
503 // 0x0024 : Receive FIFO Size
504 // This register contains the size of the Receive FIFO, in 4-byte words
505 // see the note in the documentation for the hwcfg3 register about configuring the dynamic FIFOs}
507 // 0x0028 : Non Periodic Transmit FIFO Size
508 // The low 16 bits of this register contain the offset of the Nonperiodic Transmit FIFO, in 4-byte words, from the start of the memory reserved by the controller for dynamic FIFOs.
509 // The high 16 bits of this register contain its size, in 4-byte words}
510 // see the note in the documentation for the hwcfg3 register about configuring the dynamic FIFOs}
512 // 0x002c : Non Periodic Transmit FIFO/Queue Status (Read Only)
514 // 0x0030 : I2C Access
515 uint32_t i2ccontrol;
516 // 0x0034 : PHY Vendor Control
518 // 0x0038 : General Purpose Input/Output
519 uint32_t gpio;
520 // 0x003c : User ID
521 uint32_t userid;
522 // 0x0040 : Vendor ID (Read Only)
523 uint32_t vendorid;
524 // 0x0044 : User HW Config1 (Read Only)
525 uint32_t hwcfg1;
526 // 0x0048 : User HW Config2 (Read Only)
527 uint32_t hwcfg2;
528 // 0x004c : User HW Config3 (Read Only)
529 // The high 16 bits of this read-only register contain the maximum total size, in words, of the dynamic FIFOs (Rx, Nonperiodic Tx, and Periodic Tx).
530 // Software must set up these three dynamic FIFOs in the rx_fifo_size, nonperiodic_tx_fifo_size, and host_periodic_tx_fifo_size registers such that
531 // their total size does not exceed this maximum total size and no FIFOs overlap}
532 // Note: Software must explicitly configure the dynamic FIFOs even if the controller is operating in DMA mode, since the default values for the
533 // FIFO sizes and offsets may be invalid. For example, in Broadcom's instantiation of this controller for the BCM2835, only 4080 words are
534 // available for dynamic FIFOs, but the dynamic FIFO sizes are set to 4096, 32, and 0, which are invalid as they add up to more than 4080.
535 // IF YOU DO NOT DO THIS YOU WILL GET SILENT MEMORY CORRUPTION}
536 // The low 16 bits of this register contain various flags that are not documented here as we don't use any in our driver
537 uint32_t hwcfg3;
538 // 0x0050 : User HW Config4 (Read Only)
539 uint32_t hwcfg4;
540 // 0x0054 : Core LPM Configuration
542 // 0x0058 : Global PowerDown
544 // 0x005c : Global DFIFO SW Config
546 // 0x0060 : ADP Control (Attach Detection Protocol)
547 uint32_t adpcontrol;
548 // 0x0064 : Reserved
549 uint32_t reserved0x0064[39];
550 // 0x0100 : Host Periodic Transmit FIFO Size
551 // The low 16 bits of this register configure the offset of the Periodic Transmit FIFO, in 4-byte words, from the start of the memory reserved by the controller for dynamic FIFOs.
552 // The high 16 bits of this register configure its size, in 4-byte words}
553 // see the note in the documentation for the hwcfg3 register about configuring the dynamic FIFOs}
555 // 0x0104 : Device Periodic Transmit FIFO#n (if dedicated fifos are disabled, otherwise Device Transmit FIFO#n)
556 uint32_t reserved0x0104[191];
557 // Host registers
558 // The registers beginning at this point are considered to be the "Host" registers. These are used for the "Host" half of the OTG (On-The-Go) protocol, which allows this hardware
559 // to act as either a USB host or a USB device. This is the only half we are concerned with in this driver and we do not declare the corresponding Device registers}
560 // 0x0400 : Host Configuration
562 // 0x0404 : Host Frame Interval
564 // 0x0408 : Host Frame Number / Frame Remaining
566 // 0x040c : Reserved
568 // 0x0410 : Host Periodic Transmit FIFO/ Queue Status
570 // 0x0414 : Host All Channels Interrupt
571 // This register contains a bit for each host channel that indicates whether an interrupt has occurred on that host channel. You cannot clear the interrupts by writing
572 // use the channel-specific interrupt registers instead}
574 // 0x0418 : Host All Channels Interrupt Mask
575 // Same format as the Host All Channels Interrupt Register, but a 1 in this register indicates that the corresponding host channel interrupt is enabled. Software can
576 // change this register. Defaults to all 0's after a reset}
578 // 0x041c : Host Frame List Base Address Register
580 // 0x0420
581 uint32_t reserved0x0420[8];
582 // 0x0440 : Host Port Control and Status
583 // This register provides the information needed to respond to status queries about the "host port", which is the port that is logically attached to the root hub
584 // When changing this register, software must read its value, then clear the enabled, connected_changed, enabled_changed, and overcurrent_changed members to avoid
585 // changing them, as those particular bits are cleared by writing 1}
587 // 0x0444
588 uint32_t reserved0x0444[47];
589 // Host channel registers
590 // 0x0500 : Array of Host Channels
591 // Each host channel can be used to execute an independent USB transfer or transaction simultaneously. A USB transfer may consist of multiple transactions, or packets.
592 // To avoid having to re-program the channel, it may be useful to use one channel for all transactions of a transfer before allowing other transfers to be scheduled on it}
594 // 0x0700
595 uint32_t reserved0x0700[((0x800 - 0x500) - (DWC_MAX_CHANNELS * sizeof(DWC_HOST_CHANNEL))) / sizeof(uint32_t)];
596 // Device registers
597 // 0x0800
598 uint32_t reserved0x0800[(0xE00 - 0x800) / sizeof(uint32_t)];
599 // 0x0e00 : Power and Clock Gating Control
601};
602
603
612
613
617{
618 // USB Properties
620 // DWCOTG Properties
622 uint32_t irq;
623 uint32_t powerid;
625 uint32_t channelcount;
629 // Channel Properties
638 // Root Hub Properties
650 // Statistics Properties
651 uint32_t interruptcount;
656 uint32_t resubmitcount;
664 uint32_t ahberrorcount;
679};
680
682
690USB_HOST * STDCALL dwc_host_create(size_t address, uint32_t irq, uint32_t powerid);
691
698
699#ifdef __cplusplus
700}
701#endif
702
703#endif // _ULTIBO_DWCOTG_H
uint32_t STDCALL dwc_host_destroy(USB_HOST *host)
Stop, deregister and destroy a DWCOTG USB host created by this driver.
#define DWC_MAX_CHANNELS
Maximum number of DWC host channels.
Definition dwcotg.h:39
struct _DWC_REGISTERS DWC_REGISTERS
Definition dwcotg.h:476
struct _DWC_HOST_CHANNEL DWC_HOST_CHANNEL
Definition dwcotg.h:422
USB_HOST *STDCALL dwc_host_create(size_t address, uint32_t irq, uint32_t powerid)
Create and register a new DWCOTG host which can be accessed using the USB API.
struct _DWC_ROOTHUB_CONFIGURATION DWC_ROOTHUB_CONFIGURATION
Definition dwcotg.h:605
struct _DWC_USB_HOST DWC_USB_HOST
Definition dwcotg.h:615
#define STDCALL
Definition globaltypes.h:45
#define PACKED
Definition globaltypes.h:48
HANDLE SPIN_HANDLE
Definition globaltypes.h:104
HANDLE MAILSLOT_HANDLE
Definition globaltypes.h:115
HANDLE THREAD_HANDLE
Definition globaltypes.h:113
HANDLE SEMAPHORE_HANDLE
Definition globaltypes.h:107
HANDLE MUTEX_HANDLE
Definition globaltypes.h:105
Definition dwcotg.h:424
uint32_t dmaaddress
Definition dwcotg.h:453
uint32_t characteristics
Definition dwcotg.h:429
uint32_t interruptmask
Definition dwcotg.h:443
uint32_t transfer
Definition dwcotg.h:446
uint32_t reserved0x0018
Definition dwcotg.h:455
uint32_t splitcontrol
Definition dwcotg.h:434
uint32_t reserved0x001c
Definition dwcotg.h:457
uint32_t interrupts
Definition dwcotg.h:440
Definition dwcotg.h:478
uint32_t hostfifostatus
Definition dwcotg.h:569
uint32_t nonperiodictransmitfifostatus
Definition dwcotg.h:513
uint32_t hwcfg4
Definition dwcotg.h:539
uint32_t hostconfiguration
Definition dwcotg.h:561
uint32_t corelpmconfiguration
Definition dwcotg.h:541
DWC_HOST_CHANNEL hostchannels[DWC_MAX_CHANNELS]
Definition dwcotg.h:593
uint32_t reserved0x0700[((0x800 - 0x500) -(DWC_MAX_CHANNELS *sizeof(DWC_HOST_CHANNEL)))/sizeof(uint32_t)]
Definition dwcotg.h:595
uint32_t corereset
Definition dwcotg.h:491
uint32_t hwcfg3
Definition dwcotg.h:537
uint32_t coreinterruptmask
Definition dwcotg.h:498
uint32_t hwcfg2
Definition dwcotg.h:527
uint32_t reserved0x0800[(0xE00 - 0x800)/sizeof(uint32_t)]
Definition dwcotg.h:598
uint32_t powerclockcontrol
Definition dwcotg.h:600
uint32_t globalfifoconfig
Definition dwcotg.h:545
uint32_t hostperiodictransmitfifosize
Definition dwcotg.h:554
uint32_t reserved0x0104[191]
Definition dwcotg.h:556
uint32_t receivestatuspop
Definition dwcotg.h:502
uint32_t reserved0x0444[47]
Definition dwcotg.h:588
uint32_t coreusbconfiguration
Definition dwcotg.h:488
uint32_t otgcontrol
Definition dwcotg.h:481
uint32_t nonperiodictransmitfifosize
Definition dwcotg.h:511
uint32_t hostframeinterval
Definition dwcotg.h:563
uint32_t vendorid
Definition dwcotg.h:523
uint32_t i2ccontrol
Definition dwcotg.h:515
uint32_t hostchannelsinterrupt
Definition dwcotg.h:573
uint32_t adpcontrol
Definition dwcotg.h:547
uint32_t hostchannelsinterruptmask
Definition dwcotg.h:577
uint32_t hwcfg1
Definition dwcotg.h:525
uint32_t hostframenumber
Definition dwcotg.h:565
uint32_t userid
Definition dwcotg.h:521
uint32_t phyvendorcontrol
Definition dwcotg.h:517
uint32_t gpio
Definition dwcotg.h:519
uint32_t receivestatus
Definition dwcotg.h:500
uint32_t coreinterrupts
Definition dwcotg.h:495
uint32_t ahbconfiguration
Definition dwcotg.h:486
uint32_t reserved0x040c
Definition dwcotg.h:567
uint32_t otginterrupt
Definition dwcotg.h:483
uint32_t reserved0x0064[39]
Definition dwcotg.h:549
uint32_t hostframelist
Definition dwcotg.h:579
uint32_t globalpowerdown
Definition dwcotg.h:543
uint32_t receivefifosize
Definition dwcotg.h:506
uint32_t reserved0x0420[8]
Definition dwcotg.h:581
uint32_t hostportcontrolstatus
Definition dwcotg.h:586
Definition dwcotg.h:607
USB_ENDPOINT_DESCRIPTOR endpointdescriptor
Definition dwcotg.h:610
USB_CONFIGURATION_DESCRIPTOR configurationdescriptor
Definition dwcotg.h:608
USB_INTERFACE_DESCRIPTOR interfacedescriptor
Definition dwcotg.h:609
Definition dwcotg.h:617
USB_DEVICE_DESCRIPTOR * devicedescriptor
Device descriptor for the root hub.
Definition dwcotg.h:643
USB_HOST host
Definition dwcotg.h:619
uint32_t startofframecount
Number of requests queued to wait for start of frame.
Definition dwcotg.h:657
MUTEX_HANDLE channelfreelock
Lock for access to ChannelFreeMask.
Definition dwcotg.h:633
uint32_t transactionrestartcount
Number of times a transaction is restarted to continue or complete the transfer.
Definition dwcotg.h:676
USB_DEVICE_STATUS * devicestatus
Device status for the root hub.
Definition dwcotg.h:641
USB_STRING_DESCRIPTOR * hubstringtable[3]
String table for Language, Product and Manufacturer strings for the root hub.
Definition dwcotg.h:645
uint32_t irq
The IRQ assigned to this host.
Definition dwcotg.h:622
uint32_t completesplitcount
Number of complete split transactions.
Definition dwcotg.h:673
uint32_t completesplitrestartcount
Number of times a complete split transaction has been restarted at start split due to errors.
Definition dwcotg.h:674
uint32_t startsplitcount
Number of start split transactions.
Definition dwcotg.h:672
uint32_t babbleerrorcount
Number of babble errors received by the host controller.
Definition dwcotg.h:666
uint32_t lastframenumber
Frame Number at the last Start Of Frame interrupt.
Definition dwcotg.h:637
USB_HUB_DESCRIPTOR * hubdescriptor
Hub descriptor for the root hub.
Definition dwcotg.h:642
uint32_t nyetresponsecount
Number of NYET responses received by the host controller.
Definition dwcotg.h:661
MAILSLOT_HANDLE schedulermailslot
USB requests that have been submitted to the Host but not yet started on a channel.
Definition dwcotg.h:628
USB_STRING_DESCRIPTOR * hubmanufacturerstring
Manufacturer identifier string for the root hub.
Definition dwcotg.h:648
uint32_t transactionerrorcount
Number of transaction errors received by the host controller.
Definition dwcotg.h:665
THREAD_HANDLE schedulerthread
Thread ID of USB request scheduler thread.
Definition dwcotg.h:626
DWC_ROOTHUB_CONFIGURATION * hubconfiguration
Configuration, Interface and Endpoint descriptors for the root hub.
Definition dwcotg.h:644
uint32_t startofframemask
Bitmap of channels waiting for Start of Frame.
Definition dwcotg.h:635
uint32_t interruptcount
Number of interrupt requests received by the host controller.
Definition dwcotg.h:651
uint32_t stallresponsecount
Number of Stall responses received by the host controller.
Definition dwcotg.h:662
uint32_t portinterruptcount
Number of port interrupts received by the host controller.
Definition dwcotg.h:652
uint32_t framelistrollovercount
Number of frame list rollover errors received by the host controller.
Definition dwcotg.h:668
uint32_t startofframeinterruptcount
Number of start of frame interrupts received by the host controller.
Definition dwcotg.h:654
USB_STRING_DESCRIPTOR * hubproductstring
Product identifier string for the root hub.
Definition dwcotg.h:646
SPIN_HANDLE lock
Host lock (Differs from lock in Host portion) (Spin lock due to use by interrupt handler).
Definition dwcotg.h:621
USB_REQUEST * channelrequests[DWC_MAX_CHANNELS]
Current USB request pending on each hardware channel (or nil of no request is pending).
Definition dwcotg.h:631
USB_STRING_DESCRIPTOR * hublanguagestring
Language identifier string for the root hub.
Definition dwcotg.h:647
SEMAPHORE_HANDLE channelfreewait
Number of free channels in ChannelFreeMask.
Definition dwcotg.h:634
uint32_t channelfreemask
Bitmap of channel free (1) or used (0) status.
Definition dwcotg.h:632
USB_PORT_STATUS * portstatus
Host port status for the root hub (Obtained from port interrupt due to status change).
Definition dwcotg.h:640
uint32_t disconnectinterruptcount
Number of disconnect interrupts received by the host controller.
Definition dwcotg.h:655
uint32_t dmabufferreadcount
Number of IN requests that required a DMA buffer copy.
Definition dwcotg.h:658
uint32_t channelinterruptcount
Number of channel interrupts received by the host controller.
Definition dwcotg.h:653
uint32_t excesstransactioncount
Number of excess transaction errors received by the host controller.
Definition dwcotg.h:667
uint32_t dmabufferwritecount
Number of OUT requests that required a DMA buffer copy.
Definition dwcotg.h:659
uint32_t nopacketstransferredcount
Number of times no packets were transferred but no error occured when a channel halted.
Definition dwcotg.h:678
uint32_t nakresponsecount
Number of NAK responses received by the host controller.
Definition dwcotg.h:660
uint32_t requestcancelcount
Number of requests Cancelled by the host controller.
Definition dwcotg.h:663
USB_HUB_STATUS * hubstatus
Hub status for the root hub.
Definition dwcotg.h:639
SPIN_HANDLE startofframelock
Lock for access to StartOfFrameMask (Spin lock due to use by interrupt handler).
Definition dwcotg.h:636
THREAD_HANDLE completionthread
Thread ID of USB request completion thread.
Definition dwcotg.h:627
uint32_t resubmitcount
Number of requests resubmitted for later retry.
Definition dwcotg.h:656
void * dmabuffers[DWC_MAX_CHANNELS]
DMA buffers allocated for each hardware channel (4 byte aligned / 1 per channel).
Definition dwcotg.h:630
DWC_REGISTERS * registers
Memory mapped registers of the Synopsys DesignWare Hi-Speed USB 2.0 OTG Controller.
Definition dwcotg.h:624
uint32_t frameoverruncount
Number of frame overrun errors received by the host controller.
Definition dwcotg.h:670
uint32_t ahberrorcount
Number of AHB errors received by the host controller.
Definition dwcotg.h:664
uint32_t datatoggleerrorcount
Number of data toggle errors received by the host controller.
Definition dwcotg.h:669
uint32_t powerid
The Power ID required to power on this host.
Definition dwcotg.h:623
uint32_t transferrestartcount
Number of times a transfer is restarted to continue or retry the transfer.
Definition dwcotg.h:675
USB_REQUEST * hubstatuschange
Status change request to the root hub interrupt endpoint (nil if no request is pending).
Definition dwcotg.h:649
uint32_t shortattemptcount
Number of short attempts where transfer size was less than the request size.
Definition dwcotg.h:671
uint32_t nochannelcompletedcount
Number of times the channel completed interrupt bit was not set when a request completed.
Definition dwcotg.h:677
uint32_t channelcount
The number of channels available on this host.
Definition dwcotg.h:625
struct _USB_PORT_STATUS USB_PORT_STATUS
Definition usb.h:1086
struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR
Definition usb.h:796
struct _USB_ENDPOINT_DESCRIPTOR USB_ENDPOINT_DESCRIPTOR
Definition usb.h:825
struct _USB_HUB_DESCRIPTOR USB_HUB_DESCRIPTOR
Definition usb.h:1071
struct _USB_HUB_STATUS USB_HUB_STATUS
Definition usb.h:1094
struct _USB_DEVICE_STATUS USB_DEVICE_STATUS
Definition usb.h:850
struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR
Definition usb.h:776
struct _USB_REQUEST USB_REQUEST
Forward declared to satisfy USBHost.
Definition usb.h:974
struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR
Definition usb.h:837
struct _USB_INTERFACE_DESCRIPTOR USB_INTERFACE_DESCRIPTOR
Definition usb.h:810
struct _USB_HOST USB_HOST
Forward declared to satisfy USBDevice.
Definition usb.h:857