diff options
author | Thomas Jung | 2015-05-13 18:05:08 +0000 |
---|---|---|
committer | Thomas Jung | 2015-05-13 18:05:08 +0000 |
commit | d991551092c58585d205783e5f9e551f41483157 (patch) | |
tree | a31102f28f01643d7a963980977aa6d1dd994fa9 /runtime/org.eclipse.etrice.runtime.c/src/platforms | |
parent | a9fbc42dca8984549e9c630a41a8a2d0469debce (diff) | |
download | org.eclipse.etrice-d991551092c58585d205783e5f9e551f41483157.tar.gz org.eclipse.etrice-d991551092c58585d205783e5f9e551f41483157.tar.xz org.eclipse.etrice-d991551092c58585d205783e5f9e551f41483157.zip |
etrice.runtime.c ST runtime added for XMC4500 with fixed timing
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/platforms')
10 files changed, 566 insertions, 0 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etDatatypes.h b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etDatatypes.h new file mode 100644 index 000000000..d46e7007f --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etDatatypes.h @@ -0,0 +1,93 @@ +/******************************************************************************* + * 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: + * Thomas Schuetz (initial contribution), Thomas Jung + * + *******************************************************************************/ + +#ifndef _ETDATATYPES_H_ +#define _ETDATATYPES_H_ + +/* + * typedefs for platform specific datatypes + * Version for TI MSP 430 + * + * */ + +#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; + + +/* 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; + +#define ALIGNMENT 4 /* power of 2 and >= sizeof(int) ! */ +#define ARGC_ARGV_AVAILABLE 1 + +typedef float32 etFloat32; +typedef float32 etFloat64; + +/* string datatypes */ +typedef char* charPtr; + + +typedef FILE* etFileHandle; + +typedef int8 etAddressId; + + +/* + * 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/platforms/ST_XMC4500_DaveCE_Generic/etLogger.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etLogger.c new file mode 100644 index 000000000..fb114d302 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etLogger.c @@ -0,0 +1,100 @@ +/******************************************************************************* + * 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: + * Thomas Schuetz (initial contribution) + * + *******************************************************************************/ + +/* + * etLogger.c + * + * Created on: 16.01.2012 + * Author: tschuetz + */ + + +#include "debugging/etLogger.h" + +#include <stdarg.h> + + +void etLogger_logError(const char* message){ +#ifdef ET_LOGGER_ACTIVATE + printf("ERROR: %s\n", message); +#endif +} + +void etLogger_logWarning(const char* message){ +#ifdef ET_LOGGER_ACTIVATE + printf("WARNING: %s\n", message); +#endif +} + +void etLogger_logInfo(const char* message){ +#ifdef ET_LOGGER_ACTIVATE + printf("INFO: %s\n", message); +#endif +} + +void etLogger_logErrorF(const char* format, ... ){ +#ifdef ET_LOGGER_ACTIVATE + printf("ERROR: "); + va_list arglist; + va_start( arglist, format ); + vprintf( format, arglist ); + va_end( arglist ); + printf("\n"); +#endif +} + +void etLogger_logWarningF(const char* format, ... ){ +#ifdef ET_LOGGER_ACTIVATE + printf("WARNING: "); + va_list arglist; + va_start( arglist, format ); + vprintf( format, arglist ); + va_end( arglist ); + printf("\n"); +#endif +} + +void etLogger_logInfoF(const char* format, ... ){ +#ifdef ET_LOGGER_ACTIVATE + printf("INFO: "); + va_list arglist; + va_start( arglist, format ); + vprintf( format, arglist ); + va_end( arglist ); + printf("\n"); +#endif +} + +etFileHandle etLogger_fopen(const char* filename, const char* mode){ +#ifdef ET_LOGGER_ACTIVATE + return( fopen(filename, mode) ); +#else + return (0); +#endif +} + +int etLogger_fclose(etFileHandle file){ +#ifdef ET_LOGGER_ACTIVATE + return( fclose(file) ); +#else + return(0); +#endif +} + +void etLogger_fprintf(etFileHandle file, const char* format, ... ){ +#ifdef ET_LOGGER_ACTIVATE + va_list arglist; + va_start( arglist, format ); + vfprintf(file, format, arglist ); + va_end( arglist ); +#endif +} diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etMutex.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etMutex.c new file mode 100644 index 000000000..28837e7a8 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etMutex.c @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2013 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: + * Thomas Jung (initial contribution) + * + *******************************************************************************/ + +/** + * + * etMutex.c MinGW implementation of etMutex + * + */ + +#include "osal/etMutex.h" + +#include "debugging/etLogger.h" +#include "debugging/etMSCLogger.h" +#include "XMC4500.h" + +void etMutex_construct(etMutex* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "construct") + + ET_MSC_LOGGER_SYNC_EXIT +} +void etMutex_destruct(etMutex* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "destruct") + + ET_MSC_LOGGER_SYNC_EXIT +} + +void etMutex_enter(etMutex* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "enter") + __disable_irq(); + ET_MSC_LOGGER_SYNC_EXIT +} +void etMutex_leave(etMutex* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "leave") + __enable_irq(); + ET_MSC_LOGGER_SYNC_EXIT +} diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etPlatform.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etPlatform.c new file mode 100644 index 000000000..970893dee --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etPlatform.c @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2012 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: + * Thomas Schuetz (initial contribution), Thomas Jung + * + *******************************************************************************/ + +#include "etPlatform.h" +#include "etDatatypes.h" +#include "osal/etTime.h" + +// Ticks are generated every 100ms +#define TICKS_PER_SECOND 1000UL + + +void initHw(void) { + + etTime_init(); +} diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etPlatform.h b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etPlatform.h new file mode 100644 index 000000000..239cac464 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etPlatform.h @@ -0,0 +1,15 @@ +/* + * etPlatform.h + * + * Created on: 23.06.2012 + * Author: junggtho + */ + +#ifndef ETPLATFORM_H_ +#define ETPLATFORM_H_ + +void initHw(void); +void toggleLED0(void); +void toggleLED1(void); + +#endif /* ETPLATFORM_H_ */ diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etPlatformLifecycle.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etPlatformLifecycle.c new file mode 100644 index 000000000..4c404f90d --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etPlatformLifecycle.c @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2013 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: + * Thomas Schuetz, Thomas Jung (initial contribution) + * + *******************************************************************************/ + + + +#include "osal/etPlatformLifecycle.h" +#include "osal/etThread.h" +#include "etPlatform.h" +#include "XMC4500.h" + +/* implemenatation for eTrice interfaces*/ + +extern etThread * noThread; +void etThread_execute(etThread* self); + +void DAVE_Init(void); +void etTime_init(void); +void DAVE_InstallTickHandler(void); + + +void etUserEntry(void){ + DAVE_Init(); + etTime_init(); + DAVE_InstallTickHandler(); +// initHw(); +} + +void etUserPreRun(void){ + __enable_irq(); + etThread_execute(noThread); +} + +void etUserPostRun(void){ } +void etUserExit(void){ } + diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etSema.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etSema.c new file mode 100644 index 000000000..0f3dd7433 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etSema.c @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 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: + * Thomas Schuetz, Thomas Jung (initial contribution) + * + *******************************************************************************/ + + +#include "osal/etSema.h" +#include "osal/etTimer.h" + +#include "debugging/etMSCLogger.h" +#include "helpers/etTimeHelpers.h" + +extern etTimer * singleThreadedTimer; + +void etSema_construct(etSema* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etSema", "construct") + + ET_MSC_LOGGER_SYNC_EXIT +} +void etSema_destruct(etSema* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etSema", "destruct") + + ET_MSC_LOGGER_SYNC_EXIT +} + +void etSema_wakeup(etSema* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etSema", "wakeup") + + ET_MSC_LOGGER_SYNC_EXIT +} + +void etSema_waitForWakeup(etSema* self){ + static etTime actualTime = {0,0}; + static etTime nextTime = {0,0}; + ET_MSC_LOGGER_SYNC_ENTRY("etSema", "waitForWakeup") + // busy wait as specified in etphys + getTimeFromTarget(&actualTime); + if (etTimeHelpers_isGreater(&actualTime, &nextTime)){ + etTimeHelpers_add(&nextTime,&(singleThreadedTimer->timerInterval)); + // call the do actions for the single thread + singleThreadedTimer->timerFunction(singleThreadedTimer->timerFunctionData); + } + ET_MSC_LOGGER_SYNC_EXIT +} diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etThread.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etThread.c new file mode 100644 index 000000000..efec2794f --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etThread.c @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2013 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: + * Thomas Schuetz, Thomas Jung (initial contribution) + * + *******************************************************************************/ + +/** + * + * etThread.c FreeRTOS implementation of etThread + * + */ + +#include "osal/etThread.h" + +#include "debugging/etLogger.h" +#include "debugging/etMSCLogger.h" + +void etThread_execute(etThread* self); + +etThread * noThread = 0; + +void etThread_construct( + etThread* self, + etStacksize stacksize, + etPriority priority, + etThreadname threadName, + etThreadFunction threadFunction, + void* threadFunctionData) +{ + ET_MSC_LOGGER_SYNC_ENTRY("etThread", "construct") + + /* fill in data */ + self->stacksize = stacksize; + self->priority = priority; + self->threadName = threadName; + self->threadFunction = threadFunction; + self->threadFunctionData = threadFunctionData; + // for the single threaded port stacksize and prio is not needed + // save the Threadpointer as singleton + if(noThread==0){ + noThread=self; + }else{ + while(1){}; + } + ET_MSC_LOGGER_SYNC_EXIT +} + +void etThread_start(etThread* self) { + ET_MSC_LOGGER_SYNC_ENTRY("etThread", "start") + ET_MSC_LOGGER_SYNC_EXIT +} + +void etThread_execute(etThread* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etThread", "execute") + /* etThread_execute redirects the call from the thread to the execute function in the eTrice runtime to enable correct synchronous MSC logging */ + self->threadFunction(self->threadFunctionData); + ET_MSC_LOGGER_SYNC_EXIT +} + +void etThread_destruct(etThread* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etThread", "destruct") + + ET_MSC_LOGGER_SYNC_EXIT +} + +void etThread_sleep(etInt32 millis){ + ET_MSC_LOGGER_SYNC_ENTRY("etThread", "sleep") + + ET_MSC_LOGGER_SYNC_EXIT +} diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etTime.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etTime.c new file mode 100644 index 000000000..35b1a3a74 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etTime.c @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 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: + * Thomas Schuetz, Thomas Jung (initial contribution) + * + *******************************************************************************/ + +#include "osal/etTime.h" +#include "XMC4500.h" +#include "Dave.h" +#include "helpers/etTimeHelpers.h" + +etTime targetTime; +const PPB_Type *ppb=(PPB_Type *)0xE000E000; + +void etTime_init(void){ + targetTime.nSec=0; + targetTime.sec=0; +} + + +void getTimeFromTarget(etTime *t) { +etTime t1={0,0}; + + // keep in mind that it is not possible to stop the timer counter itself + // overflow must be checked after reading the counter + // if an overflow occurs do it again + + // the count flag is clear on read, read it + t1.nSec=ppb->SYST_CSR; + do { + // amount of ticks = reloadRegister - countRegister + t1.nSec=(ppb->SYST_RVR-ppb->SYST_CVR); + *t = targetTime; + }while(ppb->SYST_CSR & 0x00010000); + + // nSec = amount of ticks * 1000 / 120; if CPUCLK == 120Mhz + t1.nSec*=1000; + t1.nSec/=(SYSTIMER_SYS_CORE_CLOCK/1000000); + // add t1 to time + etTimeHelpers_add(t,&t1); +} + +/* the timer interrupt */ + +void etTick_Handler(void *nanoSecPerTick) { +// this interrupt will be called every 1ms +// targetTime.nSec += 1000000L; + targetTime.nSec += (uint32_t)nanoSecPerTick; + + if (targetTime.nSec >= 1000000000L) { + targetTime.nSec -= 1000000000L; + targetTime.sec++; + } +} + diff --git a/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etTimer.c b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etTimer.c new file mode 100644 index 000000000..431c97f05 --- /dev/null +++ b/runtime/org.eclipse.etrice.runtime.c/src/platforms/ST_XMC4500_DaveCE_Generic/etTimer.c @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2013 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: + * Thomas Schuetz (initial contribution), Thomas Jung + * + *******************************************************************************/ + +#include "osal/etTimer.h" +#include "helpers/etTimeHelpers.h" + +#include "debugging/etLogger.h" +#include "debugging/etMSCLogger.h" + +etTimer * singleThreadedTimer; + +void etTimer_construct(etTimer* self, etTime* timerInterval, etTimerFunction timerFunction, void* timerFunctionData){ + ET_MSC_LOGGER_SYNC_ENTRY("etTimer", "construct") + { + self->osTimerData = NULL; + self->timerInterval.sec = timerInterval->sec; + self->timerInterval.nSec = timerInterval->nSec; + self->timerFunction = timerFunction; + self->timerFunctionData = timerFunctionData; + + + } + // store the timer, it will be needed to call the do actions + singleThreadedTimer = self; + + ET_MSC_LOGGER_SYNC_EXIT +} + +void etTimer_start(etTimer* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etTimer", "start") + + ET_MSC_LOGGER_SYNC_EXIT +} + + +void etTimer_stop(etTimer* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etTimer", "stop") + + ET_MSC_LOGGER_SYNC_EXIT +} + +void etTimer_destruct(etTimer* self){ + ET_MSC_LOGGER_SYNC_ENTRY("etTimer", "destruct") + + ET_MSC_LOGGER_SYNC_EXIT +} + + |