diff options
| author | hathach <[email protected]> | 2018-12-05 17:45:38 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-12-05 17:45:38 +0700 |
| commit | b2ec8230d9acffbc0df280832b0341b82584b226 (patch) | |
| tree | 25e4eae94d5731873fee9da2bfe216eec6d0cc2a | |
| parent | cf60b206528fc955bbdd1bfec2c7016a985313ea (diff) | |
| parent | 27793cbd3dba550f9a7124d5e539325904b795e8 (diff) | |
Merge pull request #19 from hathach/devlocal
queue lock/unlock with isr
| -rw-r--r-- | examples/device/cdc_msc_hid/ses/samd21/samd21.emProject | 1 | ||||
| -rw-r--r-- | src/common/tusb_fifo.h | 3 | ||||
| -rw-r--r-- | src/device/usbd.c | 38 | ||||
| -rw-r--r-- | src/device/usbd_control.c | 1 | ||||
| -rw-r--r-- | src/device/usbd_pvt.h | 4 | ||||
| -rw-r--r-- | src/host/usbh.h | 3 | ||||
| -rw-r--r-- | src/osal/osal_freertos.h | 4 | ||||
| -rw-r--r-- | src/osal/osal_mynewt.h | 4 | ||||
| -rw-r--r-- | src/osal/osal_none.h | 96 | ||||
| -rw-r--r-- | src/portable/nordic/nrf5x/hal_nrf5x.c | 6 | ||||
| -rw-r--r-- | src/portable/nordic/nrf5x/nrf_drv_usbd_errata.h | 93 | ||||
| -rw-r--r-- | src/tusb.c | 8 | ||||
| -rw-r--r-- | src/tusb.h | 10 | ||||
| -rw-r--r-- | src/tusb_hal.h | 33 | ||||
| -rw-r--r-- | src/tusb_option.h | 1 |
15 files changed, 171 insertions, 134 deletions
diff --git a/examples/device/cdc_msc_hid/ses/samd21/samd21.emProject b/examples/device/cdc_msc_hid/ses/samd21/samd21.emProject index d61b82cfa..fbb8841b7 100644 --- a/examples/device/cdc_msc_hid/ses/samd21/samd21.emProject +++ b/examples/device/cdc_msc_hid/ses/samd21/samd21.emProject @@ -22,6 +22,7 @@ c_user_include_directories="../../src;$(rootDir)/hw/cmsis/Include;$(rootDir)/hw;$(rootDir)/src;$(asf4Dir);$(asf4Dir)/include;$(asf4Dir)/config;$(asf4Dir)/hri;$(asf4Dir)/hal/include;$(asf4Dir)/hal/utils/include;$(asf4Dir)/hpl/port;$(asf4Dir)/hpl/gclk;$(asf4Dir)/hpl/pm" debug_register_definition_file="ATSAMD21G18A_Registers.xml" debug_target_connection="J-Link" + gcc_enable_all_warnings="Yes" gcc_entry_point="Reset_Handler" link_use_linker_script_file="No" linker_memory_map_file="$(ProjectDir)/ATSAMD21G18A_MemoryMap.xml" diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h index 61d92b602..e88c2ac6d 100644 --- a/src/common/tusb_fifo.h +++ b/src/common/tusb_fifo.h @@ -67,13 +67,12 @@ typedef struct uint8_t* buffer ; ///< buffer pointer
uint16_t depth ; ///< max items
uint16_t item_size ; ///< size of each item
+ bool overwritable ;
volatile uint16_t count ; ///< number of items in queue
volatile uint16_t wr_idx ; ///< write pointer
volatile uint16_t rd_idx ; ///< read pointer
- bool overwritable ;
-
#if CFG_FIFO_MUTEX
tu_fifo_mutex_t mutex;
#endif
diff --git a/src/device/usbd.c b/src/device/usbd.c index ddb63cebb..78eebf76b 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -161,8 +161,9 @@ enum { USBD_CLASS_DRIVER_COUNT = sizeof(usbd_class_drivers) / sizeof(usbd_class_ //--------------------------------------------------------------------+
OSAL_TASK_DEF(_usbd_task_def, "usbd", usbd_task, CFG_TUD_TASK_PRIO, CFG_TUD_TASK_STACK_SZ);
-/*------------- event queue -------------*/
-OSAL_QUEUE_DEF(_usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t);
+// Event queue
+// role device/host is used by OS NONE for mutex (disable usb isr) only
+OSAL_QUEUE_DEF(OPT_MODE_DEVICE, _usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t);
static osal_queue_t _usbd_q;
//--------------------------------------------------------------------+
@@ -188,11 +189,11 @@ bool tud_mounted(void) //--------------------------------------------------------------------+
// USBD Task
//--------------------------------------------------------------------+
-tusb_error_t usbd_init (void)
+bool usbd_init (void)
{
// Init device queue & task
_usbd_q = osal_queue_create(&_usbd_qdef);
- TU_VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED);
+ TU_ASSERT(_usbd_q != NULL);
osal_task_create(&_usbd_task_def);
@@ -200,17 +201,10 @@ tusb_error_t usbd_init (void) for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) usbd_class_drivers[i].init();
// Init device controller driver
- #if (CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE)
- dcd_init(0);
- dcd_int_enable(0);
- #endif
-
- #if (CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE)
- dcd_init(1);
- dcd_int_enable(1);
- #endif
+ TU_ASSERT(dcd_init(TUD_OPT_RHPORT));
+ dcd_int_enable(TUD_OPT_RHPORT);
- return TUSB_ERROR_NONE;
+ return true;
}
static void usbd_reset(uint8_t rhport)
@@ -268,14 +262,14 @@ static void usbd_task_body(void) break;
case DCD_EVENT_BUS_RESET:
- // note: if task is too slow, we could clear the event of the new attached
usbd_reset(event.rhport);
+ // TODO remove since if task is too slow, we could clear the event of the new attached
osal_queue_reset(_usbd_q);
break;
case DCD_EVENT_UNPLUGGED:
- // note: if task is too slow, we could clear the event of the new attached
usbd_reset(event.rhport);
+ // TODO remove since if task is too slow, we could clear the event of the new attached
osal_queue_reset(_usbd_q);
tud_umount_cb(); // invoke callback
@@ -587,6 +581,11 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) TU_ASSERT(event->xfer_complete.result == XFER_RESULT_SUCCESS,);
break;
+ // Not an DCD event, just a convenient way to defer ISR function should we need
+ case USBD_EVT_FUNC_CALL:
+ osal_queue_send(_usbd_q, event, in_isr);
+ break;
+
default: break;
}
}
@@ -622,6 +621,8 @@ void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_ //--------------------------------------------------------------------+
// Helper
//--------------------------------------------------------------------+
+
+// Helper to parse an pair of endpoint descriptors (IN & OUT)
tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in)
{
for(int i=0; i<2; i++)
@@ -645,7 +646,8 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_d return TUSB_ERROR_NONE;
}
-void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr )
+// Helper to defer an isr function
+void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr)
{
dcd_event_t event =
{
@@ -656,7 +658,7 @@ void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr ) event.func_call.func = func;
event.func_call.param = param;
- osal_queue_send(_usbd_q, &event, in_isr);
+ dcd_event_handler(&event, in_isr);
}
#endif
diff --git a/src/device/usbd_control.c b/src/device/usbd_control.c index ebeaaaa4d..ae7e894b7 100644 --- a/src/device/usbd_control.c +++ b/src/device/usbd_control.c @@ -83,7 +83,6 @@ bool usbd_control_status(uint8_t rhport, tusb_control_request_t const * request) return dcd_edpt_xfer(rhport, request->bmRequestType_bit.direction ? EDPT_CTRL_OUT : EDPT_CTRL_IN, NULL, 0);
}
-
// Each transaction is up to endpoint0's max packet size
static bool start_control_data_xact(uint8_t rhport)
{
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index 30f010887..cbe5017bb 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -51,8 +51,8 @@ extern tud_desc_set_t const* usbd_desc_set; //--------------------------------------------------------------------+ // INTERNAL API for stack management //--------------------------------------------------------------------+ -tusb_error_t usbd_init (void); -void usbd_task (void* param); +bool usbd_init (void); +void usbd_task (void* param); // Carry out Data and Status stage of control transfer diff --git a/src/host/usbh.h b/src/host/usbh.h index 22fdef162..56efb6ff7 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -97,14 +97,11 @@ ATTR_WEAK void tuh_device_mount_failed_cb(tusb_error_t error, tusb_desc_devic //--------------------------------------------------------------------+ #ifdef _TINY_USB_SOURCE_FILE_ - void usbh_enumeration_task(void* param); tusb_error_t usbh_init(void); tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, uint8_t* data); - - #endif #ifdef __cplusplus diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index 52cadd798..704aafd64 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -139,7 +139,9 @@ static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) //--------------------------------------------------------------------+ // QUEUE API //--------------------------------------------------------------------+ -#define OSAL_QUEUE_DEF(_name, _depth, _type) \ + +// role device/host is used by OS NONE for mutex (disable usb isr) only +#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \ static _type _name##_##buf[_depth];\ osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; diff --git a/src/osal/osal_mynewt.h b/src/osal/osal_mynewt.h index cb09680e0..62b5b45e8 100644 --- a/src/osal/osal_mynewt.h +++ b/src/osal/osal_mynewt.h @@ -75,7 +75,9 @@ static inline void osal_task_delay(uint32_t msec) //--------------------------------------------------------------------+ // QUEUE API //--------------------------------------------------------------------+ -#define OSAL_QUEUE_DEF(_name, _depth, _type) \ + +// role device/host is used by OS NONE for mutex (disable usb isr) only +#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \ static _type _name##_##buf[_depth];\ static struct os_event* _name##_##evbuf[_depth];\ osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf, .evbuf = _name##_##evbuf};\ diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 40ecb9c37..4d5a4dd57 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -93,12 +93,11 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) static inline tusb_error_t osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) {
(void) msec;
while (true) {
- while (sem_hdl->count == 0) {
- }
- if (sem_hdl->count == 0) {
- sem_hdl->count--;
- break;
- }
+ while (sem_hdl->count == 0) { }
+ if (sem_hdl->count == 0) {
+ sem_hdl->count--;
+ break;
+ }
}
return TUSB_ERROR_NONE;
}
@@ -124,40 +123,97 @@ static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) //--------------------------------------------------------------------+
#include "common/tusb_fifo.h"
-#define OSAL_QUEUE_DEF(_name, _depth, _type) TU_FIFO_DEF(_name, _depth, _type, false)
+// extern to avoid including dcd.h and hcd.h
+#if TUSB_OPT_DEVICE_ENABLED
+extern void dcd_int_disable(uint8_t rhport);
+extern void dcd_int_enable(uint8_t rhport);
+#endif
-typedef tu_fifo_t osal_queue_def_t;
-typedef tu_fifo_t* osal_queue_t;
+#if MODE_HOST_SUPPORTED
+extern void hcd_int_disable(uint8_t rhport);
+extern void hcd_int_enable(uint8_t rhport);
+#endif
+
+typedef struct
+{
+ uint8_t role; // device or host
+ tu_fifo_t ff;
+}osal_queue_def_t;
+
+typedef osal_queue_def_t* osal_queue_t;
+
+// role device/host is used by OS NONE for mutex (disable usb isr) only
+#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \
+ uint8_t _name##_buf[_depth*sizeof(_type)]; \
+ osal_queue_def_t _name = { \
+ .role = _role, \
+ .ff = { \
+ .buffer = _name##_buf, \
+ .depth = _depth, \
+ .item_size = sizeof(_type), \
+ .overwritable = false, \
+ }\
+ }
+
+// lock queue by disable usb isr
+static inline void _osal_q_lock(osal_queue_t qhdl)
+{
+#if TUSB_OPT_DEVICE_ENABLED
+ if (qhdl->role == OPT_MODE_DEVICE) dcd_int_disable(TUD_OPT_RHPORT);
+#endif
+
+#if MODE_HOST_SUPPORTED
+ if (qhdl->role == OPT_MODE_HOST) hcd_int_disable(TUH_OPT_RHPORT);
+#endif
+}
+
+// unlock queue
+static inline void _osal_q_unlock(osal_queue_t qhdl)
+{
+#if TUSB_OPT_DEVICE_ENABLED
+ if (qhdl->role == OPT_MODE_DEVICE) dcd_int_enable(TUD_OPT_RHPORT);
+#endif
+
+#if MODE_HOST_SUPPORTED
+ if (qhdl->role == OPT_MODE_HOST) hcd_int_enable(TUH_OPT_RHPORT);
+#endif
+}
static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
{
- tu_fifo_clear(qdef);
+ tu_fifo_clear(&qdef->ff);
return (osal_queue_t) qdef;
}
-static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr)
+static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr)
{
if (!in_isr) {
- tusb_hal_int_disable_all();
+ _osal_q_lock(qhdl);
}
- bool success = tu_fifo_write( (tu_fifo_t*) queue_hdl, data);
+
+ bool success = tu_fifo_write(&qhdl->ff, data);
+
if (!in_isr) {
- tusb_hal_int_enable_all();
+ _osal_q_unlock(qhdl);
}
+
return success;
}
-static inline void osal_queue_reset(osal_queue_t const queue_hdl)
+static inline void osal_queue_reset(osal_queue_t const qhdl)
{
// tusb_hal_int_disable_all();
- tu_fifo_clear( (tu_fifo_t*) queue_hdl);
+ tu_fifo_clear(&qhdl->ff);
// tusb_hal_int_enable_all();
}
-static inline bool osal_queue_receive(osal_queue_t const queue_hdl, void* data) {
- tusb_hal_int_disable_all();
- bool success = tu_fifo_read(queue_hdl, data);
- tusb_hal_int_enable_all();
+// non blocking
+static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data)
+{
+ _osal_q_lock(qhdl);
+ bool success = tu_fifo_read(&qhdl->ff, data);
+ _osal_q_unlock(qhdl);
+
return success;
}
diff --git a/src/portable/nordic/nrf5x/hal_nrf5x.c b/src/portable/nordic/nrf5x/hal_nrf5x.c index 4cbcd1788..f0a0b9632 100644 --- a/src/portable/nordic/nrf5x/hal_nrf5x.c +++ b/src/portable/nordic/nrf5x/hal_nrf5x.c @@ -145,7 +145,6 @@ void tusb_hal_nrf_power_event (uint32_t event) /* Enable the peripheral */ // ERRATA 171, 187, 166 - // Somehow Errata 187 check failed for pca10056 1.0.0 (2018.19) if ( nrf_drv_usbd_errata_187() ) { // CRITICAL_REGION_ENTER(); @@ -209,7 +208,6 @@ void tusb_hal_nrf_power_event (uint32_t event) // CRITICAL_REGION_EXIT(); } - // Somehow Errata 187 check failed for pca10056 1.0.0 (2018.19) if ( nrf_drv_usbd_errata_187() ) { // CRITICAL_REGION_ENTER(); @@ -247,9 +245,7 @@ void tusb_hal_nrf_power_event (uint32_t event) NVIC_EnableIRQ(USBD_IRQn); // Wait for HFCLK - while ( !hfclk_running() ) - { - } + while ( !hfclk_running() ) { } // Enable pull up nrf_usbd_pullup_enable(); diff --git a/src/portable/nordic/nrf5x/nrf_drv_usbd_errata.h b/src/portable/nordic/nrf5x/nrf_drv_usbd_errata.h index f8c554f08..4a76e7eaa 100644 --- a/src/portable/nordic/nrf5x/nrf_drv_usbd_errata.h +++ b/src/portable/nordic/nrf5x/nrf_drv_usbd_errata.h @@ -1,30 +1,30 @@ /** * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA - * + * * 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, except as embedded into a Nordic * Semiconductor ASA integrated circuit in a product or a software update for * such product, 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 Nordic Semiconductor ASA nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. - * + * * 4. This software, with or without modification, must only be used with a * Nordic Semiconductor ASA integrated circuit. - * + * * 5. Any software provided in binary form under this license must not be reverse * engineered, decompiled, modified and/or disassembled. - * + * * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -35,7 +35,7 @@ * 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. - * + * */ #ifndef NRF_DRV_USBD_ERRATA_H__ @@ -68,34 +68,47 @@ */ static inline bool nrf_drv_usbd_errata_type_52840(void) { - return ((((*(uint32_t *)0xF0000FE0) & 0xFF) == 0x08) && - (((*(uint32_t *)0xF0000FE4) & 0x0F) == 0x0)); + return (*(uint32_t *)0x10000130UL == 0x8UL); +} + +/** + * @brief Internal auxiliary function to check if the program is running on Engineering A revision + * @retval true It is NRF52480 chip and it is Engineering A revision + * @retval false It is other chip + */ +static inline bool nrf_drv_usbd_errata_type_52840_eng_a(void) +{ + return (nrf_drv_usbd_errata_type_52840() && (*(uint32_t *)0x10000134UL == 0x0UL)); } /** - * @brief Internal auxiliary function to check if the program is running on first sample of - * NRF52840 chip - * @retval true It is NRF52480 chip and it is first sample version + * @brief Internal auxiliary function to check if the program is running on Engineering B revision + * @retval true It is NRF52480 chip and it is Engineering B revision * @retval false It is other chip */ -static inline bool nrf_drv_usbd_errata_type_52840_proto1(void) +static inline bool nrf_drv_usbd_errata_type_52840_eng_b(void) { - return ( nrf_drv_usbd_errata_type_52840() && - ( ((*(uint32_t *)0xF0000FE8) & 0xF0) == 0x00 ) && - ( ((*(uint32_t *)0xF0000FEC) & 0xF0) == 0x00 ) ); + return (nrf_drv_usbd_errata_type_52840() && (*(uint32_t *)0x10000134UL == 0x1UL)); } /** - * @brief Internal auxiliary function to check if the program is running on first final product of - * NRF52840 chip - * @retval true It is NRF52480 chip and it is first final product + * @brief Internal auxiliary function to check if the program is running on Engineering C revision + * @retval true It is NRF52480 chip and it is Engineering C revision * @retval false It is other chip */ -static inline bool nrf_drv_usbd_errata_type_52840_fp1(void) +static inline bool nrf_drv_usbd_errata_type_52840_eng_c(void) { - return ( nrf_drv_usbd_errata_type_52840() && - ( ((*(uint32_t *)0xF0000FE8) & 0xF0) == 0x20 ) && - ( ((*(uint32_t *)0xF0000FEC) & 0xF0) == 0x00 ) ); + return (nrf_drv_usbd_errata_type_52840() && (*(uint32_t *)0x10000134UL == 0x2UL)); +} + +/** + * @brief Internal auxiliary function to check if the program is running on Engineering D revision + * @retval true It is NRF52480 chip and it is Engineering D revision + * @retval false It is other chip + */ +static inline bool nrf_drv_usbd_errata_type_52840_eng_d(void) +{ + return (nrf_drv_usbd_errata_type_52840() && (*(uint32_t *)0x10000134UL == 0x3UL)); } /** @@ -108,7 +121,7 @@ static inline bool nrf_drv_usbd_errata_type_52840_fp1(void) */ static inline bool nrf_drv_usbd_errata_104(void) { - return NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_proto1(); + return (NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_eng_a()); } /** @@ -121,7 +134,7 @@ static inline bool nrf_drv_usbd_errata_104(void) */ static inline bool nrf_drv_usbd_errata_154(void) { - return NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_proto1(); + return (NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_eng_a()); } /** @@ -134,7 +147,7 @@ static inline bool nrf_drv_usbd_errata_154(void) */ static inline bool nrf_drv_usbd_errata_166(void) { - return NRF_DRV_USBD_ERRATA_ENABLE && true; + return (NRF_DRV_USBD_ERRATA_ENABLE && true); } /** @@ -147,7 +160,7 @@ static inline bool nrf_drv_usbd_errata_166(void) */ static inline bool nrf_drv_usbd_errata_171(void) { - return NRF_DRV_USBD_ERRATA_ENABLE && true; + return (NRF_DRV_USBD_ERRATA_ENABLE && true); } /** @@ -160,33 +173,37 @@ static inline bool nrf_drv_usbd_errata_171(void) */ static inline bool nrf_drv_usbd_errata_187(void) { - return NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_fp1(); + return (NRF_DRV_USBD_ERRATA_ENABLE && + (nrf_drv_usbd_errata_type_52840_eng_b() || + nrf_drv_usbd_errata_type_52840_eng_c() || + nrf_drv_usbd_errata_type_52840_eng_d()) + ); } /** - * @brief Function to check if chip requires errata ??? + * @brief Function to check if chip requires errata 199 * - * Errata: SIZE.EPOUT not writable + * Errata: USBD cannot receive tasks during DMA * * @retval true Errata should be implemented * @retval false Errata should not be implemented */ -static inline bool nrf_drv_usbd_errata_sizeepout_rw(void) +static inline bool nrf_drv_usb_errata_199(void) { - return NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_proto1(); + return (NRF_DRV_USBD_ERRATA_ENABLE && true); } /** - * @brief Function to check if chip requires errata 199 + * @brief Function to check if chip requires errata 200 * - * Errata: USBD cannot receive tasks during DMA + * Errata: SIZE.EPOUT not writable * * @retval true Errata should be implemented * @retval false Errata should not be implemented */ -static inline bool nrf_drv_usb_errata_199(void) +static inline bool nrf_drv_usbd_errata_200(void) { - return NRF_DRV_USBD_ERRATA_ENABLE && true; + return (NRF_DRV_USBD_ERRATA_ENABLE && nrf_drv_usbd_errata_type_52840_eng_a()); } /** @} */ diff --git a/src/tusb.c b/src/tusb.c index 81c4907fb..fe4dbb2c1 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -47,17 +47,17 @@ static bool _initialized = false;
-tusb_error_t tusb_init(void)
+bool tusb_init(void)
{
// skip if already initialized
- if (_initialized) return TUSB_ERROR_NONE;
+ if (_initialized) return true;
#if MODE_HOST_SUPPORTED
- TU_ASSERT_ERR( usbh_init() ); // host stack init
+ TU_VERIFY( usbh_init() == TUSB_ERROR_NONE ); // init host stack
#endif
#if TUSB_OPT_DEVICE_ENABLED
- TU_ASSERT_ERR ( usbd_init() ); // device stack init
+ TU_VERIFY ( usbd_init() ); // init device stack
#endif
_initialized = true;
diff --git a/src/tusb.h b/src/tusb.h index c0246ccc8..4f8918ce5 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -101,16 +101,14 @@ /** \ingroup group_application_api
* @{ */
-/** \brief Initialize the usb stack
- * \return Error Code of the \ref TUSB_ERROR enum
- * \note Function will initialize the stack according to configuration in the configure file (tusb_config.h)
- */
-tusb_error_t tusb_init(void);
+// Initialize device/host stack according to tusb_config.h
+// 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, so it should be called periodically within the mainloop
+ * & callback are invoked within this function. This should be called periodically within the mainloop
*
@code
int main(void)
diff --git a/src/tusb_hal.h b/src/tusb_hal.h index 301e8c2f2..e02ff480d 100644 --- a/src/tusb_hal.h +++ b/src/tusb_hal.h @@ -53,40 +53,9 @@ extern "C" { //--------------------------------------------------------------------+
// Only required to implement if using No RTOS (osal_none)
+// TODO could be remove
uint32_t tusb_hal_millis(void);
-// TODO remove
-extern void dcd_int_enable (uint8_t rhport);
-extern void dcd_int_disable(uint8_t rhport);
-
-// Enable all ports' interrupt
-// TODO remove
-static inline void tusb_hal_int_enable_all(void)
-{
-#ifdef CFG_TUSB_RHPORT0_MODE
- dcd_int_enable(0);
-#endif
-
-#ifdef CFG_TUSB_RHPORT0_MODE
- dcd_int_enable(1);
-#endif
-}
-
-// Disable all ports' interrupt
-// TODO remove
-static inline void tusb_hal_int_disable_all(void)
-{
-#ifdef CFG_TUSB_RHPORT0_MODE
- dcd_int_disable(0);
-#endif
-
-#ifdef CFG_TUSB_RHPORT0_MODE
- dcd_int_disable(1);
-#endif
-}
-
-
-
#ifdef __cplusplus
}
#endif
diff --git a/src/tusb_option.h b/src/tusb_option.h index c558b30ff..6b84db21c 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -123,7 +123,6 @@ // Which roothub port is configured as device
#define TUD_OPT_RHPORT ( (CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE) ? 0 : ((CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE) ? 1 : -1) )
-
#if TUD_OPT_RHPORT == 0
#define TUD_OPT_HIGH_SPEED ( CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED )
#else
|
