I am trying to use _timer_start_periodic_every() from within ISR (when a button is pressed), but receives results of TIMER_NULL_ID.
When I am debugging into the function, when reaching _timer_start_periodic_every_internal(), this function always reaches following condition and returns MQX_INVALID_LWSEM error:
/* Gain exclusive access to the timer queues */
if (kernel_data->ACTIVE_PTR != timer_component_ptr->TIMER_TD_PTR)
{
if (_lwsem_wait(&timer_component_ptr->TIMER_ENTRIES_LWSEM) != MQX_OK)
{
_task_set_error(MQX_INVALID_LWSEM);
return(TIMER_NULL_ID);
} /* Endif */
} /* Endif */
According to the MQX user's guide, _timer_start_ functions are not included in "Functions That the ISR Cannot Call" - so it should succeed.
However, from the implementation above, I can see that it calls _lwsem_wait() which is not allowed in an ISR.
So, my questions:
1. Why can't I allocate a timer from the ISR?
2. If it is because of the lwsem_wait() usage - then why it is still allowed to use?
Thanks,
Lior.
Hi Panpwr,
An ISR routine must not call a function that can block.
In the ISR you can call functions that do not block. Setting an event would be OK. Then in a user task that is blocked waiting for that event, have the code you want ready to run.
Please review section "Handling Interrupts and Exceptions" in "MQX_User_Guid.pdf" in the MQX4.1/doc/mqx path.
Regards,
David
According to your answer, I understand that this function obviously should be listed in the user guide, under the section "Functions That the ISR Cannot Call" as well, correct?
The question is: Why is it not listed there (only _timer_cancel appear)? Maybe there is an alternative way to use this function in spite of the blocking call?