sync with tinyusb repo

This commit is contained in:
hathach committed 2018-10-22 12:27:09 +07:00
1 parent b39dd4f53a
commit 1713e81e44
11 files changed
+65 -54

No files matched your search

-10
View File
@@ -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.
@@ -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;
}
@@ -58,9 +58,8 @@
//--------------------------------------------------------------------+
// Compile-time Assert (use TU_VERIFY_STATIC to avoid name conflict)
//--------------------------------------------------------------------+
#if defined(__ICCARM__) || (__STDC_VERSION__ >= 201112L )
#include <assert.h>
#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
+5 -25
View File
@@ -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;
+1 -1
View File
@@ -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 -------------//
+7
View File
@@ -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
+38 -3
View File
@@ -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
@@ -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
+2 -3
View File
@@ -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 \
@@ -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 |
+3 -2
View File
@@ -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
/** @} */