Skip to content

Commit dfb010e

Browse files
committed
Change MBED_STATIC_ASSERTs version for built-in
1 parent a28e809 commit dfb010e

File tree

30 files changed

+181
-183
lines changed

30 files changed

+181
-183
lines changed

TESTS/mbedmicro-mbed/static_assert/test_c.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,43 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
#include "mbed_assert.h"
18+
#include <assert.h>
1919
#define THE_ANSWER 42
2020

2121
// Tests for static asserts in different contexts
2222
// multiple asserts are used to guarantee no conflicts occur in generated labels
2323

2424
// Test for static asserts in global context
25-
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
26-
"An int must be larger than char");
27-
MBED_STATIC_ASSERT(2 + 2 == 4,
28-
"Hopefully the universe is mathematically consistent");
29-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
30-
"Said Deep Thought, with infinite majesty and calm");
25+
static_assert(sizeof(int) >= sizeof(char),
26+
"An int must be larger than char");
27+
static_assert(2 + 2 == 4,
28+
"Hopefully the universe is mathematically consistent");
29+
static_assert(THE_ANSWER == 42,
30+
"Said Deep Thought, with infinite majesty and calm");
3131

3232
struct test {
3333
int dummy;
3434

3535
// Test for static asserts in struct context
36-
MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char),
37-
"An int must be larger than char");
38-
MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
39-
"Hopefully the universe is mathematically consistent");
40-
MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
41-
"Said Deep Thought, with infinite majesty and calm");
36+
static_assert(sizeof(int) >= sizeof(char),
37+
"An int must be larger than char");
38+
static_assert(2 + 2 == 4,
39+
"Hopefully the universe is mathematically consistent");
40+
static_assert(THE_ANSWER == 42,
41+
"Said Deep Thought, with infinite majesty and calm");
4242
};
4343

44-
MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
45-
"Static assertions should not change the size of a struct");
44+
static_assert(sizeof(struct test) == sizeof(int),
45+
"Static assertions should not change the size of a struct");
4646

4747
void doit_c(void)
4848
{
4949
// Test for static asserts in function context
50-
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
51-
"An int must be larger than char");
52-
MBED_STATIC_ASSERT(2 + 2 == 4,
53-
"Hopefully the universe is mathematically consistent");
54-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
55-
"Said Deep Thought, with infinite majesty and calm");
50+
static_assert(sizeof(int) >= sizeof(char),
51+
"An int must be larger than char");
52+
static_assert(2 + 2 == 4,
53+
"Hopefully the universe is mathematically consistent");
54+
static_assert(THE_ANSWER == 42,
55+
"Said Deep Thought, with infinite majesty and calm");
5656
}
5757

TESTS/mbedmicro-mbed/static_assert/test_cpp.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,43 @@
2222
// multiple asserts are used to guarantee no conflicts occur in generated labels
2323

2424
// Test for static asserts in global context
25-
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
26-
"An int must be larger than char");
27-
MBED_STATIC_ASSERT(2 + 2 == 4,
28-
"Hopefully the universe is mathematically consistent");
29-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
30-
"Said Deep Thought, with infinite majesty and calm");
25+
static_assert(sizeof(int) >= sizeof(char),
26+
"An int must be larger than char");
27+
static_assert(2 + 2 == 4,
28+
"Hopefully the universe is mathematically consistent");
29+
static_assert(THE_ANSWER == 42,
30+
"Said Deep Thought, with infinite majesty and calm");
3131

3232
struct test {
3333
int dummy;
3434

3535
// Test for static asserts in struct context
36-
MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char),
37-
"An int must be larger than char");
38-
MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
39-
"Hopefully the universe is mathematically consistent");
40-
MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
41-
"Said Deep Thought, with infinite majesty and calm");
36+
static_assert(sizeof(int) >= sizeof(char),
37+
"An int must be larger than char");
38+
static_assert(2 + 2 == 4,
39+
"Hopefully the universe is mathematically consistent");
40+
static_assert(THE_ANSWER == 42,
41+
"Said Deep Thought, with infinite majesty and calm");
4242

