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:

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
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.
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
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.
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
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
PM_Dialog,
Sorry, I am confused by your last post 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?
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
No problem, thanks for clarifying.