Skip to content

Commit e3c925d

Browse files
committed
Add other dependencies
fixup Signed-off-by: Mirko Covizzi <[email protected]>
1 parent 4614ade commit e3c925d

11 files changed

+342
-5
lines changed

lib/peer_manager/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
zephyr_library()
88
zephyr_library_include_directories(include)
99
zephyr_library_sources(peer_manager.c)
10+
zephyr_library_sources(nrf_strerror.c)
1011

1112
add_subdirectory(modules)
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Copyright (c) 2008-2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/** @file
8+
* @brief Common defines and macros for firmware developed by Nordic Semiconductor.
9+
*/
10+
11+
#ifndef NORDIC_COMMON_H__
12+
#define NORDIC_COMMON_H__
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
/**
19+
* @brief Check if selected module is enabled
20+
*
21+
* This is save function for driver enable checking.
22+
* Correct from Lint point of view (not using default of undefined value).
23+
*
24+
* Usage:
25+
* @code
26+
#if NRF_MODULE_ENABLED(UART)
27+
...
28+
#endif
29+
* @endcode
30+
*
31+
* @param module The module name.
32+
*
33+
* @retval 1 The macro <module>_ENABLE is defined and is non-zero.
34+
* @retval 0 The macro <module>_ENABLE is not defined or it equals zero.
35+
*
36+
* @note
37+
* This macro intentionally does not implement second expansion level.
38+
* The name of the module to be checked has to be given directly as a parameter.
39+
* And given parameter would be connected with @c _ENABLED postfix directly
40+
* without evaluating its value.
41+
*/
42+
#ifdef NRF_MODULE_ENABLE_ALL
43+
#warning "Do not use NRF_MODULE_ENABLE_ALL for real builds."
44+
#define NRF_MODULE_ENABLED(module) 1
45+
#else
46+
#define NRF_MODULE_ENABLED(module) ((defined(module##_ENABLED) && (module##_ENABLED)) ? 1 : 0)
47+
#endif
48+
/** The upper 8 bits of a 32 bit value */
49+
#define MSB_32(a) (((a)&0xFF000000) >> 24)
50+
/** The lower 8 bits (of a 32 bit value) */
51+
#define LSB_32(a) ((a)&0x000000FF)
52+
53+
/** The upper 8 bits of a 16 bit value */
54+
#define MSB_16(a) (((a)&0xFF00) >> 8)
55+
/** The lower 8 bits (of a 16 bit value) */
56+
#define LSB_16(a) ((a)&0x00FF)
57+
58+
/** Leaves the minimum of the two 32-bit arguments */
59+
#define MIN(a, b) ((a) < (b) ? (a) : (b))
60+
/** Leaves the maximum of the two 32-bit arguments */
61+
#define MAX(a, b) ((a) < (b) ? (b) : (a))
62+
63+
/**@brief Concatenates two parameters.
64+
*
65+
* It realizes two level expansion to make it sure that all the parameters
66+
* are actually expanded before gluing them together.
67+
*
68+
* @param p1 First parameter to concatenating
69+
* @param p2 Second parameter to concatenating
70+
*
71+
* @return Two parameters glued together.
72+
* They have to create correct C mnemonic in other case
73+
* preprocessor error would be generated.
74+
*
75+
* @sa CONCAT_3
76+
*/
77+
#define CONCAT_2(p1, p2) CONCAT_2_(p1, p2)
78+
/** Auxiliary macro used by @ref CONCAT_2 */
79+
#define CONCAT_2_(p1, p2) p1##p2
80+
81+
/**@brief Concatenates three parameters.
82+
*
83+
* It realizes two level expansion to make it sure that all the parameters
84+
* are actually expanded before gluing them together.
85+
*
86+
* @param p1 First parameter to concatenating
87+
* @param p2 Second parameter to concatenating
88+
* @param p3 Third parameter to concatenating
89+
*
90+
* @return Three parameters glued together.
91+
* They have to create correct C mnemonic in other case
92+
* preprocessor error would be generated.
93+
*
94+
* @sa CONCAT_2
95+
*/
96+
#define CONCAT_3(p1, p2, p3) CONCAT_3_(p1, p2, p3)
97+
/** Auxiliary macro used by @ref CONCAT_3 */
98+
#define CONCAT_3_(p1, p2, p3) p1##p2##p3
99+
100+
#define STRINGIFY_(val) #val
101+
/** Converts a macro argument into a character constant.
102+
*/
103+
#define STRINGIFY(val) STRINGIFY_(val)
104+
105+
/** Counts number of elements inside the array
106+
*/
107+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
108+
109+
/**@brief Set a bit in the uint32 word.
110+
*
111+
* @param[in] W Word whose bit is being set.
112+
* @param[in] B Bit number in the word to be set.
113+
*/
114+
#define SET_BIT(W, B) ((W) |= (uint32_t)(1U << (B)))
115+
116+
/**@brief Clears a bit in the uint32 word.
117+
*
118+
* @param[in] W Word whose bit is to be cleared.
119+
* @param[in] B Bit number in the word to be cleared.
120+
*/
121+
#define CLR_BIT(W, B) ((W) &= (~(uint32_t)(1U << (B))))
122+
123+
/**@brief Checks if a bit is set.
124+
*
125+
* @param[in] W Word whose bit is to be checked.
126+
* @param[in] B Bit number in the word to be checked.
127+
*
128+
* @retval 1 if bit is set.
129+
* @retval 0 if bit is not set.
130+
*/
131+
#define IS_SET(W, B) (((W) >> (B)) & 1)
132+
133+
#define BIT_0 0x01 /**< The value of bit 0 */
134+
#define BIT_1 0x02 /**< The value of bit 1 */
135+
#define BIT_2 0x04 /**< The value of bit 2 */
136+
#define BIT_3 0x08 /**< The value of bit 3 */
137+
#define BIT_4 0x10 /**< The value of bit 4 */
138+
#define BIT_5 0x20 /**< The value of bit 5 */
139+
#define BIT_6 0x40 /**< The value of bit 6 */
140+
#define BIT_7 0x80 /**< The value of bit 7 */
141+
#define BIT_8 0x0100 /**< The value of bit 8 */
142+
#define BIT_9 0x0200 /**< The value of bit 9 */
143+
#define BIT_10 0x0400 /**< The value of bit 10 */
144+
#define BIT_11 0x0800 /**< The value of bit 11 */
145+
#define BIT_12 0x1000 /**< The value of bit 12 */
146+
#define BIT_13 0x2000 /**< The value of bit 13 */
147+
#define BIT_14 0x4000 /**< The value of bit 14 */
148+
#define BIT_15 0x8000 /**< The value of bit 15 */
149+
#define BIT_16 0x00010000 /**< The value of bit 16 */
150+
#define BIT_17 0x00020000 /**< The value of bit 17 */
151+
#define BIT_18 0x00040000 /**< The value of bit 18 */
152+
#define BIT_19 0x00080000 /**< The value of bit 19 */
153+
#define BIT_20 0x00100000 /**< The value of bit 20 */
154+
#define BIT_21 0x00200000 /**< The value of bit 21 */
155+
#define BIT_22 0x00400000 /**< The value of bit 22 */
156+
#define BIT_23 0x00800000 /**< The value of bit 23 */
157+
#define BIT_24 0x01000000 /**< The value of bit 24 */
158+
#define BIT_25 0x02000000 /**< The value of bit 25 */
159+
#define BIT_26 0x04000000 /**< The value of bit 26 */
160+
#define BIT_27 0x08000000 /**< The value of bit 27 */
161+
#define BIT_28 0x10000000 /**< The value of bit 28 */
162+
#define BIT_29 0x20000000 /**< The value of bit 29 */
163+
#define BIT_30 0x40000000 /**< The value of bit 30 */
164+
#define BIT_31 0x80000000 /**< The value of bit 31 */
165+
166+
#define UNUSED_VARIABLE(X) ((void)(X))
167+
#define UNUSED_PARAMETER(X) UNUSED_VARIABLE(X)
168+
#define UNUSED_RETURN_VALUE(X) UNUSED_VARIABLE(X)
169+
170+
#ifdef __cplusplus
171+
}
172+
#endif
173+
174+
#endif /* NORDIC_COMMON_H__ */
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2017-2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/**
8+
* @defgroup nrf_strerror Error code to string converter
9+
* @ingroup app_common
10+
*
11+
* @brief Module for converting error code into a printable string.
12+
* @{
13+
*/
14+
#ifndef NRF_STRERROR_H__
15+
#define NRF_STRERROR_H__
16+
17+
#include <stdint.h>
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
/**
24+
* @brief Function for getting a printable error string.
25+
*
26+
* @param code Error code to convert.
27+
*
28+
* @note This function cannot fail.
29+
* For the function that may fail with error translation, see @ref nrf_strerror_find.
30+
*
31+
* @return Pointer to the printable string.
32+
* If the string is not found,
33+
* it returns a simple string that says that the error is unknown.
34+
*/
35+
char const *nrf_strerror_get(uint32_t code);
36+
37+
/**
38+
* @brief Function for finding a printable error string.
39+
*
40+
* This function gets the error string in the same way as @ref nrf_strerror_get,
41+
* but if the string is not found, it returns NULL.
42+
*
43+
* @param code Error code to convert.
44+
* @return Pointer to the printable string.
45+
* If the string is not found, NULL is returned.
46+
*/
47+
char const *nrf_strerror_find(uint32_t code);
48+
49+
/** @} */
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
#endif /* NRF_STRERROR_H__ */

