osal clean up

remove OSAL_TASK_DEF, osal_task_create. Applicaton should create a task
and call tinyusb_task(). This make API consistent with NO OS.
This commit is contained in:
hathach
2018-12-13 13:49:09 +07:00
parent b562fa741b
commit bc46dc6edf
19 changed files with 75 additions and 238 deletions

View File

@@ -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);
}
}

View File

@@ -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,9 +206,13 @@ 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.
*/
void usbd_task( void* param)
{
(void) param;
// Loop until there is no more events in the queue
while (1)
{
@@ -297,25 +286,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
//--------------------------------------------------------------------+

View File

@@ -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,18 @@ 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.
*/
void usbh_task(void* param)
{
(void) param;
// 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 +624,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
//--------------------------------------------------------------------+

View File

@@ -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

View File

@@ -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) );

View File

@@ -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) );

View File

@@ -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();

View File

@@ -68,7 +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
@@ -79,8 +78,6 @@ void tusb_task(void)
usbd_task(NULL);
#endif
}
#endif
/*------------------------------------------------------------------*/
/* Debug

View File

@@ -105,11 +105,9 @@
// return true if success
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
*
/** Run all tinyusb's internal tasks (e.g host task, device task) and invoke callback
* This should be called periodically within the mainloop.
@code
int main(void)
{
@@ -126,10 +124,9 @@ bool tusb_init(void);
}
}
@endcode
*
*/
void tusb_task(void);
#endif
/** @} */

View File

@@ -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