F´ Flight Software - C/C++ Documentation  NASA-v2.0.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TaskRunner.cpp
Go to the documentation of this file.
1 /*
2  * TaskRunner.cpp
3  *
4  * Created on: Feb 28, 2019
5  * Author: lestarch
6  */
7 #include <Fw/Types/Assert.hpp>
11 namespace Os {
12 
14  m_index(0),
15  m_cont(true)
16 {
17  for (U32 i = 0; i < TASK_REGISTRY_CAP; i++) {
18  this->m_task_table[i] = 0;
19  }
21 }
23 
25  FW_ASSERT(m_index < TASK_REGISTRY_CAP);
26  this->m_task_table[m_index] = task;
27  m_index++;
28 }
29 
31  bool found = false;
32  //Squash that existing task
33  for (U32 i = 0; i < TASK_REGISTRY_CAP; i++) {
34  found = found | (task == this->m_task_table[i]);
35  //If not found, keep looking
36  if (!found) {
37  continue;
38  }
39  //If we are less than the end of the array, shift variables over
40  else if (i < TASK_REGISTRY_CAP - 1) {
41  this->m_task_table[i] = this->m_task_table[i+1];
42  }
43  //If the last element, mark NULL
44  else {
45  this->m_task_table[i] = NULL;
46  }
47  }
48 }
49 
51  m_cont = false;
52 }
53 
55  U32 i = 0;
56  if (!m_cont) {
57  return;
58  }
59  //Loop through full table
60  for (i = 0; i < TASK_REGISTRY_CAP; i++) {
61  //Break at end of table
62  if (m_task_table[i] == NULL) {
63  break;
64  }
65  //Get bare task or break
66  BareTaskHandle* handle = reinterpret_cast<BareTaskHandle*>(m_task_table[i]->getRawHandle());
67  if (handle == NULL || handle->m_routine == NULL || !handle->m_enabled) {
68  continue;
69  }
70  //Run-it!
71  handle->m_routine(handle->m_argument);
72  //Disable tasks that have "exited" or stopped
73  handle->m_enabled = m_task_table[i]->isStarted();
74  }
75  //Check if no tasks, and stop
76  if (i == 0) {
77  m_cont = false;
78  }
79 }
80 }
Os
Definition: File.cpp:7
Os::TaskRunner::addTask
void addTask(Task *task)
Definition: TaskRunner.cpp:24
Os::BareTaskHandle::m_enabled
bool m_enabled
Save the priority.
Definition: BareTaskHandle.hpp:19
Os::BareTaskHandle::m_argument
void * m_argument
Definition: BareTaskHandle.hpp:25
Os::BareTaskHandle::m_routine
Task::taskRoutine m_routine
Argument input pointer.
Definition: BareTaskHandle.hpp:23
Os::Task::registerTaskRegistry
static void registerTaskRegistry(TaskRegistry *registry)
Definition: TaskCommon.cpp:35
Assert.hpp
Os::TaskRunner::stop
void stop()
Definition: TaskRunner.cpp:50
Os::TaskRunner::~TaskRunner
~TaskRunner()
Definition: TaskRunner.cpp:22
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Os::Task::isStarted
bool isStarted(void)
check to see if task is started
Definition: TaskCommon.cpp:19
Os::TaskRunner::run
void run()
Definition: TaskRunner.cpp:54
Os::Task::getRawHandle
POINTER_CAST getRawHandle()
Definition: TaskCommon.cpp:31
Os::Task
forward declaration
Definition: Task.hpp:15
Os::BareTaskHandle
Definition: BareTaskHandle.hpp:14
Os::TaskRunner::removeTask
void removeTask(Task *task)
Definition: TaskRunner.cpp:30
Os::TaskRunner::TaskRunner
TaskRunner()
< Nothing constructor
Definition: TaskRunner.cpp:13
TaskRunner.hpp
TASK_REGISTRY_CAP
#define TASK_REGISTRY_CAP
Definition: TaskRunner.hpp:13
BasicTypes.hpp
Declares ISF basic types.
BareTaskHandle.hpp
NULL
#define NULL
NULL.
Definition: BasicTypes.hpp:100