summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorJulian Blake Kongslie2022-05-08 15:51:35 -0700
committerJulian Blake Kongslie2022-05-08 15:51:35 -0700
commit38c5ae5b60eae9562b97da42f47af3861847f8e5 (patch)
tree556fd9e5c38fb2feea56ce5741ca02a5e110ad63 /tool
parentMake the script for setting up the TTY actually connect. (diff)
downloadmultipdp8-38c5ae5b60eae9562b97da42f47af3861847f8e5.tar.xz
*Proper* serial port for memory downloads. 115200 8O2 RS232 with CRTRTS.
Diffstat (limited to '')
-rw-r--r--tool/con.c106
-rwxr-xr-xtool/connect13
-rwxr-xr-xtool/download.tcl (renamed from download.tcl)9
-rw-r--r--tool/p8bin2uart.c2
4 files changed, 119 insertions, 11 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
11struct termios save;
12
13void
14host(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
38void
39hup(int signo)
40{
41 write(1, "HUP\n", 4);
42 tcsetattr(0, TCSADRAIN, &save);
43 _exit(0);
44}
45
46void
47user(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
65int
66main(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
3set -eux 3set -eu
4 4
5OLD_SETTINGS="$(stty -F /dev/ttyUSB0 -g)" 5OLD_SETTINGS="$(stty -g -F /dev/ttyUSB0)"
6 6
7stty -F /dev/ttyUSB0 \ 7stty -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
27con /dev/ttyUSB0 || true 30con /dev/ttyUSB0 || true
28 31
29stty -F "$OLD_SETTINGS" 32stty -drain "$OLD_SETTINGS" -F /dev/ttyUSB0 2> /dev/null
diff --git a/download.tcl b/tool/download.tcl
index 635e54b..c0dca55 100755
--- a/download.tcl
+++ b/tool/download.tcl
@@ -12,14 +12,13 @@ if {$::argc > 1} {
12 set core [lindex $::argv 0] 12 set core [lindex $::argv 0]
13} 13}
14 14
15spawn nios2-terminal --instance 0 15spawn tool/connect
16expect -ex "connected to hardware target"
17 16
18send "@[format %x [expr $core * 32768 / $wordsperline]]\n" 17send "@[format %x [expr $core * 32768 / $wordsperline]]\n"
19 18
20while {[gets stdin line] >= 0} { 19while {[gets stdin line] >= 0} {
21 send "$line\n" 20 send "$line\n"
22 expect -ex "$line" 21 expect -ex "$line\n"
23} 22}
24 23
25# It's likely we ended with a very large zero-memory operation. We want to see 24# It's likely we ended with a very large zero-memory operation. We want to see
@@ -30,5 +29,5 @@ expect -ex "?"
30send "?" 29send "?"
31expect -ex "?" 30expect -ex "?"
32 31
33send "\004" 32send "\n~."
34expect -ex "exiting due to ^D on remote" 33wait
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
136char buf[MAX_LINE_SIZE * 2] = {0}; 136char buf[MAX_LINE_SIZE * 2] = {0};
137 137