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 | rtemsTask class. |
---|
15 | |
---|
16 | This class allows the user to create a RTEMS task, or to access and |
---|
17 | manage an already existing task. |
---|
18 | |
---|
19 | The first constructor with the task parameters creates a RTEMS task |
---|
20 | object. The destructor of this object also deletes the task |
---|
21 | object. The last status code should be checked after construction to |
---|
22 | see if the create completed successfully. |
---|
23 | |
---|
24 | The second constructor connects to an existing task object. The last |
---|
25 | status code should be checked after construction to see if the |
---|
26 | task existed. |
---|
27 | |
---|
28 | The third constructor is a copy constructor. Connects to an existing |
---|
29 | object which is in scope. |
---|
30 | |
---|
31 | The RTEMS id is set to self in the default construction. |
---|
32 | |
---|
33 | The creation of the task object can be defered until after |
---|
34 | construction. This allows for static task objects to be created. |
---|
35 | |
---|
36 | RTEMS should be initialised before static constructors run, how-ever |
---|
37 | threads will will not. You need to watch the start-order. |
---|
38 | |
---|
39 | A task object can change state from an owner of a task to being |
---|
40 | connected to a task. |
---|
41 | |
---|
42 | Task objects connected to another task do not receive notification |
---|
43 | when the task connected to changes state. |
---|
44 | |
---|
45 | The sleep methods operate on the current thread not the task |
---|
46 | reference by this object. |
---|
47 | |
---|
48 | Mode control is through the rtemsTaskMode class. |
---|
49 | |
---|
50 | The rtemsTask class reserved notepad register 31. |
---|
51 | |
---|
52 | ------------------------------------------------------------------------ */ |
---|
53 | |
---|
54 | #if !defined(_rtemsTask_h_) |
---|
55 | #define _rtemsTask_h_ |
---|
56 | |
---|
57 | #include <rtems++/rtemsStatusCode.h> |
---|
58 | |
---|
59 | /* ---- |
---|
60 | rtemsTask |
---|
61 | */ |
---|
62 | |
---|
63 | class rtemsTask |
---|
64 | : public rtemsStatusCode |
---|
65 | { |
---|
66 | public: |
---|
67 | enum FloatingPoint { fpoff = RTEMS_NO_FLOATING_POINT, |
---|
68 | fpon = RTEMS_FLOATING_POINT }; |
---|
69 | enum Scope { local = RTEMS_LOCAL, |
---|
70 | global = RTEMS_GLOBAL }; |
---|
71 | |
---|
72 | // only the first 4 characters of the name are taken |
---|
73 | |
---|
74 | // creates a task |
---|
75 | rtemsTask(const char* name, |
---|
76 | const rtems_task_priority initial_priority, |
---|
77 | const uint32_t stack_size, |
---|
78 | const rtems_mode preemption = RTEMS_NO_PREEMPT, |
---|
79 | const rtems_mode timeslice = RTEMS_NO_TIMESLICE, |
---|
80 | const rtems_mode asr = RTEMS_NO_ASR, |
---|
81 | const rtems_interrupt_level interrupt_level = 0, |
---|
82 | const FloatingPoint floating_point = fpoff, |
---|
83 | const Scope scope = local); |
---|
84 | |
---|
85 | // connects to a task |
---|
86 | rtemsTask(const char *name, const uint32_t node = RTEMS_SEARCH_ALL_NODES); |
---|
87 | |
---|
88 | // copy and default constructors |
---|
89 | rtemsTask(const rtemsTask& task); |
---|
90 | rtemsTask(); |
---|
91 | |
---|
92 | // only the creator's destructor will delete the actual object |
---|
93 | virtual ~rtemsTask(); |
---|
94 | |
---|
95 | // create or destroy (delete) the task |
---|
96 | virtual const rtems_status_code create(const char* name, |
---|
97 | const rtems_task_priority initial_priority, |
---|
98 | const uint32_t stack_size, |
---|
99 | const rtems_mode preemption = RTEMS_NO_PREEMPT, |
---|
100 | const rtems_mode timeslice = RTEMS_NO_TIMESLICE, |
---|
101 | const rtems_mode asr = RTEMS_NO_ASR, |
---|
102 | const rtems_interrupt_level interrupt_level = 0, |
---|
103 | const FloatingPoint floating_point = fpoff, |
---|
104 | const Scope scope = local); |
---|
105 | virtual const rtems_status_code destroy(); |
---|
106 | |
---|
107 | // connect to an existing task object, will not be the owner |
---|
108 | const rtemsTask& operator=(const rtemsTask& task); |
---|
109 | virtual const rtems_status_code connect(const char *name, |
---|
110 | const uint32_t node = RTEMS_SEARCH_ALL_NODES); |
---|
111 | |
---|
112 | // run control |
---|
113 | virtual const rtems_status_code start(const rtems_task_argument argument); |
---|
114 | virtual const rtems_status_code restart(const rtems_task_argument argument); |
---|
115 | virtual const rtems_status_code suspend(); |
---|
116 | virtual const rtems_status_code resume(); |
---|
117 | |
---|
118 | // sleep control, the timeout is in micro-seconds |
---|
119 | virtual const rtems_status_code wake_after(const rtems_interval micro_secs); |
---|
120 | virtual const rtems_status_code wake_when(const rtems_time_of_day& tod); |
---|
121 | |
---|
122 | // priority control |
---|
123 | const rtems_status_code get_priority(rtems_task_priority& priority); |
---|
124 | const rtems_status_code set_priority(const rtems_task_priority priority); |
---|
125 | const rtems_status_code set_priority(const rtems_task_priority priority, |
---|
126 | rtems_task_priority& old_priority); |
---|
127 | |
---|
128 | // notepad control |
---|
129 | const rtems_status_code get_note(const uint32_t notepad, |
---|
130 | uint32_t& note); |
---|
131 | const rtems_status_code set_note(const uint32_t notepad, |
---|
132 | const uint32_t note); |
---|
133 | |
---|
134 | // object id, and name |
---|
135 | const rtems_id id_is() const { return id; } |
---|
136 | const rtems_name name_is() const { return name; } |
---|
137 | const char *name_string() const { return name_str; } |
---|
138 | |
---|
139 | protected: |
---|
140 | |
---|
141 | // task entry point |
---|
142 | virtual void body(rtems_task_argument argument); |
---|
143 | |
---|
144 | private: |
---|
145 | |
---|
146 | // make the object to point to RTEMS_SELF |
---|
147 | void make_self(); |
---|
148 | |
---|
149 | // task name |
---|
150 | rtems_name name; |
---|
151 | char name_str[5]; |
---|
152 | |
---|
153 | // owner, true if this object owns the task |
---|
154 | // will delete the task when it destructs |
---|
155 | bool owner; |
---|
156 | |
---|
157 | // the rtems id, object handle |
---|
158 | rtems_id id; |
---|
159 | |
---|
160 | // the argument for the task, this class uses the actual argument |
---|
161 | // passed to RTEMS |
---|
162 | rtems_task_argument argument; |
---|
163 | |
---|
164 | // common entry point to the task |
---|
165 | static rtems_task origin(rtems_task_argument argument); |
---|
166 | }; |
---|
167 | |
---|
168 | #endif // _rtemsTask_h_ |
---|