Commit 40d082ac authored by deuce's avatar deuce
Browse files

Add support for SPEED_MACROS_ONLY which defines that termios speeds must

be set and read using the POSIX macros and related (currently Linux-only).
parent 22b9e485
......@@ -298,7 +298,7 @@ endif
# PThread-specific flags
ifeq ($(os),linux) # Linux
CFLAGS += -DPOSIX_C_SOURCE=200809L -D_BSD_SOURCE -D_XOPEN_SOURCE=700
CFLAGS += -DPOSIX_C_SOURCE=200809L -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -DSPEED_MACROS_ONLY
ifndef THREADS_ACTUALLY_WORK
CFLAGS += -D_THREAD_SUID_BROKEN
endif
......
......@@ -11,6 +11,9 @@ if(WIN32)
list(APPEND SOURCE comio_win32.c)
else()
list(APPEND SOURCE comio_nix.c)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_compile_definitions(comio PRIVATE SPEED_MACROS_ONLY)
endif()
endif()
add_library(comio SHARED ${SOURCE})
set_target_properties(comio PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
......
......@@ -40,6 +40,160 @@
#include "comio.h"
#include "genwrap.h"
#ifdef SPEED_MACROS_ONLY
#define SUPPORTED_SPEED(x) \
if (speed <= (x)) \
return B##x
speed_t rate_to_macro(unsigned long speed)
{
// Standard values
SUPPORTED_SPEED(0);
SUPPORTED_SPEED(50);
SUPPORTED_SPEED(75);
SUPPORTED_SPEED(110);
SUPPORTED_SPEED(134);
SUPPORTED_SPEED(150);
SUPPORTED_SPEED(200);
SUPPORTED_SPEED(300);
SUPPORTED_SPEED(600);
SUPPORTED_SPEED(1200);
SUPPORTED_SPEED(1800);
SUPPORTED_SPEED(2400);
SUPPORTED_SPEED(4800);
SUPPORTED_SPEED(9600);
SUPPORTED_SPEED(19200);
SUPPORTED_SPEED(38400);
// Non-POSIX
#ifdef B57600
SUPPORTED_SPEED(57600);
#endif
#ifdef B115200
SUPPORTED_SPEED(115200);
#endif
#ifdef B230400
SUPPORTED_SPEED(230400);
#endif
#ifdef B460800
SUPPORTED_SPEED(460800);
#endif
#ifdef B500000
SUPPORTED_SPEED(500000);
#endif
#ifdef B576000
SUPPORTED_SPEED(576000);
#endif
#ifdef B921600
SUPPORTED_SPEED(921600);
#endif
#ifdef B1000000
SUPPORTED_SPEED(1000000);
#endif
#ifdef B1152000
SUPPORTED_SPEED(1152000);
#endif
#ifdef B1500000
SUPPORTED_SPEED(1500000);
#endif
#ifdef B2000000
SUPPORTED_SPEED(2000000);
#endif
#ifdef B2500000
SUPPORTED_SPEED(2500000);
#endif
#ifdef B3000000
SUPPORTED_SPEED(3000000);
#endif
#ifdef B3500000
SUPPORTED_SPEED(3500000);
#endif
#ifdef B4000000
SUPPORTED_SPEED(4000000);
#endif
return B0;
}
#undef SUPPORTED_SPEED
#define SUPPORTED_SPEED(x) \
if (speed == B##x) \
return x;
unsigned long macro_to_rate(speed_t speed)
{
// Standard values
SUPPORTED_SPEED(0);
SUPPORTED_SPEED(50);
SUPPORTED_SPEED(75);
SUPPORTED_SPEED(110);
SUPPORTED_SPEED(134);
SUPPORTED_SPEED(150);
SUPPORTED_SPEED(200);
SUPPORTED_SPEED(300);
SUPPORTED_SPEED(600);
SUPPORTED_SPEED(1200);
SUPPORTED_SPEED(1800);
SUPPORTED_SPEED(2400);
SUPPORTED_SPEED(4800);
SUPPORTED_SPEED(9600);
SUPPORTED_SPEED(19200);
SUPPORTED_SPEED(38400);
// Non-POSIX
#ifdef B57600
SUPPORTED_SPEED(57600);
#endif
#ifdef B115200
SUPPORTED_SPEED(115200);
#endif
#ifdef B230400
SUPPORTED_SPEED(230400);
#endif
#ifdef B460800
SUPPORTED_SPEED(460800);
#endif
#ifdef B500000
SUPPORTED_SPEED(500000);
#endif
#ifdef B576000
SUPPORTED_SPEED(576000);
#endif
#ifdef B921600
SUPPORTED_SPEED(921600);
#endif
#ifdef B1000000
SUPPORTED_SPEED(1000000);
#endif
#ifdef B1152000
SUPPORTED_SPEED(1152000);
#endif
#ifdef B1500000
SUPPORTED_SPEED(1500000);
#endif
#ifdef B2000000
SUPPORTED_SPEED(2000000);
#endif
#ifdef B2500000
SUPPORTED_SPEED(2500000);
#endif
#ifdef B3000000
SUPPORTED_SPEED(3000000);
#endif
#ifdef B3500000
SUPPORTED_SPEED(3500000);
#endif
#ifdef B4000000
SUPPORTED_SPEED(4000000);
#endif
return 0;
}
#undef SUPPORTED_SPEED
#else
#define rate_to_macro(x) (x)
#define macro_to_rate(x) (x)
#endif
char* COMIOCALL comVersion(char* str, size_t len)
{
char revision[16];
......@@ -119,8 +273,8 @@ long COMIOCALL comGetBaudRate(COM_HANDLE handle)
* We actually have TWO speeds available...
* return the biggest one
*/
in = cfgetispeed(&t);
out = cfgetospeed(&t);
in = macro_to_rate(cfgetispeed(&t));
out = macro_to_rate(cfgetospeed(&t));
return ((long)(in>out?in:out));
}
......@@ -131,8 +285,8 @@ BOOL COMIOCALL comSetBaudRate(COM_HANDLE handle, unsigned long rate)
if(tcgetattr(handle, &t))
return FALSE;
cfsetispeed(&t, rate);
cfsetospeed(&t, rate);
cfsetispeed(&t, rate_to_macro(rate));
cfsetospeed(&t, rate_to_macro(rate));
if(tcsetattr(handle, TCSANOW, &t)==-1)
return FALSE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment