source: rtems/c/src/librtems++/include/rtems++/rtemsTimer.h @ fa9ef954

4.104.114.84.9
Last change on this file since fa9ef954 was fa9ef954, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:53:21 PM

2003-09-04 Joel Sherrill <joel@…>

  • include/rtems++/rtemsEvent.h, include/rtems++/rtemsInterrupt.h, include/rtems++/rtemsMessageQueue.h, include/rtems++/rtemsSemaphore.h, include/rtems++/rtemsStatusCode.h, include/rtems++/rtemsTask.h, include/rtems++/rtemsTaskMode.h, include/rtems++/rtemsTimer.h, src/rtemsEvent.cc, src/rtemsInterrupt.cc, src/rtemsMessageQueue.cc, src/rtemsSemaphore.cc, src/rtemsStatusCode.cc, src/rtemsTask.cc, src/rtemsTimer.cc: URL for license changed.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2  ------------------------------------------------------------------------
3  $Id$
4  ------------------------------------------------------------------------
5
6  COPYRIGHT (c) 1997
7  Objective Design Systems Ltd Pty (ODS)
8  All rights reserved (R) Objective Design Systems Ltd Pty
9 
10  The license and distribution terms for this file may be found in the
11  file LICENSE in this distribution or at
12  http://www.rtems.com/license/LICENSE.
13
14  ------------------------------------------------------------------------
15
16  rtemsTimer class.
17
18  This class allows the user to create a RTEMS timer.
19
20  The trigger method is called when the timer expires. The method is
21  called using the thread which calls the RTEMS 'rtems_clock_tick'
22  method.
23
24  Timers are always local to a node.
25 
26  ------------------------------------------------------------------------ */
27
28#if !defined(_rtemsTimer_h_)
29#define _rtemsTimer_h_
30
31#include <rtems++/rtemsStatusCode.h>
32
33/* ----
34    rtemsTimer
35*/
36
37class rtemsTimer
38  : public rtemsStatusCode
39{
40public:
41  // only the first 4 characters of the name are taken,
42
43  // create a timer object
44  rtemsTimer(const char* name);
45  rtemsTimer();
46 
47  // destroies the actual object
48  virtual ~rtemsTimer();
49
50  // create or destroy (delete) the timer
51  virtual const rtems_status_code create(const char* name);
52  virtual const rtems_status_code destroy();
53 
54  // timer control
55  inline const rtems_status_code fire_after(const rtems_interval micro_secs);
56  inline const rtems_status_code repeat_fire_at(const rtems_interval micro_secs);
57  inline const rtems_status_code fire_when(const rtems_time_of_day& when);
58 
59  inline const rtems_status_code cancel();
60  inline const rtems_status_code reset();
61   
62  // object id, and name
63  const rtems_id id_is() const { return id; }
64  const rtems_name name_is() const { return name; }
65  const char *name_string() const { return name_str; }
66 
67protected:
68
69  // triggered method is called when the timer fires
70  virtual void triggered() = 0;
71 
72private:
73  // not permitted
74  rtemsTimer(const rtemsTimer& timer);
75  rtemsTimer& operator=(const rtemsTimer& timer);
76
77  // make this object reference an invalid RTEMS object
78  void make_invalid();
79 
80  // semaphore name
81  rtems_name name;
82  char name_str[5];
83
84  // repeat true restart the timer when it fires
85  bool repeat;
86
87  // the rtems id, object handle
88  rtems_id id;
89
90  // common timer handler
91  static void common_handler(rtems_id id, void *user_data);
92};
93
94const rtems_status_code rtemsTimer::fire_after(const rtems_interval micro_secs)
95{
96  repeat = false;
97  rtems_interval usecs =
98    micro_secs && (micro_secs < _TOD_Microseconds_per_tick) ?
99    _TOD_Microseconds_per_tick : micro_secs;
100  return set_status_code(rtems_timer_fire_after(id,
101                                                TOD_MICROSECONDS_TO_TICKS(usecs),
102                                                common_handler,
103                                                this));
104}
105
106const rtems_status_code rtemsTimer::repeat_fire_at(const rtems_interval micro_secs)
107{
108  repeat = true;
109  rtems_interval usecs =
110    micro_secs && (micro_secs < _TOD_Microseconds_per_tick) ?
111    _TOD_Microseconds_per_tick : micro_secs;
112  return set_status_code(rtems_timer_fire_after(id,
113                                                TOD_MICROSECONDS_TO_TICKS(usecs),
114                                                common_handler,
115                                                this));
116}
117
118const rtems_status_code rtemsTimer::fire_when(const rtems_time_of_day& when)
119{
120  return set_status_code(rtems_timer_fire_when(id,
121                                               (rtems_time_of_day*) &when,
122                                               common_handler,
123                                               this));
124}
125
126const rtems_status_code rtemsTimer::cancel()
127{
128  repeat = false;
129  return set_status_code(rtems_timer_cancel(id));
130}
131
132const rtems_status_code rtemsTimer::reset()
133{ 
134  return set_status_code(rtems_timer_reset(id));
135}
136
137#endif  // _rtemsTimer_h_
138
139
140
141
142
143
144
145
Note: See TracBrowser for help on using the repository browser.