rename STATIC_ASSERT to VERIFY_STATIC to avoid name conflict with other codes

This commit is contained in:
hathach 2018-03-28 14:16:14 +07:00
parent 9cacb93bd8
commit 43ac711795
16 changed files with 65 additions and 61 deletions

View File

@ -137,7 +137,7 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint16_t fat_signature ; ///< Signature value (0xAA55).
}fat12_boot_sector_t;
STATIC_ASSERT(sizeof(fat12_boot_sector_t) == 512, "size is not correct");
VERIFY_STATIC(sizeof(fat12_boot_sector_t) == 512, "size is not correct");
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t name[11];
@ -163,7 +163,7 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint32_t file_size;
}fat_directory_t;
STATIC_ASSERT(sizeof(fat_directory_t) == 32, "size is not correct");
VERIFY_STATIC(sizeof(fat_directory_t) == 32, "size is not correct");
void fat12_fs_init(uint8_t msc_device_ramdisk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE])
{

View File

@ -300,7 +300,7 @@ typedef struct ATTR_PACKED
uint8_t : 0;
}cdc_acm_capability_t;
STATIC_ASSERT(sizeof(cdc_acm_capability_t) == 1, "mostly problem with compiler");
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;
STATIC_ASSERT(sizeof(cdc_line_coding_t) == 7, "size is not correct");
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;
STATIC_ASSERT(sizeof(cdc_line_control_state_t) == 2, "size is not correct");
VERIFY_STATIC(sizeof(cdc_line_control_state_t) == 2, "size is not correct");
/** @} */

View File

@ -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;
STATIC_ASSERT(sizeof(rndis_msg_query_t) == 28, "Make sure flexible array member does not affect layout");
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;
STATIC_ASSERT(sizeof(rndis_msg_query_cmplt_t) == 24, "Make sure flexible array member does not affect layout");
VERIFY_STATIC(sizeof(rndis_msg_query_cmplt_t) == 24, "Make sure flexible array member does not affect layout");
//------------- Reset -------------//
/// \brief Reset Message

View File

