summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-10-31 08:29:11 +0700
committerGitHub <[email protected]>2019-10-31 08:29:11 +0700
commit4d329d46cc36a8df05580ea7b19f2ce7a8dc2bf7 (patch)
tree089b0b4e162aa02b326f4283b91fa895597c6ef4 /src
parent78523301bb7f6ae5bba18768ad670d9b2ae73fd7 (diff)
parente69d2a4a834b975f957fc5341fe4d08cf706adb6 (diff)
Merge pull request #206 from hathach/develop
Added a couple of unit testing with Ceedling/Cmock/Unity
Diffstat (limited to 'src')
-rw-r--r--src/device/dcd.h49
-rw-r--r--src/device/usbd.c30
-rw-r--r--src/device/usbd.h3
-rw-r--r--src/device/usbd_pvt.h2
-rw-r--r--src/tusb.c2
5 files changed, 45 insertions, 41 deletions
diff --git a/src/device/dcd.h b/src/device/dcd.h
index c417ee4be..9fa98c669 100644
--- a/src/device/dcd.h
+++ b/src/device/dcd.h
@@ -79,7 +79,7 @@ typedef struct TU_ATTR_ALIGNED(4)
};
} dcd_event_t;
-TU_VERIFY_STATIC(sizeof(dcd_event_t) <= 12, "size is not correct");
+//TU_VERIFY_STATIC(sizeof(dcd_event_t) <= 12, "size is not correct");
/*------------------------------------------------------------------*/
/* Device API
@@ -119,20 +119,51 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr);
// clear stall, data toggle is also reset to DATA0
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr);
-/*------------------------------------------------------------------*/
-/* Event Function
- * Called by DCD to notify device stack
- *------------------------------------------------------------------*/
-void dcd_event_handler(dcd_event_t const * event, bool in_isr);
+//--------------------------------------------------------------------+
+// Event API
+//--------------------------------------------------------------------+
+
+// Called by DCD to notify device stack
+extern void dcd_event_handler(dcd_event_t const * event, bool in_isr);
// helper to send bus signal event
-void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr);
+static inline void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr);
// helper to send setup received
-void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr);
+static inline void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr);
// helper to send transfer complete event
-void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr);
+static inline void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr);
+
+
+//--------------------------------------------------------------------+
+// Inline helper
+//--------------------------------------------------------------------+
+
+static inline void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr)
+{
+ dcd_event_t event = { .rhport = rhport, .event_id = eid, };
+ dcd_event_handler(&event, in_isr);
+}
+
+static inline void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr)
+{
+ dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_SETUP_RECEIVED };
+ memcpy(&event.setup_received, setup, 8);
+
+ dcd_event_handler(&event, in_isr);
+}
+
+static inline void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr)
+{
+ dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_XFER_COMPLETE };
+
+ event.xfer_complete.ep_addr = ep_addr;
+ event.xfer_complete.len = xferred_bytes;
+ event.xfer_complete.result = result;
+
+ dcd_event_handler(&event, in_isr);
+}
#ifdef __cplusplus
}
diff --git a/src/device/usbd.c b/src/device/usbd.c
index f53b1d691..46affdab4 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -290,7 +290,7 @@ bool tud_remote_wakeup(void)
//--------------------------------------------------------------------+
// USBD Task
//--------------------------------------------------------------------+
-bool usbd_init (void)
+bool tud_init (void)
{
TU_LOG2("USBD init\r\n");
@@ -884,34 +884,6 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr)
}
}
-// helper to send bus signal event
-void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr)
-{
- dcd_event_t event = { .rhport = rhport, .event_id = eid, };
- dcd_event_handler(&event, in_isr);
-}
-
-// helper to send setup received
-void dcd_event_setup_received(uint8_t rhport, uint8_t const * setup, bool in_isr)
-{
- dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_SETUP_RECEIVED };
- memcpy(&event.setup_received, setup, 8);
-
- dcd_event_handler(&event, in_isr);
-}
-
-// helper to send transfer complete event
-void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr)
-{
- dcd_event_t event = { .rhport = rhport, .event_id = DCD_EVENT_XFER_COMPLETE };
-
- event.xfer_complete.ep_addr = ep_addr;
- event.xfer_complete.len = xferred_bytes;
- event.xfer_complete.result = result;
-
- dcd_event_handler(&event, in_isr);
-}
-
//--------------------------------------------------------------------+
// Helper
//--------------------------------------------------------------------+
diff --git a/src/device/usbd.h b/src/device/usbd.h
index 0ad126e94..b3665d7f2 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -41,6 +41,9 @@
// Application API
//--------------------------------------------------------------------+
+// Init device stack
+bool tud_init (void);
+
// Task function should be called in main/rtos loop
void tud_task (void);
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h
index 892680142..b9947044b 100644
--- a/src/device/usbd_pvt.h
+++ b/src/device/usbd_pvt.h
@@ -33,8 +33,6 @@
extern "C" {
#endif
-bool usbd_init (void);
-
//--------------------------------------------------------------------+
// USBD Endpoint API
//--------------------------------------------------------------------+
diff --git a/src/tusb.c b/src/tusb.c
index 271b35f1e..7a1e73ec7 100644
--- a/src/tusb.c
+++ b/src/tusb.c
@@ -47,7 +47,7 @@ bool tusb_init(void)
#endif
#if TUSB_OPT_DEVICE_ENABLED
- TU_ASSERT ( usbd_init() ); // init device stack
+ TU_ASSERT ( tud_init() ); // init device stack
#endif
_initialized = true;