/**
* @file o3000_portable.h
* @brief O-3000 definitions to make portable platform-independent code
* @author Patrick Roth - roth@stettbacher.ch
* @author Christian Jaeggi - jaeggi@stettbacher.ch
* @version 1.0
* @date 2016-03-01
* @copyright 2012-2016 Stettbacher Signal Processing AG
*
* @remarks
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
*/
#ifndef _O3000_PORTABLE_H
#define _O3000_PORTABLE_H
/* stdint.h is not available on older MSVC */
#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#else
#include
#endif // defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
/*
* Calling conventions
* The System V ABI is one of the major ABIs in use today and is virtually universal among Unix
* systems. It is the calling convention used by toolchains such as i686-elf-gcc and x86_64-elf-gcc.
*
* Windows builds often use "project files" and are less transparent and more ad hoc than Makefiles.
* As an example, the driver crashes by calling a callback previously register via .NET. Therfore
* on MSVC, the calling ABI is defined. On other system (UNIX), the macros below are left
* empty.
*
* _WIN32 is always defined for Win32 or Win64 applications.
*/
#ifndef _WIN32
#define __cdecl /* nothing */
#define __stdcall /* nothing */
#define __fastcall /* nothing */
#else
#include
#endif // _WIN32
/*
* aligned malloc functiions
*/
#ifndef _WIN32
#define ALIGNED_ALLOC(align, size) aligned_alloc(align, size)
#define ALIGNED_FREE(buf) free(buf)
#else
#include
#define ALIGNED_ALLOC(align, size) _aligned_malloc(size, align)
#define ALIGNED_FREE(buf) _aligned_free(buf)
#endif // _WIN32
/*
* structure packing macros
*/
#if defined(_MSC_VER)
#define __func__ __FUNCTION__
#define __packed__ __packed
#else
/* define nothing for __func__ because it's used as default macro at source code */
#define __packed__ __attribute__ ((packed))
#endif // defined(_MSC_VER)
/*
* mutexes
*
* copied from libusb project see files os/threads_windows.* and os/threads_poxix.*
*/
#if defined(_MSC_VER)
#define O3000_MUTEX_INITIALIZER 0L
typedef LONG o3000_mutex_static_t;
static inline void o3000_mutex_static_lock(o3000_mutex_static_t *mutex) {
while (InterlockedExchange(mutex, 1L) == 1L)
SleepEx(0, TRUE);
}
static inline void o3000_mutex_static_unlock(o3000_mutex_static_t *mutex) {
InterlockedExchange(mutex, 0L);
}
#else
#include
#define O3000_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
typedef pthread_mutex_t o3000_mutex_static_t;
static inline void o3000_mutex_static_lock(o3000_mutex_static_t *mutex) {
(void)pthread_mutex_lock(mutex);
}
static inline void o3000_mutex_static_unlock(o3000_mutex_static_t *mutex) {
(void)pthread_mutex_unlock(mutex);
}
#endif // defined(_MSC_VER)
#endif // _O3000_PORTABLE_H