FreeCalypso > hg > freecalypso-tools
annotate rvinterf/etmsync/tmsmain.c @ 497:74610c4f10f7
target-utils: added 10 ms delay at the end of abb_power_off()
The deosmification of the ABB access code (replacement of osmo_delay_ms()
bogus delays with correctly-timed ones, which are significantly shorter)
had one annoying side effect: when executing the poweroff command from
any of the programs, one last '=' prompt character was being sent (and
received by the x86 host) as the Calypso board powers off. With delays
being shorter now, the abb_power_off() function was returning and the
standalone program's main loop was printing its prompt before the Iota chip
fully executed the switch-off sequence!
I thought about inserting an endless tight loop at the end of the
abb_power_off() function, but the implemented solution of a 10 ms delay
is a little nicer IMO because if the DEVOFF operation doesn't happen for
some reason in a manual hacking scenario, there won't be an artificial
blocker in the form of a tight loop keeping us from further poking around.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 25 May 2019 20:44:05 +0000 |
parents | e40bb5a6c6b9 |
children |
rev | line source |
---|---|
269
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module contains the main() function for fc-tmsync. |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <unistd.h> |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "exitcodes.h" |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 extern char *socket_pathname; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 main(argc, argv) |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char **argv; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern int optind; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern char *optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 int c, sopt = 0; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char command[512]; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 while ((c = getopt(argc, argv, "+B:l:p:s:w:")) != EOF) |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 switch (c) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 case 'B': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 rvinterf_Bopt = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 case 'l': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 rvinterf_lopt = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 case 'p': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 rvinterf_ttyport = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 case 's': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 socket_pathname = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 sopt++; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 case 'w': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 rvinterf_wopt = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 case '?': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 default: |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 /* error msg already printed */ |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(ERROR_USAGE); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rvinterf_ttyport) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (sopt) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 fprintf(stderr, |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 "%s error: -p and -s options are mutually exclusive\n", |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 argv[0]); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(ERROR_USAGE); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
423
e40bb5a6c6b9
rvinterf clients: implemented 30 ms delay for batch ops with -p
Mychaela Falconia <falcon@freecalypso.org>
parents:
269
diff
changeset
|
51 launch_rvinterf(argv[optind] || !isatty(0)); |
269
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } else { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(stderr, |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n", |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 argv[0]); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 exit(ERROR_USAGE); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 connect_local_socket(); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 setlinebuf(stdout); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (argv[optind]) |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return dispatch_ready_argv(argc - optind, argv + optind); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 for (;;) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (isatty(0)) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 rx_control(0); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fputs("tmsync> ", stdout); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 fflush(stdout); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (!fgets(command, sizeof command, stdin)) |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 exit(0); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 parse_and_dispatch_cmd(command, 0); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |