|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2016 Nordic Semiconductor ASA |
| 2 | + * Copyright (c) 2016-2025 Nordic Semiconductor ASA |
3 | 3 | * Copyright (c) 2016 Vinayak Kariappa Chettimada
|
4 | 4 | *
|
5 | 5 | * SPDX-License-Identifier: Apache-2.0
|
6 | 6 | */
|
7 | 7 |
|
8 | 8 | #include "common/assert.h"
|
9 | 9 |
|
10 |
| -#ifdef CONFIG_BT_CTLR_ASSERT_HANDLER |
| 10 | +#if defined(CONFIG_BT_CTLR_ASSERT_HANDLER) |
11 | 11 | void bt_ctlr_assert_handle(char *file, uint32_t line);
|
| 12 | + |
| 13 | +#if defined(CONFIG_BT_CTLR_ASSERT_OPTIMIZE_FOR_SIZE) |
| 14 | +BUILD_ASSERT(IS_ENABLED(CONFIG_CPU_CORTEX_M)); |
| 15 | +/* Generate assertion as undefined instruction exception. |
| 16 | + */ |
| 17 | +#define LL_ASSERT(x) \ |
| 18 | + do { \ |
| 19 | + if (unlikely(!(x))) { \ |
| 20 | + __asm__ inline volatile (".inst 0xde00\n"); \ |
| 21 | + } \ |
| 22 | + } while (0) |
| 23 | + |
| 24 | +#else /* !CONFIG_BT_CTLR_ASSERT_OPTIMIZE_FOR_SIZE */ |
| 25 | +/* Generate assertion with file name and line number. |
| 26 | + * NOTE: Variable code size increase per assertion check, depends on full file name path string |
| 27 | + * length. |
| 28 | + */ |
12 | 29 | #define LL_ASSERT(cond) \
|
13 |
| - if (!(cond)) { \ |
| 30 | + if (unlikely(!(cond))) { \ |
14 | 31 | BT_ASSERT_PRINT(cond); \
|
15 | 32 | bt_ctlr_assert_handle(__FILE__, __LINE__); \
|
16 | 33 | }
|
| 34 | +#endif /* !CONFIG_BT_CTLR_ASSERT_OPTIMIZE_FOR_SIZE */ |
| 35 | + |
17 | 36 | #define LL_ASSERT_MSG(cond, fmt, ...) \
|
18 |
| - if (!(cond)) { \ |
| 37 | + if (unlikely(!(cond))) { \ |
19 | 38 | BT_ASSERT_PRINT(cond); \
|
20 | 39 | BT_ASSERT_PRINT_MSG(fmt, ##__VA_ARGS__); \
|
21 | 40 | bt_ctlr_assert_handle(__FILE__, __LINE__); \
|
22 | 41 | }
|
23 |
| -#else |
| 42 | + |
| 43 | +#else /* !CONFIG_BT_CTLR_ASSERT_HANDLER */ |
| 44 | + |
| 45 | +#if defined(CONFIG_BT_CTLR_ASSERT_OPTIMIZE_FOR_SIZE) |
| 46 | +BUILD_ASSERT(IS_ENABLED(CONFIG_CPU_CORTEX_M)); |
| 47 | +/* Generate assertion as undefined instruction exception. |
| 48 | + */ |
| 49 | +#define LL_ASSERT(x) \ |
| 50 | + do { \ |
| 51 | + if (unlikely(!(x))) { \ |
| 52 | + __asm__ inline volatile (".inst 0xde00\n"); \ |
| 53 | + } \ |
| 54 | + } while (0) |
| 55 | + |
| 56 | +#else /* !CONFIG_BT_CTLR_ASSERT_OPTIMIZE_FOR_SIZE */ |
24 | 57 | #define LL_ASSERT(cond) \
|
25 | 58 | BT_ASSERT(cond)
|
| 59 | +#endif /* !CONFIG_BT_CTLR_ASSERT_OPTIMIZE_FOR_SIZE */ |
| 60 | + |
26 | 61 | #define LL_ASSERT_MSG(cond, fmt, ...) \
|
27 | 62 | BT_ASSERT_MSG(cond, fmt, ##__VA_ARGS__)
|
28 |
| -#endif |
| 63 | +#endif /* !CONFIG_BT_CTLR_ASSERT_HANDLER */ |
29 | 64 |
|
30 | 65 | /* Fatal asserts.
|
31 | 66 | * The Controller will otherwise misbehave causing memory leak or system-wide memory corruptions due
|
|
0 commit comments