ccNOos  v0.0.0
Build Portable Microcontroller Applications!
execution_system.h
Go to the documentation of this file.
1 /** \file execution_system.h
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  Declarations for straight C and 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 #ifndef __EXECUTION_SYSTEM__
28 #define __EXECUTION_SYSTEM__
29 
30 #include "version_config.h"
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 // Time Constants
34 #define TIME_us_PER_MIN (60000000u)
35 #define TIME_uS_PER_HR (3600000000u)
36 #define TIME_uS_PER_SEC (1000000u)
37 
38 #define TIME_SEC_PER_MIN (60u)
39 #define TIME_MIN_PER_HR (60u)
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 // Exception Flag Index
43 #define EXP_SETUP (0u)
44 #define EXP_LOOP (1u)
45 #define EXP_SYSTICK (2u)
46 #define EXP_PLATFORM (3u)
47 #define EXP_HANDLER (4u)
48 
49 // Platform Specific Configuration Functions
50 void platformSetup();
51 void platformStart();
52 void platformLoopDelay();
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 // Cross-Platform, Reusable, C/C++ Execution System Data Structure
57 {
58  UI_32 uSecTicks;
59  UI_32 hourTicks;
61 };
62 
63 // Execution System Data Structure Creation
65  UI_32 uSperTick
66  );
67 
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 // Cross-Platform, Reusable, C/C++ Module API Functions
71 UI_32 getuSecTicks();
72 UI_32 getHourTicks();
74 
75 #ifdef __cplusplus
76 #define _DeclareExeSys executionSystemClass exeSystem(uSEC_PER_CLOCK);
77 #define _ExeSys_ exeSystem.getExeDataPtr()->
78 #else
79 #define _DeclareExeSys struct executionSystemStruct exeSystem;
80 #define _ExeSys_ exeSystem.
81 #endif
82 
83 #define __ExeSysAPIFuncsTemplate \
84 _DeclareExeSys \
85 UI_32 getuSecTicks()\
86 {\
87  return _ExeSys_ uSecTicks;\
88 }\
89 UI_32 getHourTicks()\
90 {\
91  return _ExeSys_ hourTicks;\
92 }\
93 UI_32 getuSecPerSysTick()\
94 {\
95  return _ExeSys_ uSecPerSysTick;\
96 }
97 #define ExeSysAPIFuncsTemplate __ExeSysAPIFuncsTemplate
98 
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 // C Execution System Base Components - not compiled in C++ build
102 #ifndef __cplusplus
103 
104 
105 struct computeModuleStruct; // forward declaration
106 struct ioDeviceStruct; // forward declaration
107 
109 {
112 };
113 
115 {
118  int (*entryPoint)(
119  struct computeModuleStruct *dataPtrIn
120  );
121 };
122 
124 {
129 };
130 
131 void ModuleExeArea(
132  UI_32 ExcpIndex,
133  struct linkedEntryPointStruct* exeListHeadIn
134  );
135 
137  struct linkedEntryPointStruct* exeListHeadIn
138  );
139 
140 // Entry Points of the Execution System (module execution areas)
141 int ExecuteMain(
142  struct executionSystemStruct* exeStructIn,
143  struct executionEntryStruct* exeEntryPtrsIn
144  );
145 int ExecuteSetup(
146  struct executionSystemStruct* exeStructIn,
147  struct executionEntryStruct* exeEntryPtrsIn
148  );
149 int ExecuteLoop(
150  struct executionSystemStruct* exeStructIn,
151  struct executionEntryStruct* exeEntryPtrsIn
152  );
153 void ExecuteSysTick(
154  struct executionSystemStruct* exeStructIn,
155  struct executionEntryStruct* exeEntryPtrsIn
156  );
157 
158 // Application/Platform Configuration Function
160 
161 #endif // !__cplusplus
162 
163 
164 
165 
166 
167 #ifdef __cplusplus
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 // Cross-Platform, Reusable, C++ Only Execution System Classes
171 class IODeviceClass; // forward declaration
172 class computeModuleClass; // forward declaration
173 
174 class linkedIODeviceClass
175 {
176 private:
177  IODeviceClass* devPtr = nullptr;
178  linkedIODeviceClass* nextPtr = nullptr;
179 public:
180  linkedIODeviceClass(
181  IODeviceClass* devPtrIn,
182  linkedIODeviceClass* nextPtrIn
183  );
184  IODeviceClass* getDevPtr();
185  linkedIODeviceClass* getNextIOClassPtr();
186 };
187 
188 class linkedEntryPointClass
189 {
190 private:
191  computeModuleClass* modulePtr = nullptr;
192  linkedEntryPointClass* nextPtr = nullptr;
193 public:
194  linkedEntryPointClass(
195  computeModuleClass* modulePtrIn,
196  linkedEntryPointClass* nextPtrIn
197  );
198  computeModuleClass* getComputeModule();
199  linkedEntryPointClass* getNextEPClassPtr();
200 };
201 
202 class executionSystemClass // declaration of execution system class
203 {
204 protected:
205  struct executionSystemStruct data;
206  linkedEntryPointClass* setupListHead = nullptr;
207  linkedEntryPointClass* loopListHead = nullptr;
208  linkedEntryPointClass* sysTickListHead = nullptr;
209  linkedEntryPointClass* exceptionListHead = nullptr;
210  void ModuleExeArea(int EXE_AREA_INDEX);
211  void ModuleExceptionArea();
212 public:
213  executionSystemClass(
214  UI_32 uSperTick
215  );
216  virtual void ExecuteSetup();
217  virtual void ExecuteLoop();
218  int ExecuteMain();
219  virtual void ExecuteSysTick();
220  struct executionSystemStruct* getExeDataPtr() {return &data;}
221  void LinkTheListsHead(
222  linkedEntryPointClass* setupListHeadIn,
223  linkedEntryPointClass* loopListHeadIn,
224  linkedEntryPointClass* sysTickListHeadIn,
225  linkedEntryPointClass* exceptionListHeadIn
226  );
227 };
228 
229 
230 
231 
232 #endif // !__cplusplus
233 #endif // ! __EXECUTION_SYSTEM__
linkedEntryPointStruct::dataPtr
struct computeModuleStruct * dataPtr
Definition: execution_system.h:117
executionSystemStruct::uSecPerSysTick
UI_32 uSecPerSysTick
Definition: execution_system.h:60
linkedIODeviceStruct
Definition: execution_system.h:109
executionEntryStruct::loopListHead
struct linkedEntryPointStruct * loopListHead
Definition: execution_system.h:126
computeModuleStruct
Definition: compute_module.h:33
executionEntryStruct
Definition: execution_system.h:124
linkedEntryPointStruct::nextPtr
struct linkedEntryPointStruct * nextPtr
Definition: execution_system.h:116
ExecuteSetup
int ExecuteSetup(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:150
executionSystemStruct
Definition: execution_system.h:57
getHourTicks
UI_32 getHourTicks()
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
getuSecTicks
UI_32 getuSecTicks()
CreateExecutionSystemStruct
struct executionSystemStruct CreateExecutionSystemStruct(UI_32 uSperTick)
Definition: execution_system.c:31
ExecuteMain
int ExecuteMain(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:112
platformSetup
void platformSetup()
Definition: Platform_Arduino.h:66
platformLoopDelay
void platformLoopDelay()
Definition: Platform_Arduino.h:128
ExecuteSysTick
void ExecuteSysTick(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:193
version_config.h
IMS: ccNOos, Declarations for straight C and C++
getuSecPerSysTick
UI_32 getuSecPerSysTick()
ModuleExceptionArea
void ModuleExceptionArea(struct linkedEntryPointStruct *exeListHeadIn)
Definition: execution_system.c:80
executionSystemStruct::hourTicks
UI_32 hourTicks
Definition: execution_system.h:59
ExecuteLoop
int ExecuteLoop(struct executionSystemStruct *exeStructIn, struct executionEntryStruct *exeEntryPtrsIn)
Definition: execution_system.c:173
executionEntryStruct::setupListHead
struct linkedEntryPointStruct * setupListHead
Definition: execution_system.h:125
linkedEntryPointStruct
Definition: execution_system.h:115
linkedIODeviceStruct::nextPtr
struct linkedIODeviceStruct * nextPtr
Definition: execution_system.h:111
ModuleExeArea
void ModuleExeArea(UI_32 ExcpIndex, struct linkedEntryPointStruct *exeListHeadIn)
Definition: execution_system.c:47
linkedIODeviceStruct::devPtr
struct ioDeviceStruct * devPtr
Definition: execution_system.h:110
ioDeviceStruct
Definition: io_device.h:134
executionSystemStruct::uSecTicks
UI_32 uSecTicks
Definition: execution_system.h:58
applicationConfig
void applicationConfig()
executionEntryStruct::sysTickListHead
struct linkedEntryPointStruct * sysTickListHead
Definition: execution_system.h:127