replace tusbh_cdc_isr by tusbh_cdc_xfer_isr with extra parameter as

- pipe id
- xferred_bytes

host_class_driver_t add xferred_bytes parameter
void (* const isr) (pipe_handle_t, tusb_event_t); -->   void (* const isr) (pipe_handle_t, tusb_event_t, uint32_t);

update hid_host & its tests
This commit is contained in:
hathach 2013-07-03 11:36:08 +07:00
parent b3f98bc15a
commit 1667ef5041
10 changed files with 26 additions and 13 deletions

View File

@ -70,7 +70,7 @@ void tusbh_cdc_unmounted_isr(uint8_t dev_addr)
// application tear-down
}
void tusbh_cdc_isr(uint8_t dev_addr, tusb_event_t event)
void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes)
{
switch(event)
{
@ -83,7 +83,9 @@ void tusbh_cdc_isr(uint8_t dev_addr, tusb_event_t event)
tusbh_cdc_receive(dev_addr, buffer_in, sizeof(buffer_in), true); // ignore & continue
break;
case TUSB_EVENT_XFER_STALLED:
default :
ASSERT(false, (void) 0); // error
break;
}
}

View File

@ -52,6 +52,7 @@
#include "mouse_app.h"
#include "keyboard_app.h"
#include "cdc_serial_app.h"
#if defined(__CODE_RED)
#include <cr_section_macros.h>

View File

@ -215,7 +215,7 @@ void test_keyboard_isr_event_complete(void)
tusbh_hid_keyboard_isr_Expect(dev_addr, TUSB_EVENT_XFER_COMPLETE);
//------------- Code Under TEST -------------//
hidh_isr(p_hidh_kbd->pipe_hdl, TUSB_EVENT_XFER_COMPLETE);
hidh_isr(p_hidh_kbd->pipe_hdl, TUSB_EVENT_XFER_COMPLETE, 8);
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_COMPLETE, tusbh_hid_keyboard_status(dev_addr));

View File

@ -205,7 +205,7 @@ void test_mouse_isr_event_xfer_complete(void)
tusbh_hid_mouse_isr_Expect(dev_addr, TUSB_EVENT_XFER_COMPLETE);
//------------- Code Under TEST -------------//
hidh_isr(p_hidh_mouse->pipe_hdl, TUSB_EVENT_XFER_COMPLETE);
hidh_isr(p_hidh_mouse->pipe_hdl, TUSB_EVENT_XFER_COMPLETE, 8);
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_COMPLETE, tusbh_hid_mouse_status(dev_addr));
@ -216,7 +216,7 @@ void test_mouse_isr_event_xfer_error(void)
tusbh_hid_mouse_isr_Expect(dev_addr, TUSB_EVENT_XFER_ERROR);
//------------- Code Under TEST -------------//
hidh_isr(p_hidh_mouse->pipe_hdl, TUSB_EVENT_XFER_ERROR);
hidh_isr(p_hidh_mouse->pipe_hdl, TUSB_EVENT_XFER_ERROR, 0);
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_ERROR, tusbh_hid_mouse_status(dev_addr));

View File

@ -63,6 +63,16 @@ STATIC_ INLINE_ bool tusbh_cdc_is_mounted(uint8_t dev_addr)
return (tusbh_device_get_mounted_class_flag(dev_addr) & BIT_(TUSB_CLASS_CDC)) != 0;
}
static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl) ATTR_PURE ATTR_ALWAYS_INLINE;
static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl)
{
cdch_data_t const * p_cdc = cdch_data + (pipe_hdl.dev_addr-1);
return pipehandle_is_equal( pipe_hdl, p_cdc->pipe_notification ) ? CDC_PIPE_NOTIFICATION :
pipehandle_is_equal( pipe_hdl, p_cdc->pipe_in ) ? CDC_PIPE_DATA_IN :
pipehandle_is_equal( pipe_hdl, p_cdc->pipe_out ) ? CDC_PIPE_DATA_OUT : 0;
}
//--------------------------------------------------------------------+
// APPLICATION API (parameter validation needed)
//--------------------------------------------------------------------+
@ -186,11 +196,11 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
return TUSB_ERROR_NONE;
}
void cdch_isr(pipe_handle_t pipe_hdl, tusb_event_t event)
void cdch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes)
{
if (tusbh_cdc_isr)
if (tusbh_cdc_xfer_isr)
{
tusbh_cdc_isr(pipe_hdl.dev_addr, event);
tusbh_cdc_xfer_isr( pipe_hdl.dev_addr, event, get_app_pipeid(pipe_hdl), xferred_bytes );
}
}

View File

@ -72,7 +72,7 @@ tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t lengt
void tusbh_cdc_mounted_isr(uint8_t dev_addr) ATTR_WEAK;
void tusbh_cdc_unmounted_isr(uint8_t dev_addr) ATTR_WEAK;
void tusbh_cdc_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK;
void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK;
void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes) ATTR_WEAK;
//--------------------------------------------------------------------+
// USBH-CLASS API
//--------------------------------------------------------------------+
@ -91,7 +91,7 @@ extern cdch_data_t cdch_data[TUSB_CFG_HOST_DEVICE_MAX]; // TODO consider to move
void cdch_init(void);
tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
void cdch_isr(pipe_handle_t pipe_hdl, tusb_event_t event);
void cdch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes);
void cdch_close(uint8_t dev_addr);
#endif

View File

@ -288,7 +288,7 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
OSAL_SUBTASK_END
}
void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event)
void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes)
{
#if TUSB_CFG_HOST_HID_KEYBOARD
if ( pipehandle_is_equal(pipe_hdl, keyboard_data[pipe_hdl.dev_addr-1].pipe_hdl) )

View File

@ -99,7 +99,7 @@ typedef struct {
void hidh_init(void);
tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event);
void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes);
void hidh_close(uint8_t dev_addr);
#endif

View File

@ -245,7 +245,7 @@ void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t even
osal_semaphore_post( usbh_devices[ pipe_hdl.dev_addr ].control.sem_hdl );
}else if (usbh_class_drivers[class_index].isr)
{
usbh_class_drivers[class_index].isr(pipe_hdl, event);
usbh_class_drivers[class_index].isr(pipe_hdl, event, xferred_bytes);
}else
{
ASSERT(false, (void) 0); // something wrong, no one claims the isr's source

View File

@ -76,7 +76,7 @@ typedef enum tusb_interface_status_{
typedef struct {
void (* const init) (void);
tusb_error_t (* const open_subtask)(uint8_t, tusb_descriptor_interface_t const *, uint16_t*);
void (* const isr) (pipe_handle_t, tusb_event_t);
void (* const isr) (pipe_handle_t, tusb_event_t, uint32_t);
void (* const close) (uint8_t);
} host_class_driver_t;
//--------------------------------------------------------------------+