OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [librtems++/] [include/] [rtems++/] [rtemsTimer.h] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
  ------------------------------------------------------------------------
3
  $Id: rtemsTimer.h,v 1.2 2001-09-27 12:02:05 chris Exp $
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.OARcorp.com/rtems/license.html.
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
 
37
class rtemsTimer
38
  : public rtemsStatusCode
39
{
40
public:
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
 
67
protected:
68
 
69
  // triggered method is called when the timer fires
70
  virtual void triggered() = 0;
71
 
72
private:
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
 
94
const 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
 
106
const 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
 
118
const 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
 
126
const rtems_status_code rtemsTimer::cancel()
127
{
128
  repeat = false;
129
  return set_status_code(rtems_timer_cancel(id));
130
}
131
 
132
const 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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.