summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-12-05 18:58:30 +0700
committerhathach <[email protected]>2018-12-05 20:26:55 +0700
commit4537ba66e536eb1d40c73f80ab150d92c2393397 (patch)
tree09e5b5d2b480462828d30f57451f5e102f18881c /src
parente0aa38ca8d2106aca9842b310640346f6a8ac562 (diff)
fixing build error with host stack
Diffstat (limited to 'src')
-rw-r--r--src/device/usbd.c2
-rw-r--r--src/host/ehci/ehci.c1
-rw-r--r--src/host/usbh.c117
-rw-r--r--src/host/usbh.h2
-rw-r--r--src/host/usbh_hcd.h3
-rw-r--r--src/osal/osal_freertos.h4
-rw-r--r--src/tusb.c9
7 files changed, 74 insertions, 64 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 78eebf76b..121ee3da9 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -298,7 +298,7 @@ static void usbd_task_body(void)
/* USB device task
* Thread that handles all device events. With an real RTOS, the task must be a forever loop and never return.
- * For codign convenience with no RTOS, we use wrapped sub-function for processing to easily return at any time.
+ * For coding convenience with no RTOS, we use wrapped sub-function for processing to easily return at any time.
*/
void usbd_task( void* param)
{
diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c
index 27808d59b..491651f5c 100644
--- a/src/host/ehci/ehci.c
+++ b/src/host/ehci/ehci.c
@@ -42,7 +42,6 @@
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
-#include "hal/hal.h"
#include "osal/osal.h"
#include "../hcd.h"
diff --git a/src/host/usbh.c b/src/host/usbh.c
index a0aab3b96..3bb90e71d 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -42,10 +42,19 @@
#define _TINY_USB_SOURCE_FILE_
-#ifndef CFG_TUD_TASK_PRIO
-#define CFG_TUD_TASK_PRIO 0
+#ifndef CFG_TUH_TASK_QUEUE_SZ
+#define CFG_TUH_TASK_QUEUE_SZ 16
#endif
+#ifndef CFG_TUH_TASK_STACK_SZ
+#define CFG_TUH_TASK_STACK_SZ 200
+#endif
+
+#ifndef CFG_TUH_TASK_PRIO
+#define CFG_TUH_TASK_PRIO 0
+#endif
+
+
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
@@ -111,10 +120,13 @@ enum { USBH_CLASS_DRIVER_COUNT = sizeof(usbh_class_drivers) / sizeof(host_class_
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address
-//------------- Enumeration Task Data -------------/
-enum { ENUM_QUEUE_DEPTH = 16 };
+OSAL_TASK_DEF(_usbh_task_def, "usbh", usbh_task, CFG_TUH_TASK_PRIO, CFG_TUH_TASK_STACK_SZ);
+
+// Event queue
+// role device/host is used by OS NONE for mutex (disable usb isr) only
+OSAL_QUEUE_DEF(OPT_MODE_HOST, _usbh_qdef, CFG_TUH_TASK_QUEUE_SZ, uint32_t);
+static osal_queue_t _usbh_q;
-STATIC_VAR osal_queue_t enum_queue_hdl;
CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) STATIC_VAR uint8_t enum_data_buffer[CFG_TUSB_HOST_ENUM_BUFFER_SIZE];
//------------- Reporter Task Data -------------//
@@ -144,23 +156,21 @@ tusb_error_t usbh_init(void)
{
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
- TU_ASSERT_ERR( hcd_init() );
-
//------------- Enumeration & Reporter Task init -------------//
- enum_queue_hdl = osal_queue_create( ENUM_QUEUE_DEPTH, sizeof(uint32_t) );
- TU_ASSERT(enum_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED);
+ _usbh_q = osal_queue_create( &_usbh_qdef );
+ TU_ASSERT(_usbh_q, TUSB_ERROR_OSAL_QUEUE_FAILED);
- osal_task_create(usbh_enumeration_task, "usbh", 200, NULL, CFG_TUD_TASK_PRIO);
+ osal_task_create(&_usbh_task_def);
//------------- Semaphore, Mutex for Control Pipe -------------//
for(uint8_t i=0; i<CFG_TUSB_HOST_DEVICE_MAX+1; i++) // including address zero
{
usbh_device_info_t * const p_device = &usbh_devices[i];
- p_device->control.sem_hdl = osal_semaphore_create(1, 0);
+ p_device->control.sem_hdl = osal_semaphore_create(&p_device->control.sem_def);
TU_ASSERT(p_device->control.sem_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED);
- p_device->control.mutex_hdl = osal_mutex_create();
+ p_device->control.mutex_hdl = osal_mutex_create(&p_device->control.mutex_def);
TU_ASSERT(p_device->control.mutex_hdl, TUSB_ERROR_OSAL_MUTEX_FAILED);
}
@@ -173,6 +183,8 @@ tusb_error_t usbh_init(void)
}
}
+ TU_ASSERT_ERR( hcd_init() );
+
return TUSB_ERROR_NONE;
}
@@ -181,12 +193,13 @@ tusb_error_t usbh_init(void)
tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType, uint8_t bRequest,
uint16_t wValue, uint16_t wIndex, uint16_t wLength, uint8_t* data)
{
- static tusb_error_t error; // FIXME [CMSIS-RTX] use svc for OS API, error value changed after mutex release at the end of function
+ // FIXME [CMSIS-RTX] use svc for OS API, error value changed after mutex release at the end of function
+ static tusb_error_t error;
- OSAL_SUBTASK_BEGIN
+// OSAL_SUBTASK_BEGIN
- osal_mutex_wait(usbh_devices[dev_addr].control.mutex_hdl, OSAL_TIMEOUT_NORMAL, &error);
- STASK_ASSERT_ERR_HDLR(error, osal_mutex_release(usbh_devices[dev_addr].control.mutex_hdl));
+ error = osal_mutex_lock(usbh_devices[dev_addr].control.mutex_hdl, OSAL_TIMEOUT_NORMAL);
+ STASK_ASSERT_ERR_HDLR(error, osal_mutex_unlock(usbh_devices[dev_addr].control.mutex_hdl));
usbh_devices[dev_addr].control.request = (tusb_control_request_t) {
{.bmRequestType = bmRequestType},
@@ -195,16 +208,11 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType,
.wIndex = wIndex,
.wLength = wLength
};
-
-#ifndef _TEST_
usbh_devices[dev_addr].control.pipe_status = 0;
-#else
- usbh_devices[dev_addr].control.pipe_status = XFER_RESULT_SUCCESS; // in Test project, mark as complete immediately
-#endif
error = hcd_pipe_control_xfer(dev_addr, &usbh_devices[dev_addr].control.request, data);
- if ( TUSB_ERROR_NONE == error ) osal_semaphore_wait(usbh_devices[dev_addr].control.sem_hdl, OSAL_TIMEOUT_NORMAL, &error);
- osal_mutex_release(usbh_devices[dev_addr].control.mutex_hdl);
+ if ( TUSB_ERROR_NONE == error ) error = osal_semaphore_wait(usbh_devices[dev_addr].control.sem_hdl, OSAL_TIMEOUT_NORMAL);
+ osal_mutex_unlock(usbh_devices[dev_addr].control.mutex_hdl);
STASK_ASSERT_ERR(error);
if (XFER_RESULT_STALLED == usbh_devices[dev_addr].control.pipe_status) STASK_RETURN(TUSB_ERROR_USBH_XFER_STALLED);
@@ -214,10 +222,9 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType,
// XFER_RESULT_SUCCESS == usbh_devices[dev_addr].control.pipe_status,
// tuh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) );
- OSAL_SUBTASK_END
+// OSAL_SUBTASK_END
}
-tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) ATTR_ALWAYS_INLINE;
tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
{
osal_semaphore_reset( usbh_devices[dev_addr].control.sem_hdl );
@@ -228,7 +235,6 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
return TUSB_ERROR_NONE;
}
-static inline tusb_error_t usbh_pipe_control_close(uint8_t dev_addr) ATTR_ALWAYS_INLINE;
static inline tusb_error_t usbh_pipe_control_close(uint8_t dev_addr)
{
TU_ASSERT_ERR( hcd_pipe_control_close(dev_addr) );
@@ -263,13 +269,13 @@ void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, xfer_result_t eve
{
usbh_devices[ pipe_hdl.dev_addr ].control.pipe_status = event;
// usbh_devices[ pipe_hdl.dev_addr ].control.xferred_bytes = xferred_bytes; not yet neccessary
- osal_semaphore_post( usbh_devices[ pipe_hdl.dev_addr ].control.sem_hdl );
+ osal_semaphore_post( usbh_devices[ pipe_hdl.dev_addr ].control.sem_hdl, true );
}else if (usbh_class_drivers[class_index].isr)
{
usbh_class_drivers[class_index].isr(pipe_hdl, event, xferred_bytes);
}else
{
- TU_ASSERT(false); // something wrong, no one claims the isr's source
+ TU_ASSERT(false, ); // something wrong, no one claims the isr's source
}
}
@@ -282,7 +288,7 @@ void usbh_hub_port_plugged_isr(uint8_t hub_addr, uint8_t hub_port)
.hub_port = hub_port
};
- osal_queue_send(enum_queue_hdl, &enum_entry);
+ osal_queue_send(_usbh_q, &enum_entry, true);
}
void usbh_hcd_rhport_plugged_isr(uint8_t hostid)
@@ -294,7 +300,7 @@ void usbh_hcd_rhport_plugged_isr(uint8_t hostid)
.hub_port = 0
};
- osal_queue_send(enum_queue_hdl, &enum_entry);
+ osal_queue_send(_usbh_q, &enum_entry, true);
}
// a device unplugged on hostid, hub_addr, hub_port
@@ -346,33 +352,13 @@ void usbh_hcd_rhport_unplugged_isr(uint8_t hostid)
.hub_port = 0
};
- osal_queue_send(enum_queue_hdl, &enum_entry);
+ osal_queue_send(_usbh_q, &enum_entry, true);
}
//--------------------------------------------------------------------+
// ENUMERATION TASK
//--------------------------------------------------------------------+
-static tusb_error_t enumeration_body_subtask(void);
-
-// To enable the TASK_ASSERT style (quick return on false condition) in a real RTOS, a task must act as a wrapper
-// and is used mainly to call subtasks. Within a subtask return statement can be called freely, the task with
-// forever loop cannot have any return at all.
-void usbh_enumeration_task(void* param)
-{
- (void) param;
-
-#if CFG_TUSB_OS != OPT_OS_NONE
- while (1) {
-#endif
-
- enumeration_body_subtask();
-
-#if CFG_TUSB_OS != OPT_OS_NONE
- }
-#endif
-}
-
-tusb_error_t enumeration_body_subtask(void)
+tusb_error_t usbh_task_body(void)
{
enum {
POWER_STABLE_DELAY = 500,
@@ -387,10 +373,9 @@ tusb_error_t enumeration_body_subtask(void)
static uint8_t configure_selected = 1; // TODO move
static uint8_t *p_desc = NULL; // TODO move
- OSAL_SUBTASK_BEGIN
+// OSAL_SUBTASK_BEGIN
- osal_queue_receive(enum_queue_hdl, &enum_entry, OSAL_TIMEOUT_WAIT_FOREVER, &error);
- STASK_ASSERT_ERR(error);
+ if ( !osal_queue_receive(_usbh_q, &enum_entry) ) return;
usbh_devices[0].core_id = enum_entry.core_id; // TODO refractor integrate to device_pool
usbh_devices[0].hub_addr = enum_entry.hub_addr;
@@ -617,7 +602,27 @@ tusb_error_t enumeration_body_subtask(void)
tuh_device_mount_succeed_cb(new_addr);
- OSAL_SUBTASK_END
+// OSAL_SUBTASK_END
+}
+
+
+/* USB Host task
+ * Thread that handles all device events. With an real RTOS, the task must be a forever loop and never return.
+ * For coding convenience with no RTOS, we use wrapped sub-function for processing to easily return at any time.
+ */
+void usbh_task(void* param)
+{
+ (void) param;
+
+#if CFG_TUSB_OS != OPT_OS_NONE
+ while (1) {
+#endif
+
+ usbh_task_body();
+
+#if CFG_TUSB_OS != OPT_OS_NONE
+ }
+#endif
}
//--------------------------------------------------------------------+
diff --git a/src/host/usbh.h b/src/host/usbh.h
index 56efb6ff7..22c85a5d0 100644
--- a/src/host/usbh.h
+++ b/src/host/usbh.h
@@ -97,7 +97,7 @@ ATTR_WEAK void tuh_device_mount_failed_cb(tusb_error_t error, tusb_desc_devic
//--------------------------------------------------------------------+
#ifdef _TINY_USB_SOURCE_FILE_
-void usbh_enumeration_task(void* param);
+void usbh_task(void* param);
tusb_error_t usbh_init(void);
tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType, uint8_t bRequest,
diff --git a/src/host/usbh_hcd.h b/src/host/usbh_hcd.h
index f6b72273a..cd2a712e4 100644
--- a/src/host/usbh_hcd.h
+++ b/src/host/usbh_hcd.h
@@ -91,7 +91,10 @@ typedef struct {
// uint8_t xferred_bytes; TODO not yet necessary
tusb_control_request_t request;
+ osal_semaphore_def_t sem_def;
osal_semaphore_t sem_hdl; // used to synchronize with HCD when control xfer complete
+
+ osal_mutex_def_t mutex_def;
osal_mutex_t mutex_hdl; // used to exclusively occupy control pipe
} control;
} usbh_device_info_t;
diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h
index 704aafd64..458e54b5c 100644
--- a/src/osal/osal_freertos.h
+++ b/src/osal/osal_freertos.h
@@ -107,10 +107,10 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
return in_isr ? xSemaphoreGiveFromISR(sem_hdl, NULL) : xSemaphoreGive(sem_hdl);
}
-static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, uint32_t *err)
+static inline tusb_error_t osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec)
{
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec);
- (*err) = (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT);
+ return (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT);
}
static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl)
diff --git a/src/tusb.c b/src/tusb.c
index fe4dbb2c1..6d2b92dc8 100644
--- a/src/tusb.c
+++ b/src/tusb.c
@@ -39,14 +39,17 @@
#include "tusb_option.h"
#if TUSB_OPT_HOST_ENABLED || TUSB_OPT_DEVICE_ENABLED
-
#define _TINY_USB_SOURCE_FILE_
#include "tusb.h"
-#include "device/usbd_pvt.h"
static bool _initialized = false;
+// TODO clean up
+#if TUSB_OPT_DEVICE_ENABLED
+#include "device/usbd_pvt.h"
+#endif
+
bool tusb_init(void)
{
// skip if already initialized
@@ -69,7 +72,7 @@ bool tusb_init(void)
void tusb_task(void)
{
#if MODE_HOST_SUPPORTED
- usbh_enumeration_task(NULL);
+ usbh_task(NULL);
#endif
#if TUSB_OPT_DEVICE_ENABLED