diff options
| author | hathach <[email protected]> | 2013-09-13 16:53:17 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-09-13 16:53:17 +0700 |
| commit | c71f5c6f1ba46a23847a2eea83176e15058f21e6 (patch) | |
| tree | 427c7aa2c1d1625325495111ba6096e1844cbb2f /tinyusb | |
| parent | 1f573eecf27bfd18f07c9efb2c3941ec4c5c6db6 (diff) | |
integrate & able to run cmsis-rtx with current code base
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/common/binary.h | 2 | ||||
| -rw-r--r-- | tinyusb/host/ehci/ehci.c | 2 | ||||
| -rw-r--r-- | tinyusb/mcu_capacity.h | 6 | ||||
| -rw-r--r-- | tinyusb/osal/osal.h | 12 | ||||
| -rw-r--r-- | tinyusb/osal/osal_cmsis_rtx.h | 248 | ||||
| -rw-r--r-- | tinyusb/osal/osal_freeRTOS.h | 3 |
6 files changed, 264 insertions, 9 deletions
diff --git a/tinyusb/common/binary.h b/tinyusb/common/binary.h index 260175976..e7669853a 100644 --- a/tinyusb/common/binary.h +++ b/tinyusb/common/binary.h @@ -57,7 +57,7 @@ #endif /// n-th Bit -#define BIT_(n) (1 << (n)) +#define BIT_(n) (1U << (n)) /// set n-th bit of x to 1 #define BIT_SET_(x, n) ( (x) | BIT_(n) ) diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 2654cccf0..addf33adf 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -155,7 +155,7 @@ bool hcd_port_connect_status(uint8_t hostid) tusb_speed_t hcd_port_speed_get(uint8_t hostid) { - return get_operational_register(hostid)->portsc_bit.nxp_port_speed; // NXP specific port speed + return (tusb_speed_t) get_operational_register(hostid)->portsc_bit.nxp_port_speed; // NXP specific port speed } //--------------------------------------------------------------------+ diff --git a/tinyusb/mcu_capacity.h b/tinyusb/mcu_capacity.h index dd5ea01e8..e287cf4b5 100644 --- a/tinyusb/mcu_capacity.h +++ b/tinyusb/mcu_capacity.h @@ -59,6 +59,12 @@ // CAP is abbreviation for Capacity //--------------------------------------------------------------------+ +// ARCHTECTURE +//--------------------------------------------------------------------+ + + + +//--------------------------------------------------------------------+ // Controller //--------------------------------------------------------------------+ #if MCU == MCU_LPC43XX || MCU == MCU_LPC18XX diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index e15bdd1a6..cc6b7f700 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -58,11 +58,11 @@ #include "tusb_option.h" -#define TUSB_OS_NONE 1 -#define TUSB_OS_FREERTOS 2 -#define TUSB_OS_CMSIS 3 -#define TUSB_OS_UCOS2 4 -#define TUSB_OS_UCOS3 5 +#define TUSB_OS_NONE 1 +#define TUSB_OS_FREERTOS 2 +#define TUSB_OS_CMSIS_RTX 3 +#define TUSB_OS_UCOS2 4 +#define TUSB_OS_UCOS3 5 #ifndef _TEST_ @@ -70,6 +70,8 @@ #include "osal_none.h" #elif TUSB_CFG_OS == TUSB_OS_FREERTOS #include "osal_freeRTOS.h" +#elif TUSB_CFG_OS == TUSB_OS_CMSIS_RTX + #include "osal_cmsis_rtx.h" #else #error TUSB_CFG_OS is not defined or OS is not supported yet #endif diff --git a/tinyusb/osal/osal_cmsis_rtx.h b/tinyusb/osal/osal_cmsis_rtx.h new file mode 100644 index 000000000..4381b1eb1 --- /dev/null +++ b/tinyusb/osal/osal_cmsis_rtx.h @@ -0,0 +1,248 @@ +/**************************************************************************/ +/*! + @file osal_cmsis_rtx.h + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (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. +*/ +/**************************************************************************/ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_OSAL_CMSIS_RTX_H_ +#define _TUSB_OSAL_CMSIS_RTX_H_ + +#include "osal_common.h" +#include "cmsis_os.h" + +#ifdef __cplusplus + extern "C" { +#endif + +//--------------------------------------------------------------------+ +// TICK API +//--------------------------------------------------------------------+ +#define osal_tick_get osKernelSysTick + +//--------------------------------------------------------------------+ +// TASK API +//--------------------------------------------------------------------+ +#define OSAL_TASK_FUNCTION(task_func) \ + void task_func + +typedef osThreadDef_t osal_task_t; + +#define OSAL_TASK_DEF(task_name, task_code, task_stack_depth, task_prio) \ + osThreadDef(task_code, task_prio, 1, task_stack_depth*4) // stack depth is in bytes + +#define OSAL_TASK_REF(task_name) osThread(task_name) + +static inline tusb_error_t osal_task_create(const osal_task_t *task) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; +static inline tusb_error_t osal_task_create(const osal_task_t *task) +{ + return ( osThreadCreate(task, NULL) != NULL ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TASK_CREATE_FAILED; +} + +#define osal_task_delay(msec) osDelay(msec) + +#define OSAL_TASK_LOOP_BEGIN \ + while(1) { + +#define OSAL_TASK_LOOP_END \ + } + +//------------- Sub Task -------------// +#define OSAL_SUBTASK_BEGIN // TODO refractor move +#define OSAL_SUBTASK_END \ + return TUSB_ERROR_NONE; + +#define SUBTASK_EXIT(error) return error; + +#define OSAL_SUBTASK_INVOKED_AND_WAIT(subtask, status) \ + status = subtask + +//------------- Sub Task Assert -------------// +#define SUBTASK_ASSERT_STATUS(sts) ASSERT_STATUS(sts) +#define SUBTASK_ASSERT(condition) ASSERT(condition, TUSB_ERROR_OSAL_TASK_FAILED) + +#define _SUBTASK_ASSERT_ERROR_HANDLER(error, func_call)\ + func_call; return error + +#define SUBTASK_ASSERT_STATUS_WITH_HANDLER(sts, func_call) \ + ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, tusb_error_t status = (tusb_error_t)(sts),\ + TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status]) + +#define SUBTASK_ASSERT_WITH_HANDLER(condition, func_call) \ + ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, ,\ + condition, TUSB_ERROR_OSAL_TASK_FAILED, "%s", "evaluated to false") + + +//--------------------------------------------------------------------+ +// Semaphore API +//--------------------------------------------------------------------+ +typedef struct { + uint32_t sem_cb[2]; +}osal_semaphore_t; + +typedef osSemaphoreId osal_semaphore_handle_t; + +#define OSAL_SEM_DEF(name) osal_semaphore_t name +#define OSAL_SEM_REF(name) (&name) + +static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; +static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem) +{ + return osSemaphoreCreate( &(osSemaphoreDef_t) { p_sem }, 0 ); +} + +// TODO add timeout (with instant return from ISR option) for semaphore post & queue send +static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl) ATTR_ALWAYS_INLINE; +static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl) +{ + return (osSemaphoreRelease(sem_hdl) == osOK) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_SEMAPHORE_FAILED; +} + +static inline void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error) ATTR_ALWAYS_INLINE; +static inline void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error) +{ + (*p_error) = ( osSemaphoreWait(sem_hdl, msec) > 0 ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT; +} + +static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl) ATTR_ALWAYS_INLINE; +static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl) +{ + osSemaphoreWait(sem_hdl, 0); // instant return without putting caller to suspend +} + +//--------------------------------------------------------------------+ +// MUTEX API (priority inheritance) +//--------------------------------------------------------------------+ +typedef struct { + uint32_t mutex_cb[3]; +}osal_mutex_t; + +typedef osMutexId osal_mutex_handle_t; + +#define OSAL_MUTEX_DEF(name) osal_mutex_t name +#define OSAL_MUTEX_REF(name) (&name) + +static inline osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; +static inline osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex) +{ + return osMutexCreate( &(osMutexDef_t) {p_mutex} ); +} + +static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t const mutex_hdl) ATTR_ALWAYS_INLINE; +static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t const mutex_hdl) +{ + return (osMutexRelease(mutex_hdl) == osOK) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_MUTEX_FAILED; +} + +static inline void osal_mutex_wait(osal_mutex_handle_t const mutex_hdl, uint32_t msec, tusb_error_t *p_error) ATTR_ALWAYS_INLINE; +static inline void osal_mutex_wait(osal_mutex_handle_t const mutex_hdl, uint32_t msec, tusb_error_t *p_error) +{ + (*p_error) = ( osMutexWait(mutex_hdl, msec) == osOK ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT; +} + +static inline void osal_mutex_reset(osal_mutex_handle_t const mutex_hdl) ATTR_ALWAYS_INLINE; +static inline void osal_mutex_reset(osal_mutex_handle_t const mutex_hdl) +{ + osMutexRelease(mutex_hdl); +} + +//--------------------------------------------------------------------+ +// QUEUE API (for RTX: osMailQId is osMessageQDef_t.pool) +//--------------------------------------------------------------------+ +typedef osMailQDef_t osal_queue_t; +typedef osal_queue_t * osal_queue_handle_t; + +#define OSAL_QUEUE_DEF(name, queue_depth, type)\ + osMailQDef(name, queue_depth, type); + +#define OSAL_QUEUE_REF(name) osMailQ(name) + +static inline osal_queue_handle_t osal_queue_create(osal_queue_t * const p_queue) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; +static inline osal_queue_handle_t osal_queue_create(osal_queue_t * const p_queue) +{ + return (NULL != osMailCreate(p_queue, NULL)) ? p_queue : NULL; +} + +static inline void osal_queue_receive (osal_queue_handle_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) ATTR_ALWAYS_INLINE; +static inline void osal_queue_receive (osal_queue_handle_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) +{ + osEvent evt = osMailGet(queue_hdl->pool, msec); + + if (evt.status != osEventMail) + { + (*p_error) = TUSB_ERROR_OSAL_TIMEOUT; + }else + { + memcpy(p_data, evt.value.p, queue_hdl->item_sz); + osMailFree(queue_hdl->pool, evt.value.p); + (*p_error) = TUSB_ERROR_NONE; + } +} + +static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, void const * data) ATTR_ALWAYS_INLINE; +static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, void const * data) +{ + void *p_buf = osMailAlloc(queue_hdl->pool, 0); // instantly return in case of sending within ISR (mostly used) + if (p_buf == NULL) return TUSB_ERROR_OSAL_QUEUE_FAILED; + + memcpy(p_buf, data, queue_hdl->item_sz); + osMailPut(queue_hdl->pool, p_buf); + return TUSB_ERROR_NONE; +} + +static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl) ATTR_ALWAYS_INLINE; +static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl) +{ + osEvent evt; + + while( (evt = osMailGet(queue_hdl->pool, 0) ).status == osEventMail ) + { + osMailFree(queue_hdl->pool, evt.value.p); + } +} + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_OSAL_CMSIS_RTX_H_ */ + +/** @} */ diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h index 52883126b..8bdd58cd8 100644 --- a/tinyusb/osal/osal_freeRTOS.h +++ b/tinyusb/osal/osal_freeRTOS.h @@ -120,7 +120,6 @@ static inline void osal_task_delay(uint32_t msec) status = subtask //------------- Sub Task Assert -------------// - #define SUBTASK_ASSERT_STATUS(sts) ASSERT_STATUS(sts) #define SUBTASK_ASSERT(condition) ASSERT(condition, TUSB_ERROR_OSAL_TASK_FAILED) @@ -178,7 +177,7 @@ typedef xSemaphoreHandle osal_mutex_handle_t; static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t const mutex_hdl) ATTR_ALWAYS_INLINE; static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t const mutex_hdl) { - return (xSemaphoreGive(mutex_hdl) == pdPASS) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_SEMAPHORE_FAILED; + return (xSemaphoreGive(mutex_hdl) == pdPASS) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_MUTEX_FAILED; } static inline void osal_mutex_wait(osal_mutex_handle_t const mutex_hdl, uint32_t msec, tusb_error_t *p_error) ATTR_ALWAYS_INLINE; |
