ccNOos  v0.0.0
Build Portable Microcontroller Applications!
execution_system.c
Go to the documentation of this file.
1 /** \file execution_system.c
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 straight C
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.h"
28 #include "console_menu.h"
29 
30 
32  UI_32 uSperTick
33  )
34 {
35  struct executionSystemStruct outStruct;
36  outStruct.hourTicks = 0u;
37  outStruct.uSecTicks = 0u;
38  outStruct.uSecPerSysTick = uSperTick;
39  return outStruct;
40 }
41 
42 
43 ////////////////////////////////////////////////////////////////////////////////
44 // C Application Entry Points (not built in cpp build)
45 #ifndef __cplusplus
46 
48  UI_32 ExcpIndex,
49  struct linkedEntryPointStruct* exeListHeadIn
50  )
51 {
52  struct linkedEntryPointStruct* currentExeNode = exeListHeadIn;
53  int retVal;
54  if(currentExeNode!=nullptr)
55  {
56  if(currentExeNode->entryPoint != nullptr)
57  {
58  do
59  {
60  if(currentExeNode->dataPtr->exceptionFlags==0u)
61  retVal = currentExeNode->entryPoint(
62  currentExeNode->dataPtr
63  );
64  else
65  retVal = RETURN_SUCCESS;
66 
67  if(retVal != RETURN_SUCCESS)
68  currentExeNode->dataPtr->exceptionFlags |= (0x00000001 << ExcpIndex);
69 
70  if(currentExeNode->nextPtr != nullptr)
71  currentExeNode = currentExeNode->nextPtr;
72  else
73  break;
74 
75  }while(currentExeNode->entryPoint != nullptr);
76  }
77  }
78 }
79 
81  struct linkedEntryPointStruct* exeListHeadIn
82  )
83 {
84  struct linkedEntryPointStruct* currentExeNode = exeListHeadIn;
85  int retVal;
86  if(currentExeNode!=nullptr)
87  {
88  if(currentExeNode->entryPoint != nullptr)
89  {
90  do
91  {
92  if(currentExeNode->dataPtr->exceptionFlags!=0u)
93  retVal = currentExeNode->entryPoint(
94  currentExeNode->dataPtr
95  );
96  else
97  retVal = RETURN_SUCCESS;
98 
99  if(retVal != RETURN_SUCCESS)
100  currentExeNode->dataPtr->exceptionFlags |= (0x00000001 << EXP_HANDLER);
101 
102  if(currentExeNode->nextPtr != nullptr)
103  currentExeNode = currentExeNode->nextPtr;
104  else
105  break;
106 
107  }while(currentExeNode->entryPoint != nullptr);
108  }
109  }
110 }
111 
113  struct executionSystemStruct* exeStructIn,
114  struct executionEntryStruct* exeEntryPtrsIn
115  )
116 {
117  if(exeStructIn == nullptr || exeEntryPtrsIn == nullptr)
118  return RETURN_ERROR;
119 
120  // platform exe system setup
121  platformSetup();
122 
123  // module setup execution area
125  EXP_SETUP,
126  exeEntryPtrsIn->setupListHead
127  );
128 
129  // platform exe system start
130  platformStart();
131 
132  // module exception and loop execution areas
133  for(;;)
134  {
136  exeEntryPtrsIn->exceptionListHead
137  );
138 
140  EXP_LOOP,
141  exeEntryPtrsIn->loopListHead
142  );
143 
145  }
146 
147  return RETURN_SUCCESS;
148 }
149 
151  struct executionSystemStruct* exeStructIn,
152  struct executionEntryStruct* exeEntryPtrsIn
153  )
154 {
155  if(exeStructIn == nullptr || exeEntryPtrsIn == nullptr)
156  return RETURN_ERROR;
157 
158  // platform exe system setup
159  platformSetup();
160 
161  // module setup execution area
163  EXP_SETUP,
164  exeEntryPtrsIn->setupListHead
165  );
166 
167  // platform exe system start
168  platformStart();
169 
170  return RETURN_SUCCESS;
171 }
172 
174  struct executionSystemStruct* exeStructIn,
175  struct executionEntryStruct* exeEntryPtrsIn
176  )
177 {
178  // module exception and loop execution areas
180  exeEntryPtrsIn->exceptionListHead
181  );
182 
184  EXP_LOOP,
185  exeEntryPtrsIn->loopListHead
186  );
187 
189 
190  return RETURN_SUCCESS;
191 }
192 
194  struct executionSystemStruct* exeStructIn,
195  struct executionEntryStruct* exeEntryPtrsIn
196  )
197 {
198  exeStructIn->uSecTicks += exeStructIn->uSecPerSysTick;
199  if(exeStructIn->uSecTicks >= TIME_uS_PER_HR)
200  {
201  exeStructIn->uSecTicks = 0u;
202  exeStructIn->hourTicks++;
203  }
204 
205  // module systick execution area
207  EXP_SYSTICK,
208  exeEntryPtrsIn->sysTickListHead
209  );
210 
211 }
212 #endif
213 
console_menu.h
IMS: ccNOos, Declarations for straight C and C++
ExecuteLoop
int ExecuteLoop(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:173
linkedEntryPointStruct::dataPtr
struct computeModuleStruct * dataPtr
Definition: execution_system.h:117
EXP_SETUP
#define EXP_SETUP
Definition: execution_system.h:43
executionSystemStruct::uSecPerSysTick
UI_32 uSecPerSysTick
Definition: execution_system.h:60
EXP_HANDLER
#define EXP_HANDLER
Definition: execution_system.h:47
executionEntryStruct::loopListHead
struct linkedEntryPointStruct * loopListHead
Definition: execution_system.h:126
ModuleExeArea
void ModuleExeArea(UI_32 ExcpIndex, struct linkedEntryPointStruct *exeListHeadIn)
Definition: execution_system.c:47
executionEntryStruct
Definition: execution_system.h:124
linkedEntryPointStruct::nextPtr
struct linkedEntryPointStruct * nextPtr
Definition: execution_system.h:116
executionSystemStruct
Definition: execution_system.h:57
executionEntryStruct::exceptionListHead
struct linkedEntryPointStruct * exceptionListHead
Definition: execution_system.h:128
platformStart
void platformStart()
Definition: Platform_Arduino.h:114
linkedEntryPointStruct::entryPoint
int(* entryPoint)(struct computeModuleStruct *dataPtrIn)
Definition: execution_system.h:118
execution_system.h
IMS: ccNOos, Declarations for straight C and C++
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
executionSystemStruct::hourTicks
UI_32 hourTicks
Definition: execution_system.h:59
ExecuteSetup
int ExecuteSetup(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:150
executionEntryStruct::setupListHead
struct linkedEntryPointStruct * setupListHead
Definition: execution_system.h:125
ExecuteMain
int ExecuteMain(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:112
computeModuleStruct::exceptionFlags
UI_32 exceptionFlags
Definition: compute_module.h:34
linkedEntryPointStruct
Definition: execution_system.h:115
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
executionSystemStruct::uSecTicks
UI_32 uSecTicks
Definition: execution_system.h:58
executionEntryStruct::sysTickListHead
struct linkedEntryPointStruct * sysTickListHead
Definition: execution_system.h:127