F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Task.cpp
Go to the documentation of this file.
2#include <Os/Task.hpp>
4#include <Fw/Types/Assert.hpp>
5#include <cstdio>
6#include <new>
7
8namespace Os {
9
11 m_handle(0),
12 m_identifier(0),
13 m_affinity(-1),
14 m_started(false),
15 m_suspendedOnPurpose(false)
16{}
17
18Task::TaskStatus Task::start(const Fw::StringBase &name, taskRoutine routine, void* arg, NATIVE_UINT_TYPE priority, NATIVE_UINT_TYPE stackSize, NATIVE_UINT_TYPE cpuAffinity, NATIVE_UINT_TYPE identifier) {
19 //Get a task handle, and set it up
20 BareTaskHandle* handle = new(std::nothrow) BareTaskHandle();
21 if (handle == nullptr) {
23 }
24 //Set handle member variables
25 handle->m_enabled = true;
26 handle->m_priority = priority;
27 handle->m_routine = routine;
28 handle->m_argument = arg;
29 //Register this task using our custom task handle
30 m_handle = reinterpret_cast<POINTER_CAST>(handle);
31 this->m_name = "BR_";
32 this->m_name += name;
33 this->m_identifier = identifier;
34 // If a registry has been registered, register task
35 if (Task::s_taskRegistry) {
36 Task::s_taskRegistry->addTask(this);
37 }
38 //Running the task the first time allows setup activities for the task
39 handle->m_routine(handle->m_argument);
40 return Task::TASK_OK;
41}
42
44{
45 //Task delays are a bad idea in baremetal tasks
47}
48
50 if (this->m_handle) {
51 delete reinterpret_cast<BareTaskHandle*>(this->m_handle);
52 }
53 // If a registry has been registered, remove task
54 if (Task::s_taskRegistry) {
55 Task::s_taskRegistry->removeTask(this);
56 }
57}
58
59void Task::suspend(bool onPurpose) {
60 FW_ASSERT(reinterpret_cast<BareTaskHandle*>(this->m_handle) != nullptr);
61 reinterpret_cast<BareTaskHandle*>(this->m_handle)->m_enabled = false;
62}
63
65 FW_ASSERT(reinterpret_cast<BareTaskHandle*>(this->m_handle) != nullptr);
66 reinterpret_cast<BareTaskHandle*>(this->m_handle)->m_enabled = true;
67}
68
70 FW_ASSERT(reinterpret_cast<BareTaskHandle*>(this->m_handle) != nullptr);
71 return !reinterpret_cast<BareTaskHandle*>(this->m_handle)->m_enabled;
72}
73
74Task::TaskStatus Task::join(void **value_ptr) {
75 return TASK_OK;
76}
77
78}
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformPointerCastType POINTER_CAST
Definition BasicTypes.h:53
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
bool m_enabled
Save the priority.
Task::taskRoutine m_routine
Argument input pointer.
NATIVE_INT_TYPE m_priority
Function passed into the task.
static TaskStatus delay(NATIVE_UINT_TYPE msecs)
delay the task
Definition Task.cpp:43
Task()
constructor
Definition Task.cpp:10
virtual ~Task()
destructor
Definition Task.cpp:49
bool isSuspended()
check with OS to see if it is suspended already
Definition Task.cpp:69
void suspend(bool onPurpose=false)
suspend task
Definition Task.cpp:59
TaskStatus join(void **value_ptr)
Wait for task to finish.
Definition Task.cpp:74
TaskStatus
Definition Task.hpp:18
@ TASK_OK
message sent/received okay
Definition Task.hpp:19
@ TASK_DELAY_ERROR
error trying to delay the task
Definition Task.hpp:24
@ TASK_UNKNOWN_ERROR
unexpected error return value
Definition Task.hpp:22
void resume()
resume execution of task
Definition Task.cpp:64
TaskStatus start(const Fw::StringBase &name, taskRoutine routine, void *arg, NATIVE_UINT_TYPE priority=TASK_DEFAULT, NATIVE_UINT_TYPE stackSize=TASK_DEFAULT, NATIVE_UINT_TYPE cpuAffinity=TASK_DEFAULT, NATIVE_UINT_TYPE identifier=TASK_DEFAULT)
start the task
Definition Task.cpp:18
Definition File.cpp:6