diff options
Diffstat (limited to '')
| -rw-r--r-- | tool/con.c | 106 | ||||
| -rwxr-xr-x | tool/connect | 13 | ||||
| -rwxr-xr-x | tool/download.tcl (renamed from download.tcl) | 9 | ||||
| -rw-r--r-- | tool/p8bin2uart.c | 2 |
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 | |||
| 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/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 | ||
| 15 | spawn nios2-terminal --instance 0 | 15 | spawn tool/connect |
| 16 | expect -ex "connected to hardware target" | ||
| 17 | 16 | ||
| 18 | send "@[format %x [expr $core * 32768 / $wordsperline]]\n" | 17 | send "@[format %x [expr $core * 32768 / $wordsperline]]\n" |
| 19 | 18 | ||
| 20 | while {[gets stdin line] >= 0} { | 19 | while {[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 "?" | |||
| 30 | send "?" | 29 | send "?" |
| 31 | expect -ex "?" | 30 | expect -ex "?" |
| 32 | 31 | ||
| 33 | send "\004" | 32 | send "\n~." |
| 34 | expect -ex "exiting due to ^D on remote" | 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 | ||
