F´ Flight Software - C/C++ Documentation  NASA-v1.5.0
A framework for building embedded system applications to NASA flight quality standards.
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 }
29  FW_ASSERT(m_index < TASK_REGISTRY_CAP);
30  this->m_task_table[m_index] = task;
31  m_index++;
32 }
38  bool found = false;
39  //Squash that existing task
40  for (U32 i = 0; i < TASK_REGISTRY_CAP; i++) {
41  found = found | (task == this->m_task_table[i]);
42  //If not found, keep looking
43  if (!found) {
44  continue;
45  }
46  //If we are less than the end of the array, shift variables over
47  else if (i < TASK_REGISTRY_CAP - 1) {
48  this->m_task_table[i] = this->m_task_table[i+1];
49  }
50  //If the last element, mark NULL
51  else {
52  this->m_task_table[i] = NULL;
53  }
54  }
55 }
60  m_cont = false;
61 }
66  U32 i = 0;
67  if (!m_cont) {
68  return;
69  }
70  //Loop through full table
71  for (i = 0; i < TASK_REGISTRY_CAP; i++) {
72  //Break at end of table
73  if (m_task_table[i] == NULL) {
74  break;
75  }
76  //Get bare task or break
77  BareTaskHandle* handle = reinterpret_cast<BareTaskHandle*>(m_task_table[i]->getRawHandle());
78  if (handle == NULL || handle->m_routine == NULL || !handle->m_enabled) {
79  continue;
80  }
81  //Run-it!
82  handle->m_routine(handle->m_argument);
83  //Disable tasks that have "exited" or stopped
84  handle->m_enabled = m_task_table[i]->isStarted();
85  }
86  //Check if no tasks, and stop
87  if (i == 0) {
88  m_cont = false;
89  }
90 }
91 }
Os
Definition: File.cpp:7
Os::TaskRunner::addTask
void addTask(Task *task)
Definition: TaskRunner.cpp:28
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:59
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:65
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:37
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