add some doxygen work
finalize device disconnection & suspend
- suspend & resume & remote wake up is not supported yet
This commit is contained in:
hathach
2013-11-22 15:16:24 +07:00
parent d1ef89a154
commit 83f1d660ce
24 changed files with 219 additions and 236 deletions

View File

@@ -217,14 +217,21 @@ void dcd_isr(uint8_t coreid)
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_RESET);
}
if ( (dev_status_reg & SIE_DEV_STATUS_CONNECT_CHANGE_MASK) && !(dev_status_reg & SIE_DEV_STATUS_CONNECT_STATUS_MASK))
{ // TODO device is disconnected, require using VBUS (P1_30), cannot use CONNECT_STATUS as connection status
if (dev_status_reg & SIE_DEV_STATUS_CONNECT_CHANGE_MASK)
{ // device is disconnected, require using VBUS (P1_30)
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_UNPLUGGED);
}
if ( (dev_status_reg & SIE_DEV_STATUS_SUSPEND_CHANGE_MASK) && (dev_status_reg & SIE_DEV_STATUS_SUSPEND_MASK) )
if (dev_status_reg & SIE_DEV_STATUS_SUSPEND_CHANGE_MASK)
{
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_SUSPENDED);
if (dev_status_reg & SIE_DEV_STATUS_SUSPEND_MASK)
{
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_SUSPENDED);
}
// else
// {
// usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_RESUME);
// }
}
}

View File

@@ -36,13 +36,13 @@
*/
/**************************************************************************/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
/** \ingroup Port_DCD
* @{
* \defgroup LPC175x_6x
* @{
*/
#ifndef _TUSB_DCD_LPC175X_6X_H_
#define _TUSB_DCD_LPC175X_6X_H_
@@ -53,7 +53,7 @@
#endif
typedef struct
typedef struct ATTR_ALIGNED(4)
{
//------------- Word 0 -------------//
uint32_t next;
@@ -81,7 +81,7 @@ typedef struct
//------------- Word 4 -------------//
// uint32_t iso_packet_size_addr; // iso only, can be omitted for non-iso
} ATTR_ALIGNED(4) dcd_dma_descriptor_t;
}dcd_dma_descriptor_t;
STATIC_ASSERT( sizeof(dcd_dma_descriptor_t) == 16, "size is not correct"); // TODO not support ISO for now
@@ -239,3 +239,5 @@ static inline uint32_t sie_read (uint8_t cmd_code, uint8_t data_len)
#endif /* _TUSB_DCD_LPC175X_6X_H_ */
/** @} */
/** @} */

View File

