Skip to content

Commit 08c4e51

Browse files
committed
macos guards working
1 parent 1b936d2 commit 08c4e51

File tree

7 files changed

+472
-1
lines changed

7 files changed

+472
-1
lines changed

Host/Source/LibOpenBLT/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ if(WIN32)
103103
endif()
104104
endif()
105105
elseif(APPLE)
106-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_MACOS -DPLATFORM_64BIT -pthread -std=gnu99")
106+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_MACOS -DPLATFORM_64BIT -DNO_CAN_OR_USB -pthread -std=gnu99")
107107
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
108108
elseif(UNIX)
109109
if(CMAKE_SIZEOF_VOID_P EQUAL 4)

Host/Source/LibOpenBLT/candriver.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
* \endinternal
2727
****************************************************************************************/
2828

29+
#ifndef NO_CAN_OR_USB
30+
2931
/****************************************************************************************
3032
* Include files
3133
****************************************************************************************/
@@ -281,4 +283,5 @@ void CanRegisterEvents(tCanEvents const * events)
281283
} /*** end of CanRegisterEvents ***/
282284

283285

286+
#endif // NO_CAN_OR_USB
284287
/*********************************** end of candriver.c ********************************/

Host/Source/LibOpenBLT/openblt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
#include "session.h" /* Communication session module */
4040
#include "xcploader.h" /* XCP loader module */
4141
#include "xcptpuart.h" /* XCP UART transport layer */
42+
#ifndef NO_CAN_OR_USB
4243
#include "xcptpcan.h" /* XCP CAN transport layer */
4344
#include "xcptpusb.h" /* XCP USB transport layer */
45+
#endif // NO_CAN_OR_USB
4446
#include "xcptpnet.h" /* XCP TCP/IP transport layer */
4547

4648

@@ -173,6 +175,7 @@ LIBOPENBLT_EXPORT void BltSessionInit(uint32_t sessionType,
173175
xcpLoaderSettings.transport = XcpTpUartGetTransport();
174176
}
175177
}
178+
#ifndef NO_CAN_OR_USB
176179
else if (transportType == BLT_TRANSPORT_XCP_V10_CAN)
177180
{
178181
/* Verify transportSettings parameters because the XCP CAN transport layer
@@ -210,6 +213,7 @@ LIBOPENBLT_EXPORT void BltSessionInit(uint32_t sessionType,
210213
/* Link the transport layer to the XCP loader settings. */
211214
xcpLoaderSettings.transport = XcpTpUsbGetTransport();
212215
}
216+
#endif // NO_CAN_OR_USB
213217
else if (transportType == BLT_TRANSPORT_XCP_V10_NET)
214218
{
215219
/* Verify transportSettings parameters because the XCP NET transport layer
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/************************************************************************************//**
2+
* \file port/linux/critutil.c
3+
* \brief Critical section utility source file.
4+
* \ingroup Utility
5+
* \internal
6+
*----------------------------------------------------------------------------------------
7+
* C O P Y R I G H T
8+
*----------------------------------------------------------------------------------------
9+
* Copyright (c) 2017 by Feaser http://www.feaser.com All rights reserved
10+
*
11+
*----------------------------------------------------------------------------------------
12+
* L I C E N S E
13+
*----------------------------------------------------------------------------------------
14+
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
15+
* modify it under the terms of the GNU General Public License as published by the Free
16+
* Software Foundation, either version 3 of the License, or (at your option) any later
17+
* version.
18+
*
19+
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
20+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21+
* PURPOSE. See the GNU General Public License for more details.
22+
*
23+
* You have received a copy of the GNU General Public License along with OpenBLT. It
24+
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
25+
*
26+
* \endinternal
27+
****************************************************************************************/
28+
29+
/****************************************************************************************
30+
* Include files
31+
****************************************************************************************/
32+
#include <assert.h> /* for assertions */
33+
#include <stdint.h> /* for standard integer types */
34+
#include <stdbool.h> /* for boolean type */
35+
#include <pthread.h> /* for posix threads */
36+
#include "util.h" /* Utility module */
37+
38+
39+
/****************************************************************************************
40+
* Local data declarations
41+
****************************************************************************************/
42+
/** \brief Flag to determine if the critical section object was already initialized. */
43+
static volatile bool criticalSectionInitialized = false;
44+
45+
/** \brief Critical section object. */
46+
static volatile pthread_mutex_t mtxCritSect;
47+
48+
49+
/************************************************************************************//**
50+
** \brief Initializes the critical section module. Should be called before the
51+
** Enter/Exit functions are used. It is okay to call this initialization
52+
** multiple times from different modules.
53+
**
54+
****************************************************************************************/
55+
void UtilCriticalSectionInit(void)
56+
{
57+
/* Only initialize if not yet done so previously. */
58+
if (!criticalSectionInitialized)
59+
{
60+
/* Initialize the critical section object. */
61+
(void)pthread_mutex_init((pthread_mutex_t *)&mtxCritSect, NULL);
62+
/* Set initialized flag. */
63+
criticalSectionInitialized = true;
64+
}
65+
} /*** end of UtilCriticalSectionInit ***/
66+
67+
68+
/************************************************************************************//**
69+
** \brief Terminates the critical section module. Should be called once critical
70+
** sections are no longer needed. Typically called from another module's
71+
** termination function that also initialized it. It is okay to call this
72+
** termination multiple times from different modules.
73+
**
74+
****************************************************************************************/
75+
void UtilCriticalSectionTerminate(void)
76+
{
77+
/* Only terminate if it was initialized. */
78+
if (criticalSectionInitialized)
79+
{
80+
/* Reset the initialized flag. */
81+
criticalSectionInitialized = false;
82+
/* Delete the critical section object. */
83+
(void)pthread_mutex_destroy((pthread_mutex_t *)&mtxCritSect);
84+
}
85+
} /*** end of UtilCriticalSectionTerminate ***/
86+
87+
88+
89+
/************************************************************************************//**
90+
** \brief Enters a critical section. The functions UtilCriticalSectionEnter and
91+
** UtilCriticalSectionExit should always be used in a pair.
92+
**
93+
****************************************************************************************/
94+
void UtilCriticalSectionEnter(void)
95+
{
96+
/* Check initialization. */
97+
assert(criticalSectionInitialized);
98+
99+
/* Only continue if actually initialized. */
100+
if (criticalSectionInitialized)
101+
{
102+
(void)pthread_mutex_lock((pthread_mutex_t *)&mtxCritSect);
103+
}
104+
} /*** end of UtilCriticalSectionEnter ***/ /*lint !e456 !e454 */
105+
106+
107+
/************************************************************************************//**
108+
** \brief Leaves a critical section. The functions UtilCriticalSectionEnter and
109+
** UtilCriticalSectionExit should always be used in a pair.
110+
**
111+
****************************************************************************************/
112+
void UtilCriticalSectionExit(void)
113+
{
114+
/* Check initialization. */
115+
assert(criticalSectionInitialized);
116+
117+
/* Only continue if actually initialized. */
118+
if (criticalSectionInitialized)
119+
{
120+
(void)pthread_mutex_unlock((pthread_mutex_t *)&mtxCritSect); /*lint !e455 */
121+
}
122+
} /*** end of UtilCriticalSectionExit ***/
123+
124+
125+
/*********************************** end of critutil.c *********************************/
126+

0 commit comments

Comments
 (0)