mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-21 21:41:09 +00:00
temporarily check cdc mounted by pipe_in & pipe_out
add tests for tusbh_cdc_xfer_isr
This commit is contained in:
parent
294ddd0acc
commit
b0f45b3651
@ -116,7 +116,9 @@ OSAL_TASK_FUNCTION( cdc_serial_app_task ) (void* p_task_para)
|
||||
osal_queue_receive(queue_hdl, &c, OSAL_TIMEOUT_WAIT_FOREVER, &error);
|
||||
|
||||
if (c)
|
||||
{
|
||||
printf("%c", c);
|
||||
}
|
||||
|
||||
OSAL_TASK_LOOP_END
|
||||
}
|
||||
|
68
tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h
Normal file
68
tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h
Normal file
@ -0,0 +1,68 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file cdc_callback.h
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This file is part of the tinyusb stack.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
/** \ingroup TBD
|
||||
* \defgroup TBD
|
||||
* \brief TBD
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_CDC_CALLBACK_H_
|
||||
#define _TUSB_CDC_CALLBACK_H_
|
||||
|
||||
#include "common/common.h"
|
||||
#include "cdc_host.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void tusbh_cdc_mounted_isr(uint8_t dev_addr);
|
||||
void tusbh_cdc_unmounted_isr(uint8_t dev_addr);
|
||||
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);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_CDC_CALLBACK_H_ */
|
||||
|
||||
/** @} */
|
@ -46,6 +46,7 @@
|
||||
#include "mock_osal.h"
|
||||
#include "mock_hcd.h"
|
||||
#include "mock_usbh.h"
|
||||
#include "mock_cdc_callback.h"
|
||||
|
||||
#include "descriptor_cdc.h"
|
||||
#include "cdc_host.h"
|
||||
@ -74,7 +75,9 @@ void tearDown(void)
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// OPEN
|
||||
//--------------------------------------------------------------------+
|
||||
void test_cdch_open_failed_to_open_notification_endpoint(void)
|
||||
{
|
||||
pipe_handle_t null_hdl = {0};
|
||||
@ -125,6 +128,7 @@ void test_cdch_open_length_check(void)
|
||||
|
||||
pipe_handle_t dummy_hld = { .dev_addr = 1 };
|
||||
hcd_pipe_open_IgnoreAndReturn(dummy_hld);
|
||||
tusbh_cdc_mounted_isr_Expect(dev_addr);
|
||||
|
||||
//------------- CUT -------------//
|
||||
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) );
|
||||
@ -136,6 +140,7 @@ void test_cdch_open_interface_number_check(void)
|
||||
{
|
||||
pipe_handle_t dummy_hld = { .dev_addr = 1 };
|
||||
hcd_pipe_open_IgnoreAndReturn(dummy_hld);
|
||||
tusbh_cdc_mounted_isr_Expect(dev_addr);
|
||||
|
||||
//------------- CUT -------------//
|
||||
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) );
|
||||
@ -148,6 +153,7 @@ void test_cdch_open_acm_capacity_check(void)
|
||||
{
|
||||
pipe_handle_t dummy_hld = { .dev_addr = 1 };
|
||||
hcd_pipe_open_IgnoreAndReturn(dummy_hld);
|
||||
tusbh_cdc_mounted_isr_Expect(dev_addr);
|
||||
|
||||
//------------- CUT -------------//
|
||||
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) );
|
||||
@ -155,28 +161,19 @@ void test_cdch_open_acm_capacity_check(void)
|
||||
TEST_ASSERT_EQUAL_MEMORY(&cdc_config_descriptor.cdc_acm.bmCapabilities, &p_cdc->acm_capability, 1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CLOSE
|
||||
//--------------------------------------------------------------------+
|
||||
void test_cdch_close_device(void)
|
||||
{
|
||||
pipe_handle_t pipe_notification = {
|
||||
.dev_addr = 1,
|
||||
.xfer_type = TUSB_XFER_INTERRUPT
|
||||
};
|
||||
|
||||
pipe_handle_t pipe_out = {
|
||||
.dev_addr = 1,
|
||||
.xfer_type = TUSB_XFER_BULK,
|
||||
.index = 0
|
||||
};
|
||||
|
||||
pipe_handle_t pipe_int = {
|
||||
.dev_addr = 1,
|
||||
.xfer_type = TUSB_XFER_BULK,
|
||||
.index = 1
|
||||
};
|
||||
pipe_handle_t pipe_notification = { .dev_addr = 1, .xfer_type = TUSB_XFER_INTERRUPT };
|
||||
pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 };
|
||||
pipe_handle_t pipe_int = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 };
|
||||
|
||||
hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification);
|
||||
hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out);
|
||||
hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_int);
|
||||
tusbh_cdc_mounted_isr_Expect(dev_addr);
|
||||
|
||||
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open_subtask(dev_addr, p_comm_interface, &length) );
|
||||
|
||||
@ -184,10 +181,15 @@ void test_cdch_close_device(void)
|
||||
hcd_pipe_close_ExpectAndReturn(pipe_int , TUSB_ERROR_NONE);
|
||||
hcd_pipe_close_ExpectAndReturn(pipe_out , TUSB_ERROR_NONE);
|
||||
|
||||
tusbh_cdc_unmounted_isr_Expect(dev_addr);
|
||||
|
||||
//------------- CUT -------------//
|
||||
cdch_close(dev_addr);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CHECKING API
|
||||
//--------------------------------------------------------------------+
|
||||
void test_cdc_serial_is_mounted_not_configured(void)
|
||||
{
|
||||
tusbh_device_get_mounted_class_flag_ExpectAndReturn(dev_addr, 0);
|
||||
@ -219,4 +221,53 @@ void test_cdc_serial_is_mounted_protocol_is_at_command(void)
|
||||
TEST_ASSERT( tusbh_cdc_serial_is_mounted(dev_addr) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// TRANSFER API
|
||||
//--------------------------------------------------------------------+
|
||||
void test_cdc_xfer_notification_pipe(void)
|
||||
{
|
||||
pipe_handle_t pipe_notification = { .dev_addr = 1, .xfer_type = TUSB_XFER_INTERRUPT };
|
||||
pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 };
|
||||
pipe_handle_t pipe_in = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 };
|
||||
|
||||
cdch_data[dev_addr-1].pipe_notification = pipe_notification;
|
||||
cdch_data[dev_addr-1].pipe_out = pipe_out;
|
||||
cdch_data[dev_addr-1].pipe_in = pipe_in;
|
||||
|
||||
tusbh_cdc_xfer_isr_Expect(dev_addr, TUSB_EVENT_XFER_COMPLETE, CDC_PIPE_NOTIFICATION, 10);
|
||||
|
||||
//------------- CUT -------------//
|
||||
cdch_isr(pipe_notification, TUSB_EVENT_XFER_COMPLETE, 10);
|
||||
}
|
||||
|
||||
void test_cdc_xfer_pipe_out(void)
|
||||
{
|
||||
pipe_handle_t pipe_notification = { .dev_addr = 1, .xfer_type = TUSB_XFER_INTERRUPT };
|
||||
pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 };
|
||||
pipe_handle_t pipe_in = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 };
|
||||
|
||||
cdch_data[dev_addr-1].pipe_notification = pipe_notification;
|
||||
cdch_data[dev_addr-1].pipe_out = pipe_out;
|
||||
cdch_data[dev_addr-1].pipe_in = pipe_in;
|
||||
|
||||
tusbh_cdc_xfer_isr_Expect(dev_addr, TUSB_EVENT_XFER_ERROR, CDC_PIPE_DATA_OUT, 20);
|
||||
|
||||
//------------- CUT -------------//
|
||||
cdch_isr(pipe_out, TUSB_EVENT_XFER_ERROR, 20);
|
||||
}
|
||||
|
||||
void test_cdc_xfer_pipe_in(void)
|
||||
{
|
||||
pipe_handle_t pipe_notification = { .dev_addr = 1, .xfer_type = TUSB_XFER_INTERRUPT };
|
||||
pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 };
|
||||
pipe_handle_t pipe_in = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 };
|
||||
|
||||
cdch_data[dev_addr-1].pipe_notification = pipe_notification;
|
||||
cdch_data[dev_addr-1].pipe_out = pipe_out;
|
||||
cdch_data[dev_addr-1].pipe_in = pipe_in;
|
||||
|
||||
tusbh_cdc_xfer_isr_Expect(dev_addr, TUSB_EVENT_XFER_STALLED, CDC_PIPE_DATA_IN, 0);
|
||||
|
||||
//------------- CUT -------------//
|
||||
cdch_isr(pipe_in, TUSB_EVENT_XFER_STALLED, 0);
|
||||
}
|
||||
|
@ -60,7 +60,13 @@
|
||||
STATIC_ INLINE_ bool tusbh_cdc_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
|
||||
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;
|
||||
// FIXME cannot use mounted class flag as at the point _open_sublass is called, the flag is not set yet
|
||||
#ifdef _TEST_
|
||||
return (tusbh_device_get_mounted_class_flag(dev_addr) & BIT_(TUSB_CLASS_CDC)) != 0;
|
||||
#else
|
||||
return pipehandle_is_valid(cdch_data[dev_addr-1].pipe_in) &&
|
||||
pipehandle_is_valid(cdch_data[dev_addr-1].pipe_out);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl) ATTR_PURE ATTR_ALWAYS_INLINE;
|
||||
@ -86,7 +92,7 @@ bool tusbh_cdc_serial_is_mounted(uint8_t dev_addr)
|
||||
|
||||
tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify)
|
||||
{
|
||||
// FIXME disable temp ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED);
|
||||
ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED);
|
||||
ASSERT( p_data != NULL && length, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
pipe_handle_t pipe_out = cdch_data[dev_addr-1].pipe_out;
|
||||
@ -100,7 +106,7 @@ tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t leng
|
||||
|
||||
tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify)
|
||||
{
|
||||
// FIXME disable temp ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED);
|
||||
ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED);
|
||||
ASSERT( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
pipe_handle_t pipe_in = cdch_data[dev_addr-1].pipe_in;
|
||||
|
Loading…
x
Reference in New Issue
Block a user