From: ljsebald <ljs...@us...> - 2023-08-29 21:43:08
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A serial program loader for the Dreamcast.". The branch, master has been updated via 9ff1c322d00cfc861514faa2188b2007ee8ab44a (commit) via af4ccc8a4b839c6a8c5ff954c06ffc0544f8600b (commit) via 5cf66a2fb0c626fee68b113de8846f28cf163a21 (commit) from be68a319e519c2da4bf9ff2b3a33914799dcb6b0 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 9ff1c322d00cfc861514faa2188b2007ee8ab44a Merge: be68a31 af4ccc8 Author: Lawrence Sebald <ljs...@us...> Date: Tue Aug 29 17:42:21 2023 -0400 Merge pull request #18 from Tchan0/refactor_termios Refactor termios in preparation of termios2 commit af4ccc8a4b839c6a8c5ff954c06ffc0544f8600b Author: Tchan0 <617...@us...> Date: Fri Aug 25 19:08:49 2023 +0200 Removal of -DB compiler defines Removal of -DB1500000 -DB500000 -DB230400, since the #ifdefs should be enough commit 5cf66a2fb0c626fee68b113de8846f28cf163a21 Author: Tchan0 <617...@us...> Date: Fri Aug 25 19:07:47 2023 +0200 refactor termios stuff in preparation of termios2 Small refactoring of the termios baudrate constants selection: - to eliminate the possibility of an endless loop if speed & INITIAL_SPEED are not part of the available constants - default to 38400 (the highest POSIX value) if no match was found with speed & INITIAL_SPEED - put 57600 and 115200 inside ifdefs as they in fact do not seem to be part of POSIX - code moved to separate functions to facilitate future integration of termios2 - changed variable name speedsel to baudconst, as there are already so many variables containing "speed", which ends up being confusing ----------------------------------------------------------------------- Summary of changes: host-src/tool/Makefile | 2 +- host-src/tool/dc-tool.c | 94 +++++++++++++++++++++++++++++++------------------ 2 files changed, 60 insertions(+), 36 deletions(-) diff --git a/host-src/tool/Makefile b/host-src/tool/Makefile index 5a206e8..edc894e 100644 --- a/host-src/tool/Makefile +++ b/host-src/tool/Makefile @@ -3,7 +3,7 @@ include ../../Makefile.cfg LZOPATH = ../../minilzo-2.10 CC = $(HOSTCC) -CFLAGS = $(HOSTCFLAGS) -DDCLOAD_VERSION=\"$(VERSION)\" -DDEFAULT_SPEED=$(TOOL_DEFAULT_SPEED) -DSERIALDEVICE="\"$(SERIALDEVICE)\"" -DHAVE_GETOPT -DB1500000 -DB500000 -DB230400 +CFLAGS = $(HOSTCFLAGS) -DDCLOAD_VERSION=\"$(VERSION)\" -DDEFAULT_SPEED=$(TOOL_DEFAULT_SPEED) -DSERIALDEVICE="\"$(SERIALDEVICE)\"" -DHAVE_GETOPT LDFLAGS = $(HOSTLDFLAGS) INCLUDE = -I$(LZOPATH) -I/usr/local/include diff --git a/host-src/tool/dc-tool.c b/host-src/tool/dc-tool.c index e1b8ff9..fe21d45 100644 --- a/host-src/tool/dc-tool.c +++ b/host-src/tool/dc-tool.c @@ -512,70 +512,71 @@ void output_error(void) { } #endif -/* setup serial port */ -int open_serial(char *devicename, unsigned int speed, unsigned int *speedtest) { - *speedtest = speed; #ifndef _WIN32 - struct termios newtio; - speed_t speedsel; - - dcfd = open(devicename, O_RDWR | O_NOCTTY); - if(dcfd < 0) { - perror(devicename); - exit(-1); - } - - tcgetattr(dcfd, &oldtio); // save current serial port settings - memset(&newtio, 0, sizeof(newtio)); // clear struct for new port settings +void get_supported_speed (unsigned int *speed, speed_t *baudconst){ + speed_t tmpbaud; + unsigned int tmpspeed = *speed; - newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD; - newtio.c_iflag = IGNPAR; - newtio.c_oflag = 0; - newtio.c_lflag = 0; - newtio.c_cc[VTIME] = 0; // inter-character timer unused - newtio.c_cc[VMIN] = 1; // blocking read until 1 character arrives - - for(speedsel=0; !speedsel;) { - switch(speed) { + for (tmpbaud = B0; tmpbaud == B0;) { + switch(tmpspeed) { #ifdef B1500000 case 1500000: - speedsel = B1500000; + tmpbaud = B1500000; break; #endif #ifdef B500000 case 500000: - speedsel = B500000; + tmpbaud = B500000; break; #endif #ifdef B230400 case 230400: - speedsel = B230400; + tmpbaud = B230400; break; #endif +#ifdef B115200 case 115200: - speedsel = B115200; + tmpbaud = B115200; break; +#endif +#ifdef B57600 case 57600: - speedsel = B57600; + tmpbaud = B57600; break; +#endif case 38400: - speedsel = B38400; + tmpbaud = B38400; break; case 19200: - speedsel = B19200; + tmpbaud = B19200; break; case 9600: - speedsel = B9600; + tmpbaud = B9600; break; default: - printf("Unsupported baudrate (%d) - falling back to initial baudrate (%d)\n", speed, INITIAL_SPEED); - *speedtest = speed = INITIAL_SPEED; + tmpspeed = (tmpspeed == INITIAL_SPEED ? 38400 : INITIAL_SPEED); break; } } + *baudconst = tmpbaud; + *speed = tmpspeed; +} - cfsetispeed(&newtio, speedsel); - cfsetospeed(&newtio, speedsel); +void set_io_speed (unsigned int speed, speed_t baudconst) { + struct termios newtio; + + tcgetattr(dcfd, &oldtio); // save current serial port settings + + memset(&newtio, 0, sizeof(newtio)); // clear struct for new port settings + newtio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD; + newtio.c_iflag = IGNPAR; + newtio.c_oflag = 0; + newtio.c_lflag = 0; + newtio.c_cc[VTIME] = 0; // inter-character timer unused + newtio.c_cc[VMIN] = 1; // blocking read until 1 character arrives + + cfsetispeed(&newtio, baudconst); + cfsetospeed(&newtio, baudconst); // we don't error on these because it *may* still work if(tcflush(dcfd, TCIFLUSH) < 0) { @@ -596,6 +597,29 @@ int open_serial(char *devicename, unsigned int speed, unsigned int *speedtest) { } } #endif +} +#endif + +/* setup serial port */ +int open_serial(char *devicename, unsigned int speed, unsigned int *speedtest) { + *speedtest = speed; +#ifndef _WIN32 + speed_t baudconst; + + dcfd = open(devicename, O_RDWR | O_NOCTTY); + if(dcfd < 0) { + perror(devicename); + exit(-1); + } + + oldspeed = speed; + get_supported_speed (&speed, &baudconst); + if (speed != oldspeed){ + printf("Unsupported baudrate (%d) - falling back to baudrate (%d)\n", oldspeed, speed); + *speedtest = speed; + } + + set_io_speed (speed, baudconst); #else BOOL fSuccess; hooks/post-receive -- A serial program loader for the Dreamcast. |