Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: efe9f2775c173fc08726da9c5b61ba6847043c18 (plain) (blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
87
88
89
90
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
 * 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)
 *
 *******************************************************************************/

#include "etDatatypes.h"
#include "platform/etPlatform.h"

#include "debugging/etLogger.h"
#include "debugging/etMSCLogger.h"

/* implemenatation for eTrice interfaces*/

void etUserEntry(void){ }

void etUserPreRun(void){ }

void etUserPostRun(void){ }

void etUserExit(void){ }


/* platform specific functions */

#if defined __MINGW32__

/******************thread********************/
void etThread_execute(etThread* self);

void etThread_construct(etThread* self){
	ET_MSC_LOGGER_SYNC_ENTRY("etThread", "construct")
	self->osData = (HANDLE)_beginthread( (etThreadFunction)etThread_execute, self->stacksize, self );
	SetThreadPriority(self->osData, self->priority);
	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")
	TerminateThread(self->osData, 0);
	ET_MSC_LOGGER_SYNC_EXIT
}


/******************thread helpers********************/
void etThread_sleep(etInt32 millis){
	ET_MSC_LOGGER_SYNC_ENTRY("etThread", "sleep")
	Sleep(millis);
	ET_MSC_LOGGER_SYNC_EXIT
}

/*****************mutex**********************/
void etMutex_construct(etMutex* self){
	ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "construct")
	InitializeCriticalSection( &(self->osData) );
	ET_MSC_LOGGER_SYNC_EXIT
}
void etMutex_destruct(etMutex* self){
	ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "destruct")
	DeleteCriticalSection( &(self->osData) );
	ET_MSC_LOGGER_SYNC_EXIT
}

void etMutex_enter(etMutex* self){
	ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "enter")
    EnterCriticalSection( &(self->osData) );
	ET_MSC_LOGGER_SYNC_EXIT
}
void etMutex_leave(etMutex* self){
	ET_MSC_LOGGER_SYNC_ENTRY("etMutex", "leave")
    LeaveCriticalSection( &(self->osData) );
	ET_MSC_LOGGER_SYNC_EXIT
}

/********************semaphore****************/
void etSema_construct(etSema* self){
	ET_MSC_LOGGER_SYNC_ENTRY("etSema", "construct")
	self->osData = CreateEvent( NULL, FALSE, FALSE, NULL );
	ET_MSC_LOGGER_SYNC_EXIT
}
void etSema_destruct(etSema* self){
	ET_MSC_LOGGER_SYNC_ENTRY("etSema", "destruct")
	// TODO: implement this function
	ET_MSC_LOGGER_SYNC_EXIT
}

void etSema_wakeup(etSema* self){
	ET_MSC_LOGGER_SYNC_ENTRY("etSema", "wakeup")
	SetEvent( self->osData );
	ET_MSC_LOGGER_SYNC_EXIT
}

void etSema_waitForWakeup(etSema* self){
	ET_MSC_LOGGER_SYNC_ENTRY("etSema", "waitForWakeup")
	WaitForSingleObject( self->osData, INFINITE );
	ET_MSC_LOGGER_SYNC_EXIT
}
/*********************************************/

#elif defined __GNUC__

/******************thread********************/
void etThread_construct(etThread* self){}

void etThread_destruct(etThread* self){}

/*****************mutex**********************/
void etMutex_construct(etMutex* self){}
void etMutex_destruct(etMutex* self){}
void etMutex_enter(etMutex* self){}
void etMutex_leave(etMutex* self){}

/********************semaphore****************/
void etSema_construct(etSema* self){}
void etSema_destruct(etSema* self){}

void etSema_wakeup(etSema* self){}

void etSema_waitForWakeup(etSema* self){}
/*********************************************/

#endif

Back to the top