summaryrefslogtreecommitdiff
path: root/tinyusb/device
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-11-22 15:16:24 +0700
committerhathach <[email protected]>2013-11-22 15:16:24 +0700
commit83f1d660ce1a1520b7a7e781d05c47221067f3f7 (patch)
treec86ce99d5ce7feb84669c9d390eb80cf29590076 /tinyusb/device
parentd1ef89a1543581d1703ea43b0056b5112fd64019 (diff)
clean up
add some doxygen work finalize device disconnection & suspend - suspend & resume & remote wake up is not supported yet
Diffstat (limited to 'tinyusb/device')
-rw-r--r--tinyusb/device/dcd_lpc175x_6x.c15
-rw-r--r--tinyusb/device/dcd_lpc175x_6x.h14
-rw-r--r--tinyusb/device/dcd_lpc43xx.c28
-rw-r--r--tinyusb/device/dcd_lpc_11uxx_13uxx.c44
-rw-r--r--tinyusb/device/usbd.h1
-rw-r--r--tinyusb/device/usbd_dcd.h3
6 files changed, 73 insertions, 32 deletions
diff --git a/tinyusb/device/dcd_lpc175x_6x.c b/tinyusb/device/dcd_lpc175x_6x.c
index d755b94ee..bb6410e02 100644
--- a/tinyusb/device/dcd_lpc175x_6x.c
+++ b/tinyusb/device/dcd_lpc175x_6x.c
@@ -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);
+// }
}
}
diff --git a/tinyusb/device/dcd_lpc175x_6x.h b/tinyusb/device/dcd_lpc175x_6x.h
index f66438702..3da20bf27 100644
--- a/tinyusb/device/dcd_lpc175x_6x.h
+++ b/tinyusb/device/dcd_lpc175x_6x.h
@@ -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_ */
/** @} */
+/** @} */
+
diff --git a/tinyusb/device/dcd_lpc43xx.c b/tinyusb/device/dcd_lpc43xx.c
index fe55273c4..d28b95600 100644
--- a/tinyusb/device/dcd_lpc43xx.c
+++ b/tinyusb/device/dcd_lpc43xx.c
@@ -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 -------------//
diff --git a/tinyusb/device/dcd_lpc_11uxx_13uxx.c b/tinyusb/device/dcd_lpc_11uxx_13uxx.c
index bb7409d21..209462ef9 100644
--- a/tinyusb/device/dcd_lpc_11uxx_13uxx.c
+++ b/tinyusb/device/dcd_lpc_11uxx_13uxx.c
@@ -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 -------------//
diff --git a/tinyusb/device/usbd.h b/tinyusb/device/usbd.h
index d9b74c788..6128f506d 100644
--- a/tinyusb/device/usbd.h
+++ b/tinyusb/device/usbd.h
@@ -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
diff --git a/tinyusb/device/usbd_dcd.h b/tinyusb/device/usbd_dcd.h
index 8fbcc317c..c427fb8c4 100644
--- a/tinyusb/device/usbd_dcd.h
+++ b/tinyusb/device/usbd_dcd.h
@@ -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 {