43-
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
44-
"An int must be larger than char");
45-
MBED_STATIC_ASSERT(2 + 2 == 4,
46-
"Hopefully the universe is mathematically consistent");
47-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
48-
"Said Deep Thought, with infinite majesty and calm");
43+
static_assert(sizeof(int) >= sizeof(char),
44+
"An int must be larger than char");
45+
static_assert(2 + 2 == 4,
46+
"Hopefully the universe is mathematically consistent");
47+
static_assert(THE_ANSWER == 42,
48+
"Said Deep Thought, with infinite majesty and calm");
4949
};
5050

51-
MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
52-
"Static assertions should not change the size of a struct");
51+
static_assert(sizeof(struct test) == sizeof(int),
52+
"Static assertions should not change the size of a struct");
5353

5454
void doit_c(void)
5555
{
5656
// Test for static asserts in function context
57-
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
58-
"An int must be larger than char");
59-
MBED_STATIC_ASSERT(2 + 2 == 4,
60-
"Hopefully the universe is mathematically consistent");
61-
MBED_STATIC_ASSERT(THE_ANSWER == 42,
62-
"Said Deep Thought, with infinite majesty and calm");
57+
static_assert(sizeof(int) >= sizeof(char),
58+
"An int must be larger than char");
59+
static_assert(2 + 2 == 4,
60+
"Hopefully the universe is mathematically consistent");
61+
static_assert(THE_ANSWER == 42,
62+
"Said Deep Thought, with infinite majesty and calm");
6363
}
6464

components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ SDBlockDevice::SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName c
264264
_card_type = SDCARD_NONE;
265265

266266
// Set default to 100kHz for initialisation and 1MHz for data transfer
267-
MBED_STATIC_ASSERT(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
268-
"Initialization frequency should be between 100KHz to 400KHz");
267+
static_assert(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
268+
"Initialization frequency should be between 100KHz to 400KHz");
269269
_init_sck = MBED_CONF_SD_INIT_FREQUENCY;
270270
_transfer_sck = hz;
271271

@@ -285,8 +285,8 @@ SDBlockDevice::SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_
285285
_card_type = SDCARD_NONE;
286286

287287
// Set default to 100kHz for initialisation and 1MHz for data transfer
288-
MBED_STATIC_ASSERT(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
289-
"Initialization frequency should be between 100KHz to 400KHz");
288+
static_assert(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
289+
"Initialization frequency should be between 100KHz to 400KHz");
290290
_init_sck = MBED_CONF_SD_INIT_FREQUENCY;
291291
_transfer_sck = hz;
292292

@@ -711,15 +711,15 @@ uint8_t SDBlockDevice::_cmd_spi(SDBlockDevice::cmdSupported cmd, uint32_t arg)
711711
// CMD0 is executed in SD mode, hence should have correct CRC
712712
// CMD8 CRC verification is always enabled
713713
switch (cmd) {
714-
case CMD0_GO_IDLE_STATE:
715-
cmdPacket[5] = 0x95;
716-
break;
717-
case CMD8_SEND_IF_COND:
718-
cmdPacket[5] = 0x87;
719-
break;
720-
default:
721-
cmdPacket[5] = 0xFF; // Make sure bit 0-End bit is high
722-
break;
714+
case CMD0_GO_IDLE_STATE:
715+
cmdPacket[5] = 0x95;
716+
break;
717+
case CMD8_SEND_IF_COND:
718+
cmdPacket[5] = 0x87;
719+
break;
720+
default:
721+
cmdPacket[5] = 0xFF; // Make sure bit 0-End bit is high
722+
break;
723723
}
724724
}
725725

@@ -817,30 +817,30 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
817817

