- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I want to share variables between the two cores of the MPC5668G. I was thinking about using the core mutex to implement a lock mechanism to avoir both core to access the same memory address at the same time. However, when I look at MQX code I started to belive that core mutex can't work. Here is why:
In function _core_mutex_lock, if the mutex is already lock, the task is suspended which is the behaviour I would expect. A call to _core_mutex_unlock will resume the suspended task. However, if the mutex is lock by the other core, the task is also suspended and the only mean to resume it is for the other core to unlock the mutex. This will trigger the an interrupt on the first core. The ISR (_sema4_isr) is suppose to resume the task but when I look at the _core_mutex_lock function, before the task is suspended because the mutex is lock by the other core (in blue), the interrupts are disabled (in red).
uint32_t _core_mutex_lock( CORE_MUTEX_PTR core_mutex_ptr )
{
unsigned char lock = _psp_core_num()+1;
#if MQX_CHECK_ERRORS
if (core_mutex_ptr == NULL) {
return MQX_INVALID_POINTER;
}
if (core_mutex_ptr->VALID != CORE_MUTEX_VALID) {
return MQX_INVALID_POINTER;
}
#endif
_sema4_int_disable();
#if BSPCFG_CORE_MUTEX_STATS
core_mutex_ptr->LOCKS++;
#endif
/* Check to see if this core already own it */
if (*core_mutex_ptr->GATE_PTR == lock) {
/* Yes, then we have to wait for owning task to release it */
#if BSPCFG_CORE_MUTEX_STATS
core_mutex_ptr->WAITS++;
#endif
_taskq_suspend(core_mutex_ptr->WAIT_Q);
} else {
/* can only try to lock the mutex if another task is not waiting otherwise we need to get in line */
if (_taskq_get_value(core_mutex_ptr->WAIT_Q)==0) {
*core_mutex_ptr->GATE_PTR = lock;
}
if (*core_mutex_ptr->GATE_PTR != lock) {
#if BSPCFG_CORE_MUTEX_STATS
core_mutex_ptr->WAITS++;
#endif
_taskq_suspend(core_mutex_ptr->WAIT_Q);
/* Our turn now */
}
}
_sema4_int_enable();
return COREMUTEX_OK;
}
My understanding is that ISR will never be called (since interrupts are disabled) so task will never resumed and interrupts will never be re-enabled.
Maybe there is something that I missed ? Can anyone explain to me how a task can be resumed if mutex is lock by the other core?
Thanks,
Hugo
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The interrupts will be disabled only for the current task. Since task in suspended, if interrupts are enabled in the next task that will be activated, the ISR _sema4_isr will be serviced.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The interrupts will be disabled only for the current task. Since task in suspended, if interrupts are enabled in the next task that will be activated, the ISR _sema4_isr will be serviced.