From 424735d44041fc478b572f973d997829b402153d Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 18 Jun 2018 14:05:24 +0700 Subject: rename subfolder source to src --- src/osal/osal.h | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/osal/osal.h (limited to 'src/osal/osal.h') diff --git a/src/osal/osal.h b/src/osal/osal.h new file mode 100644 index 000000000..669159607 --- /dev/null +++ b/src/osal/osal.h @@ -0,0 +1,96 @@ +/**************************************************************************/ +/*! + @file osal.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. +*/ +/**************************************************************************/ + +#ifndef _TUSB_OSAL_H_ +#define _TUSB_OSAL_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +/** \addtogroup group_osal + * @{ */ + +#include "tusb_option.h" +#include "common/tusb_common.h" + +enum +{ + OSAL_TIMEOUT_NOTIMEOUT = 0, // return immediately + OSAL_TIMEOUT_NORMAL = 10, // default timeout + OSAL_TIMEOUT_WAIT_FOREVER = 0xFFFFFFFFUL +}; + +#define OSAL_TIMEOUT_CONTROL_XFER OSAL_TIMEOUT_WAIT_FOREVER + + +#if CFG_TUSB_OS == OPT_OS_NONE + #include "osal_none.h" + +#else + #if CFG_TUSB_OS == OPT_OS_FREERTOS + #include "osal_freeRTOS.h" + #else + #error CFG_TUSB_OS is not defined or OS is not supported yet + #endif + + #define OSAL_TASK_BEGIN while(1) { + #define OSAL_TASK_END } + + //------------- Sub Task -------------// + #define OSAL_SUBTASK_BEGIN + #define OSAL_SUBTASK_END return TUSB_ERROR_NONE; + + #define STASK_RETURN(_error) return _error; + #define STASK_INVOKE(_subtask, _status) (_status) = _subtask + + //------------- Sub Task Assert -------------// + #define STASK_ASSERT_ERR(_err) VERIFY_ERR(_err) + #define STASK_ASSERT_ERR_HDLR(_err, _func) VERIFY_ERR_HDLR(_err, _func) + + #define STASK_ASSERT(_cond) VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED) + #define STASK_ASSERT_HDLR(_cond, _func) VERIFY_HDLR(_cond, _func) +#endif + +#ifdef __cplusplus + } +#endif + +/** @} */ + +#endif /* _TUSB_OSAL_H_ */ -- cgit v1.3.1 From d438000b99a5dbd5357d042fa48d0d87f180f032 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 22 Jun 2018 16:01:55 +0700 Subject: clean up --- src/device/usbd.c | 8 ++++++-- src/device/usbd_pvt.h | 2 +- src/osal/osal.h | 1 + src/osal/osal_freeRTOS.h | 2 +- src/osal/osal_none.h | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src/osal/osal.h') diff --git a/src/device/usbd.c b/src/device/usbd.c index 4332c2925..0f6cebc6c 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -182,7 +182,7 @@ typedef struct ATTR_ALIGNED(4) // USBD_EVT_FUNC_CALL struct { - void (*func)(void*); + osal_task_func_t func; void* param; }func_call; }; @@ -308,6 +308,10 @@ static tusb_error_t usbd_main_st(void) } } } + else if ( USBD_EVT_FUNC_CALL == event.event_id ) + { + if ( event.func_call.func ) event.func_call.func(event.func_call.param); + } else { STASK_ASSERT(false); @@ -631,7 +635,7 @@ 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(void (*func)(void*), void* param, bool isr ) +void usbd_defer_func(osal_task_func_t func, void* param, bool isr ) { usbd_task_event_t event = { diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index 4632fc52b..8189d5811 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -76,7 +76,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_d /*------------------------------------------------------------------*/ /* Other Helpers *------------------------------------------------------------------*/ -void usbd_defer_func( void (*func)(void*), void* param, bool isr ); +void usbd_defer_func( osal_task_func_t func, void* param, bool isr ); #ifdef __cplusplus diff --git a/src/osal/osal.h b/src/osal/osal.h index 669159607..7a8e6ecbf 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -58,6 +58,7 @@ enum #define OSAL_TIMEOUT_CONTROL_XFER OSAL_TIMEOUT_WAIT_FOREVER +typedef void (*osal_task_func_t)( void * ); #if CFG_TUSB_OS == OPT_OS_NONE #include "osal_none.h" diff --git a/src/osal/osal_freeRTOS.h b/src/osal/osal_freeRTOS.h index 6e6535da3..b14ed3100 100644 --- a/src/osal/osal_freeRTOS.h +++ b/src/osal/osal_freeRTOS.h @@ -71,7 +71,7 @@ static inline bool in_isr(void) typedef struct { - void (*func)(void *param); + osal_task_func_t func; uint16_t prio; uint16_t stack_sz; diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 0e29d110e..9bdb047b4 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -68,7 +68,7 @@ #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; +typedef void* osal_task_t; static inline osal_task_t osal_task_create(osal_task_def_t* taskdef) { -- cgit v1.3.1 From e07b1acbed02fff395c91b421b7fdf6c7cda61a4 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 13 Aug 2018 18:10:23 +0700 Subject: rename VERIFY to TU_VERIFY to avoid conflict with application --- examples/obsolete/host/src/cdc_serial_host_app.c | 2 +- examples/obsolete/host/src/keyboard_host_app.c | 2 +- examples/obsolete/host/src/mouse_host_app.c | 2 +- src/class/cdc/cdc.h | 6 +- src/class/cdc/cdc_device.c | 4 +- src/class/cdc/cdc_rndis.h | 4 +- src/class/cdc/cdc_rndis_host.c | 2 +- src/class/hid/hid_device.c | 12 ++-- src/class/hid/hid_host.c | 2 +- src/class/msc/msc.h | 32 ++++----- src/class/msc/msc_device.c | 2 +- src/class/msc/msc_device.h | 2 +- src/common/tusb_compiler.h | 6 +- src/common/tusb_types.h | 2 +- src/common/tusb_verify.h | 78 +++++++++++----------- src/device/usbd.c | 8 +-- src/host/ehci/ehci.c | 4 +- src/host/ehci/ehci.h | 10 +-- src/host/hub.h | 6 +- src/host/ohci/ohci.h | 10 +-- src/osal/osal.h | 8 +-- src/osal/osal_none.h | 8 +-- .../nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c | 2 +- src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c | 6 +- src/portable/nxp/lpc17xx/dcd_lpc175x_6x.h | 2 +- src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c | 8 +-- src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.h | 4 +- src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c | 2 +- src/tusb.c | 2 +- 29 files changed, 119 insertions(+), 119 deletions(-) (limited to 'src/osal/osal.h') diff --git a/examples/obsolete/host/src/cdc_serial_host_app.c b/examples/obsolete/host/src/cdc_serial_host_app.c index 0782d0518..e21a3a67d 100644 --- a/examples/obsolete/host/src/cdc_serial_host_app.c +++ b/examples/obsolete/host/src/cdc_serial_host_app.c @@ -115,7 +115,7 @@ void cdc_serial_host_app_init(void) sem_hdl = osal_semaphore_create(1, 0); TU_ASSERT( sem_hdl, VOID_RETURN); - VERIFY( osal_task_create(cdc_serial_host_app_task, "cdc", 128, NULL, CDC_SERIAL_APP_TASK_PRIO), ); + TU_VERIFY( osal_task_create(cdc_serial_host_app_task, "cdc", 128, NULL, CDC_SERIAL_APP_TASK_PRIO), ); } //------------- main task -------------// diff --git a/examples/obsolete/host/src/keyboard_host_app.c b/examples/obsolete/host/src/keyboard_host_app.c index 130df0feb..26b1a0800 100644 --- a/examples/obsolete/host/src/keyboard_host_app.c +++ b/examples/obsolete/host/src/keyboard_host_app.c @@ -105,7 +105,7 @@ void keyboard_host_app_init(void) queue_kbd_hdl = osal_queue_create( QUEUE_KEYBOARD_REPORT_DEPTH, sizeof(hid_keyboard_report_t) ); TU_ASSERT( queue_kbd_hdl, VOID_RETURN ); - VERIFY( osal_task_create(keyboard_host_app_task, "kbd", 128, NULL, KEYBOARD_APP_TASK_PRIO), ); + TU_VERIFY( osal_task_create(keyboard_host_app_task, "kbd", 128, NULL, KEYBOARD_APP_TASK_PRIO), ); } //------------- main task -------------// diff --git a/examples/obsolete/host/src/mouse_host_app.c b/examples/obsolete/host/src/mouse_host_app.c index e9ee482d8..c326becb8 100644 --- a/examples/obsolete/host/src/mouse_host_app.c +++ b/examples/obsolete/host/src/mouse_host_app.c @@ -106,7 +106,7 @@ void mouse_host_app_init(void) queue_mouse_hdl = osal_queue_create( QUEUE_MOUSE_REPORT_DEPTH, sizeof(hid_mouse_report_t) ); TU_ASSERT( queue_mouse_hdl, VOID_RETURN); - VERIFY( osal_task_create(mouse_host_app_task, "mouse", 128, NULL, MOUSE_APP_TASK_PRIO), ); + TU_VERIFY( osal_task_create(mouse_host_app_task, "mouse", 128, NULL, MOUSE_APP_TASK_PRIO), ); } //------------- main task -------------// diff --git a/src/class/cdc/cdc.h b/src/class/cdc/cdc.h index b0c4f90d4..1b127ad28 100644 --- a/src/class/cdc/cdc.h +++ b/src/class/cdc/cdc.h @@ -300,7 +300,7 @@ typedef struct ATTR_PACKED uint8_t : 0; }cdc_acm_capability_t; -VERIFY_STATIC(sizeof(cdc_acm_capability_t) == 1, "mostly problem with compiler"); +TU_VERIFY_STATIC(sizeof(cdc_acm_capability_t) == 1, "mostly problem with compiler"); /// \brief Abstract Control Management Functional Descriptor /// \details This functional descriptor describes the commands supported by by the Communications Class interface with SubClass code of \ref CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL @@ -390,7 +390,7 @@ typedef struct ATTR_PACKED uint8_t data_bits; ///< can be 5, 6, 7, 8 or 16 } cdc_line_coding_t; -VERIFY_STATIC(sizeof(cdc_line_coding_t) == 7, "size is not correct"); +TU_VERIFY_STATIC(sizeof(cdc_line_coding_t) == 7, "size is not correct"); typedef struct ATTR_PACKED { @@ -399,7 +399,7 @@ typedef struct ATTR_PACKED uint16_t : 14; } cdc_line_control_state_t; -VERIFY_STATIC(sizeof(cdc_line_control_state_t) == 2, "size is not correct"); +TU_VERIFY_STATIC(sizeof(cdc_line_control_state_t) == 2, "size is not correct"); /** @} */ diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index bbf1c8ceb..175e78d2f 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -157,11 +157,11 @@ uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize) bool tud_cdc_n_write_flush (uint8_t itf) { cdcd_interface_t* p_cdc = &_cdcd_itf[itf]; - VERIFY( !dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete + TU_VERIFY( !dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete uint16_t count = tu_fifo_read_n(&_cdcd_itf[itf].tx_ff, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE); - VERIFY( tud_cdc_n_connected(itf) ); // fifo is empty if not connected + TU_VERIFY( tud_cdc_n_connected(itf) ); // fifo is empty if not connected if ( count ) TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epout_buf, count) ); diff --git a/src/class/cdc/cdc_rndis.h b/src/class/cdc/cdc_rndis.h index 460477eb0..20da5660b 100644 --- a/src/class/cdc/cdc_rndis.h +++ b/src/class/cdc/cdc_rndis.h @@ -142,7 +142,7 @@ typedef struct { uint8_t oid_buffer[] ; ///< Flexible array contains the input data supplied by the host, required for the OID query request processing by the device, as per the host NDIS specification. } rndis_msg_query_t, rndis_msg_set_t; -VERIFY_STATIC(sizeof(rndis_msg_query_t) == 28, "Make sure flexible array member does not affect layout"); +TU_VERIFY_STATIC(sizeof(rndis_msg_query_t) == 28, "Make sure flexible array member does not affect layout"); /// \brief Query Complete Message /// \details This message MUST be sent by the device in response to a query OID message. @@ -156,7 +156,7 @@ typedef struct { uint8_t oid_buffer[] ; ///< Flexible array member contains the response data to the OID query request as specified by the host. } rndis_msg_query_cmplt_t; -VERIFY_STATIC(sizeof(rndis_msg_query_cmplt_t) == 24, "Make sure flexible array member does not affect layout"); +TU_VERIFY_STATIC(sizeof(rndis_msg_query_cmplt_t) == 24, "Make sure flexible array member does not affect layout"); //------------- Reset -------------// /// \brief Reset Message diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c index 62361feb4..4d28b0e0c 100644 --- a/src/class/cdc/cdc_rndis_host.c +++ b/src/class/cdc/cdc_rndis_host.c @@ -75,7 +75,7 @@ static tusb_error_t send_message_get_response_subtask( uint8_t dev_addr, cdch_da tusb_error_t tusbh_cdc_rndis_get_mac_addr(uint8_t dev_addr, uint8_t mac_address[6]) { TU_ASSERT( tusbh_cdc_rndis_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); - VERIFY( mac_address, TUSB_ERROR_INVALID_PARA); + TU_VERIFY( mac_address, TUSB_ERROR_INVALID_PARA); memcpy(mac_address, rndish_data[dev_addr-1].mac_address, 6); diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 0527c14bf..410359e6d 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -125,7 +125,7 @@ bool tud_hid_generic_ready(void) bool tud_hid_generic_report(uint8_t report_id, void const* report, uint8_t len) { - VERIFY( tud_hid_generic_ready() && (len < REPORT_BUFSIZE) ); + TU_VERIFY( tud_hid_generic_ready() && (len < REPORT_BUFSIZE) ); hidd_interface_t * p_hid = &_hidd_itf[ITF_IDX_GENERIC]; @@ -159,7 +159,7 @@ bool tud_hid_keyboard_is_boot_protocol(void) static bool hidd_kbd_report(hid_keyboard_report_t const *p_report) { - VERIFY( tud_hid_keyboard_ready() ); + TU_VERIFY( tud_hid_keyboard_ready() ); hidd_interface_t * p_hid = _kbd_rpt.itf; @@ -253,7 +253,7 @@ bool tud_hid_mouse_is_boot_protocol(void) static bool hidd_mouse_report(hid_mouse_report_t const *p_report) { - VERIFY( tud_hid_mouse_ready() ); + TU_VERIFY( tud_hid_mouse_ready() ); hidd_interface_t * p_hid = _mse_rpt.itf; memcpy(p_hid->report_buf, p_report, sizeof(hid_mouse_report_t)); @@ -277,7 +277,7 @@ bool tud_hid_mouse_data(uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8 bool tud_hid_mouse_move(int8_t x, int8_t y) { - VERIFY( tud_hid_mouse_ready() ); + TU_VERIFY( tud_hid_mouse_ready() ); hidd_interface_t * p_hid = _mse_rpt.itf; uint8_t prev_buttons = p_hid->report_buf[0]; @@ -287,7 +287,7 @@ bool tud_hid_mouse_move(int8_t x, int8_t y) bool tud_hid_mouse_scroll(int8_t vertical, int8_t horizontal) { - VERIFY( tud_hid_mouse_ready() ); + TU_VERIFY( tud_hid_mouse_ready() ); hidd_interface_t * p_hid = _mse_rpt.itf; uint8_t prev_buttons = p_hid->report_buf[0]; @@ -390,7 +390,7 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u TU_ASSERT(p_hid, ERR_TUD_INVALID_DESCRIPTOR); } - VERIFY(p_hid->desc_report, ERR_TUD_INVALID_DESCRIPTOR); + TU_VERIFY(p_hid->desc_report, ERR_TUD_INVALID_DESCRIPTOR); TU_ASSERT( dcd_edpt_open(rhport, desc_edpt), ERR_TUD_EDPT_OPEN_FAILED ); p_hid->itf_num = desc_itf->bInterfaceNumber; diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index fa617c5b0..369dad638 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -77,7 +77,7 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int //------------- parameters validation -------------// // TODO change to use is configured function TU_ASSERT (TUSB_DEVICE_STATE_CONFIGURED == tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY); - VERIFY (report, TUSB_ERROR_INVALID_PARA); + TU_VERIFY (report, TUSB_ERROR_INVALID_PARA); TU_ASSSERT (!hcd_pipe_is_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY); TU_ASSERT_ERR( hcd_pipe_xfer(p_hid->pipe_hdl, report, p_hid->report_size, true) ) ; diff --git a/src/class/msc/msc.h b/src/class/msc/msc.h index ab8f066b3..ca5615055 100644 --- a/src/class/msc/msc.h +++ b/src/class/msc/msc.h @@ -109,7 +109,7 @@ typedef struct ATTR_PACKED uint8_t command[16] ; ///< The command block to be executed by the device. The device shall interpret the first cmd_len bytes in this field as a command block }msc_cbw_t; -VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct"); +TU_VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct"); /// Command Status Wrapper typedef struct ATTR_PACKED @@ -120,7 +120,7 @@ typedef struct ATTR_PACKED uint8_t status ; ///< indicates the success or failure of the command. Values from \ref msc_csw_status_t }msc_csw_t; -VERIFY_STATIC(sizeof(msc_csw_t) == 13, "size is not correct"); +TU_VERIFY_STATIC(sizeof(msc_csw_t) == 13, "size is not correct"); //--------------------------------------------------------------------+ // SCSI Constant @@ -173,7 +173,7 @@ typedef struct ATTR_PACKED uint8_t control ; } scsi_test_unit_ready_t; -VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct"); +TU_VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct"); /// SCSI Inquiry Command typedef struct ATTR_PACKED @@ -186,7 +186,7 @@ typedef struct ATTR_PACKED uint8_t control ; } scsi_inquiry_t, scsi_request_sense_t; -VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct"); +TU_VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct"); /// SCSI Inquiry Response Data typedef struct ATTR_PACKED @@ -232,7 +232,7 @@ typedef struct ATTR_PACKED uint8_t product_rev[4]; ///< 4 bytes of ASCII data defined by the vendor. } scsi_inquiry_resp_t; -VERIFY_STATIC(sizeof(scsi_inquiry_resp_t) == 36, "size is not correct"); +TU_VERIFY_STATIC(sizeof(scsi_inquiry_resp_t) == 36, "size is not correct"); typedef struct ATTR_PACKED @@ -259,7 +259,7 @@ typedef struct ATTR_PACKED } scsi_sense_fixed_resp_t; -VERIFY_STATIC(sizeof(scsi_sense_fixed_resp_t) == 18, "size is not correct"); +TU_VERIFY_STATIC(sizeof(scsi_sense_fixed_resp_t) == 18, "size is not correct"); typedef struct ATTR_PACKED { @@ -277,7 +277,7 @@ typedef struct ATTR_PACKED uint8_t control; } scsi_mode_sense6_t; -VERIFY_STATIC( sizeof(scsi_mode_sense6_t) == 6, "size is not correct"); +TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_t) == 6, "size is not correct"); typedef struct ATTR_PACKED { @@ -287,7 +287,7 @@ typedef struct ATTR_PACKED uint8_t block_descriptor_len; } scsi_mode_sense6_resp_t; -VERIFY_STATIC( sizeof(scsi_mode_sense6_resp_t) == 4, "size is not correct"); +TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_resp_t) == 4, "size is not correct"); typedef struct ATTR_PACKED { @@ -297,7 +297,7 @@ typedef struct ATTR_PACKED uint8_t control; } scsi_prevent_allow_medium_removal_t; -VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct"); +TU_VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct"); typedef struct ATTR_PACKED { @@ -320,7 +320,7 @@ typedef struct ATTR_PACKED uint8_t control; } scsi_start_stop_unit_t; -VERIFY_STATIC( sizeof(scsi_start_stop_unit_t) == 6, "size is not correct"); +TU_VERIFY_STATIC( sizeof(scsi_start_stop_unit_t) == 6, "size is not correct"); //--------------------------------------------------------------------+ // SCSI MMC @@ -334,7 +334,7 @@ typedef struct ATTR_PACKED uint8_t control; } scsi_read_format_capacity_t; -VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct"); +TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct"); typedef struct ATTR_PACKED{ uint8_t reserved[3]; @@ -348,7 +348,7 @@ typedef struct ATTR_PACKED{ } scsi_read_format_capacity_data_t; -VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not correct"); +TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not correct"); //--------------------------------------------------------------------+ // SCSI Block Command (SBC-3) @@ -366,7 +366,7 @@ typedef struct ATTR_PACKED uint8_t control ; } scsi_read_capacity10_t; -VERIFY_STATIC(sizeof(scsi_read_capacity10_t) == 10, "size is not correct"); +TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_t) == 10, "size is not correct"); /// SCSI Read Capacity 10 Response Data typedef struct { @@ -374,7 +374,7 @@ typedef struct { uint32_t block_size ; ///< Block size in bytes } scsi_read_capacity10_resp_t; -VERIFY_STATIC(sizeof(scsi_read_capacity10_resp_t) == 8, "size is not correct"); +TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_resp_t) == 8, "size is not correct"); /// SCSI Read 10 Command typedef struct ATTR_PACKED @@ -387,8 +387,8 @@ typedef struct ATTR_PACKED uint8_t control ; } scsi_read10_t, scsi_write10_t; -VERIFY_STATIC(sizeof(scsi_read10_t) == 10, "size is not correct"); -VERIFY_STATIC(sizeof(scsi_write10_t) == 10, "size is not correct"); +TU_VERIFY_STATIC(sizeof(scsi_read10_t) == 10, "size is not correct"); +TU_VERIFY_STATIC(sizeof(scsi_write10_t) == 10, "size is not correct"); #ifdef __cplusplus } diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 27762805c..a11212c4b 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -152,7 +152,7 @@ void mscd_reset(uint8_t rhport) tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) { // only support SCSI's BOT protocol - VERIFY( ( MSC_SUBCLASS_SCSI == p_desc_itf->bInterfaceSubClass && + TU_VERIFY( ( MSC_SUBCLASS_SCSI == p_desc_itf->bInterfaceSubClass && MSC_PROTOCOL_BOT == p_desc_itf->bInterfaceProtocol ), TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL ); mscd_interface_t * p_msc = &_mscd_itf; diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index 6080b10df..8403dfed9 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -47,7 +47,7 @@ //--------------------------------------------------------------------+ // Class Driver Configuration //--------------------------------------------------------------------+ -VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct"); +TU_VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct"); #ifndef CFG_TUD_MSC_MAXLUN #define CFG_TUD_MSC_MAXLUN 1 diff --git a/src/common/tusb_compiler.h b/src/common/tusb_compiler.h index 35a4cc928..09cc59633 100644 --- a/src/common/tusb_compiler.h +++ b/src/common/tusb_compiler.h @@ -56,12 +56,12 @@ #endif //--------------------------------------------------------------------+ -// Compile-time Assert (use VERIFY_STATIC to avoid name conflict) +// Compile-time Assert (use TU_VERIFY_STATIC to avoid name conflict) //--------------------------------------------------------------------+ #if defined(__ICCARM__) || (__STDC_VERSION__ >= 201112L ) - #define VERIFY_STATIC static_assert + #define TU_VERIFY_STATIC static_assert #else - #define VERIFY_STATIC(const_expr, _mess) enum { XSTRING_CONCAT_(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) } + #define TU_VERIFY_STATIC(const_expr, _mess) enum { XSTRING_CONCAT_(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) } #endif // allow debugger to watch any module-wide variables anywhere diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 1e8a5ef27..c3ed4f2bd 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -369,7 +369,7 @@ typedef struct ATTR_PACKED{ uint16_t wLength; } tusb_control_request_t; -VERIFY_STATIC( sizeof(tusb_control_request_t) == 8, "mostly compiler option issue"); +TU_VERIFY_STATIC( sizeof(tusb_control_request_t) == 8, "mostly compiler option issue"); // TODO move to somewhere suitable static inline uint8_t bm_request_type(uint8_t direction, uint8_t type, uint8_t recipient) diff --git a/src/common/tusb_verify.h b/src/common/tusb_verify.h index adcdfc97f..41c2b5be1 100644 --- a/src/common/tusb_verify.h +++ b/src/common/tusb_verify.h @@ -50,8 +50,8 @@ * * e.g * - * - VERIFY( cond ) will return false if cond is false - * - VERIFY( cond, err) will return err instead if cond is false + * - TU_VERIFY( cond ) will return false if cond is false + * - TU_VERIFY( cond, err) will return err instead if cond is false *------------------------------------------------------------------*/ #ifdef __cplusplus @@ -60,7 +60,7 @@ //--------------------------------------------------------------------+ -// VERIFY Helper +// TU_VERIFY Helper //--------------------------------------------------------------------+ #if CFG_TUSB_DEBUG >= 1 #include @@ -88,21 +88,21 @@ /* Macro Generator *------------------------------------------------------------------*/ -// Helper to implement optional parameter for VERIFY Macro family +// Helper to implement optional parameter for TU_VERIFY Macro family #define GET_3RD_ARG(arg1, arg2, arg3, ...) arg3 #define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4 -/*------------- Generator for VERIFY and VERIFY_HDLR -------------*/ -#define VERIFY_DEFINE(_cond, _handler, _ret) do { if ( !(_cond) ) { _handler; return _ret; } } while(0) +/*------------- Generator for TU_VERIFY and TU_VERIFY_HDLR -------------*/ +#define TU_VERIFY_DEFINE(_cond, _handler, _ret) do { if ( !(_cond) ) { _handler; return _ret; } } while(0) -/*------------- Generator for VERIFY_ERR and VERIFY_ERR_HDLR -------------*/ -#define VERIFY_ERR_DEF2(_error, _handler) \ +/*------------- Generator for TU_VERIFY_ERR and TU_VERIFY_ERR_HDLR -------------*/ +#define TU_VERIFY_ERR_DEF2(_error, _handler) \ do { \ uint32_t _err = (uint32_t)(_error); \ if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _err; }\ } while(0) -#define VERIFY_ERR_DEF3(_error, _handler, _ret) \ +#define TU_VERIFY_ERR_DEF3(_error, _handler, _ret) \ do { \ uint32_t _err = (uint32_t)(_error); \ if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _ret; }\ @@ -112,66 +112,66 @@ /*------------------------------------------------------------------*/ -/* VERIFY - * - VERIFY_1ARGS : return false if failed - * - VERIFY_2ARGS : return provided value if failed +/* TU_VERIFY + * - TU_VERIFY_1ARGS : return false if failed + * - TU_VERIFY_2ARGS : return provided value if failed *------------------------------------------------------------------*/ -#define VERIFY_1ARGS(_cond) VERIFY_DEFINE(_cond, , false) -#define VERIFY_2ARGS(_cond, _ret) VERIFY_DEFINE(_cond, , _ret) +#define TU_VERIFY_1ARGS(_cond) TU_VERIFY_DEFINE(_cond, , false) +#define TU_VERIFY_2ARGS(_cond, _ret) TU_VERIFY_DEFINE(_cond, , _ret) -#define VERIFY(...) GET_3RD_ARG(__VA_ARGS__, VERIFY_2ARGS, VERIFY_1ARGS)(__VA_ARGS__) +#define TU_VERIFY(...) GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_2ARGS, TU_VERIFY_1ARGS)(__VA_ARGS__) /*------------------------------------------------------------------*/ -/* VERIFY WITH HANDLER - * - VERIFY_HDLR_2ARGS : execute handler, return false if failed - * - VERIFY_HDLR_3ARGS : execute handler, return provided error if failed +/* TU_VERIFY WITH HANDLER + * - TU_VERIFY_HDLR_2ARGS : execute handler, return false if failed + * - TU_VERIFY_HDLR_3ARGS : execute handler, return provided error if failed *------------------------------------------------------------------*/ -#define VERIFY_HDLR_2ARGS(_cond, _handler) VERIFY_DEFINE(_cond, _handler, false) -#define VERIFY_HDLR_3ARGS(_cond, _handler, _ret) VERIFY_DEFINE(_cond, _handler, _ret) +#define TU_VERIFY_HDLR_2ARGS(_cond, _handler) TU_VERIFY_DEFINE(_cond, _handler, false) +#define TU_VERIFY_HDLR_3ARGS(_cond, _handler, _ret) TU_VERIFY_DEFINE(_cond, _handler, _ret) -#define VERIFY_HDLR(...) GET_4TH_ARG(__VA_ARGS__, VERIFY_HDLR_3ARGS, VERIFY_HDLR_2ARGS)(__VA_ARGS__) +#define TU_VERIFY_HDLR(...) GET_4TH_ARG(__VA_ARGS__, TU_VERIFY_HDLR_3ARGS, TU_VERIFY_HDLR_2ARGS)(__VA_ARGS__) /*------------------------------------------------------------------*/ -/* VERIFY STATUS - * - VERIFY_ERR_1ARGS : return status of condition if failed - * - VERIFY_ERR_2ARGS : return provided status code if failed +/* TU_VERIFY STATUS + * - TU_VERIFY_ERR_1ARGS : return status of condition if failed + * - TU_VERIFY_ERR_2ARGS : return provided status code if failed *------------------------------------------------------------------*/ -#define VERIFY_ERR_1ARGS(_error) VERIFY_ERR_DEF2(_error, ) -#define VERIFY_ERR_2ARGS(_error, _ret) VERIFY_ERR_DEF3(_error, ,_ret) +#define TU_VERIFY_ERR_1ARGS(_error) TU_VERIFY_ERR_DEF2(_error, ) +#define TU_VERIFY_ERR_2ARGS(_error, _ret) TU_VERIFY_ERR_DEF3(_error, ,_ret) -#define VERIFY_ERR(...) GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__) +#define TU_VERIFY_ERR(...) GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_ERR_2ARGS, TU_VERIFY_ERR_1ARGS)(__VA_ARGS__) /*------------------------------------------------------------------*/ -/* VERIFY STATUS WITH HANDLER - * - VERIFY_ERR_HDLR_2ARGS : execute handler, return status if failed - * - VERIFY_ERR_HDLR_3ARGS : execute handler, return provided error if failed +/* TU_VERIFY STATUS WITH HANDLER + * - TU_VERIFY_ERR_HDLR_2ARGS : execute handler, return status if failed + * - TU_VERIFY_ERR_HDLR_3ARGS : execute handler, return provided error if failed *------------------------------------------------------------------*/ -#define VERIFY_ERR_HDLR_2ARGS(_error, _handler) VERIFY_ERR_DEF2(_error, _handler) -#define VERIFY_ERR_HDLR_3ARGS(_error, _handler, _ret) VERIFY_ERR_DEF3(_error, _handler, _ret) +#define TU_VERIFY_ERR_HDLR_2ARGS(_error, _handler) TU_VERIFY_ERR_DEF2(_error, _handler) +#define TU_VERIFY_ERR_HDLR_3ARGS(_error, _handler, _ret) TU_VERIFY_ERR_DEF3(_error, _handler, _ret) -#define VERIFY_ERR_HDLR(...) GET_4TH_ARG(__VA_ARGS__, VERIFY_ERR_HDLR_3ARGS, VERIFY_ERR_HDLR_2ARGS)(__VA_ARGS__) +#define TU_VERIFY_ERR_HDLR(...) GET_4TH_ARG(__VA_ARGS__, TU_VERIFY_ERR_HDLR_3ARGS, TU_VERIFY_ERR_HDLR_2ARGS)(__VA_ARGS__) /*------------------------------------------------------------------*/ /* ASSERT - * basically VERIFY with verify_breakpoint() as handler + * basically TU_VERIFY with verify_breakpoint() as handler * - 1 arg : return false if failed * - 2 arg : return error if failed *------------------------------------------------------------------*/ -#define ASSERT_1ARGS(_cond) VERIFY_DEFINE(_cond, _MESS_FAILED(); verify_breakpoint(), false) -#define ASSERT_2ARGS(_cond, _ret) VERIFY_DEFINE(_cond, _MESS_FAILED(); verify_breakpoint(), _ret) +#define ASSERT_1ARGS(_cond) TU_VERIFY_DEFINE(_cond, _MESS_FAILED(); verify_breakpoint(), false) +#define ASSERT_2ARGS(_cond, _ret) TU_VERIFY_DEFINE(_cond, _MESS_FAILED(); verify_breakpoint(), _ret) #define TU_ASSERT(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS)(__VA_ARGS__) /*------------------------------------------------------------------*/ /* ASSERT Error - * basically VERIFY Error with verify_breakpoint() as handler + * basically TU_VERIFY Error with verify_breakpoint() as handler *------------------------------------------------------------------*/ -#define ASERT_ERR_1ARGS(_error) VERIFY_ERR_DEF2(_error, verify_breakpoint()) -#define ASERT_ERR_2ARGS(_error, _ret) VERIFY_ERR_DEF3(_error, verify_breakpoint(), _ret) +#define ASERT_ERR_1ARGS(_error) TU_VERIFY_ERR_DEF2(_error, verify_breakpoint()) +#define ASERT_ERR_2ARGS(_error, _ret) TU_VERIFY_ERR_DEF3(_error, verify_breakpoint(), _ret) #define TU_ASSERT_ERR(...) GET_3RD_ARG(__VA_ARGS__, ASERT_ERR_2ARGS, ASERT_ERR_1ARGS)(__VA_ARGS__) diff --git a/src/device/usbd.c b/src/device/usbd.c index 219562fa6..79ad8ffa2 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -189,7 +189,7 @@ typedef struct ATTR_ALIGNED(4) }; } usbd_task_event_t; -VERIFY_STATIC(sizeof(usbd_task_event_t) <= 12, "size is not correct"); +TU_VERIFY_STATIC(sizeof(usbd_task_event_t) <= 12, "size is not correct"); OSAL_TASK_DEF(_usbd_task_def, "usbd", usbd_task, CFG_TUD_TASK_PRIO, CFG_TUD_TASK_STACK_SZ); @@ -234,10 +234,10 @@ tusb_error_t usbd_init (void) //------------- Task init -------------// _usbd_q = osal_queue_create(&_usbd_qdef); - VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED); + TU_VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED); _usbd_ctrl_sem = osal_semaphore_create(&_usbd_sem_def); - VERIFY(_usbd_q, TUSB_ERROR_OSAL_SEMAPHORE_FAILED); + TU_VERIFY(_usbd_q, TUSB_ERROR_OSAL_SEMAPHORE_FAILED); osal_task_create(&_usbd_task_def); @@ -507,7 +507,7 @@ static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * co if ( desc_index < tud_desc_set.string_count ) { desc_data = tud_desc_set.string_arr[desc_index]; - VERIFY( desc_data != NULL, 0 ); + TU_VERIFY( desc_data != NULL, 0 ); len = desc_data[0]; // first byte of descriptor is its size }else diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 09f2f573a..32fcc8140 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -64,7 +64,7 @@ CFG_TUSB_ATTR_USBRAM STATIC_VAR ehci_data_t ehci_data; CFG_TUSB_ATTR_USBRAM ATTR_ALIGNED(4096) STATIC_VAR ehci_link_t period_frame_list0[EHCI_FRAMELIST_SIZE]; #ifndef __ICCARM__ // IAR cannot able to determine the alignment with datalignment pragma - VERIFY_STATIC( ALIGN_OF(period_frame_list0) == 4096, "Period Framelist must be 4k alginment"); // validation + TU_VERIFY_STATIC( ALIGN_OF(period_frame_list0) == 4096, "Period Framelist must be 4k alginment"); // validation #endif #endif @@ -72,7 +72,7 @@ CFG_TUSB_ATTR_USBRAM STATIC_VAR ehci_data_t ehci_data; CFG_TUSB_ATTR_USBRAM ATTR_ALIGNED(4096) STATIC_VAR ehci_link_t period_frame_list1[EHCI_FRAMELIST_SIZE]; #ifndef __ICCARM__ // IAR cannot able to determine the alignment with datalignment pragma - VERIFY_STATIC( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4k alginment"); // validation + TU_VERIFY_STATIC( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4k alginment"); // validation #endif #endif #endif diff --git a/src/host/ehci/ehci.h b/src/host/ehci/ehci.h index 250023ee5..f5180402b 100644 --- a/src/host/ehci/ehci.h +++ b/src/host/ehci/ehci.h @@ -81,7 +81,7 @@ enum { }; //------------- Validation -------------// -VERIFY_STATIC(EHCI_CFG_FRAMELIST_SIZE_BITS <= 7, "incorrect value"); +TU_VERIFY_STATIC(EHCI_CFG_FRAMELIST_SIZE_BITS <= 7, "incorrect value"); //--------------------------------------------------------------------+ // EHCI Data Structure @@ -150,7 +150,7 @@ typedef struct { uint32_t buffer[5]; } ehci_qtd_t; // XXX qtd is used to declare overlay in ehci_qhd_t -> cannot be declared with ATTR_ALIGNED(32) -VERIFY_STATIC( sizeof(ehci_qtd_t) == 32, "size is not correct" ); +TU_VERIFY_STATIC( sizeof(ehci_qtd_t) == 32, "size is not correct" ); /// Queue Head (section 3.6) typedef struct ATTR_ALIGNED(32) { @@ -202,7 +202,7 @@ typedef struct ATTR_ALIGNED(32) { ehci_qtd_t * volatile p_qtd_list_tail; // tail of the scheduled TD list } ehci_qhd_t; -VERIFY_STATIC( sizeof(ehci_qhd_t) == 64, "size is not correct" ); +TU_VERIFY_STATIC( sizeof(ehci_qhd_t) == 64, "size is not correct" ); /// Highspeed Isochronous Transfer Descriptor (section 3.3) typedef struct ATTR_ALIGNED(32) { @@ -234,7 +234,7 @@ typedef struct ATTR_ALIGNED(32) { // uint32_t reserved[6]; } ehci_itd_t; -VERIFY_STATIC( sizeof(ehci_itd_t) == 64, "size is not correct" ); +TU_VERIFY_STATIC( sizeof(ehci_itd_t) == 64, "size is not correct" ); /// Split (Full-Speed) Isochronous Transfer Descriptor typedef struct ATTR_ALIGNED(32) { @@ -298,7 +298,7 @@ typedef struct ATTR_ALIGNED(32) { uint8_t reserved2[2]; } ehci_sitd_t; -VERIFY_STATIC( sizeof(ehci_sitd_t) == 32, "size is not correct" ); +TU_VERIFY_STATIC( sizeof(ehci_sitd_t) == 32, "size is not correct" ); //--------------------------------------------------------------------+ // EHCI Operational Register diff --git a/src/host/hub.h b/src/host/hub.h index b8499275c..67c02f2e3 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -104,7 +104,7 @@ typedef struct ATTR_PACKED{ uint8_t PortPwrCtrlMask; // just for compatibility, should be 0xff } descriptor_hub_desc_t; -VERIFY_STATIC( sizeof(descriptor_hub_desc_t) == 9, "size is not correct"); +TU_VERIFY_STATIC( sizeof(descriptor_hub_desc_t) == 9, "size is not correct"); enum { HUB_REQUEST_GET_STATUS = 0 , @@ -157,7 +157,7 @@ typedef struct { } status, status_change; } hub_status_response_t; -VERIFY_STATIC( sizeof(hub_status_response_t) == 4, "size is not correct"); +TU_VERIFY_STATIC( sizeof(hub_status_response_t) == 4, "size is not correct"); // data in response of HUB_REQUEST_GET_STATUS, wIndex = Port num typedef struct { @@ -182,7 +182,7 @@ typedef struct { } status_current, status_change; } hub_port_status_response_t; -VERIFY_STATIC( sizeof(hub_port_status_response_t) == 4, "size is not correct"); +TU_VERIFY_STATIC( sizeof(hub_port_status_response_t) == 4, "size is not correct"); tusb_error_t hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port); tusb_error_t hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t feature); diff --git a/src/host/ohci/ohci.h b/src/host/ohci/ohci.h index f49d85261..c407b8ac1 100644 --- a/src/host/ohci/ohci.h +++ b/src/host/ohci/ohci.h @@ -79,7 +79,7 @@ typedef struct { uint8_t reserved[116+4]; // TODO try to make use of this area if possible, extra 4 byte to make the whole struct size = 256 }ohci_hcca_t; // ATTR_ALIGNED(256) -VERIFY_STATIC( sizeof(ohci_hcca_t) == 256, "size is not correct" ); +TU_VERIFY_STATIC( sizeof(ohci_hcca_t) == 256, "size is not correct" ); typedef struct { uint32_t reserved[2]; @@ -112,7 +112,7 @@ typedef struct ATTR_ALIGNED(16) { uint8_t* buffer_end; } ohci_gtd_t; -VERIFY_STATIC( sizeof(ohci_gtd_t) == 16, "size is not correct" ); +TU_VERIFY_STATIC( sizeof(ohci_gtd_t) == 16, "size is not correct" ); typedef struct ATTR_ALIGNED(16) { //------------- Word 0 -------------// @@ -153,7 +153,7 @@ typedef struct ATTR_ALIGNED(16) { uint32_t next_ed; // 4 lsb bits are free to use } ohci_ed_t; -VERIFY_STATIC( sizeof(ohci_ed_t) == 16, "size is not correct" ); +TU_VERIFY_STATIC( sizeof(ohci_ed_t) == 16, "size is not correct" ); typedef struct ATTR_ALIGNED(32) { /*---------- Word 1 ----------*/ @@ -178,7 +178,7 @@ typedef struct ATTR_ALIGNED(32) { volatile uint16_t offset_packetstatus[8]; } ochi_itd_t; -VERIFY_STATIC( sizeof(ochi_itd_t) == 32, "size is not correct" ); +TU_VERIFY_STATIC( sizeof(ochi_itd_t) == 32, "size is not correct" ); // structure with member alignment required from large to small typedef struct ATTR_ALIGNED(256) { @@ -298,7 +298,7 @@ typedef volatile struct }; }ohci_registers_t; -VERIFY_STATIC( sizeof(ohci_registers_t) == 0x5c, "size is not correct"); +TU_VERIFY_STATIC( sizeof(ohci_registers_t) == 0x5c, "size is not correct"); #ifdef __cplusplus } diff --git a/src/osal/osal.h b/src/osal/osal.h index 7a8e6ecbf..3e0d9d5f1 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -81,11 +81,11 @@ typedef void (*osal_task_func_t)( void * ); #define STASK_INVOKE(_subtask, _status) (_status) = _subtask //------------- Sub Task Assert -------------// - #define STASK_ASSERT_ERR(_err) VERIFY_ERR(_err) - #define STASK_ASSERT_ERR_HDLR(_err, _func) VERIFY_ERR_HDLR(_err, _func) + #define STASK_ASSERT_ERR(_err) TU_VERIFY_ERR(_err) + #define STASK_ASSERT_ERR_HDLR(_err, _func) TU_VERIFY_ERR_HDLR(_err, _func) - #define STASK_ASSERT(_cond) VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED) - #define STASK_ASSERT_HDLR(_cond, _func) VERIFY_HDLR(_cond, _func) + #define STASK_ASSERT(_cond) TU_VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED) + #define STASK_ASSERT_HDLR(_cond, _func) TU_VERIFY_HDLR(_cond, _func) #endif #ifdef __cplusplus diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index b8cd2893c..3531686b4 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -121,11 +121,11 @@ static inline osal_task_t osal_task_create(osal_task_def_t* taskdef) //------------- Sub Task Assert -------------// #define STASK_RETURN(error) do { TASK_RESTART; return error; } while(0) -#define STASK_ASSERT_ERR(_err) VERIFY_ERR_HDLR(_err, verify_breakpoint(); TASK_RESTART, TUSB_ERROR_FAILED) -#define STASK_ASSERT_ERR_HDLR(_err, _func) VERIFY_ERR_HDLR(_err, verify_breakpoint(); _func; TASK_RESTART, TUSB_ERROR_FAILED ) +#define STASK_ASSERT_ERR(_err) TU_VERIFY_ERR_HDLR(_err, verify_breakpoint(); TASK_RESTART, TUSB_ERROR_FAILED) +#define STASK_ASSERT_ERR_HDLR(_err, _func) TU_VERIFY_ERR_HDLR(_err, verify_breakpoint(); _func; TASK_RESTART, TUSB_ERROR_FAILED ) -#define STASK_ASSERT(_cond) VERIFY_HDLR(_cond, verify_breakpoint(); TASK_RESTART, TUSB_ERROR_FAILED) -#define STASK_ASSERT_HDLR(_cond, _func) VERIFY_HDLR(_cond, verify_breakpoint(); _func; TASK_RESTART, TUSB_ERROR_FAILED) +#define STASK_ASSERT(_cond) TU_VERIFY_HDLR(_cond, verify_breakpoint(); TASK_RESTART, TUSB_ERROR_FAILED) +#define STASK_ASSERT_HDLR(_cond, _func) TU_VERIFY_HDLR(_cond, verify_breakpoint(); _func; TASK_RESTART, TUSB_ERROR_FAILED) //--------------------------------------------------------------------+ // QUEUE API diff --git a/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c b/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c index 68eef47e1..0eaecf1b8 100644 --- a/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c +++ b/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c @@ -104,7 +104,7 @@ typedef struct ATTR_PACKED volatile uint16_t active : 1 ; ///< The buffer is enabled. HW can use the buffer to store received OUT data or to transmit data on the IN endpoint. Software can only set this bit to ‘1’. As long as this bit is set to one, software is not allowed to update any of the values in this 32-bit word. In case software wants to deactivate the buffer, it must write a one to the corresponding “skip” bit in the USB Endpoint skip register. Hardware can only write this bit to zero. It will do this when it receives a short packet or when the NBytes field transitions to zero or when software has written a one to the “skip” bit. }dcd_11u_13u_qhd_t; -VERIFY_STATIC( sizeof(dcd_11u_13u_qhd_t) == 4, "size is not correct" ); +TU_VERIFY_STATIC( sizeof(dcd_11u_13u_qhd_t) == 4, "size is not correct" ); // NOTE data will be transferred as soon as dcd get request by dcd_pipe(_queue)_xfer using double buffering. // If there is another dcd_edpt_xfer request, the new request will be saved and executed when the first is done. diff --git a/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c b/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c index 948572129..a87e7d899 100644 --- a/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c +++ b/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c @@ -384,7 +384,7 @@ bool dcd_control_xfer(uint8_t rhport, tusb_dir_t dir, uint8_t * p_buffer, uint16 { (void) rhport; - VERIFY( !(length != 0 && p_buffer == NULL) ); + TU_VERIFY( !(length != 0 && p_buffer == NULL) ); // determine Endpoint where Data & Status phase occurred (IN or OUT) uint8_t const ep_data = (dir == TUSB_DIR_IN) ? 1 : 0; @@ -399,13 +399,13 @@ bool dcd_control_xfer(uint8_t rhport, tusb_dir_t dir, uint8_t * p_buffer, uint16 dcd_data.control_dma.remaining_bytes = length; // lpc17xx already received the first DATA OUT packet by now - VERIFY_ERR ( pipe_control_xfer(ep_data, p_buffer, length), false ); + TU_VERIFY_ERR ( pipe_control_xfer(ep_data, p_buffer, length), false ); } //------------- Status Phase (opposite direct to Data) -------------// if (dir == TUSB_DIR_OUT) { // only write for CONTROL OUT, CONTROL IN data will be retrieved in hal_dcd_isr // TODO ???? - VERIFY_ERR ( pipe_control_write(NULL, 0), false ); + TU_VERIFY_ERR ( pipe_control_write(NULL, 0), false ); } return true; diff --git a/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.h b/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.h index 1df1fcd30..4746b4acf 100644 --- a/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.h +++ b/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.h @@ -80,7 +80,7 @@ typedef struct ATTR_ALIGNED(4) // uint32_t iso_packet_size_addr; // iso only, can be omitted for non-iso }dcd_dma_descriptor_t; -VERIFY_STATIC( sizeof(dcd_dma_descriptor_t) == 16, "size is not correct"); // TODO not support ISO for now +TU_VERIFY_STATIC( sizeof(dcd_dma_descriptor_t) == 16, "size is not correct"); // TODO not support ISO for now //--------------------------------------------------------------------+ diff --git a/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c b/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c index 0b48ad1e6..61f829713 100644 --- a/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c +++ b/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c @@ -244,7 +244,7 @@ bool dcd_control_xfer(uint8_t rhport, tusb_dir_t dir, uint8_t * p_buffer, uint16 // wait until ENDPTSETUPSTAT before priming data/status in response TODO add time out while(lpc_usb->ENDPTSETUPSTAT & BIT_(0)) {} - VERIFY( !qhd->qtd_overlay.active ); + TU_VERIFY( !qhd->qtd_overlay.active ); dcd_qtd_t* qtd = &p_dcd->qtd[0]; qtd_init(qtd, p_buffer, length); @@ -295,7 +295,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) { // TODO USB1 only has 4 non-control enpoint (USB0 has 5) // TODO not support ISO yet - VERIFY ( p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); + TU_VERIFY ( p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); tusb_dir_t dir = (p_endpoint_desc->bEndpointAddress & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT; @@ -313,7 +313,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) volatile uint32_t * reg_control = get_reg_control_addr(rhport, ep_idx); // endpoint must not be already enabled - VERIFY( !( (*reg_control) & (ENDPTCTRL_MASK_ENABLE << (dir ? 16 : 0)) ) ); + TU_VERIFY( !( (*reg_control) & (ENDPTCTRL_MASK_ENABLE << (dir ? 16 : 0)) ) ); (*reg_control) |= ((p_endpoint_desc->bmAttributes.xfer << 2) | ENDPTCTRL_MASK_ENABLE | ENDPTCTRL_MASK_TOGGLE_RESET) << (dir ? 16 : 0); @@ -363,7 +363,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t { uint8_t ep_idx = edpt_addr2phy(ep_addr); - VERIFY ( pipe_add_xfer(rhport, ep_idx, buffer, total_bytes, true) ); + TU_VERIFY ( pipe_add_xfer(rhport, ep_idx, buffer, total_bytes, true) ); dcd_qhd_t* p_qhd = &dcd_data_ptr[rhport]->qhd[ ep_idx ]; dcd_qtd_t* p_qtd = &dcd_data_ptr[rhport]->qtd[ p_qhd->list_qtd_idx[0] ]; diff --git a/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.h b/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.h index 92e24c1fb..1476c0d30 100644 --- a/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.h +++ b/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.h @@ -122,7 +122,7 @@ typedef struct uint8_t reserved; } dcd_qtd_t; -VERIFY_STATIC( sizeof(dcd_qtd_t) == 32, "size is not correct"); +TU_VERIFY_STATIC( sizeof(dcd_qtd_t) == 32, "size is not correct"); typedef struct { @@ -153,7 +153,7 @@ typedef struct uint8_t reserved[16-DCD_QTD_PER_QHD_MAX]; } dcd_qhd_t; -VERIFY_STATIC( sizeof(dcd_qhd_t) == 64, "size is not correct"); +TU_VERIFY_STATIC( sizeof(dcd_qhd_t) == 64, "size is not correct"); #ifdef __cplusplus diff --git a/src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c b/src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c index 18745d03e..213b8dd99 100644 --- a/src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c +++ b/src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c @@ -86,7 +86,7 @@ bool tusb_hal_init(void) //------------- USB0 -------------// #if CFG_TUSB_RHPORT0_MODE CGU_EnableEntity(CGU_CLKSRC_PLL0, DISABLE); /* Disable PLL first */ - VERIFY( CGU_ERROR_SUCCESS == CGU_SetPLL0()); /* the usb core require output clock = 480MHz */ + TU_VERIFY( CGU_ERROR_SUCCESS == CGU_SetPLL0()); /* the usb core require output clock = 480MHz */ CGU_EntityConnect(CGU_CLKSRC_XTAL_OSC, CGU_CLKSRC_PLL0); CGU_EnableEntity(CGU_CLKSRC_PLL0, ENABLE); /* Enable PLL after all setting is done */ diff --git a/src/tusb.c b/src/tusb.c index 0ef1301a4..b064d03f9 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -49,7 +49,7 @@ tusb_error_t tusb_init(void) // skip if already initialized if (_initialized) return TUSB_ERROR_NONE; - VERIFY( tusb_hal_init(), TUSB_ERROR_FAILED ) ; // hardware init + TU_VERIFY( tusb_hal_init(), TUSB_ERROR_FAILED ) ; // hardware init #if MODE_HOST_SUPPORTED TU_ASSERT_ERR( usbh_init() ); // host stack init -- cgit v1.3.1 From 4ef01d721ad6b49775f067d89faa5545d918f32f Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 30 Aug 2018 15:21:15 +0700 Subject: clean up osal task and subtask --- src/device/usbd.c | 9 ++++++--- src/osal/osal.h | 4 +++- src/osal/osal_none.h | 25 +++++++++---------------- 3 files changed, 18 insertions(+), 20 deletions(-) (limited to 'src/osal/osal.h') diff --git a/src/device/usbd.c b/src/device/usbd.c index 8f1f6be90..2f760808b 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -107,7 +107,7 @@ static usbd_class_driver_t const usbd_class_drivers[] = .open = cdcd_open, .control_req_st = cdcd_control_request_st, .xfer_cb = cdcd_xfer_cb, - .sof = cdcd_sof, + .sof = NULL, .reset = cdcd_reset }, #endif @@ -250,6 +250,9 @@ tusb_error_t usbd_init (void) // To enable the TASK_ASSERT style (quick return on false condition) in a real RTOS, a task must act as a wrapper // and is used mainly to call subtasks. Within a subtask return statement can be called freely, the task with // forever loop cannot have any return at all. + +// Within tinyusb stack, all task's code must be placed in subtask to be able to support multiple RTOS +// including none. void usbd_task( void* param) { (void) param; @@ -306,7 +309,7 @@ static tusb_error_t usbd_main_st(void) } else { - STASK_ASSERT(false); + verify_breakpoint(); } } @@ -577,7 +580,7 @@ void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event) case USBD_BUS_EVENT_SOF: { - #if CFG_TUD_CDC_FLUSH_ON_SOF + #if 0 usbd_task_event_t task_event = { .rhport = rhport, diff --git a/src/osal/osal.h b/src/osal/osal.h index 3e0d9d5f1..16dc8da27 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -61,8 +61,10 @@ 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" diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 3531686b4..012de9c78 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -79,18 +79,6 @@ static inline osal_task_t osal_task_create(osal_task_def_t* taskdef) #define TASK_RESTART \ _state = 0 -#define OSAL_TASK_BEGIN \ - static uint16_t _state = 0; \ - ATTR_UNUSED static uint32_t _timeout = 0; \ - (void) _timeout; \ - switch(_state) { \ - case 0: { - -#define OSAL_TASK_END \ - default: TASK_RESTART; break; \ - }} \ - return; - #define osal_task_delay(msec) \ do { \ _timeout = tusb_hal_millis(); \ @@ -102,11 +90,16 @@ static inline osal_task_t osal_task_create(osal_task_def_t* taskdef) //--------------------------------------------------------------------+ // SUBTASK (a sub function that uses OS blocking services & called by a task //--------------------------------------------------------------------+ -#define OSAL_SUBTASK_BEGIN OSAL_TASK_BEGIN +#define OSAL_SUBTASK_BEGIN \ + static uint16_t _state = 0; \ + ATTR_UNUSED static uint32_t _timeout = 0; \ + (void) _timeout; \ + switch(_state) { \ + case 0: { -#define OSAL_SUBTASK_END \ - default: TASK_RESTART; break; \ - }} \ +#define OSAL_SUBTASK_END \ + default: TASK_RESTART; break; \ + }} \ return TUSB_ERROR_NONE; #define STASK_INVOKE(_subtask, _status) \ -- cgit v1.3.1 From e6fdfe8ac722a8b3ba89e47e827e7297195f9a99 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 2 Sep 2018 20:37:02 +0700 Subject: rename file --- src/osal/osal.h | 2 +- src/osal/osal_freeRTOS.h | 200 ----------------------------------------------- src/osal/osal_freertos.h | 200 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 201 deletions(-) delete mode 100644 src/osal/osal_freeRTOS.h create mode 100644 src/osal/osal_freertos.h (limited to 'src/osal/osal.h') diff --git a/src/osal/osal.h b/src/osal/osal.h index 16dc8da27..8af1d5b31 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -67,7 +67,7 @@ typedef void (*osal_task_func_t)( void * ); #include "osal_none.h" #else #if CFG_TUSB_OS == OPT_OS_FREERTOS - #include "osal_freeRTOS.h" + #include "osal_freertos.h" #else #error CFG_TUSB_OS is not defined or OS is not supported yet #endif diff --git a/src/osal/osal_freeRTOS.h b/src/osal/osal_freeRTOS.h deleted file mode 100644 index 321b00ac7..000000000 --- a/src/osal/osal_freeRTOS.h +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************/ -/*! - @file osal_freeRTOS.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 group_osal - * @{ - * \defgroup Group_FreeRTOS FreeRTOS - * @{ */ - -#ifndef _TUSB_OSAL_FREERTOS_H_ -#define _TUSB_OSAL_FREERTOS_H_ - -//------------- FreeRTOS Headers -------------// -#include "FreeRTOS.h" -#include "semphr.h" -#include "queue.h" -#include "task.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if 0 -// Helper to determine if we are in ISR to use ISR API (only cover ARM Cortex) -static inline bool in_isr(void) -{ - return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk); -} -#endif - -//--------------------------------------------------------------------+ -// TASK API -//--------------------------------------------------------------------+ -#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) \ - 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; - -typedef TaskHandle_t osal_task_t; - -static inline osal_task_t 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); -} - -static inline void osal_task_delay(uint32_t msec) -{ - vTaskDelay( pdMS_TO_TICKS(msec) ); -} - -//--------------------------------------------------------------------+ -// QUEUE API -//--------------------------------------------------------------------+ -#define OSAL_QUEUE_DEF(_name, _depth, _type) \ - uint8_t _name##_##buf[_depth*sizeof(_type)];\ - osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; - -typedef struct -{ - uint16_t depth; - uint16_t item_sz; - void* buf; - - StaticQueue_t sq; -}osal_queue_def_t; - -typedef QueueHandle_t osal_queue_t; - -static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) -{ - return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); -} - -static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) -{ - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - (*p_error) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); -} - -static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data) -{ - return xQueueSendToBackFromISR(queue_hdl, data, NULL); -} - -static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data) -{ - return xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER) == pdTRUE; -} - -static inline void osal_queue_flush(osal_queue_t const queue_hdl) -{ - // TODO move to thread context -// xQueueReset(queue_hdl); -} - -//--------------------------------------------------------------------+ -// Semaphore API -//--------------------------------------------------------------------+ -typedef StaticSemaphore_t osal_semaphore_def_t; -typedef SemaphoreHandle_t osal_semaphore_t; - -static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) -{ - return xSemaphoreCreateBinaryStatic(semdef); -} - -static inline bool osal_semaphore_post_isr(osal_semaphore_t sem_hdl) -{ - return xSemaphoreGiveFromISR(sem_hdl, NULL) == pdTRUE; -} - -static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) -{ - return xSemaphoreGive(sem_hdl) == pdTRUE; -} - -static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) -{ - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - (*p_error) = (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); -} - -static inline void osal_semaphore_reset_isr(osal_semaphore_t const sem_hdl) -{ - xSemaphoreTakeFromISR(sem_hdl, NULL); -} - -//--------------------------------------------------------------------+ -// MUTEX API (priority inheritance) -//--------------------------------------------------------------------+ -typedef SemaphoreHandle_t osal_mutex_t; - -#define osal_mutex_create(x) xSemaphoreCreateMutex() - -static inline bool osal_mutex_release(osal_mutex_t mutex_hdl) -{ - return xSemaphoreGive(mutex_hdl); -} - -static inline void osal_mutex_wait(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error) -{ - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - (*p_error) = (xSemaphoreTake(mutex_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); -} - - -#ifdef __cplusplus - } -#endif - -#endif /* _TUSB_OSAL_FREERTOS_H_ */ - -/** @} */ -/** @} */ - diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h new file mode 100644 index 000000000..321b00ac7 --- /dev/null +++ b/src/osal/osal_freertos.h @@ -0,0 +1,200 @@ +/**************************************************************************/ +/*! + @file osal_freeRTOS.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 group_osal + * @{ + * \defgroup Group_FreeRTOS FreeRTOS + * @{ */ + +#ifndef _TUSB_OSAL_FREERTOS_H_ +#define _TUSB_OSAL_FREERTOS_H_ + +//------------- FreeRTOS Headers -------------// +#include "FreeRTOS.h" +#include "semphr.h" +#include "queue.h" +#include "task.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if 0 +// Helper to determine if we are in ISR to use ISR API (only cover ARM Cortex) +static inline bool in_isr(void) +{ + return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk); +} +#endif + +//--------------------------------------------------------------------+ +// TASK API +//--------------------------------------------------------------------+ +#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) \ + 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; + +typedef TaskHandle_t osal_task_t; + +static inline osal_task_t 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); +} + +static inline void osal_task_delay(uint32_t msec) +{ + vTaskDelay( pdMS_TO_TICKS(msec) ); +} + +//--------------------------------------------------------------------+ +// QUEUE API +//--------------------------------------------------------------------+ +#define OSAL_QUEUE_DEF(_name, _depth, _type) \ + uint8_t _name##_##buf[_depth*sizeof(_type)];\ + osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; + +typedef struct +{ + uint16_t depth; + uint16_t item_sz; + void* buf; + + StaticQueue_t sq; +}osal_queue_def_t; + +typedef QueueHandle_t osal_queue_t; + +static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) +{ + return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); +} + +static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) +{ + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); + (*p_error) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); +} + +static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data) +{ + return xQueueSendToBackFromISR(queue_hdl, data, NULL); +} + +static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data) +{ + return xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER) == pdTRUE; +} + +static inline void osal_queue_flush(osal_queue_t const queue_hdl) +{ + // TODO move to thread context +// xQueueReset(queue_hdl); +} + +//--------------------------------------------------------------------+ +// Semaphore API +//--------------------------------------------------------------------+ +typedef StaticSemaphore_t osal_semaphore_def_t; +typedef SemaphoreHandle_t osal_semaphore_t; + +static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) +{ + return xSemaphoreCreateBinaryStatic(semdef); +} + +static inline bool osal_semaphore_post_isr(osal_semaphore_t sem_hdl) +{ + return xSemaphoreGiveFromISR(sem_hdl, NULL) == pdTRUE; +} + +static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) +{ + return xSemaphoreGive(sem_hdl) == pdTRUE; +} + +static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) +{ + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); + (*p_error) = (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); +} + +static inline void osal_semaphore_reset_isr(osal_semaphore_t const sem_hdl) +{ + xSemaphoreTakeFromISR(sem_hdl, NULL); +} + +//--------------------------------------------------------------------+ +// MUTEX API (priority inheritance) +//--------------------------------------------------------------------+ +typedef SemaphoreHandle_t osal_mutex_t; + +#define osal_mutex_create(x) xSemaphoreCreateMutex() + +static inline bool osal_mutex_release(osal_mutex_t mutex_hdl) +{ + return xSemaphoreGive(mutex_hdl); +} + +static inline void osal_mutex_wait(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error) +{ + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); + (*p_error) = (xSemaphoreTake(mutex_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); +} + + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_OSAL_FREERTOS_H_ */ + +/** @} */ +/** @} */ + -- cgit v1.3.1 From 8600c4b6168c652347cab9a6b82aaabcf0e481eb Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 4 Sep 2018 14:20:30 +0700 Subject: adding mynewt to osal --- src/device/usbd.c | 2 +- src/osal/osal.c | 7 ++ src/osal/osal.h | 39 ++++++++- src/osal/osal_freertos.h | 10 +-- src/osal/osal_mynewt.h | 215 +++++++++++++++++++++++++++++++++++++++++++++++ src/osal/osal_none.h | 5 +- src/tusb_option.h | 5 +- 7 files changed, 269 insertions(+), 14 deletions(-) create mode 100644 src/osal/osal_mynewt.h (limited to 'src/osal/osal.h') diff --git a/src/device/usbd.c b/src/device/usbd.c index 2f760808b..89dd4b722 100644 --- a/src/device/usbd.c +++ b/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/src/osal/osal.c b/src/osal/osal.c index f2078b09c..4507b0b8f 100644 --- a/src/osal/osal.c +++ b/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/src/osal/osal.h b/src/osal/osal.h index 8af1d5b31..d64837205 100644 --- a/src/osal/osal.h +++ b/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 + /* 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/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index 321b00ac7..52d34c187 100644 --- a/src/osal/osal_freertos.h +++ b/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/src/osal/osal_mynewt.h b/src/osal/osal_mynewt.h new file mode 100644 index 000000000..db65ac553 --- /dev/null +++ b/src/osal/osal_mynewt.h @@ -0,0 +1,215 @@ +/**************************************************************************/ +/*! + @file osal_mynewt.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. +*/ +/**************************************************************************/ + +#ifndef OSAL_MYNEWT_H_ +#define OSAL_MYNEWT_H_ + +#include "os/os.h" + +#ifdef __cplusplus + extern "C" { +#endif + +//--------------------------------------------------------------------+ +// 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) ); +} + +//--------------------------------------------------------------------+ +// QUEUE API +//--------------------------------------------------------------------+ +#define OSAL_QUEUE_DEF(_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};\ + +typedef struct +{ + uint16_t depth; + uint16_t item_sz; + void* buf; + void* evbuf; + + struct os_mempool mpool; + struct os_mempool epool; + + struct os_eventq evq; +}osal_queue_def_t; + +typedef osal_queue_def_t* osal_queue_t; + +static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) +{ + if ( OS_OK != os_mempool_init(&qdef->mpool, qdef->depth, qdef->item_sz, qdef->buf, "usbd queue") ) return NULL; + if ( OS_OK != os_mempool_init(&qdef->epool, qdef->depth, sizeof(struct os_event), qdef->evbuf, "usbd evqueue") ) return NULL; + + os_eventq_init(&qdef->evq); + return (osal_queue_t) qdef; +} + +static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) +{ + (void) msec; + struct os_event* ev; + + if ( msec == 0 ) + { + ev = os_eventq_get_no_wait(&queue_hdl->evq); + if ( !ev ) + { + *p_error = TUSB_ERROR_OSAL_TIMEOUT; + return; + } + }else + { + ev = os_eventq_get(&queue_hdl->evq); + } + + memcpy(p_data, ev->ev_arg, queue_hdl->item_sz); // copy message + os_memblock_put(&queue_hdl->mpool, ev->ev_arg); // put back mem block + os_memblock_put(&queue_hdl->epool, ev); // put back ev block + + *p_error = TUSB_ERROR_NONE; +} + +#define osal_queue_send_isr osal_queue_send + +static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data) +{ + // get a block from mem pool for data + void* ptr = os_memblock_get(&queue_hdl->mpool); + if (!ptr) return false; + memcpy(ptr, data, queue_hdl->item_sz); + + // get a block from event pool to put into queue + struct os_event* ev = (struct os_event*) os_memblock_get(&queue_hdl->epool); + if (!ev) + { + os_memblock_put(&queue_hdl->mpool, ptr); + return false; + } + memclr_(ev, sizeof(struct os_event)); + ev->ev_arg = ptr; + + os_eventq_put(&queue_hdl->evq, ev); + + return true; +} + +static inline void osal_queue_flush(osal_queue_t const queue_hdl) +{ + +} + +//--------------------------------------------------------------------+ +// Semaphore API +//--------------------------------------------------------------------+ +typedef struct os_sem osal_semaphore_def_t; +typedef struct os_sem* osal_semaphore_t; + +static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) +{ + return (os_sem_init(semdef, 0) == OS_OK) ? (osal_semaphore_t) semdef : NULL; +} + +#define osal_semaphore_post_isr osal_semaphore_post + +static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) +{ + return os_sem_release(sem_hdl) == OS_OK; +} + +static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) +{ + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? OS_TIMEOUT_NEVER : os_time_ms_to_ticks32(msec); + (*p_error) = ( (os_sem_pend(sem_hdl, ticks) == OS_OK) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT ); +} + +static inline void osal_semaphore_reset_isr(osal_semaphore_t const sem_hdl) +{ +// xSemaphoreTakeFromISR(sem_hdl, NULL); +} + +#if 0 +//--------------------------------------------------------------------+ +// MUTEX API (priority inheritance) +//--------------------------------------------------------------------+ +typedef struct os_mutex osal_mutex_t; + +#define osal_mutex_create(x) xSemaphoreCreateMutex() + +static inline bool osal_mutex_release(osal_mutex_t mutex_hdl) +{ + return xSemaphoreGive(mutex_hdl); +} + +static inline void osal_mutex_wait(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error) +{ + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); + (*p_error) = (xSemaphoreTake(mutex_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); +} +#endif + + +#ifdef __cplusplus + } +#endif + +#endif /* OSAL_MYNEWT_H_ */ diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 012de9c78..22c89868a 100644 --- a/src/osal/osal_none.h +++ b/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/src/tusb_option.h b/src/tusb_option.h index 22b78453c..846367129 100644 --- a/src/tusb_option.h +++ b/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 /** @} */ -- cgit v1.3.1 From 3dd635f4c14c6e23ed1a3d2254ecf58b7398e2d7 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 23 Oct 2018 15:53:29 +0700 Subject: merge osal_queue_send_isr to osal_queue_send, osal_semaphore_post_isr to osal_semaphore_post --- src/osal/osal.h | 6 ++---- src/osal/osal_freertos.h | 18 ++++-------------- src/osal/osal_mynewt.h | 11 +++++------ src/osal/osal_none.h | 10 ++++------ 4 files changed, 15 insertions(+), 30 deletions(-) (limited to 'src/osal/osal.h') diff --git a/src/osal/osal.h b/src/osal/osal.h index d64837205..93ac48b13 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -80,15 +80,13 @@ typedef void (*osal_task_func_t)( void * ); * 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) + * bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) * 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) + * bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) * 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) * diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index 52d34c187..be7e6b38b 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -120,14 +120,9 @@ static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_dat (*p_error) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); } -static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data) +static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) { - return xQueueSendToBackFromISR(queue_hdl, data, NULL); -} - -static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data) -{ - return xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER) == pdTRUE; + return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER); } static inline void osal_queue_flush(osal_queue_t const queue_hdl) @@ -147,14 +142,9 @@ static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semde return xSemaphoreCreateBinaryStatic(semdef); } -static inline bool osal_semaphore_post_isr(osal_semaphore_t sem_hdl) -{ - return xSemaphoreGiveFromISR(sem_hdl, NULL) == pdTRUE; -} - -static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) +static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) { - return xSemaphoreGive(sem_hdl) == pdTRUE; + return in_isr ? xSemaphoreGiveFromISR(sem_hdl, NULL) : xSemaphoreGive(sem_hdl); } static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) diff --git a/src/osal/osal_mynewt.h b/src/osal/osal_mynewt.h index 59cd1b821..cb09680e0 100644 --- a/src/osal/osal_mynewt.h +++ b/src/osal/osal_mynewt.h @@ -129,10 +129,10 @@ static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_dat *p_error = TUSB_ERROR_NONE; } -#define osal_queue_send_isr osal_queue_send - -static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data) +static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) { + (void) in_isr; + // get a block from mem pool for data void* ptr = os_memblock_get(&queue_hdl->mpool); if (!ptr) return false; @@ -169,10 +169,9 @@ static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semde return (os_sem_init(semdef, 0) == OS_OK) ? (osal_semaphore_t) semdef : NULL; } -#define osal_semaphore_post_isr osal_semaphore_post - -static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) +static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) { + (void) in_isr; return os_sem_release(sem_hdl) == OS_OK; } diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 22c89868a..91848f221 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -133,13 +133,12 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) return (osal_queue_t) qdef; } -static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data) +static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) { + (void) in_isr; return tu_fifo_write( (tu_fifo_t*) queue_hdl, data); } -#define osal_queue_send osal_queue_send_isr - static inline void osal_queue_flush(osal_queue_t const queue_hdl) { queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; @@ -182,10 +181,9 @@ static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semde return semdef; } -#define osal_semaphore_post_isr osal_semaphore_post - -static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) +static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) { + (void) in_isr; if (sem_hdl->count < sem_hdl->max_count ) sem_hdl->count++; return true; } -- cgit v1.3.1 From 4683dc1e680bbed3909b2b1dc519886b2cee0107 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 2 Nov 2018 15:45:27 +0700 Subject: add osal_mutex --- src/osal/osal.h | 10 ++--- src/osal/osal_freertos.h | 31 +++++++------ src/osal/osal_none.h | 113 +++++++++++++++++++++++++---------------------- 3 files changed, 80 insertions(+), 74 deletions(-) (limited to 'src/osal/osal.h') diff --git a/src/osal/osal.h b/src/osal/osal.h index 93ac48b13..c40ab661d 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -81,20 +81,20 @@ typedef void (*osal_task_func_t)( void * ); * 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(osal_queue_t const queue_hdl, void const * data, bool in_isr) - * osal_queue_flush() TODO remove + * osal_queue_reset() * * Semaphore * osal_semaphore_def_t, osal_semaphore_t * osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) * bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) * 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) + * void osal_semaphore_reset(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) + * osal_mutex_create(osal_mutex_def_t* mdef) + * bool osal_mutex_unlock(osal_mutex_t mutex_hdl) + * void osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error) */ #if CFG_TUSB_OS == OPT_OS_FREERTOS diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index be7e6b38b..f41e91c67 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -114,10 +114,10 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); } -static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) +static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *err) { uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - (*p_error) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); + (*err) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); } static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) @@ -125,10 +125,9 @@ static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * da return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER); } -static inline void osal_queue_flush(osal_queue_t const queue_hdl) +static inline void osal_queue_reset(osal_queue_t const queue_hdl) { - // TODO move to thread context -// xQueueReset(queue_hdl); + xQueueReset(queue_hdl); } //--------------------------------------------------------------------+ @@ -147,33 +146,33 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) return in_isr ? xSemaphoreGiveFromISR(sem_hdl, NULL) : xSemaphoreGive(sem_hdl); } -static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) +static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *err) { uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - (*p_error) = (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); + (*err) = (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); } -static inline void osal_semaphore_reset_isr(osal_semaphore_t const sem_hdl) +static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl) { - xSemaphoreTakeFromISR(sem_hdl, NULL); + xQueueReset(sem_hdl); } //--------------------------------------------------------------------+ // MUTEX API (priority inheritance) //--------------------------------------------------------------------+ +typedef StaticSemaphore_t osal_mutex_def_t; typedef SemaphoreHandle_t osal_mutex_t; -#define osal_mutex_create(x) xSemaphoreCreateMutex() - -static inline bool osal_mutex_release(osal_mutex_t mutex_hdl) +static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) { - return xSemaphoreGive(mutex_hdl); + return xSemaphoreCreateMutexStatic(mdef); } -static inline void osal_mutex_wait(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error) +#define osal_mutex_lock osal_semaphore_wait + +static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) { - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - (*p_error) = (xSemaphoreTake(mutex_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); + return xSemaphoreGive(mutex_hdl); } diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 783e4fd2e..39748800b 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -78,12 +78,12 @@ static inline bool osal_task_create(osal_task_def_t* taskdef) #define TASK_RESTART \ _state = 0 -#define osal_task_delay(msec) \ - do { \ - _timeout = tusb_hal_millis(); \ - _state = __LINE__; case __LINE__: \ - if ( _timeout + msec > tusb_hal_millis() ) \ - return TUSB_ERROR_OSAL_WAITING; \ +#define osal_task_delay(_msec) \ + do { \ + _timeout = tusb_hal_millis(); \ + _state = __LINE__; case __LINE__: \ + if ( _timeout + (_msec) > tusb_hal_millis() ) \ + return TUSB_ERROR_OSAL_WAITING; \ }while(0) //--------------------------------------------------------------------+ @@ -139,26 +139,26 @@ static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * da return tu_fifo_write( (tu_fifo_t*) queue_hdl, data); } -static inline void osal_queue_flush(osal_queue_t const queue_hdl) +static inline void osal_queue_reset(osal_queue_t const queue_hdl) { queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; } -#define osal_queue_receive(queue_hdl, p_data, msec, p_error) \ - do { \ - _timeout = tusb_hal_millis(); \ - _state = __LINE__; case __LINE__: \ - if( queue_hdl->count == 0 ) { \ - if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + msec <= tusb_hal_millis()) ) \ - *(p_error) = TUSB_ERROR_OSAL_TIMEOUT; \ - else \ - return TUSB_ERROR_OSAL_WAITING; \ - } else{ \ - /*tusb_hal_int_disable_all();*/ \ - tu_fifo_read(queue_hdl, p_data); \ - /*tusb_hal_int_enable_all();*/ \ - *(p_error) = TUSB_ERROR_NONE; \ - } \ +#define osal_queue_receive(_q_hdl, p_data, _msec, _err) \ + do { \ + _timeout = tusb_hal_millis(); \ + _state = __LINE__; case __LINE__: \ + if( (_q_hdl)->count == 0 ) { \ + if ( ((_msec) != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + (_msec) <= tusb_hal_millis()) ) \ + *(_err) = TUSB_ERROR_OSAL_TIMEOUT; \ + else \ + return TUSB_ERROR_OSAL_WAITING; \ + } else{ \ + /* Enter critical ? */ \ + tu_fifo_read(queue_hdl, p_data); \ + /* Exit critical ? */ \ + *(_err) = TUSB_ERROR_NONE; \ + } \ }while(0) @@ -168,67 +168,74 @@ static inline void osal_queue_flush(osal_queue_t const queue_hdl) typedef struct { volatile uint16_t count; - uint16_t max_count; }osal_semaphore_def_t; typedef osal_semaphore_def_t* osal_semaphore_t; - static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) { - semdef->count = 0; - semdef->max_count = 1; + semdef->count = 0; return semdef; } -static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) +static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) { (void) in_isr; - if (sem_hdl->count < sem_hdl->max_count ) sem_hdl->count++; + sem_hdl->count++; return true; } -static inline void osal_semaphore_reset_isr(osal_semaphore_t sem_hdl) +static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) { sem_hdl->count = 0; } -#define osal_semaphore_wait(sem_hdl, msec, p_error) \ - do { \ - _timeout = tusb_hal_millis(); \ - _state = __LINE__; case __LINE__: \ - if( sem_hdl->count == 0 ) { \ - if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && (_timeout + msec <= tusb_hal_millis()) ) \ - *(p_error) = TUSB_ERROR_OSAL_TIMEOUT; \ - else \ - return TUSB_ERROR_OSAL_WAITING; \ - } else{ \ - /*tusb_hal_int_disable_all();*/ \ - sem_hdl->count--; \ - /*tusb_hal_int_enable_all();*/ \ - *(p_error) = TUSB_ERROR_NONE; \ - } \ +#define osal_semaphore_wait(_sem_hdl, _msec, _err) \ + do { \ + _timeout = tusb_hal_millis(); \ + _state = __LINE__; case __LINE__: \ + if( (_sem_hdl)->count == 0 ) { \ + if ( ((_msec) != OSAL_TIMEOUT_WAIT_FOREVER) && (_timeout + (_msec) <= tusb_hal_millis()) ) \ + *(_err) = TUSB_ERROR_OSAL_TIMEOUT; \ + else \ + return TUSB_ERROR_OSAL_WAITING; \ + } else{ \ + /* Enter critical ? */ \ + (_sem_hdl)->count--; \ + /* Exit critical ? */ \ + *(_err) = TUSB_ERROR_NONE; \ + } \ }while(0) //--------------------------------------------------------------------+ -// MUTEX API (priority inheritance) +// MUTEX API +// Within tinyusb, mutex is never used in ISR context //--------------------------------------------------------------------+ -#if 0 +typedef osal_semaphore_def_t osal_mutex_def_t; typedef osal_semaphore_t osal_mutex_t; -static inline osal_mutex_t osal_mutex_create(void) +static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef) { - return osal_semaphore_create(1, 0); + mdef->count = 1; + return mdef; } -static inline bool osal_mutex_release(osal_mutex_t mutex_hdl) +#define osal_mutex_unlock(_mutex_hdl) osal_semaphore_post(_mutex_hdl, false) +#define osal_mutex_lock osal_semaphore_wait + +// check if mutex is available for non-thread/substask usage in some cases +static inline bool osal_mutex_lock_notask(osal_mutex_t mutex_hdl) { - return osal_semaphore_post(mutex_hdl); + if (mutex_hdl->count) + { + mutex_hdl->count--; + return true; + }else + { + return false; + } } -#define osal_mutex_wait osal_semaphore_wait -#endif - #ifdef __cplusplus } -- cgit v1.3.1 From 2708632a6a65e467cae131ce38082d6a45a837d0 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 2 Nov 2018 17:26:35 +0700 Subject: clean up osal --- src/device/usbd_pvt.h | 3 +- src/osal/osal.c | 1 - src/osal/osal.h | 6 ++-- src/osal/osal_freertos.h | 79 +++++++++++++++++++++---------------------- src/osal/osal_none.h | 88 +++++++++++++++++++++++------------------------- src/tusb.h | 1 + 6 files changed, 88 insertions(+), 90 deletions(-) (limited to 'src/osal/osal.h') diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index d7e014cb1..0b6b56d7d 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -39,6 +39,7 @@ #define USBD_PVT_H_ #include "osal/osal.h" +#include "common/tusb_fifo.h" #ifdef __cplusplus extern "C" { @@ -68,7 +69,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_d #define usbd_control_xfer_st(_rhport, _dir, _buffer, _len) \ do { \ if (_len) { \ - tusb_error_t err; \ + uint32_t err; \ dcd_control_xfer(_rhport, _dir, (uint8_t*) _buffer, _len); \ osal_semaphore_wait( _usbd_ctrl_sem, OSAL_TIMEOUT_CONTROL_XFER, &err ); \ STASK_ASSERT_ERR( err ); \ diff --git a/src/osal/osal.c b/src/osal/osal.c index 4507b0b8f..f5105d4d1 100644 --- a/src/osal/osal.c +++ b/src/osal/osal.c @@ -39,7 +39,6 @@ #include "tusb_option.h" #include "osal.h" - //--------------------------------------------------------------------+ // TICK API //--------------------------------------------------------------------+ diff --git a/src/osal/osal.h b/src/osal/osal.h index c40ab661d..2ca06f66e 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -79,7 +79,7 @@ typedef void (*osal_task_func_t)( void * ); * 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) + * osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, uint32_t *p_error) * bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) * osal_queue_reset() * @@ -87,14 +87,14 @@ typedef void (*osal_task_func_t)( void * ); * osal_semaphore_def_t, osal_semaphore_t * osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) * bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) - * void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) + * void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, uint32_t *p_error) * void osal_semaphore_reset(osal_semaphore_t const sem_hdl) * * Mutex * osal_mutex_t * osal_mutex_create(osal_mutex_def_t* mdef) * bool osal_mutex_unlock(osal_mutex_t mutex_hdl) - * void osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error) + * void osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec, uint32_t *p_error) */ #if CFG_TUSB_OS == OPT_OS_FREERTOS diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index f41e91c67..ae988ec1f 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -91,45 +91,6 @@ static inline void osal_task_delay(uint32_t msec) vTaskDelay( pdMS_TO_TICKS(msec) ); } -//--------------------------------------------------------------------+ -// QUEUE API -//--------------------------------------------------------------------+ -#define OSAL_QUEUE_DEF(_name, _depth, _type) \ - static _type _name##_##buf[_depth];\ - osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; - -typedef struct -{ - uint16_t depth; - uint16_t item_sz; - void* buf; - - StaticQueue_t sq; -}osal_queue_def_t; - -typedef QueueHandle_t osal_queue_t; - -static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) -{ - return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); -} - -static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *err) -{ - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - (*err) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); -} - -static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) -{ - return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER); -} - -static inline void osal_queue_reset(osal_queue_t const queue_hdl) -{ - xQueueReset(queue_hdl); -} - //--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ @@ -146,7 +107,7 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) return in_isr ? xSemaphoreGiveFromISR(sem_hdl, NULL) : xSemaphoreGive(sem_hdl); } -static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *err) +static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, uint32_t *err) { uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); (*err) = (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); @@ -175,6 +136,44 @@ static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) return xSemaphoreGive(mutex_hdl); } +//--------------------------------------------------------------------+ +// QUEUE API +//--------------------------------------------------------------------+ +#define OSAL_QUEUE_DEF(_name, _depth, _type) \ + static _type _name##_##buf[_depth];\ + osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; + +typedef struct +{ + uint16_t depth; + uint16_t item_sz; + void* buf; + + StaticQueue_t sq; +}osal_queue_def_t; + +typedef QueueHandle_t osal_queue_t; + +static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) +{ + return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); +} + +static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, uint32_t *err) +{ + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); + (*err) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); +} + +static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) +{ + return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER); +} + +static inline void osal_queue_reset(osal_queue_t const queue_hdl) +{ + xQueueReset(queue_hdl); +} #ifdef __cplusplus } diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 39748800b..796ddc15f 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -43,8 +43,6 @@ #ifndef _TUSB_OSAL_NONE_H_ #define _TUSB_OSAL_NONE_H_ -#include "common/tusb_fifo.h" - #ifdef __cplusplus extern "C" { #endif @@ -119,49 +117,6 @@ static inline bool osal_task_create(osal_task_def_t* taskdef) #define STASK_ASSERT(_cond) TU_VERIFY_HDLR(_cond, TU_BREAKPOINT(); TASK_RESTART, TUSB_ERROR_FAILED) #define STASK_ASSERT_HDLR(_cond, _func) TU_VERIFY_HDLR(_cond, TU_BREAKPOINT(); _func; TASK_RESTART, TUSB_ERROR_FAILED) -//--------------------------------------------------------------------+ -// QUEUE API -//--------------------------------------------------------------------+ -#define OSAL_QUEUE_DEF(_name, _depth, _type) TU_FIFO_DEF(_name, _depth, _type, false) - -typedef tu_fifo_t osal_queue_def_t; -typedef tu_fifo_t* osal_queue_t; - -static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) -{ - tu_fifo_clear(qdef); - return (osal_queue_t) qdef; -} - -static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) -{ - (void) in_isr; - return tu_fifo_write( (tu_fifo_t*) queue_hdl, data); -} - -static inline void osal_queue_reset(osal_queue_t const queue_hdl) -{ - queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; -} - -#define osal_queue_receive(_q_hdl, p_data, _msec, _err) \ - do { \ - _timeout = tusb_hal_millis(); \ - _state = __LINE__; case __LINE__: \ - if( (_q_hdl)->count == 0 ) { \ - if ( ((_msec) != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + (_msec) <= tusb_hal_millis()) ) \ - *(_err) = TUSB_ERROR_OSAL_TIMEOUT; \ - else \ - return TUSB_ERROR_OSAL_WAITING; \ - } else{ \ - /* Enter critical ? */ \ - tu_fifo_read(queue_hdl, p_data); \ - /* Exit critical ? */ \ - *(_err) = TUSB_ERROR_NONE; \ - } \ - }while(0) - - //--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ @@ -236,6 +191,49 @@ static inline bool osal_mutex_lock_notask(osal_mutex_t mutex_hdl) } } +//--------------------------------------------------------------------+ +// QUEUE API +//--------------------------------------------------------------------+ +#include "common/tusb_fifo.h" + +#define OSAL_QUEUE_DEF(_name, _depth, _type) TU_FIFO_DEF(_name, _depth, _type, false) + +typedef tu_fifo_t osal_queue_def_t; +typedef tu_fifo_t* osal_queue_t; + +static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) +{ + tu_fifo_clear(qdef); + return (osal_queue_t) qdef; +} + +static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) +{ + (void) in_isr; + return tu_fifo_write( (tu_fifo_t*) queue_hdl, data); +} + +static inline void osal_queue_reset(osal_queue_t const queue_hdl) +{ + queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; +} + +#define osal_queue_receive(_q_hdl, p_data, _msec, _err) \ + do { \ + _timeout = tusb_hal_millis(); \ + _state = __LINE__; case __LINE__: \ + if( (_q_hdl)->count == 0 ) { \ + if ( ((_msec) != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + (_msec) <= tusb_hal_millis()) ) \ + *(_err) = TUSB_ERROR_OSAL_TIMEOUT; \ + else \ + return TUSB_ERROR_OSAL_WAITING; \ + } else{ \ + /* Enter critical ? */ \ + tu_fifo_read(_q_hdl, p_data); \ + /* Exit critical ? */ \ + *(_err) = TUSB_ERROR_NONE; \ + } \ + }while(0) #ifdef __cplusplus } diff --git a/src/tusb.h b/src/tusb.h index 01fdf5ed3..c0246ccc8 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -49,6 +49,7 @@ #include "common/tusb_common.h" #include "tusb_hal.h" #include "osal/osal.h" +#include "common/tusb_fifo.h" //------------- HOST -------------// #if MODE_HOST_SUPPORTED -- cgit v1.3.1 From 10bf41f718ea867a3621e11b4c49e72605bbcc89 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 14 Nov 2018 16:31:28 +0700 Subject: change osal_queue_receive() signature - fix build issue with freertos --- .gitignore | 16 +++++++++++++++ .../device/nrf52840_freertos/src/msc_flash_qspi.c | 2 +- src/device/dcd.h | 2 -- src/device/usbd.c | 23 +++++++++++----------- src/host/usbh.c | 10 ++++++++-- src/osal/osal.h | 7 +------ src/osal/osal_freertos.h | 5 ++--- src/osal/osal_none.h | 11 ++++++----- 8 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 .gitignore (limited to 'src/osal/osal.h') diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..266cbe08f --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +/.metadata +html +latex +test_old +tests/build +*.d +*.o +*.mk +*.ld +*.launch +*.map +*.axf +/tests/lpc175x_6x/build/ +/tests/lpc18xx_43xx/build/ +/demos/*/*/Board_* +/demos/*/*/KeilBuild/ diff --git a/examples/device/nrf52840_freertos/src/msc_flash_qspi.c b/examples/device/nrf52840_freertos/src/msc_flash_qspi.c index 53bdc5a71..30adf1d92 100644 --- a/examples/device/nrf52840_freertos/src/msc_flash_qspi.c +++ b/examples/device/nrf52840_freertos/src/msc_flash_qspi.c @@ -61,7 +61,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff // Callback invoked when received WRITE10 command. // Process data in buffer to disk's storage and return number of written bytes -int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) +int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize) { uint32_t addr = lba * CFG_TUD_MSC_BLOCK_SZ + offset; diff --git a/src/device/dcd.h b/src/device/dcd.h index 0c976edec..ff836f405 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -125,8 +125,6 @@ void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_ /*------------------------------------------------------------------*/ /* Endpoint API *------------------------------------------------------------------*/ - -//------------- Non-control Endpoints -------------// bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc); bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes); bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr); diff --git a/src/device/usbd.c b/src/device/usbd.c index c9d5e5642..4a9b13a25 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -245,24 +245,25 @@ void usbd_task( void* param) { (void) param; - OSAL_TASK_BEGIN +#if CFG_TUSB_OS != OPT_OS_NONE + while (1) { +#endif + usbd_main_st(); - OSAL_TASK_END + +#if CFG_TUSB_OS != OPT_OS_NONE + } +#endif } static tusb_error_t usbd_main_st(void) { dcd_event_t event; - tusb_error_t err = TUSB_ERROR_NONE; + // Loop until there is no more events in the queue - while (_usbd_q->count > 0) + while (1) { - tu_memclr(&event, sizeof(dcd_event_t)); - - err = osal_queue_receive(_usbd_q, &event); - if (err != TUSB_ERROR_NONE) { - break; - } + if ( !osal_queue_receive(_usbd_q, &event) ) return TUSB_ERROR_NONE; if ( DCD_EVENT_SETUP_RECEIVED == event.event_id ) { @@ -312,7 +313,7 @@ static tusb_error_t usbd_main_st(void) } } - return err; + return TUSB_ERROR_NONE; } void tud_control_interface_control_complete_cb(uint8_t rhport, uint8_t interface, tusb_control_request_t const * const p_request) { diff --git a/src/host/usbh.c b/src/host/usbh.c index b849de9b9..f996d7a70 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -361,9 +361,15 @@ void usbh_enumeration_task(void* param) { (void) param; - OSAL_TASK_BEGIN +#if CFG_TUSB_OS != OPT_OS_NONE + while (1) { +#endif + enumeration_body_subtask(); - OSAL_TASK_END + +#if CFG_TUSB_OS != OPT_OS_NONE + } +#endif } tusb_error_t enumeration_body_subtask(void) diff --git a/src/osal/osal.h b/src/osal/osal.h index 2ca06f66e..6846b5757 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -62,10 +62,6 @@ 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 - #else /* RTOS Porting API * @@ -105,8 +101,7 @@ typedef void (*osal_task_func_t)( void * ); #error CFG_TUSB_OS is not defined or OS is not supported yet #endif - #define OSAL_TASK_BEGIN while(1) { - #define OSAL_TASK_END } + // TODO remove subtask related macros later //------------- Sub Task -------------// #define OSAL_SUBTASK_BEGIN diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index f29759225..52cadd798 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -159,10 +159,9 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef) return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); } -static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, uint32_t *err) +static inline bool osal_queue_receive(osal_queue_t const queue_hdl, void* data) { - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - (*err) = ( xQueueReceive(queue_hdl, p_data, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); + return xQueueReceive(queue_hdl, data, portMAX_DELAY); } static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 383809180..5ba246d5f 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -89,6 +89,7 @@ static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semde static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) { + (void) in_isr; sem_hdl->count++; return true; } @@ -157,11 +158,11 @@ static inline void osal_queue_reset(osal_queue_t const queue_hdl) queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; } -static inline tusb_error_t osal_queue_receive(osal_queue_t const queue_hdl, void* data) { - if (!tu_fifo_read(queue_hdl, data)) { - return TUSB_ERROR_OSAL_WAITING; - } - return TUSB_ERROR_NONE; + +static inline bool osal_queue_receive(osal_queue_t const queue_hdl, void* data) +{ + // osal none return immediately without blocking + return tu_fifo_read(queue_hdl, data); } -- cgit v1.3.1 From 1d3583785f9f890da2e6ac720d1327ab0452f974 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Dec 2018 17:31:25 +0700 Subject: change osal_semaphore_wait to return bool --- src/osal/osal.h | 2 +- src/osal/osal_freertos.h | 4 ++-- src/osal/osal_none.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/osal/osal.h') diff --git a/src/osal/osal.h b/src/osal/osal.h index 6846b5757..55e3e077c 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -83,7 +83,7 @@ typedef void (*osal_task_func_t)( void * ); * osal_semaphore_def_t, osal_semaphore_t * osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef) * bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) - * void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, uint32_t *p_error) + * bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) * void osal_semaphore_reset(osal_semaphore_t const sem_hdl) * * Mutex diff --git a/src/osal/osal_freertos.h b/src/osal/osal_freertos.h index 458e54b5c..acec4a95d 100644 --- a/src/osal/osal_freertos.h +++ b/src/osal/osal_freertos.h @@ -107,10 +107,10 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) return in_isr ? xSemaphoreGiveFromISR(sem_hdl, NULL) : xSemaphoreGive(sem_hdl); } -static inline tusb_error_t osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) +static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec) { uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); - return (xSemaphoreTake(sem_hdl, ticks) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT); + return xSemaphoreTake(sem_hdl, ticks); } static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl) diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 61ed0d45e..4da5cffc8 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -96,15 +96,15 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) sem_hdl->count = 0; } -static inline tusb_error_t osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) +// TODO blocking for now +static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec) { (void) msec; - // TODO blocking for now while (sem_hdl->count == 0) { } sem_hdl->count--; - return TUSB_ERROR_NONE; + return true; } //--------------------------------------------------------------------+ -- cgit v1.3.1