summaryrefslogtreecommitdiffstats
path: root/c/src/lib/include/rtems++/rtemsTask.h
blob: 08156428fbe7b1d3aaa9b8cd5b20c9a7c4acdad1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
  ------------------------------------------------------------------------
  $Id$
  ------------------------------------------------------------------------

  COPYRIGHT (c) 1997
  Objective Design Systems Ltd Pty (ODS)
  All rights reserved (R) Objective Design Systems Ltd Pty
  
  The license and distribution terms for this file may be found in the
  file LICENSE in this distribution or at
  http://www.OARcorp.com/rtems/license.html.

  ------------------------------------------------------------------------

  rtemsTask class.

  This class allows the user to create a RTEMS task, or to access and
  manage an already existing task.

  The first constructor with the task parameters creates a RTEMS task
  object. The destructor of this object also deletes the task
  object. The last status code should be checked after construction to
  see if the create completed successfully.

  The second constructor connects to an existing task object. The last
  status code should be checked after construction to see if the
  task existed.

  The third constructor is a copy constructor. Connects to an existing
  object which is in scope.
  
  The RTEMS id is set to self in the default construction.

  The creation of the task object can be defered until after
  construction. This allows for static task objects to be created.

  RTEMS should be initialised before static constructors run, how-ever
  threads will will not. You need to watch the start-order.

  A task object can change state from an owner of a task to being
  connected to a task.

  Task objects connected to another task do not receive notification
  when the task connected to changes state.

  The sleep methods operate on the current thread not the task
  reference by this object.

  Mode control is through the rtemsTaskMode class.

  The rtemsTask class reserved notepad register 31.
  
  ------------------------------------------------------------------------ */

#if !defined(_rtemsTask_h_)
#define _rtemsTask_h_

#include <rtems++/rtemsStatusCode.h>

/* ----
    rtemsTask
*/

class rtemsTask
  : public rtemsStatusCode
{
public:
  enum FloatingPoint { fpoff = RTEMS_NO_FLOATING_POINT,
                       fpon = RTEMS_FLOATING_POINT };
  enum Scope { local = RTEMS_LOCAL,
               global = RTEMS_GLOBAL };

  // only the first 4 characters of the name are taken  

  // creates a task
  rtemsTask(const char* name,
            const rtems_task_priority initial_priority,
            const rtems_unsigned32 stack_size,
            const rtems_mode preemption = RTEMS_NO_PREEMPT,
            const rtems_mode timeslice = RTEMS_NO_TIMESLICE,
            const rtems_mode asr = RTEMS_NO_ASR,
            const rtems_interrupt_level interrupt_level = 0,
            const FloatingPoint floating_point = fpoff,
            const Scope scope = local);

  // connects to a task
  rtemsTask(const char *name, const rtems_unsigned32 node = RTEMS_SEARCH_ALL_NODES);

  // copy and default constructors
  rtemsTask(const rtemsTask& task);
  rtemsTask();
  
  // only the creator's destructor will delete the actual object
  virtual ~rtemsTask();
    
  // create or destroy (delete) the task
  virtual const rtems_status_code create(const char* name,
                                         const rtems_task_priority initial_priority,
                                         const rtems_unsigned32 stack_size,
                                         const rtems_mode preemption = RTEMS_NO_PREEMPT,
                                         const rtems_mode timeslice = RTEMS_NO_TIMESLICE,
                                         const rtems_mode asr = RTEMS_NO_ASR,
                                         const rtems_interrupt_level interrupt_level = 0,
                                         const FloatingPoint floating_point = fpoff,
                                         const Scope scope = local);
  virtual const rtems_status_code destroy();

  // connect to an existing task object, will not be the owner
  const rtemsTask& operator=(const rtemsTask& task);
  virtual const rtems_status_code connect(const char *name,
                                          const rtems_unsigned32 node = RTEMS_SEARCH_ALL_NODES);
  
  // run control
  virtual const rtems_status_code start(const rtems_task_argument argument);
  virtual const rtems_status_code restart(const rtems_task_argument argument);
  virtual const rtems_status_code suspend();
  virtual const rtems_status_code resume();

  // sleep control, the timeout is in micro-seconds
  virtual const rtems_status_code wake_after(const rtems_interval micro_secs);
  virtual const rtems_status_code wake_when(const rtems_time_of_day& tod);
  
  // priority control
  const rtems_status_code get_priority(rtems_task_priority& priority);
  const rtems_status_code set_priority(const rtems_task_priority priority);
  const rtems_status_code set_priority(const rtems_task_priority priority,
                                       rtems_task_priority& old_priority);
  
  // notepad control
  const rtems_status_code get_note(const rtems_unsigned32 notepad,
                                   rtems_unsigned32& note);
  const rtems_status_code set_note(const rtems_unsigned32 notepad,
                                   const rtems_unsigned32 note);

  // object id, and name
  const rtems_id id_is() const { return id; }
  const rtems_name name_is() const { return name; }
  const char *name_string() const { return name_str; }
  
protected:

  // task entry point
  virtual void body(rtems_task_argument argument);
  
private:

  // make the object to point to RTEMS_SELF
  void make_self();
  
  // task name
  rtems_name name;
  char name_str[5];

  // owner, true if this object owns the task
  // will delete the task when it destructs
  bool owner;
    
  // the rtems id, object handle
  rtems_id id;

  // the argument for the task, this class uses the actual argument
  // passed to RTEMS
  rtems_task_argument argument;
  
  // common entry point to the task
  static rtems_task origin(rtems_task_argument argument);
};

#endif  // _rtemsTask_h_