summaryrefslogtreecommitdiff
path: root/src
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
parentb562fa741b5a8bb47d4e32c0a0f2600b72993b9a (diff)
parentedf885ca465e16d74833a4866951ca9aa7d4326c (diff)
Merge pull request #25 from hathach/devlocal
remove OSAL_TASK_DEF, osal_task_create
Diffstat (limited to 'src')
-rw-r--r--src/class/hid/hid_device.c2
-rw-r--r--src/class/hid/hid_host.c4
-rw-r--r--src/common/tusb_error.h33
-rw-r--r--src/common/tusb_fifo.c4
-rw-r--r--src/device/usbd.c60
-rw-r--r--src/device/usbd.h1
-rw-r--r--src/device/usbd_pvt.h2
-rw-r--r--src/host/usbh.c58
-rw-r--r--src/host/usbh.h9
-rw-r--r--src/osal/osal.h2
-rw-r--r--src/osal/osal_freertos.h21
-rw-r--r--src/osal/osal_mynewt.h21
-rw-r--r--src/osal/osal_none.h10
-rw-r--r--src/tusb.c14
-rw-r--r--src/tusb.h37
-rw-r--r--src/tusb_option.h5
16 files changed, 69 insertions, 214 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index bd49c157a..70aa7370d 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -340,7 +340,7 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
/*------------- Boot protocol only keyboard & mouse -------------*/
if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT)
{
- TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE, ERR_TUD_INVALID_DESCRIPTOR);
+ TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE);
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD)
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index 1e44055ec..b01cd9d59 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -238,12 +238,12 @@ bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac
#endif
{
- // TUSB_ERROR_HIDH_NOT_SUPPORTED_PROTOCOL
+ // Not supported protocol
return false;
}
}else
{
- // TUSB_ERROR_HIDH_NOT_SUPPORTED_SUBCLASS
+ // Not supported subclass
return false;
}
diff --git a/src/common/tusb_error.h b/src/common/tusb_error.h
index 677fc44e4..7e67dd0a0 100644
--- a/src/common/tusb_error.h
+++ b/src/common/tusb_error.h
@@ -57,44 +57,13 @@
ENTRY(TUSB_ERROR_INVALID_PARA )\
ENTRY(TUSB_ERROR_DEVICE_NOT_READY )\
ENTRY(TUSB_ERROR_INTERFACE_IS_BUSY )\
- ENTRY(TUSB_ERROR_HCD_FAILED )\
ENTRY(TUSB_ERROR_HCD_OPEN_PIPE_FAILED )\
- ENTRY(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND )\
- ENTRY(TUSB_ERROR_USBH_MOUNT_CONFIG_DESC_TOO_LONG )\
- ENTRY(TUSB_ERROR_USBH_DESCRIPTOR_CORRUPTED )\
- ENTRY(TUSB_ERROR_USBH_XFER_STALLED )\
- ENTRY(TUSB_ERROR_USBH_XFER_FAILED )\
ENTRY(TUSB_ERROR_OSAL_TIMEOUT )\
- ENTRY(TUSB_ERROR_OSAL_WAITING ) /* only used by OSAL_NONE in the subtask */ \
- ENTRY(TUSB_ERROR_OSAL_TASK_FAILED )\
- ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED )\
- ENTRY(TUSB_ERROR_OSAL_SEMAPHORE_FAILED )\
- ENTRY(TUSB_ERROR_OSAL_MUTEX_FAILED )\
- ENTRY(TUSB_ERROR_EHCI_NOT_ENOUGH_QTD )\
- ENTRY(TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE )\
- ENTRY(TUSB_ERROR_HIDH_NOT_SUPPORTED_PROTOCOL )\
- ENTRY(TUSB_ERROR_HIDH_NOT_SUPPORTED_SUBCLASS )\
- ENTRY(TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS )\
- ENTRY(TUSB_ERROR_CDC_UNSUPPORTED_PROTOCOL )\
ENTRY(TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED )\
- ENTRY(TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL )\
- ENTRY(TUSB_ERROR_MSCH_UNKNOWN_SCSI_COMMAND )\
ENTRY(TUSB_ERROR_MSCH_DEVICE_NOT_MOUNTED )\
- ENTRY(TUSB_ERROR_HUB_FEATURE_NOT_SUPPORTED )\
- ENTRY(TUSB_ERROR_DESCRIPTOR_CORRUPTED )\
- ENTRY(TUSB_ERROR_DCD_FAILED )\
- ENTRY(TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT )\
- ENTRY(TUSB_ERROR_DCD_NOT_ENOUGH_QTD )\
- ENTRY(TUSB_ERROR_DCD_OPEN_PIPE_FAILED )\
- ENTRY(TUSB_ERROR_DCD_EDPT_XFER )\
- ENTRY(TUSB_ERROR_NOT_SUPPORTED_YET )\
- ENTRY(TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED )\
+ ENTRY(TUSB_ERROR_NOT_SUPPORTED )\
ENTRY(TUSB_ERROR_NOT_ENOUGH_MEMORY )\
ENTRY(TUSB_ERROR_FAILED )\
- \
- ENTRY(ERR_TUD_INVALID_DESCRIPTOR) \
- ENTRY(ERR_TUD_EDPT_OPEN_FAILED) \
-
/// \brief Error Code returned
typedef enum
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index 2acd4b696..8902f5a4e 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -48,9 +48,7 @@ static void tu_fifo_lock(tu_fifo_t *f)
{
if (f->mutex)
{
- uint32_t err;
- (void) err;
- osal_mutex_lock(f->mutex, OSAL_TIMEOUT_WAIT_FOREVER, &err);
+ osal_mutex_lock(f->mutex, OSAL_TIMEOUT_WAIT_FOREVER);
}
}
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 8c685d5b3..a3fbfdff9 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -36,8 +36,6 @@
*/
/**************************************************************************/
-// This top level class manages the bus state and delegates events to class-specific drivers.
-
#include "tusb_option.h"
#if TUSB_OPT_DEVICE_ENABLED
@@ -52,15 +50,6 @@
#define CFG_TUD_TASK_QUEUE_SZ 16
#endif
-#ifndef CFG_TUD_TASK_STACK_SZ
-#define CFG_TUD_TASK_STACK_SZ 150
-#endif
-
-#ifndef CFG_TUD_TASK_PRIO
-#define CFG_TUD_TASK_PRIO 0
-#endif
-
-
//--------------------------------------------------------------------+
// Device Data
//--------------------------------------------------------------------+
@@ -153,16 +142,14 @@ static usbd_class_driver_t const usbd_class_drivers[] =
#endif
};
-enum { USBD_CLASS_DRIVER_COUNT = sizeof(usbd_class_drivers) / sizeof(usbd_class_driver_t) };
-
+enum { USBD_CLASS_DRIVER_COUNT = TU_ARRAY_SZIE(usbd_class_drivers) };
//--------------------------------------------------------------------+
// DCD Event
//--------------------------------------------------------------------+
-OSAL_TASK_DEF(_usbd_task_def, "usbd", usbd_task, CFG_TUD_TASK_PRIO, CFG_TUD_TASK_STACK_SZ);
// Event queue
-// role device/host is used by OS NONE for mutex (disable usb isr) only
+// OPT_MODE_DEVICE is used by OS NONE for mutex (disable usb isr)
OSAL_QUEUE_DEF(OPT_MODE_DEVICE, _usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t);
static osal_queue_t _usbd_q;
@@ -195,8 +182,6 @@ bool usbd_init (void)
_usbd_q = osal_queue_create(&_usbd_qdef);
TU_ASSERT(_usbd_q != NULL);
- osal_task_create(&_usbd_task_def);
-
// Init class drivers
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) usbd_class_drivers[i].init();
@@ -221,8 +206,26 @@ static void usbd_reset(uint8_t rhport)
}
}
-// Main device task implementation
-static void usbd_task_body(void)
+/* USB Device Driver task
+ * This top level thread manages all device 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();
+
+ tud_task(); // tinyusb device task
+ }
+ }
+ @endcode
+ */
+void tud_task (void)
{
// Loop until there is no more events in the queue
while (1)
@@ -297,25 +300,6 @@ 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 coding convenience with no RTOS, we use wrapped sub-function for processing to easily return at any time.
- */
-void usbd_task( void* param)
-{
- (void) param;
-
-#if CFG_TUSB_OS != OPT_OS_NONE
- while (1) {
-#endif
-
- usbd_task_body();
-
-#if CFG_TUSB_OS != OPT_OS_NONE
- }
-#endif
-}
-
//--------------------------------------------------------------------+
// Control Request Parser & Handling
//--------------------------------------------------------------------+
diff --git a/src/device/usbd.h b/src/device/usbd.h
index f9e0d8f4d..f9e7368ce 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -81,6 +81,7 @@ extern tud_desc_set_t tud_desc_set;
// APPLICATION API
//--------------------------------------------------------------------+
bool tud_mounted(void);
+void tud_task (void);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK (WEAK is optional)
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h
index 798a871b1..06951673f 100644
--- a/src/device/usbd_pvt.h
+++ b/src/device/usbd_pvt.h
@@ -52,8 +52,6 @@ extern tud_desc_set_t const* usbd_desc_set;
// INTERNAL API for stack management
//--------------------------------------------------------------------+
bool usbd_init (void);
-void usbd_task (void* param);
-
// Carry out Data and Status stage of control transfer
// - If len = 0, it is equivalent to sending status only
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);
diff --git a/src/osal/osal.h b/src/osal/osal.h
index 55e3e077c..f38a5305f 100644
--- a/src/osal/osal.h
+++ b/src/osal/osal.h
@@ -68,8 +68,6 @@ typedef void (*osal_task_func_t)( void * );
* uint32_t tusb_hal_millis(void)
*
* Task
- * osal_task_def_t
- * bool osal_task_create(osal_task_def_t* taskdef)
* void osal_task_delay(uint32_t msec)
*
* Queue
diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h
index acec4a95d..3e3fa7e95 100644
--- a/src/osal/osal_freertos.h
+++ b/src/osal/osal_freertos.h
@@ -65,27 +65,6 @@ static inline bool in_isr(void)
//--------------------------------------------------------------------+
// TASK API
//--------------------------------------------------------------------+
-#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) \
- static uint8_t _name##_##buf[_stack_sz*sizeof(StackType_t)]; \
- osal_task_def_t _name = { .func = _func, .prio = _prio, .stack_sz = _stack_sz, .buf = _name##_##buf, .strname = _str };
-
-typedef struct
-{
- osal_task_func_t func;
-
- uint16_t prio;
- uint16_t stack_sz;
- void* buf;
- const char* strname;
-
- StaticTask_t stask;
-}osal_task_def_t;
-
-static inline bool osal_task_create(osal_task_def_t* taskdef)
-{
- return NULL != xTaskCreateStatic(taskdef->func, taskdef->strname, taskdef->stack_sz, NULL, taskdef->prio, (StackType_t*) taskdef->buf, &taskdef->stask);
-}
-
static inline void osal_task_delay(uint32_t msec)
{
vTaskDelay( pdMS_TO_TICKS(msec) );
diff --git a/src/osal/osal_mynewt.h b/src/osal/osal_mynewt.h
index 62b5b45e8..d63ea731d 100644
--- a/src/osal/osal_mynewt.h
+++ b/src/osal/osal_mynewt.h
@@ -46,27 +46,6 @@
//--------------------------------------------------------------------+
// TASK API
//--------------------------------------------------------------------+
-#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) \
- static os_stack_t _name##_##buf[_stack_sz]; \
- osal_task_def_t _name = { .func = _func, .prio = _prio, .stack_sz = _stack_sz, .buf = _name##_##buf, .strname = _str };
-
-typedef struct
-{
- struct os_task mynewt_task;
- osal_task_func_t func;
-
- uint16_t prio;
- uint16_t stack_sz;
- void* buf;
- const char* strname;
-}osal_task_def_t;
-
-static inline bool osal_task_create(osal_task_def_t* taskdef)
-{
- return OS_OK == os_task_init(&taskdef->mynewt_task, taskdef->strname, taskdef->func, NULL, taskdef->prio, OS_WAIT_FOREVER,
- (os_stack_t*) taskdef->buf, taskdef->stack_sz);
-}
-
static inline void osal_task_delay(uint32_t msec)
{
os_time_delay( os_time_ms_to_ticks32(msec) );
diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h
index ff37113c6..55db674ce 100644
--- a/src/osal/osal_none.h
+++ b/src/osal/osal_none.h
@@ -51,17 +51,7 @@
//--------------------------------------------------------------------+
// TASK API
-// Virtually do nothing in osal none
//--------------------------------------------------------------------+
-#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) osal_task_def_t _name;
-typedef uint8_t osal_task_def_t;
-
-static inline bool osal_task_create(osal_task_def_t* taskdef)
-{
- (void) taskdef;
- return true;
-}
-
static inline void osal_task_delay(uint32_t msec)
{
uint32_t start = tusb_hal_millis();
diff --git a/src/tusb.c b/src/tusb.c
index 4f7996664..ad2dcbfd3 100644
--- a/src/tusb.c
+++ b/src/tusb.c
@@ -68,20 +68,6 @@ bool tusb_init(void)
return TUSB_ERROR_NONE;
}
-#if CFG_TUSB_OS == OPT_OS_NONE
-void tusb_task(void)
-{
- #if TUSB_OPT_HOST_ENABLED
- usbh_task(NULL);
- #endif
-
- #if TUSB_OPT_DEVICE_ENABLED
- usbd_task(NULL);
- #endif
-}
-#endif
-
-
/*------------------------------------------------------------------*/
/* Debug
*------------------------------------------------------------------*/
diff --git a/src/tusb.h b/src/tusb.h
index 4d65c80e1..3a13bbecc 100644
--- a/src/tusb.h
+++ b/src/tusb.h
@@ -101,35 +101,24 @@
/** \ingroup group_application_api
* @{ */
-// Initialize device/host stack according to tusb_config.h
-// return true if success
+// Initialize device/host stack
bool tusb_init(void);
-#if CFG_TUSB_OS == OPT_OS_NONE
-/** \brief Run all tinyusb's internal tasks (e.g host task, device task).
- * \note This function is only required when using no RTOS (\ref CFG_TUSB_OS == OPT_OS_NONE). All the stack functions
- * & callback are invoked within this function. This should be called periodically within the mainloop
- *
- @code
- int main(void)
- {
- your_init_code();
- tusb_init();
+// TODO
+// bool tusb_teardown(void);
- // other config code
- while(1) // the mainloop
- {
- your_application_code();
+// backward compatible only. TODO remove later
+static inline void tusb_task(void)
+{
+ #if TUSB_OPT_HOST_ENABLED
+ tuh_task();
+ #endif
- tusb_task(); // handle tinyusb event, task etc ...
- }
- }
- @endcode
- *
- */
-void tusb_task(void);
-#endif
+ #if TUSB_OPT_DEVICE_ENABLED
+ tud_task();
+ #endif
+}
/** @} */
diff --git a/src/tusb_option.h b/src/tusb_option.h
index 8b2e59b17..07d8387e3 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -224,11 +224,6 @@
//------------------------------------------------------------------
// Configuration Validation
//------------------------------------------------------------------
-
-#if (CFG_TUSB_OS != OPT_OS_NONE) && !defined (CFG_TUD_TASK_PRIO)
- #error CFG_TUD_TASK_PRIO need to be defined (hint: use the highest if possible)
-#endif
-
#if CFG_TUD_ENDOINT0_SIZE > 64
#error Control Endpoint Max Packet Size cannot be larger than 64
#endif