summaryrefslogtreecommitdiff
path: root/src/host
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-12-13 15:28:04 +0700
committerGitHub <[email protected]>2018-12-13 15:28:04 +0700
commit27208ad2fdbd7af5080531eafd9a1a20515cedc1 (patch)
tree6869937edf3afe3182665c329343e6a55b99ba59 /src/host
parentb562fa741b5a8bb47d4e32c0a0f2600b72993b9a (diff)
parentedf885ca465e16d74833a4866951ca9aa7d4326c (diff)
Merge pull request #25 from hathach/devlocal
remove OSAL_TASK_DEF, osal_task_create
Diffstat (limited to 'src/host')
-rw-r--r--src/host/usbh.c58
-rw-r--r--src/host/usbh.h9
2 files changed, 28 insertions, 39 deletions
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 39de4f7e7..d0b5edb63 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -46,15 +46,6 @@
#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
//--------------------------------------------------------------------+
@@ -123,9 +114,9 @@ enum { USBH_CLASS_DRIVER_COUNT = TU_ARRAY_SZIE(usbh_class_drivers) };
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address
-OSAL_TASK_DEF(_usbh_task_def, "usbh", usbh_task, CFG_TUH_TASK_PRIO, CFG_TUH_TASK_STACK_SZ);
+// including zero-address
+CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
// Event queue
// role device/host is used by OS NONE for mutex (disable usb isr) only
@@ -161,8 +152,6 @@ bool usbh_init(void)
_usbh_q = osal_queue_create( &_usbh_qdef );
TU_ASSERT(_usbh_q != NULL);
- 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
{
@@ -610,12 +599,32 @@ bool enum_task(hcd_event_t* event)
return true;
}
-bool usbh_task_body(void)
+/* USB Host Driver task
+ * This top level thread manages all host controller event and delegates events to class-specific drivers.
+ * This should be called periodically within the mainloop or rtos thread.
+ *
+ @code
+ int main(void)
+ {
+ application_init();
+ tusb_init();
+
+ while(1) // the mainloop
+ {
+ application_code();
+
+ tuh_task(); // tinyusb host task
+ }
+ }
+ @endcode
+ */
+void tuh_task(void)
{
+ // Loop until there is no more events in the queue
while (1)
{
hcd_event_t event;
- if ( !osal_queue_receive(_usbh_q, &event) ) return false;
+ if ( !osal_queue_receive(_usbh_q, &event) ) return;
switch (event.event_id)
{
@@ -629,25 +638,6 @@ bool usbh_task_body(void)
}
}
-/* 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
-}
-
//--------------------------------------------------------------------+
// INTERNAL HELPER
//--------------------------------------------------------------------+
diff --git a/src/host/usbh.h b/src/host/usbh.h
index 3656b9a0d..fee1235f4 100644
--- a/src/host/usbh.h
+++ b/src/host/usbh.h
@@ -78,9 +78,9 @@ typedef struct {
//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
-//tusb_error_t tusbh_configuration_set (uint8_t dev_addr, uint8_t configure_number) ATTR_WARN_UNUSED_RESULT;
-tusb_device_state_t tuh_device_get_state (uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT ATTR_PURE;
-static inline bool tuh_device_is_configured(uint8_t dev_addr) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_PURE;
+void tuh_task(void);
+
+tusb_device_state_t tuh_device_get_state (uint8_t dev_addr);
static inline bool tuh_device_is_configured(uint8_t dev_addr)
{
return tuh_device_get_state(dev_addr) == TUSB_DEVICE_STATE_CONFIGURED;
@@ -89,7 +89,7 @@ static inline bool tuh_device_is_configured(uint8_t dev_addr)
//--------------------------------------------------------------------+
// APPLICATION CALLBACK
//--------------------------------------------------------------------+
-ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device) ATTR_WARN_UNUSED_RESULT;
+ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device);
/** Callback invoked when device is mounted (configured) */
ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr);
@@ -103,7 +103,6 @@ ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr);
#ifdef _TINY_USB_SOURCE_FILE_
bool usbh_init(void);
-void usbh_task(void* param);
bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8_t* data);