Lab 1 Program C

Dependents:   Lab1C

Fork of mbed by -deleted-

Committer:
simon.ford@mbed.co.uk
Date:
Fri Nov 14 15:25:20 2008 +0000
Revision:
3:aefd12a1f1c5
Child:
4:5d1359a283bc
Added Ticker and Timeout abstractions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon.ford@mbed.co.uk 3:aefd12a1f1c5 1 /* mbed Microcontroller Library - TimerEvent
simon.ford@mbed.co.uk 3:aefd12a1f1c5 2 * Copyright (c) 2007-2008, sford
simon.ford@mbed.co.uk 3:aefd12a1f1c5 3 */
simon.ford@mbed.co.uk 3:aefd12a1f1c5 4
simon.ford@mbed.co.uk 3:aefd12a1f1c5 5 #ifndef MBED_TIMEREVENT_H
simon.ford@mbed.co.uk 3:aefd12a1f1c5 6 #define MBED_TIMEREVENT_H
simon.ford@mbed.co.uk 3:aefd12a1f1c5 7
simon.ford@mbed.co.uk 3:aefd12a1f1c5 8 namespace mbed {
simon.ford@mbed.co.uk 3:aefd12a1f1c5 9
simon.ford@mbed.co.uk 3:aefd12a1f1c5 10 // Base abstraction for timer interrupts
simon.ford@mbed.co.uk 3:aefd12a1f1c5 11 class TimerEvent {
simon.ford@mbed.co.uk 3:aefd12a1f1c5 12
simon.ford@mbed.co.uk 3:aefd12a1f1c5 13 public:
simon.ford@mbed.co.uk 3:aefd12a1f1c5 14
simon.ford@mbed.co.uk 3:aefd12a1f1c5 15 // The handler registered with the underlying timer interrupt
simon.ford@mbed.co.uk 3:aefd12a1f1c5 16 static void irq();
simon.ford@mbed.co.uk 3:aefd12a1f1c5 17
simon.ford@mbed.co.uk 3:aefd12a1f1c5 18 // Destruction removes it...
simon.ford@mbed.co.uk 3:aefd12a1f1c5 19 virtual ~TimerEvent();
simon.ford@mbed.co.uk 3:aefd12a1f1c5 20
simon.ford@mbed.co.uk 3:aefd12a1f1c5 21 protected:
simon.ford@mbed.co.uk 3:aefd12a1f1c5 22
simon.ford@mbed.co.uk 3:aefd12a1f1c5 23 // The handler called to service the timer event of the derived class
simon.ford@mbed.co.uk 3:aefd12a1f1c5 24 virtual void handler() = 0;
simon.ford@mbed.co.uk 3:aefd12a1f1c5 25
simon.ford@mbed.co.uk 3:aefd12a1f1c5 26 // insert in to linked list
simon.ford@mbed.co.uk 3:aefd12a1f1c5 27 void insert(unsigned int timestamp);
simon.ford@mbed.co.uk 3:aefd12a1f1c5 28
simon.ford@mbed.co.uk 3:aefd12a1f1c5 29 // remove from linked list, if in it
simon.ford@mbed.co.uk 3:aefd12a1f1c5 30 void remove();
simon.ford@mbed.co.uk 3:aefd12a1f1c5 31
simon.ford@mbed.co.uk 3:aefd12a1f1c5 32 // Get the current usec timestamp
simon.ford@mbed.co.uk 3:aefd12a1f1c5 33 static unsigned int timestamp();
simon.ford@mbed.co.uk 3:aefd12a1f1c5 34
simon.ford@mbed.co.uk 3:aefd12a1f1c5 35 static TimerEvent *_head; // The head of the list of the events, NULL if none
simon.ford@mbed.co.uk 3:aefd12a1f1c5 36 TimerEvent *_next; // Pointer to the next in the list, NULL if last
simon.ford@mbed.co.uk 3:aefd12a1f1c5 37 unsigned int _timestamp; // The timestamp at which the even should be triggered
simon.ford@mbed.co.uk 3:aefd12a1f1c5 38
simon.ford@mbed.co.uk 3:aefd12a1f1c5 39 };
simon.ford@mbed.co.uk 3:aefd12a1f1c5 40
simon.ford@mbed.co.uk 3:aefd12a1f1c5 41 }
simon.ford@mbed.co.uk 3:aefd12a1f1c5 42
simon.ford@mbed.co.uk 3:aefd12a1f1c5 43 #endif