FreeCalypso > hg > freecalypso-sw
comparison loadtools/sercomm.c @ 49:54392d1ea474
loadtools: first beginnings for the baud rate switching logic
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Jun 2013 02:53:16 +0000 |
parents | fea204bc7674 |
children | f1df95eed62c |
comparison
equal
deleted
inserted
replaced
48:38664e0b7c32 | 49:54392d1ea474 |
---|---|
8 #include <sys/ioctl.h> | 8 #include <sys/ioctl.h> |
9 #include <termios.h> | 9 #include <termios.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <unistd.h> | 12 #include <unistd.h> |
13 #include "baudrate.h" | |
13 | 14 |
14 char *target_ttydev; | 15 char *target_ttydev; |
15 int target_fd; | 16 int target_fd; |
16 struct termios target_termios; | 17 struct termios target_termios; |
18 | |
19 struct baudrate baud_rate_table[] = { | |
20 /* the first listed rate will be our default */ | |
21 {"115200", B115200, 0}, | |
22 {"57600", B57600, 1}, | |
23 {"38400", B38400, 2}, | |
24 {"19200", B19200, 4}, | |
25 /* non-standard high baud rates "remapped" by CP2102 usb2serial IC */ | |
26 {"812500", B921600, -1}, | |
27 {"406250", B460800, -1}, | |
28 {"203125", B230400, -1}, | |
29 /* table search terminator */ | |
30 {NULL, B0, -1}, | |
31 }; | |
32 struct baudrate *current_baud_rate; | |
17 | 33 |
18 open_target_serial() | 34 open_target_serial() |
19 { | 35 { |
20 target_fd = open(target_ttydev, O_RDWR|O_NONBLOCK); | 36 target_fd = open(target_ttydev, O_RDWR|O_NONBLOCK); |
21 if (target_fd < 0) { | 37 if (target_fd < 0) { |
36 exit(1); | 52 exit(1); |
37 } | 53 } |
38 return 0; | 54 return 0; |
39 } | 55 } |
40 | 56 |
41 switch_baud_rate(code) | 57 switch_baud_rate(br) |
58 struct baudrate *br; | |
42 { | 59 { |
43 cfsetispeed(&target_termios, code); | 60 cfsetispeed(&target_termios, br->termios_code); |
44 cfsetospeed(&target_termios, code); | 61 cfsetospeed(&target_termios, br->termios_code); |
45 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { | 62 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { |
46 perror("tcsetattr to switch baud rate"); | 63 perror("tcsetattr to switch baud rate"); |
47 exit(1); | 64 exit(1); |
48 } | 65 } |
66 current_baud_rate = br; | |
49 } | 67 } |