Hi Francois,

> On Jun 9, 2017, at 10:16 AM, François Berder <fber...@outlook.fr> wrote:
> 
...
> 
> 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 

indeed, this is why this was placed in MCU specific code.

> 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.

I assume this would be, most likely the “wait” instruction will not actually
halt the MCU if there are interrupts pending. You’ll need to make sure
is that MCU will not sleep if there are those.

Sorry if I’m stating the obvious here; would take a look at application
notes/sample code Microchip has written about saving power when idling.
They should have called out issues that you should take into account here.


Reply via email to