diff options
| author | Julian Blake Kongslie | 2022-05-08 15:51:35 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-05-08 15:51:35 -0700 |
| commit | 38c5ae5b60eae9562b97da42f47af3861847f8e5 (patch) | |
| tree | 556fd9e5c38fb2feea56ce5741ca02a5e110ad63 /tool | |
| parent | Make the script for setting up the TTY actually connect. (diff) | |
| download | multipdp8-38c5ae5b60eae9562b97da42f47af3861847f8e5.tar.xz | |
*Proper* serial port for memory downloads. 115200 8O2 RS232 with CRTRTS.
Diffstat (limited to 'tool')
| -rw-r--r-- | tool/con.c | 106 | ||||
| -rwxr-xr-x | tool/connect | 13 | ||||
| -rwxr-xr-x | tool/download.tcl | 33 | ||||
| -rw-r--r-- | tool/p8bin2uart.c | 2 |
4 files changed, 148 insertions, 6 deletions
diff --git a/tool/con.c b/tool/con.c new file mode 100644 index 0000000..8522786 --- /dev/null +++ b/tool/con.c | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /* con device */ | ||
| 2 | |||
| 3 | #include <signal.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <fcntl.h> | ||
| 8 | #include <termios.h> | ||
| 9 | #include <unistd.h> | ||
| 10 | |||
| 11 | struct termios save; | ||
| 12 | |||
| 13 | void | ||
| 14 | host(int fd) | ||
| 15 | { | ||
| 16 | int cc; | ||
| 17 | char buf[128]; | ||
| 18 | |||
| 19 | for (;;) { | ||
| 20 | cc = read(fd, buf, sizeof buf); | ||
| 21 | #ifdef HEX | ||
| 22 | if (cc < 0) | ||
| 23 | break; | ||
| 24 | for (int i = 0; i < cc; ++i) { | ||
| 25 | char hex[3]; | ||
| 26 | sprintf(hex, "%02X", (unsigned char) buf[i]); | ||
| 27 | write(1, hex, 2); | ||
| 28 | } | ||
| 29 | #else | ||
| 30 | if (cc > 0) | ||
| 31 | write(1, buf, cc); | ||
| 32 | else if (cc < 0) | ||
| 33 | break; | ||
| 34 | #endif | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | void | ||
| 39 | hup(int signo) | ||
| 40 | { | ||
| 41 | write(1, "HUP\n", 4); | ||
| 42 | tcsetattr(0, TCSADRAIN, &save); | ||
| 43 | _exit(0); | ||
| 44 | } | ||
| 45 | |||
| 46 | void | ||
| 47 | user(int fd) | ||
| 48 | { | ||
| 49 | char c, last = '\r'; | ||
| 50 | |||
| 51 | signal(SIGHUP, hup); | ||
| 52 | for (;;) | ||
| 53 | while (read(0, &c, 1) > 0) { | ||
| 54 | if (c == '~' && (last == '\n' || last == '\r' | ||
| 55 | || last == 4)) { | ||
| 56 | read(0, &c, 1); | ||
| 57 | if (c == '.') | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | write(fd, &c, 1); | ||
| 61 | last = c; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | int | ||
| 66 | main(int argc, char *argv[]) | ||
| 67 | { | ||
| 68 | int fd; | ||
| 69 | pid_t pid; | ||
| 70 | struct termios t; | ||
| 71 | |||
| 72 | if (argc != 2) | ||
| 73 | exit(1); | ||
| 74 | |||
| 75 | fd = open(argv[1], O_RDWR | O_NDELAY); | ||
| 76 | if (fd < 0) | ||
| 77 | exit(2); | ||
| 78 | fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NDELAY); | ||
| 79 | tcgetattr(fd, &t); | ||
| 80 | t.c_cc[VMIN] = 1; | ||
| 81 | t.c_cc[VTIME] = 0; | ||
| 82 | tcsetattr(fd, TCSADRAIN, &t); | ||
| 83 | |||
| 84 | tcgetattr(0, &t); | ||
| 85 | save = t; | ||
| 86 | t.c_iflag = 0; | ||
| 87 | t.c_oflag = 0; | ||
| 88 | t.c_lflag = 0; | ||
| 89 | t.c_cc[VMIN] = 1; | ||
| 90 | t.c_cc[VTIME] = 0; | ||
| 91 | tcsetattr(0, TCSADRAIN, &t); | ||
| 92 | |||
| 93 | if ((pid = fork()) > 0) { | ||
| 94 | user(fd); | ||
| 95 | } else if (pid == 0) { | ||
| 96 | host(fd); | ||
| 97 | } else { | ||
| 98 | perror("fork"); | ||
| 99 | _exit(EXIT_FAILURE); | ||
| 100 | } | ||
| 101 | |||
| 102 | tcsetattr(0, TCSADRAIN, &save); | ||
| 103 | kill(pid, SIGKILL); | ||
| 104 | close(fd); | ||
| 105 | _exit(EXIT_SUCCESS); | ||
| 106 | } | ||
diff --git a/tool/connect b/tool/connect index 536db5b..f900e0c 100755 --- a/tool/connect +++ b/tool/connect | |||
| @@ -1,21 +1,24 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | 2 | ||
| 3 | set -eux | 3 | set -eu |
| 4 | 4 | ||
| 5 | OLD_SETTINGS="$(stty -F /dev/ttyUSB0 -g)" | 5 | OLD_SETTINGS="$(stty -g -F /dev/ttyUSB0)" |
| 6 | 6 | ||
| 7 | stty -F /dev/ttyUSB0 \ | 7 | stty -F /dev/ttyUSB0 \ |
| 8 | 115200 \ | 8 | 115200 \ |
| 9 | -drain \ | 9 | -drain \ |
| 10 | -clocal \ | 10 | -clocal \ |
| 11 | cread \ | 11 | cread \ |
| 12 | -crtscts \ | 12 | crtscts \ |
| 13 | cs8 \ | 13 | cs8 \ |
| 14 | cstopb \ | 14 | cstopb \ |
| 15 | -hup \ | 15 | -hup \ |
| 16 | parenb \ | 16 | parenb \ |
| 17 | -parodd \ | 17 | parodd \ |
| 18 | -cmspar \ | ||
| 18 | -igncr \ | 19 | -igncr \ |
| 20 | ignpar \ | ||
| 21 | -parmrk \ | ||
| 19 | inpck \ | 22 | inpck \ |
| 20 | -istrip \ | 23 | -istrip \ |
| 21 | -ixany \ | 24 | -ixany \ |
| @@ -26,4 +29,4 @@ stty -F /dev/ttyUSB0 \ | |||
| 26 | 29 | ||
| 27 | con /dev/ttyUSB0 || true | 30 | con /dev/ttyUSB0 || true |
| 28 | 31 | ||
| 29 | stty -F "$OLD_SETTINGS" | 32 | stty -drain "$OLD_SETTINGS" -F /dev/ttyUSB0 2> /dev/null |
diff --git a/tool/download.tcl b/tool/download.tcl new file mode 100755 index 0000000..c0dca55 --- /dev/null +++ b/tool/download.tcl | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | #!/usr/bin/env expect | ||
| 2 | |||
| 3 | set timeout 3600 | ||
| 4 | |||
| 5 | set core 0 | ||
| 6 | set wordsperline 1 | ||
| 7 | |||
| 8 | if {$::argc > 1} { | ||
| 9 | set core [lindex $::argv 0] | ||
| 10 | set wordsperline [lindex $::argv 1] | ||
| 11 | } elseif {$::argc > 0} { | ||
| 12 | set core [lindex $::argv 0] | ||
| 13 | } | ||
| 14 | |||
| 15 | spawn tool/connect | ||
| 16 | |||
| 17 | send "@[format %x [expr $core * 32768 / $wordsperline]]\n" | ||
| 18 | |||
| 19 | while {[gets stdin line] >= 0} { | ||
| 20 | send "$line\n" | ||
| 21 | expect -ex "$line\n" | ||
| 22 | } | ||
| 23 | |||
| 24 | # It's likely we ended with a very large zero-memory operation. We want to see | ||
| 25 | # two command bytes echoed back to us in order to guarantee that the zero | ||
| 26 | # operation has completely flushed to memory. | ||
| 27 | send "?" | ||
| 28 | expect -ex "?" | ||
| 29 | send "?" | ||
| 30 | expect -ex "?" | ||
| 31 | |||
| 32 | send "\n~." | ||
| 33 | wait | ||
diff --git a/tool/p8bin2uart.c b/tool/p8bin2uart.c index de5a328..88c19cd 100644 --- a/tool/p8bin2uart.c +++ b/tool/p8bin2uart.c | |||
| @@ -131,7 +131,7 @@ load(FILE *fp) | |||
| 131 | return v; | 131 | return v; |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | #define MAX_LINE_SIZE 63 | 134 | #define MAX_LINE_SIZE 127 |
| 135 | 135 | ||
| 136 | char buf[MAX_LINE_SIZE * 2] = {0}; | 136 | char buf[MAX_LINE_SIZE * 2] = {0}; |
| 137 | 137 | ||
