diff options
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c')
14 files changed, 253 insertions, 289 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/.cproject b/runtime/org.eclipse.etrice.runtime.c/.cproject index 46d4069c4..eab210cb1 100644 --- a/runtime/org.eclipse.etrice.runtime.c/.cproject +++ b/runtime/org.eclipse.etrice.runtime.c/.cproject @@ -40,6 +40,7 @@ <listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/src/common}""/> <listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/src/config}""/> <listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/src/platforms/MT_WIN_MinGW}""/> + <listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/src/util}""/> </option> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.316560634" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> </tool> diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory.h b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory.h index 38d274e5a..2b960e259 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory.h @@ -19,7 +19,7 @@ * this macro computes the memory aligned value for a given size. It uses the ALIGNMENT * defined in etDatatypes.h */ -#define MEM_CEIL(n) ((n)+((ALIGNMENT-((n)&(ALIGNMENT-1)))&(ALIGNMENT-1))) +#define MEM_CEIL(n) ((n)+((etALIGNMENT-((n)&(etALIGNMENT-1)))&(etALIGNMENT-1))) struct etMemory; diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c index e97b2b1e7..09e2008ab 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/base/etMemory_FreeList.c @@ -60,7 +60,7 @@ static void* etMemory_getFreeListMem(etFreeListMemory* self, etUInt16 size) { int asize, slot_offset, slot, slot_size; ET_MSC_LOGGER_SYNC_ENTRY("etMemory", "getFreeListMem") - asize = (size / ALIGNMENT); + asize = (size / etALIGNMENT); for (slot_offset = 0; slot_offset < self->nslots; slot_offset++) { slot = (asize + slot_offset) % self->nslots; slot_size = self->freelists[slot].objsize; @@ -87,7 +87,7 @@ static void etMemory_putFreeListMem(etFreeListMemory* self, void* obj, etUInt16 { int asize, slot_offset, slot, slot_size; - asize = (size / ALIGNMENT); + asize = (size / etALIGNMENT); for (slot_offset = 0; slot_offset < self->nslots; slot_offset++) { slot = (asize + slot_offset) % self->nslots; slot_size = self->freelists[slot].objsize; diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/etStdDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/common/etStdDatatypes.h new file mode 100644 index 000000000..294068261 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/etStdDatatypes.h @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2011 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Juergen Haug (initial contribution) + * + *******************************************************************************/ + +/* + * Generic version for most platforms based on std. + */ + +#ifndef _ETSTDDATATYPES_H_ +#define _ETSTDDATATYPES_H_ + +/* + Define switches for additional data types: + #define ET_INT64 + #define ET_FLOAT32 + #define ET_FLOAT64 + */ + +#include <stddef.h> +#include <stdint.h> +#include <stdbool.h> + +/* --- Data types for room.basic.types */ + +// bool already defined +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; + +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; + +#ifdef ET_INT64 +typedef uint64_t uint64; +typedef int64_t int64; +#endif + +#ifdef ET_FLOAT32 +typedef float float32; +#endif +#ifdef ET_FLOAT64 +typedef double float64; +#endif + +typedef char* charPtr; + +/*-----------------------------------------------------------*/ + +/*--- Cross language support (e.g. Java,C/C++) */ + +#define null NULL +// typedef x boolean + +/*-----------------------------------------------------------*/ + +//--- Required types of runtime +typedef bool etBool; +#define ET_TRUE true +#define ET_FALSE false + +typedef uint8 etUInt8; +typedef uint16 etUInt16; +typedef uint32 etUInt32; + +typedef int8 etInt8; +typedef int16 etInt16; +typedef int32 etInt32; + +#ifdef ET_INT64 +typedef uint64_t etUInt64; +typedef int64_t etInt64; +#endif + +#ifdef ET_FLOAT32 +typedef float32 etFloat32; +#endif +#ifdef ET_FLOAT64 +typedef float64 etFloat64; +#endif + +typedef charPtr etCharPtr; + +typedef etInt16 etAddressId; + +/* mandatory: + #define etALIGNMENT x // power of 2 and >= sizeof(int) ! + typedef x etFileHandle; + */ + +/* + typedef float32 etFloat32; + typedef float64 etFloat64; + */ + +/* types for osal */ + +/* mandatory: + typedef x etOSMutexData; + typedef x etOSThreadData; + typedef x etOSThreadId; + typedef x etOSSemaData; + typedef x etOSTimerData; + typedef x etOSTimerId; + */ + +/*-----------------------------------------------------------*/ + +#endif /* _ETSTDDATATYPES_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c index 544ffaf8f..bc903795e 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.c @@ -55,14 +55,28 @@ static OrderInfo* getOrderInfo(etInt16 id) { return NULL; } +/* float measuring */ +#if defined (ET_FLOAT32) || defined (ET_FLOAT64) +#define ETUNIT_FLOAT +#ifdef ET_FLOAT64 +typedef etFloat64 etUnitFloat; +#else +typedef etFloat32 etUnitFloat; +#endif +#endif + + /* forward declarations of private functions */ static void expect_equal_int(etInt16 id, const char* message, etInt32 expected, etInt32 actual, const char* file, int line); static void expect_range_int(etInt16 id, const char* message, etInt32 min, etInt32 max, etInt32 actual, const char* file, int line); static void expect_equal_uint(etInt16 id, const char* message, etUInt32 expected, etUInt32 actual, const char* file, int line); static void expect_range_uint(etInt16 id, const char* message, etUInt32 min, etUInt32 max, etUInt32 actual, const char* file, int line); -static void expect_equal_float(etInt16 id, const char* message, etFloat64 expected, etFloat64 actual, etFloat64 precision, const char* file, int line); -static void expect_range_float(etInt16 id, const char* message, etFloat64 min, etFloat64 max, etFloat64 actual, const char* file, int line); +#ifdef ETUNIT_FLOAT +static void expect_equal_float(etInt16 id, const char* message, etUnitFloat expected, etUnitFloat actual, etUnitFloat precision, const char* file, int line); +static void expect_range_float(etInt16 id, const char* message, etUnitFloat min, etUnitFloat max, etUnitFloat actual, const char* file, int line); +#endif + static void etUnit_handleExpect(etInt16 id, etBool result, const char *trace, const char* expected, const char* actual, const char* file, int line); /* public functions */ @@ -97,8 +111,6 @@ void etUnit_open(const char* testResultPath, const char* testFileName) { /* prepare time measurement */ getTimeFromTarget(&etUnit_startTime); - etLogger_logInfoF("Start Time: %ld", etTimeHelpers_convertToMSec(&etUnit_startTime)); - } void etUnit_close(void) { @@ -106,7 +118,10 @@ void etUnit_close(void) { etLogger_fclose(etUnit_reportfile); etUnit_reportfile = NULL; } - etLogger_logInfoF("End Time: %ld", clock()); + etTime endTime; + getTimeFromTarget(&endTime); + etTimeHelpers_subtract(&endTime, &etUnit_startTime); + etLogger_logInfoF("Elapsed Time: %ld ms", etTimeHelpers_convertToMSec(&endTime)); if (etUnit_errorCounter == 0) etLogger_logInfoF("Error Counter: %ld", etUnit_errorCounter); else @@ -148,7 +163,6 @@ void etUnit_closeTestCase(etInt16 id) { OrderInfo* info = getOrderInfo(id); if(info != NULL){ if (info->currentIndex != info->size) { - char testresult[ETUNIT_FAILURE_TEXT_LEN]; etUnit_handleExpect(id, ET_FALSE, "EXPECT_ORDER was not completed", NULL, NULL, 0, 0); } } @@ -231,21 +245,25 @@ void expect_equal_void_ptr(etInt16 id, const char* message, const void* expected } } +#ifdef ET_FLOAT32 void expectEqualFloat32(etInt16 id, const char* message, etFloat32 expected, etFloat32 actual, etFloat32 precision, const char* file, int line) { expect_equal_float(id, message, expected, actual, precision, file, line); } -void expectEqualFloat64(etInt16 id, const char* message, etFloat64 expected, etFloat64 actual, etFloat64 precision, const char* file, int line) { - expect_equal_float(id, message, expected, actual, precision, file, line); -} - void expectRangeFloat32(etInt16 id, const char* message, etFloat32 min, etFloat32 max, etFloat32 actual, const char* file, int line) { expect_range_float(id, message, min, max, actual, file, line); } +#endif + +#ifdef ET_FLOAT64 +void expectEqualFloat64(etInt16 id, const char* message, etFloat64 expected, etFloat64 actual, etFloat64 precision, const char* file, int line) { + expect_equal_float(id, message, expected, actual, precision, file, line); +} void expectRangeFloat64(etInt16 id, const char* message, etFloat64 min, etFloat64 max, etFloat64 actual, const char* file, int line) { expect_range_float(id, message, min, max, actual, file, line); } +#endif void expectOrderStart(etInt16 id, etInt16* list, etInt16 size, const char* file, int line) { int i; @@ -362,7 +380,8 @@ static void expect_range_uint(etInt16 id, const char* message, etUInt32 min, etU } } -static void expect_equal_float(etInt16 id, const char* message, etFloat64 expected, etFloat64 actual, etFloat64 precision, const char* file, int line) { +#ifdef ETUNIT_FLOAT +static void expect_equal_float(etInt16 id, const char* message, etUnitFloat expected, etUnitFloat actual, etUnitFloat precision, const char* file, int line) { if (expected - actual < -precision || expected - actual > precision) { char testresult[ETUNIT_FAILURE_TEXT_LEN]; char exp[16], act[16]; @@ -375,7 +394,7 @@ static void expect_equal_float(etInt16 id, const char* message, etFloat64 expect } } -static void expect_range_float(etInt16 id, const char* message, etFloat64 min, etFloat64 max, etFloat64 actual, const char* file, int line) { +static void expect_range_float(etInt16 id, const char* message, etUnitFloat min, etUnitFloat max, etUnitFloat actual, const char* file, int line) { if (actual < min || actual > max) { char testresult[ETUNIT_FAILURE_TEXT_LEN]; char exp[64], act[16]; @@ -392,6 +411,7 @@ static void expect_range_float(etInt16 id, const char* message, etFloat64 min, e etUnit_handleExpect(id, ET_TRUE, "", NULL, NULL, file, line); } } +#endif static void etUnit_handleExpect(etInt16 id, etBool result, const char *resulttext, const char* exp, const char* act, const char* file, int line) { if (result == ET_TRUE) { diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.h b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.h index eb2c30bca..99c5bb3e0 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/etUnit/etUnit.h @@ -130,13 +130,18 @@ void etUnit_closeAll(etInt16 id); /* * float values */ +#ifdef ET_FLOAT32 /** calls \ref expectEqualFloat32() */ #define EXPECT_EQUAL_FLOAT32(id, msg, expected, actual, precision) expectEqualFloat32(id, msg, expected, actual, precision, __FILE__, __LINE__) +#define EXPECT_RANGE_FLOAT32(id, msg, min, max, actual) expectRangeFloat32(id, msg, min, max, actual, __FILE__, __LINE__) +#endif + +#ifdef ET_FLOAT64 /** calls \ref expectEqualFloat64() */ #define EXPECT_EQUAL_FLOAT64(id, msg, expected, actual, precision) expectEqualFloat64(id, msg, expected, actual, precision, __FILE__, __LINE__) - -#define EXPECT_RANGE_FLOAT32(id, msg, min, max, actual) expectRangeFloat32(id, msg, min, max, actual, __FILE__, __LINE__) #define EXPECT_RANGE_FLOAT64(id, msg, min, max, actual) expectRangeFloat64(id, msg, min, max, actual, __FILE__, __LINE__) +#endif + /* * Pointers @@ -287,7 +292,9 @@ void expectEqualUInt32(etInt16 id, const char* msg, etUInt32 expected, etUInt32 * \param file the file name with the test case * \param line the line */ +#ifdef ET_FLOAT32 void expectEqualFloat32(etInt16 id, const char* msg, etFloat32 expected, etFloat32 actual, etFloat32 precision, const char* file, int line); +#endif /** * reports an error if two floats aren't equal * @@ -299,7 +306,9 @@ void expectEqualFloat32(etInt16 id, const char* msg, etFloat32 expected, etFloat * \param file the file name with the test case * \param line the line */ +#ifdef ET_FLOAT64 void expectEqualFloat64(etInt16 id, const char* msg, etFloat64 expected, etFloat64 actual, etFloat64 precision, const char* file, int line); +#endif /** * reports an error if a value is not inside a range e.g. [-5.1, +3.0] @@ -312,7 +321,9 @@ void expectEqualFloat64(etInt16 id, const char* msg, etFloat64 expected, etFloat * \param file the file name with the test case * \param line the line */ +#ifdef ET_FLOAT32 void expectRangeFloat32(etInt16 id, const char* message, etFloat32 min, etFloat32 max, etFloat32 actual, const char* file, int line) ; +#endif /** * reports an error if a value is not inside a range e.g. [-5.1, +3.0] @@ -325,7 +336,9 @@ void expectRangeFloat32(etInt16 id, const char* message, etFloat32 min, etFloat3 * \param file the file name with the test case * \param line the line */ +#ifdef ET_FLOAT64 void expectRangeFloat64(etInt16 id, const char* message, etFloat64 min, etFloat64 max, etFloat64 actual, const char* file, int line) ; +#endif /** * reports an error if two pointers aren't equal diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.c b/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.c index 708d55c29..7149058f3 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.c @@ -61,14 +61,14 @@ void etTimeHelpers_convertToEtTime(etTime *result, etInt32 milliSeconds){ result->nSec = milliSeconds%1000 * 1000000; } -boolean etTimeHelpers_isGreater(etTime* t1, etTime* t2) { +etBool etTimeHelpers_isGreater(etTime* t1, etTime* t2) { if (t1->sec > t2->sec) return ET_TRUE; if (t1->sec < t2->sec) return ET_FALSE; if (t1->nSec > t2->nSec) return ET_TRUE; return ET_FALSE; } -boolean etTimeHelpers_isGreaterOrEqual(etTime* t1, etTime* t2) { +etBool etTimeHelpers_isGreaterOrEqual(etTime* t1, etTime* t2) { if (t1->sec > t2->sec) return ET_TRUE; if (t1->sec < t2->sec) return ET_FALSE; if (t1->nSec >= t2->nSec) return ET_TRUE; diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.h b/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.h index e70f66376..b08839d86 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/common/helpers/etTimeHelpers.h @@ -75,7 +75,7 @@ void etTimeHelpers_convertToEtTime(etTime *result, etInt32 milliSeconds); * \param t1 first time * \param t2 second time */ -boolean etTimeHelpers_isGreater(etTime* t1, etTime* t2); +etBool etTimeHelpers_isGreater(etTime* t1, etTime* t2); /** * check if t1 is greater than or equal as t2 @@ -83,6 +83,6 @@ boolean etTimeHelpers_isGreater(etTime* t1, etTime* t2); * \param t1 first time * \param t2 second time */ -boolean etTimeHelpers_isGreaterOrEqual(etTime* t1, etTime* t2); +etBool etTimeHelpers_isGreaterOrEqual(etTime* t1, etTime* t2); #endif /* _ETTIMEHELPERS_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_32Bit_FreeRTOS_Generic/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_32Bit_FreeRTOS_Generic/etDatatypes.h index e0b270816..40d3aaaef 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_32Bit_FreeRTOS_Generic/etDatatypes.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_32Bit_FreeRTOS_Generic/etDatatypes.h @@ -14,9 +14,15 @@ #define _ETDATATYPES_H_ /* - * typedefs for FreeRTOS on a 32Bit environment - * - * */ + * typedefs for platform specific datatypes + * FreeRTOS on a 32Bit version + */ + +#define ET_INT64 +#define ET_FLOAT32 +//#define ET_FLOAT64 /* not available on this platform */ + +#include "etStdDatatypes.h" #include <stdio.h> #include <FreeRTOS.h> @@ -24,75 +30,26 @@ #include <timers.h> #include <semphr.h> -/* unsigned integer datatypes */ -typedef unsigned char uint8; -typedef unsigned short int uint16; -typedef unsigned int uint32; -typedef unsigned long long uint64; - -/* signed integer datatypes */ -typedef char int8; -typedef short int int16; -typedef int int32; -typedef long long int64; - +/*--- Data types for room.basic.types */ -/* float datatypes */ -typedef float float32; -/* typedef double float64; */ /* not available on this platform */ - -/* boolean datatypes and values */ -//typedef char bool; /* TODO: bool, Bool, Boolean, and boolean are already defined in some platforms*/ -//typedef bool boolean; -typedef char boolean; - -#ifndef ET_TRUE - #define ET_TRUE 1 -#endif -#ifndef ET_FALSE - #define ET_FALSE 0 -#endif - -/* - * typedefs for eTrice Runtime and Testing - * - * */ +/*-----------------------------------------------------------*/ -typedef int8 etInt8; -typedef int16 etInt16; -typedef int32 etInt32; - -typedef uint8 etUInt8; -typedef uint16 etUInt16; -typedef uint32 etUInt32; - -//typedef bool etBool; -typedef char etBool; +/*--- Data types for runtime */ #define ALIGNMENT 4 /* power of 2 and >= sizeof(int) ! */ -typedef float32 etFloat32; -typedef float32 etFloat64; - -/* string datatypes */ -typedef char* charPtr; - - typedef FILE* etFileHandle; -typedef int8 etAddressId; - - -/* - * typedefs for OS-specific types - */ +/* types for osal */ typedef xSemaphoreHandle etOSMutexData; typedef xSemaphoreHandle etOSSemaData; typedef xTaskHandle etOSThreadData; -typedef uint16 etOSThreadId; +typedef etUInt16 etOSThreadId; typedef xTimerHandle etOSTimerData; -typedef uint16 etOSTimerId; +typedef etUInt16 etOSTimerId; + +/*-----------------------------------------------------------*/ #endif /* _DATATYPES_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etDatatypes.h index 007aa865c..14407a0a1 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etDatatypes.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_POSIX_GENERIC_GCC/etDatatypes.h @@ -17,8 +17,13 @@ /* * typedefs for platform specific datatypes * POSIX version - * - * */ + */ + +#define ET_INT64 +#define ET_FLOAT32 +#define ET_FLOAT64 + +#include "etStdDatatypes.h" #include <stdio.h> #include <pthread.h> @@ -26,79 +31,17 @@ #include <signal.h> #include <sys/types.h> -/* unsigned integer datatypes */ -typedef unsigned char uint8; -typedef unsigned short int uint16; -typedef unsigned long uint32; -typedef unsigned long long uint64; - -/* signed integer datatypes */ -typedef char int8; -typedef short int int16; -typedef long int32; -typedef long long int64; - +/*--- Data types for room.basic.types */ -/* float datatypes */ -typedef float float32; -typedef double float64; +/*-----------------------------------------------------------*/ -/* string datatypes */ -typedef char* charPtr; - - -#ifndef NULL - #define NULL 0 -#endif - -/* boolean datatypes and values */ -typedef char bool; /* TODO: bool, Bool, Boolean, and boolean are already defined in some platforms*/ -typedef bool boolean; - -#ifndef ET_TRUE - #define ET_TRUE 1 -#endif -#ifndef ET_FALSE - #define ET_FALSE 0 -#endif -#ifndef true - #define true 1 -#endif -#ifndef false - #define false 0 -#endif - -#define ALIGNMENT 8 /* power of 2 and >= sizeof(int) ! */ - -/* - * typedefs for eTrice Runtime and Testing - * - * */ - -typedef int8 etInt8; -typedef int16 etInt16; -typedef int32 etInt32; - -typedef uint8 etUInt8; -typedef uint16 etUInt16; -typedef uint32 etUInt32; - -typedef charPtr etCharPtr; - -typedef float32 etFloat32; -typedef float64 etFloat64; - -typedef bool etBool; +/*--- Data types for runtime */ +#define etALIGNMENT 8 /* power of 2 and >= sizeof(int) ! */ typedef FILE* etFileHandle; -typedef int16 etAddressId; - -/* - * typedefs for OS-specific types - */ - +/* types for osal */ typedef pthread_mutex_t etOSMutexData; typedef pthread_t etOSThreadData; typedef pthread_t etOSThreadId; @@ -108,9 +51,9 @@ typedef struct { timer_t timerid; sigevent_t te; etBool signaled; -} -etOSTimerData; +} etOSTimerData; typedef timer_t etOSTimerId; +/*-----------------------------------------------------------*/ #endif /* _DATATYPES_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h index a50da01b2..8adfcda08 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/MT_WIN_MinGW/etDatatypes.h @@ -15,87 +15,31 @@ /* * typedefs for platform specific datatypes - * generic Version for most bigger 32 and 64 bit platforms like Linux an Windows - * - * */ + * MinGW version + */ + +#define ET_INT64 +#define ET_FLOAT32 +#define ET_FLOAT64 + +#include "etStdDatatypes.h" #include <stdio.h> #define WINVER 0x0500 #include <windows.h> -/* unsigned integer datatypes */ -typedef unsigned char uint8; -typedef unsigned short int uint16; -typedef unsigned long uint32; -typedef unsigned long long uint64; - -/* signed integer datatypes */ -typedef char int8; -typedef short int int16; -typedef long int32; -typedef long long int64; - - -/* float datatypes */ -typedef float float32; -typedef double float64; - -/* string datatypes */ -typedef char* charPtr; - - -#ifndef NULL - #define NULL 0 -#endif - -/* boolean datatypes and values */ -typedef char bool; /* TODO: bool, Bool, Boolean, and boolean are already defined in some platforms*/ - -#ifndef ET_TRUE - #define ET_TRUE 1 -#endif -#ifndef ET_FALSE - #define ET_FALSE 0 -#endif -#ifndef true - #define true 1 -#endif -#ifndef false - #define false 0 -#endif +/*--- Data types for room.basic.types */ -#define ALIGNMENT 8 /* power of 2 and >= sizeof(int) ! */ +/*-----------------------------------------------------------*/ -/* - * typedefs for eTrice Runtime and Testing - * - * */ - -typedef int8 etInt8; -typedef int16 etInt16; -typedef int32 etInt32; - -typedef uint8 etUInt8; -typedef uint16 etUInt16; -typedef uint32 etUInt32; - -typedef charPtr etCharPtr; - -typedef float32 etFloat32; -typedef float64 etFloat64; - -typedef bool etBool; +/*--- Data types for runtime */ +#define etALIGNMENT 8 /* power of 2 and >= sizeof(int) ! */ typedef FILE* etFileHandle; -typedef int16 etAddressId; - -/* - * typedefs for OS-specific types - */ - +/* types for osal */ typedef CRITICAL_SECTION etOSMutexData; typedef HANDLE etOSThreadData; typedef DWORD etOSThreadId; @@ -103,4 +47,6 @@ typedef HANDLE etOSSemaData; typedef HANDLE etOSTimerData; typedef DWORD etOSTimerId; +/*-----------------------------------------------------------*/ + #endif /* _DATATYPES_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_32Bit_Generic/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_32Bit_Generic/etDatatypes.h index 762d9b50c..f21fb05d4 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_32Bit_Generic/etDatatypes.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_32Bit_Generic/etDatatypes.h @@ -16,75 +16,35 @@ /* * typedefs for platform specific datatypes * Version for 32 Bit Controllers like ARM Cortex M - * - * */ - -#include <stdio.h> - -/* unsigned integer datatypes */ -typedef unsigned char uint8; -typedef unsigned short int uint16; -typedef unsigned int uint32; -typedef unsigned long long uint64; - -/* signed integer datatypes */ -typedef char int8; -typedef short int int16; -typedef int int32; -typedef long long int64; + */ +#define ET_INT64 +#define ET_FLOAT32 +//#define ET_FLOAT64 /* not available on this platform */ -/* float datatypes */ -typedef float float32; -/* typedef double float64; */ /* not available on this platform */ -/* boolean datatypes and values */ -typedef char boolean; -#ifndef ET_TRUE - #define ET_TRUE 1 -#endif -#ifndef ET_FALSE - #define ET_FALSE 0 -#endif +#include "etStdDatatypes.h" -/* - * typedefs for eTrice Runtime and Testing - * - * */ +#include <stdio.h> -typedef int8 etInt8; -typedef int16 etInt16; -typedef int32 etInt32; +/*--- Data types for room.basic.types */ -typedef uint8 etUInt8; -typedef uint16 etUInt16; -typedef uint32 etUInt32; +/*-----------------------------------------------------------*/ -//typedef bool etBool; -typedef char etBool; +/*--- Data types for runtime */ #define ALIGNMENT 4 /* power of 2 and >= sizeof(int) ! */ -typedef float32 etFloat32; -typedef float32 etFloat64; - -/* string datatypes */ -typedef char* charPtr; - - typedef FILE* etFileHandle; -typedef int8 etAddressId; +/* types for osal */ +typedef etUInt32 etOSMutexData; +typedef etUInt32 etOSSemaData; +typedef etUInt32 etOSThreadData; +typedef etUInt32 etOSThreadId; +typedef etUInt32 etOSTimerData; +typedef etUInt32 etOSTimerId; - -/* - * typedefs for OS-specific types - */ -typedef uint32 etOSMutexData; -typedef uint32 etOSSemaData; -typedef uint32 etOSThreadData; -typedef uint32 etOSThreadId; -typedef uint32 etOSTimerData; -typedef uint32 etOSTimerId; +/*-----------------------------------------------------------*/ #endif /* _DATATYPES_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.c b/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.c index d849b4edb..b20444b56 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.c +++ b/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.c @@ -12,9 +12,11 @@ #include "RandomGenerator.h" +#ifdef ET_FLOAT64 + #include "math.h" -void RandomGenerator_init(RandomGenerator* self, float64 seed, float64 min, float64 max){ +void RandomGenerator_init(RandomGenerator* self, etFloat64 seed, etFloat64 min, etFloat64 max){ self->seed = seed; self->min = min; self->max = max; @@ -23,12 +25,14 @@ void RandomGenerator_init(RandomGenerator* self, float64 seed, float64 min, floa } -float64 RandomGenerator_getNext(RandomGenerator* self){ +etFloat64 RandomGenerator_getNext(RandomGenerator* self){ self->seed = 1000. * fabs(log(self->seed)); /* shift comma 3 times to get nice values */ - int64 resultInt = self->seed; /* get int number left of comma */ + etInt64 resultInt = self->seed; /* get int number left of comma */ self->seed = self->seed - resultInt; /* cut off everything left of comma */ self->current = self->seed*self->range + self->min; /* stretch to range */ self->seed += 0.1; /** seed must always be bigger than 0 for log in next iteration */ return self->current; } + +#endif diff --git a/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.h b/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.h index 3cda64a74..25e3d1b28 100644 --- a/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.h +++ b/runtime/org.eclipse.etrice.runtime.c/src/util/RandomGenerator.h @@ -15,12 +15,14 @@ #include "etDatatypes.h" +#ifdef ET_FLOAT64 + typedef struct RandomGenerator { - float64 seed; - float64 max; - float64 min; - float64 range; - float64 current; + etFloat64 seed; + etFloat64 max; + etFloat64 min; + etFloat64 range; + etFloat64 current; }RandomGenerator; /** @@ -35,11 +37,11 @@ typedef struct RandomGenerator { * (...) * RandomNumberGenerator rand; * RandomNumberGenerator_init(&rand, 0.321, -10, 10); -* float64 result = RandomNumberGenerator_getNext(&rand); +* etFloat64 result = RandomNumberGenerator_getNext(&rand); * (...) * result now holds a random number between -10 and 10; */ -void RandomGenerator_init(RandomGenerator* self, float64 seed, float64 min, float64 max); +void RandomGenerator_init(RandomGenerator* self, etFloat64 seed, etFloat64 min, etFloat64 max); /** * initialze once before use. @@ -48,7 +50,8 @@ void RandomGenerator_init(RandomGenerator* self, float64 seed, float64 min, floa * @return A random number between min and max * */ -float64 RandomGenerator_getNext(RandomGenerator* self); +etFloat64 RandomGenerator_getNext(RandomGenerator* self); +#endif #endif /* RANDOMGENERATOR_H_ */ |