@ -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;
STATIC_ASSERT(sizeof(msc_cbw_t) == 31, "size is not correct");
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;
STATIC_ASSERT(sizeof(msc_csw_t) == 13, "size is not correct");
VERIFY_STATIC(sizeof(msc_csw_t) == 13, "size is not correct");
//--------------------------------------------------------------------+
// SCSI Constant
@ -172,7 +172,7 @@ typedef struct ATTR_PACKED
uint8_t control ;
} scsi_test_unit_ready_t;
STATIC_ASSERT(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct");
VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct");
/// SCSI Inquiry Command
typedef struct ATTR_PACKED
@ -185,7 +185,7 @@ typedef struct ATTR_PACKED
uint8_t control ;
} scsi_inquiry_t, scsi_request_sense_t;
STATIC_ASSERT(sizeof(scsi_inquiry_t) == 6, "size is not correct");
VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct");
/// SCSI Inquiry Response Data
typedef struct ATTR_PACKED
@ -231,7 +231,7 @@ typedef struct ATTR_PACKED
uint8_t product_revision[4] ; ///< 4 bytes of ASCII data defined by the vendor.
} scsi_inquiry_data_t;
STATIC_ASSERT(sizeof(scsi_inquiry_data_t) == 36, "size is not correct");
VERIFY_STATIC(sizeof(scsi_inquiry_data_t) == 36, "size is not correct");
typedef struct ATTR_PACKED
@ -258,7 +258,7 @@ typedef struct ATTR_PACKED
} scsi_sense_fixed_data_t;
STATIC_ASSERT(sizeof(scsi_sense_fixed_data_t) == 18, "size is not correct");
VERIFY_STATIC(sizeof(scsi_sense_fixed_data_t) == 18, "size is not correct");
typedef struct ATTR_PACKED
{
@ -276,7 +276,7 @@ typedef struct ATTR_PACKED
uint8_t control;
} scsi_mode_sense_6_t;
STATIC_ASSERT( sizeof(scsi_mode_sense_6_t) == 6, "size is not correct");
VERIFY_STATIC( sizeof(scsi_mode_sense_6_t) == 6, "size is not correct");
typedef struct ATTR_PACKED
{
@ -286,7 +286,7 @@ typedef struct ATTR_PACKED
uint8_t block_descriptor_length;
} scsi_mode_parameters_t;
STATIC_ASSERT( sizeof(scsi_mode_parameters_t) == 4, "size is not correct");
VERIFY_STATIC( sizeof(scsi_mode_parameters_t) == 4, "size is not correct");
typedef struct ATTR_PACKED
{
@ -296,7 +296,7 @@ typedef struct ATTR_PACKED
uint8_t control;
} scsi_prevent_allow_medium_removal_t;
STATIC_ASSERT( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct");
VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct");
//--------------------------------------------------------------------+
// SCSI MMC
@ -310,7 +310,7 @@ typedef struct ATTR_PACKED
uint8_t control;
} scsi_read_format_capacity_t;
STATIC_ASSERT( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct");
VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct");
typedef struct ATTR_PACKED{
uint8_t reserved[3];
@ -324,7 +324,7 @@ typedef struct ATTR_PACKED{
} scsi_read_format_capacity_data_t;
STATIC_ASSERT( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not correct");
VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not correct");
//--------------------------------------------------------------------+
// SCSI Block Command (SBC-3)
@ -342,7 +342,7 @@ typedef struct ATTR_PACKED
uint8_t control ;
} scsi_read_capacity10_t;
STATIC_ASSERT(sizeof(scsi_read_capacity10_t) == 10, "size is not correct");
VERIFY_STATIC(sizeof(scsi_read_capacity10_t) == 10, "size is not correct");
/// SCSI Read Capacity 10 Response Data
typedef struct {
@ -350,7 +350,7 @@ typedef struct {
uint32_t block_size ; ///< Block size in bytes
} scsi_read_capacity10_data_t;
STATIC_ASSERT(sizeof(scsi_read_capacity10_data_t) == 8, "size is not correct");
VERIFY_STATIC(sizeof(scsi_read_capacity10_data_t) == 8, "size is not correct");
/// SCSI Read 10 Command
typedef struct ATTR_PACKED
@ -363,8 +363,8 @@ typedef struct ATTR_PACKED
uint8_t control ;
} scsi_read10_t, scsi_write10_t;
STATIC_ASSERT(sizeof(scsi_read10_t) == 10, "size is not correct");
STATIC_ASSERT(sizeof(scsi_write10_t) == 10, "size is not correct");
VERIFY_STATIC(sizeof(scsi_read10_t) == 10, "size is not correct");
VERIFY_STATIC(sizeof(scsi_write10_t) == 10, "size is not correct");
#ifdef __cplusplus
}

View File

@ -1,6 +1,6 @@
/**************************************************************************/
/*!
@file common.h
@file tusb_common.h
@author hathach (tinyusb.org)
@section LICENSE

View File

@ -53,7 +53,7 @@
// Compile-time Assert
//--------------------------------------------------------------------+
#ifdef __ICCARM__
#define STATIC_ASSERT static_assert
#define VERIFY_STATIC static_assert
#else
#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
#define _ASSERT_COUNTER __COUNTER__
@ -61,7 +61,7 @@
#define _ASSERT_COUNTER __LINE__
#endif
#define STATIC_ASSERT(const_expr, message) enum { XSTRING_CONCAT_(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) }
#define VERIFY_STATIC(const_expr, message) enum { XSTRING_CONCAT_(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) }
#endif
// allow debugger to watch any module-wide variables anywhere

View File

@ -380,7 +380,7 @@ typedef struct ATTR_PACKED{
uint16_t wLength;
} tusb_control_request_t;
STATIC_ASSERT( sizeof(tusb_control_request_t) == 8, "mostly compiler option issue");
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)

View File

@ -45,16 +45,26 @@
extern "C" {
#endif
//--------------------------------------------------------------------+
// Compile-time Verify
//--------------------------------------------------------------------+
#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
#define _VERIFY_COUNTER __COUNTER__
#else
#define _VERIFY_COUNTER __LINE__
#endif
/**
* Helper to implement optional parameter for VERIFY Macro family
*/
#define GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
#define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
#define VERIFY_STATIC(const_expr) enum { XSTRING_CONCAT_(static_verify_, _VERIFY_COUNTER) = 1/(!!(const_expr)) }
//--------------------------------------------------------------------+
// Compile-time Verify (like assert static)
//--------------------------------------------------------------------+
#ifdef __ICCARM__
#define VERIFY_STATIC static_assert
#else
#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
#define _VERIFY_COUNTER __COUNTER__
#else
#define _VERIFY_COUNTER __LINE__
#endif
#define VERIFY_STATIC(const_expr, _mess) enum { XSTRING_CONCAT_(_verify_static_, _VERIFY_COUNTER) = 1/(!!(const_expr)) }
#endif
//--------------------------------------------------------------------+
// VERIFY Helper
@ -68,12 +78,6 @@
#define _ASSERT_MESS()
#endif
/**
* Helper to implement optional parameter for VERIFY Macro family
*/
#define GET_3RD_ARG(arg1, arg2, arg3, ...) arg3
#define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
/*------------------------------------------------------------------*/
/* VERIFY STATUS
* - VERIFY_STS_1ARGS : return status of condition if failed

View File

@ -178,7 +178,7 @@ typedef struct ATTR_ALIGNED(4)
};
} usbd_task_event_t;
STATIC_ASSERT(sizeof(usbd_task_event_t) <= 12, "size is not correct");
VERIFY_STATIC(sizeof(usbd_task_event_t) <= 12, "size is not correct");
#ifndef TUC_DEVICE_STACKSIZE
#define TUC_DEVICE_STACKSIZE 150

View File

@ -65,7 +65,7 @@ TUSB_CFG_ATTR_USBRAM STATIC_VAR ehci_data_t ehci_data;
TUSB_CFG_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
STATIC_ASSERT( ALIGN_OF(period_frame_list0) == 4096, "Period Framelist must be 4k alginment"); // validation
VERIFY_STATIC( ALIGN_OF(period_frame_list0) == 4096, "Period Framelist must be 4k alginment"); // validation
#endif
#endif
@ -73,7 +73,7 @@ TUSB_CFG_ATTR_USBRAM STATIC_VAR ehci_data_t ehci_data;
TUSB_CFG_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
STATIC_ASSERT( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4k alginment"); // validation
VERIFY_STATIC( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4k alginment"); // validation
#endif
#endif
#endif

View File

@ -81,7 +81,7 @@ enum {
};
//------------- Validation -------------//
STATIC_ASSERT(EHCI_CFG_FRAMELIST_SIZE_BITS <= 7, "incorrect value");
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)
STATIC_ASSERT( sizeof(ehci_qtd_t) == 32, "size is not correct" );
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;
STATIC_ASSERT( sizeof(ehci_qhd_t) == 64, "size is not correct" );
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;
STATIC_ASSERT( sizeof(ehci_itd_t) == 64, "size is not correct" );
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;
STATIC_ASSERT( sizeof(ehci_sitd_t) == 32, "size is not correct" );
VERIFY_STATIC( sizeof(ehci_sitd_t) == 32, "size is not correct" );
//--------------------------------------------------------------------+
// EHCI Operational Register

View File

@ -104,7 +104,7 @@ typedef struct ATTR_PACKED{
uint8_t PortPwrCtrlMask; // just for compatibility, should be 0xff
} descriptor_hub_desc_t;
STATIC_ASSERT( sizeof(descriptor_hub_desc_t) == 9, "size is not correct");
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;
STATIC_ASSERT( sizeof(hub_status_response_t) == 4, "size is not correct");
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;
STATIC_ASSERT( sizeof(hub_port_status_response_t) == 4, "size is not correct");
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);

View File

@ -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)
STATIC_ASSERT( sizeof(ohci_hcca_t) == 256, "size is not correct" );
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;
STATIC_ASSERT( sizeof(ohci_gtd_t) == 16, "size is not correct" );
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;
STATIC_ASSERT( sizeof(ohci_ed_t) == 16, "size is not correct" );
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;
STATIC_ASSERT( sizeof(ochi_itd_t) == 32, "size is not correct" );
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;
STATIC_ASSERT( sizeof(ohci_registers_t) == 0x5c, "size is not correct");
VERIFY_STATIC( sizeof(ohci_registers_t) == 0x5c, "size is not correct");
#ifdef __cplusplus
}

View File

@ -105,7 +105,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;
STATIC_ASSERT( sizeof(dcd_11u_13u_qhd_t) == 4, "size is not correct" );
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.

View File

@ -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;
STATIC_ASSERT( sizeof(dcd_dma_descriptor_t) == 16, "size is not correct"); // TODO not support ISO for now
VERIFY_STATIC( sizeof(dcd_dma_descriptor_t) == 16, "size is not correct"); // TODO not support ISO for now
//--------------------------------------------------------------------+

View File

@ -119,7 +119,7 @@ typedef struct {
uint8_t reserved;
} dcd_qtd_t;
STATIC_ASSERT( sizeof(dcd_qtd_t) == 32, "size is not correct");
VERIFY_STATIC( sizeof(dcd_qtd_t) == 32, "size is not correct");
typedef struct ATTR_ALIGNED(64) {
// Word 0: Capabilities and Characteristics
@ -149,7 +149,7 @@ typedef struct ATTR_ALIGNED(64) {
uint8_t reserved[16-DCD_QTD_PER_QHD_MAX];
} dcd_qhd_t;
STATIC_ASSERT( sizeof(dcd_qhd_t) == 64, "size is not correct");
VERIFY_STATIC( sizeof(dcd_qhd_t) == 64, "size is not correct");
#ifdef __cplusplus