From 73d10728e5fcc1be0b358237688061a9cc461e1f Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 5 Jun 2019 23:11:57 +0700 Subject: [PATCH 1/6] enhance Serial.available()/write() to prevent blocking wait without yield/delay --- .../Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp b/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp index e73fca682..bc7163318 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp +++ b/cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp @@ -64,12 +64,24 @@ void Adafruit_USBD_CDC::end(void) Adafruit_USBD_CDC::operator bool() { - return tud_cdc_connected(); + bool ret = tud_cdc_connected(); + + // Add an yield to run usb background in case sketch block wait as follows + // while( !Serial ) {} + if ( !ret ) yield(); + + return ret; } int Adafruit_USBD_CDC::available(void) { - return tud_cdc_available(); + uint32_t count = tud_cdc_available(); + + // Add an yield to run usb background in case sketch block wait as follows + // while( !Serial.available() ) {} + if (!count) yield(); + + return count; } int Adafruit_USBD_CDC::peek(void) From 3f2fbc6e75b9a0e326fa8f5ea0b268c1541a5bfa Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Jun 2019 11:12:40 +0700 Subject: [PATCH 2/6] update tinyusb --- .../tinyusb/src/class/cdc/cdc.h | 28 +++++++++---------- .../tinyusb/src/class/cdc/cdc_device.h | 8 +++--- .../tinyusb/src/class/hid/hid.h | 6 ++-- .../tinyusb/src/class/hid/hid_device.h | 10 +++---- .../tinyusb/src/class/midi/midi.h | 4 +-- .../tinyusb/src/class/midi/midi_device.h | 2 +- .../tinyusb/src/class/msc/msc.h | 28 +++++++++---------- .../tinyusb/src/class/msc/msc_device.h | 24 ++++++++-------- .../tinyusb/src/common/tusb_common.h | 3 -- .../tinyusb/src/common/tusb_compiler.h | 27 ++++++++++-------- .../tinyusb/src/common/tusb_types.h | 26 ++++++++--------- .../tinyusb/src/device/dcd.h | 2 +- .../tinyusb/src/device/usbd.c | 2 +- .../tinyusb/src/device/usbd.h | 8 +++--- .../tinyusb/src/tusb_option.h | 2 +- .../nRF5/Adafruit_TinyUSB_Core/tusb_config.h | 2 +- 16 files changed, 91 insertions(+), 91 deletions(-) diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc.h index 200f6eaae..2e865bdbb 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc.h @@ -212,7 +212,7 @@ typedef enum // FUNCTIONAL DESCRIPTOR (COMMUNICATION INTERFACE) //--------------------------------------------------------------------+ /// Header Functional Descriptor (Communication Interface) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -221,7 +221,7 @@ typedef struct ATTR_PACKED }cdc_desc_func_header_t; /// Union Functional Descriptor (Communication Interface) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -231,7 +231,7 @@ typedef struct ATTR_PACKED }cdc_desc_func_union_t; #define cdc_desc_func_union_n_t(no_slave)\ - struct ATTR_PACKED { \ + struct TU_ATTR_PACKED { \ uint8_t bLength ;\ uint8_t bDescriptorType ;\ uint8_t bDescriptorSubType ;\ @@ -240,7 +240,7 @@ typedef struct ATTR_PACKED } /// Country Selection Functional Descriptor (Communication Interface) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -250,7 +250,7 @@ typedef struct ATTR_PACKED }cdc_desc_func_country_selection_t; #define cdc_desc_func_country_selection_n_t(no_country) \ - struct ATTR_PACKED {\ + struct TU_ATTR_PACKED {\ uint8_t bLength ;\ uint8_t bDescriptorType ;\ uint8_t bDescriptorSubType ;\ @@ -264,7 +264,7 @@ typedef struct ATTR_PACKED /// \brief Call Management Functional Descriptor /// \details This functional descriptor describes the processing of calls for the Communications Class interface. -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -280,7 +280,7 @@ typedef struct ATTR_PACKED }cdc_desc_func_call_management_t; -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t support_comm_request : 1; ///< Device supports the request combination of Set_Comm_Feature, Clear_Comm_Feature, and Get_Comm_Feature. uint8_t support_line_request : 1; ///< Device supports the request combination of Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State. @@ -293,7 +293,7 @@ TU_VERIFY_STATIC(sizeof(cdc_acm_capability_t) == 1, "mostly problem with compile /// \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 -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -303,7 +303,7 @@ typedef struct ATTR_PACKED /// \brief Direct Line Management Functional Descriptor /// \details This functional descriptor describes the commands supported by the Communications Class interface with SubClass code of \ref CDC_FUNC_DESC_DIRECT_LINE_MANAGEMENT -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -319,7 +319,7 @@ typedef struct ATTR_PACKED /// \brief Telephone Ringer Functional Descriptor /// \details The Telephone Ringer functional descriptor describes the ringer capabilities supported by the Communications Class interface, /// with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -331,7 +331,7 @@ typedef struct ATTR_PACKED /// \brief Telephone Operational Modes Functional Descriptor /// \details The Telephone Operational Modes functional descriptor describes the operational modes supported by /// the Communications Class interface, with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -347,7 +347,7 @@ typedef struct ATTR_PACKED /// \brief Telephone Call and Line State Reporting Capabilities Descriptor /// \details The Telephone Call and Line State Reporting Capabilities functional descriptor describes the abilities of a /// telephone device to report optional call and line states. -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -371,7 +371,7 @@ static inline uint8_t cdc_functional_desc_typeof(uint8_t const * p_desc) //--------------------------------------------------------------------+ // Requests //--------------------------------------------------------------------+ -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint32_t bit_rate; uint8_t stop_bits; ///< 0: 1 stop bit - 1: 1.5 stop bits - 2: 2 stop bits @@ -381,7 +381,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(cdc_line_coding_t) == 7, "size is not correct"); -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint16_t dte_is_present : 1; ///< Indicates to DCE if DTE is presentor not. This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR. uint16_t half_duplex_carrier_control : 1; diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h index 9e1087631..3c1af9dbf 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h @@ -91,16 +91,16 @@ static inline bool tud_cdc_write_flush (void) //--------------------------------------------------------------------+ // Invoked when received new data -ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf); +TU_ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf); // Invoked when received `wanted_char` -ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char); +TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char); // Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE -ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts); +TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts); // Invoked when line coding is change via SET_LINE_CODING -ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding); +TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding); /** @} */ /** @} */ diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid.h index 902c01ef5..04b255ea8 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid.h @@ -44,7 +44,7 @@ * @{ */ /// USB HID Descriptor -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */ uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */ @@ -150,7 +150,7 @@ typedef enum * @{ */ /// Standard HID Boot Protocol Mouse Report. -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */ int8_t x; /**< Current delta x movement of the mouse. */ @@ -178,7 +178,7 @@ typedef enum * @{ */ /// Standard HID Boot Protocol Keyboard Report. -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t modifier; /**< Keyboard modifier (KEYBOARD_MODIFER_* masks). */ uint8_t reserved; /**< Reserved for OEM use, always set to 0. */ diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid_device.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid_device.h index aa1f2b83e..947dbb75f 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid_device.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid_device.h @@ -70,24 +70,24 @@ bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y // Invoked when received GET HID REPORT DESCRIPTOR request // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete -ATTR_WEAK uint8_t const * tud_hid_descriptor_report_cb(void); +TU_ATTR_WEAK uint8_t const * tud_hid_descriptor_report_cb(void); // Invoked when received GET_REPORT control request // Application must fill buffer report's content and return its length. // Return zero will cause the stack to STALL request -ATTR_WEAK uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); +TU_ATTR_WEAK uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); // Invoked when received SET_REPORT control request or // received data on OUT endpoint ( Report ID = 0, Type = 0 ) -ATTR_WEAK void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); +TU_ATTR_WEAK void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); // Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report ) -ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode); +TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode); // Invoked when received SET_IDLE request. return false will stall the request // - Idle Rate = 0 : only send report if there is changes, i.e skip duplication // - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms). -ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate); +TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate); /* --------------------------------------------------------------------+ * HID Report Descriptor Template diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi.h index ee318f788..50f2be679 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi.h @@ -42,7 +42,7 @@ // FUNCTIONAL DESCRIPTOR (COMMUNICATION INTERFACE) //--------------------------------------------------------------------+ /// Header Functional Descriptor (Communication Interface) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific @@ -52,7 +52,7 @@ typedef struct ATTR_PACKED }midi_desc_func_header_t; /// Union Functional Descriptor (Communication Interface) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi_device.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi_device.h index 84f4c57bd..45e009010 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi_device.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi_device.h @@ -82,7 +82,7 @@ static inline bool tud_midi_write_flush (void) //--------------------------------------------------------------------+ // APPLICATION CALLBACK API (WEAK is optional) //--------------------------------------------------------------------+ -ATTR_WEAK void tud_midi_rx_cb(uint8_t itf); +TU_ATTR_WEAK void tud_midi_rx_cb(uint8_t itf); //--------------------------------------------------------------------+ // Internal Class Driver API diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc.h index 95fac6598..d461513fc 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc.h @@ -86,7 +86,7 @@ typedef enum }msc_csw_status_t; /// Command Block Wrapper -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint32_t signature; ///< Signature that helps identify this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW. uint32_t tag; ///< Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTagfield of the associated CSW. The dCSWTagpositively associates a CSW with the corresponding CBW. @@ -100,7 +100,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct"); /// Command Status Wrapper -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint32_t signature ; ///< Signature that helps identify this data packet as a CSW. The signature field shall contain the value 53425355h (little endian), indicating CSW. uint32_t tag ; ///< The device shall set this field to the value received in the dCBWTag of the associated CBW. @@ -153,7 +153,7 @@ typedef enum //--------------------------------------------------------------------+ /// SCSI Test Unit Ready Command -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_TEST_UNIT_READY uint8_t lun ; ///< Logical Unit @@ -164,7 +164,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct"); /// SCSI Inquiry Command -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_INQUIRY uint8_t reserved1 ; @@ -177,7 +177,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct"); /// SCSI Inquiry Response Data -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t peripheral_device_type : 5; uint8_t peripheral_qualifier : 3; @@ -223,7 +223,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(scsi_inquiry_resp_t) == 36, "size is not correct"); -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t response_code : 7; ///< 70h - current errors, Fixed Format 71h - deferred errors, Fixed Format uint8_t valid : 1; @@ -249,7 +249,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC(sizeof(scsi_sense_fixed_resp_t) == 18, "size is not correct"); -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_MODE_SENSE_6 @@ -268,7 +268,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_t) == 6, "size is not correct"); // This is only a Mode parameter header(6). -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t data_len; uint8_t medium_type; @@ -281,7 +281,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_resp_t) == 4, "size is not correct"); -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t cmd_code; ///< SCSI OpCode for \ref SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL uint8_t reserved[3]; @@ -291,7 +291,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct"); -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t cmd_code; @@ -318,7 +318,7 @@ TU_VERIFY_STATIC( sizeof(scsi_start_stop_unit_t) == 6, "size is not correct"); // SCSI MMC //--------------------------------------------------------------------+ /// SCSI Read Format Capacity: Write Capacity -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t cmd_code; uint8_t reserved[6]; @@ -328,7 +328,7 @@ typedef struct ATTR_PACKED TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct"); -typedef struct ATTR_PACKED{ +typedef struct TU_ATTR_PACKED{ uint8_t reserved[3]; uint8_t list_length; /// must be 8*n, length in bytes of formattable capacity descriptor followed it. @@ -348,7 +348,7 @@ TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not c //--------------------------------------------------------------------+ /// SCSI Read Capacity 10 Command: Read Capacity -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_READ_CAPACITY_10 uint8_t reserved1 ; @@ -369,7 +369,7 @@ typedef struct { TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_resp_t) == 8, "size is not correct"); /// SCSI Read 10 Command -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t cmd_code ; ///< SCSI OpCode uint8_t reserved ; // has LUN according to wiki diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc_device.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc_device.h index b2cd7e89f..d66994851 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc_device.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc_device.h @@ -72,7 +72,7 @@ bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, u * \retval negative Indicate error e.g reading disk I/O. tinyusb will \b STALL the corresponding * endpoint and return failed status in command status wrapper phase. */ -ATTR_WEAK int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize); +TU_ATTR_WEAK int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize); /** * Invoked when received \ref SCSI_CMD_WRITE_10 command @@ -91,19 +91,19 @@ ATTR_WEAK int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, * \retval negative Indicate error writing disk I/O. Tinyusb will \b STALL the corresponding * endpoint and return failed status in command status wrapper phase. */ -ATTR_WEAK int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize); +TU_ATTR_WEAK int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize); // Invoked when received SCSI_CMD_INQUIRY // Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively -ATTR_WEAK void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]); +TU_ATTR_WEAK void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]); // Invoked when received Test Unit Ready command. // return true allowing host to read/write this LUN e.g SD card inserted -ATTR_WEAK bool tud_msc_test_unit_ready_cb(uint8_t lun); +TU_ATTR_WEAK bool tud_msc_test_unit_ready_cb(uint8_t lun); // Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size // Application update block count and block size -ATTR_WEAK void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size); +TU_ATTR_WEAK void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size); /** * Invoked when received an SCSI command not in built-in list below. @@ -121,29 +121,29 @@ ATTR_WEAK void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* * \retval negative Indicate error e.g unsupported command, tinyusb will \b STALL the corresponding * endpoint and return failed status in command status wrapper phase. */ -ATTR_WEAK int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize); +TU_ATTR_WEAK int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize); /*------------- Optional callbacks -------------*/ // Invoked when received GET_MAX_LUN request, required for multiple LUNs implementation -ATTR_WEAK uint8_t tud_msc_get_maxlun_cb(void); +TU_ATTR_WEAK uint8_t tud_msc_get_maxlun_cb(void); // Invoked when received Start Stop Unit command // - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage // - Start = 1 : active mode, if load_eject = 1 : load disk storage -ATTR_WEAK void tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject); +TU_ATTR_WEAK void tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject); // Invoked when Read10 command is complete -ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun); +TU_ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun); // Invoke when Write10 command is complete, can be used to flush flash caching -ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun); +TU_ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun); // Invoked when command in tud_msc_scsi_cb is complete -ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16]); +TU_ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16]); // Hook to make a mass storage device read-only. TODO remove -ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun); +TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun); /** @} */ /** @} */ diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_common.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_common.h index 4b74bcfc0..c77be2a9f 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_common.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_common.h @@ -57,9 +57,6 @@ #define TU_BIT(n) (1U << (n)) -// for declaration of reserved field, make use of _TU_COUNTER_ -#define TU_RESERVED XSTRING_CONCAT_(reserved, _TU_COUNTER_) - //--------------------------------------------------------------------+ // INCLUDES //--------------------------------------------------------------------+ diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_compiler.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_compiler.h index 0978d1c0f..09768ef88 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_compiler.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_compiler.h @@ -32,10 +32,10 @@ #ifndef _TUSB_COMPILER_H_ #define _TUSB_COMPILER_H_ -#define STRING_(x) #x ///< stringify without expand -#define XSTRING_(x) STRING_(x) ///< expand then stringify -#define STRING_CONCAT_(a, b) a##b ///< concat without expand -#define XSTRING_CONCAT_(a, b) STRING_CONCAT_(a, b) ///< expand then concat +#define TU_STRING(x) #x ///< stringify without expand +#define TU_XSTRING(x) TU_STRING(x) ///< expand then stringify +#define TU_STRCAT(a, b) a##b ///< concat without expand +#define TU_XSTRCAT(a, b) TU_STRCAT(a, b) ///< expand then concat #if defined __COUNTER__ && __COUNTER__ != __COUNTER__ #define _TU_COUNTER_ __COUNTER__ @@ -47,20 +47,23 @@ #if __STDC_VERSION__ >= 201112L #define TU_VERIFY_STATIC _Static_assert #else - #define TU_VERIFY_STATIC(const_expr, _mess) enum { XSTRING_CONCAT_(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) } + #define TU_VERIFY_STATIC(const_expr, _mess) enum { TU_XSTRCAT(_verify_static_, _TU_COUNTER_) = 1/(!!(const_expr)) } #endif +// for declaration of reserved field, make use of _TU_COUNTER_ +#define TU_RESERVED TU_XSTRCAT(reserved, _TU_COUNTER_) + //--------------------------------------------------------------------+ // Compiler porting with Attribute and Endian //--------------------------------------------------------------------+ #if defined(__GNUC__) - #define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes))) - #define ATTR_SECTION(sec_name) __attribute__ ((section(#sec_name))) - #define ATTR_PACKED __attribute__ ((packed)) - #define ATTR_PREPACKED - #define ATTR_WEAK __attribute__ ((weak)) - #define ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used - #define ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused + #define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes))) + #define TU_ATTR_SECTION(sec_name) __attribute__ ((section(#sec_name))) + #define TU_ATTR_PACKED __attribute__ ((packed)) + #define TU_ATTR_PREPACKED + #define TU_ATTR_WEAK __attribute__ ((weak)) + #define TU_ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used + #define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused // Endian conversion use well-known host to network (big endian) naming #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_types.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_types.h index 786533849..34ad26f15 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_types.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/common/tusb_types.h @@ -200,7 +200,7 @@ enum //--------------------------------------------------------------------+ /// USB Standard Device Descriptor (section 9.6.1, table 9-8) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes. uint8_t bDescriptorType ; ///< DEVICE Descriptor Type. @@ -222,7 +222,7 @@ typedef struct ATTR_PACKED } tusb_desc_device_t; /// USB Standard Configuration Descriptor (section 9.6.1 table 9-10) */ -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type @@ -236,7 +236,7 @@ typedef struct ATTR_PACKED } tusb_desc_configuration_t; /// USB Standard Interface Descriptor (section 9.6.1 table 9-12) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes uint8_t bDescriptorType ; ///< INTERFACE Descriptor Type @@ -251,21 +251,21 @@ typedef struct ATTR_PACKED } tusb_desc_interface_t; /// USB Standard Endpoint Descriptor (section 9.6.1 table 9-13) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes uint8_t bDescriptorType ; ///< ENDPOINT Descriptor Type uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint. - struct ATTR_PACKED { + struct TU_ATTR_PACKED { uint8_t xfer : 2; uint8_t sync : 2; uint8_t usage : 2; uint8_t : 2; } bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host. - struct ATTR_PACKED { + struct TU_ATTR_PACKED { uint16_t size : 11; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero. uint16_t hs_period_mult : 2; uint16_t : 0; @@ -275,7 +275,7 @@ typedef struct ATTR_PACKED } tusb_desc_endpoint_t; /// USB Other Speed Configuration Descriptor (section 9.6.1 table 9-11) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of descriptor uint8_t bDescriptorType ; ///< Other_speed_Configuration Type @@ -289,7 +289,7 @@ typedef struct ATTR_PACKED } tusb_desc_other_speed_t; /// USB Device Qualifier Descriptor (section 9.6.1 table 9-9) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of descriptor uint8_t bDescriptorType ; ///< Device Qualifier Type @@ -304,7 +304,7 @@ typedef struct ATTR_PACKED } tusb_desc_device_qualifier_t; /// USB Interface Association Descriptor (IAD ECN) -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of descriptor uint8_t bDescriptorType ; ///< Other_speed_Configuration Type @@ -320,13 +320,13 @@ typedef struct ATTR_PACKED } tusb_desc_interface_assoc_t; /// USB Header Descriptor -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes uint8_t bDescriptorType ; ///< Descriptor Type } tusb_desc_header_t; -typedef struct ATTR_PACKED +typedef struct TU_ATTR_PACKED { uint8_t bLength ; ///< Size of this descriptor in bytes uint8_t bDescriptorType ; ///< Descriptor Type @@ -337,9 +337,9 @@ typedef struct ATTR_PACKED /*------------------------------------------------------------------*/ /* Types *------------------------------------------------------------------*/ -typedef struct ATTR_PACKED{ +typedef struct TU_ATTR_PACKED{ union { - struct ATTR_PACKED { + struct TU_ATTR_PACKED { uint8_t recipient : 5; ///< Recipient type tusb_request_recipient_t. uint8_t type : 2; ///< Request type tusb_request_type_t. uint8_t direction : 1; ///< Direction type. tusb_dir_t diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/dcd.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/dcd.h index bd7088fe4..0ed4a77d9 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/dcd.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/dcd.h @@ -52,7 +52,7 @@ typedef enum USBD_EVENT_FUNC_CALL } dcd_eventid_t; -typedef struct ATTR_ALIGNED(4) +typedef struct TU_ATTR_ALIGNED(4) { uint8_t rhport; uint8_t event_id; diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.c b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.c index e22de4728..38838b61f 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.c +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.c @@ -40,7 +40,7 @@ // Device Data //--------------------------------------------------------------------+ typedef struct { - struct ATTR_PACKED + struct TU_ATTR_PACKED { volatile uint8_t connected : 1; volatile uint8_t configured : 1; diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.h index 46143a215..4b10f1a0e 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.h @@ -76,17 +76,17 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index); uint16_t const* tud_descriptor_string_cb(uint8_t index); // Invoked when device is mounted (configured) -ATTR_WEAK void tud_mount_cb(void); +TU_ATTR_WEAK void tud_mount_cb(void); // Invoked when device is unmounted -ATTR_WEAK void tud_umount_cb(void); +TU_ATTR_WEAK void tud_umount_cb(void); // Invoked when usb bus is suspended // Within 7ms, device must draw an average of current less than 2.5 mA from bus -ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en); +TU_ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en); // Invoked when usb bus is resumed -ATTR_WEAK void tud_resume_cb(void); +TU_ATTR_WEAK void tud_resume_cb(void); //--------------------------------------------------------------------+ // Interface Descriptor Template diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/tusb_option.h b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/tusb_option.h index 694191406..9415992a7 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/tusb_option.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/tusb_option.h @@ -131,7 +131,7 @@ #endif #ifndef CFG_TUSB_MEM_ALIGN -#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) +#define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4) #endif #ifndef CFG_TUSB_OS diff --git a/cores/nRF5/Adafruit_TinyUSB_Core/tusb_config.h b/cores/nRF5/Adafruit_TinyUSB_Core/tusb_config.h index f117108bc..2448c838e 100644 --- a/cores/nRF5/Adafruit_TinyUSB_Core/tusb_config.h +++ b/cores/nRF5/Adafruit_TinyUSB_Core/tusb_config.h @@ -42,7 +42,7 @@ #define CFG_TUSB_OS OPT_OS_FREERTOS #define CFG_TUSB_MEM_SECTION -#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) +#define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4) //-------------------------------------------------------------------- // DEVICE CONFIGURATION From a73eb9d765d94b2401f0924a38bd397aff38dc81 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Jun 2019 11:19:13 +0700 Subject: [PATCH 3/6] clean up compipler macros --- cores/nRF5/compiler_macro.h | 85 +------------------ cores/nRF5/verify.h | 8 +- .../src/services/BLEHidGeneric.h | 7 +- 3 files changed, 8 insertions(+), 92 deletions(-) diff --git a/cores/nRF5/compiler_macro.h b/cores/nRF5/compiler_macro.h index 1bdddc232..698717ae0 100644 --- a/cores/nRF5/compiler_macro.h +++ b/cores/nRF5/compiler_macro.h @@ -36,92 +36,13 @@ */ /******************************************************************************/ -/** \ingroup Group_Compiler - * \defgroup Group_GCC GNU GCC - * @{ - */ - #ifndef _COMPILER_MACRO_H_ #define _COMPILER_MACRO_H_ -#define STRING_(x) #x // stringify without expand -#define XSTRING_(x) STRING_(x) // expand then stringify -#define STRING_CONCAT_(a, b) a##b // concat without expand -#define XSTRING_CONCAT_(a, b) STRING_CONCAT_(a, b) // expand then concat - -#define ALIGN_OF(x) __alignof__(x) - -/// Normally, the compiler places the objects it generates in sections like data or bss & function in text. Sometimes, however, you need additional sections, or you need certain particular variables to appear in special sections, for example to map to special hardware. The section attribute specifies that a variable (or function) lives in a particular section -#define ATTR_SECTION(section) __attribute__ ((#section)) - -/// If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, an error that includes message is diagnosed. This is useful for compile-time checking -#define ATTR_ERROR(Message) __attribute__ ((error(Message))) - -/// If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, a warning that includes message is diagnosed. This is useful for compile-time checking -#define ATTR_WARNING(Message) __attribute__ ((warning(Message))) - -/** - * \defgroup Group_VariableAttr Variable Attributes - * @{ - */ - -/// This attribute specifies a minimum alignment for the variable or structure field, measured in bytes -#define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes))) - -/// The packed attribute specifies that a variable or structure field should have the smallest possible alignment—one byte for a variable, and one bit for a field, unless you specify a larger value with the aligned attribute -#define ATTR_PACKED __attribute__ ((packed)) - -#define ATTR_PREPACKED - -#define ATTR_PACKED_STRUCT(x) x __attribute__ ((packed)) -/** @} */ - -/** - * \defgroup Group_FuncAttr Function Attributes - * @{ - */ - -/// Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level is specified -#define ATTR_ALWAYS_INLINE __attribute__ ((always_inline)) - -/// The nonnull attribute specifies that some function parameters should be non-null pointers. f the compiler determines that a null pointer is passed in an argument slot marked as non-null, and the -Wnonnull option is enabled, a warning is issued. All pointer arguments are marked as non-null -#define ATTR_NON_NULL __attribute__ ((nonull)) - -#define ATTR_NO_RETURN __attribute__ ((noreturn)) - -/// Many functions have no effects except the return value and their return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure -#define ATTR_PURE __attribute__ ((pure)) - -/// Many functions do not examine any values except their arguments, and have no effects except the return value. Basically this is just slightly more strict class than the pure attribute below, since function is not allowed to read global memory. -/// Note that a function that has pointer arguments and examines the data pointed to must not be declared const. Likewise, a function that calls a non-const function usually must not be const. It does not make sense for a const function to return void -#define ATTR_CONST __attribute__ ((const)) - -/// The deprecated attribute results in a warning if the function is used anywhere in the source file. This is useful when identifying functions that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated function, to enable users to easily find further information about why the function is deprecated, or what they should do instead. Note that the warnings only occurs for uses -#define ATTR_DEPRECATED __attribute__ ((deprecated)) - -/// Same as the deprecated attribute with optional message in the warning -#define ATTR_DEPRECATED_MESS(mess) __attribute__ ((deprecated(mess))) - -/// The weak attribute causes the declaration to be emitted as a weak symbol rather than a global. This is primarily useful in defining library functions that can be overridden in user code -#define ATTR_WEAK __attribute__ ((weak)) - -/// The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified -#define ATTR_ALIAS(func) __attribute__ ((alias(#func))) - -/// The weakref attribute marks a declaration as a weak reference. It is equivalent with weak + alias attribute, but require function is static -#define ATTR_WEAKREF(func) __attribute__ ((weakref(#func))) - -/// The warn_unused_result attribute causes a warning to be emitted if a caller of the function with this attribute does not use its return value. This is useful for functions where not checking the result is either a security problem or always a bug -#define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) - -/// This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. This is useful, for example, when the function is referenced only in inline assembly. -#define ATTR_USED __attribute__ ((used)) - -/// This attribute, attached to a function, means that the function is meant to be possibly unused. GCC does not produce a warning for this function. -#define ATTR_UNUSED __attribute__ ((unused)) +#include "common/tusb_compiler.h" -#define ATTR_OPTIMIZE(n) __attribute__ ((optimize(XSTRING_(O##n)))) +#define ATTR_PACKED TU_ATTR_PACKED +#define ATTR_WEAK TU_ATTR_WEAK #endif /* _COMPILER_MACRO_H_ */ -/// @} diff --git a/cores/nRF5/verify.h b/cores/nRF5/verify.h index 0b8d52745..24ad994dc 100644 --- a/cores/nRF5/verify.h +++ b/cores/nRF5/verify.h @@ -50,13 +50,7 @@ extern "C" //--------------------------------------------------------------------+ // Compile-time Assert //--------------------------------------------------------------------+ -#if defined __COUNTER__ && __COUNTER__ != __COUNTER__ - #define _VERIFY_COUNTER __COUNTER__ -#else - #define _VERIFY_COUNTER __LINE__ -#endif - -#define VERIFY_STATIC(const_expr) enum { XSTRING_CONCAT_(static_verify_, _VERIFY_COUNTER) = 1/(!!(const_expr)) } +#define VERIFY_STATIC(const_expr) TU_VERIFY_STATIC(const_expr, "Assert failed") //--------------------------------------------------------------------+ // VERIFY Helper diff --git a/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h b/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h index 5f7a09cbc..d7d86804b 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h +++ b/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h @@ -64,15 +64,16 @@ extern hid_keycode_to_ascii_t const hid_keycode_to_ascii[128]; /// HID Consumer Control Report -typedef ATTR_PACKED_STRUCT(struct) +typedef struct ATTR_PACKED { uint16_t usage_value; ///< Usage value of the pressed control } hid_consumer_control_report_t; /// Gamepad report -typedef ATTR_PACKED_STRUCT(struct) +typedef struct ATTR_PACKED { - ATTR_PACKED_STRUCT(struct){ + struct ATTR_PACKED + { uint8_t x : 2; uint8_t y : 2; uint8_t : 4; From 452db14e415c14c8f4942e50cdf9aaa5e693ad40 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Jun 2019 11:19:53 +0700 Subject: [PATCH 4/6] remove rtos_idle_callback(), sketch define vApplicationIdleHook() if needed --- cores/nRF5/Arduino.h | 2 -- cores/nRF5/hooks.c | 2 ++ cores/nRF5/rtos.cpp | 6 ------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/cores/nRF5/Arduino.h b/cores/nRF5/Arduino.h index 8ac06a865..d45da06ec 100644 --- a/cores/nRF5/Arduino.h +++ b/cores/nRF5/Arduino.h @@ -119,8 +119,6 @@ void suspendLoop(void); #define portInputRegister(port) ( (volatile uint32_t*) &(port->IN) ) #define portModeRegister(port) ( &(port->DIR) ) #define digitalPinHasPWM(P) ( g_ADigitalPinMap[P] > 1 ) - -void rtos_idle_callback(void) ATTR_WEAK; /* * digitalPinToTimer(..) is AVR-specific and is not defined for nRF52 * architecture. If you need to check if a pin supports PWM you must diff --git a/cores/nRF5/hooks.c b/cores/nRF5/hooks.c index f87c20444..f00bbb244 100644 --- a/cores/nRF5/hooks.c +++ b/cores/nRF5/hooks.c @@ -30,6 +30,8 @@ static void __empty() { } void yield(void) __attribute__ ((weak, alias("__empty"))); +void vApplicationIdleHook( void ) __attribute__ ((weak, alias("__empty"))); + /** * SysTick hook * diff --git a/cores/nRF5/rtos.cpp b/cores/nRF5/rtos.cpp index 7e164f78d..2006822ca 100644 --- a/cores/nRF5/rtos.cpp +++ b/cores/nRF5/rtos.cpp @@ -101,12 +101,6 @@ void vApplicationMallocFailedHook(void) LOG_LV1("RTOS", "Failed to Malloc"); } -void vApplicationIdleHook( void ) -{ - // Call user callback if defined - if ( rtos_idle_callback ) rtos_idle_callback(); -} - /* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an * implementation of vApplicationGetIdleTaskMemory() to provide the memory that is * used by the Idle task. */ From 6bcffbd2528425a24bb2bd39ff53e50c4c580e35 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Jun 2019 11:40:56 +0700 Subject: [PATCH 5/6] clean up warnings --- cores/nRF5/utility/debug.cpp | 2 +- libraries/Bluefruit52Lib/src/BLEAdvertising.cpp | 2 +- libraries/Bluefruit52Lib/src/BLEDiscovery.cpp | 5 ++++- libraries/InternalFileSytem/src/flash/flash_cache.c | 3 ++- libraries/InternalFileSytem/src/flash/flash_nrf5x.c | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cores/nRF5/utility/debug.cpp b/cores/nRF5/utility/debug.cpp index 58fc0d23e..7939fcfa3 100644 --- a/cores/nRF5/utility/debug.cpp +++ b/cores/nRF5/utility/debug.cpp @@ -262,7 +262,7 @@ void dbgDumpMemoryCFormat(const char* str, void const *buf, uint16_t count) buf8++; } - printf("\n\};\n"); + printf("\n};\n"); } diff --git a/libraries/Bluefruit52Lib/src/BLEAdvertising.cpp b/libraries/Bluefruit52Lib/src/BLEAdvertising.cpp index b8b76f7b3..a766b588c 100644 --- a/libraries/Bluefruit52Lib/src/BLEAdvertising.cpp +++ b/libraries/Bluefruit52Lib/src/BLEAdvertising.cpp @@ -346,7 +346,7 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout) }, .p_peer_addr = NULL , // Undirected advertisement .interval = interval , // advertising interval (in units of 0.625 ms) - .duration = timeout*100 , // in 10-ms unit + .duration = (uint16_t) (timeout*100), // in 10-ms unit .max_adv_evts = 0, // TODO can be used for fast/slow mode .channel_mask = { 0, 0, 0, 0, 0 } , // 40 channel, set 1 to disable diff --git a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp index 220e5d840..0c789b545 100644 --- a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp +++ b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp @@ -144,7 +144,10 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar // only discover CCCD descriptor if (disc_chr->chars[d].char_props.notify || disc_chr->chars[d].char_props.indicate ) { - ble_gattc_handle_range_t range = { disc_chr->chars[d].handle_value + 1, _hdl_range.end_handle }; + ble_gattc_handle_range_t range = { + .start_handle = (uint16_t) (disc_chr->chars[d].handle_value + 1), + .end_handle = _hdl_range.end_handle + }; if ( range.start_handle <= range.end_handle ) { diff --git a/libraries/InternalFileSytem/src/flash/flash_cache.c b/libraries/InternalFileSytem/src/flash/flash_cache.c index 5fc17609c..7004b6ddd 100644 --- a/libraries/InternalFileSytem/src/flash/flash_cache.c +++ b/libraries/InternalFileSytem/src/flash/flash_cache.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ +#include #include "flash_cache.h" #include "common_func.h" #include "variant.h" @@ -124,6 +125,6 @@ void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t cou } else { - fc->read(dst, (void*) addr, count); + fc->read(dst, addr, count); } } diff --git a/libraries/InternalFileSytem/src/flash/flash_nrf5x.c b/libraries/InternalFileSytem/src/flash/flash_nrf5x.c index 2a2edb6bb..01b92d69f 100644 --- a/libraries/InternalFileSytem/src/flash/flash_nrf5x.c +++ b/libraries/InternalFileSytem/src/flash/flash_nrf5x.c @@ -26,6 +26,7 @@ #include "flash_cache.h" #include "nrf_sdm.h" #include "nrf_soc.h" +#include "delay.h" #include "rtos.h" //--------------------------------------------------------------------+ From d87536bbb7caab6b6185abdfb8762d4d22aa41c9 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Jun 2019 11:59:38 +0700 Subject: [PATCH 6/6] more warning clean up --- cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.c | 5 +++++ cores/nRF5/verify.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.c b/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.c index 1da677473..bfb8564a5 100644 --- a/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.c +++ b/cores/nRF5/sysview/SEGGER_SYSVIEW_FreeRTOS.c @@ -10,6 +10,9 @@ File : SEGGER_SYSVIEW_FreeRTOS.c Purpose : Interface between FreeRTOS and SystemView. Revision: $Rev: 7947 $ */ + +#if CFG_DEBUG >= 3 + #include "FreeRTOS.h" #include "task.h" #include "SEGGER_SYSVIEW.h" @@ -208,4 +211,6 @@ const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { _cbSendTaskList, }; +#endif // CFG_DEBUG + /*************************** End of file ****************************/ diff --git a/cores/nRF5/verify.h b/cores/nRF5/verify.h index 24ad994dc..8314276b5 100644 --- a/cores/nRF5/verify.h +++ b/cores/nRF5/verify.h @@ -56,6 +56,8 @@ extern "C" // VERIFY Helper //--------------------------------------------------------------------+ #if CFG_DEBUG >= 1 +#include + #define VERIFY_MESS(_status, _funcstr) \ do { \ const char* (*_fstr)(int32_t) = _funcstr;\