Hi Freaks :lol:
I have been designing a certain electronic Device and i am nearly finished
but i still need some bits n' bolts tidy up plus your ideas here would be very much appreciated.
My project has about 9 Tasks, in my Cooperative Real time Scheduling (Thanks to Kartman's for his Tutorial, I really made a use of it).
My Task 6 deals with switching some relays & Actuators based on if certain buttons were pressed. (it does this by keeping on pooling and read inputs to see if any button was pressed).
I have a Watchdog Resetting every 20 ms and is placed right next to dispatch () within the main () since each task was assigned to use about 15 ms when dispatch ever took longer than 15 ms until 20 ms then Watchdog will kick in an reset the MCU. this was fine as far as i could see.
The dilemma i had was on some sleeping mode. i really wanted to use power save mode but. to me based on the application of this project it seems like i can never have some periodic Sleeping time as Tasks ran independent. and i would like each task to go back to sleep as soon as it's done with its stuffs
Ex. Task 6 is reading about some pressed buttons and if a button is pressed Task 6 will execute its code and wait about 3 mins (during time in which it must remain active without Sleeping) and after these 3 mins task 6 will then read the status (either ON or OFF) of all relays & actuators and save them before it can allow the MCU to go back to sleep mode.
Other tasks also do something different but the issue here is that they all are active in completely different manner & time so if i was to create some periodic sleep time. this would surely create some violations.
My approach was to create a function "Go_to_Sleep()" and i would call Go_to_Sleep() everytime each task finishes its stuff. ofcourse we would wake up on next time the interrupt fires. this looks fine to me as far as i can see, But Though is this the right way of doing it? my thought was that since each task has its own Interrupt associated to it, every task would allow itself to run whenever its interrupt fires and then hand over to MCU to sleep and the other task etc...
So the Original question probably was "How do we put MCU to sleep having Tasks (Scheduled at different times obviously) given that we would like to maximise the sleeping time but preferably putting mcu to sleep evrytime there isn't any active task
Another Alternative i once though of was something like "Kicking Go_to_Sleep()" Thus Kicking MCU from Sleeping just like we do on a Watchdog but is this even possible (I am sorry if this sounds funny ':)' in some ways)
Thus I could just set MCU to Sleep and when every single active task is running it would be stopping CMU from sleeping and when it finishes the MCU would get to sleep?
Last issue was the facts that even when MCU is sleeping I am pretty sure convinced that the Watchdog would probably still be firing (since main() which was stopping it from reseting but main() itself is inaccessible during sleep ()
and this means some unnecessary MCU resets during sleep () unfortunately.
any standard Cleaver way on how to deal with this issue?
if this issue is not dealt, is this bad for MCU's life cycle?
PS: All of my Interrupts are very small, in facts the only thing the do is to only enable some boolean variables.
I am sorry for writing so much but i am sure someone will give me
a good insight in this.
Many Thanks & Merry Xmas to all.
Regards.
Kase