ccNOos  v0.0.0
Build Portable Microcontroller Applications!
version_config.h
Go to the documentation of this file.
1 /** \file version_config.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 __VERSIONCONFIG__
28 #define __VERSIONCONFIG__
29 
30 #define ccNOos_MajorVer 0
31 #define ccNOos_MinorVer 0
32 #define ccNOos_BuildNumber 0
33 
34 #define ccNOos_DevString dev
35 #define ccNOos_VerDate 08JAN2021
36 
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 // Compiler Static Assert Macro Stack
40 // - Useful to enforce correct config at compile time
41 #define CTASTR2(pre,post) pre ## post
42 #define CTASTR(pre,post) CTASTR2(pre,post)
43 #define STATIC_ASSERT(cond,msg) \
44  typedef struct { int CTASTR(static_assertion_failed_,msg) : !!(cond); } \
45  CTASTR(static_assertion_failed_,__COUNTER__)
46 
47 //////////////////////////////////////////////////////////////////////////////
48 // Compiler Stringize Macros
49 // - Convert macro name or macro value to string constant in code
50 #define xstr(s) str(s)
51 #define str(s) #s
52 
53 ////////////////////////////////////////////////////////////////////////////
54 // Version Strings for Compile time and Run time
55 //
56 #ifdef ccNOos_ReleaseBuild
57 #define ccNOos_VersionNumber ccNOos_MajorVer.ccNOos_MinorVer.ccNOos_BuildNumber
58 #endif
59 #ifndef ccNOos_ReleaseBuild
60 #define ccNOos_VersionNumber ccNOos_MajorVer.ccNOos_MinorVer.ccNOos_BuildNumber-ccNOos_DevString
61 #endif
62 
63 const char* ccNOosccNOos_VerString();
65 
66 #define ccNOosVersionsTemplate \
67  const char* ccNOosccNOos_VerString()\
68  {\
69  return xstr(ccNOos_VersionNumber);\
70  }\
71  const char* ccNOosccNOos_VerDateString()\
72  {\
73  return xstr(ccNOos_VerDate);\
74  }
75 
76 // an eco system wide restriction on maximum buffer size...
77 #ifndef charBuffMax
78 #define charBuffMax 128
79 #endif
80 
81 /////////////////////////////////////////////////////////////////////////////
82 // COMPILER CONSTANTS
83 
84 /** \def RETURN_SUCCESS
85 * \brief Function Return Value for Success
86 */
87 #define RETURN_SUCCESS (0)
88 
89 /** \def RETURN_ERROR
90 * \brief Function Return Value for ERROR
91 */
92 #define RETURN_ERROR (-1)
93 
94 /////////////////////////////////////////////////////////////////////////////
95 // Compiler Configuration for Platform Selection
96 #ifdef PLATFORM_PSoC4
97  #define PLATFORM_NAME PSoC4
98  #define MAIN_C_NOos_Wsystick
99  #define INTSIZE32
100 #endif
101 #ifdef PLATFORM_QTCreatorC
102  #define PLATFORM_NAME QTCreatorC
103  #define MAIN_C_NOos_NOsystick
104  #define INTSIZE32
105 #endif
106 #ifdef PLATFORM_WIN32
107  #define PLATFORM_NAME Win32
108  #define MAIN_CPP_NOos_NOsystick
109  #define INTSIZE32
110 #endif
111 #ifdef PLATFORM_ARDUINO
112  #define PLATFORM_NAME Arduino
113  #define MAIN_CPP_NOos_NOsystick_Arduino
114  #define INTSIZE16
115 #endif
116 #ifdef PLATFORM_ccOS
117  #define PLATFORM_NAME ccOS
118  #define INTSIZE_STD
119 #endif
120 #ifdef PLATFORM_CUSTOM
121  #define PLATFORM_NAME Custom
122  #define PLATFORM_MAIN_CUSTOM
123 #endif
124 #ifndef PLATFORM_NAME
125  #error PLATFORM_NAME must be defined, see examples
126 #endif
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 // Fixed Width Integer Data Types
130 // - enforce correct config at compile time
131 #ifdef INTSIZE_STD // only used if compiling for ccOS layer
132 #include <stdint.h>
133 typedef uint8_t UI_8;
134 typedef uint16_t UI_16;
135 typedef uint32_t UI_32;
136 typedef uint64_t UI_64;
137 typedef int8_t I_8;
138 typedef int16_t I_16;
139 typedef int32_t I_32;
140 typedef int64_t I_64;
141 #define INTSIZE_FIXED
142 #define __USINGCONSOLEMENU
143 #define __USINGFLOATPRINTF
144 #endif
145 #ifdef INTSIZE8
146 typedef unsigned int UI_8;
147 typedef unsigned long UI_16;
148 typedef unsigned long long UI_32;
149 //typedef unsigned long long UI_64;
150 #define INTSIZE_FIXED
151 #endif
152 #ifdef INTSIZE16
153 typedef unsigned char UI_8;
154 typedef unsigned int UI_16;
155 typedef unsigned long UI_32;
156 typedef unsigned long long UI_64;
157 typedef char I_8;
158 typedef int I_16;
159 typedef long I_32;
160 typedef long long I_64;
161 #define INTSIZE_FIXED
162 #endif
163 #ifdef INTSIZE32
164 typedef unsigned char UI_8;
165 typedef unsigned short UI_16;
166 typedef unsigned int UI_32;
167 typedef unsigned long UI_64;
168 typedef char I_8;
169 typedef short I_16;
170 typedef int I_32;
171 typedef long I_64;
172 #define INTSIZE_FIXED
173 #endif
174 #ifndef INTSIZE_FIXED
175  #error INTSIZEx must be defined as INTSIZE8, INTSIZE16, or INTSIZE32 bits in type
176 #endif
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 // Static Assert Calls
180 // - for Fixed Width Correctness
181 STATIC_ASSERT(sizeof(UI_8)==1, UI_8_must_be_8_bits);
182 STATIC_ASSERT(sizeof(UI_16)==2, UI_16_must_be_16_bits);
183 STATIC_ASSERT(sizeof(UI_32)==4, UI_32_must_be_32_bits);
184 STATIC_ASSERT(sizeof(I_8)==1, I_8_must_be_8_bits);
185 STATIC_ASSERT(sizeof(I_16)==2, I_16_must_be_16_bits);
186 STATIC_ASSERT(sizeof(I_32)==4, I_32_must_be_32_bits);
187 
188 ///////////////////////////////////////////////////////////////////////////////
189 // True / False macros for UI_8 data type in boolean operatoins
190 #define ui8FALSE (0u)
191 #define ui8TRUE (1u)
192 
193 /////////////////////////////////////////////////////////////////////////////
194 // Compiler Configuration for nullptr support
195 #ifdef REDEFINE_NULLPTR
196  #warning redefining nullptr !!!
197  #define nullptr NULL
198 #else
199  #ifndef __cplusplus
200  #define nullptr (0u)
201  #endif
202 #endif
203 
204 /////////////////////////////////////////////////////////////////////////////
205 // Compiler Configuration for Execution System Calls and Main Entry Points
206 #ifdef MAIN_C_NOos_Wsystick
207  #define PLATFORM_MAIN
208 #endif
209 #ifdef MAIN_CPP_NOos_NOsystick
210  #define PLATFORM_MAIN
211 #endif
212 #ifdef MAIN_CPP_NOos_NOsystick_Arduino
213 #define PLATFORM_MAIN
214 #endif
215 #ifdef MAIN_C_NOos_NOsystick
216  #define PLATFORM_MAIN
217 #endif
218 #ifdef PLATFORM_ccOS
219  #define PLATFORM_MAIN
220 #endif
221 #ifdef PLATFORM_MAIN_CUSTOM
222  #define PLATFORM_MAIN
223 #endif
224 #ifndef PLATFORM_MAIN
225  #error PLATFORM_MAIN must be defined, see examples
226 #endif
227 
228 //////////////////////////////////////////////////////////////////////////////
229 // Template Macros to enforce Adherence to ccNOos concepts
230 
231 // Naming Conventions Driven by Unique Module Name
232 // formatted as an acceptable c language variable name
233 
234 // Name of Module Structure Data Type
235 #define __MODstructTYPEname(mNAME) mNAME##Struct
236 #define MODstructTYPEname(mNAME) __MODstructTYPEname(mNAME)
237 
238 // Name of Module Instance Data Variable
239 #define __MODdataINST(mNAME) mNAME##Data
240 #define MODdataINST(mNAME) __MODdataINST(mNAME)
241 
242 // Name of Module Instance Data Pointer within Function Code
243 #define __MODdataPTR(mNAME) mNAME##DataPtrIn
244 #define MODdataPTR(mNAME) __MODdataPTR(mNAME)
245 
246 // Name of Module Setup Function
247 #define __MODsetup(mNAME) setup_##mNAME
248 #define MODsetup(mNAME) __MODsetup(mNAME)
249 
250 // Name of Module Loop Function
251 #define __MODloop(mNAME) loop_##mNAME
252 #define MODloop(mNAME) __MODloop(mNAME)
253 
254 // Name of Module Systick Function
255 #define __MODsystick(mNAME) systick_##mNAME
256 #define MODsystick(mNAME) __MODsystick(mNAME)
257 
258 // Name of Module Print Menu Function
259 #define __MODprintMENU(mNAME) printM_##mNAME
260 #define MODprintMENU(mNAME) __MODprintMENU(mNAME)
261 
262 // Name of Module Parse Input Function
263 #define __MODparseINPUT(mNAME) parseI_##mNAME
264 #define MODparseINPUT(mNAME) __MODparseINPUT(mNAME)
265 
266 // Name of Module Data Structure Initialization Function
267 #define __MODstructCREATE(mNAME) Create##mNAME##Struct
268 #define MODstructCREATE(mNAME) __MODstructCREATE(mNAME)
269 
270 
271 // Declaration Code Snippets using Naming Conventions
272 // formatted as an acceptable c
273 
274 
275 // Declaration Code - Module Data Type - Structure Definition
276 #define __MODdeclareSTRUCT(mNAME) struct __MODstructTYPEname(mNAME)
277 #define MODdeclareSTRUCT(mNAME) __MODdeclareSTRUCT(mNAME)
278 
279 // Declaration Code - Module Data Structure 1st element - must be compute module
280 #define COMPMODFIRST struct computeModuleStruct compMod
281 
282 // Declare Inputs List - Module Functions operating on Module Data Pointer
283 #define __MODdeclarePTRIN(mNAME) struct __MODstructTYPEname(mNAME)* __MODdataPTR(mNAME)
284 #define MODdeclarePTRIN(mNAME) __MODdeclarePTRIN(mNAME)
285 
286 // Declaration Code - Module Data Structure in C
287 #define __MODdeclareDATA(mNAME) struct __MODstructTYPEname(mNAME) __MODdataINST(mNAME)
288 #define MODdeclareDATA(mNAME) __MODdeclareDATA(mNAME)
289 
290 // Declaration Code - Module Create Function Prototype
291 #define __MODdeclareCREATE(mNAME) __MODdeclareSTRUCT(mNAME) __MODstructCREATE(mNAME)
292 #define MODdeclareCREATE(mNAME) __MODdeclareCREATE(mNAME)
293 
294 // Declaration Code - Module Setup Function Prototype
295 #define __MODdeclareSETUP(mNAME) int __MODsetup(mNAME) ( struct computeModuleStruct* compModPtrIn )
296 #define MODdeclareSETUP(mNAME) __MODdeclareSETUP(mNAME)
297 
298 // Declaration Code - Module Loop Function Prototype
299 #define __MODdeclareLOOP(mNAME) int __MODloop(mNAME) ( struct computeModuleStruct* compModPtrIn )
300 #define MODdeclareLOOP(mNAME) __MODdeclareLOOP(mNAME)
301 
302 // Declaration Code - Module Print Menu Function Prototype
303 #define __MODdeclarePRINTm(mNAME) void __MODprintMENU(mNAME) ( struct computeModuleStruct* compModPtrIn, struct uiStruct* uiStructPtrIn )
304 #define MODdeclarePRINTm(mNAME) __MODdeclarePRINTm(mNAME)
305 
306 // Declaration Code - Module Parse Menu Function Prototype
307 #define __MODdeclarePARSEi(mNAME) void __MODparseINPUT(mNAME) ( struct computeModuleStruct* compModPtrIn, struct uiStruct* uiStructPtrIn )
308 #define MODdeclarePARSEi(mNAME) __MODdeclarePARSEi(mNAME)
309 
310 // Declaration Code - Module Systick Function Prototype
311 #define __MODdeclareSYSTICK(mNAME) void __MODsystick(mNAME) ( struct computeModuleStruct* compModPtrIn )
312 #define MODdeclareSYSTICK(mNAME) __MODdeclareSYSTICK(mNAME)
313 
314 // Code Snippets to Simplify Common Tasks
315 //
316 
317 
318 // Snippet Code - Create and Cast Pointer to Module Data and Ensure not null
319 #define __MODDATAPTR_RETURN(mNAME) \
320  __MODdeclarePTRIN(mNAME) = ( ( __MODdeclareSTRUCT(mNAME)* )(compModPtrIn));\
321  if (__MODdataPTR(mNAME) == nullptr)\
322  return;
323 #define MODDATAPTR_RETURN(mNAME) __MODDATAPTR_RETURN(mNAME)
324 
325 
326 // Snippet Code - Create and Cast Pointer to Module Data and Ensure not null
327 #define __MODDATAPTR_ERROR_RETURN(mNAME) \
328  __MODdeclarePTRIN(mNAME) = ( ( __MODdeclareSTRUCT(mNAME)* )(compModPtrIn));\
329  if (__MODdataPTR(mNAME) == nullptr)\
330  return RETURN_ERROR;
331 #define MODDATAPTR_ERROR_RETURN(mNAME) __MODDATAPTR_ERROR_RETURN(mNAME)
332 
333 // Snippet Code - Check for module errors
334 #define __IF_MODULE_ERROR(mNAME) if(__MODdataPTR(mNAME)->compMod.exceptionFlags != 0u)
335 #define IF_MODULE_ERROR( mNAME ) __IF_MODULE_ERROR( mNAME )
336 
337 // Snippet Code - Clear module errors from within Check for module errors conditional block
338 #define __CLEAR_MODULE_ERRORS(mNAME) __MODdataPTR(mNAME)->compMod.exceptionFlags = 0u
339 #define CLEAR_MODULE_ERRORS(mNAME) __CLEAR_MODULE_ERRORS(mNAME)
340 
341 // Main Function Template - C with an OS Linux or Windows or Similar non-real-time
342 #define __C_NOos_MAINnSYSTICK_TEMPLATE ccNOosVersionsTemplate \
343 int main()\
344 {\
345  applicationConfig();\
346  return ExecuteMain(&exeSystem, &exeEntryPoints);\
347 }\
348 void SysTickISRCallback(void);\
349 void SysTickISRCallback(void)\
350 {\
351  ExecuteSysTick(&exeSystem, &exeEntryPoints);\
352 }
353 #define C_NOos_MAINnSYSTICK_TEMPLATE __C_NOos_MAINnSYSTICK_TEMPLATE
354 
355 // Main Function Template - C with an OS Linux or Windows or Similar non-real-time
356 #define __C_OS_MAIN_TEMPLATE ccNOosVersionsTemplate \
357 int main(int argc, char** argv)\
358 {\
359  clock_t tlast = clock();\
360  clock_t tnow, tdelta;\
361  UI_32* uSecTicksPtr = &exeSystem.uSecTicks;\
362  UI_32* hourTicksPtr = &exeSystem.hourTicks;\
363  applicationConfig();\
364  ExecuteSetup(&exeSystem, &exeEntryPoints);\
365  for (;;)\
366  {\
367  tnow = clock();\
368  if (tnow >= tlast)\
369  tdelta = tnow - tlast;\
370  else\
371  tdelta = tnow + (LONG_MAX - tlast);\
372  tlast = tnow;\
373  (*uSecTicksPtr) += tdelta * uSEC_PER_CLOCK;\
374  if ((*uSecTicksPtr) >= TIME_uS_PER_HR)\
375  {\
376  (*uSecTicksPtr) = 0u;\
377  (*hourTicksPtr)++;\
378  }\
379  ExecuteLoop(&exeSystem, &exeEntryPoints);\
380  }\
381  return RETURN_ERROR;\
382 }
383 #define C_OS_MAIN_TEMPLATE __C_OS_MAIN_TEMPLATE
384 
385 //
386 // C++ specific macro code templates
387 #ifdef __cplusplus
388 
389 // Name of Platform Specific Application
390 #define __PLATFORM_APP_NAME(PLATNAME) PLATNAME##_Application
391 #define PLATFORM_APP_NAME(PLATNAME) __PLATFORM_APP_NAME(PLATNAME)
392 
393 // Name of Module Class Type
394 #define __MODCLASS_NAME(MODNAME) MODNAME##_class
395 #define MODCLASS_NAME(MODNAME) __MODCLASS_NAME(MODNAME)
396 
397 // Declaration Code - Module Setup Inline wrapper
398 #define __MODCLASS_SETUP_INLINE(mNAME) int mod_setup(){return __MODsetup(mNAME)((struct computeModuleStruct*)(&__MODdataINST(mNAME)));}
399 #define MODCLASS_SETUP_INLINE(mNAME) __MODCLASS_SETUP_INLINE(mNAME)
400 
401 // Declaration Code - Module Loop Inline wrapper
402 #define __MODCLASS_LOOP_INLINE(mNAME) int mod_loop(){return __MODloop(mNAME)((struct computeModuleStruct*)(&__MODdataINST(mNAME)));}
403 #define MODCLASS_LOOP_INLINE(mNAME) __MODCLASS_LOOP_INLINE(mNAME)
404 
405 // Declaration Code - Module SysTick Inline wrapper
406 #define __MODCLASS_SYSTICK_INLINE(mNAME) void mod_systick(){return __MODsystick(mNAME)((struct computeModuleStruct*)(&__MODdataINST(mNAME)));}
407 #define MODCLASS_SYSTICK_INLINE(mNAME) __MODCLASS_SYSTICK_INLINE(mNAME)
408 
409 // Declaration Code - Module Exception Handler Inline wrapper
410 #define __MODCLASS_ExcpHndlr_INLINE(mNAME) int mod_excphandler(){return __MODsetup(mNAME)((struct computeModuleStruct*)(&__MODdataINST(mNAME)));}
411 #define MODCLASS_ExcpHndlr_INLINE(mNAME) __MODCLASS_ExcpHndlr_INLINE(mNAME)
412 
413 // Declaration Code - Module Setup Inline wrapper
414 #define __MODULE_CONSTRUCT_DEFINE(mNAME) MODCLASS_NAME(mNAME)::MODCLASS_CONSTRUCTOR_PROTO(mNAME): computeModuleClass( & __MODdataINST(mNAME).compMod)
415 #define MODULE_CONSTRUCT_DEFINE(mNAME) __MODULE_CONSTRUCT_DEFINE(mNAME)
416 
417 // Declaration Code - Application Instance Declaration
418 #define __PLATFORM_APP_CPPTEMPLATE(PLATNAME) __PLATFORM_APP_NAME(PLATNAME) theApplicationExample;
419 #define PLATFORM_APP_CPPTEMPLATE(PLATNAME) __PLATFORM_APP_CPPTEMPLATE(PLATNAME)
420 
421 // Main Function Template - CPP with an OS Linux or Windows or Similar non-real-time
422 #define __CPP_OS_MAIN_TEMPLATE ccNOosVersionsTemplate \
423 int main(int argc, char** argv)\
424 {\
425  clock_t tlast = clock();\
426  clock_t tnow, tdelta;\
427  UI_32* uSecTicksPtr = &exeSystem.getExeDataPtr()->uSecTicks;\
428  UI_32* hourTicksPtr = &exeSystem.getExeDataPtr()->hourTicks;\
429  exeSystem.ExecuteSetup();\
430  for (;;)\
431  {\
432  tnow = clock();\
433  if (tnow >= tlast)\
434  tdelta = tnow - tlast;\
435  else\
436  tdelta = tnow + (LONG_MAX - tlast);\
437  tlast = tnow;\
438  (*uSecTicksPtr) += tdelta * uSEC_PER_CLOCK;\
439  if ((*uSecTicksPtr) >= TIME_uS_PER_HR)\
440  {\
441  (*uSecTicksPtr) = 0u;\
442  (*hourTicksPtr)++;\
443  }\
444  exeSystem.ExecuteLoop();\
445  }\
446  return RETURN_ERROR;\
447 }
448 #define CPP_OS_MAIN_TEMPLATE __CPP_OS_MAIN_TEMPLATE
449 
450 #define __CPP_MAIN_TEMPLATE_ARDUINO ccNOosVersionsTemplate \
451 unsigned long tlast;\
452 unsigned long tnow, tdelta;\
453 uint32_t* uSecTicksPtr;\
454 uint32_t* hourTicksPtr;\
455 void setup() {\
456  tlast = millis();\
457  tnow, tdelta;\
458  uSecTicksPtr = &exeSystem.getExeDataPtr()->uSecTicks;\
459  hourTicksPtr = &exeSystem.getExeDataPtr()->hourTicks;\
460  exeSystem.ExecuteSetup();\
461 }\
462 \
463 void loop()\
464 {\
465  tnow = millis();\
466  if (tnow >= tlast)\
467  tdelta = tnow - tlast;\
468  else\
469  tdelta = tnow + (0xffffffff - tlast);\
470  tlast = tnow;\
471 \
472  (*uSecTicksPtr) += tdelta * uSEC_PER_CLOCK;\
473  if ((*uSecTicksPtr) >= TIME_uS_PER_HR)\
474  {\
475  (*uSecTicksPtr) = 0u;\
476  (*hourTicksPtr)++;\
477  }\
478 \
479  exeSystem.ExecuteLoop();\
480 \
481 }
482 #define CPP_MAIN_TEMPLATE_ARDUINO __CPP_MAIN_TEMPLATE_ARDUINO
483 
484 #endif // !__cplusplus
485 #endif // !__VERSIONCONFIG__
ccNOosccNOos_VerString
const char * ccNOosccNOos_VerString()
ccNOosccNOos_VerDateString
const char * ccNOosccNOos_VerDateString()
STATIC_ASSERT
#define STATIC_ASSERT(cond, msg)
Definition: version_config.h:43