source: rtems/c/src/librtems++/src/rtemsTimer.cc @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2  ------------------------------------------------------------------------
3
4  COPYRIGHT (c) 1997
5  Objective Design Systems Ltd Pty (ODS)
6  All rights reserved (R) Objective Design Systems Ltd Pty
7 
8  The license and distribution terms for this file may be found in the
9  file LICENSE in this distribution or at
10  http://www.rtems.org/license/LICENSE.
11
12  ------------------------------------------------------------------------
13
14  See header file.
15
16  ------------------------------------------------------------------------
17*/
18
19#include <cstring>
20#include <rtems++/rtemsTimer.h>
21
22/* ----
23    rtemsTimer
24*/
25
26rtemsTimer::rtemsTimer(const char* tname)
27  : name(0),
28    repeat(false),
29    id(0)
30{
31  strcpy(name_str, "    ");
32  create(tname);
33}
34
35rtemsTimer::rtemsTimer()
36  : name(0),
37    repeat(false),
38    id(0)
39{
40  strcpy(name_str, "    ");
41}
42
43rtemsTimer::~rtemsTimer()
44{
45  destroy();
46}
47
48void rtemsTimer::make_invalid()
49{
50  strcpy(name_str, "    ");
51  name = 0;
52  id = 0;
53  repeat = false;
54}
55const rtems_status_code rtemsTimer::create(const char* tname)
56{
57  if (id)
58    return set_status_code(RTEMS_ILLEGAL_ON_SELF);
59
60  strcpy(name_str, "    ");
61  for (int c = 0; (c < 4) && (tname[c] != '\0'); c++)
62    name_str[c] = tname[c];
63  name = rtems_build_name(name_str[0],
64                          name_str[1],
65                          name_str[2],
66                          name_str[3]);
67 
68  set_status_code(rtems_timer_create(name, &id));
69
70  if (unsuccessful())
71  {
72    make_invalid();
73  }
74 
75  return last_status_code();
76}
77
78const rtems_status_code rtemsTimer::destroy()
79{
80  if (id)
81  {
82    set_status_code(rtems_timer_delete(id));
83    make_invalid();
84  }
85  else
86    set_status_code(RTEMS_NOT_OWNER_OF_RESOURCE);
87 
88  return last_status_code();
89}
90 
91void rtemsTimer::common_handler(rtems_id , void *user_data)
92{
93  rtemsTimer *timer = (rtemsTimer*) user_data;
94 
95  if (timer->repeat)
96    timer->reset();
97
98  timer->triggered();
99}
Note: See TracBrowser for help on using the repository browser.