Skip to content

Commit fd038b4

Browse files
authored
Merge pull request #1 from FOME-Tech/macos
support macos
2 parents 8321fc6 + 08c4e51 commit fd038b4

File tree

13 files changed

+1020
-2
lines changed

13 files changed

+1020
-2
lines changed

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug",
11+
"program": "${workspaceFolder}/Host/BootCommander",
12+
"args": ["-d=/dev/tty.usbmodem1301", "/Users/matthewkennedy/Downloads/fome_update.srec"],
13+
"cwd": "${workspaceFolder}/Host/"
14+
}
15+
]
16+
}

Host/Source/BootCommander/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ if(WIN32)
8888
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WINDOWS -DPLATFORM_64BIT -D_CRT_SECURE_NO_WARNINGS")
8989
endif()
9090
endif()
91+
elseif(APPLE)
92+
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
9193
elseif(UNIX)
9294
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
9395
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_LINUX -DPLATFORM_32BIT -pthread -std=gnu99")

Host/Source/LibOpenBLT/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ option(LINT_ENABLED "Configurable to enable/disable the PC-lint target" OFF)
6363
# Set the port directory, which is platform specific
6464
if(WIN32)
6565
set(PROJECT_PORT_DIR ${PROJECT_SOURCE_DIR}/port/windows)
66+
elseif(APPLE)
67+
set(PROJECT_PORT_DIR ${PROJECT_SOURCE_DIR}/port/macos)
6668
elseif(UNIX)
6769
set(PROJECT_PORT_DIR ${PROJECT_SOURCE_DIR}/port/linux)
6870
endif(WIN32)
@@ -100,6 +102,9 @@ if(WIN32)
100102
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WINDOWS -DPLATFORM_64BIT -D_CRT_SECURE_NO_WARNINGS")
101103
endif()
102104
endif()
105+
elseif(APPLE)
106+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_MACOS -DPLATFORM_64BIT -DNO_CAN_OR_USB -pthread -std=gnu99")
107+
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
103108
elseif(UNIX)
104109
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
105110
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_LINUX -DPLATFORM_32BIT -pthread -std=gnu99")
@@ -186,7 +191,9 @@ endif(BUILD_STATIC)
186191
# "make openblt_shared" to build individually shared library.
187192
if(BUILD_SHARED)
188193
add_library(openblt_shared SHARED ${LIB_SRCS})
189-
if(UNIX)
194+
if (APPLE)
195+
# Nothing to do here, but we need the case as UNIX will also be defined
196+
elseif(UNIX)
190197
# Under Unix the LibUsb library (http://libusb.info/) is needed for the USB support.
191198
# Make sure the libusb-1.0-0 and libusb-1.0-0-dev packages are installed to be able
192199
# to build LibOpenBLT. Example under Debian/Ubuntu:
@@ -196,7 +203,7 @@ if(BUILD_SHARED)
196203
elseif(WIN32)
197204
# Link the Winsock library
198205
target_link_libraries(openblt_shared ws2_32 winusb setupapi)
199-
endif(UNIX)
206+
endif(APPLE)
200207
if(CMAKE_C_COMPILER_ID MATCHES MSVC)
201208
# Microsoft Visual Studio does not add "lib" to the name of the DLL, whereas GCC
202209
# (including MinGW) does. Correct this here.

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+

Host/Source/LibOpenBLT/port/macos/dummy/dummy.h

Whitespace-only changes.

0 commit comments

Comments
 (0)