comparison loadtools/romload.c @ 683:ecea01f65146

loadtools: implemented -t option for boot ROM wait timeout
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 10 Mar 2020 07:05:32 +0000
parents 46d7ed4ee634
children
comparison
equal deleted inserted replaced
682:a7496a1e0df7 683:ecea01f65146
26 26
27 struct srecreader iramimage; 27 struct srecreader iramimage;
28 struct baudrate *romload_baud_rate = baud_rate_table; /* 1st entry default */ 28 struct baudrate *romload_baud_rate = baud_rate_table; /* 1st entry default */
29 29
30 static int beacon_interval = 13; /* in milliseconds */ 30 static int beacon_interval = 13; /* in milliseconds */
31 static int beacon_timeout; /* ditto */
31 32
32 static u_char beacon_cmd[2] = {'<', 'i'}; 33 static u_char beacon_cmd[2] = {'<', 'i'};
33 34
34 static u_char param_cmd[11] = {'<', 'p', 35 static u_char param_cmd[11] = {'<', 'p',
35 0x00, /* baud rate select code (115200) */ 36 0x00, /* baud rate select code (115200) */
79 beacon_interval = i; 80 beacon_interval = i;
80 } 81 }
81 82
82 /* 83 /*
83 * The following function should be called by command line option 84 * The following function should be called by command line option
85 * parsers upon encountering the -t option.
86 */
87 set_romload_timeout(arg)
88 char *arg;
89 {
90 beacon_timeout = atoi(arg);
91 }
92
93 /*
94 * The following function should be called by command line option
84 * parsers upon encountering the -b option. 95 * parsers upon encountering the -b option.
85 */ 96 */
86 set_romload_baudrate(arg) 97 set_romload_baudrate(arg)
87 char *arg; 98 char *arg;
88 { 99 {
149 } 160 }
150 161
151 static 162 static
152 send_beacons() 163 send_beacons()
153 { 164 {
165 int time_accum;
166
154 printf("Sending beacons to %s\n", target_ttydev); 167 printf("Sending beacons to %s\n", target_ttydev);
155 do 168 for (time_accum = 0; ; ) {
156 write(target_fd, beacon_cmd, sizeof beacon_cmd); 169 write(target_fd, beacon_cmd, sizeof beacon_cmd);
157 while (expect_response(beacon_interval) != 'i'); 170 if (expect_response(beacon_interval) == 'i')
158 return 0; 171 return 0;
172 time_accum += beacon_interval;
173 if (beacon_timeout && time_accum >= beacon_timeout) {
174 fprintf(stderr,
175 "Timeout waiting for boot ROM response\n");
176 exit(1);
177 }
178 }
159 } 179 }
160 180
161 static int 181 static int
162 expect_add_response(buf, expect_bytes, timeout) 182 expect_add_response(buf, expect_bytes, timeout)
163 u_char *buf; 183 u_char *buf;