Main Site Documentation

RealTimeClock With Alarm for .Net Call backs?


#1

Hello guys,
i was kind of wondering if it would possible to add to the RealTimeClock Class the ability to set alarms that will call back a .net function, kind of like the current Alarm but for software use…

this would be great to create events based on Date and Time… sort of a scheduler without the over head of creating a separate thread for that…

or is that something we can already do ?

thanks.
Jay.


#2

can you use a Timer?


#3

yes i can. but to me it would make a whole lot more sense to tap into the RealTimeClock processing, since it is already running in the background… instead of running my own timer that would essentially be doing the same thing.

does it make sense…?

so the new methods would be :

add event, remove events… passing a date and time of when the event would run… and my callback method / function.

thanks

Jay.


#4

Look at RealTimeClock.SetAlarm() method.

I think you can use this, and feed the Alarm pin into an Interrupt port.


#5

Hi Mike,
the idea is to be able to add as many functions (Alarms) as i want to the RealTimeClock… without involving any hardware… this is pure software… that’s the idea anyway… kind of like i want at 01-01-12 12:00PM myMethod() would run, and while that is i can have another myMethod2 set to run at 01-13-12 2:00 PM and so on… so Alarm pin would be limited to calling the same interrupt if i’m reading it right…

thanks Mike.
Jay.


#6

Sounds like a fun thing to build. I have done it several times. Not a lot of code.

You could go to the MS .NET MF site and submit a request.

The question will be whether the functionality will be used by enough people to justify the necessary development and run-time resources to add it.


#7

So you have done it using the timer i assume right? any sample code ?

maybe i will do it that way for now… until it gets implemented, i just hate the idea of wasting that extra processing power while another one is already running doing the exact same thing.

Thanks.
Jay.


#8

I think you are over estimating the resource saving of using the RTC. Most of the resources that are used go to maintaining the pending alarm queues, not keeping track of time.

I do not have sample code. The only code I have is written in C++ and it integrates with an application framework.


#9

Yes timers do not use much to run. Using RTC alarm is just over complicating things and probably using more resources at the end.


#10

I see thanks for clarifying things GUS…

I’ll mess with the timer and see if i can create a scheduler class that would allow me to set call backs…

thank you guys.

Jay.


#11

If you have any problems, let me know. There are some “interesting” aspects to queue management.


#12

I know i will have questions…
thanks Mike.


#13

I started to write a scheduler. A bit more complicated than I remembered. :smiley:

I hope to have it done within a day or so, and I will post in code section.


#14

Oooooooo…
Cool Mike…

Thanks for sharing…

Jay.


#15

Hey Mike,
just thinking about this… now if i schedule an event that would mean i’ll have to create a new thread and a timer for each event correct?


#16

Jay:

I have finished the code, but it has only been tested under the emulator.

In my scheduler, there is one thread for managing the pending timer requests, and one or more worker threads for executing callbacks.

I thought a bit about where the execution of the expired event should occur. Since the scheduler is a shared resource, I thought it would not be good to execute an expiration event on the thread that is managing the pending timers. If the callback took a long time, then it could mess up the timers.

I choose to use a separate thread for executing the callbacks. In fact, when the scheduler is instantiated, there is an option to define multiple worker threads.


#17

My knowledge of this topic is limited, but I also have been looking at using the RTC to schedule multiple alarms. The advantages I see of using the RTC over the extended timer is:

[ulist]
The RTC is run in hardware
The RTC will continue to run even if the main processor is hibernating
The RTC will wake-up the processor when an alarm event occurs[/ulist]


#18

Hi,
@ Mike thanks for the updates on the topic,
I will look at when i come back from Vacation and test it for you and report any changes… again thank you very much for your help.
@ jasdev: i agree with you, some of those were the reasons why i wanted it done at the RTC Level but as Gus pointed out it is harder to manage i guess. so for now i’ll do with this and most likely use the Current Alarm feature to always set the next event and monitor the interrupt… and when that event fires, create another alarm for the next event and continue on like that…

What do you think?

Jay.


#19

Remember that regardless of whether you use a software timer or the hardware RTC, you don’t have to schedule all the wake-ups, just the next wake-up.

Shouldn’t be that hard to manage, either way.


#20

Hello Mike,
Would you mind posting your code, i’d like to start with the scheduler and wanted to see what you have done so far…
thanks.

Happy New Year !!!

Jay.