arkhipenko / TaskScheduler

Cooperative multitasking for Arduino, ESPx, STM32, nRF and other microcontrollers
http://playground.arduino.cc/Code/TaskScheduler
BSD 3-Clause "New" or "Revised" License
1.26k stars 230 forks source link

Add sleep features for MSP430 and MSP432 boards #75

Closed elominp closed 5 years ago

elominp commented 5 years ago

Hello,

I modified a little bit your library to enable MSP430 and MSP432 based boards to use the sleep feature. It doesn't require a lot of change, just calling the sleep function on MSP430 boards and delay on MSP432 (as it uses TI-RTOS, delay yields the current thread and if there aren't any other TI-RTOS threads than the main Energia thread, it will put the board to sleep until the delay expires)

arkhipenko commented 5 years ago

Thank you. Will definitely look into this. I think I need to extend the scheduler API to include a way to register a "sleep" callback method. This would be a more generic and immediate solution for all the MCs out there...

arkhipenko commented 5 years ago

Please test the "testing" branch. I updated with your changes and overall support with custom sleep function.

elominp commented 5 years ago

I tried your testing branch with one of my MSP430 boards using the two first examples to see if the sleep works and it works OK :)

Here is the power trace of the Scheduler_example01 (without sleep) running:

example01_power_trace

Here is the power trace of the Scheduler_example02 (with sleep) running:

example02_power_trace_1

I can confirm the sleep is working as the mean current and total energy usage of the sketch running for 60 seconds is way below without the sleep and the Serial.println of Task2 does occur every around 500ms.

I don't have the time right now to test the MSP432 board but there shouldn't be any problem, the delay call does all the work.

arkhipenko commented 5 years ago

Awesome! Could you please test with example 6 IDLE?

You can also play with various sleep methods ideas using example 23....

Thanks for your help!

On Jun 12, 2019 2:38 AM, Guillaume Pirou notifications@github.com wrote:

I tried your testing branch with one of my MSP430 boards using the two first examples to see if the sleep works and it works OK :)

Here is the power trace of the Scheduler_example01 (without sleep) running:

[example01_power_trace]https://user-images.githubusercontent.com/10993286/59327218-2bb40f00-8ce9-11e9-945e-7ee0d1669f62.PNG

Here is the power trace of the Scheduler_example02 (with sleep) running:

[example02_power_trace_1]https://user-images.githubusercontent.com/10993286/59328499-d0841b80-8cec-11e9-98df-3f4853775ddb.PNG

I can confirm the sleep is working as the mean current and total energy usage of the sketch running for 60 seconds is way below without the sleep and the Serial.println of Task2 does occur every around 500ms.

I don't have the time right now to test the MSP432 board but there shouldn't be any problem, the delay call does all the work.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/arkhipenko/TaskScheduler/pull/75?email_source=notifications&email_token=AACMMTL4NQWTQ27R22Y3WUTP2CKUTA5CNFSM4HWJLRR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXPM4AQ#issuecomment-501140994, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AACMMTL6IX2CLNU72ZVAHMLP2CKUTANCNFSM4HWJLRRQ.

elominp commented 5 years ago

I tried the example 6 IDLE (with sleep disabled and enabled) and the example23 on my MSP430 board, then ran them again on my MSP432 board and they all seem to run ok.

I took some screenshots of the results if you're interested:

Example 6 (without uncommenting the _TASK_SLEEP_ON_IDLE_RUN:

example06_scenario1_not_sleeping

The same example with the define uncommented (the mcu used less power and c1 result is inferior to the previous run as expected:

example06_scenario_2_sleep

Running the example 23 the timings using the empty sleep are identical to the delayed one by 1 millisecond but used more power, so the mcu sleep also worked here:

example23

For the MSP432, the tests also ran OK:

Example 1:

Scheduler_example01_msp432

Example 2:

Scheduler_example02_msp432

Example 6 with _TASK_SLEEP_ON_IDLE_RUN commented:

Scheduler_example06_msp432_without_sleep

Example 6 with _TASK_SLEEP_ON_IDLE_RUN uncommented:

Scheduler_example06_msp432_with_sleep

Example 23:

Scheduler_example23_msp432

So in conclusion: everythings works OK and I think your addition of the setSleepMethod callback is the great idea :)

arkhipenko commented 5 years ago

Thank you! This is the most thorough test I have received so far from anyone!!!

elominp commented 5 years ago

You're welcome :)