lib/peer_manager/modules/auth_status_tracker.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <zephyr/logging/log.h>
99
#include <nrf_error.h>
10+
#include <nrf_strerror.h>
1011
#include <bm_timer.h>
1112
#include <modules/id_manager.h>
1213
#include <modules/auth_status_tracker.h>

lib/peer_manager/modules/gatt_cache_manager.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
#include <stdint.h>
88
#include <zephyr/logging/log.h>
99
#include <zephyr/sys/atomic.h>
10+
#include <zephyr/sys/__assert.h>
1011
#include <nrf_error.h>
12+
#include <nrf_strerror.h>
13+
#include <nordic_common.h>
1114
#include <ble_gap.h>
1215
#include <ble_err.h>
1316
#include <ble_conn_state.h>
@@ -35,7 +38,7 @@ typedef atomic_t nrf_mtx_t;
3538
*/
3639
__STATIC_INLINE void nrf_mtx_init(nrf_mtx_t *p_mtx)
3740
{
38-
ASSERT(p_mtx != NULL);
41+
__ASSERT(p_mtx != NULL, "");
3942

4043
atomic_set(p_mtx, NRF_MTX_UNLOCKED);
4144
}
@@ -50,7 +53,7 @@ __STATIC_INLINE void nrf_mtx_init(nrf_mtx_t *p_mtx)
5053
*/
5154
__STATIC_INLINE bool nrf_mtx_trylock(nrf_mtx_t *p_mtx)
5255
{
53-
ASSERT(p_mtx != NULL);
56+
__ASSERT(p_mtx != NULL, "");
5457

5558
return atomic_cas(p_mtx, NRF_MTX_UNLOCKED, NRF_MTX_LOCKED);
5659
}
@@ -67,8 +70,8 @@ __STATIC_INLINE bool nrf_mtx_trylock(nrf_mtx_t *p_mtx)
6770
*/
6871
__STATIC_INLINE void nrf_mtx_unlock(nrf_mtx_t *p_mtx)
6972
{
70-
ASSERT(p_mtx != NULL);
71-
ASSERT(*p_mtx == NRF_MTX_LOCKED);
73+
__ASSERT(p_mtx != NULL, "");
74+
__ASSERT(*p_mtx == NRF_MTX_LOCKED, "");
7275

7376
atomic_set(p_mtx, NRF_MTX_UNLOCKED);
7477
}
@@ -326,7 +329,7 @@ static uint32_t service_changed_cccd(uint16_t conn_handle, uint16_t *p_cccd)
326329

