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
API Change: IPM - callback improvement #26780
API Change: IPM - callback improvement #26780
Conversation
c02e929
to
bbea413
Compare
@carlescufi let's bring that one up at the next API meeting as well |
bbea413
to
709adbb
Compare
@nordic-krch and @anangl could you please take a look? |
drivers/ipm/ipm_nrfx_ipc.c
Outdated
@@ -36,7 +37,8 @@ static void nrfx_ipc_handler(uint32_t event_mask, void *p_context) | |||
__ASSERT(event_idx < NRFX_IPC_ID_MAX_VALUE, | |||
"Illegal event_idx: %d", event_idx); | |||
event_mask &= ~BIT(event_idx); | |||
nrfx_ipm_data.callback(nrfx_ipm_data.callback_ctx, | |||
nrfx_ipm_data.callback(nrfx_ipm_data.dev, |
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.
This is a single instance part of the driver, so you could use DEVICE_GET(ipm_nrf)
here and avoid adding the dev
field.
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.
ok
drivers/ipm/ipm_nrfx_ipc.c
Outdated
@@ -133,7 +135,8 @@ static void vipm_dispatcher(uint32_t event_mask, void *p_context) | |||
event_mask &= ~BIT(event_idx); | |||
if (nrfx_vipm_data.callback[event_idx] != NULL) { | |||
nrfx_vipm_data.callback[event_idx] | |||
(nrfx_vipm_data.callback_ctx[event_idx], | |||
(nrfx_vipm_data.ipm_device, |
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.
The ipm_device
field is currently not initialized. It is actually not used at all (looks like it's some remnant of an earlier version of the driver). You'll need to initialize it in vipm_nrf_init()
to use it this way (and perhaps rename it to dev
, to avoid confusion).
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.
indeed, done
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.
I'm sorry, now I see I was wrong in my previous comment. This field should be changed to an array of struct device *
and its entries should be initialized in vipm_nrf_##_idx##_register_callback()
(like callback[_idx]
and callback_ctx[_idx]
are), not in vipm_nrf_init()
.
77b729a
to
7e09b81
Compare
@@ -36,7 +36,8 @@ static void nrfx_ipc_handler(uint32_t event_mask, void *p_context) | |||
__ASSERT(event_idx < NRFX_IPC_ID_MAX_VALUE, | |||
"Illegal event_idx: %d", event_idx); | |||
event_mask &= ~BIT(event_idx); | |||
nrfx_ipm_data.callback(nrfx_ipm_data.callback_ctx, | |||
nrfx_ipm_data.callback(DEVICE_GET(ipm_nrf), |
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.
This requires also DEVICE_DECLARE(ipm_nrf);
to be added above.
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.
oh yes
drivers/ipm/ipm_nrfx_ipc.c
Outdated
@@ -133,7 +135,8 @@ static void vipm_dispatcher(uint32_t event_mask, void *p_context) | |||
event_mask &= ~BIT(event_idx); | |||
if (nrfx_vipm_data.callback[event_idx] != NULL) { | |||
nrfx_vipm_data.callback[event_idx] | |||
(nrfx_vipm_data.callback_ctx[event_idx], | |||
(nrfx_vipm_data.ipm_device, |
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.
I'm sorry, now I see I was wrong in my previous comment. This field should be changed to an array of struct device *
and its entries should be initialized in vipm_nrf_##_idx##_register_callback()
(like callback[_idx]
and callback_ctx[_idx]
are), not in vipm_nrf_init()
.
@anangl For vipm: which device should it be? tDEVICE_GET(ipm_nrf) or the actual vipm? If it's the later, current change is fine. If it should be the first, then let's just use it as is, without .dev attribute. |
@tbursztyka When |
Wait, that driver seems to be doing things upside down... why having one static struct vipm_nrf_data nrfx_vipm_data; when each and every vipm device could have its own static struct vipm_nrf_data nrfx_vipm_##idx##_data; (and the attributes there would not be arrays)? That seems to add complexity for no reason. |
7e09b81
to
43cbe50
Compare
@anangl I have followed the change you advised. However, this vipm driver would definitely gain in simplicity by using device's private data instead of those arrays (it would require only an external static sturct device *ipc_device[NRFX_IPC_ID_MAX_VALUE]). That would save rom a bit, since the code would be shared for all instances, and ram usage would be the same. |
I agree. I have no idea why the driver has been done this way. It's quite confusing, too. This unusual approach used here was the cause I was wrong in my initial comment. I just misunderstood it. |
4fc927b
to
813cf7a
Compare
Let's normalize the callback like it is done in other APIs. This will avoid the need to do not so nice code (storing the ipm device pointer as global, or else) and more importantly will help to move all device instance to constant. Fixes zephyrproject-rtos#26923 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Of course IPM drivers now provide their device instance. There are 2 drivers using IPM callbacks as well, so they get the imp device instance pointer now through the callback. Fixes zephyrproject-rtos#26923 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Applications using IPM callbacks get the imp device instance pointer now through the callback. Which help to clarify a bit the code here and there as well. Fixes zephyrproject-rtos#26923 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Provide the IPM device pointer to the callback. Fixes zephyrproject-rtos#26923 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
s/context/user_data Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
s/context/user_data Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Documenting the change. Fixes zephyrproject-rtos#26923 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
813cf7a
to
53378b3
Compare
ipm_callback_t do not provide the IPM device's callback caller as parameter, forcing users to use the context parameter instead for this purpose, which in turn limits its usage (they cannot provide some private data, or have to mangle thing together storing the IPM dev pointer into the private data).
All other API provide the callback's caller device pointer, and thus adding it as first parameter to ipm_callback_t
All users of ipm_register_callback() function need to adapt their callbacks accordingly.