Merge pull request #206 from hathach/develop
Added a couple of unit testing with Ceedling/Cmock/Unity
This commit is contained in:
		| @@ -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 | ||||
|  } | ||||
|   | ||||
| @@ -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 | ||||
| //--------------------------------------------------------------------+ | ||||
|   | ||||
| @@ -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); | ||||
|  | ||||
|   | ||||
| @@ -33,8 +33,6 @@ | ||||
|  extern "C" { | ||||
| #endif | ||||
|  | ||||
| bool usbd_init (void); | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // USBD Endpoint API | ||||
| //--------------------------------------------------------------------+ | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach