FreeCalypso > hg > freecalypso-reveng
comparison frbl/test/main.c @ 323:cefa700d1b8f
frbl: beginning of frbl2test
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 05 Mar 2020 22:05:01 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
322:6e442ed0f64d | 323:cefa700d1b8f |
---|---|
1 #include <sys/types.h> | |
2 #include <sys/file.h> | |
3 #include <sys/ioctl.h> | |
4 #include <stdint.h> | |
5 #include <stdio.h> | |
6 #include <stdlib.h> | |
7 #include <string.h> | |
8 #include <strings.h> | |
9 #include <termios.h> | |
10 #include <unistd.h> | |
11 #include "srecreader.h" | |
12 | |
13 char *target_ttydev; | |
14 int target_fd; | |
15 int baudrate_code; | |
16 struct termios target_termios; | |
17 struct srecreader srimage; | |
18 | |
19 main(argc, argv) | |
20 char **argv; | |
21 { | |
22 if (argc != 4) { | |
23 fprintf(stderr, "usage: %s ttyport baud image.srec\n", argv[0]); | |
24 exit(1); | |
25 } | |
26 target_ttydev = argv[1]; | |
27 if (!strcmp(argv[2], "115200")) | |
28 baudrate_code = B115200; | |
29 else if (!strcmp(argv[2], "230400")) | |
30 baudrate_code = B230400; | |
31 else { | |
32 fprintf(stderr, | |
33 "error: baud rate argument must be 115200 or 230400\n"); | |
34 exit(1); | |
35 } | |
36 srimage.filename = argv[3]; | |
37 | |
38 target_fd = open(target_ttydev, O_RDWR|O_NONBLOCK); | |
39 if (target_fd < 0) { | |
40 perror(target_ttydev); | |
41 exit(1); | |
42 } | |
43 ioctl(target_fd, TIOCEXCL); | |
44 target_termios.c_iflag = IGNBRK; | |
45 target_termios.c_oflag = 0; | |
46 target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8; | |
47 target_termios.c_lflag = 0; | |
48 target_termios.c_cc[VMIN] = 1; | |
49 target_termios.c_cc[VTIME] = 0; | |
50 cfsetispeed(&target_termios, baudrate_code); | |
51 cfsetospeed(&target_termios, baudrate_code); | |
52 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { | |
53 perror("tcsetattr"); | |
54 exit(1); | |
55 } | |
56 frbl_test_main(); | |
57 tty_passthru(); | |
58 exit(0); | |
59 } |