Re-entrancy and kernel and SDK calls

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
10 posts / 0 new
Last post
JamesHiebert
Offline
Last seen:6 months 3 weeks ago
加入:2014-10-24 14:17
Re-entrancy and kernel and SDK calls

Hello Dialog,

Are kernel and SDK calls for the DA14581/SDK 5.0.X re-entrant safe (e.g., ke_msg_alloc(), ke_msg_send(), arch_restore_sleep_mode(), arch_force_active_mode())? We do make these calls from an ISR and from app tasks.

Are there any calls we should definitely NOT make from an ISR?

Thanks!

Device:
PM_Dialog
Offline
Last seen:18 hours 30 min ago
Staff
加入:2018-02-08 11:03
Hi JamesHiebert,

Hi JamesHiebert,

Could you please clarify what you mean with “re-entrant safe”? You can call these functions from an ISR, but you will not be completely sure that if you get another interrupt and the ISR will be triggered again, you will not have any other issue. It is highly recommended to use these functions under conditions and not from an ISR.

Thanks, PM_Dialog

JamesHiebert
Offline
Last seen:6 months 3 weeks ago
加入:2014-10-24 14:17
PM_Dialog,

PM_Dialog,

What I mean by re-entrant safe is the following:
1. Task T is running function F when...
2. An interrupts occurs and handler H runs to process the interrupt.
3. Handler H also calls function F.
4. Handler H completes and returns control to task T, which resumes running function F.

At this point, will function F behave predictably? Unpredictable problems may occur if function F accesses static or global variables, depending on the design of function F and when the interrupt occurred.

PM_Dialog
Offline
Last seen:18 hours 30 min ago
Staff
加入:2018-02-08 11:03
Hi JamesHiebert,

Hi JamesHiebert,

If you call twice the ke_msg_alloc(), you will allocate the message twice. The same will happen with ke_msg_send(), if you call it twice, the kernel message will be sent twice. The arch_restore_sleep_mode() restore the sleep mode to what it was before disabling and the arch_force_active_mode() will δisable sleep but save the sleep mode status, so if the arch_restore_sleep_mode is going to be called twice, also the arch_force_active_mode() should be called twice. It is highly recommended to use these functions under conditions, if you would like to use them into an ISR. Are you using these function in an ISR?

Thanks, PM_Dialog

JamesHiebert
Offline
Last seen:6 months 3 weeks ago
加入:2014-10-24 14:17
Hi PM_Dialog,

Hi PM_Dialog,

Yes, arch_restore_sleep_mode(), arch_force_active_mode(), ke_msg_alloc(), and ke_msg_send() are all called from ISRs.

I understand that calling functions more than once should result in their behaviors to occur more than once. But what if execution is in the middle of ke_msg_alloc() (or ke_msg_send()) when the interrupt occurs and ke_msg_alloc() (or ke_msg_send()) is called again from the ISR? Do those two functions mask interrupts while executing?

To protect against this scenario, I could mask and restore interrupts in arch_restore_sleep_mode() and arch_force_active_mode() (or surround the calls from tasks to ke_msg_alloc() and ke_msg_send() with code that masks and restores interrupts if these latter two are not protected). Do I need to?

Thanks.

PM_Dialog
Offline
Last seen:18 hours 30 min ago
Staff
加入:2018-02-08 11:03
Hi JamesHiebert,

Hi JamesHiebert,

As you are able to see from the source code of arch_restore_sleep_mode() and arch_force_active_mode(), these functions don’t mask the interrupts. Regarding the ke_msg_alloc() and ke_msg_send() functions, let me check it and I will get back to you as soon as possible.

Thanks, PM_Dialog

PM_Dialog
Offline
Last seen:18 hours 30 min ago
Staff
加入:2018-02-08 11:03
Hi JamesHiebert,

Hi JamesHiebert,

我检查的源代码ke_msg_alloc()和柯_msg_send() functions, and both of them disable the interrupts as arch_restore_sleep_mode() and arch_force_active_mode() functions.

Thanks, PM_Dialog

JamesHiebert
Offline
Last seen:6 months 3 weeks ago
加入:2014-10-24 14:17
PM_Dialog,

PM_Dialog,

对不起,你把我给弄糊涂了which says "...ke_msg_alloc() and ke_msg_send() functions, and both of them disable the interrupts as arch_restore_sleep_mode() and arch_force_active_mode() functions." You're seeming to imply that all 4 functions disable interrupts. However, functions arch_restore_sleep_mode() and arch_force_active_mode() do NOT disable interrupts. Are you saying ke_msg_alloc() and ke_msg_send() functions do or do not disable interrupts?

PM_Dialog
Offline
Last seen:18 hours 30 min ago
Staff
加入:2018-02-08 11:03
Hi JamesHiebert,

Hi JamesHiebert,

My apologies for the confusion. The arch_restore_sleep_mode() and arch_force_active_mode()do NOT disableinterrupt, but the ke_msg_alloc() and ke_msg_send() functionsdisablethe interrupts.

Thanks, PM_Dialog

JamesHiebert
Offline
Last seen:6 months 3 weeks ago
加入:2014-10-24 14:17
No problem, thanks for

No problem, thanks for clarifying.