1 | // $URL: http://subversion:8080/svn/gsc/trunk/drivers/LINUX/18AI32SSC1M/savedata/main.c $ |
---|
2 | // $Rev: 36231 $ |
---|
3 | // $Date: 2016-09-01 21:02:10 -0500 (Thu, 01 Sep 2016) $ |
---|
4 | |
---|
5 | #include <ctype.h> |
---|
6 | #include <stdio.h> |
---|
7 | #include <stdlib.h> |
---|
8 | #include <string.h> |
---|
9 | #include <time.h> |
---|
10 | |
---|
11 | #include "main.h" |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | // variables ******************************************************************* |
---|
16 | |
---|
17 | static int _continuous = 0; |
---|
18 | static int _def_index = 0; |
---|
19 | static int _ignore_errors = 0; |
---|
20 | static s32 _io_mode = GSC_IO_MODE_PIO; |
---|
21 | static long _minute_limit = 0; |
---|
22 | static int _test_limit = -1; |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | //***************************************************************************** |
---|
27 | static int _parse_args(int argc, char** argv) |
---|
28 | { |
---|
29 | char buf[64]; |
---|
30 | char c; |
---|
31 | int errs = 0; |
---|
32 | int i; |
---|
33 | int j; |
---|
34 | int k; |
---|
35 | |
---|
36 | printf("savedata - Capture and Save Data to Disk\n"); |
---|
37 | printf("USAGE: savedata <-c> <-C> <-dma> <-dmdma> <-m#> <-n#> <-pio> <index>\n"); |
---|
38 | printf(" -c Continue testing until an error occurs.\n"); |
---|
39 | printf(" -C Continue testing even if errors occur.\n"); |
---|
40 | printf(" -dma Use standard DMA for data transfer.\n"); |
---|
41 | printf(" -dmdma Use Demand Mode DMA for data transfer.\n"); |
---|
42 | printf(" -m# Run for at most # minutes (a decimal number).\n"); |
---|
43 | printf(" -n# Repeat test at most # times (a decimal number).\n"); |
---|
44 | printf(" -pio Use PIO for data transfer. This is the default.\n"); |
---|
45 | printf(" index The zero based index of the device to access.\n"); |
---|
46 | |
---|
47 | gsc_label("Arguments"); |
---|
48 | printf("(%d argument%s)\n", argc - 1, ((argc - 1) > 1) ? "s" : ""); |
---|
49 | gsc_label_level_inc(); |
---|
50 | |
---|
51 | for (i = 0; i < argc; i++) |
---|
52 | { |
---|
53 | sprintf(buf, "Argument %d", i); |
---|
54 | gsc_label(buf); |
---|
55 | printf("%s\n", argv[i]); |
---|
56 | } |
---|
57 | |
---|
58 | gsc_label_level_dec(); |
---|
59 | |
---|
60 | for (i = 1; i < argc; i++) |
---|
61 | { |
---|
62 | if (strcmp(argv[i], "-c") == 0) |
---|
63 | { |
---|
64 | _continuous = 1; |
---|
65 | _ignore_errors = 0; |
---|
66 | continue; |
---|
67 | } |
---|
68 | |
---|
69 | if (strcmp(argv[i], "-C") == 0) |
---|
70 | { |
---|
71 | _continuous = 1; |
---|
72 | _ignore_errors = 1; |
---|
73 | continue; |
---|
74 | } |
---|
75 | |
---|
76 | if (strcmp(argv[i], "-dma") == 0) |
---|
77 | { |
---|
78 | _io_mode = GSC_IO_MODE_DMA; |
---|
79 | continue; |
---|
80 | } |
---|
81 | |
---|
82 | if (strcmp(argv[i], "-dmdma") == 0) |
---|
83 | { |
---|
84 | _io_mode = GSC_IO_MODE_DMDMA; |
---|
85 | continue; |
---|
86 | } |
---|
87 | |
---|
88 | if (strcmp(argv[i], "-pio") == 0) |
---|
89 | { |
---|
90 | _io_mode = GSC_IO_MODE_PIO; |
---|
91 | continue; |
---|
92 | } |
---|
93 | |
---|
94 | if ((argv[i][0] == '-') && (argv[i][1] == 'm') && (argv[i][2])) |
---|
95 | { |
---|
96 | j = sscanf(&argv[i][2], "%d%c", &k, &c); |
---|
97 | |
---|
98 | if ((j == 1) && (k > 0)) |
---|
99 | { |
---|
100 | _minute_limit = k; |
---|
101 | continue; |
---|
102 | } |
---|
103 | |
---|
104 | errs = 1; |
---|
105 | printf("ERROR: invalid argument: %s\n", argv[i]); |
---|
106 | break; |
---|
107 | } |
---|
108 | |
---|
109 | if ((argv[i][0] == '-') && (argv[i][1] == 'n') && (argv[i][2])) |
---|
110 | { |
---|
111 | j = sscanf(&argv[i][2], "%d%c", &k, &c); |
---|
112 | |
---|
113 | if ((j == 1) && (k > 0)) |
---|
114 | { |
---|
115 | _test_limit = k; |
---|
116 | continue; |
---|
117 | } |
---|
118 | |
---|
119 | errs = 1; |
---|
120 | printf("ERROR: invalid argument: %s\n", argv[i]); |
---|
121 | break; |
---|
122 | } |
---|
123 | |
---|
124 | j = sscanf(argv[i], "%d%c", &k, &c); |
---|
125 | |
---|
126 | if ((j == 1) && (k >= 0)) |
---|
127 | { |
---|
128 | _def_index = k; |
---|
129 | continue; |
---|
130 | } |
---|
131 | |
---|
132 | errs = 1; |
---|
133 | printf("ERROR: invalid argument: %s\n", argv[i]); |
---|
134 | break; |
---|
135 | } |
---|
136 | |
---|
137 | return(errs); |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | /****************************************************************************** |
---|
143 | * |
---|
144 | * Function: _perform_tests |
---|
145 | * |
---|
146 | * Purpose: |
---|
147 | * |
---|
148 | * Perform the appropriate testing. |
---|
149 | * |
---|
150 | * Arguments: |
---|
151 | * |
---|
152 | * fd The handle for the board to access. |
---|
153 | * |
---|
154 | * Returned: |
---|
155 | * |
---|
156 | * >= 0 The number of errors encounterred. |
---|
157 | * |
---|
158 | ******************************************************************************/ |
---|
159 | |
---|
160 | static int _perform_tests(int fd) |
---|
161 | { |
---|
162 | int errs = 0; |
---|
163 | const char* psz; |
---|
164 | struct tm* stm; |
---|
165 | time_t tt; |
---|
166 | |
---|
167 | time(&tt); |
---|
168 | stm = localtime(&tt); |
---|
169 | psz = asctime(stm); |
---|
170 | gsc_label("Performing Operation"); |
---|
171 | printf("%s", psz); |
---|
172 | |
---|
173 | errs += os_id_driver(AI32SSC1M_BASE_NAME); |
---|
174 | errs += ai32ssc1m_id_board(fd, -1, NULL); |
---|
175 | errs += save_data(fd, _io_mode); |
---|
176 | |
---|
177 | return(errs); |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | /****************************************************************************** |
---|
183 | * |
---|
184 | * Function: main |
---|
185 | * |
---|
186 | * Purpose: |
---|
187 | * |
---|
188 | * Control the overall flow of the application. |
---|
189 | * |
---|
190 | * Arguments: |
---|
191 | * |
---|
192 | * argc The number of command line arguments. |
---|
193 | * |
---|
194 | * argv The list of command line arguments. |
---|
195 | * |
---|
196 | * Returned: |
---|
197 | * |
---|
198 | * EXIT_SUCCESS We tested a device. |
---|
199 | * EXIT_FAILURE We didn't test a device. |
---|
200 | * |
---|
201 | ******************************************************************************/ |
---|
202 | |
---|
203 | int main(int argc, char *argv[]) |
---|
204 | { |
---|
205 | int errs; |
---|
206 | time_t exec = time(NULL); |
---|
207 | long failures = 0; |
---|
208 | int fd = 0; |
---|
209 | long hours; |
---|
210 | long mins; |
---|
211 | time_t now; |
---|
212 | long passes = 0; |
---|
213 | int qty; |
---|
214 | int ret = EXIT_FAILURE; |
---|
215 | long secs; |
---|
216 | time_t t_limit; |
---|
217 | time_t test; |
---|
218 | long tests = 0; |
---|
219 | |
---|
220 | for (;;) |
---|
221 | { |
---|
222 | gsc_label_init(28); |
---|
223 | test = time(NULL); |
---|
224 | errs = _parse_args(argc, argv); |
---|
225 | |
---|
226 | if (errs) |
---|
227 | break; |
---|
228 | |
---|
229 | os_id_host(); |
---|
230 | t_limit = exec + (_minute_limit * 60); |
---|
231 | qty = ai32ssc1m_count_boards(); |
---|
232 | |
---|
233 | if (qty <= 0) |
---|
234 | break; |
---|
235 | |
---|
236 | gsc_label("Accessing Board Index"); |
---|
237 | printf("%d\n", _def_index); |
---|
238 | fd = gsc_dev_open(_def_index, AI32SSC1M_BASE_NAME, 0); |
---|
239 | |
---|
240 | if (fd == -1) |
---|
241 | { |
---|
242 | errs = 1; |
---|
243 | printf( "ERROR: Unable to access device %d.", _def_index); |
---|
244 | } |
---|
245 | |
---|
246 | if (errs == 0) |
---|
247 | { |
---|
248 | ret = EXIT_SUCCESS; |
---|
249 | errs = _perform_tests(fd); |
---|
250 | } |
---|
251 | |
---|
252 | gsc_dev_close(_def_index, fd); |
---|
253 | |
---|
254 | now = time(NULL); |
---|
255 | tests++; |
---|
256 | |
---|
257 | if (errs) |
---|
258 | { |
---|
259 | failures++; |
---|
260 | printf( "\nRESULTS: FAIL <--- (%d error%s)", |
---|
261 | errs, |
---|
262 | (errs == 1) ? "" : "s"); |
---|
263 | } |
---|
264 | else |
---|
265 | { |
---|
266 | passes++; |
---|
267 | printf("\nRESULTS: PASS"); |
---|
268 | } |
---|
269 | |
---|
270 | secs = now - test; |
---|
271 | hours = secs / 3600; |
---|
272 | secs = secs % 3600; |
---|
273 | mins = secs / 60; |
---|
274 | secs = secs % 60; |
---|
275 | printf(" (duration %ld:%ld:%02ld)\n", hours, mins, secs); |
---|
276 | |
---|
277 | secs = now - exec; |
---|
278 | hours = secs / 3600; |
---|
279 | secs = secs % 3600; |
---|
280 | mins = secs / 60; |
---|
281 | secs = secs % 60; |
---|
282 | printf( "SUMMARY: tests %ld, pass %ld, fail %ld" |
---|
283 | " (duration %ld:%ld:%02ld)\n\n", |
---|
284 | tests, |
---|
285 | passes, |
---|
286 | failures, |
---|
287 | hours, |
---|
288 | mins, |
---|
289 | secs); |
---|
290 | |
---|
291 | if ((_test_limit > 0) && (_test_limit <= tests)) |
---|
292 | break; |
---|
293 | |
---|
294 | if (_continuous == 0) |
---|
295 | break; |
---|
296 | |
---|
297 | if ((_ignore_errors == 0) && (errs)) |
---|
298 | break; |
---|
299 | |
---|
300 | if ((_minute_limit) && (now >= t_limit)) |
---|
301 | break; |
---|
302 | } |
---|
303 | |
---|
304 | return(ret); |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | |
---|