Home > Multitasking, Projects, RTOS, SKC++ > SKC++: Tasks and Timers

SKC++: Tasks and Timers

Monday, October 19, 2009 Leave a comment Go to comments

Just possibly, you may have been wondering why Task::wait does not include a timeout parameter. The answer is that it does not need to because a timeout is itself an event, so this can be waited for along with whatever event might be timed out. SKC++ has general-purpose timers which can be used not only for timing out other events but in their own right for other purposes. Here is a picture:-


Note that a timer, although not a task, is an active object. In other words, it runs autonomously and concurrently with other timers and with the system’s tasks.

Timer and RepeatingTimer are built into the kernel but it is expected that users might want to add hardware timers to the same specification, so I have included that specification in the diagram as an abstract interface. Generally I am not keen on putting purely abstract interfaces into the implementation of normal embedded systems, where they add overhead for no good reason. In such systems, the concrete classes are almost always fully decided before compilation of the system; abstract interfaces make more sense in parts of distributed systems where the concrete classes are not available to the compilation or may not even be decided until run-time. However, here the objective is to encourage users to develop classes which are consistent with existing ones without necessarily sharing any of their code, so deriving from an abstract class seems sensible. Having said that, though, I am quite likely to end up moving the implementations of some methods from Timer and RepeatingTimer to the base class simply because their code will probably be identical. Of course, they can still be overridden as necessary within a user class.

A timer is always associated with the task which creates it and it will post its designated event to that task. This may seem restrictive but it is a principle of SKC++ that each task should control its own timing. I have not been able to think of a case where this might cause a problem. If you can think of any, please let me know!

Coming back to timeouts, here is a code snippet (not of production quality!) showing the use of a timer to do this job:

void MyTask::activity()
    Timer timeout(EVENT_0);
        Event event = wait();

        // Other stuff...

Next time, I’ll move on to message-passing. This is quite a big subject, so there might be some intervening posts, unrelated to SKC++, while I work on it.

Categories: Multitasking, Projects, RTOS, SKC++ Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: