EmptyEpsilon: fix serial code on musl and on ppc

This commit is contained in:
q66 2021-03-09 13:13:53 +01:00
parent 8f7b98804c
commit 462b2c11aa
2 changed files with 166 additions and 1 deletions

View file

@ -0,0 +1,165 @@
this fixes the serial driver on musl as well as on ppc
diff --git src/hardware/serialDriver.cpp src/hardware/serialDriver.cpp
index 0bb0228..ece29ab 100644
--- src/hardware/serialDriver.cpp
+++ src/hardware/serialDriver.cpp
@@ -2,11 +2,14 @@
#ifdef __WIN32__
#include <windows.h>
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
//Including ioctl or termios conflicts with asm/termios.h which we need for TCGETS2. So locally define the ioctl and tcsendbreak functions. Yes, it's dirty, but it works.
//#include <sys/ioctl.h>
//#include <termios.h>
#ifndef ANDROID
+#ifndef __GLIBC__
+#define __THROW
+#endif
extern "C" {
extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
extern int tcsendbreak (int __fd, int __duration) __THROW;
@@ -16,6 +19,12 @@
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
+#ifdef __powerpc__
+ /* ppc has no tcgets2 or termios2, but termios covers the same stuff */
+ #define termios2 termios
+ #define TCGETS2 TCGETS
+ #define TCSETS2 TCSETS
+#endif
#endif
#if defined(__APPLE__) && defined(__MACH__)
#include <IOKit/serial/ioss.h>
@@ -57,7 +66,7 @@ SerialPort::SerialPort(string name)
}
}
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
if (!name.startswith("/dev/"))
name = "/dev/" + name;
handle = open(name.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
@@ -76,7 +85,7 @@ SerialPort::~SerialPort()
CloseHandle(handle);
handle = INVALID_HANDLE_VALUE;
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
close(handle);
handle = 0;
#endif
@@ -87,7 +96,7 @@ bool SerialPort::isOpen()
#ifdef __WIN32__
return handle != INVALID_HANDLE_VALUE;
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
return handle;
#endif
return false;
@@ -163,7 +172,7 @@ void SerialPort::configure(int baudrate, int databits, EParity parity, EStopBits
LOG(ERROR) << "SetCommState failed!" << error;
}
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
fsync(handle);
struct termios2 tio;
@@ -317,7 +326,7 @@ void SerialPort::send(void* data, int data_size)
data_size -= written;
}
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
while(data_size > 0)
{
int written = write(handle, data, data_size);
@@ -345,7 +354,7 @@ int SerialPort::recv(void* data, int data_size)
}
return read_size;
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
int bytes_read = read(handle, data, data_size);
if (bytes_read > 0)
return bytes_read;
@@ -361,7 +370,7 @@ void SerialPort::setDTR()
#ifdef __WIN32__
EscapeCommFunction(handle, SETDTR);
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
int bit = TIOCM_DTR;
ioctl(handle, TIOCMBIS, &bit);
#endif
@@ -377,7 +386,7 @@ void SerialPort::clearDTR()
#ifdef __WIN32__
EscapeCommFunction(handle, CLRDTR);
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
int bit = TIOCM_DTR;
ioctl(handle, TIOCMBIC, &bit);
#endif
@@ -393,7 +402,7 @@ void SerialPort::setRTS()
#ifdef __WIN32__
EscapeCommFunction(handle, SETRTS);
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
int bit = TIOCM_RTS;
ioctl(handle, TIOCMBIS, &bit);
#endif
@@ -409,7 +418,7 @@ void SerialPort::clearRTS()
#ifdef __WIN32__
EscapeCommFunction(handle, CLRRTS);
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
int bit = TIOCM_RTS;
ioctl(handle, TIOCMBIC, &bit);
#endif
@@ -425,7 +434,7 @@ void SerialPort::sendBreak()
Sleep(1);
ClearCommBreak(handle);
#endif
-#if (defined(__gnu_linux__) && !defined(ANDROID)) || (defined(__APPLE__) && defined(__MACH__))
+#if (defined(__linux__) && !defined(ANDROID)) || (defined(__APPLE__) && defined(__MACH__))
tcsendbreak(handle, 0);
#endif
}
@@ -456,7 +465,7 @@ std::vector<string> SerialPort::getAvailablePorts()
LOG(ERROR) << "Failed to open registry key for serial port list.";
}
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
DIR* dir = opendir("/dev/");
if (dir)
{
@@ -511,7 +520,7 @@ string SerialPort::getPseudoDriverName(string port)
}
return ret;
#endif
-#ifdef __gnu_linux__
+#ifdef __linux__
FILE* f = fopen(("/sys/class/tty/" + port + "/device/modalias").c_str(), "rt");
if (!f)
return "";
diff --git src/hardware/serialDriver.h src/hardware/serialDriver.h
index 29cc0b5..9513457 100644
--- src/hardware/serialDriver.h
+++ src/hardware/serialDriver.h
@@ -14,7 +14,7 @@ private:
#ifdef __WIN32__
HANDLE handle;
#endif
-#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
int handle;
#endif

View file

@ -4,7 +4,7 @@ _ver_major=2020
_ver_minor=11
_ver_patch=23
version="${_ver_major}.${_ver_minor}.${_ver_patch}"
revision=1
revision=2
wrksrc="EmptyEpsilon-EE-${version}"
build_style=cmake
configure_args="-DSERIOUS_PROTON_DIR=$XBPS_BUILDDIR/SeriousProton-EE-${version}