-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: gnss: introduce node based callback macros #99208
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?
drivers: gnss: introduce node based callback macros #99208
Conversation
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]>
5ed3687 to
9e54972
Compare
|
bjarki-andreasen
left a comment
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.
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))) = { \ |
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.
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 _



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
_callbackwhen 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_idand_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:
This is because GNSS_RTK_DATA_CALLBACK_DEFINE only uses
_callbackto identify the callback being registered. As a fix, use the recently introduced GNSS_DT_RTK_DATA_CALLBACK_DEFINE instead, which takes into account thenode_idwhile naming the callback.This PR is a continuation of #98646.
Signed-off-by: Pedro André [email protected]