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.hpp
Go to the documentation of this file.
1#ifndef _Task_hpp_
2#define _Task_hpp_
3
4#include <FpConfig.hpp>
6#include <Os/TaskString.hpp>
7
8#include <Os/TaskId.hpp>
9#include <Fw/Deprecate.hpp>
10#include <limits>
11
12namespace Os {
13
14 class TaskRegistry;
15 class Task {
16 public:
18 typedef enum {
28 } TaskStatus ;
29
30 typedef void (*taskRoutine)(void* ptr);
31
34 void* arg;
35 };
36
37 Task();
38 virtual ~Task();
39
40 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);
41
42 // Deprecated: only the name, routine, and argument are **required** parameters. This ordering of parameters is therefore inappropriate and will be removed in the future
43 DEPRECATED(TaskStatus start(const Fw::StringBase &name, NATIVE_INT_TYPE identifier, NATIVE_INT_TYPE priority, NATIVE_INT_TYPE stackSize, taskRoutine routine, void* arg, NATIVE_INT_TYPE cpuAffinity = static_cast<NATIVE_INT_TYPE>(TASK_DEFAULT)),
44 "Please switch to start(Fw::StringBase &name, taskRoutine routine, void* arg, NATIVE_UINT_TYPE priority, NATIVE_UINT_TYPE stackSize, NATIVE_UINT_TYPE cpuAffinity, NATIVE_UINT_TYPE identifier)");
45 I32 getIdentifier();
46 static TaskId getOsIdentifier(); //Gets the Os Task ID. Useful for passive components.
47
48 static TaskStatus delay(NATIVE_UINT_TYPE msecs);
50
51 TaskStatus join(void **value_ptr);
52 void suspend(bool onPurpose = false);
53 void resume();
54 bool wasSuspended();
55 bool isSuspended();
56 bool isStarted();
57 void setStarted(bool started);
62
63 static void registerTaskRegistry(TaskRegistry* registry);
64
65 private:
66
67 POINTER_CAST m_handle;
68 NATIVE_INT_TYPE m_identifier;
69 TaskString m_name;
70 NATIVE_INT_TYPE m_affinity;
71
72 void toString(char* buf, NATIVE_INT_TYPE buffSize);
73 bool m_started;
74 bool m_suspendedOnPurpose;
75 TaskRoutineWrapper m_routineWrapper;
76
77 static TaskRegistry* s_taskRegistry;
78 static NATIVE_INT_TYPE s_numTasks;
79
80 };
81
83 public:
84 TaskRegistry();
85 virtual ~TaskRegistry();
86 virtual void addTask(Task* task) = 0;
87 virtual void removeTask(Task* task) = 0;
88
89 private:
90 };
91}
92
93#endif
PlatformPointerCastType POINTER_CAST
Definition BasicTypes.h:53
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
C++-compatible configuration header for fprime configuration.
forward declaration
Definition Task.hpp:15
bool wasSuspended()
returns whether or not task was suspended on purpose
static TaskStatus delay(NATIVE_UINT_TYPE msecs)
delay the task
Definition Task.cpp:43
I32 getIdentifier()
get the identifier for the task
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
static const NATIVE_UINT_TYPE TASK_DEFAULT
Definition Task.hpp:17
void(* taskRoutine)(void *ptr)
prototype for task routine started in task context
Definition Task.hpp:30
static TaskId getOsIdentifier()
Definition Task.cpp:295
TaskStatus join(void **value_ptr)
Wait for task to finish.
Definition Task.cpp:74
TaskStatus
Definition Task.hpp:18
@ TASK_ERROR_PERMISSION
permissions error setting-up tasks
Definition Task.hpp:27
@ TASK_OK
message sent/received okay
Definition Task.hpp:19
@ TASK_INVALID_STACK
started with invalid stack size
Definition Task.hpp:21
@ TASK_DELAY_ERROR
error trying to delay the task
Definition Task.hpp:24
@ TASK_INVALID_PARAMS
started task with invalid parameters
Definition Task.hpp:20
@ TASK_INVALID_AFFINITY
unable to set the task affinity
Definition Task.hpp:23
@ TASK_ERROR_RESOURCES
unable to allocate more tasks
Definition Task.hpp:26
@ TASK_UNKNOWN_ERROR
unexpected error return value
Definition Task.hpp:22
@ TASK_JOIN_ERROR
error trying to join the task
Definition Task.hpp:25
void resume()
resume execution of task
Definition Task.cpp:64
bool isStarted()
check to see if task is started
static void registerTaskRegistry(TaskRegistry *registry)
void setStarted(bool started)
set task to started when thread is fully up. Avoids a VxWorks race condition.
POINTER_CAST getRawHandle()
DEPRECATED(TaskStatus start(const Fw::StringBase &name, NATIVE_INT_TYPE identifier, NATIVE_INT_TYPE priority, NATIVE_INT_TYPE stackSize, taskRoutine routine, void *arg, NATIVE_INT_TYPE cpuAffinity=static_cast< NATIVE_INT_TYPE >(TASK_DEFAULT)), "Please switch to start(Fw::StringBase &name, taskRoutine routine, void* arg, NATIVE_UINT_TYPE priority, NATIVE_UINT_TYPE stackSize, NATIVE_UINT_TYPE cpuAffinity, NATIVE_UINT_TYPE identifier)")
start the task
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
static NATIVE_INT_TYPE getNumTasks()
virtual void addTask(Task *task)=0
Add a task to the registry.
TaskRegistry()
constructor for task registry
virtual ~TaskRegistry()
destructor for task registry
virtual void removeTask(Task *task)=0
remove a task from the registry
Definition File.cpp:6
taskRoutine routine
contains the task entrypoint
Definition Task.hpp:33
void * arg
contains the task entrypoint pointer
Definition Task.hpp:34