-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: gnss: allow same callback #98646
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
drivers: gnss: allow same callback #98646
Conversation
The current implementation of GNSS_DATA_CALLBACK_DEFINE and GNSS_SATELLITES_CALLBACK_DEFINE only use the provided `_callback` to uniquely identify the entry that will be created. This implies that the same callback cannot be registered twice, even if the device it is being attached to is different. In order to allow the same callback to be registered several times, the ideal would be to also use `_dev` in combination with `_callback` to uniquely identify the generated entry. But this would require getting the node_id of the device, hence breaking the current API. In order to avoid that, use __COUNTER__ to avoid collisions. Signed-off-by: Pedro André <[email protected]>
When multiple instances of the same type of RTK enabled GNSS device are
instantiated on the same board, there will be a collision with their RTK
data callbacks. The u-blox F9P module is a clear example of that, where the
following compilation error is reported:
error: redefinition of '_gnss_rtk_data_callback__f9p_rtk_data_cb'
Similar to the solution used at d36a0fc (drivers: gnss: allow same
callback), use `__COUNTER__` instead of `_callback` in the generated entry
to avoid collisions.
Signed-off-by: Pedro André <[email protected]>
|
Hello @PedroSAndre, and thank you very much for your first pull request to the Zephyr project! |
|
|
The way to reuse the callback is to set The solution in this PR works as well, but it should not be strictly necessary |
I was not aware of the Considering that, I do agree that the first commit can be considered not strictly necessary. Despite this, I still believe there is a point in including these changes. First of all, passing It is also relevant to note that this does not break any of the old functionality. If the user wants to still provide For the second commit, I think using |
For device drivers, we should add GNSS_DT_INST variants to define unique names for callbacks, these use the devicetree ordinal to generate a unique name, and the struct device is gotten from devicetree as well, so just inst/node_id + callback: GNSS_DT_DATA_CALLBACK_DEFINE(node_id, callback) |
Thank you for your feedback once again @bjarki-andreasen. I believe I understand where you are coming from, but won't adding macros specific for device drivers be a bit unnecessary? Since the But I am probably missing some context as to why adding more macros is ideal, so please feel free to disagree :). |
By device drivers, I don't just mean within them, consider We use the devicetree to tie a struct to a specific instance of something, with this PR, defining the callback looks like this: There are only two different usages of the and a driver would use the inst variant: We get rid of the redundant DEVICE_DT_GET and DEVICE_DT_INST_GET calls within the macros this way, its not functionally different, its just more consise I can agree to this PR as is, just to not break anything, we can add the DT based macros later, and replace uses of the current macro then. |
Thank you again for your feedback @bjarki-andreasen. Since the idea is for us to move into the DT based macros anyway, I have taken the liberty of implementing those changes in #99208. Considering those are the ideal solution, there is no point in merging the changes in this PR, so I will close it for now if that is okay with everyone :). |



drivers: gnss: allow same callback
The current implementation of GNSS_DATA_CALLBACK_DEFINE and
GNSS_SATELLITES_CALLBACK_DEFINE only use the provided
_callbacktouniquely identify the entry that will be created. This implies that the
same callback cannot be registered twice, even if the device it is being
attached to is different.
In order to allow the same callback to be registered several times, the
ideal would be to also use
_devin combination with_callbacktouniquely identify the generated entry. But this would require getting the
node_id of the device, hence breaking the current API. In order to avoid
that, use COUNTER to avoid collisions.
gnss: rtk: fix multiple instances of same device
When multiple instances of the same type of RTK enabled GNSS device are
instantiated on the same board, there will be a collision with their RTK
data callbacks. The u-blox F9P module is a clear example of that, where the
following compilation error is reported:
Similar to the solution used at d36a0fc (drivers: gnss: allow same
callback), use
__COUNTER__instead of_callbackin the generated entryto avoid collisions.