move ehci and ohci to portable folder
This commit is contained in:
901
src/portable/ehci/ehci.c
Normal file
901
src/portable/ehci/ehci.c
Normal file
@@ -0,0 +1,901 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#if TUSB_OPT_HOST_ENABLED && \
|
||||
(CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || \
|
||||
CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX )
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "osal/osal.h"
|
||||
|
||||
#include "host/hcd.h"
|
||||
#include "host/usbh_hcd.h"
|
||||
#include "ehci.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
// Periodic frame list must be 4K alignment
|
||||
CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4096) static ehci_data_t ehci_data;
|
||||
|
||||
// EHCI portable
|
||||
uint32_t hcd_ehci_register_addr(uint8_t rhport);
|
||||
bool hcd_ehci_init (uint8_t rhport); // TODO move later
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PROTOTYPE
|
||||
//--------------------------------------------------------------------+
|
||||
static inline ehci_link_t* get_period_head(uint8_t rhport, uint8_t interval_ms)
|
||||
{
|
||||
(void) rhport;
|
||||
return (ehci_link_t*) &ehci_data.period_head_arr[ tu_log2( tu_min8(EHCI_FRAMELIST_SIZE, interval_ms) ) ];
|
||||
}
|
||||
|
||||
static inline ehci_qhd_t* qhd_control(uint8_t dev_addr)
|
||||
{
|
||||
return &ehci_data.control[dev_addr].qhd;
|
||||
}
|
||||
|
||||
static inline ehci_qhd_t* qhd_async_head(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
return qhd_control(0); // control qhd of dev0 is used as async head
|
||||
}
|
||||
|
||||
static inline ehci_qtd_t* qtd_control(uint8_t dev_addr)
|
||||
{
|
||||
return &ehci_data.control[dev_addr].qtd;
|
||||
}
|
||||
|
||||
|
||||
static inline ehci_qhd_t* qhd_next (ehci_qhd_t const * p_qhd);
|
||||
static inline ehci_qhd_t* qhd_find_free (void);
|
||||
static inline ehci_qhd_t* qhd_get_from_addr (uint8_t dev_addr, uint8_t ep_addr);
|
||||
|
||||
// determine if a queue head has bus-related error
|
||||
static inline bool qhd_has_xact_error (ehci_qhd_t * p_qhd)
|
||||
{
|
||||
return (p_qhd->qtd_overlay.buffer_err || p_qhd->qtd_overlay.babble_err || p_qhd->qtd_overlay.xact_err);
|
||||
//p_qhd->qtd_overlay.non_hs_period_missed_uframe || p_qhd->qtd_overlay.pingstate_err TODO split transaction error
|
||||
}
|
||||
|
||||
static void qhd_init (ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc);
|
||||
|
||||
static inline ehci_qtd_t* qtd_find_free (void);
|
||||
static inline ehci_qtd_t* qtd_next (ehci_qtd_t const * p_qtd);
|
||||
static inline void qtd_insert_to_qhd (ehci_qhd_t *p_qhd, ehci_qtd_t *p_qtd_new);
|
||||
static inline void qtd_remove_1st_from_qhd (ehci_qhd_t *p_qhd);
|
||||
static void qtd_init (ehci_qtd_t* p_qtd, void* buffer, uint16_t total_bytes);
|
||||
|
||||
static inline void list_insert (ehci_link_t *current, ehci_link_t *new, uint8_t new_type);
|
||||
static inline ehci_link_t* list_next (ehci_link_t *p_link_pointer);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HCD API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
uint32_t hcd_uframe_number(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
return ehci_data.uframe_number + ehci_data.regs->frame_index;
|
||||
}
|
||||
|
||||
void hcd_port_reset(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
ehci_registers_t* regs = ehci_data.regs;
|
||||
|
||||
// regs->portsc_bm.port_enabled = 0; // disable port before reset
|
||||
// regs->portsc_bm.port_reset = 1;
|
||||
|
||||
uint32_t portsc = regs->portsc;
|
||||
|
||||
portsc &= ~(EHCI_PORTSC_MASK_PORT_EANBLED);
|
||||
portsc |= EHCI_PORTSC_MASK_PORT_RESET;
|
||||
|
||||
regs->portsc = portsc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void hcd_port_reset_end(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
ehci_registers_t* regs = ehci_data.regs;
|
||||
regs->portsc_bm.port_reset = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool hcd_port_connect_status(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
return ehci_data.regs->portsc_bm.current_connect_status;
|
||||
}
|
||||
|
||||
tusb_speed_t hcd_port_speed_get(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
return (tusb_speed_t) ehci_data.regs->portsc_bm.nxp_port_speed; // NXP specific port speed
|
||||
}
|
||||
|
||||
static void list_remove_qhd_by_addr(ehci_link_t* list_head, uint8_t dev_addr)
|
||||
{
|
||||
for(ehci_link_t* prev = list_head;
|
||||
!prev->terminate && (tu_align32(prev->address) != (uint32_t) list_head);
|
||||
prev = list_next(prev) )
|
||||
{
|
||||
// TODO check type for ISO iTD and siTD
|
||||
ehci_qhd_t* qhd = (ehci_qhd_t*) list_next(prev);
|
||||
if ( qhd->dev_addr == dev_addr )
|
||||
{
|
||||
// TODO deactive all TD, wait for QHD to inactive before removal
|
||||
prev->address = qhd->next.address;
|
||||
|
||||
// EHCI 4.8.2 link the removed qhd to async head (which always reachable by Host Controller)
|
||||
qhd->next.address = ((uint32_t) list_head) | (EHCI_QTYPE_QHD << 1);
|
||||
|
||||
if ( qhd->int_smask )
|
||||
{
|
||||
// period list queue element is guarantee to be free in the next frame (1 ms)
|
||||
qhd->used = 0;
|
||||
}else
|
||||
{
|
||||
// async list use async advance handshake
|
||||
// mark as removing, will completely re-usable when async advance isr occurs
|
||||
qhd->removing = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close all opened endpoint belong to this device
|
||||
void hcd_device_close(uint8_t rhport, uint8_t dev_addr)
|
||||
{
|
||||
// skip dev0
|
||||
if (dev_addr == 0) return;
|
||||
|
||||
// Remove from async list
|
||||
list_remove_qhd_by_addr( (ehci_link_t*) qhd_async_head(rhport), dev_addr );
|
||||
|
||||
// Remove from all interval period list
|
||||
for(uint8_t i = 0; i < TU_ARRAY_SIZE(ehci_data.period_head_arr); i++)
|
||||
{
|
||||
list_remove_qhd_by_addr( (ehci_link_t*) &ehci_data.period_head_arr[i], dev_addr);
|
||||
}
|
||||
|
||||
// Async doorbell (EHCI 4.8.2 for operational details)
|
||||
ehci_data.regs->command_bm.async_adv_doorbell = 1;
|
||||
}
|
||||
|
||||
// EHCI controller init
|
||||
bool hcd_ehci_init(uint8_t rhport)
|
||||
{
|
||||
tu_memclr(&ehci_data, sizeof(ehci_data_t));
|
||||
|
||||
ehci_data.regs = (ehci_registers_t* ) hcd_ehci_register_addr(rhport);
|
||||
|
||||
ehci_registers_t* regs = ehci_data.regs;
|
||||
|
||||
//------------- CTRLDSSEGMENT Register (skip) -------------//
|
||||
//------------- USB INT Register -------------//
|
||||
regs->inten = 0; // 1. disable all the interrupt
|
||||
regs->status = EHCI_INT_MASK_ALL; // 2. clear all status
|
||||
|
||||
regs->inten = EHCI_INT_MASK_ERROR | EHCI_INT_MASK_PORT_CHANGE | EHCI_INT_MASK_ASYNC_ADVANCE |
|
||||
EHCI_INT_MASK_NXP_PERIODIC | EHCI_INT_MASK_NXP_ASYNC | EHCI_INT_MASK_FRAMELIST_ROLLOVER;
|
||||
|
||||
//------------- Asynchronous List -------------//
|
||||
ehci_qhd_t * const async_head = qhd_async_head(rhport);
|
||||
tu_memclr(async_head, sizeof(ehci_qhd_t));
|
||||
|
||||
async_head->next.address = (uint32_t) async_head; // circular list, next is itself
|
||||
async_head->next.type = EHCI_QTYPE_QHD;
|
||||
async_head->head_list_flag = 1;
|
||||
async_head->qtd_overlay.halted = 1; // inactive most of time
|
||||
async_head->qtd_overlay.next.terminate = 1; // TODO removed if verified
|
||||
|
||||
regs->async_list_addr = (uint32_t) async_head;
|
||||
|
||||
//------------- Periodic List -------------//
|
||||
// Build the polling interval tree with 1 ms, 2 ms, 4 ms and 8 ms (framesize) only
|
||||
for(uint32_t i=0; i<4; i++)
|
||||
{
|
||||
ehci_data.period_head_arr[i].int_smask = 1; // queue head in period list must have smask non-zero
|
||||
ehci_data.period_head_arr[i].qtd_overlay.halted = 1; // dummy node, always inactive
|
||||
}
|
||||
|
||||
ehci_link_t * const framelist = ehci_data.period_framelist;
|
||||
ehci_link_t * const period_1ms = get_period_head(rhport, 1);
|
||||
// all links --> period_head_arr[0] (1ms)
|
||||
// 0, 2, 4, 6 etc --> period_head_arr[1] (2ms)
|
||||
// 1, 5 --> period_head_arr[2] (4ms)
|
||||
// 3 --> period_head_arr[3] (8ms)
|
||||
|
||||
// TODO EHCI_FRAMELIST_SIZE with other size than 8
|
||||
for(uint32_t i=0; i<EHCI_FRAMELIST_SIZE; i++)
|
||||
{
|
||||
framelist[i].address = (uint32_t) period_1ms;
|
||||
framelist[i].type = EHCI_QTYPE_QHD;
|
||||
}
|
||||
|
||||
for(uint32_t i=0; i<EHCI_FRAMELIST_SIZE; i+=2)
|
||||
{
|
||||
list_insert(framelist + i, get_period_head(rhport, 2), EHCI_QTYPE_QHD);
|
||||
}
|
||||
|
||||
for(uint32_t i=1; i<EHCI_FRAMELIST_SIZE; i+=4)
|
||||
{
|
||||
list_insert(framelist + i, get_period_head(rhport, 4), EHCI_QTYPE_QHD);
|
||||
}
|
||||
|
||||
list_insert(framelist+3, get_period_head(rhport, 8), EHCI_QTYPE_QHD);
|
||||
|
||||
period_1ms->terminate = 1;
|
||||
|
||||
regs->periodic_list_base = (uint32_t) framelist;
|
||||
|
||||
//------------- TT Control (NXP only) -------------//
|
||||
regs->nxp_tt_control = 0;
|
||||
|
||||
//------------- USB CMD Register -------------//
|
||||
regs->command |= TU_BIT(EHCI_USBCMD_POS_RUN_STOP) | TU_BIT(EHCI_USBCMD_POS_ASYNC_ENABLE)
|
||||
| TU_BIT(EHCI_USBCMD_POS_PERIOD_ENABLE) // TODO enable period list only there is int/iso endpoint
|
||||
| ((EHCI_CFG_FRAMELIST_SIZE_BITS & TU_BIN8(011)) << EHCI_USBCMD_POS_FRAMELIST_SZIE)
|
||||
| ((EHCI_CFG_FRAMELIST_SIZE_BITS >> 2) << EHCI_USBCMD_POS_NXP_FRAMELIST_SIZE_MSB);
|
||||
|
||||
//------------- ConfigFlag Register (skip) -------------//
|
||||
regs->portsc_bm.port_power = 1; // enable port power
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void ehci_stop(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
ehci_registers_t* regs = ehci_data.regs;
|
||||
|
||||
regs->command_bm.run_stop = 0;
|
||||
|
||||
// USB Spec: controller has to stop within 16 uframe = 2 frames
|
||||
while( regs->status_bm.hc_halted == 0 ) {}
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CONTROL PIPE API
|
||||
//--------------------------------------------------------------------+
|
||||
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
// FIXME control only for now
|
||||
if ( epnum == 0 )
|
||||
{
|
||||
ehci_qhd_t* qhd = qhd_control(dev_addr);
|
||||
ehci_qtd_t* qtd = qtd_control(dev_addr);
|
||||
|
||||
qtd_init(qtd, buffer, buflen);
|
||||
|
||||
// first first data toggle is always 1 (data & setup stage)
|
||||
qtd->data_toggle = 1;
|
||||
qtd->pid = dir ? EHCI_PID_IN : EHCI_PID_OUT;
|
||||
qtd->int_on_complete = 1;
|
||||
qtd->next.terminate = 1;
|
||||
|
||||
// sw region
|
||||
qhd->p_qtd_list_head = qtd;
|
||||
qhd->p_qtd_list_tail = qtd;
|
||||
|
||||
// attach TD
|
||||
qhd->qtd_overlay.next.address = (uint32_t) qtd;
|
||||
}else
|
||||
{
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr);
|
||||
ehci_qtd_t *p_qtd = qtd_find_free();
|
||||
TU_ASSERT(p_qtd);
|
||||
|
||||
qtd_init(p_qtd, buffer, buflen);
|
||||
p_qtd->pid = p_qhd->pid;
|
||||
|
||||
// Insert TD to QH
|
||||
qtd_insert_to_qhd(p_qhd, p_qtd);
|
||||
|
||||
p_qhd->p_qtd_list_tail->int_on_complete = 1;
|
||||
|
||||
// attach head QTD to QHD start transferring
|
||||
p_qhd->qtd_overlay.next.address = (uint32_t) p_qhd->p_qtd_list_head;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8])
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
ehci_qhd_t* qhd = &ehci_data.control[dev_addr].qhd;
|
||||
ehci_qtd_t* td = &ehci_data.control[dev_addr].qtd;
|
||||
|
||||
qtd_init(td, (void*) setup_packet, 8);
|
||||
td->pid = EHCI_PID_SETUP;
|
||||
td->int_on_complete = 1;
|
||||
td->next.terminate = 1;
|
||||
|
||||
// sw region
|
||||
qhd->p_qtd_list_head = td;
|
||||
qhd->p_qtd_list_tail = td;
|
||||
|
||||
// attach TD
|
||||
qhd->qtd_overlay.next.address = (uint32_t) td;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// BULK/INT/ISO PIPE API
|
||||
//--------------------------------------------------------------------+
|
||||
bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
// TODO not support ISO yet
|
||||
TU_ASSERT (ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
|
||||
|
||||
//------------- Prepare Queue Head -------------//
|
||||
ehci_qhd_t * p_qhd;
|
||||
|
||||
if ( ep_desc->bEndpointAddress == 0 )
|
||||
{
|
||||
p_qhd = qhd_control(dev_addr);
|
||||
}else
|
||||
{
|
||||
p_qhd = qhd_find_free();
|
||||
}
|
||||
TU_ASSERT(p_qhd);
|
||||
|
||||
qhd_init(p_qhd, dev_addr, ep_desc);
|
||||
|
||||
// control of dev0 is always present as async head
|
||||
if ( dev_addr == 0 ) return true;
|
||||
|
||||
// Insert to list
|
||||
ehci_link_t * list_head = NULL;
|
||||
|
||||
switch (ep_desc->bmAttributes.xfer)
|
||||
{
|
||||
case TUSB_XFER_CONTROL:
|
||||
case TUSB_XFER_BULK:
|
||||
list_head = (ehci_link_t*) qhd_async_head(rhport);
|
||||
break;
|
||||
|
||||
case TUSB_XFER_INTERRUPT:
|
||||
list_head = get_period_head(rhport, p_qhd->interval_ms);
|
||||
break;
|
||||
|
||||
case TUSB_XFER_ISOCHRONOUS:
|
||||
// TODO iso is not supported
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
TU_ASSERT(list_head);
|
||||
|
||||
// TODO might need to disable async/period list
|
||||
list_insert(list_head, (ehci_link_t*) p_qhd, EHCI_QTYPE_QHD);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes)
|
||||
{
|
||||
//------------- set up QTD -------------//
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr);
|
||||
ehci_qtd_t *p_qtd = qtd_find_free();
|
||||
|
||||
TU_ASSERT(p_qtd);
|
||||
|
||||
qtd_init(p_qtd, buffer, total_bytes);
|
||||
p_qtd->pid = p_qhd->pid;
|
||||
|
||||
//------------- insert TD to TD list -------------//
|
||||
qtd_insert_to_qhd(p_qhd, p_qtd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete)
|
||||
{
|
||||
TU_ASSERT ( hcd_pipe_queue_xfer(dev_addr, ep_addr, buffer, total_bytes) );
|
||||
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr);
|
||||
|
||||
if ( int_on_complete )
|
||||
{ // the just added qtd is pointed by list_tail
|
||||
p_qhd->p_qtd_list_tail->int_on_complete = 1;
|
||||
}
|
||||
p_qhd->qtd_overlay.next.address = (uint32_t) p_qhd->p_qtd_list_head; // attach head QTD to QHD start transferring
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr);
|
||||
return !p_qhd->qtd_overlay.halted && (p_qhd->p_qtd_list_head != NULL);
|
||||
}
|
||||
|
||||
bool hcd_edpt_stalled(uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr);
|
||||
return p_qhd->qtd_overlay.halted && !qhd_has_xact_error(p_qhd);
|
||||
}
|
||||
|
||||
bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
ehci_qhd_t *p_qhd = qhd_get_from_addr(dev_addr, ep_addr);
|
||||
p_qhd->qtd_overlay.halted = 0;
|
||||
// TODO reset data toggle ?
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// EHCI Interrupt Handler
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// async_advance is handshake between usb stack & ehci controller.
|
||||
// This isr mean it is safe to modify previously removed queue head from async list.
|
||||
// In tinyusb, queue head is only removed when device is unplugged.
|
||||
static void async_advance_isr(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
ehci_qhd_t* qhd_pool = ehci_data.qhd_pool;
|
||||
for(uint32_t i = 0; i < HCD_MAX_ENDPOINT; i++)
|
||||
{
|
||||
if ( qhd_pool[i].removing )
|
||||
{
|
||||
qhd_pool[i].removing = 0;
|
||||
qhd_pool[i].used = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void port_connect_status_change_isr(uint8_t hostid)
|
||||
{
|
||||
// NOTE There is an sequence plug->unplug->…..-> plug if device is powering with pre-plugged device
|
||||
if (ehci_data.regs->portsc_bm.current_connect_status)
|
||||
{
|
||||
hcd_port_reset(hostid);
|
||||
hcd_event_device_attach(hostid, true);
|
||||
}else // device unplugged
|
||||
{
|
||||
hcd_event_device_remove(hostid, true);
|
||||
}
|
||||
}
|
||||
|
||||
static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd)
|
||||
{
|
||||
// free all TDs from the head td to the first active TD
|
||||
while(p_qhd->p_qtd_list_head != NULL && !p_qhd->p_qtd_list_head->active)
|
||||
{
|
||||
// TD need to be freed and removed from qhd, before invoking callback
|
||||
bool is_ioc = (p_qhd->p_qtd_list_head->int_on_complete != 0);
|
||||
p_qhd->total_xferred_bytes += p_qhd->p_qtd_list_head->expected_bytes - p_qhd->p_qtd_list_head->total_bytes;
|
||||
|
||||
p_qhd->p_qtd_list_head->used = 0; // free QTD
|
||||
qtd_remove_1st_from_qhd(p_qhd);
|
||||
|
||||
if (is_ioc)
|
||||
{
|
||||
// end of request
|
||||
// call USBH callback
|
||||
hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), p_qhd->total_xferred_bytes, XFER_RESULT_SUCCESS, true);
|
||||
p_qhd->total_xferred_bytes = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void async_list_xfer_complete_isr(ehci_qhd_t * const async_head)
|
||||
{
|
||||
ehci_qhd_t *p_qhd = async_head;
|
||||
do
|
||||
{
|
||||
if ( !p_qhd->qtd_overlay.halted ) // halted or error is processed in error isr
|
||||
{
|
||||
qhd_xfer_complete_isr(p_qhd);
|
||||
}
|
||||
p_qhd = qhd_next(p_qhd);
|
||||
}while(p_qhd != async_head); // async list traversal, stop if loop around
|
||||
}
|
||||
|
||||
static void period_list_xfer_complete_isr(uint8_t hostid, uint8_t interval_ms)
|
||||
{
|
||||
uint16_t max_loop = 0;
|
||||
uint32_t const period_1ms_addr = (uint32_t) get_period_head(hostid, 1);
|
||||
ehci_link_t next_item = * get_period_head(hostid, interval_ms);
|
||||
|
||||
// TODO abstract max loop guard for period
|
||||
while( !next_item.terminate &&
|
||||
!(interval_ms > 1 && period_1ms_addr == tu_align32(next_item.address)) &&
|
||||
max_loop < (HCD_MAX_ENDPOINT + EHCI_MAX_ITD + EHCI_MAX_SITD)*CFG_TUSB_HOST_DEVICE_MAX)
|
||||
{
|
||||
switch ( next_item.type )
|
||||
{
|
||||
case EHCI_QTYPE_QHD:
|
||||
{
|
||||
ehci_qhd_t *p_qhd_int = (ehci_qhd_t *) tu_align32(next_item.address);
|
||||
if ( !p_qhd_int->qtd_overlay.halted )
|
||||
{
|
||||
qhd_xfer_complete_isr(p_qhd_int);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EHCI_QTYPE_ITD: // TODO support hs/fs ISO
|
||||
case EHCI_QTYPE_SITD:
|
||||
case EHCI_QTYPE_FSTN:
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
next_item = *list_next(&next_item);
|
||||
max_loop++;
|
||||
}
|
||||
}
|
||||
|
||||
static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd)
|
||||
{
|
||||
if ( (p_qhd->dev_addr != 0 && p_qhd->qtd_overlay.halted) || // addr0 cannot be protocol STALL
|
||||
qhd_has_xact_error(p_qhd) )
|
||||
{
|
||||
// current qhd has error in transaction
|
||||
xfer_result_t error_event;
|
||||
|
||||
// no error bits are set, endpoint is halted due to STALL
|
||||
error_event = qhd_has_xact_error(p_qhd) ? XFER_RESULT_FAILED : XFER_RESULT_STALLED;
|
||||
|
||||
p_qhd->total_xferred_bytes += p_qhd->p_qtd_list_head->expected_bytes - p_qhd->p_qtd_list_head->total_bytes;
|
||||
|
||||
// if ( XFER_RESULT_FAILED == error_event ) TU_BREAKPOINT(); // TODO skip unplugged device
|
||||
|
||||
p_qhd->p_qtd_list_head->used = 0; // free QTD
|
||||
qtd_remove_1st_from_qhd(p_qhd);
|
||||
|
||||
if ( 0 == p_qhd->ep_number )
|
||||
{
|
||||
// control cannot be halted --> clear all qtd list
|
||||
p_qhd->p_qtd_list_head = NULL;
|
||||
p_qhd->p_qtd_list_tail = NULL;
|
||||
|
||||
p_qhd->qtd_overlay.next.terminate = 1;
|
||||
p_qhd->qtd_overlay.alternate.terminate = 1;
|
||||
p_qhd->qtd_overlay.halted = 0;
|
||||
|
||||
ehci_qtd_t *p_setup = qtd_control(p_qhd->dev_addr);
|
||||
p_setup->used = 0;
|
||||
}
|
||||
|
||||
// call USBH callback
|
||||
hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), p_qhd->total_xferred_bytes, error_event, true);
|
||||
|
||||
p_qhd->total_xferred_bytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void xfer_error_isr(uint8_t hostid)
|
||||
{
|
||||
//------------- async list -------------//
|
||||
ehci_qhd_t * const async_head = qhd_async_head(hostid);
|
||||
ehci_qhd_t *p_qhd = async_head;
|
||||
do
|
||||
{
|
||||
qhd_xfer_error_isr( p_qhd );
|
||||
p_qhd = qhd_next(p_qhd);
|
||||
}while(p_qhd != async_head); // async list traversal, stop if loop around
|
||||
|
||||
//------------- TODO refractor period list -------------//
|
||||
uint32_t const period_1ms_addr = (uint32_t) get_period_head(hostid, 1);
|
||||
for (uint8_t interval_ms=1; interval_ms <= EHCI_FRAMELIST_SIZE; interval_ms *= 2)
|
||||
{
|
||||
ehci_link_t next_item = * get_period_head(hostid, interval_ms);
|
||||
|
||||
// TODO abstract max loop guard for period
|
||||
while( !next_item.terminate &&
|
||||
!(interval_ms > 1 && period_1ms_addr == tu_align32(next_item.address)) )
|
||||
{
|
||||
switch ( next_item.type )
|
||||
{
|
||||
case EHCI_QTYPE_QHD:
|
||||
{
|
||||
ehci_qhd_t *p_qhd_int = (ehci_qhd_t *) tu_align32(next_item.address);
|
||||
qhd_xfer_error_isr(p_qhd_int);
|
||||
}
|
||||
break;
|
||||
|
||||
// TODO support hs/fs ISO
|
||||
case EHCI_QTYPE_ITD:
|
||||
case EHCI_QTYPE_SITD:
|
||||
case EHCI_QTYPE_FSTN:
|
||||
default: break;
|
||||
}
|
||||
|
||||
next_item = *list_next(&next_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------- Host Controller Driver's Interrupt Handler -------------//
|
||||
void hcd_int_handler(uint8_t rhport)
|
||||
{
|
||||
ehci_registers_t* regs = ehci_data.regs;
|
||||
|
||||
uint32_t int_status = regs->status;
|
||||
int_status &= regs->inten;
|
||||
|
||||
regs->status |= int_status; // Acknowledge handled interrupt
|
||||
|
||||
if (int_status == 0) return;
|
||||
|
||||
if (int_status & EHCI_INT_MASK_FRAMELIST_ROLLOVER)
|
||||
{
|
||||
ehci_data.uframe_number += (EHCI_FRAMELIST_SIZE << 3);
|
||||
}
|
||||
|
||||
if (int_status & EHCI_INT_MASK_PORT_CHANGE)
|
||||
{
|
||||
uint32_t port_status = regs->portsc & EHCI_PORTSC_MASK_ALL;
|
||||
|
||||
if (regs->portsc_bm.connect_status_change)
|
||||
{
|
||||
port_connect_status_change_isr(rhport);
|
||||
}
|
||||
|
||||
regs->portsc |= port_status; // Acknowledge change bits in portsc
|
||||
}
|
||||
|
||||
if (int_status & EHCI_INT_MASK_ERROR)
|
||||
{
|
||||
xfer_error_isr(rhport);
|
||||
}
|
||||
|
||||
//------------- some QTD/SITD/ITD with IOC set is completed -------------//
|
||||
if (int_status & EHCI_INT_MASK_NXP_ASYNC)
|
||||
{
|
||||
async_list_xfer_complete_isr( qhd_async_head(rhport) );
|
||||
}
|
||||
|
||||
if (int_status & EHCI_INT_MASK_NXP_PERIODIC)
|
||||
{
|
||||
for (uint8_t i=1; i <= EHCI_FRAMELIST_SIZE; i *= 2)
|
||||
{
|
||||
period_list_xfer_complete_isr( rhport, i );
|
||||
}
|
||||
}
|
||||
|
||||
//------------- There is some removed async previously -------------//
|
||||
if (int_status & EHCI_INT_MASK_ASYNC_ADVANCE) // need to place after EHCI_INT_MASK_NXP_ASYNC
|
||||
{
|
||||
async_advance_isr(rhport);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HELPER
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
//------------- queue head helper -------------//
|
||||
static inline ehci_qhd_t* qhd_find_free (void)
|
||||
{
|
||||
for (uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
|
||||
{
|
||||
if ( !ehci_data.qhd_pool[i].used ) return &ehci_data.qhd_pool[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline ehci_qhd_t* qhd_next(ehci_qhd_t const * p_qhd)
|
||||
{
|
||||
return (ehci_qhd_t*) tu_align32(p_qhd->next.address);
|
||||
}
|
||||
|
||||
static inline ehci_qhd_t* qhd_get_from_addr(uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
ehci_qhd_t* qhd_pool = ehci_data.qhd_pool;
|
||||
|
||||
for(uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
|
||||
{
|
||||
if ( (qhd_pool[i].dev_addr == dev_addr) &&
|
||||
ep_addr == tu_edpt_addr(qhd_pool[i].ep_number, qhd_pool[i].pid) )
|
||||
{
|
||||
return &qhd_pool[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//------------- TD helper -------------//
|
||||
static inline ehci_qtd_t* qtd_find_free(void)
|
||||
{
|
||||
for (uint32_t i=0; i<HCD_MAX_XFER; i++)
|
||||
{
|
||||
if ( !ehci_data.qtd_pool[i].used ) return &ehci_data.qtd_pool[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline ehci_qtd_t* qtd_next(ehci_qtd_t const * p_qtd )
|
||||
{
|
||||
return (ehci_qtd_t*) tu_align32(p_qtd->next.address);
|
||||
}
|
||||
|
||||
static inline void qtd_remove_1st_from_qhd(ehci_qhd_t *p_qhd)
|
||||
{
|
||||
if (p_qhd->p_qtd_list_head == p_qhd->p_qtd_list_tail) // last TD --> make it NULL
|
||||
{
|
||||
p_qhd->p_qtd_list_head = p_qhd->p_qtd_list_tail = NULL;
|
||||
}else
|
||||
{
|
||||
p_qhd->p_qtd_list_head = qtd_next( p_qhd->p_qtd_list_head );
|
||||
}
|
||||
}
|
||||
|
||||
static inline void qtd_insert_to_qhd(ehci_qhd_t *p_qhd, ehci_qtd_t *p_qtd_new)
|
||||
{
|
||||
if (p_qhd->p_qtd_list_head == NULL) // empty list
|
||||
{
|
||||
p_qhd->p_qtd_list_head = p_qhd->p_qtd_list_tail = p_qtd_new;
|
||||
}else
|
||||
{
|
||||
p_qhd->p_qtd_list_tail->next.address = (uint32_t) p_qtd_new;
|
||||
p_qhd->p_qtd_list_tail = p_qtd_new;
|
||||
}
|
||||
}
|
||||
|
||||
static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc)
|
||||
{
|
||||
// address 0 is used as async head, which always on the list --> cannot be cleared (ehci halted otherwise)
|
||||
if (dev_addr != 0)
|
||||
{
|
||||
tu_memclr(p_qhd, sizeof(ehci_qhd_t));
|
||||
}
|
||||
|
||||
uint8_t const xfer_type = ep_desc->bmAttributes.xfer;
|
||||
uint8_t const interval = ep_desc->bInterval;
|
||||
|
||||
p_qhd->dev_addr = dev_addr;
|
||||
p_qhd->fl_inactive_next_xact = 0;
|
||||
p_qhd->ep_number = tu_edpt_number(ep_desc->bEndpointAddress);
|
||||
p_qhd->ep_speed = _usbh_devices[dev_addr].speed;
|
||||
p_qhd->data_toggle_control= (xfer_type == TUSB_XFER_CONTROL) ? 1 : 0;
|
||||
p_qhd->head_list_flag = (dev_addr == 0) ? 1 : 0; // addr0's endpoint is the static asyn list head
|
||||
p_qhd->max_packet_size = ep_desc->wMaxPacketSize.size;
|
||||
p_qhd->fl_ctrl_ep_flag = ((xfer_type == TUSB_XFER_CONTROL) && (p_qhd->ep_speed != TUSB_SPEED_HIGH)) ? 1 : 0;
|
||||
p_qhd->nak_reload = 0;
|
||||
|
||||
// Bulk/Control -> smask = cmask = 0
|
||||
// TODO Isochronous
|
||||
if (TUSB_XFER_INTERRUPT == xfer_type)
|
||||
{
|
||||
if (TUSB_SPEED_HIGH == p_qhd->ep_speed)
|
||||
{
|
||||
TU_ASSERT( interval <= 16, );
|
||||
if ( interval < 4) // sub milisecond interval
|
||||
{
|
||||
p_qhd->interval_ms = 0;
|
||||
p_qhd->int_smask = (interval == 1) ? TU_BIN8(11111111) :
|
||||
(interval == 2) ? TU_BIN8(10101010) : TU_BIN8(01000100);
|
||||
}else
|
||||
{
|
||||
p_qhd->interval_ms = (uint8_t) tu_min16( 1 << (interval-4), 255 );
|
||||
p_qhd->int_smask = TU_BIT(interval % 8);
|
||||
}
|
||||
}else
|
||||
{
|
||||
TU_ASSERT( 0 != interval, );
|
||||
// Full/Low: 4.12.2.1 (EHCI) case 1 schedule start split at 1 us & complete split at 2,3,4 uframes
|
||||
p_qhd->int_smask = 0x01;
|
||||
p_qhd->fl_int_cmask = TU_BIN8(11100);
|
||||
p_qhd->interval_ms = interval;
|
||||
}
|
||||
}else
|
||||
{
|
||||
p_qhd->int_smask = p_qhd->fl_int_cmask = 0;
|
||||
}
|
||||
|
||||
p_qhd->fl_hub_addr = _usbh_devices[dev_addr].hub_addr;
|
||||
p_qhd->fl_hub_port = _usbh_devices[dev_addr].hub_port;
|
||||
p_qhd->mult = 1; // TODO not use high bandwidth/park mode yet
|
||||
|
||||
//------------- HCD Management Data -------------//
|
||||
p_qhd->used = 1;
|
||||
p_qhd->removing = 0;
|
||||
p_qhd->p_qtd_list_head = NULL;
|
||||
p_qhd->p_qtd_list_tail = NULL;
|
||||
p_qhd->pid = tu_edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint
|
||||
|
||||
//------------- active, but no TD list -------------//
|
||||
p_qhd->qtd_overlay.halted = 0;
|
||||
p_qhd->qtd_overlay.next.terminate = 1;
|
||||
p_qhd->qtd_overlay.alternate.terminate = 1;
|
||||
if (TUSB_XFER_BULK == xfer_type && p_qhd->ep_speed == TUSB_SPEED_HIGH && p_qhd->pid == EHCI_PID_OUT)
|
||||
{
|
||||
p_qhd->qtd_overlay.ping_err = 1; // do PING for Highspeed Bulk OUT, EHCI section 4.11
|
||||
}
|
||||
}
|
||||
|
||||
static void qtd_init(ehci_qtd_t* p_qtd, void* buffer, uint16_t total_bytes)
|
||||
{
|
||||
tu_memclr(p_qtd, sizeof(ehci_qtd_t));
|
||||
|
||||
p_qtd->used = 1;
|
||||
|
||||
p_qtd->next.terminate = 1; // init to null
|
||||
p_qtd->alternate.terminate = 1; // not used, always set to terminated
|
||||
p_qtd->active = 1;
|
||||
p_qtd->err_count = 3; // TODO 3 consecutive errors tolerance
|
||||
p_qtd->data_toggle = 0;
|
||||
p_qtd->total_bytes = total_bytes;
|
||||
p_qtd->expected_bytes = total_bytes;
|
||||
|
||||
p_qtd->buffer[0] = (uint32_t) buffer;
|
||||
for(uint8_t i=1; i<5; i++)
|
||||
{
|
||||
p_qtd->buffer[i] |= tu_align4k( p_qtd->buffer[i-1] ) + 4096;
|
||||
}
|
||||
}
|
||||
|
||||
//------------- List Managing Helper -------------//
|
||||
static inline void list_insert(ehci_link_t *current, ehci_link_t *new, uint8_t new_type)
|
||||
{
|
||||
new->address = current->address;
|
||||
current->address = ((uint32_t) new) | (new_type << 1);
|
||||
}
|
||||
|
||||
static inline ehci_link_t* list_next(ehci_link_t *p_link_pointer)
|
||||
{
|
||||
return (ehci_link_t*) tu_align32(p_link_pointer->address);
|
||||
}
|
||||
|
||||
#endif
|
||||
460
src/portable/ehci/ehci.h
Normal file
460
src/portable/ehci/ehci.h
Normal file
@@ -0,0 +1,460 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_HCD
|
||||
* @{
|
||||
* \defgroup EHCI
|
||||
* \brief EHCI driver. All documents sources mentioned here (eg section 3.5) is referring to EHCI Specs unless state otherwise
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_EHCI_H_
|
||||
#define _TUSB_EHCI_H_
|
||||
|
||||
|
||||
/* Abbreviation
|
||||
* HC: Host Controller
|
||||
* HCD: Host Controller Driver
|
||||
* QHD: Queue Head for non-ISO transfer
|
||||
* QTD: Queue Transfer Descriptor for non-ISO transfer
|
||||
* ITD: Iso Transfer Descriptor for highspeed
|
||||
* SITD: Split ISO Transfer Descriptor for full-speed
|
||||
* SMASK: Start Split mask for Slipt Transaction
|
||||
* CMASK: Complete Split mask for Slipt Transaction
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// EHCI CONFIGURATION & CONSTANTS
|
||||
//--------------------------------------------------------------------+
|
||||
#define EHCI_CFG_FRAMELIST_SIZE_BITS 7 /// Framelist Size (NXP specific) (0:1024) - (1:512) - (2:256) - (3:128) - (4:64) - (5:32) - (6:16) - (7:8)
|
||||
#define EHCI_FRAMELIST_SIZE (1024 >> EHCI_CFG_FRAMELIST_SIZE_BITS)
|
||||
|
||||
// TODO merge OHCI with EHCI
|
||||
enum {
|
||||
EHCI_MAX_ITD = 4,
|
||||
EHCI_MAX_SITD = 16
|
||||
};
|
||||
|
||||
//------------- Validation -------------//
|
||||
TU_VERIFY_STATIC(EHCI_CFG_FRAMELIST_SIZE_BITS <= 7, "incorrect value");
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// EHCI Data Structure
|
||||
//--------------------------------------------------------------------+
|
||||
enum
|
||||
{
|
||||
EHCI_QTYPE_ITD = 0 ,
|
||||
EHCI_QTYPE_QHD ,
|
||||
EHCI_QTYPE_SITD ,
|
||||
EHCI_QTYPE_FSTN
|
||||
};
|
||||
|
||||
/// EHCI PID
|
||||
enum
|
||||
{
|
||||
EHCI_PID_OUT = 0 ,
|
||||
EHCI_PID_IN ,
|
||||
EHCI_PID_SETUP
|
||||
};
|
||||
|
||||
/// Link pointer
|
||||
typedef union {
|
||||
uint32_t address;
|
||||
struct {
|
||||
uint32_t terminate : 1;
|
||||
uint32_t type : 2;
|
||||
};
|
||||
}ehci_link_t;
|
||||
|
||||
/// Queue Element Transfer Descriptor
|
||||
/// Qtd is used to declare overlay in ehci_qhd_t -> cannot be declared with TU_ATTR_ALIGNED(32)
|
||||
typedef struct
|
||||
{
|
||||
// Word 0: Next QTD Pointer
|
||||
ehci_link_t next;
|
||||
|
||||
// Word 1: Alternate Next QTD Pointer (not used)
|
||||
union{
|
||||
ehci_link_t alternate;
|
||||
struct {
|
||||
uint32_t : 5;
|
||||
uint32_t used : 1;
|
||||
uint32_t : 10;
|
||||
uint32_t expected_bytes : 16;
|
||||
};
|
||||
};
|
||||
|
||||
// Word 2: qTQ Token
|
||||
volatile uint32_t ping_err : 1 ; ///< For Highspeed: 0 Out, 1 Ping. Full/Slow used as error indicator
|
||||
volatile uint32_t non_hs_split_state : 1 ; ///< Used by HC to track the state of slipt transaction
|
||||
volatile uint32_t non_hs_missed_uframe : 1 ; ///< HC misses a complete slip transaction
|
||||
volatile uint32_t xact_err : 1 ; ///< Error (Timeout, CRC, Bad PID ... )
|
||||
volatile uint32_t babble_err : 1 ; ///< Babble detected, also set Halted bit to 1
|
||||
volatile uint32_t buffer_err : 1 ; ///< Data overrun/underrun error
|
||||
volatile uint32_t halted : 1 ; ///< Serious error or STALL received
|
||||
volatile uint32_t active : 1 ; ///< Start transfer, clear by HC when complete
|
||||
|
||||
uint32_t pid : 2 ; ///< 0: OUT, 1: IN, 2 Setup
|
||||
volatile uint32_t err_count : 2 ; ///< Error Counter of consecutive errors
|
||||
volatile uint32_t current_page : 3 ; ///< Index into the qTD buffer pointer list
|
||||
uint32_t int_on_complete : 1 ; ///< Interrupt on complete
|
||||
volatile uint32_t total_bytes : 15 ; ///< Transfer bytes, decreased during transaction
|
||||
volatile uint32_t data_toggle : 1 ; ///< Data Toogle bit
|
||||
|
||||
|
||||
/// Buffer Page Pointer List, Each element in the list is a 4K page aligned, physical memory address. The lower 12 bits in each pointer are reserved (except for the first one) as each memory pointer must reference the start of a 4K page
|
||||
uint32_t buffer[5];
|
||||
} ehci_qtd_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(ehci_qtd_t) == 32, "size is not correct" );
|
||||
|
||||
/// Queue Head
|
||||
typedef struct TU_ATTR_ALIGNED(32)
|
||||
{
|
||||
// Word 0: Next QHD
|
||||
ehci_link_t next;
|
||||
|
||||
// Word 1: Endpoint Characteristics
|
||||
uint32_t dev_addr : 7 ; ///< device address
|
||||
uint32_t fl_inactive_next_xact : 1 ; ///< Only valid for Periodic with Full/Slow speed
|
||||
uint32_t ep_number : 4 ; ///< EP number
|
||||
uint32_t ep_speed : 2 ; ///< 0: Full, 1: Low, 2: High
|
||||
uint32_t data_toggle_control : 1 ; ///< 0: use DT in qHD, 1: use DT in qTD
|
||||
uint32_t head_list_flag : 1 ; ///< Head of the queue
|
||||
uint32_t max_packet_size : 11 ; ///< Max packet size
|
||||
uint32_t fl_ctrl_ep_flag : 1 ; ///< 1 if is Full/Low speed control endpoint
|
||||
uint32_t nak_reload : 4 ; ///< Used by HC
|
||||
|
||||
// Word 2: Endpoint Capabilities
|
||||
uint32_t int_smask : 8 ; ///< Interrupt Schedule Mask
|
||||
uint32_t fl_int_cmask : 8 ; ///< Split Completion Mask for Full/Slow speed
|
||||
uint32_t fl_hub_addr : 7 ; ///< Hub Address for Full/Slow speed
|
||||
uint32_t fl_hub_port : 7 ; ///< Hub Port for Full/Slow speed
|
||||
uint32_t mult : 2 ; ///< Transaction per micro frame
|
||||
|
||||
// Word 3: Current qTD Pointer
|
||||
volatile uint32_t qtd_addr;
|
||||
|
||||
// Word 4-11: Transfer Overlay
|
||||
volatile ehci_qtd_t qtd_overlay;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
/// Due to the fact QHD is 32 bytes aligned but occupies only 48 bytes
|
||||
/// thus there are 16 bytes padding free that we can make use of.
|
||||
//--------------------------------------------------------------------+
|
||||
uint8_t used;
|
||||
uint8_t removing; // removed from asyn list, waiting for async advance
|
||||
uint8_t pid;
|
||||
uint8_t interval_ms; // polling interval in frames (or milisecond)
|
||||
|
||||
uint16_t total_xferred_bytes; // number of bytes xferred until a qtd with ioc bit set
|
||||
uint8_t reserved2[2];
|
||||
|
||||
ehci_qtd_t * volatile p_qtd_list_head; // head of the scheduled TD list
|
||||
ehci_qtd_t * volatile p_qtd_list_tail; // tail of the scheduled TD list
|
||||
} ehci_qhd_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(ehci_qhd_t) == 64, "size is not correct" );
|
||||
|
||||
/// Highspeed Isochronous Transfer Descriptor (section 3.3)
|
||||
typedef struct TU_ATTR_ALIGNED(32) {
|
||||
// Word 0: Next Link Pointer
|
||||
ehci_link_t next;
|
||||
|
||||
// Word 1-8: iTD Transaction Status and Control List
|
||||
struct {
|
||||
// iTD Control
|
||||
volatile uint32_t offset : 12 ; ///< This field is a value that is an offset, expressed in bytes, from the beginning of a buffer.
|
||||
volatile uint32_t page_select : 3 ; ///< These bits are set by software to indicate which of the buffer page pointers the offset field in this slot should be concatenated to produce the starting memory address for this transaction. The valid range of values for this field is 0 to 6
|
||||
uint32_t int_on_complete : 1 ; ///< If this bit is set to a one, it specifies that when this transaction completes, the Host Controller should issue an interrupt at the next interrupt threshold
|
||||
volatile uint32_t length : 12 ; ///< For an OUT, this field is the number of data bytes the host controller will send during the transaction. The host controller is not required to update this field to reflect the actual number of bytes transferred during the transfer
|
||||
///< For an IN, the initial value of the field is the number of bytes the host expects the endpoint to deliver. During the status update, the host controller writes back the number of bytes successfully received. The value in this register is the actual byte count
|
||||
// iTD Status
|
||||
volatile uint32_t error : 1 ; ///< Set to a one by the Host Controller during status update in the case where the host did not receive a valid response from the device (Timeout, CRC, Bad PID, etc.). This bit may only be set for isochronous IN transactions.
|
||||
volatile uint32_t babble_err : 1 ; ///< Set to a 1 by the Host Controller during status update when a babble is detected during the transaction
|
||||
volatile uint32_t buffer_err : 1 ; ///< Set to a 1 by the Host Controller during status update to indicate that the Host Controller is unable to keep up with the reception of incoming data (overrun) or is unable to supply data fast enough during transmission (underrun).
|
||||
volatile uint32_t active : 1 ; ///< Set to 1 by software to enable the execution of an isochronous transaction by the Host Controller
|
||||
} xact[8];
|
||||
|
||||
// Word 9-15 Buffer Page Pointer List (Plus)
|
||||
uint32_t BufferPointer[7];
|
||||
|
||||
// // FIXME: Store meta data into buffer pointer reserved for saving memory
|
||||
// /*---------- HCD Area ----------*/
|
||||
// uint32_t used;
|
||||
// uint32_t IhdIdx;
|
||||
// uint32_t reserved[6];
|
||||
} ehci_itd_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(ehci_itd_t) == 64, "size is not correct" );
|
||||
|
||||
/// Split (Full-Speed) Isochronous Transfer Descriptor
|
||||
typedef struct TU_ATTR_ALIGNED(32)
|
||||
{
|
||||
// Word 0: Next Link Pointer
|
||||
ehci_link_t next;
|
||||
|
||||
// Word 1: siTD Endpoint Characteristics
|
||||
uint32_t dev_addr : 7; ///< This field selects the specific device serving as the data source or sink.
|
||||
uint32_t : 1; ///< reserved
|
||||
uint32_t ep_number : 4; ///< This 4-bit field selects the particular endpoint number on the device serving as the data source or sink.
|
||||
uint32_t : 4; ///< This field is reserved and should be set to zero.
|
||||
uint32_t hub_addr : 7; ///< This field holds the device address of the transaction translators’ hub.
|
||||
uint32_t : 1; ///< reserved
|
||||
uint32_t port_number : 7; ///< This field is the port number of the recipient transaction translator.
|
||||
uint32_t direction : 1; ///< 0 = OUT; 1 = IN. This field encodes whether the full-speed transaction should be an IN or OUT.
|
||||
|
||||
// Word 2: Micro-frame Schedule Control
|
||||
uint8_t int_smask ; ///< This field (along with the Activeand SplitX-statefields in the Statusbyte) are used to determine during which micro-frames the host controller should execute complete-split transactions
|
||||
uint8_t fl_int_cmask; ///< This field (along with the Activeand SplitX-statefields in the Statusbyte) are used to determine during which micro-frames the host controller should execute start-split transactions.
|
||||
uint16_t reserved ; ///< reserved
|
||||
|
||||
// Word 3: siTD Transfer Status and Control
|
||||
// Status [7:0] TODO indentical to qTD Token'status --> refractor later
|
||||
volatile uint32_t : 1 ; // reserved
|
||||
volatile uint32_t split_state : 1 ;
|
||||
volatile uint32_t missed_uframe : 1 ;
|
||||
volatile uint32_t xact_err : 1 ;
|
||||
volatile uint32_t babble_err : 1 ;
|
||||
volatile uint32_t buffer_err : 1 ;
|
||||
volatile uint32_t error : 1 ;
|
||||
volatile uint32_t active : 1 ;
|
||||
// Micro-frame Schedule Control
|
||||
volatile uint32_t cmask_progress : 8 ; ///< This field is used by the host controller to record which split-completes have been executed. See Section 4.12.3.3.2 for behavioral requirements.
|
||||
volatile uint32_t total_bytes : 10 ; ///< This field is initialized by software to the total number of bytes expected in this transfer. Maximum value is 1023
|
||||
volatile uint32_t : 4 ; ///< reserved
|
||||
volatile uint32_t page_select : 1 ; ///< Used to indicate which data page pointer should be concatenated with the CurrentOffsetfield to construct a data buffer pointer
|
||||
uint32_t int_on_complete : 1 ; ///< Do not interrupt when transaction is complete. 1 = Do interrupt when transaction is complete
|
||||
uint32_t : 0 ; // padding to the end of current storage unit
|
||||
|
||||
/// Word 4-5: Buffer Pointer List
|
||||
uint32_t buffer[2]; // buffer[1] TP: Transaction Position - T-Count: Transaction Count
|
||||
|
||||
// union{
|
||||
// uint32_t BufferPointer1;
|
||||
// struct {
|
||||
// volatile uint32_t TCount : 3;
|
||||
// volatile uint32_t TPosition : 2;
|
||||
// };
|
||||
// };
|
||||
|
||||
/*---------- Word 6 ----------*/
|
||||
ehci_link_t back;
|
||||
|
||||
/// SITD is 32-byte aligned but occupies only 28 --> 4 bytes for storing extra data
|
||||
uint8_t used;
|
||||
uint8_t ihd_idx;
|
||||
uint8_t reserved2[2];
|
||||
} ehci_sitd_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(ehci_sitd_t) == 32, "size is not correct" );
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// EHCI Operational Register
|
||||
//--------------------------------------------------------------------+
|
||||
enum ehci_interrupt_mask_{
|
||||
EHCI_INT_MASK_USB = TU_BIT(0),
|
||||
EHCI_INT_MASK_ERROR = TU_BIT(1),
|
||||
EHCI_INT_MASK_PORT_CHANGE = TU_BIT(2),
|
||||
|
||||
EHCI_INT_MASK_FRAMELIST_ROLLOVER = TU_BIT(3),
|
||||
EHCI_INT_MASK_PCI_HOST_SYSTEM_ERROR = TU_BIT(4),
|
||||
EHCI_INT_MASK_ASYNC_ADVANCE = TU_BIT(5),
|
||||
EHCI_INT_MASK_NXP_SOF = TU_BIT(7),
|
||||
|
||||
EHCI_INT_MASK_NXP_ASYNC = TU_BIT(18),
|
||||
EHCI_INT_MASK_NXP_PERIODIC = TU_BIT(19),
|
||||
|
||||
EHCI_INT_MASK_ALL =
|
||||
EHCI_INT_MASK_USB | EHCI_INT_MASK_ERROR | EHCI_INT_MASK_PORT_CHANGE |
|
||||
EHCI_INT_MASK_FRAMELIST_ROLLOVER | EHCI_INT_MASK_PCI_HOST_SYSTEM_ERROR |
|
||||
EHCI_INT_MASK_ASYNC_ADVANCE | EHCI_INT_MASK_NXP_SOF |
|
||||
EHCI_INT_MASK_NXP_ASYNC | EHCI_INT_MASK_NXP_PERIODIC
|
||||
};
|
||||
|
||||
enum ehci_usbcmd_pos_ {
|
||||
EHCI_USBCMD_POS_RUN_STOP = 0,
|
||||
EHCI_USBCMD_POS_FRAMELIST_SZIE = 2,
|
||||
EHCI_USBCMD_POS_PERIOD_ENABLE = 4,
|
||||
EHCI_USBCMD_POS_ASYNC_ENABLE = 5,
|
||||
EHCI_USBCMD_POS_NXP_FRAMELIST_SIZE_MSB = 15,
|
||||
EHCI_USBCMD_POS_INTERRUPT_THRESHOLD = 16
|
||||
};
|
||||
|
||||
enum ehci_portsc_change_mask_{
|
||||
EHCI_PORTSC_MASK_CURRENT_CONNECT_STATUS = TU_BIT(0),
|
||||
EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = TU_BIT(1),
|
||||
EHCI_PORTSC_MASK_PORT_EANBLED = TU_BIT(2),
|
||||
EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = TU_BIT(3),
|
||||
EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = TU_BIT(5),
|
||||
|
||||
EHCI_PORTSC_MASK_PORT_RESET = TU_BIT(8),
|
||||
|
||||
EHCI_PORTSC_MASK_ALL =
|
||||
EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE |
|
||||
EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE |
|
||||
EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE
|
||||
};
|
||||
|
||||
typedef volatile struct
|
||||
{
|
||||
union {
|
||||
uint32_t command;
|
||||
|
||||
struct {
|
||||
uint32_t run_stop : 1 ; ///< 1=Run. 0=Stop
|
||||
uint32_t reset : 1 ; ///< SW write 1 to reset HC, clear by HC when complete
|
||||
uint32_t framelist_size : 2 ; ///< Frame List size 0: 1024, 1: 512, 2: 256
|
||||
uint32_t periodic_enable : 1 ; ///< This bit controls whether the host controller skips processing the Periodic Schedule. Values mean: 0b Do not process the Periodic Schedule 1b Use the PERIODICLISTBASE register to access the Periodic Schedule.
|
||||
uint32_t async_enable : 1 ; ///< This bit controls whether the host controller skips processing the Asynchronous Schedule. Values mean: 0b Do not process the Asynchronous Schedule 1b Use the ASYNCLISTADDR register to access the Asynchronous Schedule.
|
||||
uint32_t async_adv_doorbell : 1 ; ///< Tell HC to interrupt next time it advances async list. Clear by HC
|
||||
uint32_t light_reset : 1 ; ///< Reset HC without affecting ports state
|
||||
uint32_t async_park_count : 2 ; ///< not used by tinyusb
|
||||
uint32_t : 1 ;
|
||||
uint32_t async_park_enable : 1 ; ///< Enable park mode, not used by tinyusb
|
||||
uint32_t : 3 ;
|
||||
uint32_t nxp_framelist_size_msb : 1 ; ///< NXP customized : Bit 2 of the Frame List Size bits \n 011b: 128 elements \n 100b: 64 elements \n 101b: 32 elements \n 110b: 16 elements \n 111b: 8 elements
|
||||
uint32_t int_threshold : 8 ; ///< Default 08h. Interrupt rate in unit of micro frame
|
||||
}command_bm;
|
||||
};
|
||||
|
||||
union {
|
||||
uint32_t status;
|
||||
|
||||
struct {
|
||||
uint32_t usb : 1 ; ///< qTD with IOC is retired
|
||||
uint32_t usb_error : 1 ; ///< qTD retired due to error
|
||||
uint32_t port_change_detect : 1 ; ///< Set when PortOwner or ForcePortResume change from 0 -> 1
|
||||
uint32_t framelist_rollover : 1 ; ///< R/WC The Host Controller sets this bit to a one when the Frame List Index(see Section 2.3.4) rolls over from its maximum value to zero. The exact value at which the rollover occurs depends on the frame list size. For example, if the frame list size (as programmed in the Frame List Sizefield of the USBCMD register) is 1024, the Frame Index Registerrolls over every time FRINDEX[13] toggles. Similarly, if the size is 512, the Host Controller sets this bit to a one every time FRINDEX[12] toggles.
|
||||
uint32_t pci_host_system_error : 1 ; ///< R/WC (not used by NXP) The Host Controller sets this bit to 1 when a serious error occurs during a host system access involving the Host Controller module. In a PCI system, conditions that set this bit to 1 include PCI Parity error, PCI Master Abort, and PCI Target Abort. When this error occurs, the Host Controller clears the Run/Stop bit in the Command register to prevent further execution of the scheduled TDs.
|
||||
uint32_t async_adv : 1 ; ///< Async Advance interrupt
|
||||
uint32_t : 1 ;
|
||||
uint32_t nxp_int_sof : 1 ; ///< NXP customized: this bit will be set every 125us and can be used by host controller driver as a time base.
|
||||
uint32_t : 4 ;
|
||||
uint32_t hc_halted : 1 ; ///< Opposite value to run_stop bit.
|
||||
uint32_t reclamation : 1 ; ///< Used to detect empty async shecudle
|
||||
uint32_t periodic_status : 1 ; ///< Periodic schedule status
|
||||
uint32_t async_status : 1 ; ///< Async schedule status
|
||||
uint32_t : 2 ;
|
||||
uint32_t nxp_int_async : 1 ; ///< NXP customized: This bit is set by the Host Controller when the cause of an interrupt is a completion of a USB transaction where the Transfer Descriptor (TD) has an interrupt on complete (IOC) bit set andthe TD was from the asynchronous schedule. This bit is also set by the Host when a short packet is detected andthe packet is on the asynchronous schedule.
|
||||
uint32_t nxp_int_period : 1 ; ///< NXP customized: This bit is set by the Host Controller when the cause of an interrupt is a completion of a USB transaction where the Transfer Descriptor (TD) has an interrupt on complete (IOC) bit set andthe TD was from the periodic schedule.
|
||||
uint32_t : 12 ;
|
||||
}status_bm;
|
||||
};
|
||||
|
||||
union{
|
||||
uint32_t inten;
|
||||
|
||||
struct {
|
||||
uint32_t usb : 1 ;
|
||||
uint32_t usb_error : 1 ;
|
||||
uint32_t port_change_detect : 1 ;
|
||||
uint32_t framelist_rollover : 1 ;
|
||||
uint32_t pci_host_system_error : 1 ;
|
||||
uint32_t async_adv : 1 ;
|
||||
uint32_t : 1 ;
|
||||
uint32_t nxp_int_sof : 1 ;
|
||||
uint32_t : 10 ;
|
||||
uint32_t nxp_int_async : 1 ;
|
||||
uint32_t nxp_int_period : 1 ;
|
||||
uint32_t : 12 ;
|
||||
}inten_bm;
|
||||
};
|
||||
|
||||
uint32_t frame_index ; ///< Micro frame counter
|
||||
uint32_t ctrl_ds_seg ; ///< Control Data Structure Segment
|
||||
uint32_t periodic_list_base ; ///< Beginning address of perodic frame list
|
||||
uint32_t async_list_addr ; ///< Address of next async QHD to be executed
|
||||
uint32_t nxp_tt_control ; ///< nxp embedded transaction translator (reserved by EHCI specs)
|
||||
uint32_t reserved[8] ;
|
||||
uint32_t config_flag ; ///< not used by NXP
|
||||
|
||||
union {
|
||||
uint32_t portsc ; ///< port status and control
|
||||
struct {
|
||||
uint32_t current_connect_status : 1; ///< 0: No device, 1: Device is present on port
|
||||
uint32_t connect_status_change : 1; ///< Change in Current Connect Status
|
||||
uint32_t port_enabled : 1; ///< Ports can only be enabled by HC as a part of the reset and enable. SW can write 0 to disable
|
||||
uint32_t port_enable_change : 1; ///< Port Enabled has changed
|
||||
uint32_t over_current_active : 1; ///< Port has an over-current condition
|
||||
uint32_t over_current_change : 1; ///< Change to Over-current Active
|
||||
uint32_t force_port_resume : 1; ///< Resume detected/driven on port. This functionality defined for manipulating this bit depends on the value of the Suspend bit.
|
||||
uint32_t suspend : 1; ///< Port in suspend state
|
||||
uint32_t port_reset : 1; ///< 1=Port is in Reset. 0=Port is not in Reset
|
||||
uint32_t nxp_highspeed_status : 1; ///< NXP customized: 0=connected to the port is not in High-speed mode, 1=connected to the port is in High-speed mode
|
||||
uint32_t line_status : 2; ///< D+/D- state: 00: SE0, 10: J-state, 01: K-state
|
||||
uint32_t port_power : 1; ///< 0= power off, 1= power on
|
||||
uint32_t port_owner : 1; ///< not used by NXP
|
||||
uint32_t port_indicator_control : 2; ///< 00b: off, 01b: Amber, 10b: green, 11b: undefined
|
||||
uint32_t port_test_control : 4; ///< Port test mode, not used by tinyusb
|
||||
uint32_t wake_on_connect_enable : 1; ///< Enables device connects as wake-up events
|
||||
uint32_t wake_on_disconnect_enable : 1; ///< Enables device disconnects as wake-up events
|
||||
uint32_t wake_on_over_current_enable : 1; ///< Enables over-current conditions as wake-up events
|
||||
uint32_t nxp_phy_clock_disable : 1; ///< NXP customized: the PHY can be put into Low Power Suspend – Clock Disable when the downstream device has been put into suspend mode or when no downstream device is connected. Low power suspend is completely under the control of software. 0: enable PHY clock, 1: disable PHY clock
|
||||
uint32_t nxp_port_force_fullspeed : 1; ///< NXP customized: Writing this bit to a 1 will force the port to only connect at Full Speed. It disables the chirp sequence that allowsthe port to identify itself as High Speed. This is useful for testing FS configurations with a HS host, hub or device.
|
||||
uint32_t : 1;
|
||||
uint32_t nxp_port_speed : 2; ///< NXP customized: This register field indicates the speed atwhich the port is operating. For HS mode operation in the host controllerand HS/FS operation in the device controller the port routing steers data to the Protocol engine. For FS and LS mode operation in the host controller, the port routing steers data to the Protocol Engine w/ Embedded Transaction Translator. 0x0: Fullspeed, 0x1: Lowspeed, 0x2: Highspeed
|
||||
uint32_t TU_RESERVED : 4;
|
||||
}portsc_bm;
|
||||
};
|
||||
}ehci_registers_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// EHCI Data Organization
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct
|
||||
{
|
||||
ehci_link_t period_framelist[EHCI_FRAMELIST_SIZE];
|
||||
|
||||
// for NXP ECHI, only implement 1 ms & 2 ms & 4 ms, 8 ms (framelist)
|
||||
// [0] : 1ms, [1] : 2ms, [2] : 4ms, [3] : 8 ms
|
||||
ehci_qhd_t period_head_arr[4];
|
||||
|
||||
// Note control qhd of dev0 is used as head of async list
|
||||
struct {
|
||||
ehci_qhd_t qhd;
|
||||
ehci_qtd_t qtd;
|
||||
}control[CFG_TUSB_HOST_DEVICE_MAX+1];
|
||||
|
||||
ehci_qhd_t qhd_pool[HCD_MAX_ENDPOINT];
|
||||
ehci_qtd_t qtd_pool[HCD_MAX_XFER] TU_ATTR_ALIGNED(32);
|
||||
|
||||
ehci_registers_t* regs;
|
||||
|
||||
volatile uint32_t uframe_number;
|
||||
}ehci_data_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_EHCI_H_ */
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
688
src/portable/ohci/ohci.c
Normal file
688
src/portable/ohci/ohci.c
Normal file
@@ -0,0 +1,688 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#include <common/tusb_common.h>
|
||||
|
||||
#if TUSB_OPT_HOST_ENABLED && \
|
||||
(CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC40XX)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "osal/osal.h"
|
||||
|
||||
#include "host/hcd.h"
|
||||
#include "host/usbh_hcd.h"
|
||||
#include "ohci.h"
|
||||
|
||||
// TODO remove
|
||||
#include "chip.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
#define OHCI_REG ((ohci_registers_t *) LPC_USB_BASE)
|
||||
|
||||
enum {
|
||||
OHCI_CONTROL_FUNCSTATE_RESET = 0,
|
||||
OHCI_CONTROL_FUNCSTATE_RESUME,
|
||||
OHCI_CONTROL_FUNCSTATE_OPERATIONAL,
|
||||
OHCI_CONTROL_FUNCSTATE_SUSPEND
|
||||
};
|
||||
|
||||
enum {
|
||||
OHCI_CONTROL_CONTROL_BULK_RATIO = 3, ///< This specifies the service ratio between Control and Bulk EDs. 0 = 1:1, 3 = 4:1
|
||||
OHCI_CONTROL_LIST_PERIODIC_ENABLE_MASK = TU_BIT(2),
|
||||
OHCI_CONTROL_LIST_ISOCHRONOUS_ENABLE_MASK = TU_BIT(3),
|
||||
OHCI_CONTROL_LIST_CONTROL_ENABLE_MASK = TU_BIT(4),
|
||||
OHCI_CONTROL_LIST_BULK_ENABLE_MASK = TU_BIT(5),
|
||||
};
|
||||
|
||||
enum {
|
||||
OHCI_FMINTERVAL_FI = 0x2EDF, // 7.3.1 nominal (reset) value
|
||||
OHCI_FMINTERVAL_FSMPS = (6*(OHCI_FMINTERVAL_FI-210)) / 7, // 5.4 calculated based on maximum overhead + bit stuffing
|
||||
};
|
||||
|
||||
enum {
|
||||
OHCI_PERIODIC_START = 0x3E67
|
||||
};
|
||||
|
||||
enum {
|
||||
OHCI_INT_SCHEDULING_OVERUN_MASK = TU_BIT(0),
|
||||
OHCI_INT_WRITEBACK_DONEHEAD_MASK = TU_BIT(1),
|
||||
OHCI_INT_SOF_MASK = TU_BIT(2),
|
||||
OHCI_INT_RESUME_DETECTED_MASK = TU_BIT(3),
|
||||
OHCI_INT_UNRECOVERABLE_ERROR_MASK = TU_BIT(4),
|
||||
OHCI_INT_FRAME_OVERFLOW_MASK = TU_BIT(5),
|
||||
OHCI_INT_RHPORT_STATUS_CHANGE_MASK = TU_BIT(6),
|
||||
|
||||
OHCI_INT_OWNERSHIP_CHANGE_MASK = TU_BIT(30),
|
||||
OHCI_INT_MASTER_ENABLE_MASK = TU_BIT(31),
|
||||
};
|
||||
|
||||
enum {
|
||||
OHCI_RHPORT_CURRENT_CONNECT_STATUS_MASK = TU_BIT(0),
|
||||
OHCI_RHPORT_PORT_ENABLE_STATUS_MASK = TU_BIT(1),
|
||||
OHCI_RHPORT_PORT_SUSPEND_STATUS_MASK = TU_BIT(2),
|
||||
OHCI_RHPORT_PORT_OVER_CURRENT_INDICATOR_MASK = TU_BIT(3),
|
||||
OHCI_RHPORT_PORT_RESET_STATUS_MASK = TU_BIT(4), ///< write '1' to reset port
|
||||
|
||||
OHCI_RHPORT_PORT_POWER_STATUS_MASK = TU_BIT(8),
|
||||
OHCI_RHPORT_LOW_SPEED_DEVICE_ATTACHED_MASK = TU_BIT(9),
|
||||
|
||||
OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK = TU_BIT(16),
|
||||
OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK = TU_BIT(17),
|
||||
OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK = TU_BIT(18),
|
||||
OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK = TU_BIT(19),
|
||||
OHCI_RHPORT_PORT_RESET_CHANGE_MASK = TU_BIT(20),
|
||||
|
||||
OHCI_RHPORT_ALL_CHANGE_MASK = OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK | OHCI_RHPORT_PORT_ENABLE_CHANGE_MASK |
|
||||
OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK | OHCI_RHPORT_OVER_CURRENT_CHANGE_MASK | OHCI_RHPORT_PORT_RESET_CHANGE_MASK
|
||||
};
|
||||
|
||||
enum {
|
||||
OHCI_CCODE_NO_ERROR = 0,
|
||||
OHCI_CCODE_CRC = 1,
|
||||
OHCI_CCODE_BIT_STUFFING = 2,
|
||||
OHCI_CCODE_DATA_TOGGLE_MISMATCH = 3,
|
||||
OHCI_CCODE_STALL = 4,
|
||||
OHCI_CCODE_DEVICE_NOT_RESPONDING = 5,
|
||||
OHCI_CCODE_PID_CHECK_FAILURE = 6,
|
||||
OHCI_CCODE_UNEXPECTED_PID = 7,
|
||||
OHCI_CCODE_DATA_OVERRUN = 8,
|
||||
OHCI_CCODE_DATA_UNDERRUN = 9,
|
||||
OHCI_CCODE_BUFFER_OVERRUN = 12,
|
||||
OHCI_CCODE_BUFFER_UNDERRUN = 13,
|
||||
OHCI_CCODE_NOT_ACCESSED = 14,
|
||||
};
|
||||
|
||||
enum {
|
||||
OHCI_INT_ON_COMPLETE_YES = 0,
|
||||
OHCI_INT_ON_COMPLETE_NO = TU_BIN8(111)
|
||||
};
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static ohci_data_t ohci_data;
|
||||
|
||||
static ohci_ed_t * const p_ed_head[] =
|
||||
{
|
||||
[TUSB_XFER_CONTROL] = &ohci_data.control[0].ed,
|
||||
[TUSB_XFER_BULK ] = &ohci_data.bulk_head_ed,
|
||||
[TUSB_XFER_INTERRUPT] = &ohci_data.period_head_ed,
|
||||
[TUSB_XFER_ISOCHRONOUS] = NULL // TODO Isochronous
|
||||
};
|
||||
|
||||
static void ed_list_insert(ohci_ed_t * p_pre, ohci_ed_t * p_ed);
|
||||
static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBH-HCD API
|
||||
//--------------------------------------------------------------------+
|
||||
// Initialization according to 5.1.1.4
|
||||
bool hcd_init(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
//------------- Data Structure init -------------//
|
||||
tu_memclr(&ohci_data, sizeof(ohci_data_t));
|
||||
for(uint8_t i=0; i<32; i++)
|
||||
{ // assign all interrupt pointes to period head ed
|
||||
ohci_data.hcca.interrupt_table[i] = (uint32_t) &ohci_data.period_head_ed;
|
||||
}
|
||||
|
||||
ohci_data.control[0].ed.skip = 1;
|
||||
ohci_data.bulk_head_ed.skip = 1;
|
||||
ohci_data.period_head_ed.skip = 1;
|
||||
|
||||
// reset controller
|
||||
OHCI_REG->command_status_bit.controller_reset = 1;
|
||||
while( OHCI_REG->command_status_bit.controller_reset ) {} // should not take longer than 10 us
|
||||
|
||||
//------------- init ohci registers -------------//
|
||||
OHCI_REG->control_head_ed = (uint32_t) &ohci_data.control[0].ed;
|
||||
OHCI_REG->bulk_head_ed = (uint32_t) &ohci_data.bulk_head_ed;
|
||||
OHCI_REG->hcca = (uint32_t) &ohci_data.hcca;
|
||||
|
||||
OHCI_REG->interrupt_disable = OHCI_REG->interrupt_enable; // disable all interrupts
|
||||
OHCI_REG->interrupt_status = OHCI_REG->interrupt_status; // clear current set bits
|
||||
OHCI_REG->interrupt_enable = OHCI_INT_WRITEBACK_DONEHEAD_MASK | OHCI_INT_RESUME_DETECTED_MASK |
|
||||
OHCI_INT_UNRECOVERABLE_ERROR_MASK | OHCI_INT_FRAME_OVERFLOW_MASK | OHCI_INT_RHPORT_STATUS_CHANGE_MASK |
|
||||
OHCI_INT_MASTER_ENABLE_MASK;
|
||||
|
||||
OHCI_REG->control |= OHCI_CONTROL_CONTROL_BULK_RATIO | OHCI_CONTROL_LIST_CONTROL_ENABLE_MASK |
|
||||
OHCI_CONTROL_LIST_BULK_ENABLE_MASK | OHCI_CONTROL_LIST_PERIODIC_ENABLE_MASK; // TODO Isochronous
|
||||
|
||||
OHCI_REG->frame_interval = (OHCI_FMINTERVAL_FSMPS << 16) | OHCI_FMINTERVAL_FI;
|
||||
OHCI_REG->periodic_start = (OHCI_FMINTERVAL_FI * 9) / 10; // Periodic start is 90% of frame interval
|
||||
|
||||
OHCI_REG->control_bit.hc_functional_state = OHCI_CONTROL_FUNCSTATE_OPERATIONAL; // make HC's state to operational state TODO use this to suspend (save power)
|
||||
OHCI_REG->rh_status_bit.local_power_status_change = 1; // set global power for ports
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t hcd_uframe_number(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
return (ohci_data.frame_number_hi << 16 | OHCI_REG->frame_number) << 3;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PORT API
|
||||
//--------------------------------------------------------------------+
|
||||
void hcd_port_reset(uint8_t hostid)
|
||||
{
|
||||
(void) hostid;
|
||||
OHCI_REG->rhport_status[0] = OHCI_RHPORT_PORT_RESET_STATUS_MASK;
|
||||
}
|
||||
|
||||
bool hcd_port_connect_status(uint8_t hostid)
|
||||
{
|
||||
(void) hostid;
|
||||
return OHCI_REG->rhport_status_bit[0].current_connect_status;
|
||||
}
|
||||
|
||||
tusb_speed_t hcd_port_speed_get(uint8_t hostid)
|
||||
{
|
||||
(void) hostid;
|
||||
return OHCI_REG->rhport_status_bit[0].low_speed_device_attached ? TUSB_SPEED_LOW : TUSB_SPEED_FULL;
|
||||
}
|
||||
|
||||
// endpoints are tied to an address, which only reclaim after a long delay when enumerating
|
||||
// thus there is no need to make sure ED is not in HC's cahed as it will not for sure
|
||||
void hcd_device_close(uint8_t rhport, uint8_t dev_addr)
|
||||
{
|
||||
// TODO OHCI
|
||||
(void) rhport;
|
||||
|
||||
// addr0 serves as static head --> only set skip bit
|
||||
if ( dev_addr == 0 )
|
||||
{
|
||||
ohci_data.control[0].ed.skip = 1;
|
||||
}else
|
||||
{
|
||||
// remove control
|
||||
ed_list_remove_by_addr( p_ed_head[TUSB_XFER_CONTROL], dev_addr);
|
||||
|
||||
// remove bulk
|
||||
ed_list_remove_by_addr(p_ed_head[TUSB_XFER_BULK], dev_addr);
|
||||
|
||||
// remove interrupt
|
||||
ed_list_remove_by_addr(p_ed_head[TUSB_XFER_INTERRUPT], dev_addr);
|
||||
|
||||
// TODO remove ISO
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Controller API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CONTROL PIPE API
|
||||
//--------------------------------------------------------------------+
|
||||
static inline tusb_xfer_type_t ed_get_xfer_type(ohci_ed_t const * const p_ed)
|
||||
{
|
||||
return (p_ed->ep_number == 0 ) ? TUSB_XFER_CONTROL :
|
||||
(p_ed->is_iso ) ? TUSB_XFER_ISOCHRONOUS :
|
||||
(p_ed->is_interrupt_xfer ) ? TUSB_XFER_INTERRUPT : TUSB_XFER_BULK;
|
||||
}
|
||||
|
||||
static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t max_packet_size, uint8_t endpoint_addr, uint8_t xfer_type, uint8_t interval)
|
||||
{
|
||||
(void) interval;
|
||||
|
||||
// address 0 is used as async head, which always on the list --> cannot be cleared
|
||||
if (dev_addr != 0)
|
||||
{
|
||||
tu_memclr(p_ed, sizeof(ohci_ed_t));
|
||||
}
|
||||
|
||||
p_ed->dev_addr = dev_addr;
|
||||
p_ed->ep_number = endpoint_addr & 0x0F;
|
||||
p_ed->pid = (xfer_type == TUSB_XFER_CONTROL) ? OHCI_PID_SETUP : ( (endpoint_addr & TUSB_DIR_IN_MASK) ? OHCI_PID_IN : OHCI_PID_OUT );
|
||||
p_ed->speed = _usbh_devices[dev_addr].speed;
|
||||
p_ed->is_iso = (xfer_type == TUSB_XFER_ISOCHRONOUS) ? 1 : 0;
|
||||
p_ed->max_packet_size = max_packet_size;
|
||||
|
||||
p_ed->used = 1;
|
||||
p_ed->is_interrupt_xfer = (xfer_type == TUSB_XFER_INTERRUPT ? 1 : 0);
|
||||
}
|
||||
|
||||
static void gtd_init(ohci_gtd_t* p_td, void* data_ptr, uint16_t total_bytes)
|
||||
{
|
||||
tu_memclr(p_td, sizeof(ohci_gtd_t));
|
||||
|
||||
p_td->used = 1;
|
||||
p_td->expected_bytes = total_bytes;
|
||||
|
||||
p_td->buffer_rounding = 1; // less than queued length is not a error
|
||||
p_td->delay_interrupt = OHCI_INT_ON_COMPLETE_NO;
|
||||
p_td->condition_code = OHCI_CCODE_NOT_ACCESSED;
|
||||
|
||||
p_td->current_buffer_pointer = data_ptr;
|
||||
p_td->buffer_end = total_bytes ? (((uint8_t*) data_ptr) + total_bytes-1) : NULL;
|
||||
}
|
||||
|
||||
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8])
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
ohci_ed_t* p_ed = &ohci_data.control[dev_addr].ed;
|
||||
ohci_gtd_t *p_setup = &ohci_data.control[dev_addr].gtd;
|
||||
|
||||
gtd_init(p_setup, (void*) setup_packet, 8);
|
||||
p_setup->index = dev_addr;
|
||||
p_setup->pid = OHCI_PID_SETUP;
|
||||
p_setup->data_toggle = TU_BIN8(10); // DATA0
|
||||
p_setup->delay_interrupt = OHCI_INT_ON_COMPLETE_YES;
|
||||
|
||||
//------------- Attach TDs list to Control Endpoint -------------//
|
||||
p_ed->td_head.address = (uint32_t) p_setup;
|
||||
|
||||
OHCI_REG->command_status_bit.control_list_filled = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO move around
|
||||
static ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr);
|
||||
static ohci_gtd_t * gtd_find_free(void);
|
||||
static void td_insert_to_ed(ohci_ed_t* p_ed, ohci_gtd_t * p_gtd);
|
||||
|
||||
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
// FIXME control only for now
|
||||
if ( epnum == 0 )
|
||||
{
|
||||
ohci_ed_t* const p_ed = &ohci_data.control[dev_addr].ed;
|
||||
ohci_gtd_t *p_data = &ohci_data.control[dev_addr].gtd;
|
||||
|
||||
gtd_init(p_data, buffer, buflen);
|
||||
|
||||
p_data->index = dev_addr;
|
||||
p_data->pid = dir ? OHCI_PID_IN : OHCI_PID_OUT;
|
||||
p_data->data_toggle = TU_BIN8(11); // DATA1
|
||||
p_data->delay_interrupt = OHCI_INT_ON_COMPLETE_YES;
|
||||
|
||||
p_ed->td_head.address = (uint32_t) p_data;
|
||||
|
||||
OHCI_REG->command_status_bit.control_list_filled = 1;
|
||||
}else
|
||||
{
|
||||
ohci_ed_t * p_ed = ed_from_addr(dev_addr, ep_addr);
|
||||
ohci_gtd_t* p_gtd = gtd_find_free();
|
||||
|
||||
TU_ASSERT(p_gtd);
|
||||
|
||||
gtd_init(p_gtd, buffer, buflen);
|
||||
p_gtd->index = p_ed-ohci_data.ed_pool;
|
||||
p_gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES;
|
||||
|
||||
td_insert_to_ed(p_ed, p_gtd);
|
||||
|
||||
tusb_xfer_type_t xfer_type = ed_get_xfer_type( ed_from_addr(dev_addr, ep_addr) );
|
||||
if (TUSB_XFER_BULK == xfer_type) OHCI_REG->command_status_bit.bulk_list_filled = 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// BULK/INT/ISO PIPE API
|
||||
//--------------------------------------------------------------------+
|
||||
static ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
if ( tu_edpt_number(ep_addr) == 0 ) return &ohci_data.control[dev_addr].ed;
|
||||
|
||||
ohci_ed_t* ed_pool = ohci_data.ed_pool;
|
||||
|
||||
for(uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
|
||||
{
|
||||
if ( (ed_pool[i].dev_addr == dev_addr) &&
|
||||
ep_addr == tu_edpt_addr(ed_pool[i].ep_number, ed_pool[i].pid == OHCI_PID_IN) )
|
||||
{
|
||||
return &ed_pool[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ohci_ed_t * ed_find_free(void)
|
||||
{
|
||||
ohci_ed_t* ed_pool = ohci_data.ed_pool;
|
||||
|
||||
for(uint8_t i = 0; i < HCD_MAX_ENDPOINT; i++)
|
||||
{
|
||||
if ( !ed_pool[i].used ) return &ed_pool[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ed_list_insert(ohci_ed_t * p_pre, ohci_ed_t * p_ed)
|
||||
{
|
||||
p_ed->next = p_pre->next;
|
||||
p_pre->next = (uint32_t) p_ed;
|
||||
}
|
||||
|
||||
static void ed_list_remove_by_addr(ohci_ed_t * p_head, uint8_t dev_addr)
|
||||
{
|
||||
ohci_ed_t* p_prev = p_head;
|
||||
|
||||
while( p_prev->next )
|
||||
{
|
||||
ohci_ed_t* ed = (ohci_ed_t*) p_prev->next;
|
||||
|
||||
if (ed->dev_addr == dev_addr)
|
||||
{
|
||||
// unlink ed
|
||||
p_prev->next = ed->next;
|
||||
|
||||
// point the removed ED's next pointer to list head to make sure HC can always safely move away from this ED
|
||||
ed->next = (uint32_t) p_head;
|
||||
ed->used = 0;
|
||||
}
|
||||
|
||||
// check next valid since we could remove it
|
||||
if (p_prev->next) p_prev = (ohci_ed_t*) p_prev->next;
|
||||
}
|
||||
}
|
||||
|
||||
bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
// TODO iso support
|
||||
TU_ASSERT(ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
|
||||
|
||||
//------------- Prepare Queue Head -------------//
|
||||
ohci_ed_t * p_ed;
|
||||
|
||||
if ( ep_desc->bEndpointAddress == 0 )
|
||||
{
|
||||
p_ed = &ohci_data.control[dev_addr].ed;
|
||||
}else
|
||||
{
|
||||
p_ed = ed_find_free();
|
||||
}
|
||||
TU_ASSERT(p_ed);
|
||||
|
||||
ed_init( p_ed, dev_addr, ep_desc->wMaxPacketSize.size, ep_desc->bEndpointAddress,
|
||||
ep_desc->bmAttributes.xfer, ep_desc->bInterval );
|
||||
|
||||
// control of dev0 is used as static async head
|
||||
if ( dev_addr == 0 )
|
||||
{
|
||||
p_ed->skip = 0; // only need to clear skip bit
|
||||
return true;
|
||||
}
|
||||
|
||||
ed_list_insert( p_ed_head[ep_desc->bmAttributes.xfer], p_ed );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static ohci_gtd_t * gtd_find_free(void)
|
||||
{
|
||||
for(uint8_t i=0; i < HCD_MAX_XFER; i++)
|
||||
{
|
||||
if ( !ohci_data.gtd_pool[i].used ) return &ohci_data.gtd_pool[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void td_insert_to_ed(ohci_ed_t* p_ed, ohci_gtd_t * p_gtd)
|
||||
{
|
||||
// tail is always NULL
|
||||
if ( tu_align16(p_ed->td_head.address) == 0 )
|
||||
{ // TD queue is empty --> head = TD
|
||||
p_ed->td_head.address |= (uint32_t) p_gtd;
|
||||
}
|
||||
else
|
||||
{ // TODO currently only support queue up to 2 TD each endpoint at a time
|
||||
((ohci_gtd_t*) tu_align16(p_ed->td_head.address))->next = (uint32_t) p_gtd;
|
||||
}
|
||||
}
|
||||
|
||||
static bool pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete)
|
||||
{
|
||||
ohci_ed_t* const p_ed = ed_from_addr(dev_addr, ep_addr);
|
||||
|
||||
// not support ISO yet
|
||||
TU_VERIFY ( !p_ed->is_iso );
|
||||
|
||||
ohci_gtd_t * const p_gtd = gtd_find_free();
|
||||
TU_ASSERT(p_gtd); // not enough gtd
|
||||
|
||||
gtd_init(p_gtd, buffer, total_bytes);
|
||||
p_gtd->index = p_ed-ohci_data.ed_pool;
|
||||
|
||||
if ( int_on_complete ) p_gtd->delay_interrupt = OHCI_INT_ON_COMPLETE_YES;
|
||||
|
||||
td_insert_to_ed(p_ed, p_gtd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes)
|
||||
{
|
||||
return pipe_queue_xfer(dev_addr, ep_addr, buffer, total_bytes, false);
|
||||
}
|
||||
|
||||
bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete)
|
||||
{
|
||||
(void) int_on_complete;
|
||||
TU_ASSERT( pipe_queue_xfer(dev_addr, ep_addr, buffer, total_bytes, true) );
|
||||
|
||||
tusb_xfer_type_t xfer_type = ed_get_xfer_type( ed_from_addr(dev_addr, ep_addr) );
|
||||
|
||||
if (TUSB_XFER_BULK == xfer_type) OHCI_REG->command_status_bit.bulk_list_filled = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
ohci_ed_t const * const p_ed = ed_from_addr(dev_addr, ep_addr);
|
||||
return tu_align16(p_ed->td_head.address) != tu_align16(p_ed->td_tail);
|
||||
}
|
||||
|
||||
bool hcd_edpt_stalled(uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
ohci_ed_t const * const p_ed = ed_from_addr(dev_addr, ep_addr);
|
||||
return p_ed->td_head.halted && p_ed->is_stalled;
|
||||
}
|
||||
|
||||
bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
ohci_ed_t * const p_ed = ed_from_addr(dev_addr, ep_addr);
|
||||
|
||||
p_ed->is_stalled = 0;
|
||||
p_ed->td_tail &= 0x0Ful; // set tail pointer back to NULL
|
||||
|
||||
p_ed->td_head.toggle = 0; // reset data toggle
|
||||
p_ed->td_head.halted = 0;
|
||||
|
||||
if ( TUSB_XFER_BULK == ed_get_xfer_type(p_ed) ) OHCI_REG->command_status_bit.bulk_list_filled = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// OHCI Interrupt Handler
|
||||
//--------------------------------------------------------------------+
|
||||
static ohci_td_item_t* list_reverse(ohci_td_item_t* td_head)
|
||||
{
|
||||
ohci_td_item_t* td_reverse_head = NULL;
|
||||
|
||||
while(td_head != NULL)
|
||||
{
|
||||
uint32_t next = td_head->next;
|
||||
|
||||
// make current's item become reverse's first item
|
||||
td_head->next = (uint32_t) td_reverse_head;
|
||||
td_reverse_head = td_head;
|
||||
|
||||
td_head = (ohci_td_item_t*) next; // advance to next item
|
||||
}
|
||||
|
||||
return td_reverse_head;
|
||||
}
|
||||
|
||||
static inline bool gtd_is_control(ohci_gtd_t const * const p_qtd)
|
||||
{
|
||||
return ((uint32_t) p_qtd) < ((uint32_t) ohci_data.gtd_pool); // check ohci_data_t for memory layout
|
||||
}
|
||||
|
||||
static inline ohci_ed_t* gtd_get_ed(ohci_gtd_t const * const p_qtd)
|
||||
{
|
||||
if ( gtd_is_control(p_qtd) )
|
||||
{
|
||||
return &ohci_data.control[p_qtd->index].ed;
|
||||
}else
|
||||
{
|
||||
return &ohci_data.ed_pool[p_qtd->index];
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t gtd_xfer_byte_left(uint32_t buffer_end, uint32_t current_buffer)
|
||||
{ // 5.2.9 OHCI sample code
|
||||
return (tu_align4k(buffer_end ^ current_buffer) ? 0x1000 : 0) +
|
||||
tu_offset4k(buffer_end) - tu_offset4k(current_buffer) + 1;
|
||||
}
|
||||
|
||||
static void done_queue_isr(uint8_t hostid)
|
||||
{
|
||||
(void) hostid;
|
||||
|
||||
// done head is written in reversed order of completion --> need to reverse the done queue first
|
||||
ohci_td_item_t* td_head = list_reverse ( (ohci_td_item_t*) tu_align16(ohci_data.hcca.done_head) );
|
||||
|
||||
while( td_head != NULL )
|
||||
{
|
||||
// TODO check if td_head is iso td
|
||||
//------------- Non ISO transfer -------------//
|
||||
ohci_gtd_t * const p_qtd = (ohci_gtd_t *) td_head;
|
||||
xfer_result_t const event = (p_qtd->condition_code == OHCI_CCODE_NO_ERROR) ? XFER_RESULT_SUCCESS :
|
||||
(p_qtd->condition_code == OHCI_CCODE_STALL) ? XFER_RESULT_STALLED : XFER_RESULT_FAILED;
|
||||
|
||||
p_qtd->used = 0; // free TD
|
||||
if ( (p_qtd->delay_interrupt == OHCI_INT_ON_COMPLETE_YES) || (event != XFER_RESULT_SUCCESS) )
|
||||
{
|
||||
ohci_ed_t * const p_ed = gtd_get_ed(p_qtd);
|
||||
|
||||
uint32_t const xferred_bytes = p_qtd->expected_bytes - gtd_xfer_byte_left((uint32_t) p_qtd->buffer_end, (uint32_t) p_qtd->current_buffer_pointer);
|
||||
|
||||
// NOTE Assuming the current list is BULK and there is no other EDs in the list has queued TDs.
|
||||
// When there is a error resulting this ED is halted, and this EP still has other queued TD
|
||||
// --> the Bulk list only has this halted EP queueing TDs (remaining)
|
||||
// --> Bulk list will be considered as not empty by HC !!! while there is no attempt transaction on this list
|
||||
// --> HC will not process Control list (due to service ratio when Bulk list not empty)
|
||||
// To walk-around this, the halted ED will have TailP = HeadP (empty list condition), when clearing halt
|
||||
// the TailP must be set back to NULL for processing remaining TDs
|
||||
if ((event != XFER_RESULT_SUCCESS))
|
||||
{
|
||||
p_ed->td_tail &= 0x0Ful;
|
||||
p_ed->td_tail |= tu_align16(p_ed->td_head.address); // mark halted EP as empty queue
|
||||
if ( event == XFER_RESULT_STALLED ) p_ed->is_stalled = 1;
|
||||
}
|
||||
|
||||
hcd_event_xfer_complete(p_ed->dev_addr,
|
||||
tu_edpt_addr(p_ed->ep_number, p_ed->pid == OHCI_PID_IN),
|
||||
xferred_bytes, event, true);
|
||||
}
|
||||
|
||||
td_head = (ohci_td_item_t*) td_head->next;
|
||||
}
|
||||
}
|
||||
|
||||
void hcd_int_handler(uint8_t hostid)
|
||||
{
|
||||
uint32_t const int_en = OHCI_REG->interrupt_enable;
|
||||
uint32_t const int_status = OHCI_REG->interrupt_status & int_en;
|
||||
|
||||
if (int_status == 0) return;
|
||||
|
||||
// Frame number overflow
|
||||
if ( int_status & OHCI_INT_FRAME_OVERFLOW_MASK )
|
||||
{
|
||||
ohci_data.frame_number_hi++;
|
||||
}
|
||||
|
||||
//------------- RootHub status -------------//
|
||||
if ( int_status & OHCI_INT_RHPORT_STATUS_CHANGE_MASK )
|
||||
{
|
||||
uint32_t const rhport_status = OHCI_REG->rhport_status[0] & OHCI_RHPORT_ALL_CHANGE_MASK;
|
||||
|
||||
// TODO dual port is not yet supported
|
||||
if ( rhport_status & OHCI_RHPORT_CONNECT_STATUS_CHANGE_MASK )
|
||||
{
|
||||
// TODO check if remote wake-up
|
||||
if ( OHCI_REG->rhport_status_bit[0].current_connect_status )
|
||||
{
|
||||
// TODO reset port immediately, without this controller will got 2-3 (debouncing connection status change)
|
||||
OHCI_REG->rhport_status[0] = OHCI_RHPORT_PORT_RESET_STATUS_MASK;
|
||||
hcd_event_device_attach(hostid, true);
|
||||
}else
|
||||
{
|
||||
hcd_event_device_remove(hostid, true);
|
||||
}
|
||||
}
|
||||
|
||||
if ( rhport_status & OHCI_RHPORT_PORT_SUSPEND_CHANGE_MASK)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
OHCI_REG->rhport_status[0] = rhport_status; // acknowledge all interrupt
|
||||
}
|
||||
|
||||
//------------- Transfer Complete -------------//
|
||||
if ( int_status & OHCI_INT_WRITEBACK_DONEHEAD_MASK)
|
||||
{
|
||||
done_queue_isr(hostid);
|
||||
}
|
||||
|
||||
OHCI_REG->interrupt_status = int_status; // Acknowledge handled interrupt
|
||||
}
|
||||
//--------------------------------------------------------------------+
|
||||
// HELPER
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
291
src/portable/ohci/ohci.h
Normal file
291
src/portable/ohci/ohci.h
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
/** \ingroup Group_HCD
|
||||
* @{
|
||||
* \defgroup OHCI
|
||||
* \brief OHCI driver. All documents sources mentioned here (eg section 3.5) is referring to OHCI Specs unless state otherwise
|
||||
* @{ */
|
||||
|
||||
#ifndef _TUSB_OHCI_H_
|
||||
#define _TUSB_OHCI_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// OHCI CONFIGURATION & CONSTANTS
|
||||
//--------------------------------------------------------------------+
|
||||
#define HOST_HCD_XFER_INTERRUPT // TODO interrupt is used widely, should always be enalbed
|
||||
#define OHCI_PERIODIC_LIST (defined HOST_HCD_XFER_INTERRUPT || defined HOST_HCD_XFER_ISOCHRONOUS)
|
||||
|
||||
// TODO merge OHCI with EHCI
|
||||
enum {
|
||||
OHCI_MAX_ITD = 4
|
||||
};
|
||||
|
||||
enum {
|
||||
OHCI_PID_SETUP = 0,
|
||||
OHCI_PID_OUT,
|
||||
OHCI_PID_IN,
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// OHCI Data Structure
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
uint32_t interrupt_table[32];
|
||||
volatile uint16_t frame_number;
|
||||
volatile uint16_t frame_pad;
|
||||
volatile uint32_t done_head;
|
||||
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
|
||||
}ohci_hcca_t; // TU_ATTR_ALIGNED(256)
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(ohci_hcca_t) == 256, "size is not correct" );
|
||||
|
||||
typedef struct {
|
||||
uint32_t reserved[2];
|
||||
volatile uint32_t next;
|
||||
uint32_t reserved2;
|
||||
}ohci_td_item_t;
|
||||
|
||||
|
||||
typedef struct TU_ATTR_ALIGNED(16)
|
||||
{
|
||||
// Word 0
|
||||
uint32_t used : 1;
|
||||
uint32_t index : 4; // endpoint index the td belongs to, or device address in case of control xfer
|
||||
uint32_t expected_bytes : 13; // TODO available for hcd
|
||||
|
||||
uint32_t buffer_rounding : 1;
|
||||
uint32_t pid : 2;
|
||||
uint32_t delay_interrupt : 3;
|
||||
volatile uint32_t data_toggle : 2;
|
||||
volatile uint32_t error_count : 2;
|
||||
volatile uint32_t condition_code : 4;
|
||||
|
||||
// Word 1
|
||||
volatile uint8_t* current_buffer_pointer;
|
||||
|
||||
// Word 2 : next TD
|
||||
volatile uint32_t next;
|
||||
|
||||
// Word 3
|
||||
uint8_t* buffer_end;
|
||||
} ohci_gtd_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(ohci_gtd_t) == 16, "size is not correct" );
|
||||
|
||||
typedef struct TU_ATTR_ALIGNED(16)
|
||||
{
|
||||
// Word 0
|
||||
uint32_t dev_addr : 7;
|
||||
uint32_t ep_number : 4;
|
||||
uint32_t pid : 2; // 00b from TD, 01b Out, 10b In
|
||||
uint32_t speed : 1;
|
||||
uint32_t skip : 1;
|
||||
uint32_t is_iso : 1;
|
||||
uint32_t max_packet_size : 11;
|
||||
// HCD: make use of 5 reserved bits
|
||||
uint32_t used : 1;
|
||||
uint32_t is_interrupt_xfer : 1;
|
||||
uint32_t is_stalled : 1;
|
||||
uint32_t : 2;
|
||||
|
||||
// Word 1
|
||||
uint32_t td_tail;
|
||||
|
||||
// Word 2
|
||||
volatile union {
|
||||
uint32_t address;
|
||||
struct {
|
||||
uint32_t halted : 1;
|
||||
uint32_t toggle : 1;
|
||||
uint32_t : 30;
|
||||
};
|
||||
}td_head;
|
||||
|
||||
// Word 3: next ED
|
||||
uint32_t next;
|
||||
} ohci_ed_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(ohci_ed_t) == 16, "size is not correct" );
|
||||
|
||||
typedef struct TU_ATTR_ALIGNED(32)
|
||||
{
|
||||
/*---------- Word 1 ----------*/
|
||||
uint32_t starting_frame : 16;
|
||||
uint32_t : 5; // can be used
|
||||
uint32_t delay_interrupt : 3;
|
||||
uint32_t frame_count : 3;
|
||||
uint32_t : 1; // can be used
|
||||
volatile uint32_t condition_code : 4;
|
||||
|
||||
/*---------- Word 2 ----------*/
|
||||
uint32_t buffer_page0; // 12 lsb bits can be used
|
||||
|
||||
/*---------- Word 3 ----------*/
|
||||
volatile uint32_t next;
|
||||
|
||||
/*---------- Word 4 ----------*/
|
||||
uint32_t buffer_end;
|
||||
|
||||
/*---------- Word 5-8 ----------*/
|
||||
volatile uint16_t offset_packetstatus[8];
|
||||
} ochi_itd_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(ochi_itd_t) == 32, "size is not correct" );
|
||||
|
||||
// structure with member alignment required from large to small
|
||||
typedef struct TU_ATTR_ALIGNED(256)
|
||||
{
|
||||
ohci_hcca_t hcca;
|
||||
|
||||
ohci_ed_t bulk_head_ed; // static bulk head (dummy)
|
||||
ohci_ed_t period_head_ed; // static periodic list head (dummy)
|
||||
|
||||
// control endpoints has reserved resources
|
||||
struct {
|
||||
ohci_ed_t ed;
|
||||
ohci_gtd_t gtd;
|
||||
}control[CFG_TUSB_HOST_DEVICE_MAX+1];
|
||||
|
||||
// ochi_itd_t itd[OHCI_MAX_ITD]; // itd requires alignment of 32
|
||||
ohci_ed_t ed_pool[HCD_MAX_ENDPOINT];
|
||||
ohci_gtd_t gtd_pool[HCD_MAX_XFER];
|
||||
|
||||
volatile uint16_t frame_number_hi;
|
||||
|
||||
} ohci_data_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// OHCI Operational Register
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// OHCI Data Organization
|
||||
//--------------------------------------------------------------------+
|
||||
typedef volatile struct
|
||||
{
|
||||
uint32_t revision;
|
||||
|
||||
union {
|
||||
uint32_t control;
|
||||
struct {
|
||||
uint32_t control_bulk_service_ratio : 2;
|
||||
uint32_t periodic_list_enable : 1;
|
||||
uint32_t isochronous_enable : 1;
|
||||
uint32_t control_list_enable : 1;
|
||||
uint32_t bulk_list_enable : 1;
|
||||
uint32_t hc_functional_state : 2;
|
||||
uint32_t interrupt_routing : 1;
|
||||
uint32_t remote_wakeup_connected : 1;
|
||||
uint32_t remote_wakeup_enale : 1;
|
||||
uint32_t TU_RESERVED : 21;
|
||||
}control_bit;
|
||||
};
|
||||
|
||||
union {
|
||||
uint32_t command_status;
|
||||
struct {
|
||||
uint32_t controller_reset : 1;
|
||||
uint32_t control_list_filled : 1;
|
||||
uint32_t bulk_list_filled : 1;
|
||||
uint32_t ownership_change_request : 1;
|
||||
uint32_t : 12;
|
||||
uint32_t scheduling_overrun_count : 2;
|
||||
}command_status_bit;
|
||||
};
|
||||
|
||||
uint32_t interrupt_status;
|
||||
uint32_t interrupt_enable;
|
||||
uint32_t interrupt_disable;
|
||||
|
||||
uint32_t hcca;
|
||||
uint32_t period_current_ed;
|
||||
uint32_t control_head_ed;
|
||||
uint32_t control_current_ed;
|
||||
uint32_t bulk_head_ed;
|
||||
uint32_t bulk_current_ed;
|
||||
uint32_t done_head;
|
||||
|
||||
uint32_t frame_interval;
|
||||
uint32_t frame_remaining;
|
||||
uint32_t frame_number;
|
||||
uint32_t periodic_start;
|
||||
uint32_t lowspeed_threshold;
|
||||
|
||||
uint32_t rh_descriptorA;
|
||||
uint32_t rh_descriptorB;
|
||||
|
||||
union {
|
||||
uint32_t rh_status;
|
||||
struct {
|
||||
uint32_t local_power_status : 1; // read Local Power Status; write: Clear Global Power
|
||||
uint32_t over_current_indicator : 1;
|
||||
uint32_t : 13;
|
||||
uint32_t device_remote_wakeup_enable : 1;
|
||||
uint32_t local_power_status_change : 1;
|
||||
uint32_t over_current_indicator_change : 1;
|
||||
uint32_t : 13;
|
||||
uint32_t clear_remote_wakeup_enable : 1;
|
||||
}rh_status_bit;
|
||||
};
|
||||
|
||||
union {
|
||||
uint32_t rhport_status[2]; // TODO NXP OHCI controller only has 2 ports
|
||||
struct {
|
||||
uint32_t current_connect_status : 1;
|
||||
uint32_t port_enable_status : 1;
|
||||
uint32_t port_suspend_status : 1;
|
||||
uint32_t port_over_current_indicator : 1;
|
||||
uint32_t port_reset_status : 1;
|
||||
uint32_t : 3;
|
||||
uint32_t port_power_status : 1;
|
||||
uint32_t low_speed_device_attached : 1;
|
||||
uint32_t : 6;
|
||||
uint32_t connect_status_change : 1;
|
||||
uint32_t port_enable_status_change : 1;
|
||||
uint32_t port_suspend_status_change : 1;
|
||||
uint32_t port_over_current_indicator_change : 1;
|
||||
uint32_t port_reset_status_change : 1;
|
||||
uint32_t TU_RESERVED : 11;
|
||||
}rhport_status_bit[2];
|
||||
};
|
||||
}ohci_registers_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(ohci_registers_t) == 0x5c, "size is not correct");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_OHCI_H_ */
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
Reference in New Issue
Block a user