Support detaching and reattaching of USB devices during runtime.

Note: At least some USB device types have their /dev/tty/ACMn number increased for every reattachment. Therefore, this new feature is to be used with a cmdline parameter like '/dev/tty/ACM*'. The quotes keeps the shell from globbing the wildcard.
This commit is contained in:
Oliver Schmidt 2022-08-24 23:18:05 +02:00
parent 95e16e6af0
commit 242a4bc6b5

View File

@ -623,6 +623,21 @@ void main(int argc, char **argv)
* Get vdrv images. * Get vdrv images.
*/ */
vdrvactive = vdrvopen(vdrvdir); vdrvactive = vdrvopen(vdrvdir);
/*
* Open socket.
*/
prlog("a2pid: Open server socket\n");
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(6551);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
srvfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (srvfd < 0)
die("error: socket create");
if (bind(srvfd,(struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
die("error: bind socket");
if (listen(srvfd, MAX_CLIENT - 1) < 0)
die("error: listen socket");
#if defined(SETSERCLK) && defined(__ARMEL__) #if defined(SETSERCLK) && defined(__ARMEL__)
/* /*
* Initialize ACIA clock for Apple II Pi card * Initialize ACIA clock for Apple II Pi card
@ -630,18 +645,21 @@ void main(int argc, char **argv)
if (devtty == deftty) if (devtty == deftty)
gpclk(271); /* divisor for ~1.8 MHz => (500/271) MHz */ gpclk(271); /* divisor for ~1.8 MHz => (500/271) MHz */
#endif #endif
/*
* Come back here on serial read error.
*/
openserial:
/* /*
* Open serial port. * Open serial port.
*/ */
if (!pathmatch(&devtty, ttypattern)) while (!pathmatch(&devtty, ttypattern))
die("error: serial port not found"); usleep(1000);
prlog("a2pid: Open serial port\n"); prlog("a2pid: Open serial port\n");
#ifdef TRACE #ifdef TRACE
printf("a2pid: open %s\n", devtty); printf("a2pid: open %s\n", devtty);
#endif #endif
a2fd = open(devtty, O_RDWR | O_NOCTTY); while ((a2fd = open(devtty, O_RDWR | O_NOCTTY)) < 0)
if (a2fd < 0) usleep(1000);
die("error: serial port open");
tcflush(a2fd, TCIFLUSH); tcflush(a2fd, TCIFLUSH);
tcgetattr(a2fd, &oldtio); /* save current port settings */ tcgetattr(a2fd, &oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio)); bzero(&newtio, sizeof(newtio));
@ -679,22 +697,7 @@ void main(int argc, char **argv)
newtio.c_cc[VMIN] = 3; /* blocking read until 3 chars received */ newtio.c_cc[VMIN] = 3; /* blocking read until 3 chars received */
tcsetattr(a2fd, TCSANOW, &newtio); tcsetattr(a2fd, TCSANOW, &newtio);
/* /*
* Open socket. * Come back here on RESET.
*/
prlog("a2pid: Open server socket\n");
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(6551);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
srvfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (srvfd < 0)
die("error: socket create");
if (bind(srvfd,(struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
die("error: bind socket");
if (listen(srvfd, MAX_CLIENT - 1) < 0)
die("error: listen socket");
/*
* Come basck here on RESET.
*/ */
reset: reset:
state = RUN; state = RUN;
@ -973,7 +976,8 @@ reset:
else else
{ {
prlog("a2pid: error read serial port ????\n"); prlog("a2pid: error read serial port ????\n");
state = STOP; close(a2fd);
goto openserial;
} }
} }
/* /*