818818
// Get rest of the response part for other commands
819819
switch (cmd) {
820-
case CMD8_SEND_IF_COND: // Response R7
821-
debug_if(_dbg, "V2-Version Card\n");
822-
_card_type = SDCARD_V2; // fallthrough
823-
// Note: No break here, need to read rest of the response
824-
case CMD58_READ_OCR: // Response R3
825-
response = (_spi.write(SPI_FILL_CHAR) << 24);
826-
response |= (_spi.write(SPI_FILL_CHAR) << 16);
827-
response |= (_spi.write(SPI_FILL_CHAR) << 8);
828-
response |= _spi.write(SPI_FILL_CHAR);
829-
debug_if(_dbg, "R3/R7: 0x%" PRIx32 "\n", response);
830-
break;
820+
case CMD8_SEND_IF_COND: // Response R7
821+
debug_if(_dbg, "V2-Version Card\n");
822+
_card_type = SDCARD_V2; // fallthrough
823+
// Note: No break here, need to read rest of the response
824+
case CMD58_READ_OCR: // Response R3
825+
response = (_spi.write(SPI_FILL_CHAR) << 24);
826+
response |= (_spi.write(SPI_FILL_CHAR) << 16);
827+
response |= (_spi.write(SPI_FILL_CHAR) << 8);
828+
response |= _spi.write(SPI_FILL_CHAR);
829+
debug_if(_dbg, "R3/R7: 0x%" PRIx32 "\n", response);
830+
break;
831831

832-
case CMD12_STOP_TRANSMISSION: // Response R1b
833-
case CMD38_ERASE:
834-
_wait_ready(SD_COMMAND_TIMEOUT);
835-
break;
832+
case CMD12_STOP_TRANSMISSION: // Response R1b
833+
case CMD38_ERASE:
834+
_wait_ready(SD_COMMAND_TIMEOUT);
835+
break;
836836

837-
case ACMD13_SD_STATUS: // Response R2
838-
response = _spi.write(SPI_FILL_CHAR);
839-
debug_if(_dbg, "R2: 0x%" PRIx32 "\n", response);
840-
break;
837+
case ACMD13_SD_STATUS: // Response R2
838+
response = _spi.write(SPI_FILL_CHAR);
839+
debug_if(_dbg, "R2: 0x%" PRIx32 "\n", response);
840+
break;
841841

842-
default: // Response R1
843-
break;
842+
default: // Response R1
843+
break;
844844
}
845845

