summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-02-04 20:54:52 +0700
committerhathach <[email protected]>2013-02-04 20:54:52 +0700
commit93269b034396673062ec79e69673e95d47f29438 (patch)
tree65c28d1881bebd59240ad4a50ec2432df27c085f
parentf88e9d045d70f4fbee24d92963cf39118deb7df9 (diff)
fix osal_semaphore_wait & osal_queue_receive of osal_none's bug
- not assign error to TUSB_ERROR_NON if succeed add code up to set device address for enumeration
-rw-r--r--tests/test/host/test_usbh.c37
-rw-r--r--tests/test/test_osal_freeRTOS.c4
-rw-r--r--tinyusb/host/usbh.c35
-rw-r--r--tinyusb/osal/osal_none.h5
4 files changed, 59 insertions, 22 deletions
diff --git a/tests/test/host/test_usbh.c b/tests/test/host/test_usbh.c
index 8f4d84be4..02177122e 100644
--- a/tests/test/host/test_usbh.c
+++ b/tests/test/host/test_usbh.c
@@ -126,6 +126,7 @@ usbh_enumerate_t enum_connect =
.hub_port = 0,
.connect_status = 1
};
+extern usbh_device_addr0_t device_addr0;
void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call)
{
@@ -134,6 +135,11 @@ void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uin
(*p_error) = TUSB_ERROR_NONE;
}
+void semaphore_wait_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call)
+{
+ (*p_error) = TUSB_ERROR_NONE;
+}
+
tusb_error_t pipe_control_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t * const p_request, uint8_t data[], int num_call)
{
tusb_descriptor_device_t dev_desc =
@@ -158,18 +164,24 @@ tusb_error_t pipe_control_stub(pipe_handle_t pipe_hdl, const tusb_std_request_t
.bNumConfigurations = 0x02
};
- if (p_request->bRequest == TUSB_REQUEST_GET_DESCRIPTOR)
+ switch (p_request->bRequest)
{
- switch (p_request->wValue >> 8)
- {
- case TUSB_DESC_DEVICE:
- memcpy(data, &dev_desc, p_request->wLength);
- break;
+ case TUSB_REQUEST_GET_DESCRIPTOR:
+ switch (p_request->wValue >> 8)
+ {
+ case TUSB_DESC_DEVICE:
+ memcpy(data, &dev_desc, p_request->wLength);
+ break;
- default:
- TEST_FAIL();
- break;
- }
+ default:
+ TEST_FAIL();
+ break;
+ }
+ break;
+
+ case TUSB_REQUEST_SET_ADDRESS:
+ TEST_ASSERT_EQUAL(p_request->wValue, 1);
+ break;
}
return TUSB_ERROR_NONE;
@@ -185,7 +197,10 @@ void test_enum_task_connect(void)
hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE);
hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub);
-// hcd_pipe_control_open_ExpectAnd(1, );
+ osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
+
+ hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub);
+ osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
usbh_enumeration_task();
}
diff --git a/tests/test/test_osal_freeRTOS.c b/tests/test/test_osal_freeRTOS.c
index ddb6b63f2..437ba130c 100644
--- a/tests/test/test_osal_freeRTOS.c
+++ b/tests/test/test_osal_freeRTOS.c
@@ -57,8 +57,8 @@ osal_queue_handle_t queue_hdl;
void setUp(void)
{
memset(statements, 0, sizeof(statements));
- sem_hdl = osal_semaphore_create(OSAL_SEM_REF(sem));
- queue_hdl = osal_queue_create(&queue);
+// sem_hdl = osal_semaphore_create(OSAL_SEM_REF(sem));
+// queue_hdl = osal_queue_create(&queue);
}
void tearDown(void)
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c
index 38d96597d..f60299a06 100644
--- a/tinyusb/host/usbh.c
+++ b/tinyusb/host/usbh.c
@@ -98,19 +98,38 @@ void usbh_enumeration_task(void)
{
tusb_std_request_t request_device_desc =
{
- .bmRequestType =
- {
- .direction = TUSB_DIR_DEV_TO_HOST,
- .type = TUSB_REQUEST_TYPE_STANDARD,
- .recipient = TUSB_REQUEST_RECIPIENT_DEVICE
- },
-
+ .bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
.bRequest = TUSB_REQUEST_GET_DESCRIPTOR,
.wValue = (TUSB_DESC_DEVICE << 8),
.wLength = 8
};
+
hcd_pipe_control_xfer(device_addr0.pipe_hdl, &request_device_desc, enum_data_buffer);
-// osal_sem_wait();
+ osal_semaphore_wait(device_addr0.sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
+ TASK_ASSERT_STATUS(error);
+ }
+
+ {
+ uint8_t new_addr = 0;
+ for (new_addr=0; new_addr<TUSB_CFG_HOST_DEVICE_MAX; new_addr++)
+ {
+ if (device_info_pool[new_addr].status == TUSB_DEVICE_STATUS_UNPLUG)
+ break;
+ }
+
+ TASK_ASSERT(new_addr < TUSB_CFG_HOST_DEVICE_MAX);
+
+ tusb_std_request_t request_set_address =
+ {
+ .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
+ .bRequest = TUSB_REQUEST_SET_ADDRESS,
+ .wValue = (new_addr+1),
+ .wLength = 8
+ };
+
+ hcd_pipe_control_xfer(device_addr0.pipe_hdl, &request_set_address, NULL);
+ osal_semaphore_wait(device_addr0.sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
+ TASK_ASSERT_STATUS(error);
}
diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h
index fafaadc3f..93f77d593 100644
--- a/tinyusb/osal/osal_none.h
+++ b/tinyusb/osal/osal_none.h
@@ -133,8 +133,10 @@ static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const se
*(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\
else\
return;\
- } else\
+ } else{\
(*(sem_hdl))--; /*TODO mutex hal_interrupt_disable consideration*/\
+ *(p_error) = TUSB_ERROR_NONE;\
+ }\
}while(0)
//--------------------------------------------------------------------+
@@ -202,6 +204,7 @@ static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl,
queue_hdl->rd_idx = (queue_hdl->rd_idx + 1) % queue_hdl->depth;\
queue_hdl->count--;\
/*TODO mutex unlock hal_interrupt_enable */\
+ *(p_error) = TUSB_ERROR_NONE;\
}\
}while(0)