-
Notifications
You must be signed in to change notification settings - Fork 21
sdh: simplifications and improvements #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
2b9ee6a
1e893a9
28089a4
a767014
c200b77
4229682
307d8e5
c8c251d
ab5e941
822882b
565a9cf
093c9f1
9431dee
a0bd9e2
39652c2
e07d39b
381bff5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -75,7 +75,7 @@ extern "C" { | |||||||||
.data_pool = &CONCAT(_name, _heap), \ | ||||||||||
}; \ | ||||||||||
NRF_SDH_BLE_OBSERVER(CONCAT(_name, _obs), ble_gq_on_ble_evt, (void *)&_name, \ | ||||||||||
CONFIG_BLE_GQ_OBSERVER_PRIO) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, done |
||||||||||
HIGH) | ||||||||||
Comment on lines
77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll leave the formatting as it is, we can do that work separately. |
||||||||||
|
||||||||||
/** | ||||||||||
* @brief Helper macro for initializing connection handle array. Used in @ref BLE_GQ_CUSTOM_DEF. | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,12 +15,66 @@ | |||||
#define NRF_SDH_H__ | ||||||
|
||||||
#include <stdbool.h> | ||||||
#include <zephyr/toolchain.h> | ||||||
#include <zephyr/sys/util.h> | ||||||
#include <zephyr/sys/iterable_sections.h> | ||||||
|
||||||
#ifdef __cplusplus | ||||||
extern "C" { | ||||||
#endif | ||||||
|
||||||
/** | ||||||
* @defgroup softdevice_observer_prio SoftDevice event observer priority levels | ||||||
* | ||||||
* A SoftDevice observer has a defined priority, which determines the order with | ||||||
* which the observer receives relevant events compared to other observers. | ||||||
* | ||||||
* Five priority levels are defined, highest, high, user, user low, lowest. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* These can be selected using the tokens HIGHEST, HIGH, USER, USER_LOW, and LOWEST respectively. | ||||||
* | ||||||
* In general, an observer priority must be defined in such a way that an observer | ||||||
* has a lower priority than that of other observers (libraries, etc.) it depends on. | ||||||
* | ||||||
* @{ | ||||||
*/ | ||||||
|
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra newline. |
||||||
/* Helper macros to check for equality */ | ||||||
|
||||||
#define H_NRF_SDH_OBSERVER_PRIO_HIGHEST_HIGHEST 1 | ||||||
#define H_NRF_SDH_OBSERVER_PRIO_HIGH_HIGH 1 | ||||||
#define H_NRF_SDH_OBSERVER_PRIO_USER_USER 1 | ||||||
#define H_NRF_SDH_OBSERVER_PRIO_USER_LOW_USER_LOW 1 | ||||||
#define H_NRF_SDH_OBSERVER_PRIO_LOWEST_LOWEST 1 | ||||||
|
||||||
/** | ||||||
* @brief Utility macro to check for observer priority validity. | ||||||
* @internal | ||||||
*/ | ||||||
#define PRIO_LEVEL_IS_VALID(level) \ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this macro strictly needed? Given that we always check the validity of the priority level in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, because |
||||||
COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_HIGHEST_##level, (), \ | ||||||
(COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_HIGH_##level, (), \ | ||||||
(COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_USER_##level, (), \ | ||||||
(COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_USER_LOW_##level, (), \ | ||||||
(COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_LOWEST_##level, (), \ | ||||||
(BUILD_ASSERT(0, "Invalid priority level"))))))))))) | ||||||
|
||||||
/** | ||||||
* @brief Utility macro to convert a priority token to its numerical value | ||||||
* @internal | ||||||
*/ | ||||||
#define PRIO_LEVEL_ORD(level) \ | ||||||
COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_HIGHEST_##level, (0), \ | ||||||
(COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_HIGH_##level, (1), \ | ||||||
(COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_USER_##level, (2), \ | ||||||
(COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_USER_LOW_##level, (3), \ | ||||||
(COND_CODE_1(H_NRF_SDH_OBSERVER_PRIO_LOWEST_##level, (4), \ | ||||||
(BUILD_ASSERT(0, "Invalid priority level"))))))))))) | ||||||
|
||||||
/** | ||||||
* @} | ||||||
*/ | ||||||
|
||||||
/** | ||||||
* @brief SoftDevice Handler state requests. | ||||||
*/ | ||||||
|
@@ -73,12 +127,13 @@ struct nrf_sdh_state_req_observer { | |||||
* @param _handler State request handler. | ||||||
* @param _ctx A context passed to the state request handler. | ||||||
* @param _prio Priority of the observer's event handler. | ||||||
* The lower the number, the higher the priority. | ||||||
* Allowed input: `HIGHEST`, `HIGH`, `USER`, `USER_LOW`, `LOWEST`. | ||||||
*/ | ||||||
#define NRF_SDH_STATE_REQ_OBSERVER(_observer, _handler, _ctx, _prio) \ | ||||||
PRIO_LEVEL_IS_VALID(_prio); \ | ||||||
static bool _handler(enum nrf_sdh_state_req, void *); \ | ||||||
const TYPE_SECTION_ITERABLE(struct nrf_sdh_state_req_observer, _observer, \ | ||||||
nrf_sdh_state_req_observers, _prio) = { \ | ||||||
nrf_sdh_state_req_observers, PRIO_LEVEL_ORD(_prio)) = { \ | ||||||
.handler = _handler, \ | ||||||
.context = _ctx, \ | ||||||
}; | ||||||
|
@@ -140,12 +195,13 @@ struct nrf_sdh_state_evt_observer { | |||||
* @param _handler State request handler. | ||||||
* @param _ctx A context passed to the state request handler. | ||||||
* @param _prio Priority of the observer's event handler. | ||||||
* The lower the number, the higher the priority. | ||||||
* Allowed input: `HIGHEST`, `HIGH`, `USER`, `USER_LOW`, `LOWEST`. | ||||||
*/ | ||||||
#define NRF_SDH_STATE_EVT_OBSERVER(_observer, _handler, _ctx, _prio) \ | ||||||
PRIO_LEVEL_IS_VALID(_prio); \ | ||||||
static void _handler(enum nrf_sdh_state_evt, void *); \ | ||||||
const TYPE_SECTION_ITERABLE(struct nrf_sdh_state_evt_observer, _observer, \ | ||||||
nrf_sdh_state_evt_observers, _prio) = { \ | ||||||
nrf_sdh_state_evt_observers, PRIO_LEVEL_ORD(_prio)) = { \ | ||||||
.handler = _handler, \ | ||||||
.context = _ctx, \ | ||||||
}; | ||||||
|
@@ -180,12 +236,13 @@ struct nrf_sdh_stack_evt_observer { | |||||
* @param _handler Stack event handler. | ||||||
* @param _ctx A context passed to the state request handler. | ||||||
* @param _prio Priority of the observer's event handler. | ||||||
* The lower the number, the higher the priority. | ||||||
* Allowed input: `HIGHEST`, `HIGH`, `USER`, `USER_LOW`, `LOWEST`. | ||||||
*/ | ||||||
#define NRF_SDH_STACK_EVT_OBSERVER(_observer, _handler, _ctx, _prio) \ | ||||||
PRIO_LEVEL_IS_VALID(_prio); \ | ||||||
static void _handler(void *); \ | ||||||
const TYPE_SECTION_ITERABLE(struct nrf_sdh_stack_evt_observer, _observer, \ | ||||||
nrf_sdh_stack_evt_observers, _prio) = { \ | ||||||
nrf_sdh_stack_evt_observers, PRIO_LEVEL_ORD(_prio)) = { \ | ||||||
.handler = _handler, \ | ||||||
.context = _ctx, \ | ||||||
}; | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ | |||||
#define NRF_SDH_BLE_H__ | ||||||
|
||||||
#include <stdint.h> | ||||||
#include <nrf_sdh.h> | ||||||
#include <ble.h> | ||||||
#include <zephyr/sys/iterable_sections.h> | ||||||
|
||||||
|
@@ -54,11 +55,12 @@ struct nrf_sdh_ble_evt_observer { | |||||
* @param _handler State request handler. | ||||||
* @param _ctx A context passed to the state request handler. | ||||||
* @param _prio Priority of the observer's event handler. | ||||||
* The lower the number, the higher the priority. | ||||||
* Allowed input: `HIGHEST`, `HIGH`, `USER`, `USER_LOW`, `LOWEST`. | ||||||
*/ | ||||||
#define NRF_SDH_BLE_OBSERVER(_observer, _handler, _ctx, _prio) \ | ||||||
PRIO_LEVEL_IS_VALID(_prio); \ | ||||||
static const TYPE_SECTION_ITERABLE(struct nrf_sdh_ble_evt_observer, _observer, \ | ||||||
nrf_sdh_ble_evt_observers, _prio) = { \ | ||||||
nrf_sdh_ble_evt_observers, PRIO_LEVEL_ORD(_prio)) = { \ | ||||||
.handler = _handler, \ | ||||||
.context = _ctx, \ | ||||||
}; | ||||||
|
}; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I think we should remove it. I will add a commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.