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