@@ -90,6 +90,14 @@ enum {
INT_MASK_NAK = BIT_(16)
};
//------------- PORTSC -------------//
enum {
PORTSC_CURRENT_CONNECT_STATUS_MASK = BIT_(0),
PORTSC_FORCE_PORT_RESUME_MASK = BIT_(6),
PORTSC_SUSPEND_MASK = BIT_(7)
};
typedef struct {
// Word 0: Next QTD Pointer
uint32_t next; ///< Next link pointer This field contains the physical memory address of the next dTD to be processed
@@ -256,7 +264,7 @@ static void lpc43xx_controller_init(uint8_t coreid)
lpc_usb->ENDPOINTLISTADDR = (uint32_t) p_dcd->qhd; // Endpoint List Address has to be 2K alignment
lpc_usb->USBSTS_D = lpc_usb->USBSTS_D;
lpc_usb->USBINTR_D = INT_MASK_USB | INT_MASK_ERROR | INT_MASK_PORT_CHANGE | INT_MASK_RESET | INT_MASK_SUSPEND; // | INT_MASK_SOF| INT_MASK_NAK;
lpc_usb->USBINTR_D = INT_MASK_USB | INT_MASK_ERROR | INT_MASK_PORT_CHANGE | INT_MASK_RESET | INT_MASK_SUSPEND; // | INT_MASK_SOF;
lpc_usb->USBCMD_D &= ~0x00FF0000; // Interrupt Threshold Interval = 0
lpc_usb->USBCMD_D |= BIT_(0); // connect
@@ -524,19 +532,27 @@ void dcd_isr(uint8_t coreid)
{
LPC_USB0_Type* const lpc_usb = LPC_USB[coreid];
uint32_t int_status = lpc_usb->USBSTS_D;
int_status &= lpc_usb->USBINTR_D;
uint32_t const int_status = lpc_usb->USBSTS_D & lpc_usb->USBINTR_D;
lpc_usb->USBSTS_D = int_status; // Acknowledge handled interrupt
if (int_status == 0) return;
if (int_status == 0) return; // disabled interrupt sources
if (int_status & INT_MASK_RESET)
{
bus_reset(coreid);
usbd_bus_reset(coreid);
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_RESET);
}
// if (int_status & INT_MASK_SUSPEND)
// {
// uint32_t portsc = lpc_usb->PORTSC1_D;
//
// if (portsc & PORTSC_SUSPEND_MASK)
// {
// tusbd_device_suspended_cb(coreid);
// }
// }
if (int_status & INT_MASK_USB)
{
//------------- Set up Received -------------//

View File

@@ -64,9 +64,10 @@ enum {
};
enum {
CMDSTAT_DEVICE_ADDR_MASK = BIT_(7 )-1,
CMDSTAT_DEVICE_ENABLE_MASK = BIT_(7 ),
CMDSTAT_SETUP_RECEIVED_MASK = BIT_(8 ),
CMDSTAT_DEVICE_CONNECT_MASK = BIT_(16),
CMDSTAT_DEVICE_CONNECT_MASK = BIT_(16), ///< reflect the softconnect only, does not reflect the actual attached state
CMDSTAT_DEVICE_SUSPEND_MASK = BIT_(17),
CMDSTAT_CONNECT_CHANGE_MASK = BIT_(24),
CMDSTAT_SUSPEND_CHANGE_MASK = BIT_(25),
@@ -131,7 +132,7 @@ void dcd_controller_set_address(uint8_t coreid, uint8_t dev_addr)
{
(void) coreid;
LPC_USB->DEVCMDSTAT &= ~0x7F;
LPC_USB->DEVCMDSTAT &= ~CMDSTAT_DEVICE_ADDR_MASK;
LPC_USB->DEVCMDSTAT |= dev_addr;
}
@@ -142,7 +143,8 @@ tusb_error_t dcd_init(void)
LPC_USB->INTSTAT = LPC_USB->INTSTAT; // clear all pending interrupt
LPC_USB->INTEN = INT_MASK_DEVICE_STATUS;
LPC_USB->DEVCMDSTAT |= CMDSTAT_DEVICE_ENABLE_MASK | CMDSTAT_DEVICE_CONNECT_MASK;
LPC_USB->DEVCMDSTAT |= CMDSTAT_DEVICE_ENABLE_MASK | CMDSTAT_DEVICE_CONNECT_MASK |
CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK;
return TUSB_ERROR_NONE;
}
@@ -170,9 +172,7 @@ void dcd_isr(uint8_t coreid)
{
(void) coreid;
uint32_t int_status = LPC_USB->INTSTAT;
int_status &= LPC_USB->INTEN;
uint32_t const int_status = LPC_USB->INTSTAT & LPC_USB->INTEN;
LPC_USB->INTSTAT = int_status; // Acknowledge handled interrupt
if (int_status == 0) return;
@@ -182,24 +182,38 @@ void dcd_isr(uint8_t coreid)
//------------- Device Status -------------//
if ( int_status & INT_MASK_DEVICE_STATUS )
{
LPC_USB->DEVCMDSTAT |= CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK /* CMDSTAT_SUSPEND_CHANGE_MASK */;
LPC_USB->DEVCMDSTAT |= CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK;
if ( dev_cmd_stat & CMDSTAT_RESET_CHANGE_MASK) // bus reset
{
bus_reset();
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_RESET);
}
// if ( (dev_cmd_stat & CMDSTAT_SUSPEND_CHANGE_MASK) && (dev_cmd_stat & CMDSTAT_DEVICE_SUSPEND_MASK) )
// { // find a way to distinct bus suspend vs unplug/plug
// usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_SUSPENDED);
// }
if ( (dev_cmd_stat & CMDSTAT_CONNECT_CHANGE_MASK) && !(dev_cmd_stat & CMDSTAT_VBUS_DEBOUNCED_MASK) )
if (dev_cmd_stat & CMDSTAT_CONNECT_CHANGE_MASK)
{ // device disconnect
usbd_dcd_bus_event_isr(0, 0);
if (dev_cmd_stat & CMDSTAT_DEVICE_ADDR_MASK)
{ // debouncing as this can be set when device is powering
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_UNPLUGGED);
}
}
// TODO support suspend & resume
if (dev_cmd_stat & CMDSTAT_SUSPEND_CHANGE_MASK)
{
if (dev_cmd_stat & CMDSTAT_DEVICE_SUSPEND_MASK)
{ // suspend signal, bus idle for more than 3ms
// Note: Host may delay more than 3 ms before and/or after bus reset before doing enumeration.
if (dev_cmd_stat & CMDSTAT_DEVICE_ADDR_MASK)
{
usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_SUSPENDED);
}
}
}
// else
// { // resume signal
// usbd_dcd_bus_event_isr(0, USBD_BUS_EVENT_RESUME);
// }
// }
}
//------------- Control Endpoint -------------//

View File

@@ -83,6 +83,7 @@ typedef struct {
// APPLICATION API
//--------------------------------------------------------------------+
bool tusbd_is_configured(uint8_t coreid) ATTR_WARN_UNUSED_RESULT;
//void tusbd_device_suspended_cb(uint8_t coreid);
//--------------------------------------------------------------------+
// CLASS-USBD & INTERNAL API

View File

@@ -62,7 +62,8 @@ enum {
typedef enum {
USBD_BUS_EVENT_RESET = 1,
USBD_BUS_EVENT_UNPLUGGED,
USBD_BUS_EVENT_SUSPENDED
USBD_BUS_EVENT_SUSPENDED,
USBD_BUS_EVENT_RESUME
}usbd_bus_event_type_t;
typedef struct {