846846
// Pass the updated response to the command
@@ -1044,41 +1044,41 @@ bd_size_t SDBlockDevice::_sd_sectors()
10441044
// csd_structure : csd[127:126]
10451045
int csd_structure = ext_bits(csd, 127, 126);
10461046
switch (csd_structure) {
1047-
case 0:
1048-
c_size = ext_bits(csd, 73, 62); // c_size : csd[73:62]
1049-
c_size_mult = ext_bits(csd, 49, 47); // c_size_mult : csd[49:47]
1050-
read_bl_len = ext_bits(csd, 83, 80); // read_bl_len : csd[83:80] - the *maximum* read block length
1051-
block_len = 1 << read_bl_len; // BLOCK_LEN = 2^READ_BL_LEN
1052-
mult = 1 << (c_size_mult + 2); // MULT = 2^C_SIZE_MULT+2 (C_SIZE_MULT < 8)
1053-
blocknr = (c_size + 1) * mult; // BLOCKNR = (C_SIZE+1) * MULT
1054-
capacity = (bd_size_t) blocknr * block_len; // memory capacity = BLOCKNR * BLOCK_LEN
1055-
blocks = capacity / _block_size;
1056-
debug_if(SD_DBG, "Standard Capacity: c_size: %" PRIu32 " \n", c_size);
1057-
debug_if(SD_DBG, "Sectors: 0x%" PRIx64 " : %" PRIu64 "\n", blocks, blocks);
1058-
debug_if(SD_DBG, "Capacity: 0x%" PRIx64 " : %" PRIu64 " MB\n", capacity, (capacity / (1024U * 1024U)));
1059-
1060-
// ERASE_BLK_EN = 1: Erase in multiple of 512 bytes supported
1061-
if (ext_bits(csd, 46, 46)) {
1062-
_erase_size = BLOCK_SIZE_HC;
1063-
} else {
1064-
// ERASE_BLK_EN = 1: Erase in multiple of SECTOR_SIZE supported
1065-
_erase_size = BLOCK_SIZE_HC * (ext_bits(csd, 45, 39) + 1);
1066-
}
1067-
break;
1068-
1069-
case 1:
1070-
hc_c_size = ext_bits(csd, 69, 48); // device size : C_SIZE : [69:48]
1071-
blocks = (hc_c_size + 1) << 10; // block count = C_SIZE+1) * 1K byte (512B is block size)
1072-
debug_if(SD_DBG, "SDHC/SDXC Card: hc_c_size: %" PRIu32 " \n", hc_c_size);
1073-
debug_if(SD_DBG, "Sectors: 0x%" PRIx64 "x : %" PRIu64 "\n", blocks, blocks);
1074-
debug_if(SD_DBG, "Capacity: %" PRIu64 " MB\n", (blocks / (2048U)));
1075-
// ERASE_BLK_EN is fixed to 1, which means host can erase one or multiple of 512 bytes.
1047+
case 0:
1048+
c_size = ext_bits(csd, 73, 62); // c_size : csd[73:62]
1049+
c_size_mult = ext_bits(csd, 49, 47); // c_size_mult : csd[49:47]
1050+
read_bl_len = ext_bits(csd, 83, 80); // read_bl_len : csd[83:80] - the *maximum* read block length
1051+
block_len = 1 << read_bl_len; // BLOCK_LEN = 2^READ_BL_LEN
1052+
mult = 1 << (c_size_mult + 2); // MULT = 2^C_SIZE_MULT+2 (C_SIZE_MULT < 8)
1053+
blocknr = (c_size + 1) * mult; // BLOCKNR = (C_SIZE+1) * MULT
1054+
capacity = (bd_size_t) blocknr * block_len; // memory capacity = BLOCKNR * BLOCK_LEN
1055+
blocks = capacity / _block_size;
1056+
debug_if(SD_DBG, "Standard Capacity: c_size: %" PRIu32 " \n", c_size);
1057+
debug_if(SD_DBG, "Sectors: 0x%" PRIx64 " : %" PRIu64 "\n", blocks, blocks);
1058+
debug_if(SD_DBG, "Capacity: 0x%" PRIx64 " : %" PRIu64 " MB\n", capacity, (capacity / (1024U * 1024U)));
1059+
1060+
// ERASE_BLK_EN = 1: Erase in multiple of 512 bytes supported
1061+
if (ext_bits(csd, 46, 46)) {
10761062
_erase_size = BLOCK_SIZE_HC;
1077-
break;
1063+
} else {
1064+
// ERASE_BLK_EN = 1: Erase in multiple of SECTOR_SIZE supported
1065+
_erase_size = BLOCK_SIZE_HC * (ext_bits(csd, 45, 39) + 1);
1066+
}
1067+
break;
10781068

1079-
default:
1080-
debug_if(SD_DBG, "CSD struct unsupported\r\n");
1081-
return 0;
1069+
case 1:
1070+
hc_c_size = ext_bits(csd, 69, 48); // device size : C_SIZE : [69:48]
1071+
blocks = (hc_c_size + 1) << 10; // block count = C_SIZE+1) * 1K byte (512B is block size)
1072+
debug_if(SD_DBG, "SDHC/SDXC Card: hc_c_size: %" PRIu32 " \n", hc_c_size);
1073+
debug_if(SD_DBG, "Sectors: 0x%" PRIx64 "x : %" PRIu64 "\n", blocks, blocks);
1074+
debug_if(SD_DBG, "Capacity: %" PRIu64 " MB\n", (blocks / (2048U)));
1075+
// ERASE_BLK_EN is fixed to 1, which means host can erase one or multiple of 512 bytes.
1076+
_erase_size = BLOCK_SIZE_HC;
1077+
break;
1078+
1079+
default:
1080+
debug_if(SD_DBG, "CSD struct unsupported\r\n");
1081+
return 0;
10821082
};
10831083
return blocks;
10841084
}

