[0074691a] | 1 | /* |
---|
| 2 | ------------------------------------------------------------------------ |
---|
| 3 | |
---|
| 4 | COPYRIGHT (c) 1997 |
---|
| 5 | Objective Design Systems Ltd Pty (ODS) |
---|
| 6 | All rights reserved (R) Objective Design Systems Ltd Pty |
---|
[1b4f2b30] | 7 | |
---|
[0074691a] | 8 | The license and distribution terms for this file may be found in the |
---|
| 9 | file LICENSE in this distribution or at |
---|
[c499856] | 10 | http://www.rtems.org/license/LICENSE. |
---|
[0074691a] | 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. |
---|
[1b4f2b30] | 30 | |
---|
[0074691a] | 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. |
---|
[1b4f2b30] | 51 | |
---|
[0074691a] | 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 | |
---|
[1c9a4c75] | 72 | // only the first 4 characters of the name are taken |
---|
[0074691a] | 73 | |
---|
| 74 | // creates a task |
---|
| 75 | rtemsTask(const char* name, |
---|
| 76 | const rtems_task_priority initial_priority, |
---|
[600a241e] | 77 | const uint32_t stack_size, |
---|
[0074691a] | 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 |
---|
[600a241e] | 86 | rtemsTask(const char *name, const uint32_t node = RTEMS_SEARCH_ALL_NODES); |
---|
[0074691a] | 87 | |
---|
| 88 | // copy and default constructors |
---|
| 89 | rtemsTask(const rtemsTask& task); |
---|
| 90 | rtemsTask(); |
---|
[1b4f2b30] | 91 | |
---|
[0074691a] | 92 | // only the creator's destructor will delete the actual object |
---|
| 93 | virtual ~rtemsTask(); |
---|
[1b4f2b30] | 94 | |
---|
[0074691a] | 95 | // create or destroy (delete) the task |
---|
| 96 | virtual const rtems_status_code create(const char* name, |
---|
| 97 | const rtems_task_priority initial_priority, |
---|
[600a241e] | 98 | const uint32_t stack_size, |
---|
[0074691a] | 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, |
---|
[600a241e] | 110 | const uint32_t node = RTEMS_SEARCH_ALL_NODES); |
---|
[1b4f2b30] | 111 | |
---|
[0074691a] | 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); |
---|
[1b4f2b30] | 121 | |
---|
[0074691a] | 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); |
---|
[1b4f2b30] | 127 | |
---|
[0074691a] | 128 | // notepad control |
---|
[600a241e] | 129 | const rtems_status_code get_note(const uint32_t notepad, |
---|
[3ac68119] | 130 | uint32_t& note) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE; |
---|
[600a241e] | 131 | const rtems_status_code set_note(const uint32_t notepad, |
---|
[3ac68119] | 132 | const uint32_t note) RTEMS_COMPILER_DEPRECATED_ATTRIBUTE; |
---|
[0074691a] | 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; } |
---|
[1b4f2b30] | 138 | |
---|
[0074691a] | 139 | protected: |
---|
| 140 | |
---|
| 141 | // task entry point |
---|
| 142 | virtual void body(rtems_task_argument argument); |
---|
[1b4f2b30] | 143 | |
---|
[0074691a] | 144 | private: |
---|
| 145 | |
---|
| 146 | // make the object to point to RTEMS_SELF |
---|
| 147 | void make_self(); |
---|
[1b4f2b30] | 148 | |
---|
[0074691a] | 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; |
---|
[1b4f2b30] | 156 | |
---|
[0074691a] | 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; |
---|
[1b4f2b30] | 163 | |
---|
[0074691a] | 164 | // common entry point to the task |
---|
| 165 | static rtems_task origin(rtems_task_argument argument); |
---|
| 166 | }; |
---|
| 167 | |
---|
| 168 | #endif // _rtemsTask_h_ |
---|