Hello,

I am currently trying to implement os_tick_idle for the 
pic32mz2048efg100 of the wifire board.

I looked at other implementations, especially the one for nrf51xxx. It 
seems that on ARM cortex M processors, interrupts are still able to wake 
up the cpu even if the "cspid i" instruction (disabling interrupts in 
OS_ENTER_CRITICAL) was executed before (source: 
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka16222.html)

However this approach does not work on PIC32. Interrupts cannot wake up 
the CPU if they are disabled. Hence, the CPU would be stuck in idle mode 
until the watchdog resets the device. The only solution would be to 
re-enable interrupts just before halting the CPU and disabling 
interrupts once the CPU woke up. Here is the pseudo-code of what would 
os_tick_idle look like:

void
os_tick_idle(uint32_t ticks)
{

     OS_ASSERT_CRITICAL();

     setup_timer(ticks);

     OS_EXIT_CRITICAL();

     asm volatile ("wait");        // Halt CPU (idle mode)

     OS_ENTER_CRITICAL();

     stop timer
     advance_time
     setup_timer(1)             // timer is setup to generate interrupt for 
every tick

}

Do you think that would be acceptable ? Let me know if you have 
suggestions how to handle this case.

Best Regards,

François

Reply via email to