327330
uint32_t err_code = sd_ble_gatts_initial_user_handle_get(&end_handle);
328331

329-
ASSERT(err_code == NRF_SUCCESS);
332+
__ASSERT(err_code == NRF_SUCCESS, "");
330333

331334
for (uint16_t handle = 1; handle < end_handle; handle++) {
332335
ble_uuid_t uuid;

lib/peer_manager/modules/gatts_cache_manager.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <string.h>
99
#include <zephyr/logging/log.h>
1010
#include <nrf_error.h>
11+
#include <nrf_strerror.h>
12+
#include <nordic_common.h>
1113
#include <ble_gap.h>
1214
#include <ble_err.h>
1315
#include <bluetooth/peer_manager/peer_manager_types.h>

lib/peer_manager/modules/peer_database.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <string.h>
88
#include <zephyr/logging/log.h>
99
#include <nrf_error.h>
10+
#include <nrf_strerror.h>
11+
#include <nordic_common.h>
1012
#include <bluetooth/peer_manager/peer_manager_types.h>
1113
#include <modules/peer_manager_internal.h>
1214
#include <modules/peer_data_storage.h>

lib/peer_manager/modules/peer_manager_handler.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66

77
#include <stdint.h>
8+
#include <stdio.h>
89
#include <string.h>
910
#include <zephyr/logging/log.h>
1011
#include <nrf_error.h>
12+
#include <nrf_strerror.h>
13+
#include <nordic_common.h>
1114
#include <ble_gap.h>
1215
#include <ble_gattc.h>
1316
#include <ble_conn_state.h>

lib/peer_manager/modules/security_dispatcher.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
66

7+
#include <stdint.h>
78
#include <string.h>
89
#include <zephyr/logging/log.h>
910
#include <nrf_error.h>
11+
#include <nrf_strerror.h>
1012
#include <ble.h>
1113
#include <ble_gap.h>
1214
#include <ble_err.h>

lib/peer_manager/modules/security_manager.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <string.h>
88
#include <zephyr/logging/log.h>
99
#include <nrf_error.h>
10+
#include <nrf_strerror.h>
1011
#include <ble_err.h>
1112
#include <ble_conn_state.h>
1213
#include <sdk_macros.h>

0 commit comments

Comments
 (0)