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.OARcorp.com/rtems/license.html. |
---|
13 | |
---|
14 | ------------------------------------------------------------------------ |
---|
15 | |
---|
16 | See header file. |
---|
17 | |
---|
18 | ------------------------------------------------------------------------ |
---|
19 | */ |
---|
20 | |
---|
21 | #include <rtems++/rtemsTimer.h> |
---|
22 | |
---|
23 | /* ---- |
---|
24 | rtemsTimer |
---|
25 | */ |
---|
26 | |
---|
27 | rtemsTimer::rtemsTimer(const char* tname) |
---|
28 | : name(0), |
---|
29 | repeat(false), |
---|
30 | id(0) |
---|
31 | { |
---|
32 | strcpy(name_str, " "); |
---|
33 | create(tname); |
---|
34 | } |
---|
35 | |
---|
36 | rtemsTimer::rtemsTimer() |
---|
37 | : name(0), |
---|
38 | repeat(false), |
---|
39 | id(0) |
---|
40 | { |
---|
41 | strcpy(name_str, " "); |
---|
42 | } |
---|
43 | |
---|
44 | rtemsTimer::~rtemsTimer() |
---|
45 | { |
---|
46 | destroy(); |
---|
47 | } |
---|
48 | |
---|
49 | void rtemsTimer::make_invalid() |
---|
50 | { |
---|
51 | strcpy(name_str, " "); |
---|
52 | name = 0; |
---|
53 | id = 0; |
---|
54 | repeat = false; |
---|
55 | } |
---|
56 | const rtems_status_code rtemsTimer::create(const char* tname) |
---|
57 | { |
---|
58 | if (id) |
---|
59 | return set_status_code(RTEMS_ILLEGAL_ON_SELF); |
---|
60 | |
---|
61 | strcpy(name_str, " "); |
---|
62 | for (int c = 0; (c < 4) && (tname[c] != '\0'); c++) |
---|
63 | name_str[c] = tname[c]; |
---|
64 | name = rtems_build_name(name_str[0], |
---|
65 | name_str[1], |
---|
66 | name_str[2], |
---|
67 | name_str[3]); |
---|
68 | |
---|
69 | set_status_code(rtems_timer_create(name, &id)); |
---|
70 | |
---|
71 | if (unsuccessful()) |
---|
72 | { |
---|
73 | make_invalid(); |
---|
74 | } |
---|
75 | |
---|
76 | return last_status_code(); |
---|
77 | } |
---|
78 | |
---|
79 | const rtems_status_code rtemsTimer::destroy() |
---|
80 | { |
---|
81 | if (id) |
---|
82 | { |
---|
83 | set_status_code(rtems_timer_delete(id)); |
---|
84 | make_invalid(); |
---|
85 | } |
---|
86 | else |
---|
87 | set_status_code(RTEMS_NOT_OWNER_OF_RESOURCE); |
---|
88 | |
---|
89 | return last_status_code(); |
---|
90 | } |
---|
91 | |
---|
92 | void rtemsTimer::common_handler(rtems_id , void *user_data) |
---|
93 | { |
---|
94 | rtemsTimer *timer = (rtemsTimer*) user_data; |
---|
95 | |
---|
96 | if (timer->repeat) |
---|
97 | timer->reset(); |
---|
98 | |
---|
99 | timer->triggered(); |
---|
100 | } |
---|