From: ljsebald <ljs...@us...> - 2023-09-05 02:10:11
|
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 da35b5992eda1330497aec78192bdd0400c239f9 (commit) from a588add704d8d271b4c729043d829733db139aa9 (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 da35b5992eda1330497aec78192bdd0400c239f9 Author: Tchan0 <617...@us...> Date: Mon Sep 4 22:21:16 2023 +0200 Add termios2 for linux, explain SH-4 custom baudrates in README (#21) * Addition of termios2, allowing custom baudrates on Linux systems. Adaptation of README to soften the recommendation for FTDI chips, and talke about the SH-4 specific baudrates. Signed-off-by: T_chan <t_c...@ho...> * Update dc-tool.c fix identation * Reverting the MacOS part of the README Reverting the MacOS part of the README, since MacOS does not support custom baudrates after all, against our assumptions. Doesn't affect the rest of the Merge Request, as that only modifies behavior on Linux systems. --------- Signed-off-by: T_chan <t_c...@ho...> ----------------------------------------------------------------------- Summary of changes: README.md | 20 +++++++-------- host-src/tool/dc-tool.c | 68 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 82e0c32..d458a42 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ Dreamcast in order to run and debug them. To be used, you must have a way to connect your Dreamcast console to your computer, it can be one of the following: * A **Coders Cable** (a serial cable, the historical way to do that). It can be - a cable with the classical `RS-232`/`DE-9` connector or with the - `FT232RL USB-Serial` module. + a cable with the classical `RS-232`/`DE-9` connector or with a + `USB-Serial` module. * A **Broadband Adapter**, ref. `HIT-400`, often shortened as **BBA**, a `10/100Mbits` Ethernet network card. * A **LAN Adapter**, ref. `HIT-300`, a `10Mbits` Ethernet network card. @@ -95,20 +95,20 @@ To run a GNU debugger session over the **dcload** connection: * Tested systems: Debian GNU/Linux 2.2; Gentoo/Linux 2.6.7; Cygwin; Mac OSX 10.3.5 (Panther); macOS 10.15.2 (Catalina), MinGW/MSYS, [DreamSDK](https://www.dreamsdk.org), MinGW-w64/MSYS2. -* `1.56M` and `500K` baud now supported with the **FTDI USB-Serial** driver, - including the driver built into macOS 10.12 and above. - **Note:** Works with the cheap and commonly available **FT232RL USB-Serial** - boards as well as the (outdated) **FT232BM USB-Serial** chip running at - `6.144Mhz`, e.g.: - - Linux: `dc-tool-ser -t /dev/usb/tts/0 -b 1500000 -x <sh-executable>` - - Windows: `dc-tool-ser -t COM4 -b 500000 -x <sh-executable>` - - macOS: `dc-tool-ser -t /dev/cu.usbserial-A50285BI -b 1500000 -x <sh-executable>` +* To attain the highest speeds with `dcload-serial`, you need to select a `USB-Serial` module that matches the baudrates that the Dreamcast's SH-4 cpu can generate. Above `115200`, the SH-4 cpu generates the following baudrates: `223214`, `260416`, `312500`, `390625`, `520833`, `781250`, `1562500`. + * **Silicon Labs CP2102N**-based chips have a good match with the SH-4, so you're pretty much guaranteed to attain the highest speed, `1562500`. + * **FTDI FT232***-based chips do no match the SH-4 baudrates closely enough, so `781250` will work, but `1.56M` will depend on your specific chip (ie, chip luck) +* Examples of how to launch a program: + * Linux: `dc-tool-ser -t /dev/usb/tts/0 -b 1500000 -x <sh-executable>` + * Windows: `dc-tool-ser -t COM4 -b 500000 -x <sh-executable>` + * macOS: `dc-tool-ser -t /dev/cu.usbserial-A50285BI -b 1500000 -x <sh-executable>` * As of `1.0.4`, little-endian byte order is enforced in the host so dc-tool now runs on big-endian systems like a Mac. * As of `1.0.3`, serial speed is changed at runtime rather than compile time. * `115200` works fine in most cases but `57600` baud is the standard baud. There is an `-e` option that will enable an alternate `115200` which may work better in some rare cases. Use this only if the regular `115200` is unstable. +* `234000` will probably only work with the `-e` option enabled. * Patches and improvements are welcome. ## Modern macOS Notes diff --git a/host-src/tool/dc-tool.c b/host-src/tool/dc-tool.c index f27e72b..2f6c416 100644 --- a/host-src/tool/dc-tool.c +++ b/host-src/tool/dc-tool.c @@ -33,11 +33,18 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> + #ifdef _WIN32 #include <windows.h> #else +#ifdef __linux__ +#include <asm/termbits.h> +#include <sys/ioctl.h> +#else #include <termios.h> #endif +#endif + #include <sys/time.h> #include <unistd.h> #include <utime.h> @@ -220,7 +227,12 @@ int getopt(int nargc, char * const *nargv, const char *ostr) { extern char *optarg; #ifndef _WIN32 int dcfd; -struct termios oldtio; +#ifdef BOTHER +typedef struct termios2 termiosx_t ; +#else +typedef struct termios termiosx_t; +#endif +termiosx_t oldtio; #else HANDLE hCommPort; BOOL bDebugSocketStarted = FALSE; @@ -517,6 +529,9 @@ void get_supported_speed (unsigned int *speed, speed_t *baudconst){ speed_t tmpbaud; unsigned int tmpspeed = *speed; +#ifdef BOTHER + *baudconst = BOTHER; //with BOTHER, any custom speed can be chosen +#else for (tmpbaud = B0; tmpbaud == B0;) { switch(tmpspeed) { #ifdef B1500000 @@ -560,12 +575,37 @@ void get_supported_speed (unsigned int *speed, speed_t *baudconst){ } *baudconst = tmpbaud; *speed = tmpspeed; +#endif +} + +void tc_close (int fd) { +#ifndef BOTHER + tcflush(fd, TCIOFLUSH); +#endif + close(fd); +} + +int tc_get_attr(int fd, termiosx_t *tio) { +#ifdef BOTHER + return ioctl(dcfd, TCGETS2, tio); +#else + return tcgetattr(dcfd, tio); +#endif +} + +int tc_set_attr (int fd, termiosx_t *tio) { +#ifdef BOTHER + return ioctl(fd, TCSETS2, tio); +#else + tcflush(fd, TCIOFLUSH); + return tcsetattr(fd, TCSANOW, tio); +#endif } void set_io_speed (unsigned int speed, speed_t baudconst) { - struct termios newtio; + termiosx_t newtio; - tcgetattr(dcfd, &oldtio); // save current serial port settings + tc_get_attr(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; @@ -575,16 +615,18 @@ void set_io_speed (unsigned int speed, speed_t baudconst) { newtio.c_cc[VTIME] = 0; // inter-character timer unused newtio.c_cc[VMIN] = 1; // blocking read until 1 character arrives +#ifdef BOTHER + newtio.c_cflag |= BOTHER; + newtio.c_ospeed = speed; + newtio.c_cflag |= BOTHER << IBSHIFT; + newtio.c_ispeed = speed; +#else cfsetispeed(&newtio, baudconst); cfsetospeed(&newtio, baudconst); +#endif - // we don't error on these because it *may* still work - if(tcflush(dcfd, TCIFLUSH) < 0) { - perror("tcflush"); - } - - if(tcsetattr(dcfd, TCSANOW, &newtio) < 0) { - perror("tcsetattr"); + if(tc_set_attr(dcfd, &newtio) < 0) { + perror("tc_set_attr"); printf("warning: your baud rate is likely set incorrectly\n"); } @@ -672,8 +714,7 @@ void finish_serial(void) { #ifdef _WIN32 FlushFileBuffers(hCommPort); #else - tcflush(dcfd, TCIOFLUSH); - tcsetattr(dcfd, TCSANOW, &oldtio); + tc_set_attr(dcfd, &oldtio); #endif cleanup(); } @@ -684,8 +725,7 @@ void close_serial(void) { FlushFileBuffers(hCommPort); CloseHandle(hCommPort); #else - tcflush(dcfd, TCIOFLUSH); - close(dcfd); + tc_close(dcfd); #endif } hooks/post-receive -- A serial program loader for the Dreamcast. |