lpc17 ohci failed to execute control transfer !!
This commit is contained in:
@@ -51,8 +51,8 @@
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HCD_EVENT_DEVICE_PLUG,
|
||||
HCD_EVENT_DEVICE_UNPLUG,
|
||||
HCD_EVENT_DEVICE_ATTACH,
|
||||
HCD_EVENT_DEVICE_REMOVE,
|
||||
HCD_EVENT_XFER_COMPLETE,
|
||||
} hcd_eventid_t;
|
||||
|
||||
@@ -67,7 +67,7 @@ typedef struct
|
||||
{
|
||||
uint8_t hub_addr;
|
||||
uint8_t hub_port;
|
||||
} plug, unplug;
|
||||
} attach, remove;
|
||||
|
||||
struct
|
||||
{
|
||||
|
||||
@@ -42,13 +42,15 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "hal/hal.h"
|
||||
#include "osal/osal.h"
|
||||
|
||||
#include "../hcd.h"
|
||||
#include "../usbh_hcd.h"
|
||||
#include "ohci.h"
|
||||
|
||||
// TODO remove
|
||||
#include "chip.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -206,16 +208,19 @@ tusb_error_t hcd_init(void)
|
||||
//--------------------------------------------------------------------+
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -223,6 +228,7 @@ tusb_speed_t hcd_port_speed_get(uint8_t hostid)
|
||||
void hcd_port_unplug(uint8_t hostid)
|
||||
{
|
||||
// TODO OHCI
|
||||
(void) hostid;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -242,6 +248,8 @@ static inline tusb_xfer_type_t ed_get_xfer_type(ohci_ed_t const * const p_ed)
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -251,7 +259,7 @@ static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t max_packet_size,
|
||||
p_ed->device_address = dev_addr;
|
||||
p_ed->endpoint_number = endpoint_addr & 0x0F;
|
||||
p_ed->direction = (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->speed = _usbh_devices[dev_addr].speed;
|
||||
p_ed->is_iso = (xfer_type == TUSB_XFER_ISOCHRONOUS) ? 1 : 0;
|
||||
p_ed->max_package_size = max_packet_size;
|
||||
|
||||
@@ -274,6 +282,22 @@ static void gtd_init(ohci_gtd_t* p_td, void* data_ptr, uint16_t total_bytes)
|
||||
p_td->buffer_end = total_bytes ? (((uint8_t*) data_ptr) + total_bytes-1) : NULL;
|
||||
}
|
||||
|
||||
bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const* ep_desc)
|
||||
{
|
||||
// FIXME control only for now
|
||||
(void) rhport;
|
||||
return hcd_pipe_control_open(dev_addr, ep_desc->wMaxPacketSize.size);
|
||||
}
|
||||
|
||||
bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr)
|
||||
{
|
||||
// FIXME control only for now
|
||||
(void) rhport;
|
||||
(void) ep_addr;
|
||||
|
||||
return hcd_pipe_control_close(dev_addr);
|
||||
}
|
||||
|
||||
tusb_error_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
|
||||
{
|
||||
ohci_ed_t* const p_ed = &ohci_data.control[dev_addr].ed;
|
||||
@@ -346,7 +370,7 @@ tusb_error_t hcd_pipe_control_close(uint8_t dev_addr)
|
||||
ed_list_remove( p_ed_head[ ed_get_xfer_type(p_ed)], p_ed );
|
||||
|
||||
// TODO refractor to be USBH
|
||||
usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG;
|
||||
_usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG;
|
||||
}
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
@@ -496,6 +520,7 @@ tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint
|
||||
|
||||
tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete)
|
||||
{
|
||||
(void) int_on_complete;
|
||||
TU_ASSERT_ERR( pipe_queue_xfer(pipe_hdl, buffer, total_bytes, true) );
|
||||
|
||||
tusb_xfer_type_t xfer_type = ed_get_xfer_type( ed_from_pipe_handle(pipe_hdl) );
|
||||
@@ -607,6 +632,8 @@ static inline uint32_t gtd_xfer_byte_left(uint32_t buffer_end, uint32_t current_
|
||||
|
||||
static void done_queue_isr(uint8_t hostid)
|
||||
{
|
||||
(void) hostid;
|
||||
|
||||
uint8_t max_loop = (CFG_TUSB_HOST_DEVICE_MAX+1)*(HCD_MAX_XFER+OHCI_MAX_ITD);
|
||||
|
||||
// done head is written in reversed order of completion --> need to reverse the done queue first
|
||||
|
||||
@@ -193,13 +193,17 @@ bool usbh_init(void)
|
||||
bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8_t* data)
|
||||
{
|
||||
usbh_device_t* dev = &_usbh_devices[dev_addr];
|
||||
const uint8_t rhport = dev->core_id;
|
||||
//const uint8_t rhport = dev->core_id;
|
||||
|
||||
TU_ASSERT(osal_mutex_lock(dev->control.mutex_hdl, OSAL_TIMEOUT_NORMAL));
|
||||
|
||||
dev->control.request = *request;
|
||||
dev->control.pipe_status = 0;
|
||||
|
||||
#if 1
|
||||
TU_ASSERT(hcd_pipe_control_xfer(dev_addr, &dev->control.request, data));
|
||||
TU_ASSERT(osal_semaphore_wait(dev->control.sem_hdl, OSAL_TIMEOUT_NORMAL));
|
||||
#else
|
||||
// Setup Stage
|
||||
hcd_setup_send(rhport, dev_addr, (uint8_t*) &dev->control.request);
|
||||
TU_VERIFY(osal_semaphore_wait(dev->control.sem_hdl, OSAL_TIMEOUT_NORMAL));
|
||||
@@ -214,6 +218,7 @@ bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8
|
||||
// Status : data toggle is always 1
|
||||
hcd_edpt_xfer(rhport, dev_addr, edpt_addr(0, 1-request->bmRequestType_bit.direction), NULL, 0);
|
||||
TU_VERIFY(osal_semaphore_wait(dev->control.sem_hdl, OSAL_TIMEOUT_NORMAL));
|
||||
#endif
|
||||
|
||||
osal_mutex_unlock(dev->control.mutex_hdl);
|
||||
|
||||
@@ -231,7 +236,7 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
|
||||
{
|
||||
osal_semaphore_reset( _usbh_devices[dev_addr].control.sem_hdl );
|
||||
//osal_mutex_reset( usbh_devices[dev_addr].control.mutex_hdl );
|
||||
|
||||
|
||||
tusb_desc_endpoint_t ep0_desc =
|
||||
{
|
||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||
@@ -296,11 +301,11 @@ void usbh_hub_port_plugged_isr(uint8_t hub_addr, uint8_t hub_port)
|
||||
hcd_event_t event =
|
||||
{
|
||||
.rhport = _usbh_devices[hub_addr].core_id,
|
||||
.event_id = HCD_EVENT_DEVICE_PLUG
|
||||
.event_id = HCD_EVENT_DEVICE_ATTACH
|
||||
};
|
||||
|
||||
event.plug.hub_addr = hub_addr;
|
||||
event.plug.hub_port = hub_port;
|
||||
event.attach.hub_addr = hub_addr;
|
||||
event.attach.hub_port = hub_port;
|
||||
|
||||
hcd_event_handler(&event, true);
|
||||
}
|
||||
@@ -310,11 +315,11 @@ void usbh_hcd_rhport_plugged_isr(uint8_t hostid)
|
||||
hcd_event_t event =
|
||||
{
|
||||
.rhport = hostid,
|
||||
.event_id = HCD_EVENT_DEVICE_PLUG
|
||||
.event_id = HCD_EVENT_DEVICE_ATTACH
|
||||
};
|
||||
|
||||
event.plug.hub_addr = 0;
|
||||
event.plug.hub_port = 0;
|
||||
event.attach.hub_addr = 0;
|
||||
event.attach.hub_port = 0;
|
||||
|
||||
hcd_event_handler(&event, true);
|
||||
}
|
||||
@@ -374,11 +379,11 @@ void usbh_hcd_rhport_unplugged_isr(uint8_t hostid)
|
||||
hcd_event_t event =
|
||||
{
|
||||
.rhport = hostid,
|
||||
.event_id = HCD_EVENT_DEVICE_UNPLUG
|
||||
.event_id = HCD_EVENT_DEVICE_REMOVE
|
||||
};
|
||||
|
||||
event.plug.hub_addr = 0;
|
||||
event.plug.hub_port = 0;
|
||||
event.attach.hub_addr = 0;
|
||||
event.attach.hub_port = 0;
|
||||
|
||||
hcd_event_handler(&event, true);
|
||||
}
|
||||
@@ -402,8 +407,8 @@ bool enum_task(hcd_event_t* event)
|
||||
tusb_control_request_t request;
|
||||
|
||||
dev0->core_id = event->rhport; // TODO refractor integrate to device_pool
|
||||
dev0->hub_addr = event->plug.hub_addr;
|
||||
dev0->hub_port = event->plug.hub_port;
|
||||
dev0->hub_addr = event->attach.hub_addr;
|
||||
dev0->hub_port = event->attach.hub_port;
|
||||
dev0->state = TUSB_DEVICE_STATE_UNPLUG;
|
||||
|
||||
//------------- connected/disconnected directly with roothub -------------//
|
||||
@@ -644,8 +649,8 @@ bool usbh_task_body(void)
|
||||
|
||||
switch (event.event_id)
|
||||
{
|
||||
case HCD_EVENT_DEVICE_PLUG:
|
||||
case HCD_EVENT_DEVICE_UNPLUG:
|
||||
case HCD_EVENT_DEVICE_ATTACH:
|
||||
case HCD_EVENT_DEVICE_REMOVE:
|
||||
enum_task(&event);
|
||||
break;
|
||||
|
||||
|
||||
@@ -42,10 +42,11 @@
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
extern void hal_hcd_isr(uint8_t hostid);
|
||||
extern void hal_dcd_isr(uint8_t rhport);
|
||||
|
||||
void USB_IRQHandler(void)
|
||||
{
|
||||
extern void hal_dcd_isr(uint8_t rhport);
|
||||
|
||||
#if MODE_HOST_SUPPORTED
|
||||
hal_hcd_isr(0);
|
||||
#endif
|
||||
@@ -55,4 +56,18 @@ void USB_IRQHandler(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
//FIXME move later
|
||||
void hcd_int_enable(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
NVIC_EnableIRQ(USB_IRQn);
|
||||
}
|
||||
|
||||
void hcd_int_disable(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
NVIC_DisableIRQ(USB_IRQn);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user