ccNOos  v0.0.0
Build Portable Microcontroller Applications!
execution_system_class.cpp
Go to the documentation of this file.
1 /** \file execution_system_class.cpp
2 * \brief <a href="https://www.inmechasol.org/" target="_blank">IMS</a>:
3  <a href="https://github.com/InMechaSol/ccNOos" target="_blank">ccNOos</a>,
4  Implementation for C++ wrappers
5 
6  Copyright 2021 <a href="https://www.inmechasol.org/" target="_blank">InMechaSol, Inc</a>
7 
8  Licensed under the Apache License, Version 2.0(the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 Notes:
21  (.c includes .h) - for straight C or
22  (.cpp includes .c which includes .h) - for C++ wrapped straight C
23  *Always compiled to a single compilation unit, either C or CPP, not both
24 
25 */
26 
27 #include "execution_system.c" // -> includes all c stuff for cpp compilation
28 
29 linkedIODeviceClass::linkedIODeviceClass(
30  IODeviceClass* devPtrIn,
31  linkedIODeviceClass* nextPtrIn
32  )
33 {
34  devPtr = devPtrIn;
35  nextPtr = nextPtrIn;
36 }
37 IODeviceClass* linkedIODeviceClass::getDevPtr()
38 {
39  return devPtr;
40 }
41 linkedIODeviceClass* linkedIODeviceClass::getNextIOClassPtr()
42 {
43  return nextPtr;
44 }
45 
46 
47 linkedEntryPointClass::linkedEntryPointClass(
48  computeModuleClass* modulePtrIn,
49  linkedEntryPointClass* nextPtrIn
50  )
51 {
52  modulePtr = modulePtrIn;
53  nextPtr = nextPtrIn;
54 }
55 computeModuleClass* linkedEntryPointClass::getComputeModule()
56 {
57  return modulePtr;
58 }
59 linkedEntryPointClass* linkedEntryPointClass::getNextEPClassPtr()
60 {
61  return nextPtr;
62 }
63 
64 
65 executionSystemClass::executionSystemClass(
66  UI_32 uSperTick
67  )
68 {
70  uSperTick
71  );
72 }
73 
74 void executionSystemClass::LinkTheListsHead(
75  linkedEntryPointClass* setupListHeadIn,
76  linkedEntryPointClass* loopListHeadIn,
77  linkedEntryPointClass* sysTickListHeadIn,
78  linkedEntryPointClass* exceptionListHeadIn
79  )
80 {
81  setupListHead = setupListHeadIn;
82  loopListHead = loopListHeadIn;
83  sysTickListHead = sysTickListHeadIn;
84  exceptionListHead = exceptionListHeadIn;
85 }
86 
87 // Variants of the "main" entry points
89 {
90  // platform exe system setup
91 #ifndef __NOEXCEPTIONS
92  try
93  {
94 #endif
95  platformSetup();
96 #ifndef __NOEXCEPTIONS
97  }
98  catch (...) {
99  ;// WriteLogLine((char*)"Platform Setup Exception"); // exe sys logging
100  }
101 #endif
102 
103  // module setup execution area
105 
106  // platform exe system start
107 #ifndef __NOEXCEPTIONS
108  try
109  {
110 #endif
111  platformStart();
112 #ifndef __NOEXCEPTIONS
113  }
114  catch (...) {
115  ;// WriteLogLine((char*)"Platform Start Exception"); // exe sys logging
116  }
117 #endif
118 }
120 {
122 
124 
126 
127 }
129 {
130  ExecuteSetup();
131 
132  // module exception and loop execution areas
133  for(;;)
134  {
135  ExecuteLoop();
136  }
137  return RETURN_SUCCESS;
138 }
139 
140 // The "systick" entry point
142 {
143  data.uSecTicks += data.uSecPerSysTick;
144  if(data.uSecTicks >= TIME_uS_PER_HR)
145  {
146  data.uSecTicks = 0u;
147  data.hourTicks++;
148  }
149 
150  // module systick execution area
152 }
153 
154 void executionSystemClass::ModuleExeArea(int EXE_AREA_INDEX)
155 {
156  if(exceptionListHead!=nullptr)
157  {
158  linkedEntryPointClass* currentExeNode;
159  switch(EXE_AREA_INDEX)
160  {
161  case EXP_SETUP:
162  currentExeNode = setupListHead;
163  break;
164  case EXP_LOOP:
165  currentExeNode = loopListHead;
166  break;
167  case EXP_SYSTICK:
168  currentExeNode = sysTickListHead;
169  break;
170  default:
171  return;
172  }
173 
174  if(currentExeNode != nullptr){
175  if(currentExeNode->getComputeModule() != nullptr)
176  {
177  int retVal;
178  do
179  {
180 
181 #ifndef __NOEXCEPTIONS
182  try
183  {
184 #endif
185  if(currentExeNode->getComputeModule()->getModuleDataPtr()->exceptionFlags == 0u)
186  {
187  switch(EXE_AREA_INDEX)
188  {
189  case EXP_SETUP:
190  retVal = currentExeNode->getComputeModule()->mod_setup();
191  break;
192  case EXP_LOOP:
193  retVal = currentExeNode->getComputeModule()->mod_loop();
194  break;
195  case EXP_SYSTICK:
196  currentExeNode->getComputeModule()->mod_systick();
197  retVal = RETURN_SUCCESS;
198  break;
199  }
200  }
201  else
202  retVal = RETURN_SUCCESS;
203 
204  if(retVal != RETURN_SUCCESS)
205 #ifndef __NOEXCEPTIONS
206  throw RETURN_ERROR;
207 
208  }
209  catch(...)
210  {
211 #endif
212  currentExeNode->getComputeModule()->getModuleDataPtr()->exceptionFlags |= (0x00000001 << EXE_AREA_INDEX);
213 #ifndef __NOEXCEPTIONS
214  }
215 #endif
216  if(currentExeNode->getNextEPClassPtr() != nullptr)
217  currentExeNode = currentExeNode->getNextEPClassPtr();
218  else
219  break;
220 
221  }while(currentExeNode->getComputeModule() != nullptr);
222  }}
223  }
224 }
226 {
227  if(exceptionListHead!=nullptr)
228  {
229  linkedEntryPointClass* currentExeNode = exceptionListHead;
230  if(currentExeNode!=nullptr)
231  {
232  int retVal;
233  do
234  {
235 
236 #ifndef __NOEXCEPTIONS
237  try
238  {
239 #endif
240  if(currentExeNode->getComputeModule()->getModuleDataPtr()->exceptionFlags != 0u)
241  retVal = currentExeNode->getComputeModule()->mod_excphandler();
242  else
243  retVal = RETURN_SUCCESS;
244 
245  if(retVal != RETURN_SUCCESS)
246 #ifndef __NOEXCEPTIONS
247  throw RETURN_ERROR;
248 
249  }
250  catch(...)
251  {
252 #endif
253  currentExeNode->getComputeModule()->getModuleDataPtr()->exceptionFlags |= (0x00000001 << EXP_HANDLER);
254 #ifndef __NOEXCEPTIONS
255  }
256 #endif
257 
258  if(currentExeNode->getNextEPClassPtr() != nullptr)
259  currentExeNode = currentExeNode->getNextEPClassPtr();
260  else
261  break;
262 
263  }while(currentExeNode->getComputeModule() != nullptr);
264  }
265  }
266 }
ExecuteLoop
int ExecuteLoop(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:173
EXP_SETUP
#define EXP_SETUP
Definition: execution_system.h:43
EXP_HANDLER
#define EXP_HANDLER
Definition: execution_system.h:47
execution_system.c
IMS: ccNOos, Implementation for straight C
ModuleExeArea
void ModuleExeArea(UI_32 ExcpIndex, struct linkedEntryPointStruct *exeListHeadIn)
Definition: execution_system.c:47
platformStart
void platformStart()
Definition: Platform_Arduino.h:114
EXP_LOOP
#define EXP_LOOP
Definition: execution_system.h:44
platformSetup
void platformSetup()
Definition: Platform_Arduino.h:66
platformLoopDelay
void platformLoopDelay()
Definition: Platform_Arduino.h:128
EXP_SYSTICK
#define EXP_SYSTICK
Definition: execution_system.h:45
ModuleExceptionArea
void ModuleExceptionArea(struct linkedEntryPointStruct *exeListHeadIn)
Definition: execution_system.c:80
CreateExecutionSystemStruct
struct executionSystemStruct CreateExecutionSystemStruct(UI_32 uSperTick)
Definition: execution_system.c:31
ExecuteSetup
int ExecuteSetup(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:150
ExecuteMain
int ExecuteMain(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:112
ExecuteSysTick
void ExecuteSysTick(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:193
TIME_uS_PER_HR
#define TIME_uS_PER_HR
Definition: execution_system.h:35
RETURN_SUCCESS
#define RETURN_SUCCESS
Function Return Value for Success.
Definition: version_config.h:87
RETURN_ERROR
#define RETURN_ERROR
Function Return Value for ERROR.
Definition: version_config.h:92