diff options
| author | hathach <[email protected]> | 2018-12-12 16:41:12 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-12-12 16:41:12 +0700 |
| commit | 908931320e206e6ae6610cfc56b2a0950f252172 (patch) | |
| tree | 8ae966733204841d54cf15f3e1154699cc884526 /src/host | |
| parent | b7ad49332cd9a5539e35a75785adb5ca2e79715a (diff) | |
| parent | 142f274c1d0cef2a1a5623885be29e2fecef4445 (diff) | |
Merge pull request #21 from hathach/devlocal
Devlocal
Diffstat (limited to 'src/host')
| -rw-r--r-- | src/host/ehci/ehci.c | 52 | ||||
| -rw-r--r-- | src/host/hcd.h | 6 | ||||
| -rw-r--r-- | src/host/hub.c | 10 | ||||
| -rw-r--r-- | src/host/ohci/ohci.c | 12 | ||||
| -rw-r--r-- | src/host/usbh.c | 38 |
5 files changed, 54 insertions, 64 deletions
diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 146ab0615..b46c9bc64 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -48,9 +48,6 @@ #include "../usbh_hcd.h"
#include "ehci.h"
-// TODO remove
-#include "chip.h"
-
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
@@ -61,13 +58,8 @@ // Periodic frame list must be 4K alignment
CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4096) static ehci_data_t ehci_data;
-//------------- Validation -------------//
-// TODO static assert for memory placement on some known MCU such as lpc43xx
-
-uint32_t hcd_ehci_register_addr(uint8_t rhport)
-{
- return (uint32_t) (rhport ? &LPC_USB1->USBCMD_H : &LPC_USB0->USBCMD_H );
-}
+// EHCI portable
+uint32_t hcd_ehci_register_addr(uint8_t rhport);
//--------------------------------------------------------------------+
// PROTOTYPE
@@ -117,7 +109,7 @@ 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);
-static bool ehci_init (uint8_t hostid);
+static bool ehci_init (uint8_t rhport);
//--------------------------------------------------------------------+
// HCD API
@@ -181,7 +173,7 @@ static void list_remove_qhd_by_addr(ehci_link_t* list_head, uint8_t dev_addr) }
// Close all opened endpoint belong to this device
-void hcd_device_remove(uint8_t rhport, uint8_t dev_addr)
+void hcd_device_close(uint8_t rhport, uint8_t dev_addr)
{
// skip dev0
if (dev_addr == 0) return;
@@ -200,9 +192,9 @@ void hcd_device_remove(uint8_t rhport, uint8_t dev_addr) }
// EHCI controller init
-static bool ehci_init(uint8_t hostid)
+static bool ehci_init(uint8_t rhport)
{
- ehci_data.regs = (ehci_registers_t* ) hcd_ehci_register_addr(hostid);
+ ehci_data.regs = (ehci_registers_t* ) hcd_ehci_register_addr(rhport);
ehci_registers_t* regs = ehci_data.regs;
@@ -215,7 +207,7 @@ static bool ehci_init(uint8_t hostid) EHCI_INT_MASK_NXP_PERIODIC | EHCI_INT_MASK_NXP_ASYNC ;
//------------- Asynchronous List -------------//
- ehci_qhd_t * const async_head = qhd_async_head(hostid);
+ 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
@@ -235,7 +227,7 @@ static bool ehci_init(uint8_t hostid) }
ehci_link_t * const framelist = ehci_data.period_framelist;
- ehci_link_t * const period_1ms = get_period_head(hostid, 1);
+ 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)
@@ -250,15 +242,15 @@ static bool ehci_init(uint8_t hostid) for(uint32_t i=0; i<EHCI_FRAMELIST_SIZE; i+=2)
{
- list_insert(framelist + i, get_period_head(hostid, 2), EHCI_QTYPE_QHD);
+ 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(hostid, 4), EHCI_QTYPE_QHD);
+ list_insert(framelist + i, get_period_head(rhport, 4), EHCI_QTYPE_QHD);
}
- list_insert(framelist+3, get_period_head(hostid, 8), EHCI_QTYPE_QHD);
+ list_insert(framelist+3, get_period_head(rhport, 8), EHCI_QTYPE_QHD);
period_1ms->terminate = 1;
@@ -279,7 +271,8 @@ static bool ehci_init(uint8_t hostid) return true;
}
-static void hcd_controller_stop(uint8_t rhport)
+#if 0
+static void ehci_stop(uint8_t rhport)
{
(void) rhport;
@@ -290,6 +283,7 @@ static void hcd_controller_stop(uint8_t rhport) // USB Spec: controller has to stop within 16 uframe = 2 frames
while( regs->status_bm.hc_halted == 0 ) {}
}
+#endif
//--------------------------------------------------------------------+
// CONTROL PIPE API
@@ -298,8 +292,8 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * {
(void) rhport;
- uint8_t const epnum = edpt_number(ep_addr);
- uint8_t const dir = edpt_dir(ep_addr);
+ 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 )
@@ -382,11 +376,11 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const {
case TUSB_XFER_CONTROL:
case TUSB_XFER_BULK:
- list_head = (ehci_link_t*) qhd_async_head(_usbh_devices[dev_addr].rhport);
+ list_head = (ehci_link_t*) qhd_async_head(rhport);
break;
case TUSB_XFER_INTERRUPT:
- list_head = get_period_head(_usbh_devices[dev_addr].rhport, p_qhd->interval_ms);
+ list_head = get_period_head(rhport, p_qhd->interval_ms);
break;
case TUSB_XFER_ISOCHRONOUS:
@@ -505,7 +499,7 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd) {
// end of request
// call USBH callback
- hcd_event_xfer_complete(p_qhd->dev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes);
+ hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes);
p_qhd->total_xferred_bytes = 0;
}
}
@@ -592,7 +586,7 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd) }
// call USBH callback
- hcd_event_xfer_complete(p_qhd->dev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes);
+ hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes);
p_qhd->total_xferred_bytes = 0;
}
@@ -718,7 +712,7 @@ static inline ehci_qhd_t* qhd_get_from_addr(uint8_t dev_addr, uint8_t ep_addr) for(uint32_t i=0; i<HCD_MAX_ENDPOINT; i++)
{
if ( (qhd_pool[i].dev_addr == dev_addr) &&
- ep_addr == edpt_addr(qhd_pool[i].ep_number, qhd_pool[i].pid) )
+ ep_addr == tu_edpt_addr(qhd_pool[i].ep_number, qhd_pool[i].pid) )
{
return &qhd_pool[i];
}
@@ -779,7 +773,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c p_qhd->dev_addr = dev_addr;
p_qhd->fl_inactive_next_xact = 0;
- p_qhd->ep_number = edpt_number(ep_desc->bEndpointAddress);
+ 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
@@ -826,7 +820,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c p_qhd->removing = 0;
p_qhd->p_qtd_list_head = NULL;
p_qhd->p_qtd_list_tail = NULL;
- p_qhd->pid = edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint
+ 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;
diff --git a/src/host/hcd.h b/src/host/hcd.h index 1496d462a..e117c20ff 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -108,8 +108,8 @@ bool hcd_port_connect_status(uint8_t hostid); void hcd_port_reset(uint8_t hostid);
tusb_speed_t hcd_port_speed_get(uint8_t hostid);
-// HCD closs all opened endpoints belong to this device
-void hcd_device_remove(uint8_t rhport, uint8_t dev_addr);
+// HCD closes all opened endpoints belong to this device
+void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
//--------------------------------------------------------------------+
// Event function
@@ -135,7 +135,7 @@ bool hcd_edpt_busy(uint8_t dev_addr, uint8_t ep_addr); bool hcd_edpt_stalled(uint8_t dev_addr, uint8_t ep_addr);
bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr);
-
+// TODO merge with pipe_xfer
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen);
//--------------------------------------------------------------------+
diff --git a/src/host/hub.c b/src/host/hub.c index e2e91d73d..6b87e935e 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -156,21 +156,21 @@ void hub_init(void) // hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) );
}
-bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length)
+bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length)
{
// not support multiple TT yet
- if ( p_interface_desc->bInterfaceProtocol > 1 ) return false;
+ if ( itf_desc->bInterfaceProtocol > 1 ) return false;
//------------- Open Interrupt Status Pipe -------------//
tusb_desc_endpoint_t const *ep_desc;
- ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_interface_desc );
+ ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
TU_ASSERT(TUSB_XFER_INTERRUPT == ep_desc->bmAttributes.xfer);
TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
- hub_data[dev_addr-1].itf_num = p_interface_desc->bInterfaceNumber;
+ hub_data[dev_addr-1].itf_num = itf_desc->bInterfaceNumber;
hub_data[dev_addr-1].ep_status = ep_desc->bEndpointAddress;
(*p_length) = sizeof(tusb_desc_interface_t) + sizeof(tusb_desc_endpoint_t);
@@ -245,7 +245,7 @@ void hub_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xf else
{
// TODO [HUB] check if hub is still plugged before polling status endpoint since failed usually mean hub unplugged
-// TU_ASSERT ( TUSB_ERROR_NONE == hcd_pipe_xfer(pipe_hdl, &p_hub->status_change, 1, true) );
+// TU_ASSERT ( hub_status_pipe_queue(dev_addr) );
}
}
diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 669aa2a15..bebb8a2ef 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -216,7 +216,7 @@ tusb_speed_t hcd_port_speed_get(uint8_t hostid) // 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_remove(uint8_t rhport, uint8_t dev_addr)
+void hcd_device_close(uint8_t rhport, uint8_t dev_addr)
{
// TODO OHCI
(void) rhport;
@@ -315,8 +315,8 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * {
(void) rhport;
- uint8_t const epnum = edpt_number(ep_addr);
- uint8_t const dir = edpt_dir(ep_addr);
+ 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 )
@@ -344,14 +344,14 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * //--------------------------------------------------------------------+
static inline ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr)
{
- if ( edpt_number(ep_addr) == 0 ) return &ohci_data.control[dev_addr].ed;
+ 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 == edpt_addr(ed_pool[i].ep_number, ed_pool[i].pid == OHCI_PID_IN) )
+ ep_addr == tu_edpt_addr(ed_pool[i].ep_number, ed_pool[i].pid == OHCI_PID_IN) )
{
return &ed_pool[i];
}
@@ -603,7 +603,7 @@ static void done_queue_isr(uint8_t hostid) }
hcd_event_xfer_complete(p_ed->dev_addr,
- edpt_addr(p_ed->ep_number, p_ed->pid == OHCI_PID_IN),
+ tu_edpt_addr(p_ed->ep_number, p_ed->pid == OHCI_PID_IN),
event, xferred_bytes);
}
diff --git a/src/host/usbh.c b/src/host/usbh.c index 31024f1f7..39de4f7e7 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -205,12 +205,12 @@ bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8 // Data stage : first data toggle is always 1
if ( request->wLength )
{
- hcd_edpt_xfer(rhport, dev_addr, edpt_addr(0, request->bmRequestType_bit.direction), data, request->wLength);
+ hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, request->bmRequestType_bit.direction), data, request->wLength);
TU_VERIFY(osal_semaphore_wait(dev->control.sem_hdl, OSAL_TIMEOUT_NORMAL));
}
// Status : data toggle is always 1
- hcd_edpt_xfer(rhport, dev_addr, edpt_addr(0, 1-request->bmRequestType_bit.direction), NULL, 0);
+ hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, 1-request->bmRequestType_bit.direction), NULL, 0);
TU_VERIFY(osal_semaphore_wait(dev->control.sem_hdl, OSAL_TIMEOUT_NORMAL));
osal_mutex_unlock(dev->control.mutex_hdl);
@@ -249,7 +249,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev {
usbh_device_t* dev = &_usbh_devices[ dev_addr ];
- if (0 == edpt_number(ep_addr))
+ if (0 == tu_edpt_number(ep_addr))
{
dev->control.pipe_status = event;
// usbh_devices[ pipe_hdl.dev_addr ].control.xferred_bytes = xferred_bytes; not yet neccessary
@@ -257,7 +257,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev }
else
{
- uint8_t drv_id = dev->ep2drv[edpt_number(ep_addr)][edpt_dir(ep_addr)];
+ uint8_t drv_id = dev->ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)];
TU_ASSERT(drv_id < USBH_CLASS_DRIVER_COUNT, );
if (usbh_class_drivers[drv_id].isr)
@@ -334,7 +334,7 @@ static void usbh_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t hub_ memset(dev->itf2drv, 0xff, sizeof(dev->itf2drv)); // invalid mapping
memset(dev->ep2drv , 0xff, sizeof(dev->ep2drv )); // invalid mapping
- hcd_device_remove(rhport, dev_addr);
+ hcd_device_close(rhport, dev_addr);
dev->state = TUSB_DEVICE_STATE_UNPLUG;
}
@@ -438,7 +438,6 @@ bool enum_task(hcd_event_t* event) #endif
TU_ASSERT_ERR( usbh_pipe_control_open(0, 8) );
- dev0->state = TUSB_DEVICE_STATE_ADDRESSED;
//------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------//
request = (tusb_control_request_t ) {
@@ -493,9 +492,8 @@ bool enum_task(hcd_event_t* event) new_dev->hub_addr = dev0->hub_addr;
new_dev->hub_port = dev0->hub_port;
new_dev->speed = dev0->speed;
- new_dev->state = TUSB_DEVICE_STATE_ADDRESSED;
- hcd_device_remove(dev0->rhport, 0); // close device 0
+ hcd_device_close(dev0->rhport, 0); // close device 0
dev0->state = TUSB_DEVICE_STATE_UNPLUG;
// open control pipe for new address
@@ -560,9 +558,9 @@ bool enum_task(hcd_event_t* event) while( p_desc < _usbh_ctrl_buf + ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength )
{
// skip until we see interface descriptor
- if ( TUSB_DESC_INTERFACE != descriptor_type(p_desc) )
+ if ( TUSB_DESC_INTERFACE != tu_desc_type(p_desc) )
{
- p_desc = descriptor_next(p_desc); // skip the descriptor, increase by the descriptor's length
+ p_desc = tu_desc_next(p_desc); // skip the descriptor, increase by the descriptor's length
}else
{
tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc;
@@ -577,7 +575,7 @@ bool enum_task(hcd_event_t* event) if( drv_id >= USBH_CLASS_DRIVER_COUNT )
{
// skip unsupported class
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
else
{
@@ -589,7 +587,7 @@ bool enum_task(hcd_event_t* event) {
// TODO Attach hub to Hub is not currently supported
// skip this interface
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
else
{
@@ -655,13 +653,11 @@ void usbh_task(void* param) //--------------------------------------------------------------------+
static inline uint8_t get_new_address(void)
{
- uint8_t addr;
- for (addr=1; addr <= CFG_TUSB_HOST_DEVICE_MAX; addr++)
+ for (uint8_t addr=1; addr <= CFG_TUSB_HOST_DEVICE_MAX; addr++)
{
- if (_usbh_devices[addr].state == TUSB_DEVICE_STATE_UNPLUG)
- break;
+ if (_usbh_devices[addr].state == TUSB_DEVICE_STATE_UNPLUG) return addr;
}
- return addr;
+ return CFG_TUSB_HOST_DEVICE_MAX;
}
static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc)
@@ -685,15 +681,15 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, while( len < desc_len )
{
- if ( TUSB_DESC_ENDPOINT == descriptor_type(p_desc) )
+ if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
{
uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress;
- ep2drv[ edpt_number(ep_addr) ][ edpt_dir(ep_addr) ] = driver_id;
+ ep2drv[ tu_edpt_number(ep_addr) ][ tu_edpt_dir(ep_addr) ] = driver_id;
}
- len += descriptor_len(p_desc);
- p_desc = descriptor_next(p_desc);
+ len += tu_desc_len(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
}
|
