├── .gitignore ├── LICENSE ├── README.rst ├── autosar └── inc │ ├── ComStack_Types.h │ ├── Platform.h │ ├── Platform_Types.h │ ├── Rte.h │ └── Std_Types.h ├── cutest ├── CuTest.c ├── CuTest.h └── license.txt ├── os ├── inc │ ├── os.h │ ├── os_core.h │ ├── os_task.h │ └── os_types.h ├── src │ ├── os_core.c │ └── os_task.c └── test │ ├── testsuite_os_core.c │ └── testsuite_os_task.c ├── projects └── eclipse │ ├── amber_runtime_test │ ├── .cproject │ ├── .gitignore │ ├── .project │ ├── cfg │ │ ├── RteApi.c │ │ ├── RteApi.h │ │ ├── RteTask.c │ │ ├── os_event_cfg.h │ │ ├── os_task_cfg.c │ │ └── os_task_cfg.h │ └── main.c │ ├── amber_simulation_test │ ├── .cproject │ ├── .gitignore │ ├── .project │ ├── cfg │ │ ├── RteTask.c │ │ ├── os_event_cfg.h │ │ ├── os_task_cfg.c │ │ └── os_task_cfg.h │ └── main.c │ └── amber_unit_test │ ├── .cproject │ ├── .gitignore │ ├── .project │ ├── cfg │ ├── adt_ringbuf_cfg.h │ ├── os_task_cfg.c │ └── os_task_cfg.h │ └── test_main.c └── util ├── inc ├── priority_queue.h └── systime.h └── src ├── priority_queue.c └── systime_wl.c /.gitignore: -------------------------------------------------------------------------------- 1 | doc/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Conny Gustafsson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Amber OS 2 | ========= 3 | 4 | Amber OS simulates the runtime behavior of an AUTOSAR OS under Windows and Linux. 5 | 6 | This project is part of a bigger initiative that involves several projects related to AUTOSAR. 7 | 8 | The goal is to make it possible to develop fully functional AUTOSAR software components (SWCs) and test them out 9 | on Linux or Windows machines by placing the SWCs in sort of virtual container. 10 | 11 | The AUTOSAR virtual container (including its SWCs) can later be deployed onto an embedded Linux system where the SWCs will run as it would 12 | on a traditional AUTOSAR system. Vehicle signal communication is done using the `APX `_ solution. 13 | 14 | This project 15 | ------------ 16 | 17 | This project contains the OS simulation layer that runs on top of Linux or Windows. It currently just contains a scheduler. 18 | 19 | Related projects 20 | ---------------- 21 | 22 | - `autosar `_: A set of python3 modules for creating and working with AUTOSAR SWCs. 23 | - `c-apx `_: APX is used as AUTOSAR Com module. 24 | - `py-apx `_: Python3 module that contains the toolchain for APX. 25 | - `autosar-demo `_: A demo project that shows how all pieces fit together. 26 | 27 | Helper projects 28 | --------------- 29 | 30 | - `adt `_: Abstract data structures for the C language. 31 | - `dtl_type `_: Dynamic language data types for C. 32 | - `cfile `_: A C code generator written in Python3. 33 | - `msocket `_: Event-driven socket wrapper for Linux and Windows. -------------------------------------------------------------------------------- /autosar/inc/ComStack_Types.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file ComStack_Types.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-20 5 | * \brief ComStack Types 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef COMSTACK_TYPES_H 27 | #define COMSTACK_TYPES_H 28 | 29 | #include "Std_Types.h" 30 | 31 | typedef uint8 PduIdType; 32 | typedef uint32 PduLengthType; 33 | 34 | typedef struct { 35 | uint8* SduDataPtr; 36 | PduLengthType SduLength; 37 | }PduInfoType; 38 | 39 | #endif /* COMSTACK_TYPES_H */ 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /autosar/inc/Platform.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORM_H 2 | #define PLATFORM_H 3 | 4 | #endif //PLATFORM_H 5 | -------------------------------------------------------------------------------- /autosar/inc/Platform_Types.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file Platform_Types.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-20 5 | * \brief Platform Types for x86-based systems 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | 27 | #ifndef PLATFORM_TYPES_H 28 | #define PLATFORM_TYPES_H 29 | 30 | #define CPU_TYPE_8 8 31 | #define CPU_TYPE_16 16 32 | #define CPU_TYPE_32 32 33 | 34 | #define MSB_FIRST 0 35 | #define LSB_FIRST 1 36 | 37 | #define HIGH_BYTE_FIRST 0 38 | #define LOW_BYTE_FIRST 1 39 | 40 | #define CPU_TYPE CPU_TYPE_32 41 | #define CPU_BIT_ORDER LSB_FIRST 42 | #define CPU_BYTE_ORDER LOW_BYTE_FIRST 43 | 44 | #ifndef TRUE 45 | #define TRUE ((boolean)1) 46 | #endif 47 | #ifndef FALSE 48 | #define FALSE ((boolean)0) 49 | #endif 50 | 51 | typedef unsigned char boolean; /* TRUE..FALSE */ 52 | typedef signed char sint8; /* -128..127 */ 53 | typedef unsigned char uint8; /* 0..255 */ 54 | typedef signed short sint16; /* -32768..32767 */ 55 | typedef unsigned short uint16; /* 0..65535 */ 56 | typedef signed int sint32; /* -2147483648..2147483647 */ 57 | typedef unsigned int uint32; /* 0..4294967295 */ 58 | 59 | typedef signed char sint8_least; 60 | typedef unsigned char uint8_least; 61 | typedef signed short sint16_least; 62 | typedef unsigned short uint16_least; 63 | typedef signed int sint32_least; 64 | typedef unsigned int uint32_least; 65 | 66 | typedef float float32; 67 | typedef double float64; 68 | 69 | #endif /* PLATFORM_TYPES_H */ 70 | -------------------------------------------------------------------------------- /autosar/inc/Rte.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file Rte.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-20 5 | * \brief RTE Type definitions 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | 27 | #ifndef _RTE_H 28 | #define _RTE_H 29 | #include "Std_Types.h" 30 | 31 | /* common errors */ 32 | #define RTE_E_OK ((Std_ReturnType) 0) 33 | #define RTE_E_INVALID ((Std_ReturnType) 1) 34 | 35 | /* overlayed errors */ 36 | #define RTE_E_LOST_DATA ((Std_ReturnType) 64) 37 | #define RTE_E_MAX_AGE_EXCEEDED ((Std_ReturnType) 64) 38 | 39 | /* infrastructure errors */ 40 | #define RTE_E_TIMEOUT ((Std_ReturnType)129) 41 | #define RTE_E_LIMIT ((Std_ReturnType)130) 42 | #define RTE_E_NO_DATA ((Std_ReturnType)131) 43 | 44 | #endif /* _RTE_H */ 45 | -------------------------------------------------------------------------------- /autosar/inc/Std_Types.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file Std_Types.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-20 5 | * \brief Standard type definitions 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | 27 | #ifndef STD_TYPES_H 28 | #define STD_TYPES_H 29 | 30 | #include "Platform_Types.h" 31 | 32 | #define STD_HIGH 1U /* Voltage level 5V or 3.3V */ 33 | #define STD_LOW 0U /* Voltage level 0V */ 34 | 35 | #define STD_ACTIVE 1U /* Logical level active */ 36 | #define STD_IDLE 0U /* Logical level idle */ 37 | 38 | #define STD_ON 1U 39 | #define STD_OFF 0U 40 | 41 | #ifndef STATUSTYPEDEFINED 42 | #define STATUSTYPEDEFINED 43 | #define E_OK 0U 44 | #endif 45 | #define E_NOT_OK 1u 46 | 47 | typedef uint8 Std_ReturnType; 48 | 49 | #endif /* STD_TYPES_H */ 50 | -------------------------------------------------------------------------------- /cutest/CuTest.c: -------------------------------------------------------------------------------- 1 | /** 2 | * cogu 2017-02-19: This is a slighty modified version of CuTest.c v1.5 (http://cutest.sourceforge.net) 3 | * I have fixed a memory leak in the framework as well as adding test macro for unsigned integer equality (CuAssertUIntEquals). 4 | * 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "CuTest.h" 14 | 15 | /*-------------------------------------------------------------------------* 16 | * CuStr 17 | *-------------------------------------------------------------------------*/ 18 | 19 | char* CuStrAlloc(int size) 20 | { 21 | char* newStr = (char*) malloc( sizeof(char) * ((unsigned int) size) ); 22 | return newStr; 23 | } 24 | 25 | char* CuStrCopy(const char* old) 26 | { 27 | int len = (int) strlen(old); 28 | char* newStr = CuStrAlloc(len + 1); 29 | strcpy(newStr, old); 30 | return newStr; 31 | } 32 | 33 | /*-------------------------------------------------------------------------* 34 | * CuString 35 | *-------------------------------------------------------------------------*/ 36 | 37 | void CuStringInit(CuString* str) 38 | { 39 | str->length = 0; 40 | str->size = STRING_MAX; 41 | str->buffer = (char*) malloc(sizeof(char) * ((unsigned int)str->size)); 42 | str->buffer[0] = '\0'; 43 | } 44 | 45 | CuString* CuStringNew(void) 46 | { 47 | CuString* str = (CuString*) malloc(sizeof(CuString)); 48 | str->length = 0; 49 | str->size = STRING_MAX; 50 | str->buffer = (char*) malloc(sizeof(char) * ((unsigned int)str->size)); 51 | str->buffer[0] = '\0'; 52 | return str; 53 | } 54 | 55 | void CuStringDelete(CuString *str) 56 | { 57 | if (!str) return; 58 | free(str->buffer); 59 | free(str); 60 | } 61 | 62 | void CuStringResize(CuString* str, int newSize) 63 | { 64 | str->buffer = (char*) realloc(str->buffer, sizeof(char) * ((unsigned int)newSize)); 65 | str->size = newSize; 66 | } 67 | 68 | void CuStringAppend(CuString* str, const char* text) 69 | { 70 | int length; 71 | 72 | if (text == NULL) { 73 | text = "NULL"; 74 | } 75 | 76 | length = (int) strlen(text); 77 | if (str->length + length + 1 >= str->size) 78 | CuStringResize(str, str->length + length + 1 + STRING_INC); 79 | str->length += length; 80 | strcat(str->buffer, text); 81 | } 82 | 83 | void CuStringAppendChar(CuString* str, char ch) 84 | { 85 | char text[2]; 86 | text[0] = ch; 87 | text[1] = '\0'; 88 | CuStringAppend(str, text); 89 | } 90 | 91 | void CuStringAppendFormat(CuString* str, const char* format, ...) 92 | { 93 | va_list argp; 94 | char buf[HUGE_STRING_LEN]; 95 | va_start(argp, format); 96 | vsprintf(buf, format, argp); 97 | va_end(argp); 98 | CuStringAppend(str, buf); 99 | } 100 | 101 | void CuStringInsert(CuString* str, const char* text, int pos) 102 | { 103 | int length = (int) strlen(text); 104 | if (pos > str->length) 105 | pos = str->length; 106 | if (str->length + length + 1 >= str->size) 107 | CuStringResize(str, str->length + length + 1 + STRING_INC); 108 | memmove(str->buffer + pos + length, str->buffer + pos, (size_t) ((str->length - pos) + 1)); 109 | str->length += length; 110 | memcpy(str->buffer + pos, text, (size_t) length); 111 | } 112 | 113 | /*-------------------------------------------------------------------------* 114 | * CuTest 115 | *-------------------------------------------------------------------------*/ 116 | 117 | void CuTestInit(CuTest* t, const char* name, TestFunction function) 118 | { 119 | t->name = CuStrCopy(name); 120 | t->failed = 0; 121 | t->ran = 0; 122 | t->message = NULL; 123 | t->function = function; 124 | t->jumpBuf = NULL; 125 | } 126 | 127 | CuTest* CuTestNew(const char* name, TestFunction function) 128 | { 129 | CuTest* tc = CU_ALLOC(CuTest); 130 | CuTestInit(tc, name, function); 131 | return tc; 132 | } 133 | 134 | void CuTestDelete(CuTest *t) 135 | { 136 | if (!t) return; 137 | free(t->name); 138 | free(t); 139 | } 140 | 141 | void CuTestRun(CuTest* tc) 142 | { 143 | jmp_buf buf; 144 | tc->jumpBuf = &buf; 145 | if (setjmp(buf) == 0) 146 | { 147 | tc->ran = 1; 148 | (tc->function)(tc); 149 | } 150 | tc->jumpBuf = 0; 151 | } 152 | 153 | static void CuFailInternal(CuTest* tc, const char* file, int line, CuString* string) 154 | { 155 | char buf[HUGE_STRING_LEN]; 156 | 157 | sprintf(buf, "%s:%d: ", file, line); 158 | CuStringInsert(string, buf, 0); 159 | 160 | tc->failed = 1; 161 | tc->message = string->buffer; 162 | if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0); 163 | } 164 | 165 | void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message) 166 | { 167 | CuString string; 168 | 169 | CuStringInit(&string); 170 | if (message2 != NULL) 171 | { 172 | CuStringAppend(&string, message2); 173 | CuStringAppend(&string, ": "); 174 | } 175 | CuStringAppend(&string, message); 176 | CuFailInternal(tc, file, line, &string); 177 | } 178 | 179 | void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition) 180 | { 181 | if (condition) return; 182 | CuFail_Line(tc, file, line, NULL, message); 183 | } 184 | 185 | void CuAssertStrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, 186 | const char* expected, const char* actual) 187 | { 188 | CuString string; 189 | if ((expected == NULL && actual == NULL) || 190 | (expected != NULL && actual != NULL && 191 | strcmp(expected, actual) == 0)) 192 | { 193 | return; 194 | } 195 | 196 | CuStringInit(&string); 197 | if (message != NULL) 198 | { 199 | CuStringAppend(&string, message); 200 | CuStringAppend(&string, ": "); 201 | } 202 | CuStringAppend(&string, "expected <"); 203 | CuStringAppend(&string, expected); 204 | CuStringAppend(&string, "> but was <"); 205 | CuStringAppend(&string, actual); 206 | CuStringAppend(&string, ">"); 207 | CuFailInternal(tc, file, line, &string); 208 | } 209 | 210 | void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, 211 | int expected, int actual) 212 | { 213 | char buf[STRING_MAX]; 214 | if (expected == actual) return; 215 | sprintf(buf, "expected <%d> but was <%d>", expected, actual); 216 | CuFail_Line(tc, file, line, message, buf); 217 | } 218 | 219 | void CuAssertUIntEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, 220 | unsigned int expected, unsigned int actual) 221 | { 222 | char buf[STRING_MAX]; 223 | if (expected == actual) return; 224 | sprintf(buf, "expected <%u> but was <%u>", expected, actual); 225 | CuFail_Line(tc, file, line, message, buf); 226 | } 227 | 228 | 229 | void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, 230 | double expected, double actual, double delta) 231 | { 232 | char buf[STRING_MAX]; 233 | if (fabs(expected - actual) <= delta) return; 234 | sprintf(buf, "expected <%f> but was <%f>", expected, actual); 235 | 236 | CuFail_Line(tc, file, line, message, buf); 237 | } 238 | 239 | void CuAssertPtrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, 240 | void* expected, void* actual) 241 | { 242 | char buf[STRING_MAX]; 243 | if (expected == actual) return; 244 | sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual); 245 | CuFail_Line(tc, file, line, message, buf); 246 | } 247 | 248 | /* CG 2018-08-08: Added function */ 249 | void CuAssertConstPtrEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message, 250 | const void* expected, const void* actual) 251 | { 252 | char buf[STRING_MAX]; 253 | if (expected == actual) return; 254 | sprintf(buf, "expected pointer <0x%p> but was <0x%p>", expected, actual); 255 | CuFail_Line(tc, file, line, message, buf); 256 | } 257 | 258 | 259 | /*-------------------------------------------------------------------------* 260 | * CuSuite 261 | *-------------------------------------------------------------------------*/ 262 | 263 | void CuSuiteInit(CuSuite* testSuite) 264 | { 265 | testSuite->count = 0; 266 | testSuite->failCount = 0; 267 | memset(testSuite->list, 0, sizeof(testSuite->list)); 268 | } 269 | 270 | CuSuite* CuSuiteNew(void) 271 | { 272 | CuSuite* testSuite = CU_ALLOC(CuSuite); 273 | CuSuiteInit(testSuite); 274 | return testSuite; 275 | } 276 | 277 | void CuSuiteDelete(CuSuite *testSuite) 278 | { 279 | unsigned int n; 280 | for (n=0; n < MAX_TEST_CASES; n++) 281 | { 282 | if (testSuite->list[n]) 283 | { 284 | CuTestDelete(testSuite->list[n]); 285 | } 286 | } 287 | free(testSuite); 288 | 289 | } 290 | 291 | void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase) 292 | { 293 | assert(testSuite->count < MAX_TEST_CASES); 294 | testSuite->list[testSuite->count] = testCase; 295 | testSuite->count++; 296 | } 297 | 298 | void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2) 299 | { 300 | int i; 301 | for (i = 0 ; i < testSuite2->count ; ++i) 302 | { 303 | CuTest* testCase = testSuite2->list[i]; 304 | CuSuiteAdd(testSuite, testCase); 305 | } 306 | free(testSuite2); ////cogu 2013-08-06: Added free in order to prevent memory leak 307 | } 308 | 309 | void CuSuiteRun(CuSuite* testSuite) 310 | { 311 | int i; 312 | for (i = 0 ; i < testSuite->count ; ++i) 313 | { 314 | CuTest* testCase = testSuite->list[i]; 315 | CuTestRun(testCase); 316 | if (testCase->failed) { testSuite->failCount += 1; } 317 | } 318 | } 319 | 320 | void CuSuiteSummary(CuSuite* testSuite, CuString* summary) 321 | { 322 | int i; 323 | for (i = 0 ; i < testSuite->count ; ++i) 324 | { 325 | CuTest* testCase = testSuite->list[i]; 326 | CuStringAppend(summary, testCase->failed ? "F" : "."); 327 | } 328 | CuStringAppend(summary, "\n\n"); 329 | } 330 | 331 | void CuSuiteDetails(CuSuite* testSuite, CuString* details) 332 | { 333 | int i; 334 | int failCount = 0; 335 | 336 | if (testSuite->failCount == 0) 337 | { 338 | int passCount = testSuite->count - testSuite->failCount; 339 | const char* testWord = passCount == 1 ? "test" : "tests"; 340 | CuStringAppendFormat(details, "OK (%d %s)\n", passCount, testWord); 341 | } 342 | else 343 | { 344 | if (testSuite->failCount == 1) 345 | CuStringAppend(details, "There was 1 failure:\n"); 346 | else 347 | CuStringAppendFormat(details, "There were %d failures:\n", testSuite->failCount); 348 | 349 | for (i = 0 ; i < testSuite->count ; ++i) 350 | { 351 | CuTest* testCase = testSuite->list[i]; 352 | if (testCase->failed) 353 | { 354 | failCount++; 355 | CuStringAppendFormat(details, "%d) %s: %s\n", 356 | failCount, testCase->name, testCase->message); 357 | } 358 | } 359 | CuStringAppend(details, "\n!!!FAILURES!!!\n"); 360 | 361 | CuStringAppendFormat(details, "Runs: %d ", testSuite->count); 362 | CuStringAppendFormat(details, "Passes: %d ", testSuite->count - testSuite->failCount); 363 | CuStringAppendFormat(details, "Fails: %d\n", testSuite->failCount); 364 | } 365 | } 366 | -------------------------------------------------------------------------------- /cutest/CuTest.h: -------------------------------------------------------------------------------- 1 | /** 2 | * cogu 2017-02-19: This is a slighty modified version of CuTest.c v1.5 (http://cutest.sourceforge.net) 3 | * I have fixed a memory leak in the framework as well as adding test macro for unsigned integer equality (CuAssertUIntEquals). 4 | * 5 | */ 6 | 7 | #ifndef CU_TEST_H 8 | #define CU_TEST_H 9 | 10 | #include 11 | #include 12 | 13 | #define CUTEST_VERSION "CuTest 1.5" 14 | 15 | /* CuString */ 16 | 17 | char* CuStrAlloc(int size); 18 | char* CuStrCopy(const char* old); 19 | 20 | #define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE))) 21 | 22 | #define HUGE_STRING_LEN 8192 23 | #define STRING_MAX 256 24 | #define STRING_INC 256 25 | 26 | typedef struct 27 | { 28 | int length; 29 | int size; 30 | char* buffer; 31 | } CuString; 32 | 33 | void CuStringInit(CuString* str); 34 | CuString* CuStringNew(void); 35 | void CuStringRead(CuString* str, const char* path); 36 | void CuStringAppend(CuString* str, const char* text); 37 | void CuStringAppendChar(CuString* str, char ch); 38 | void CuStringAppendFormat(CuString* str, const char* format, ...); 39 | void CuStringInsert(CuString* str, const char* text, int pos); 40 | void CuStringResize(CuString* str, int newSize); 41 | void CuStringDelete(CuString* str); 42 | 43 | /* CuTest */ 44 | 45 | typedef struct CuTest CuTest; 46 | 47 | typedef void (*TestFunction)(CuTest *); 48 | 49 | struct CuTest 50 | { 51 | char* name; 52 | TestFunction function; 53 | int failed; 54 | int ran; 55 | const char* message; 56 | jmp_buf *jumpBuf; 57 | }; 58 | 59 | void CuTestInit(CuTest* t, const char* name, TestFunction function); 60 | CuTest* CuTestNew(const char* name, TestFunction function); 61 | void CuTestRun(CuTest* tc); 62 | void CuTestDelete(CuTest *t); 63 | 64 | /* Internal versions of assert functions -- use the public versions */ 65 | void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message); 66 | void CuAssert_Line(CuTest* tc, const char* file, int line, const char* message, int condition); 67 | void CuAssertStrEquals_LineMsg(CuTest* tc, 68 | const char* file, int line, const char* message, 69 | const char* expected, const char* actual); 70 | void CuAssertIntEquals_LineMsg(CuTest* tc, 71 | const char* file, int line, const char* message, 72 | int expected, int actual); 73 | void CuAssertUIntEquals_LineMsg(CuTest* tc, 74 | const char* file, int line, const char* message, 75 | unsigned int expected, unsigned int actual); 76 | void CuAssertDblEquals_LineMsg(CuTest* tc, 77 | const char* file, int line, const char* message, 78 | double expected, double actual, double delta); 79 | void CuAssertPtrEquals_LineMsg(CuTest* tc, 80 | const char* file, int line, const char* message, 81 | void* expected, void* actual); 82 | void CuAssertConstPtrEquals_LineMsg(CuTest* tc, 83 | const char* file, int line, const char* message, 84 | const void* expected, const void* actual); 85 | 86 | 87 | /* public assert functions */ 88 | 89 | #define CuFail(tc, ms) CuFail_Line( (tc), __FILE__, __LINE__, NULL, (ms)) 90 | #define CuAssert(tc, ms, cond) CuAssert_Line((tc), __FILE__, __LINE__, (ms), (cond)) 91 | #define CuAssertTrue(tc, cond) CuAssert_Line((tc), __FILE__, __LINE__, "assert failed", (cond)) 92 | 93 | #define CuAssertStrEquals(tc,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac)) 94 | #define CuAssertStrEquals_Msg(tc,ms,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac)) 95 | #define CuAssertIntEquals(tc,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac)) 96 | #define CuAssertIntEquals_Msg(tc,ms,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac)) 97 | #define CuAssertUIntEquals(tc,ex,ac) CuAssertUIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac)) 98 | #define CuAssertUIntEquals_Msg(tc,ms,ex,ac) CuAssertUIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac)) 99 | #define CuAssertDblEquals(tc,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac),(dl)) 100 | #define CuAssertDblEquals_Msg(tc,ms,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac),(dl)) 101 | #define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac)) 102 | #define CuAssertPtrEquals_Msg(tc,ms,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac)) 103 | #define CuAssertConstPtrEquals(tc,ex,ac) CuAssertConstPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac)) 104 | #define CuAssertConstPtrEquals_Msg(tc,ms,ex,ac) CuAssertConstPtrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac)) 105 | 106 | 107 | #define CuAssertPtrNotNull(tc,p) CuAssert_Line((tc),__FILE__,__LINE__,"null pointer unexpected",(p != NULL)) 108 | #define CuAssertPtrNotNullMsg(tc,msg,p) CuAssert_Line((tc),__FILE__,__LINE__,(msg),(p != NULL)) 109 | 110 | /* CuSuite */ 111 | 112 | #define MAX_TEST_CASES 1024 113 | 114 | #define SUITE_ADD_TEST(SUITE,TEST) CuSuiteAdd(SUITE, CuTestNew(#TEST, TEST)) 115 | 116 | typedef struct 117 | { 118 | int count; 119 | CuTest* list[MAX_TEST_CASES]; 120 | int failCount; 121 | 122 | } CuSuite; 123 | 124 | 125 | void CuSuiteInit(CuSuite* testSuite); 126 | CuSuite* CuSuiteNew(void); 127 | void CuSuiteDelete(CuSuite *testSuite); 128 | void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase); 129 | void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2); 130 | void CuSuiteRun(CuSuite* testSuite); 131 | void CuSuiteSummary(CuSuite* testSuite, CuString* summary); 132 | void CuSuiteDetails(CuSuite* testSuite, CuString* details); 133 | 134 | #endif /* CU_TEST_H */ 135 | -------------------------------------------------------------------------------- /cutest/license.txt: -------------------------------------------------------------------------------- 1 | NOTE 2 | 3 | The license is based on the zlib/libpng license. For more details see 4 | http://www.opensource.org/licenses/zlib-license.html. The intent of the 5 | license is to: 6 | 7 | - keep the license as simple as possible 8 | - encourage the use of CuTest in both free and commercial applications 9 | and libraries 10 | - keep the source code together 11 | - give credit to the CuTest contributors for their work 12 | 13 | If you ship CuTest in source form with your source distribution, the 14 | following license document must be included with it in unaltered form. 15 | If you find CuTest useful we would like to hear about it. 16 | 17 | LICENSE 18 | 19 | Copyright (c) 2003 Asim Jalis 20 | 21 | This software is provided 'as-is', without any express or implied 22 | warranty. In no event will the authors be held liable for any damages 23 | arising from the use of this software. 24 | 25 | Permission is granted to anyone to use this software for any purpose, 26 | including commercial applications, and to alter it and redistribute it 27 | freely, subject to the following restrictions: 28 | 29 | 1. The origin of this software must not be misrepresented; you must not 30 | claim that you wrote the original software. If you use this software in 31 | a product, an acknowledgment in the product documentation would be 32 | appreciated but is not required. 33 | 34 | 2. Altered source versions must be plainly marked as such, and must not 35 | be misrepresented as being the original software. 36 | 37 | 3. This notice may not be removed or altered from any source 38 | distribution. 39 | -------------------------------------------------------------------------------- /os/inc/os.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-10 5 | * \brief Amber OS header 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef AMBER_OS_H 27 | #define AMBER_OS_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #include "os_types.h" 33 | #include "os_task.h" 34 | #include "os_core.h" 35 | #include "os_event_cfg.h" 36 | #include "os_task_cfg.h" 37 | ////////////////////////////////////////////////////////////////////////////// 38 | // PUBLIC CONSTANTS AND DATA TYPES 39 | ////////////////////////////////////////////////////////////////////////////// 40 | 41 | ////////////////////////////////////////////////////////////////////////////// 42 | // PUBLIC VARIABLES 43 | ////////////////////////////////////////////////////////////////////////////// 44 | 45 | ////////////////////////////////////////////////////////////////////////////// 46 | // PUBLIC FUNCTION PROTOTYPES 47 | ////////////////////////////////////////////////////////////////////////////// 48 | 49 | 50 | #endif //OS_H 51 | -------------------------------------------------------------------------------- /os/inc/os_core.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_core.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-12 5 | * \brief Amber OS core functions 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef OS_CORE_H 27 | #define OS_CORE_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #include "os_types.h" 33 | #include "os_task.h" 34 | #include "priority_queue.h" 35 | ////////////////////////////////////////////////////////////////////////////// 36 | // PUBLIC CONSTANTS AND DATA TYPES 37 | ////////////////////////////////////////////////////////////////////////////// 38 | #define OS_NUM_EVENTS_DEFAULT 100 39 | 40 | ////////////////////////////////////////////////////////////////////////////// 41 | // PUBLIC VARIABLES 42 | ////////////////////////////////////////////////////////////////////////////// 43 | 44 | ////////////////////////////////////////////////////////////////////////////// 45 | // PUBLIC FUNCTION PROTOTYPES 46 | ////////////////////////////////////////////////////////////////////////////// 47 | void os_init(os_cfg_t *cfg); 48 | void os_shutdown(void); 49 | void os_start(void); 50 | void os_stop(void); 51 | 52 | 53 | #if defined(UNIT_TEST) || defined(SYSTIME_SIMULATED) 54 | #define DYN_STATIC 55 | void os_scheduler_run(void); 56 | DYN_STATIC priority_queue_t *os_getPriorityQueue(void); 57 | #else 58 | #define DYN_STATIC static 59 | #endif 60 | 61 | 62 | #endif //OS_CORE_H 63 | -------------------------------------------------------------------------------- /os/inc/os_task.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_task.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-12 5 | * \brief Amber OS task 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef OS_TASK_H 27 | #define OS_TASK_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #ifdef _WIN32 33 | #include 34 | #else 35 | #include 36 | #include 37 | #endif 38 | #include 39 | #include "osmacro.h" 40 | #include "os_types.h" 41 | 42 | 43 | 44 | ////////////////////////////////////////////////////////////////////////////// 45 | // CONSTANTS AND DATA TYPES 46 | ////////////////////////////////////////////////////////////////////////////// 47 | typedef struct os_task_tag 48 | { 49 | OS_TASK_HANDLER_PTR(workerFunc, arg); 50 | THREAD_T workerThread; 51 | #ifdef _WIN32 52 | SPINLOCK_T lock; //object lock 53 | DWORD threadId; 54 | HANDLE hEvent; //Windows event is used to signal when event mask has been modified 55 | #else 56 | MUTEX_T mutex; //used for cond_var locking 57 | pthread_cond_t cond_var; //used to signal when event mask has been modified 58 | #endif 59 | uint32_t eventMask1; //each bit represents 1 event flag. In Windows it's protected by lock variable, in Linux it's protected by mutex variable 60 | bool workerThreadValid; 61 | bool quitEvent; 62 | } os_task_t; 63 | 64 | 65 | ////////////////////////////////////////////////////////////////////////////// 66 | // GLOBAL VARIABLES 67 | ////////////////////////////////////////////////////////////////////////////// 68 | 69 | 70 | ////////////////////////////////////////////////////////////////////////////// 71 | // GLOBAL FUNCTION PROTOTYPES 72 | ////////////////////////////////////////////////////////////////////////////// 73 | int8_t os_task_create(os_task_t *self, OS_TASK_HANDLER_PTR(handler, arg)); 74 | void os_task_destroy(os_task_t *self); 75 | void os_task_start(os_task_t *self); 76 | void os_task_stop(os_task_t *self); 77 | void os_task_setEvent(os_task_t *self, uint32_t eventMask); 78 | int8_t os_task_waitEvent(os_task_t *self, uint32_t *eventMask); 79 | void os_task_clearEvent(os_task_t *self); 80 | 81 | #endif //OS_TASK_H 82 | -------------------------------------------------------------------------------- /os/inc/os_types.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_types.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-12 5 | * \brief Amber OS type definitions 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef OS_TYPES_H 27 | #define OS_TYPES_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #ifdef _MSC_VER 33 | #include 34 | #else 35 | #include 36 | #endif 37 | #include "osmacro.h" 38 | 39 | ////////////////////////////////////////////////////////////////////////////// 40 | // CONSTANTS AND DATA TYPES 41 | ////////////////////////////////////////////////////////////////////////////// 42 | #define OS_TASK_HANDLER(x, arg) THREAD_PROTO(x, arg) 43 | #define OS_TASK_HANDLER_PTR(x, arg) THREAD_PROTO_PTR(x, arg) 44 | 45 | #define OS_QUIT_EVENT 0 //reserved for shutting down the worker thread 46 | #define OS_USER_EVENT_ID 1 47 | #define OS_INVALID_EVENT_ID 0xFFFF 48 | 49 | //forward declarations 50 | struct os_task_tag; 51 | 52 | typedef struct os_alarm_cfg_tag 53 | { 54 | struct os_task_tag *taskPtr; 55 | uint32_t eventMask; 56 | uint32_t u32InitDelayMs; 57 | uint32_t u32PeriodMs; 58 | } os_alarm_cfg_t; 59 | 60 | typedef struct os_task_elem_tag 61 | { 62 | struct os_task_tag *taskPtr; 63 | OS_TASK_HANDLER_PTR(taskHandlerPtr, arg); 64 | const os_alarm_cfg_t *alarms; 65 | uint32_t numAlarms; 66 | } os_task_elem_t; 67 | 68 | typedef struct os_cfg_tag 69 | { 70 | const os_task_elem_t *taskList; 71 | uint32_t numTasks; 72 | uint32_t(*timerFunc)(void); 73 | void(*alarmEventHookFunc)(const os_alarm_cfg_t *alarm); 74 | } os_cfg_t; 75 | 76 | 77 | ////////////////////////////////////////////////////////////////////////////// 78 | // GLOBAL VARIABLES 79 | ////////////////////////////////////////////////////////////////////////////// 80 | 81 | 82 | ////////////////////////////////////////////////////////////////////////////// 83 | // GLOBAL FUNCTION PROTOTYPES 84 | ////////////////////////////////////////////////////////////////////////////// 85 | 86 | #endif //OS_TYPES_H 87 | -------------------------------------------------------------------------------- /os/src/os_core.c: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // INCLUDES 3 | ////////////////////////////////////////////////////////////////////////////// 4 | #ifdef _WIN32 5 | #include 6 | #include 7 | #else 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #endif 14 | #include 15 | #include 16 | #include 17 | #include "osmacro.h" 18 | #include "osutil.h" 19 | #include "os_core.h" 20 | #include "systime.h" 21 | #include "adt_ary.h" 22 | #include 23 | #ifdef MEM_LEAK_CHECK 24 | # include "CMemLeak.h" 25 | #endif 26 | 27 | 28 | ////////////////////////////////////////////////////////////////////////////// 29 | // CONSTANTS AND DATA TYPES 30 | ////////////////////////////////////////////////////////////////////////////// 31 | #if (!defined(SYSTIME_SIMULATED) && !defined(UNIT_TEST)) 32 | static THREAD_PROTO(TimerEventWorker,arg); 33 | #endif 34 | ////////////////////////////////////////////////////////////////////////////// 35 | // LOCAL FUNCTION PROTOTYPES 36 | ////////////////////////////////////////////////////////////////////////////// 37 | static void initOsTasks(void); 38 | static void shutdownOsTasks(void); 39 | static void startOsTasks(void); 40 | static void stopOsTasks(void); 41 | static void initScheduler(void); 42 | DYN_STATIC void os_scheduler_run(void); 43 | 44 | 45 | 46 | 47 | 48 | ////////////////////////////////////////////////////////////////////////////// 49 | // GLOBAL VARIABLES 50 | ////////////////////////////////////////////////////////////////////////////// 51 | 52 | ////////////////////////////////////////////////////////////////////////////// 53 | // LOCAL VARIABLES 54 | ////////////////////////////////////////////////////////////////////////////// 55 | static priority_queue_t m_pq; 56 | static bool m_workerThreadValid; 57 | static os_cfg_t *m_cfg = 0; 58 | THREAD_T m_thread_worker; 59 | SPINLOCK_T m_spin; 60 | #ifdef _MSC_VER 61 | DWORD m_threadId; 62 | #endif 63 | uint8_t m_isRunning = 0; 64 | uint32_t (*m_getTimeFn)(void) = 0; 65 | void (*m_alarmEventHookFunc)(const os_alarm_cfg_t *alarm); 66 | 67 | 68 | ////////////////////////////////////////////////////////////////////////////// 69 | // GLOBAL FUNCTIONS 70 | ////////////////////////////////////////////////////////////////////////////// 71 | 72 | /** 73 | * \param cfg array of event object. 74 | * \param u32CfgLen number of elements in configuration array 75 | * \timerfunc pointer to function that returns current system time (default: SysTime_getTime) 76 | */ 77 | void os_init(os_cfg_t *cfg) 78 | { 79 | m_cfg = cfg; 80 | priority_queue_create(&m_pq); 81 | m_isRunning = 0; 82 | 83 | m_workerThreadValid = false; 84 | if (m_cfg->timerFunc != 0) 85 | { 86 | m_getTimeFn = m_cfg->timerFunc; 87 | } 88 | else 89 | { 90 | m_getTimeFn = SysTime_getTime; 91 | } 92 | m_alarmEventHookFunc = cfg->alarmEventHookFunc; 93 | 94 | initOsTasks(); 95 | initScheduler(); 96 | } 97 | 98 | void os_shutdown(void) 99 | { 100 | os_stop(); 101 | priority_queue_destroy(&m_pq); 102 | shutdownOsTasks(); 103 | } 104 | 105 | void os_start(void) 106 | { 107 | #if (!defined(_MSC_VER)) && (!defined(SYSTIME_SIMULATED)) 108 | pthread_attr_t attr; 109 | #endif 110 | 111 | SPINLOCK_INIT(m_spin); 112 | m_workerThreadValid = false; 113 | 114 | startOsTasks(); 115 | m_isRunning = 1; 116 | #if (!defined(SYSTIME_SIMULATED) && !defined(UNIT_TEST)) 117 | # ifdef _MSC_VER 118 | THREAD_CREATE(m_thread_worker, TimerEventWorker, 0, m_threadId); 119 | if (m_thread_worker == INVALID_HANDLE_VALUE) 120 | { 121 | m_workerThreadValid = false; 122 | return; 123 | } 124 | # else 125 | pthread_attr_init(&attr); 126 | pthread_attr_setstacksize(&attr, PROG_MAX_STACK_SIZE); 127 | THREAD_CREATE_ATTR(m_thread_worker,attr, TimerEventWorker,0); 128 | # endif 129 | m_workerThreadValid = true; 130 | #endif 131 | 132 | } 133 | 134 | void os_stop(void) 135 | { 136 | if (m_isRunning != 0) 137 | { 138 | SPINLOCK_ENTER(m_spin); 139 | m_isRunning = 0; 140 | SPINLOCK_LEAVE(m_spin); 141 | #ifndef SYSTIME_SIMULATED 142 | THREAD_JOIN(m_thread_worker); 143 | THREAD_DESTROY(m_thread_worker); 144 | #endif 145 | SPINLOCK_DESTROY(m_spin); 146 | m_workerThreadValid = false; 147 | stopOsTasks(); 148 | } 149 | } 150 | 151 | #ifdef UNIT_TEST 152 | priority_queue_t *os_getPriorityQueue(void) 153 | { 154 | return &m_pq; 155 | } 156 | #endif 157 | 158 | 159 | ////////////////////////////////////////////////////////////////////////////// 160 | // LOCAL FUNCTIONS 161 | ////////////////////////////////////////////////////////////////////////////// 162 | DYN_STATIC void os_scheduler_run(void) 163 | { 164 | uint32_t currentTimeMs = m_getTimeFn(); 165 | while(1) 166 | { 167 | adt_heap_elem_t* elem = priority_queue_top(&m_pq); 168 | if (currentTimeMs >= elem->u32Value) 169 | { 170 | const os_alarm_cfg_t *alarm = (const os_alarm_cfg_t*) elem->pItem; 171 | //printf("{%u, %08X},\n", currentTimeMs, (int) alarm->eventMask); 172 | 173 | //call hook if set 174 | if (m_alarmEventHookFunc != 0) 175 | { 176 | m_alarmEventHookFunc(alarm); 177 | } 178 | //call task handler if task is set 179 | priority_queue_incrementTopPriority(&m_pq, alarm->u32PeriodMs); 180 | if (alarm->taskPtr >= 0) 181 | { 182 | os_task_setEvent(alarm->taskPtr, alarm->eventMask); 183 | } 184 | } 185 | else 186 | { 187 | break; 188 | } 189 | } 190 | } 191 | 192 | #if (!defined(SYSTIME_SIMULATED) && !defined(UNIT_TEST)) 193 | THREAD_PROTO(TimerEventWorker,arg){ 194 | SysTime_reset(); 195 | 196 | os_scheduler_run(); 197 | 198 | for(;;) 199 | { 200 | uint8_t running; 201 | SPINLOCK_ENTER(m_spin); 202 | running = m_isRunning; 203 | SPINLOCK_LEAVE(m_spin); 204 | if(running == 0){ 205 | break; 206 | } 207 | SysTime_wait(1); 208 | os_scheduler_run(); 209 | } 210 | THREAD_RETURN(0); 211 | } 212 | #endif 213 | 214 | #ifdef UNIT_TEST 215 | DYN_STATIC priority_queue_t *os_time_getPriorityQueue(void) 216 | { 217 | return &m_pq; 218 | } 219 | #endif 220 | 221 | static void initOsTasks(void) 222 | { 223 | uint32_t i; 224 | for (i = 0; inumTasks; i++) 225 | { 226 | os_task_create(m_cfg->taskList[i].taskPtr, m_cfg->taskList[i].taskHandlerPtr); 227 | } 228 | } 229 | 230 | static void shutdownOsTasks(void) 231 | { 232 | uint32_t i; 233 | for (i = 0; inumTasks; i++) 234 | { 235 | os_task_destroy(m_cfg->taskList[i].taskPtr); 236 | } 237 | } 238 | 239 | static void startOsTasks(void) 240 | { 241 | uint32_t i; 242 | for (i = 0; inumTasks; i++) 243 | { 244 | os_task_start(m_cfg->taskList[i].taskPtr); 245 | } 246 | } 247 | 248 | static void stopOsTasks(void) 249 | { 250 | uint32_t i; 251 | for (i = 0; inumTasks; i++) 252 | { 253 | os_task_stop(m_cfg->taskList[i].taskPtr); 254 | } 255 | } 256 | 257 | static void initScheduler(void) 258 | { 259 | uint32_t i; 260 | for (i = 0; inumTasks; i++) 261 | { 262 | uint32_t j; 263 | for (j = 0; jtaskList[i].numAlarms; j++) 264 | { 265 | uint32_t u32InitDelayMs = m_cfg->taskList[i].alarms[j].u32InitDelayMs; 266 | uint32_t u32PeriodMs = m_cfg->taskList[i].alarms[j].u32PeriodMs; 267 | if (u32InitDelayMs > 0) 268 | { 269 | priority_queue_push(&m_pq, (void*)&m_cfg->taskList[i].alarms[j], u32InitDelayMs); 270 | } 271 | else 272 | { 273 | priority_queue_push(&m_pq, (void*)&m_cfg->taskList[i].alarms[j], u32PeriodMs); 274 | } 275 | } 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /os/src/os_task.c: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // INCLUDES 3 | ////////////////////////////////////////////////////////////////////////////// 4 | #include 5 | #include "os_types.h" 6 | #include "os_task.h" 7 | #ifdef _MSC_VER 8 | #include 9 | #endif 10 | #include "osmacro.h" 11 | #include 12 | #ifdef MEM_LEAK_CHECK 13 | # include "CMemLeak.h" 14 | #endif 15 | 16 | 17 | ////////////////////////////////////////////////////////////////////////////// 18 | // CONSTANTS AND DATA TYPES 19 | ////////////////////////////////////////////////////////////////////////////// 20 | #define THREAD_STACK_SIZE 65536 21 | 22 | ////////////////////////////////////////////////////////////////////////////// 23 | // LOCAL FUNCTION PROTOTYPES 24 | ////////////////////////////////////////////////////////////////////////////// 25 | 26 | 27 | ////////////////////////////////////////////////////////////////////////////// 28 | // GLOBAL VARIABLES 29 | ////////////////////////////////////////////////////////////////////////////// 30 | 31 | ////////////////////////////////////////////////////////////////////////////// 32 | // LOCAL VARIABLES 33 | ////////////////////////////////////////////////////////////////////////////// 34 | 35 | 36 | 37 | ////////////////////////////////////////////////////////////////////////////// 38 | // GLOBAL FUNCTIONS 39 | ////////////////////////////////////////////////////////////////////////////// 40 | 41 | /** 42 | * return 0 on success, non-zero on error 43 | */ 44 | int8_t os_task_create(os_task_t *self, THREAD_PROTO_PTR(handler, arg)) 45 | { 46 | if (self != 0) 47 | { 48 | self->workerThreadValid = false; 49 | self->quitEvent = false; 50 | self->workerFunc = handler; 51 | self->eventMask1 = 0u; 52 | #ifdef _WIN32 53 | SPINLOCK_INIT(self->lock); 54 | #else 55 | pthread_cond_init(&self->cond_var, NULL); 56 | MUTEX_INIT(self->mutex); 57 | #endif 58 | return 0; 59 | } 60 | return -1; 61 | } 62 | 63 | void os_task_destroy(os_task_t *self) 64 | { 65 | if (self != 0) 66 | { 67 | #ifdef _WIN32 68 | SPINLOCK_DESTROY(self->lock); 69 | #else 70 | pthread_cond_destroy(&self->cond_var); 71 | MUTEX_DESTROY(self->mutex); 72 | #endif 73 | } 74 | } 75 | 76 | void os_task_start(os_task_t *self) 77 | { 78 | if ( (self != 0) && (self->workerThreadValid == false) ) 79 | { 80 | #ifndef _MSC_VER 81 | pthread_attr_t attr; 82 | #endif 83 | 84 | #ifdef _WIN32 85 | THREAD_CREATE(self->workerThread, self->thread_func, self, self->threadId); 86 | if (self->workerThread == INVALID_HANDLE_VALUE) 87 | { 88 | self->workerThreadValid = false; 89 | return; 90 | } 91 | #else 92 | pthread_attr_init(&attr); 93 | pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE); 94 | THREAD_CREATE_ATTR(self->workerThread, attr, self->workerFunc, self); 95 | #endif 96 | self->workerThreadValid = true; 97 | } 98 | } 99 | 100 | void os_task_stop(os_task_t *self) 101 | { 102 | if (self != 0) 103 | { 104 | #ifdef _WIN32 105 | SPINLOCK_ENTER(self->lock); 106 | self->workerThreadRunning=false; 107 | SPINLOCK_LEAVE(self->lock); 108 | SetEvent(self->hEvent); 109 | #else 110 | MUTEX_LOCK(self->mutex); 111 | self->quitEvent = true; 112 | pthread_cond_signal(&self->cond_var); 113 | MUTEX_UNLOCK(self->mutex); 114 | #endif 115 | THREAD_JOIN(self->workerThread); 116 | THREAD_DESTROY(self->workerThread); 117 | self->workerThreadValid = false; 118 | } 119 | } 120 | 121 | void os_task_setEvent(os_task_t *self, uint32_t eventMask) 122 | { 123 | if (self != 0) 124 | { 125 | #ifdef _WIN32 126 | SPINLOCK_ENTER(self->lock); 127 | self->eventMask1|=eventMask; 128 | SPINLOCK_LEAVE(self->lock); 129 | SetEvent(self->hEvent); 130 | #else 131 | MUTEX_LOCK(self->mutex); 132 | self->eventMask1|=eventMask; 133 | pthread_cond_signal(&self->cond_var); 134 | MUTEX_UNLOCK(self->mutex); 135 | #endif 136 | } 137 | } 138 | 139 | /** 140 | * returns negative (-1) on error, 0 on success, 1 when quit event has been activated 141 | */ 142 | int8_t os_task_waitEvent(os_task_t *self, uint32_t *eventMask) 143 | { 144 | int8_t retval = -1; 145 | if ( (self != 0 ) && (eventMask != 0) ) 146 | { 147 | #ifdef _WIN32 148 | DWORD result = WaitForSingleObject(self->hEvent, INFINITE); 149 | if (result == WAIT_OBJECT_0) 150 | { 151 | SPINLOCK_ENTER(self->lock); 152 | *eventMask = self->eventMask1; 153 | retval = self->quitEvent? 1 : 0; 154 | SPINLOCK_LEAVE(self->lock); 155 | } 156 | #else 157 | 158 | MUTEX_LOCK(self->mutex); 159 | if ((self->quitEvent == false) && (self->eventMask1 == 0)) 160 | { 161 | int result; 162 | result = pthread_cond_wait(&self->cond_var, &self->mutex); 163 | if (result == 0) 164 | { 165 | *eventMask = self->eventMask1; 166 | self->eventMask1=0u; 167 | retval = self->quitEvent? 1 : 0; 168 | } 169 | } 170 | else 171 | { 172 | *eventMask = self->eventMask1; 173 | self->eventMask1=0u; 174 | retval = self->quitEvent? 1 : 0; 175 | } 176 | MUTEX_UNLOCK(self->mutex); 177 | #endif 178 | } 179 | return retval; 180 | } 181 | 182 | void os_task_clearEvent(os_task_t *self) 183 | { 184 | if (self != 0) 185 | { 186 | #ifdef _WIN32 187 | SPINLOCK_ENTER(self->lock); 188 | self->eventMask1 = 0u; 189 | SPINLOCK_LEAVE(self->lock); 190 | #else 191 | MUTEX_LOCK(self->mutex); 192 | self->eventMask1 = 0u; 193 | MUTEX_UNLOCK(self->mutex); 194 | #endif 195 | } 196 | } 197 | 198 | 199 | ////////////////////////////////////////////////////////////////////////////// 200 | // LOCAL FUNCTIONS 201 | ////////////////////////////////////////////////////////////////////////////// 202 | -------------------------------------------------------------------------------- /os/test/testsuite_os_core.c: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // INCLUDES 3 | ////////////////////////////////////////////////////////////////////////////// 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "CuTest.h" 11 | #include "os_core.h" 12 | #include "systime.h" 13 | #include "priority_queue.h" 14 | #ifdef MEM_LEAK_CHECK 15 | #include "CMemLeak.h" 16 | #endif 17 | 18 | 19 | ////////////////////////////////////////////////////////////////////////////// 20 | // CONSTANTS AND DATA TYPES 21 | ////////////////////////////////////////////////////////////////////////////// 22 | 23 | #define EVENT_MASK_Test_Task1_TMT_5ms ((uint32_t) 0x00000001) 24 | #define EVENT_MASK_Test_Task1_TMT_10ms ((uint32_t) 0x00000002) 25 | #define EVENT_MASK_Test_Task1_TMT_20ms ((uint32_t) 0x00000004) 26 | #define EVENT_MASK_Test_Task1_OnEntry_EcuM_Mode_RUN ((uint32_t) 0x00000008) 27 | #define EVENT_MASK_Test_Task1_OnExit_EcuM_Mode_RUN ((uint32_t) 0x00000010) 28 | 29 | #define OS_NUM_ALARMS_Test_Task1 3 30 | #define OS_NUM_EVENTS_Test_Task1 5 31 | 32 | 33 | #define EVENT_MASK_Test_Task2_TMT_20ms ((uint32_t) 0x00000001) 34 | #define EVENT_MASK_Test_Task2_TMT_50ms ((uint32_t) 0x00000002) 35 | #define EVENT_MASK_Test_Task2_TMT_100ms ((uint32_t) 0x00000004) 36 | #define EVENT_MASK_Test_Task2_OnEntry_EcuM_Mode_RUN ((uint32_t) 0x00000008) 37 | #define EVENT_MASK_Test_Task2_OnExit_EcuM_Mode_RUN ((uint32_t) 0x00000010) 38 | 39 | #define OS_NUM_ALARMS_Test_Task2 3 40 | #define OS_NUM_EVENTS_Test_Task2 5 41 | 42 | #define NUM_TEST_TASKS 2 43 | ////////////////////////////////////////////////////////////////////////////// 44 | // LOCAL FUNCTION PROTOTYPES 45 | ////////////////////////////////////////////////////////////////////////////// 46 | static void test_os_core(CuTest* tc); 47 | static OS_TASK_HANDLER(Test_Task1, arg); 48 | static OS_TASK_HANDLER(Test_Task2, arg); 49 | 50 | ////////////////////////////////////////////////////////////////////////////// 51 | // GLOBAL VARIABLES 52 | ////////////////////////////////////////////////////////////////////////////// 53 | 54 | ////////////////////////////////////////////////////////////////////////////// 55 | // LOCAL VARIABLES 56 | ////////////////////////////////////////////////////////////////////////////// 57 | static os_task_t m_os_task_Test_Task1; 58 | static os_task_t m_os_task_Test_Task2; 59 | 60 | ////////////////////////////////////////////////////////////////////////////// 61 | // GLOBAL FUNCTIONS 62 | ////////////////////////////////////////////////////////////////////////////// 63 | 64 | 65 | CuSuite* testsuite_os_core(void) 66 | { 67 | CuSuite* suite = CuSuiteNew(); 68 | 69 | SUITE_ADD_TEST(suite, test_os_core); 70 | 71 | return suite; 72 | } 73 | 74 | ////////////////////////////////////////////////////////////////////////////// 75 | // LOCAL FUNCTIONS 76 | ////////////////////////////////////////////////////////////////////////////// 77 | static void test_os_core(CuTest* tc) 78 | { 79 | 80 | ////////////////////////////////////////////////////////////////////////////// 81 | // PUBLIC VARIABLES 82 | ////////////////////////////////////////////////////////////////////////////// 83 | 84 | const os_alarm_cfg_t os_alarm_cfg_Test_Task1[OS_NUM_ALARMS_Test_Task1] = { 85 | //OS Task, Event Mask, Init Delay (ms), Period (ms) 86 | {&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_TMT_5ms, 0u, 5u}, 87 | {&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_TMT_10ms, 0u, 10u}, 88 | {&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_TMT_20ms, 0u, 20u}, 89 | }; 90 | 91 | const os_alarm_cfg_t os_alarm_cfg_Test_Task2[OS_NUM_ALARMS_Test_Task2] = { 92 | //OS Task, Event ID, Init Delay (ms), Period (ms) 93 | {&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_TMT_20ms, 0u, 20u}, 94 | {&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_TMT_50ms, 0u, 50u}, 95 | {&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_TMT_100ms, 0u, 100u}, 96 | }; 97 | 98 | const os_task_elem_t os_task_cfg[NUM_TEST_TASKS] = { 99 | //OS Task, TaskHandlerPtr, alarms, number of alarms 100 | {&m_os_task_Test_Task1, Test_Task1, &os_alarm_cfg_Test_Task1[0], OS_NUM_ALARMS_Test_Task1}, 101 | {&m_os_task_Test_Task2, Test_Task2, &os_alarm_cfg_Test_Task2[0], OS_NUM_ALARMS_Test_Task2}, 102 | }; 103 | 104 | os_cfg_t os_cfg = { 105 | &os_task_cfg[0], 106 | NUM_TEST_TASKS, 107 | 0, 108 | 0 109 | }; 110 | 111 | priority_queue_t *pq; 112 | os_alarm_cfg_t *alarm; 113 | adt_heap_elem_t *heap_elem; 114 | 115 | 116 | 117 | SysTime_initSimulated(); 118 | CuAssertUIntEquals(tc, 0, SysTime_getTime()); 119 | os_init(&os_cfg); 120 | pq = os_getPriorityQueue(); 121 | CuAssertPtrNotNull(tc, pq); 122 | heap_elem = priority_queue_top(pq); 123 | alarm = (os_alarm_cfg_t*) heap_elem->pItem; 124 | CuAssertPtrNotNull(tc, alarm); 125 | CuAssertUIntEquals(tc, 5, heap_elem->u32Value); 126 | CuAssertPtrEquals(tc, &m_os_task_Test_Task1, alarm->taskPtr); 127 | CuAssertUIntEquals(tc, EVENT_MASK_Test_Task1_TMT_5ms, alarm->eventMask); 128 | SysTime_tick(5); 129 | os_scheduler_run(); 130 | SysTime_tick(5); 131 | os_scheduler_run(); 132 | SysTime_tick(5); 133 | os_scheduler_run(); 134 | SysTime_tick(5); 135 | os_scheduler_run(); 136 | 137 | // os_task_create(&m_os_Test_Task, Test_Task, 100); 138 | // os_tem_init(m_timerEventCfg, m_timerEventState, sizeof(m_timerEventState) / sizeof(m_timerEventState[0])); 139 | // os_tem_run(); 140 | // os_tem_run(); 141 | // os_tem_run(); 142 | } 143 | 144 | OS_TASK_HANDLER(Test_Task1, arg) 145 | { 146 | bool isRunning = true; 147 | os_task_t *self = (os_task_t*)arg; 148 | if (self == 0) 149 | { 150 | fprintf(stderr, "Error: Test_Task1 called with null argument\n"); 151 | THREAD_RETURN(0); 152 | } 153 | 154 | while (isRunning == true) 155 | { 156 | 157 | } 158 | THREAD_RETURN(0); 159 | } 160 | 161 | OS_TASK_HANDLER(Test_Task2, arg) 162 | { 163 | bool isRunning = true; 164 | os_task_t *self = (os_task_t*)arg; 165 | if (self == 0) 166 | { 167 | fprintf(stderr, "Error: Test_Task1 called with null argument\n"); 168 | THREAD_RETURN(0); 169 | } 170 | 171 | printf("Test_Task2: entering main loop\n"); 172 | while (isRunning == true) 173 | { 174 | uint32_t eventMask; 175 | int8_t result = os_task_waitEvent(self, &eventMask); 176 | if (result == 0) 177 | { 178 | if (eventMask & EVENT_MASK_Test_Task2_TMT_20ms) 179 | { 180 | printf("EVENT_MASK_Test_Task2_TMT_20ms"); 181 | } 182 | if (eventMask & EVENT_MASK_Test_Task2_TMT_50ms) 183 | { 184 | printf("EVENT_MASK_Test_Task2_TMT_50ms"); 185 | } 186 | if (eventMask & EVENT_MASK_Test_Task2_TMT_100ms) 187 | { 188 | printf("EVENT_MASK_Test_Task2_TMT_100ms"); 189 | } 190 | } 191 | else if(result > 0) 192 | { 193 | isRunning = false; 194 | } 195 | else 196 | { 197 | fprintf(stderr, "os_task_waitEvent failed\n"); 198 | } 199 | } 200 | THREAD_RETURN(0); 201 | } 202 | -------------------------------------------------------------------------------- /os/test/testsuite_os_task.c: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // INCLUDES 3 | ////////////////////////////////////////////////////////////////////////////// 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "CuTest.h" 10 | #include "os_task.h" 11 | #ifdef MEM_LEAK_CHECK 12 | #include "CMemLeak.h" 13 | #endif 14 | 15 | 16 | ////////////////////////////////////////////////////////////////////////////// 17 | // CONSTANTS AND DATA TYPES 18 | ////////////////////////////////////////////////////////////////////////////// 19 | 20 | ////////////////////////////////////////////////////////////////////////////// 21 | // LOCAL FUNCTION PROTOTYPES 22 | ////////////////////////////////////////////////////////////////////////////// 23 | static void test_os_task_create(CuTest* tc); 24 | static void test_os_task_events(CuTest* tc); 25 | THREAD_PROTO(test_task, arg); 26 | 27 | ////////////////////////////////////////////////////////////////////////////// 28 | // GLOBAL VARIABLES 29 | ////////////////////////////////////////////////////////////////////////////// 30 | 31 | ////////////////////////////////////////////////////////////////////////////// 32 | // LOCAL VARIABLES 33 | ////////////////////////////////////////////////////////////////////////////// 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////////// 37 | // GLOBAL FUNCTIONS 38 | ////////////////////////////////////////////////////////////////////////////// 39 | 40 | 41 | CuSuite* testsuite_os_task(void) 42 | { 43 | CuSuite* suite = CuSuiteNew(); 44 | 45 | SUITE_ADD_TEST(suite, test_os_task_create); 46 | SUITE_ADD_TEST(suite, test_os_task_events); 47 | 48 | return suite; 49 | } 50 | 51 | ////////////////////////////////////////////////////////////////////////////// 52 | // LOCAL FUNCTIONS 53 | ////////////////////////////////////////////////////////////////////////////// 54 | 55 | static void test_os_task_create(CuTest* tc) 56 | { 57 | os_task_t task1; 58 | CuAssertIntEquals(tc, 0, os_task_create(&task1, test_task)); 59 | os_task_destroy(&task1); 60 | } 61 | 62 | static void test_os_task_events(CuTest* tc) 63 | { 64 | os_task_t task1; 65 | uint32_t eventMask; 66 | CuAssertIntEquals(tc, 0, os_task_create(&task1, test_task)); 67 | CuAssertUIntEquals(tc, 0, task1.eventMask1); 68 | os_task_setEvent(&task1, 0x10); 69 | CuAssertUIntEquals(tc, 0x10, task1.eventMask1); 70 | CuAssertIntEquals(tc, 0, os_task_waitEvent(&task1, &eventMask)); 71 | CuAssertUIntEquals(tc, 0x10, eventMask); 72 | os_task_destroy(&task1); 73 | } 74 | 75 | 76 | THREAD_PROTO(test_task, arg) 77 | { 78 | THREAD_RETURN(0); 79 | } 80 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 42 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 86 | 87 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | make 122 | 123 | all 124 | true 125 | true 126 | true 127 | 128 | 129 | make 130 | 131 | clean 132 | true 133 | true 134 | true 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug 2 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | amber_runtime_test 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | 26 | 27 | 28 | adt/inc 29 | 2 30 | PARENT-4-PROJECT_LOC/adt/inc 31 | 32 | 33 | adt/src 34 | 2 35 | PARENT-4-PROJECT_LOC/adt/src 36 | 37 | 38 | msocket/inc 39 | 2 40 | PARENT-4-PROJECT_LOC/msocket/inc 41 | 42 | 43 | msocket/src 44 | 2 45 | PARENT-4-PROJECT_LOC/msocket/src 46 | 47 | 48 | os/inc 49 | 2 50 | PARENT-3-PROJECT_LOC/os/inc 51 | 52 | 53 | os/src 54 | 2 55 | PARENT-3-PROJECT_LOC/os/src 56 | 57 | 58 | util/inc 59 | 2 60 | PARENT-3-PROJECT_LOC/util/inc 61 | 62 | 63 | util/src 64 | 2 65 | PARENT-3-PROJECT_LOC/util/src 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/cfg/RteApi.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file RteApi.c 3 | * \author Conny Gustafsson 4 | * \date 2017-10-14 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | ////////////////////////////////////////////////////////////////////////////// 27 | // INCLUDES 28 | ////////////////////////////////////////////////////////////////////////////// 29 | #include "RteApi.h" 30 | #include "os.h" 31 | 32 | ////////////////////////////////////////////////////////////////////////////// 33 | // PRIVATE CONSTANTS AND DATA TYPES 34 | ////////////////////////////////////////////////////////////////////////////// 35 | static Rte_ModeType_EcuM_Mode m_EcuM_Mode; 36 | ////////////////////////////////////////////////////////////////////////////// 37 | // PRIVATE FUNCTION PROTOTYPES 38 | ////////////////////////////////////////////////////////////////////////////// 39 | 40 | ////////////////////////////////////////////////////////////////////////////// 41 | // PUBLIC VARIABLES 42 | ////////////////////////////////////////////////////////////////////////////// 43 | 44 | ////////////////////////////////////////////////////////////////////////////// 45 | // PRIVATE VARIABLES 46 | ////////////////////////////////////////////////////////////////////////////// 47 | 48 | ////////////////////////////////////////////////////////////////////////////// 49 | // PUBLIC FUNCTIONS 50 | ////////////////////////////////////////////////////////////////////////////// 51 | void Rte_Start(void) 52 | { 53 | 54 | } 55 | 56 | void Rte_SetMode_EcuM_Mode(Rte_ModeType_EcuM_Mode newMode) 57 | { 58 | Rte_ModeType_EcuM_Mode previousMode = m_EcuM_Mode; 59 | m_EcuM_Mode = newMode; 60 | if ( (previousMode == RTE_MODE_EcuM_Mode_RUN) && (newMode != RTE_MODE_EcuM_Mode_RUN) ) 61 | { 62 | os_task_onExit_EcuM_Mode_RUN(); 63 | } 64 | else if ( (previousMode != RTE_MODE_EcuM_Mode_RUN) && (newMode == RTE_MODE_EcuM_Mode_RUN) ) 65 | { 66 | os_task_onEntry_EcuM_Mode_RUN(); 67 | } 68 | else 69 | { 70 | 71 | } 72 | } 73 | ////////////////////////////////////////////////////////////////////////////// 74 | // PRIVATE FUNCTIONS 75 | ////////////////////////////////////////////////////////////////////////////// 76 | 77 | 78 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/cfg/RteApi.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file RteApi.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-14 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef RTE_API_H 27 | #define RTE_API_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #include "Platform_Types.h" 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////////// 36 | // PUBLIC CONSTANTS AND DATA TYPES 37 | ////////////////////////////////////////////////////////////////////////////// 38 | typedef uint8 Rte_ModeType_EcuM_Mode; 39 | 40 | # define RTE_MODE_EcuM_Mode_POST_RUN ((Rte_ModeType_EcuM_Mode)0) 41 | # define RTE_MODE_EcuM_Mode_RUN ((Rte_ModeType_EcuM_Mode)1) 42 | # define RTE_MODE_EcuM_Mode_SHUTDOWN ((Rte_ModeType_EcuM_Mode)2) 43 | # define RTE_MODE_EcuM_Mode_SLEEP ((Rte_ModeType_EcuM_Mode)3) 44 | # define RTE_MODE_EcuM_Mode_STARTUP ((Rte_ModeType_EcuM_Mode)4) 45 | # define RTE_MODE_EcuM_Mode_WAKE_SLEEP ((Rte_ModeType_EcuM_Mode)5) 46 | 47 | ////////////////////////////////////////////////////////////////////////////// 48 | // PUBLIC VARIABLES 49 | ////////////////////////////////////////////////////////////////////////////// 50 | 51 | ////////////////////////////////////////////////////////////////////////////// 52 | // PUBLIC FUNCTION PROTOTYPES 53 | ////////////////////////////////////////////////////////////////////////////// 54 | void Rte_Start(void); 55 | void Rte_SetMode_EcuM_Mode(Rte_ModeType_EcuM_Mode newMode); 56 | 57 | #endif //RTE_API_H 58 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/cfg/RteTask.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file RteTask.c 3 | * \author Conny Gustafsson 4 | * \date 2017-10-13 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | ////////////////////////////////////////////////////////////////////////////// 27 | // INCLUDES 28 | ////////////////////////////////////////////////////////////////////////////// 29 | #include 30 | #include "os.h" 31 | #include "os_event_cfg.h" 32 | #include "os_task_cfg.h" 33 | #include "systime.h" 34 | 35 | ////////////////////////////////////////////////////////////////////////////// 36 | // PRIVATE CONSTANTS AND DATA TYPES 37 | ////////////////////////////////////////////////////////////////////////////// 38 | 39 | ////////////////////////////////////////////////////////////////////////////// 40 | // PRIVATE FUNCTION PROTOTYPES 41 | ////////////////////////////////////////////////////////////////////////////// 42 | 43 | ////////////////////////////////////////////////////////////////////////////// 44 | // PUBLIC VARIABLES 45 | ////////////////////////////////////////////////////////////////////////////// 46 | 47 | ////////////////////////////////////////////////////////////////////////////// 48 | // PRIVATE VARIABLES 49 | ////////////////////////////////////////////////////////////////////////////// 50 | 51 | ////////////////////////////////////////////////////////////////////////////// 52 | // PUBLIC FUNCTIONS 53 | ////////////////////////////////////////////////////////////////////////////// 54 | OS_TASK_HANDLER(Test_Task1, arg) 55 | { 56 | bool isRunning = true; 57 | os_task_t *self = (os_task_t*)arg; 58 | if (self == 0) 59 | { 60 | fprintf(stderr, "Error: Test_Task1 called with null argument\n"); 61 | THREAD_RETURN(0); 62 | } 63 | 64 | printf("Test_Task1: entering main loop\n"); 65 | while (isRunning == true) 66 | { 67 | uint32_t eventMask; 68 | int8_t result = os_task_waitEvent(self, &eventMask); 69 | if (result == 0) 70 | { 71 | if (eventMask & EVENT_MASK_Test_Task1_TMT_5ms) 72 | { 73 | //printf("%u: EVENT_MASK_Test_Task1_TMT_5ms\n", (unsigned int) SysTime_getTime()); 74 | } 75 | if (eventMask & EVENT_MASK_Test_Task1_TMT_10ms) 76 | { 77 | //printf("%u: EVENT_MASK_Test_Task1_TMT_10ms\n", (unsigned int) SysTime_getTime()); 78 | } 79 | if (eventMask & EVENT_MASK_Test_Task1_TMT_20ms) 80 | { 81 | //printf("%u: EVENT_MASK_Test_Task1_TMT_20ms\n", (unsigned int) SysTime_getTime()); 82 | } 83 | if (eventMask & EVENT_MASK_Test_Task1_OnEntry_EcuM_Mode_RUN) 84 | { 85 | printf("EVENT_MASK_Test_Task1_OnEntry_EcuM_Mode_RUN\n"); 86 | } 87 | if (eventMask & EVENT_MASK_Test_Task1_OnExit_EcuM_Mode_RUN) 88 | { 89 | printf("EVENT_MASK_Test_Task1_OnExit_EcuM_Mode_RUN\n"); 90 | } 91 | } 92 | else if(result > 0) 93 | { 94 | printf("Test_Task1_QuitEvent\n"); 95 | isRunning = false; 96 | } 97 | else 98 | { 99 | fprintf(stderr, "os_task_waitEvent failed\n"); 100 | } 101 | } 102 | THREAD_RETURN(0); 103 | } 104 | 105 | OS_TASK_HANDLER(Test_Task2, arg) 106 | { 107 | bool isRunning = true; 108 | os_task_t *self = (os_task_t*)arg; 109 | if (self == 0) 110 | { 111 | fprintf(stderr, "Error: Test_Task1 called with null argument\n"); 112 | THREAD_RETURN(0); 113 | } 114 | 115 | printf("Test_Task2: entering main loop\n"); 116 | while (isRunning == true) 117 | { 118 | uint32_t eventMask; 119 | int8_t result = os_task_waitEvent(self, &eventMask); 120 | if (result == 0) 121 | { 122 | if (eventMask & EVENT_MASK_Test_Task2_TMT_20ms) 123 | { 124 | // printf("%u: EVENT_MASK_Test_Task2_TMT_20ms\n", (unsigned int) SysTime_getTime()); 125 | } 126 | if (eventMask & EVENT_MASK_Test_Task2_TMT_50ms) 127 | { 128 | // printf("%u: EVENT_MASK_Test_Task2_TMT_50ms\n", (unsigned int) SysTime_getTime()); 129 | } 130 | if (eventMask & EVENT_MASK_Test_Task2_TMT_100ms) 131 | { 132 | // printf("%u: EVENT_MASK_Test_Task2_TMT_100ms\n", (unsigned int) SysTime_getTime()); 133 | } 134 | if (eventMask & EVENT_MASK_Test_Task1_OnEntry_EcuM_Mode_RUN) 135 | { 136 | printf("EVENT_MASK_Test_Task1_OnEntry_EcuM_Mode_RUN\n"); 137 | } 138 | if (eventMask & EVENT_MASK_Test_Task1_OnExit_EcuM_Mode_RUN) 139 | { 140 | printf("EVENT_MASK_Test_Task1_OnExit_EcuM_Mode_RUN\n"); 141 | } 142 | 143 | } 144 | else if(result > 0) 145 | { 146 | printf("Test_Task2_QuitEvent\n"); 147 | isRunning = false; 148 | } 149 | else 150 | { 151 | fprintf(stderr, "os_task_waitEvent failed\n"); 152 | } 153 | } 154 | THREAD_RETURN(0); 155 | } 156 | ////////////////////////////////////////////////////////////////////////////// 157 | // PRIVATE FUNCTIONS 158 | ////////////////////////////////////////////////////////////////////////////// 159 | 160 | 161 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/cfg/os_event_cfg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_events_cfg.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-13 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef OS_EVENTS_CFG_H 27 | #define OS_EVENTS_CFG_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #include "Platform_Types.h" 33 | 34 | ////////////////////////////////////////////////////////////////////////////// 35 | // PUBLIC CONSTANTS AND DATA TYPES 36 | ////////////////////////////////////////////////////////////////////////////// 37 | #define EVENT_MASK_Test_Task1_TMT_5ms ((uint32) 0x00000001) 38 | #define EVENT_MASK_Test_Task1_TMT_10ms ((uint32) 0x00000002) 39 | #define EVENT_MASK_Test_Task1_TMT_20ms ((uint32) 0x00000004) 40 | #define EVENT_MASK_Test_Task1_OnEntry_EcuM_Mode_RUN ((uint32) 0x00000008) 41 | #define EVENT_MASK_Test_Task1_OnExit_EcuM_Mode_RUN ((uint32) 0x00000010) 42 | 43 | #define OS_NUM_ALARMS_Test_Task1 3 44 | #define OS_NUM_EVENTS_Test_Task1 5 45 | 46 | 47 | #define EVENT_MASK_Test_Task2_TMT_20ms ((uint32) 0x00000001) 48 | #define EVENT_MASK_Test_Task2_TMT_50ms ((uint32) 0x00000002) 49 | #define EVENT_MASK_Test_Task2_TMT_100ms ((uint32) 0x00000004) 50 | #define EVENT_MASK_Test_Task2_OnEntry_EcuM_Mode_RUN ((uint32) 0x00000008) 51 | #define EVENT_MASK_Test_Task2_OnExit_EcuM_Mode_RUN ((uint32) 0x00000010) 52 | 53 | #define OS_NUM_ALARMS_Test_Task2 3 54 | #define OS_NUM_EVENTS_Test_Task2 5 55 | 56 | 57 | ////////////////////////////////////////////////////////////////////////////// 58 | // PUBLIC VARIABLES 59 | ////////////////////////////////////////////////////////////////////////////// 60 | 61 | ////////////////////////////////////////////////////////////////////////////// 62 | // PUBLIC FUNCTION PROTOTYPES 63 | ////////////////////////////////////////////////////////////////////////////// 64 | 65 | 66 | #endif //OS_EVENTS_CFG_H 67 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/cfg/os_task_cfg.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_task_cfg.c 3 | * \author Conny Gustafsson 4 | * \date 2017-10-13 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | ////////////////////////////////////////////////////////////////////////////// 27 | // INCLUDES 28 | ////////////////////////////////////////////////////////////////////////////// 29 | #include "os_event_cfg.h" 30 | #include "os_task_cfg.h" 31 | 32 | ////////////////////////////////////////////////////////////////////////////// 33 | // PRIVATE CONSTANTS AND DATA TYPES 34 | ////////////////////////////////////////////////////////////////////////////// 35 | 36 | ////////////////////////////////////////////////////////////////////////////// 37 | // FORWARD DECLARATIONS 38 | ////////////////////////////////////////////////////////////////////////////// 39 | 40 | ////////////////////////////////////////////////////////////////////////////// 41 | // PRIVATE VARIABLES 42 | ////////////////////////////////////////////////////////////////////////////// 43 | static os_task_t m_os_task_Test_Task1; 44 | static os_task_t m_os_task_Test_Task2; 45 | 46 | 47 | ////////////////////////////////////////////////////////////////////////////// 48 | // PUBLIC VARIABLES 49 | ////////////////////////////////////////////////////////////////////////////// 50 | const os_alarm_cfg_t os_alarm_cfg_Test_Task1[OS_NUM_ALARMS_Test_Task1] = { 51 | //OS Task, Event Mask, Init Delay (ms), Period (ms) 52 | {&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_TMT_5ms, 0u, 5u}, 53 | {&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_TMT_10ms, 0u, 10u}, 54 | {&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_TMT_20ms, 0u, 20u}, 55 | }; 56 | 57 | const os_alarm_cfg_t os_alarm_cfg_Test_Task2[OS_NUM_ALARMS_Test_Task2] = { 58 | //OS Task, Event ID, Init Delay (ms), Period (ms) 59 | {&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_TMT_20ms, 0u, 20u}, 60 | {&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_TMT_50ms, 0u, 50u}, 61 | {&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_TMT_100ms, 0u, 100u}, 62 | }; 63 | 64 | const os_task_elem_t os_task_cfg[OS_NUM_TASKS] = { 65 | //OS Task, TaskHandlerPtr, alarms, number of alarms 66 | {&m_os_task_Test_Task1, Test_Task1, &os_alarm_cfg_Test_Task1[0], OS_NUM_ALARMS_Test_Task1}, 67 | {&m_os_task_Test_Task2, Test_Task2, &os_alarm_cfg_Test_Task2[0], OS_NUM_ALARMS_Test_Task2}, 68 | }; 69 | 70 | os_cfg_t g_os_cfg = { 71 | &os_task_cfg[0], 72 | OS_NUM_TASKS, 73 | 0, 74 | 0 75 | }; 76 | 77 | ////////////////////////////////////////////////////////////////////////////// 78 | // PRIVATE VARIABLES 79 | ////////////////////////////////////////////////////////////////////////////// 80 | 81 | ////////////////////////////////////////////////////////////////////////////// 82 | // PUBLIC FUNCTIONS 83 | ////////////////////////////////////////////////////////////////////////////// 84 | void os_task_onExit_EcuM_Mode_RUN(void) 85 | { 86 | os_task_setEvent(&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_OnExit_EcuM_Mode_RUN); 87 | os_task_setEvent(&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_OnExit_EcuM_Mode_RUN); 88 | } 89 | 90 | void os_task_onEntry_EcuM_Mode_RUN(void) 91 | { 92 | os_task_setEvent(&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_OnEntry_EcuM_Mode_RUN); 93 | os_task_setEvent(&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_OnEntry_EcuM_Mode_RUN); 94 | } 95 | 96 | ////////////////////////////////////////////////////////////////////////////// 97 | // PRIVATE FUNCTIONS 98 | ////////////////////////////////////////////////////////////////////////////// 99 | 100 | 101 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/cfg/os_task_cfg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_task_cfg.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-13 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef OS_TASK_CFG_H 27 | #define OS_TASK_CFG_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #include "os_types.h" 33 | #include "os_task.h" 34 | 35 | ////////////////////////////////////////////////////////////////////////////// 36 | // PUBLIC CONSTANTS AND DATA TYPES 37 | ////////////////////////////////////////////////////////////////////////////// 38 | #define OS_NUM_TASKS 2 39 | 40 | ////////////////////////////////////////////////////////////////////////////// 41 | // PUBLIC VARIABLES 42 | ////////////////////////////////////////////////////////////////////////////// 43 | 44 | ////////////////////////////////////////////////////////////////////////////// 45 | // PUBLIC FUNCTION PROTOTYPES 46 | ////////////////////////////////////////////////////////////////////////////// 47 | OS_TASK_HANDLER(Test_Task1, arg); 48 | OS_TASK_HANDLER(Test_Task2, arg); 49 | extern os_cfg_t g_os_cfg; 50 | void os_task_onExit_EcuM_Mode_RUN(void); 51 | void os_task_onEntry_EcuM_Mode_RUN(void); 52 | 53 | #endif //OS_TASK_CFG_H 54 | -------------------------------------------------------------------------------- /projects/eclipse/amber_runtime_test/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "systime.h" 4 | #include "os.h" 5 | #include "osmacro.h" 6 | #include "RteApi.h" 7 | 8 | int main(int argc, char **argv) 9 | { 10 | int i; 11 | SysTime_init(1); 12 | os_init(&g_os_cfg); 13 | os_start(); 14 | SLEEP(100); 15 | Rte_SetMode_EcuM_Mode(RTE_MODE_EcuM_Mode_RUN); 16 | for(i=0;i<5;i++) 17 | { 18 | SLEEP(1000); 19 | } 20 | Rte_SetMode_EcuM_Mode(RTE_MODE_EcuM_Mode_SHUTDOWN); 21 | SLEEP(100); 22 | printf("shutting down\n"); 23 | os_stop(); 24 | os_shutdown(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /projects/eclipse/amber_simulation_test/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 42 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 87 | 88 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | make 123 | 124 | all 125 | true 126 | true 127 | true 128 | 129 | 130 | make 131 | 132 | clean 133 | true 134 | true 135 | true 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /projects/eclipse/amber_simulation_test/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug 2 | -------------------------------------------------------------------------------- /projects/eclipse/amber_simulation_test/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | amber_simulation_test 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | 26 | 27 | 28 | adt/inc 29 | 2 30 | PARENT-4-PROJECT_LOC/adt/inc 31 | 32 | 33 | adt/src 34 | 2 35 | PARENT-4-PROJECT_LOC/adt/src 36 | 37 | 38 | autosar/inc 39 | 2 40 | PARENT-3-PROJECT_LOC/autosar/inc 41 | 42 | 43 | msocket/inc 44 | 2 45 | PARENT-4-PROJECT_LOC/msocket/inc 46 | 47 | 48 | msocket/src 49 | 2 50 | PARENT-4-PROJECT_LOC/msocket/src 51 | 52 | 53 | os/inc 54 | 2 55 | PARENT-3-PROJECT_LOC/os/inc 56 | 57 | 58 | os/src 59 | 2 60 | PARENT-3-PROJECT_LOC/os/src 61 | 62 | 63 | util/inc 64 | 2 65 | PARENT-3-PROJECT_LOC/util/inc 66 | 67 | 68 | util/src 69 | 2 70 | PARENT-3-PROJECT_LOC/util/src 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /projects/eclipse/amber_simulation_test/cfg/RteTask.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file RteTask.c 3 | * \author Conny Gustafsson 4 | * \date 2017-10-13 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | ////////////////////////////////////////////////////////////////////////////// 27 | // INCLUDES 28 | ////////////////////////////////////////////////////////////////////////////// 29 | #include 30 | #include "os.h" 31 | #include "os_event_cfg.h" 32 | #include "os_task_cfg.h" 33 | #include "systime.h" 34 | 35 | ////////////////////////////////////////////////////////////////////////////// 36 | // PRIVATE CONSTANTS AND DATA TYPES 37 | ////////////////////////////////////////////////////////////////////////////// 38 | 39 | ////////////////////////////////////////////////////////////////////////////// 40 | // PRIVATE FUNCTION PROTOTYPES 41 | ////////////////////////////////////////////////////////////////////////////// 42 | 43 | ////////////////////////////////////////////////////////////////////////////// 44 | // PUBLIC VARIABLES 45 | ////////////////////////////////////////////////////////////////////////////// 46 | 47 | ////////////////////////////////////////////////////////////////////////////// 48 | // PRIVATE VARIABLES 49 | ////////////////////////////////////////////////////////////////////////////// 50 | 51 | ////////////////////////////////////////////////////////////////////////////// 52 | // PUBLIC FUNCTIONS 53 | ////////////////////////////////////////////////////////////////////////////// 54 | OS_TASK_HANDLER(Test_Task1, arg) 55 | { 56 | bool isRunning = true; 57 | os_task_t *self = (os_task_t*)arg; 58 | if (self == 0) 59 | { 60 | fprintf(stderr, "Error: Test_Task1 called with null argument\n"); 61 | THREAD_RETURN(0); 62 | } 63 | 64 | printf("Test_Task1: entering main loop\n"); 65 | while (isRunning == true) 66 | { 67 | uint32_t eventMask; 68 | int8_t result = os_task_waitEvent(self, &eventMask); 69 | if (result == 0) 70 | { 71 | if (eventMask & EVENT_MASK_Test_Task1_TMT_5ms) 72 | { 73 | //printf("%u: EVENT_MASK_Test_Task1_TMT_5ms\n", (unsigned int) SysTime_getTime()); 74 | } 75 | if (eventMask & EVENT_MASK_Test_Task1_TMT_10ms) 76 | { 77 | //printf("%u: EVENT_MASK_Test_Task1_TMT_10ms\n", (unsigned int) SysTime_getTime()); 78 | } 79 | if (eventMask & EVENT_MASK_Test_Task1_TMT_20ms) 80 | { 81 | //printf("%u: EVENT_MASK_Test_Task1_TMT_20ms\n", (unsigned int) SysTime_getTime()); 82 | } 83 | } 84 | else if(result > 0) 85 | { 86 | printf("Test_Task1_QuitEvent\n"); 87 | isRunning = false; 88 | } 89 | else 90 | { 91 | fprintf(stderr, "os_task_waitEvent failed\n"); 92 | } 93 | } 94 | THREAD_RETURN(0); 95 | } 96 | 97 | OS_TASK_HANDLER(Test_Task2, arg) 98 | { 99 | bool isRunning = true; 100 | os_task_t *self = (os_task_t*)arg; 101 | if (self == 0) 102 | { 103 | fprintf(stderr, "Error: Test_Task1 called with null argument\n"); 104 | THREAD_RETURN(0); 105 | } 106 | 107 | printf("Test_Task2: entering main loop\n"); 108 | while (isRunning == true) 109 | { 110 | uint32_t eventMask; 111 | int8_t result = os_task_waitEvent(self, &eventMask); 112 | if (result == 0) 113 | { 114 | if (eventMask & EVENT_MASK_Test_Task2_TMT_20ms) 115 | { 116 | //printf("%u: EVENT_MASK_Test_Task2_TMT_20ms\n", (unsigned int) SysTime_getTime()); 117 | } 118 | if (eventMask & EVENT_MASK_Test_Task2_TMT_50ms) 119 | { 120 | //printf("%u: EVENT_MASK_Test_Task2_TMT_50ms\n", (unsigned int) SysTime_getTime()); 121 | } 122 | if (eventMask & EVENT_MASK_Test_Task2_TMT_100ms) 123 | { 124 | //printf("%u: EVENT_MASK_Test_Task2_TMT_100ms\n", (unsigned int) SysTime_getTime()); 125 | } 126 | } 127 | else if(result > 0) 128 | { 129 | printf("Test_Task2_QuitEvent\n"); 130 | isRunning = false; 131 | } 132 | else 133 | { 134 | fprintf(stderr, "os_task_waitEvent failed\n"); 135 | } 136 | } 137 | THREAD_RETURN(0); 138 | } 139 | ////////////////////////////////////////////////////////////////////////////// 140 | // PRIVATE FUNCTIONS 141 | ////////////////////////////////////////////////////////////////////////////// 142 | 143 | 144 | -------------------------------------------------------------------------------- /projects/eclipse/amber_simulation_test/cfg/os_event_cfg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_events_cfg.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-13 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef OS_EVENTS_CFG_H 27 | #define OS_EVENTS_CFG_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #include "Platform_Types.h" 33 | 34 | ////////////////////////////////////////////////////////////////////////////// 35 | // PUBLIC CONSTANTS AND DATA TYPES 36 | ////////////////////////////////////////////////////////////////////////////// 37 | #define EVENT_MASK_Test_Task1_TMT_5ms ((uint32) 0x00000001) 38 | #define EVENT_MASK_Test_Task1_TMT_10ms ((uint32) 0x00000002) 39 | #define EVENT_MASK_Test_Task1_TMT_20ms ((uint32) 0x00000004) 40 | #define EVENT_MASK_Test_Task1_OnEntry_EcuM_Mode_RUN ((uint32) 0x00000008) 41 | #define EVENT_MASK_Test_Task1_OnExit_EcuM_Mode_RUN ((uint32) 0x00000010) 42 | 43 | #define OS_NUM_ALARMS_Test_Task1 3 44 | #define OS_NUM_EVENTS_Test_Task1 5 45 | 46 | 47 | #define EVENT_MASK_Test_Task2_TMT_20ms ((uint32) 0x00000001) 48 | #define EVENT_MASK_Test_Task2_TMT_50ms ((uint32) 0x00000002) 49 | #define EVENT_MASK_Test_Task2_TMT_100ms ((uint32) 0x00000004) 50 | #define EVENT_MASK_Test_Task2_OnEntry_EcuM_Mode_RUN ((uint32) 0x00000008) 51 | #define EVENT_MASK_Test_Task2_OnExit_EcuM_Mode_RUN ((uint32) 0x00000010) 52 | 53 | #define OS_NUM_ALARMS_Test_Task2 3 54 | #define OS_NUM_EVENTS_Test_Task2 5 55 | 56 | 57 | ////////////////////////////////////////////////////////////////////////////// 58 | // PUBLIC VARIABLES 59 | ////////////////////////////////////////////////////////////////////////////// 60 | 61 | ////////////////////////////////////////////////////////////////////////////// 62 | // PUBLIC FUNCTION PROTOTYPES 63 | ////////////////////////////////////////////////////////////////////////////// 64 | 65 | 66 | #endif //OS_EVENTS_CFG_H 67 | -------------------------------------------------------------------------------- /projects/eclipse/amber_simulation_test/cfg/os_task_cfg.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_task_cfg.c 3 | * \author Conny Gustafsson 4 | * \date 2017-10-13 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | ////////////////////////////////////////////////////////////////////////////// 27 | // INCLUDES 28 | ////////////////////////////////////////////////////////////////////////////// 29 | #include "os_event_cfg.h" 30 | #include "os_task_cfg.h" 31 | 32 | ////////////////////////////////////////////////////////////////////////////// 33 | // PRIVATE CONSTANTS AND DATA TYPES 34 | ////////////////////////////////////////////////////////////////////////////// 35 | 36 | ////////////////////////////////////////////////////////////////////////////// 37 | // FORWARD DECLARATIONS 38 | ////////////////////////////////////////////////////////////////////////////// 39 | 40 | ////////////////////////////////////////////////////////////////////////////// 41 | // PRIVATE VARIABLES 42 | ////////////////////////////////////////////////////////////////////////////// 43 | static os_task_t m_os_task_Test_Task1; 44 | static os_task_t m_os_task_Test_Task2; 45 | 46 | 47 | ////////////////////////////////////////////////////////////////////////////// 48 | // PUBLIC VARIABLES 49 | ////////////////////////////////////////////////////////////////////////////// 50 | const os_alarm_cfg_t os_alarm_cfg_Test_Task1[OS_NUM_ALARMS_Test_Task1] = { 51 | //OS Task, Event Mask, Init Delay (ms), Period (ms) 52 | {&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_TMT_5ms, 0u, 5u}, 53 | {&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_TMT_10ms, 0u, 10u}, 54 | {&m_os_task_Test_Task1, EVENT_MASK_Test_Task1_TMT_20ms, 0u, 20u}, 55 | }; 56 | 57 | const os_alarm_cfg_t os_alarm_cfg_Test_Task2[OS_NUM_ALARMS_Test_Task2] = { 58 | //OS Task, Event ID, Init Delay (ms), Period (ms) 59 | {&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_TMT_20ms, 0u, 20u}, 60 | {&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_TMT_50ms, 0u, 50u}, 61 | {&m_os_task_Test_Task2, EVENT_MASK_Test_Task2_TMT_100ms, 0u, 100u}, 62 | }; 63 | 64 | const os_task_elem_t os_task_cfg[OS_NUM_TASKS] = { 65 | //OS Task, TaskHandlerPtr, alarms, number of alarms 66 | {&m_os_task_Test_Task1, Test_Task1, &os_alarm_cfg_Test_Task1[0], OS_NUM_ALARMS_Test_Task1}, 67 | {&m_os_task_Test_Task2, Test_Task2, &os_alarm_cfg_Test_Task2[0], OS_NUM_ALARMS_Test_Task2}, 68 | }; 69 | 70 | os_cfg_t g_os_cfg = { 71 | &os_task_cfg[0], 72 | OS_NUM_TASKS, 73 | 0, 74 | 0 75 | }; 76 | 77 | ////////////////////////////////////////////////////////////////////////////// 78 | // PRIVATE VARIABLES 79 | ////////////////////////////////////////////////////////////////////////////// 80 | 81 | ////////////////////////////////////////////////////////////////////////////// 82 | // PUBLIC FUNCTIONS 83 | ////////////////////////////////////////////////////////////////////////////// 84 | 85 | ////////////////////////////////////////////////////////////////////////////// 86 | // PRIVATE FUNCTIONS 87 | ////////////////////////////////////////////////////////////////////////////// 88 | 89 | 90 | -------------------------------------------------------------------------------- /projects/eclipse/amber_simulation_test/cfg/os_task_cfg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_task_cfg.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-13 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef OS_TASK_CFG_H 27 | #define OS_TASK_CFG_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #include "os_types.h" 33 | #include "os_task.h" 34 | 35 | ////////////////////////////////////////////////////////////////////////////// 36 | // PUBLIC CONSTANTS AND DATA TYPES 37 | ////////////////////////////////////////////////////////////////////////////// 38 | #define OS_NUM_TASKS 2 39 | 40 | ////////////////////////////////////////////////////////////////////////////// 41 | // PUBLIC VARIABLES 42 | ////////////////////////////////////////////////////////////////////////////// 43 | 44 | ////////////////////////////////////////////////////////////////////////////// 45 | // PUBLIC FUNCTION PROTOTYPES 46 | ////////////////////////////////////////////////////////////////////////////// 47 | OS_TASK_HANDLER(Test_Task1, arg); 48 | OS_TASK_HANDLER(Test_Task2, arg); 49 | extern os_cfg_t g_os_cfg; 50 | 51 | #endif //OS_TASK_CFG_H 52 | -------------------------------------------------------------------------------- /projects/eclipse/amber_simulation_test/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "systime.h" 4 | #include "os.h" 5 | #include "osmacro.h" 6 | 7 | int main(int argc, char **argv) 8 | { 9 | SysTime_initSimulated(); 10 | os_init(&g_os_cfg); 11 | os_start(); 12 | SLEEP(10); 13 | int i; 14 | for(i=0;i<200;i++) 15 | { 16 | SysTime_tick(1); 17 | // SLEEP(10); 18 | os_scheduler_run(); 19 | SLEEP(1); 20 | } 21 | //SLEEP(10); 22 | os_stop(); 23 | //SLEEP(10); 24 | os_shutdown(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /projects/eclipse/amber_unit_test/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 36 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 89 | 90 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | make 128 | 129 | all 130 | true 131 | true 132 | true 133 | 134 | 135 | make 136 | 137 | clean 138 | true 139 | true 140 | true 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /projects/eclipse/amber_unit_test/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug 2 | -------------------------------------------------------------------------------- /projects/eclipse/amber_unit_test/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | amber_unit_test 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | 26 | 27 | 28 | cutest 29 | 2 30 | PARENT-3-PROJECT_LOC/cutest 31 | 32 | 33 | os 34 | 2 35 | PARENT-3-PROJECT_LOC/os 36 | 37 | 38 | util 39 | 2 40 | PARENT-3-PROJECT_LOC/util 41 | 42 | 43 | adt/inc 44 | 2 45 | PARENT-4-PROJECT_LOC/adt/inc 46 | 47 | 48 | adt/src 49 | 2 50 | PARENT-4-PROJECT_LOC/adt/src 51 | 52 | 53 | msocket/inc 54 | 2 55 | PARENT-4-PROJECT_LOC/msocket/inc 56 | 57 | 58 | msocket/src 59 | 2 60 | PARENT-4-PROJECT_LOC/msocket/src 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /projects/eclipse/amber_unit_test/cfg/adt_ringbuf_cfg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file adt_ringbuf_cfg.h 3 | * \author Conny Gustafsson 4 | * \date 2013-12-19 5 | * \brief Ringbuffer data structure 6 | * 7 | * Copyright (c) 2013-2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | 27 | /*** 28 | * This is a template file, copy and rename this file to adt_ringbuf_cfg.h. 29 | * Users should copy this file to the file name adt_ringbuf_cfg.h and place it amongst local project includes. 30 | */ 31 | 32 | #ifndef ADT_RINGBUF_CFG_H__ 33 | #define ADT_RINGBUF_CFG_H__ 34 | 35 | #define RBFS_ENABLE 1 //ringbuffer static (fixed sized blocks) 36 | #define RBFD_ENABLE 0 //ringbuffer dynamic (dynamically sized blocks) 37 | #define RBFU16_ENABLE 1 //special ringbuffer for uint16 values 38 | 39 | #endif //RINGBUF_CFG_H__ 40 | -------------------------------------------------------------------------------- /projects/eclipse/amber_unit_test/cfg/os_task_cfg.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_task_cfg.c 3 | * \author Conny Gustafsson 4 | * \date 2017-10-12 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | ////////////////////////////////////////////////////////////////////////////// 27 | // INCLUDES 28 | ////////////////////////////////////////////////////////////////////////////// 29 | #include "os_task_cfg.h" 30 | 31 | ////////////////////////////////////////////////////////////////////////////// 32 | // PRIVATE CONSTANTS AND DATA TYPES 33 | ////////////////////////////////////////////////////////////////////////////// 34 | 35 | ////////////////////////////////////////////////////////////////////////////// 36 | // PRIVATE FUNCTION PROTOTYPES 37 | ////////////////////////////////////////////////////////////////////////////// 38 | 39 | ////////////////////////////////////////////////////////////////////////////// 40 | // PRIVATE VARIABLES 41 | ////////////////////////////////////////////////////////////////////////////// 42 | //static os_task_t m_os_task_Service_Task; 43 | //static os_task_t m_os_task_App_Task; 44 | 45 | ////////////////////////////////////////////////////////////////////////////// 46 | // PUBLIC VARIABLES 47 | ////////////////////////////////////////////////////////////////////////////// 48 | /*os_task_info_t g_os_task_cfg[OS_NUM_TASKS] = { 49 | {&m_os_task_Service_Task, Service_Task}, 50 | {&m_os_task_App_Task, App_Task} 51 | };*/ 52 | 53 | ////////////////////////////////////////////////////////////////////////////// 54 | // PUBLIC FUNCTIONS 55 | ////////////////////////////////////////////////////////////////////////////// 56 | 57 | ////////////////////////////////////////////////////////////////////////////// 58 | // PRIVATE FUNCTIONS 59 | ////////////////////////////////////////////////////////////////////////////// 60 | 61 | 62 | -------------------------------------------------------------------------------- /projects/eclipse/amber_unit_test/cfg/os_task_cfg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file os_task_cfg.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-12 5 | * \brief Description 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef OS_TASK_CFG_H 27 | #define OS_TASK_CFG_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #include "os_types.h" 33 | 34 | ////////////////////////////////////////////////////////////////////////////// 35 | // PUBLIC CONSTANTS AND DATA TYPES 36 | ////////////////////////////////////////////////////////////////////////////// 37 | #define OS_NUM_TASKS 2 38 | 39 | ////////////////////////////////////////////////////////////////////////////// 40 | // PUBLIC VARIABLES 41 | ////////////////////////////////////////////////////////////////////////////// 42 | 43 | ////////////////////////////////////////////////////////////////////////////// 44 | // PUBLIC FUNCTION PROTOTYPES 45 | ////////////////////////////////////////////////////////////////////////////// 46 | OS_TASK_HANDLER(Service_Task, arg); 47 | OS_TASK_HANDLER(App_Task, arg); 48 | 49 | #endif //OS_TASK_CFG_H 50 | -------------------------------------------------------------------------------- /projects/eclipse/amber_unit_test/test_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CuTest.h" 3 | 4 | 5 | CuSuite* testsuite_os_task(void); 6 | CuSuite* testsuite_os_core(void); 7 | 8 | void RunAllTests(void) 9 | { 10 | CuString *output = CuStringNew(); 11 | CuSuite* suite = CuSuiteNew(); 12 | 13 | CuSuiteAddSuite(suite, testsuite_os_task()); 14 | CuSuiteAddSuite(suite, testsuite_os_core()); 15 | CuSuiteRun(suite); 16 | CuSuiteSummary(suite, output); 17 | CuSuiteDetails(suite, output); 18 | printf("%s\n", output->buffer); 19 | CuSuiteDelete(suite); 20 | CuStringDelete(output); 21 | } 22 | 23 | int main(void) 24 | { 25 | RunAllTests(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /util/inc/priority_queue.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file priority_queue.h 3 | * \author Conny Gustafsson 4 | * \date 2017-10-12 5 | * \brief Custom priority queue implementation that can be used as scheduler 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef OS_PQ_H 27 | #define OS_PQ_H 28 | 29 | ////////////////////////////////////////////////////////////////////////////// 30 | // INCLUDES 31 | ////////////////////////////////////////////////////////////////////////////// 32 | #include "adt_heap.h" 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////////// 36 | // CONSTANTS AND DATA TYPES 37 | ////////////////////////////////////////////////////////////////////////////// 38 | typedef struct priority_queue_tag { 39 | adt_ary_t elements; //strong references to adt_heap_elem_t 40 | int32_t startIndex; 41 | }priority_queue_t; 42 | 43 | ////////////////////////////////////////////////////////////////////////////// 44 | // GLOBAL VARIABLES 45 | ////////////////////////////////////////////////////////////////////////////// 46 | 47 | ////////////////////////////////////////////////////////////////////////////// 48 | // GLOBAL FUNCTION PROTOTYPES 49 | ////////////////////////////////////////////////////////////////////////////// 50 | //constructor/destructor 51 | priority_queue_t* priority_queue_new(void); 52 | void priority_queue_delete(priority_queue_t *self); 53 | void priority_queue_vdelete(void *arg); 54 | void priority_queue_create(priority_queue_t *self); 55 | void priority_queue_destroy(priority_queue_t *self); 56 | 57 | //accessors 58 | void priority_queue_push(priority_queue_t *self, void *pItem, uint32_t u32Priority); 59 | adt_heap_elem_t* priority_queue_pop(priority_queue_t *self); 60 | adt_heap_elem_t* priority_queue_top(priority_queue_t *self); 61 | uint32_t priority_queue_topPriority(priority_queue_t *self); 62 | void *priority_queue_topItem(priority_queue_t *self); 63 | 64 | //special functions 65 | void priority_queue_incrementTopPriority(priority_queue_t *self, uint32_t value); 66 | 67 | 68 | #endif //OS_PQ_H 69 | -------------------------------------------------------------------------------- /util/inc/systime.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file systime.h 3 | * \author Conny Gustafsson 4 | * \date 2013-10-01 5 | * \brief System Time API 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | #ifndef SYS_TIME_H 27 | #define SYS_TIME_H 28 | 29 | 30 | /********************************* Includes **********************************/ 31 | #ifdef USE_PLATFORM_TYPES 32 | #include "Platform_Types.h" 33 | #define _UINT8 uint8 34 | #define _UINT32 uint32 35 | #else 36 | #include 37 | #define _UINT8 uint8_t 38 | #define _UINT32 uint32_t 39 | #endif 40 | 41 | 42 | /**************************** Constants and Types ****************************/ 43 | 44 | /********************************* Functions *********************************/ 45 | #if defined(UNIT_TEST) || defined(SYSTIME_SIMULATED) 46 | void SysTime_initSimulated(void); 47 | void SysTime_tick(_UINT32 tickMs); 48 | #endif 49 | int SysTime_init(_UINT32 tickMs); 50 | 51 | void SysTime_destroy(void); 52 | _UINT8 SysTime_wait(int isBlocking); 53 | _UINT32 SysTime_getTime(void); 54 | void SysTime_reset(void); 55 | 56 | #undef _UINT8 57 | #undef _UINT32 58 | 59 | #endif //SYS_TIME_H 60 | 61 | -------------------------------------------------------------------------------- /util/src/priority_queue.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file priority_queue.c 3 | * \author Conny Gustafsson 4 | * \date 2017-10-12 5 | * \brief Custom priority queue implementation that can be used as scheduler 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | ////////////////////////////////////////////////////////////////////////////// 27 | // INCLUDES 28 | ////////////////////////////////////////////////////////////////////////////// 29 | #include 30 | #include "priority_queue.h" 31 | 32 | ////////////////////////////////////////////////////////////////////////////// 33 | // CONSTANTS AND DATA TYPES 34 | ////////////////////////////////////////////////////////////////////////////// 35 | 36 | ////////////////////////////////////////////////////////////////////////////// 37 | // LOCAL FUNCTION PROTOTYPES 38 | ////////////////////////////////////////////////////////////////////////////// 39 | 40 | 41 | ////////////////////////////////////////////////////////////////////////////// 42 | // GLOBAL VARIABLES 43 | ////////////////////////////////////////////////////////////////////////////// 44 | 45 | ////////////////////////////////////////////////////////////////////////////// 46 | // LOCAL VARIABLES 47 | ////////////////////////////////////////////////////////////////////////////// 48 | 49 | 50 | ////////////////////////////////////////////////////////////////////////////// 51 | // GLOBAL FUNCTIONS 52 | ////////////////////////////////////////////////////////////////////////////// 53 | priority_queue_t* priority_queue_new(void) 54 | { 55 | priority_queue_t *self = (priority_queue_t*) malloc(sizeof(priority_queue_t)); 56 | if (self != (priority_queue_t*) 0) 57 | { 58 | priority_queue_create(self); 59 | } 60 | return self; 61 | } 62 | 63 | void priority_queue_delete(priority_queue_t *self) 64 | { 65 | if (self != 0) 66 | { 67 | priority_queue_destroy(self); 68 | free(self); 69 | } 70 | } 71 | 72 | void priority_queue_vdelete(void *arg) 73 | { 74 | priority_queue_delete((priority_queue_t*) arg); 75 | } 76 | void priority_queue_create(priority_queue_t *self) 77 | { 78 | if (self != 0) 79 | { 80 | adt_ary_create(&self->elements, adt_heap_elem_vdelete); 81 | self->startIndex = 0; 82 | } 83 | } 84 | 85 | void priority_queue_destroy(priority_queue_t *self) 86 | { 87 | if (self != 0) 88 | { 89 | adt_ary_destroy(&self->elements); 90 | } 91 | } 92 | 93 | //accessors 94 | void priority_queue_push(priority_queue_t *self, void *pItem, uint32_t u32Priority) 95 | { 96 | if (self != 0) 97 | { 98 | adt_heap_elem_t *pElem = adt_heap_elem_new(pItem, u32Priority); 99 | if (pElem != 0) 100 | { 101 | adt_ary_push(&self->elements, pElem); 102 | adt_heap_sortUp(&self->elements, adt_ary_length(&self->elements)-1, ADT_MIN_HEAP); 103 | } 104 | } 105 | } 106 | 107 | adt_heap_elem_t* priority_queue_pop(priority_queue_t *self) 108 | { 109 | if (self != 0) 110 | { 111 | void **ppElem; 112 | ppElem = adt_ary_shift(&self->elements); 113 | if (ppElem != 0) 114 | { 115 | return (adt_heap_elem_t*) *ppElem; 116 | } 117 | } 118 | return (adt_heap_elem_t*) 0; 119 | } 120 | 121 | adt_heap_elem_t* priority_queue_top(priority_queue_t *self) 122 | { 123 | if (self != 0) 124 | { 125 | void **ppElem; 126 | ppElem = adt_ary_get(&self->elements, 0); 127 | if (ppElem != 0) 128 | { 129 | return (adt_heap_elem_t*) *ppElem; 130 | } 131 | } 132 | return (adt_heap_elem_t*) 0; 133 | } 134 | 135 | uint32_t priority_queue_topPriority(priority_queue_t *self) 136 | { 137 | if (self != 0) 138 | { 139 | void **ppElem; 140 | ppElem = adt_ary_get(&self->elements, 0); 141 | if (ppElem != 0) 142 | { 143 | adt_heap_elem_t *pElem = (adt_heap_elem_t*) ppElem; 144 | return pElem->u32Value; 145 | } 146 | } 147 | return 0; 148 | } 149 | 150 | void *priority_queue_topItem(priority_queue_t *self) 151 | { 152 | if (self != 0) 153 | { 154 | void **ppElem; 155 | ppElem = adt_ary_get(&self->elements, 0); 156 | if (ppElem != 0) 157 | { 158 | adt_heap_elem_t *pElem = (adt_heap_elem_t*) ppElem; 159 | return pElem->pItem; 160 | } 161 | } 162 | return (void*) 0; 163 | } 164 | 165 | 166 | //special function 167 | ///TODO: this function needs to support overflow situation, right now it doesn't 168 | void priority_queue_incrementTopPriority(priority_queue_t *self, uint32_t value) 169 | { 170 | if (self != 0) 171 | { 172 | adt_heap_elem_t *pElem = priority_queue_top(self); 173 | if (pElem != 0) 174 | { 175 | pElem->u32Value += value; ///FIXME: handle overflow situation 176 | adt_heap_sortDown(&self->elements, 0, ADT_MIN_HEAP); 177 | } 178 | } 179 | } 180 | 181 | 182 | 183 | ////////////////////////////////////////////////////////////////////////////// 184 | // LOCAL FUNCTIONS 185 | ////////////////////////////////////////////////////////////////////////////// 186 | 187 | 188 | -------------------------------------------------------------------------------- /util/src/systime_wl.c: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * \file systime_wl.c 3 | * \author Conny Gustafsson 4 | * \date 2013-10-01 5 | * \brief System Time simulation for Windows and Linux 6 | * 7 | * Copyright (c) 2017 Conny Gustafsson 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 9 | * this software and associated documentation files (the "Software"), to deal in 10 | * the Software without restriction, including without limitation the rights to 11 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 12 | * the Software, and to permit persons to whom the Software is furnished to do so, 13 | * subject to the following conditions: 14 | 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 20 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 21 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | ******************************************************************************/ 26 | 27 | /********************************* Includes **********************************/ 28 | #include 29 | #if defined(_WIN32) || defined(__CYGWIN__) 30 | #include 31 | #else 32 | #include 33 | #include 34 | #include 35 | #endif 36 | #include "systime.h" 37 | #ifdef USE_PLATFORM_TYPES 38 | #define _UINT8 uint8 39 | #define _UINT32 uint32 40 | #else 41 | #define _UINT8 uint8_t 42 | #define _UINT32 uint32_t 43 | #endif 44 | 45 | 46 | /**************************** Constants and Types ****************************/ 47 | #if defined(_WIN32) || defined(__CYGWIN__) 48 | #define SKIP_ITERATIONS 100 49 | #define MAX_ITERATIONS 1000000 50 | #define TIMER_RESOLUTION_1MS 10000U //1ms 51 | #define TIMER_RESOLUTION_05MS 5000U //0,5ms 52 | #define TIMER_TIMEOUT_MS 10U 53 | 54 | typedef LONG(CALLBACK* NTSETTIMERRESOLUTION) 55 | ( 56 | IN ULONG DesiredTime, 57 | IN BOOLEAN SetResolution, 58 | OUT PULONG ActualTime 59 | ); 60 | 61 | typedef LONG(CALLBACK* NTQUERYTIMERRESOLUTION) 62 | ( 63 | OUT PULONG MaximumTime, 64 | OUT PULONG MinimumTime, 65 | OUT PULONG CurrentTime 66 | ); 67 | #else 68 | static struct timespec m_sleepTime = { 0, 1000000*10}; 69 | static struct timespec m_beginTime; 70 | static struct timespec m_nextTime; 71 | #endif 72 | /********************************* Variables *********************************/ 73 | #if defined(_WIN32) || defined(__CYGWIN__) 74 | NTSETTIMERRESOLUTION NtSetTimerResolution; 75 | NTQUERYTIMERRESOLUTION NtQueryTimerResolution; 76 | LARGE_INTEGER m_freq; 77 | static HANDLE m_hTimer = INVALID_HANDLE_VALUE; 78 | LARGE_INTEGER m_ref; 79 | #endif 80 | static _UINT32 m_u32SystimeTick; 81 | 82 | /************************* Local Function Prototypes *************************/ 83 | #if !defined(_WIN32) && !defined(__CYGWIN__) 84 | static struct timespec timespec_add(struct timespec time1,struct timespec time2); 85 | static struct timespec timespec_subtract(struct timespec time1,struct timespec time2); 86 | #endif 87 | /***************************** Exported Functions ****************************/ 88 | #if defined(UNIT_TEST) || defined(SYSTIME_SIMULATED) 89 | void SysTime_initSimulated(void) 90 | { 91 | SysTime_reset(); 92 | } 93 | 94 | void SysTime_tick(_UINT32 tickMs) 95 | { 96 | m_u32SystimeTick += tickMs; 97 | } 98 | #endif 99 | 100 | int SysTime_init(_UINT32 tickMs) 101 | { 102 | #if defined(_WIN32) || defined(__CYGWIN__) 103 | //Windows 104 | ULONG min, max, cur; 105 | HMODULE hNtDll; 106 | LARGE_INTEGER dt; 107 | BOOL b; 108 | int i, n = 0; 109 | QueryPerformanceFrequency(&m_freq); 110 | QueryPerformanceCounter(&m_ref); 111 | hNtDll = LoadLibrary("NtDll.dll"); 112 | if (!hNtDll) 113 | { 114 | return -2; 115 | } 116 | 117 | NtQueryTimerResolution = (NTQUERYTIMERRESOLUTION)GetProcAddress(hNtDll, "NtQueryTimerResolution"); 118 | NtSetTimerResolution = (NTSETTIMERRESOLUTION)GetProcAddress(hNtDll, "NtSetTimerResolution"); 119 | 120 | NtQueryTimerResolution(&max, &min, &cur); 121 | NtSetTimerResolution(TIMER_RESOLUTION_05MS, TRUE, &cur); 122 | #ifdef SYSTIME_STAT 123 | printf("[systime] TimerResolution: %lu %lu %lu\n", (unsigned long)max, (unsigned long)min, (unsigned long)cur); 124 | #endif 125 | FreeLibrary(hNtDll); 126 | 127 | 128 | dt.QuadPart = TIMER_RESOLUTION_1MS * tickMs; 129 | m_hTimer = CreateWaitableTimer(NULL, FALSE, NULL); 130 | if ((m_hTimer == INVALID_HANDLE_VALUE) || (m_hTimer == 0)) 131 | { 132 | printf("CreateWaitableTimer failed\n"); 133 | return -1; 134 | } 135 | b = SetWaitableTimer(m_hTimer, &dt, tickMs, NULL, NULL, FALSE); 136 | if (!b) 137 | { 138 | printf("SetWaitableTimer failed\n"); 139 | return -1; 140 | } 141 | 142 | //run timer for some time to get rid of initial jitter 143 | for (i = 0; i < MAX_ITERATIONS; ++i) 144 | { 145 | if (WaitForSingleObject(m_hTimer, 0) == WAIT_OBJECT_0) 146 | { 147 | n++; 148 | if (n >= SKIP_ITERATIONS) 149 | { 150 | break; 151 | } 152 | } 153 | } 154 | SysTime_reset(); 155 | return 0; 156 | #else 157 | //Linux 158 | if( (tickMs>0) && (tickMs<=1000) ){ 159 | m_sleepTime.tv_sec = 0; 160 | m_sleepTime.tv_nsec = tickMs*1000000; 161 | SysTime_reset(); 162 | return 0; 163 | } 164 | return -1; 165 | #endif 166 | } 167 | 168 | void SysTime_destroy(void) 169 | { 170 | #if defined(_WIN32) || defined(__CYGWIN__) 171 | if (m_hTimer != INVALID_HANDLE_VALUE ) 172 | { 173 | CloseHandle(m_hTimer); 174 | } 175 | #endif 176 | } 177 | 178 | _UINT32 SysTime_getTime(void){ 179 | return m_u32SystimeTick; 180 | } 181 | 182 | 183 | #if (!defined(UNIT_TEST)) && (!defined(SYSTIME_SIMULATED)) 184 | _UINT8 SysTime_wait(int isBlocking) 185 | { 186 | #if defined(_WIN32) || defined(__CYGWIN__) 187 | if ( m_hTimer != INVALID_HANDLE_VALUE ) 188 | { 189 | DWORD timeout = isBlocking ? INFINITE : 0; 190 | if (WaitForSingleObject(m_hTimer, timeout) == WAIT_OBJECT_0) 191 | { 192 | m_u32SystimeTick++; 193 | return 1; 194 | } 195 | } 196 | return 0; 197 | #else 198 | if( (m_isSimulated == 0) && (isBlocking != 0)) 199 | { 200 | clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,&m_nextTime, NULL); 201 | m_nextTime=timespec_add(m_nextTime,m_sleepTime); 202 | } 203 | else 204 | { 205 | return 0; //nonblocking is not supported in Linux version 206 | } 207 | g_u32SystimeTick++; 208 | return 1; 209 | #endif 210 | } 211 | 212 | #endif 213 | 214 | void SysTime_reset(void) 215 | { 216 | #if (!defined(UNIT_TEST)) && (!defined(SYSTIME_SIMULATED)) 217 | 218 | # if defined(_WIN32) || defined(__CYGWIN__) 219 | SysTime_wait(1); 220 | QueryPerformanceCounter(&m_ref); 221 | # else 222 | clock_gettime(CLOCK_MONOTONIC, &m_beginTime); 223 | m_nextTime = timespec_add(m_beginTime,m_sleepTime); 224 | # endif 225 | 226 | #endif 227 | m_u32SystimeTick = 0; 228 | } 229 | 230 | 231 | /****************************** Local Functions ******************************/ 232 | #if !defined(_WIN32) && !defined(__CYGWIN__) 233 | struct timespec timespec_add (struct timespec time1,struct timespec time2){ 234 | struct timespec result ; 235 | result.tv_sec = time1.tv_sec + time2.tv_sec ; 236 | result.tv_nsec = time1.tv_nsec + time2.tv_nsec ; 237 | if (result.tv_nsec >= 1000000000L) { /* Carry? */ 238 | result.tv_sec++ ; result.tv_nsec = result.tv_nsec - 1000000000L ; 239 | } 240 | return (result) ; 241 | } 242 | 243 | struct timespec timespec_subtract (struct timespec time1,struct timespec time2){ 244 | struct timespec result ; 245 | /* Subtract the second time from the first. */ 246 | if ((time1.tv_sec < time2.tv_sec) || 247 | ((time1.tv_sec == time2.tv_sec) && 248 | (time1.tv_nsec <= time2.tv_nsec))) { /* TIME1 <= TIME2? */ 249 | result.tv_sec = result.tv_nsec = 0 ; 250 | } else { /* TIME1 > TIME2 */ 251 | result.tv_sec = time1.tv_sec - time2.tv_sec ; 252 | if (time1.tv_nsec < time2.tv_nsec) { 253 | result.tv_nsec = time1.tv_nsec + 1000000000L - time2.tv_nsec ; 254 | result.tv_sec-- ; /* Borrow a second. */ 255 | } else { 256 | result.tv_nsec = time1.tv_nsec - time2.tv_nsec ; 257 | } 258 | } 259 | 260 | return (result) ; 261 | 262 | } 263 | #endif 264 | --------------------------------------------------------------------------------