drivers/source/MbedCRC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ namespace mbed {
2323

2424
SingletonPtr<PlatformMutex> mbed_crc_mutex;
2525

26-
MBED_STATIC_ASSERT(MBED_CRC_TABLE_SIZE == 0 || MBED_CRC_TABLE_SIZE == 16 || MBED_CRC_TABLE_SIZE == 256,
27-
"Configuration setting drivers.crc-table-size must be set to 0, 16 or 256");
26+
static_assert(MBED_CRC_TABLE_SIZE == 0 || MBED_CRC_TABLE_SIZE == 16 || MBED_CRC_TABLE_SIZE == 256,
27+
"Configuration setting drivers.crc-table-size must be set to 0, 16 or 256");
2828

2929
#if MBED_CRC_TABLE_SIZE > 0
3030

events/source/equeue_mbed.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ static void equeue_tick_update()
105105

106106
void equeue_tick_init()
107107
{
108-
MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER),
109-
"The equeue_timer buffer must fit the class Timer");
110-
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
111-
"The equeue_ticker buffer must fit the class Ticker");
108+
static_assert(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER),
109+
"The equeue_timer buffer must fit the class Timer");
110+
static_assert(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
111+
"The equeue_ticker buffer must fit the class Ticker");
112112
ALIAS_TIMER *timer = new (equeue_timer) ALIAS_TIMER;
113113
ALIAS_TICKER *ticker = new (equeue_ticker) ALIAS_TICKER;
114114

@@ -155,7 +155,7 @@ void equeue_mutex_unlock(equeue_mutex_t *m)
155155

156156
#include "rtos/EventFlags.h"
157157

158-
MBED_STATIC_ASSERT(sizeof(equeue_sema_t) == sizeof(rtos::EventFlags), "equeue_sema_t / rtos::EventFlags mismatch");
158+
static_assert(sizeof(equeue_sema_t) == sizeof(rtos::EventFlags), "equeue_sema_t / rtos::EventFlags mismatch");
159159

160160
int equeue_sema_create(equeue_sema_t *s)
161161
{

features/FEATURE_BLE/ble/common/Duration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct Duration {
137137
Duration(Duration<OtherRep, OtherTB, OtherRange, OtherF> other) :
138138
duration(clamp(other.value() * (OtherTB / TB)))
139139
{
140-
MBED_STATIC_ASSERT(OtherTB >= TB && (OtherTB % TB) == 0, "Incompatible units");
140+
static_assert(OtherTB >= TB && (OtherTB % TB) == 0, "Incompatible units");
141141
}
142142

143143
/**

features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/services/crypto/COMPONENT_PSA_SRV_IPC/psa_crypto_spm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030
#include <stdlib.h>
3131
#include <string.h>
3232
#include <stdbool.h>
33+
#include <assert.h>
3334

3435
#include "psa_manifest/sid.h"
3536
#include "psa/client.h"
3637
#include "psa/crypto.h"
3738
#include "crypto_platform_spe.h"
38-
#include "mbed_assert.h"
3939

4040
#define MINOR_VER 1
4141
#define CLIENT_PSA_KEY_ID_SIZE_IN_BYTES 4
4242

43-
MBED_STATIC_ASSERT(sizeof(psa_key_id_t) == CLIENT_PSA_KEY_ID_SIZE_IN_BYTES, "Unexpected psa_key_id_t size");
43+
static_assert(sizeof(psa_key_id_t) == CLIENT_PSA_KEY_ID_SIZE_IN_BYTES, "Unexpected psa_key_id_t size");
4444

4545
/****************************************************************/
4646
/* INTERNAL HELPER FUNCTIONS */

0 commit comments

Comments
 (0)