Skip to content

Conversation

@PedroSAndre
Copy link

drivers: gnss: introduce node based callback macros

The current GNSS_DATA_CALLBACK_DEFINE, GNSS_SATELLITES_CALLBACK_DEFINE and GNSS_RTK_DATA_CALLBACK_DEFINE macros only utilize _callback when naming the respective callback. This means that if the same callback function is used more than once, there will be naming conflicts.

In order to allow the same callback function to be used several times for specific gnss devices, introduce GNSS_DT_DATA_CALLBACK_DEFINE, GNSS_DT_SATELLITES_CALLBACK_DEFINE and GNSS_DT_RTK_DATA_CALLBACK_DEFINE macros that take a device tree node identifier instead of a device reference. This makes it possible to name the callback using both node_id and _callback. Such will uniquely identify any combination of gnss device and callback.

drivers: gnss: f9p: fix multiple rtk enabled instances

The U-blox F9P driver uses the GNSS_RTK_DATA_CALLBACK_DEFINE macro to register a callback for when RTK data is available. This is an issue when multiple instances of the F9P are available and RTK is enabled since this macro leads to a naming collision. The following compilation error is reported:

 error: redefinition of '_gnss_rtk_data_callback__f9p_rtk_data_cb'

This is because GNSS_RTK_DATA_CALLBACK_DEFINE only uses _callback to identify the callback being registered. As a fix, use the recently introduced GNSS_DT_RTK_DATA_CALLBACK_DEFINE instead, which takes into account the node_id while naming the callback.

This PR is a continuation of #98646.

Signed-off-by: Pedro André [email protected]

The current GNSS_DATA_CALLBACK_DEFINE, GNSS_SATELLITES_CALLBACK_DEFINE and
GNSS_RTK_DATA_CALLBACK_DEFINE macros only utilize `_callback` when naming
the respective callback. This means that if the same callback function is
used more than once, there will be naming conflicts.

In order to allow the same callback function to be used several times for
specific gnss devices, introduce GNSS_DT_DATA_CALLBACK_DEFINE,
GNSS_DT_SATELLITES_CALLBACK_DEFINE and GNSS_DT_RTK_DATA_CALLBACK_DEFINE
macros that take a device tree node identifier instead of a device
reference. This makes it possible to name the callback using both `node_id`
and `_callback`. Such will uniquely identify any combination of gnss device
and callback.

Signed-off-by: Pedro André <[email protected]>
The U-blox F9P driver uses the GNSS_RTK_DATA_CALLBACK_DEFINE macro to
register a callback for when RTK data is available. This is an issue when
multiple instances of the F9P are available and RTK is enabled since this
macro leads to a naming collision. The following compilation error is
reported:

     error: redefinition of '_gnss_rtk_data_callback__f9p_rtk_data_cb'

This is because GNSS_RTK_DATA_CALLBACK_DEFINE only uses `_callback` to
identify the callback being registered. As a fix, use the recently
introduced GNSS_DT_RTK_DATA_CALLBACK_DEFINE instead, which takes into
account the `node_id` while naming the callback.

Signed-off-by: Pedro André <[email protected]>
@PedroSAndre PedroSAndre force-pushed the pedro/gnss/introduce-gnss-dt-macros branch from 5ed3687 to 9e54972 Compare November 11, 2025 15:13
@sonarqubecloud
Copy link

Copy link
Contributor

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool

#define GNSS_DT_DATA_CALLBACK_DEFINE(node_id, _callback) \
static const STRUCT_SECTION_ITERABLE( \
gnss_data_callback, \
_CONCAT(_CONCAT(_gnss_data_callback_, node_id), _CONCAT(_, _callback))) = { \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use DT_DEP_ORD() to get a unique integer from the node_id, this produces shorter names as the node_id can be very long:

_CONCAT(_CONCAT(_gnss_data_callback_, DT_DEP_ORD(node_id)), _CONCAT(_, _callback)))

Then use _CONCAT_4() instead of multiple _CONCAT

_CONCAT_4(_gnss_data_callback_, DT_DEP_ORD(node_id), _, _callback)

Lastly, using _node_id is a bit more consitent with _callback, though this one is entirely up to preference, many DT APIs take node_id without the _

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants