From 1713e81e44fec35b6efda895064984b581026624 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 22 Oct 2018 12:24:27 +0700 Subject: [PATCH] sync with tinyusb repo --- cores/nRF5/usb/tinyusb/README.md | 10 ----- .../usb/tinyusb/src/class/cdc/cdc_device.c | 2 + .../usb/tinyusb/src/common/tusb_compiler.h | 5 +-- cores/nRF5/usb/tinyusb/src/common/tusb_fifo.c | 30 +++----------- cores/nRF5/usb/tinyusb/src/device/usbd.c | 2 +- cores/nRF5/usb/tinyusb/src/osal/osal.c | 7 ++++ cores/nRF5/usb/tinyusb/src/osal/osal.h | 41 +++++++++++++++++-- .../osal/{osal_freeRTOS.h => osal_freertos.h} | 10 ++--- cores/nRF5/usb/tinyusb/src/osal/osal_none.h | 5 +-- .../src/portable/nordic/nrf5x/hal_nrf5x.c | 2 +- cores/nRF5/usb/tinyusb/src/tusb_option.h | 5 ++- 11 files changed, 65 insertions(+), 54 deletions(-) rename cores/nRF5/usb/tinyusb/src/osal/{osal_freeRTOS.h => osal_freertos.h} (91%) diff --git a/cores/nRF5/usb/tinyusb/README.md b/cores/nRF5/usb/tinyusb/README.md index cac53865..51b6c096 100644 --- a/cores/nRF5/usb/tinyusb/README.md +++ b/cores/nRF5/usb/tinyusb/README.md @@ -77,13 +77,3 @@ The stack supports the following MCUs ## License ## BSD license for most of the code base, but each file is individually licensed especially those in *vendor* folder. Please make sure you understand all the license term for files you use in your project. [Full license is here](tinyusb/license.md) - -## How Can I Help ## - -If you find my little USB stack is useful and want to give something back - -### Donate Time ### - -You can contribute your time by helping with programming, testing and filing bug reports, improving documentation. Or simply by using tinyusb, giving me some feedback on how to improve it and telling others about it. - - diff --git a/cores/nRF5/usb/tinyusb/src/class/cdc/cdc_device.c b/cores/nRF5/usb/tinyusb/src/class/cdc/cdc_device.c index 2215e00e..70d51c25 100644 --- a/cores/nRF5/usb/tinyusb/src/class/cdc/cdc_device.c +++ b/cores/nRF5/usb/tinyusb/src/class/cdc/cdc_device.c @@ -153,11 +153,13 @@ uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize) { uint16_t ret = tu_fifo_write_n(&_cdcd_itf[itf].tx_ff, buffer, bufsize); +#if 0 // TODO issue with circuitpython's REPL // flush if queue more than endpoint size if ( tu_fifo_count(&_cdcd_itf[itf].tx_ff) >= CFG_TUD_CDC_EPSIZE ) { tud_cdc_n_write_flush(itf); } +#endif return ret; } diff --git a/cores/nRF5/usb/tinyusb/src/common/tusb_compiler.h b/cores/nRF5/usb/tinyusb/src/common/tusb_compiler.h index 7048732c..933d7604 100644 --- a/cores/nRF5/usb/tinyusb/src/common/tusb_compiler.h +++ b/cores/nRF5/usb/tinyusb/src/common/tusb_compiler.h @@ -58,9 +58,8 @@ //--------------------------------------------------------------------+ // Compile-time Assert (use TU_VERIFY_STATIC to avoid name conflict) //--------------------------------------------------------------------+ -#if defined(__ICCARM__) || (__STDC_VERSION__ >= 201112L ) - #include - #define TU_VERIFY_STATIC static_assert +#if __STDC_VERSION__ >= 201112L + #define TU_VERIFY_STATIC _Static_assert #else #define TU_VERIFY_STATIC(const_expr, _mess) enum { XSTRING_CONCAT_(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) } #endif diff --git a/cores/nRF5/usb/tinyusb/src/common/tusb_fifo.c b/cores/nRF5/usb/tinyusb/src/common/tusb_fifo.c index e90264f8..818f4e9c 100644 --- a/cores/nRF5/usb/tinyusb/src/common/tusb_fifo.c +++ b/cores/nRF5/usb/tinyusb/src/common/tusb_fifo.c @@ -32,16 +32,13 @@ INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This file is part of the tinyusb stack. -*/ + This file is part of the tinyusb stack. + */ /**************************************************************************/ #include "tusb_fifo.h" #include "common/tusb_verify.h" // for ASSERT -/*------------------------------------------------------------------*/ -/* - *------------------------------------------------------------------*/ #if CFG_FIFO_MUTEX #define mutex_lock_if_needed(_ff) if (_ff->mutex) tu_fifo_mutex_lock(_ff->mutex) @@ -54,17 +51,6 @@ #endif -static inline uint16_t tu_min16(uint16_t x, uint16_t y) -{ - return (x < y) ? x : y; -} - -static inline bool tu_fifo_initalized(tu_fifo_t* f) -{ - return (f->buffer != NULL) && (f->depth > 0) && (f->item_size > 0); -} - - void tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable) { mutex_lock_if_needed(f); @@ -98,7 +84,6 @@ void tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si /******************************************************************************/ bool tu_fifo_read(tu_fifo_t* f, void * p_buffer) { - if( !tu_fifo_initalized(f) ) return false; if( tu_fifo_empty(f) ) return false; mutex_lock_if_needed(f); @@ -132,12 +117,10 @@ bool tu_fifo_read(tu_fifo_t* f, void * p_buffer) /******************************************************************************/ uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t count) { - if( !tu_fifo_initalized(f) ) return 0; if( tu_fifo_empty(f) ) return 0; /* Limit up to fifo's count */ - count = tu_min16(count, f->count); - if( count == 0 ) return 0; + if ( count > f->count ) count = f->count; mutex_lock_if_needed(f); @@ -176,7 +159,6 @@ uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t count) /******************************************************************************/ bool tu_fifo_peek_at(tu_fifo_t* f, uint16_t pos, void * p_buffer) { - if ( !tu_fifo_initalized(f) ) return false; if ( pos >= f->count ) return false; // rd_idx is pos=0 @@ -205,10 +187,8 @@ bool tu_fifo_peek_at(tu_fifo_t* f, uint16_t pos, void * p_buffer) FIFO will always return TRUE) */ /******************************************************************************/ -bool tu_fifo_write(tu_fifo_t* f, void const * p_data) +bool tu_fifo_write (tu_fifo_t* f, const void * p_data) { - if ( !tu_fifo_initalized(f) ) return false; - // if ( tu_fifo_full(f) && !f->overwritable ) return false; TU_ASSERT( !(tu_fifo_full(f) && !f->overwritable) ); @@ -249,7 +229,7 @@ bool tu_fifo_write(tu_fifo_t* f, void const * p_data) @return Number of written elements */ /******************************************************************************/ -uint16_t tu_fifo_write_n(tu_fifo_t* f, void const * p_data, uint16_t count) +uint16_t tu_fifo_write_n (tu_fifo_t* f, const void * p_data, uint16_t count) { if ( count == 0 ) return 0; diff --git a/cores/nRF5/usb/tinyusb/src/device/usbd.c b/cores/nRF5/usb/tinyusb/src/device/usbd.c index 2f760808..89dd4b72 100644 --- a/cores/nRF5/usb/tinyusb/src/device/usbd.c +++ b/cores/nRF5/usb/tinyusb/src/device/usbd.c @@ -335,7 +335,7 @@ static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request { OSAL_SUBTASK_BEGIN - tusb_error_t error; + ATTR_UNUSED tusb_error_t error; error = TUSB_ERROR_NONE; //------------- Standard Request e.g in enumeration -------------// diff --git a/cores/nRF5/usb/tinyusb/src/osal/osal.c b/cores/nRF5/usb/tinyusb/src/osal/osal.c index d08439a8..527e7f56 100644 --- a/cores/nRF5/usb/tinyusb/src/osal/osal.c +++ b/cores/nRF5/usb/tinyusb/src/osal/osal.c @@ -50,5 +50,12 @@ uint32_t tusb_hal_millis(void) return ( ( ((uint64_t) xTaskGetTickCount()) * 1000) / configTICK_RATE_HZ ); } +#elif CFG_TUSB_OS == OPT_OS_MYNEWT + +uint32_t tusb_hal_millis(void) +{ + return os_time_ticks_to_ms32( os_time_get() ); +} + #endif diff --git a/cores/nRF5/usb/tinyusb/src/osal/osal.h b/cores/nRF5/usb/tinyusb/src/osal/osal.h index 16dc8da2..d6483720 100644 --- a/cores/nRF5/usb/tinyusb/src/osal/osal.h +++ b/cores/nRF5/usb/tinyusb/src/osal/osal.h @@ -61,13 +61,48 @@ enum typedef void (*osal_task_func_t)( void * ); #if CFG_TUSB_OS == OPT_OS_NONE + #include "osal_none.h" + #define OSAL_TASK_BEGIN #define OSAL_TASK_END - #include "osal_none.h" #else - #if CFG_TUSB_OS == OPT_OS_FREERTOS - #include "osal_freeRTOS.h" + /* RTOS Porting API + * + * 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 + * osal_queue_def_t, osal_queue_t + * osal_queue_t osal_queue_create(osal_queue_def_t* qdef) + * osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) + * bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data) + * bool osal_queue_send(osal_queue_t const queue_hdl, void const * data) + * osal_queue_flush() TODO remove + * + * Semaphore + * osal_semaphore_def_t, osal_semaphore_t + * osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) + * bool osal_semaphore_post_isr(osal_semaphore_t sem_hdl) + * bool osal_semaphore_post(osal_semaphore_t sem_hdl) + * void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) + * void osal_semaphore_reset_isr(osal_semaphore_t const sem_hdl) + * + * Mutex + * osal_mutex_t + * osal_mutex_create() + * bool osal_mutex_release(osal_mutex_t mutex_hdl) + * void osal_mutex_wait(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error) + */ + + #if CFG_TUSB_OS == OPT_OS_FREERTOS + #include "osal_freertos.h" + #elif CFG_TUSB_OS == OPT_OS_MYNEWT + #include "osal_mynewt.h" #else #error CFG_TUSB_OS is not defined or OS is not supported yet #endif diff --git a/cores/nRF5/usb/tinyusb/src/osal/osal_freeRTOS.h b/cores/nRF5/usb/tinyusb/src/osal/osal_freertos.h similarity index 91% rename from cores/nRF5/usb/tinyusb/src/osal/osal_freeRTOS.h rename to cores/nRF5/usb/tinyusb/src/osal/osal_freertos.h index ce68d2d5..ff39bab3 100644 --- a/cores/nRF5/usb/tinyusb/src/osal/osal_freeRTOS.h +++ b/cores/nRF5/usb/tinyusb/src/osal/osal_freertos.h @@ -66,7 +66,7 @@ static inline bool in_isr(void) // TASK API //--------------------------------------------------------------------+ #define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) \ - uint8_t _name##_##buf[_stack_sz*sizeof(StackType_t)]; \ + 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 @@ -81,11 +81,9 @@ typedef struct StaticTask_t stask; }osal_task_def_t; -typedef TaskHandle_t osal_task_t; - -static inline osal_task_t osal_task_create(osal_task_def_t* taskdef) +static inline bool osal_task_create(osal_task_def_t* taskdef) { - return xTaskCreateStatic(taskdef->func, taskdef->strname, taskdef->stack_sz, NULL, taskdef->prio, (StackType_t*) taskdef->buf, &taskdef->stask); + 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) @@ -97,7 +95,7 @@ static inline void osal_task_delay(uint32_t msec) // QUEUE API //--------------------------------------------------------------------+ #define OSAL_QUEUE_DEF(_name, _depth, _type) \ - uint8_t _name##_##buf[_depth*sizeof(_type)];\ + static _type _name##_##buf[_depth];\ osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; typedef struct diff --git a/cores/nRF5/usb/tinyusb/src/osal/osal_none.h b/cores/nRF5/usb/tinyusb/src/osal/osal_none.h index 012de9c7..22c89868 100644 --- a/cores/nRF5/usb/tinyusb/src/osal/osal_none.h +++ b/cores/nRF5/usb/tinyusb/src/osal/osal_none.h @@ -68,12 +68,11 @@ #define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) osal_task_def_t _name; typedef uint8_t osal_task_def_t; -typedef void* osal_task_t; -static inline osal_task_t osal_task_create(osal_task_def_t* taskdef) +static inline bool osal_task_create(osal_task_def_t* taskdef) { (void) taskdef; - return (osal_task_t) 1; // return non zero + return true; } #define TASK_RESTART \ diff --git a/cores/nRF5/usb/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c b/cores/nRF5/usb/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c index 6ecaf403..64ef1f19 100644 --- a/cores/nRF5/usb/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c +++ b/cores/nRF5/usb/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c @@ -255,7 +255,7 @@ void tusb_hal_nrf_power_event (uint32_t event) __DSB(); } - nrf_usbd_isosplit_set(NRF_USBD_ISOSPLIT_Half); + nrf_usbd_isosplit_set(USBD_ISOSPLIT_SPLIT_HalfIN); // Enable interrupt. SOF is used as CDC auto flush NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_USBEVENT_Msk | USBD_INTEN_EPDATA_Msk | diff --git a/cores/nRF5/usb/tinyusb/src/tusb_option.h b/cores/nRF5/usb/tinyusb/src/tusb_option.h index 22b78453..84636712 100644 --- a/cores/nRF5/usb/tinyusb/src/tusb_option.h +++ b/cores/nRF5/usb/tinyusb/src/tusb_option.h @@ -62,8 +62,9 @@ /** \defgroup group_supported_os Supported RTOS * \ref CFG_TUSB_OS must be defined to one of these * @{ */ -#define OPT_OS_NONE 1 ///< No RTOS is used -#define OPT_OS_FREERTOS 2 ///< FreeRTOS is used +#define OPT_OS_NONE 1 ///< No RTOS +#define OPT_OS_FREERTOS 2 ///< FreeRTOS +#define OPT_OS_MYNEWT 3 ///< Mynewt OS /** @} */