Rev 12 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 12 | Rev 15 | ||
|---|---|---|---|
| Line 5... | Line 5... | ||
| 5 | #include <stdint.h> |
5 | #include <stdint.h> |
| 6 | #include <ctype.h> |
6 | #include <ctype.h> |
| 7 | #include <unistd.h> |
7 | #include <unistd.h> |
| 8 | #include <string.h> |
8 | #include <string.h> |
| 9 | #include "PtsModule.h" |
9 | #include "PtsModule.h" |
| - | 10 | #include <getopt.h> |
|
| 10 | 11 | ||
| 11 | void Delay(double t){ |
12 | void Delay(double t){ |
| 12 | usleep(t*1e6); |
13 | usleep(t*1e6); |
| 13 | } |
14 | } |
| 14 | 15 | ||
| Line 186... | Line 187... | ||
| 186 | } |
187 | } |
| 187 | 188 | ||
| 188 | 189 | ||
| 189 | void help(char *argv){ |
190 | void help(char *argv){ |
| 190 | printf("Usage: %s -a <ptsaddr> -v <verbose> -c .... Pts_check_configure\n", argv); |
191 | printf("Usage: %s -a <ptsaddr> -v <verbose> -c .... Pts_check_configure\n", argv); |
| 191 | printf("Usage: %s -a <ptsaddr> -v <verbose> -i <filename> -b mode ... Pts_configure_bit\n", argv); |
192 | printf("Usage: %s -a <ptsaddr> -v <verbose> -i <filename> -b mode (2) ... Pts_configure_bit\n", argv); |
| 192 | printf("Usage: %s -a <ptsaddr> -v <verbose> -e .... Pts_erase\n", argv); |
193 | printf("Usage: %s -a <ptsaddr> -v <verbose> -e .... Pts_erase\n", argv); |
| 193 | printf("Usage: %s -a <ptsaddr> -v <verbose> - |
194 | printf("Usage: %s -a <ptsaddr> -v <verbose> -x .... Pts_reset\n", argv); |
| - | 195 | printf("Usage: %s -a <ptsaddr> -v <verbose> -c .... Pts_check_configure\n", argv); |
|
| - | 196 | printf("Usage: %s -a <ptsaddr> -v <verbose> -r .... vme read\n", argv); |
|
| - | 197 | printf("Usage: %s -a <ptsaddr> -v <verbose> -w <value> .... vme write\n", argv); |
|
| 194 | printf("Usage: %s -a <ptsaddr> -v <verbose> - |
198 | printf("Usage: %s -a <ptsaddr> -v <verbose> -s <value> .... Pts_write_csr\n", argv); |
| - | 199 | printf("Example: %s --address 0x1000000 --verbose 1 --erase\n", argv); |
|
| - | 200 | printf("Example: %s --address 0x1000000 --verbose 1 --input pts_scaler.bit --load-bit 2\n", argv); |
|
| - | 201 | printf("Example: %s --address 0x1000004 --write-csr 0x7600\n", argv); |
|
| 195 | } |
202 | } |
| - | 203 | ||
| 196 | 204 | ||
| - | 205 | ||
| - | 206 | static const char *optString = "v:rxea:cs:w:i:b:h"; |
|
| - | 207 | static const struct option longOpts[] = { |
|
| - | 208 | { "verbose", required_argument, NULL, 'v' }, |
|
| - | 209 | { "reset" , no_argument, NULL, 'x' }, |
|
| - | 210 | { "erase" , no_argument, NULL, 'e' }, |
|
| - | 211 | { "address", required_argument, NULL, 'a' }, |
|
| - | 212 | { "check-configure", no_argument, NULL, 'c' }, |
|
| - | 213 | { "write-csr", required_argument , NULL, 's' }, |
|
| - | 214 | { "input", required_argument , NULL, 'i' }, |
|
| - | 215 | { "load-bit", required_argument , NULL, 'b' }, |
|
| - | 216 | { "read", no_argument , NULL, 'r' }, |
|
| - | 217 | { "write",required_argument , NULL, 'w' }, |
|
| - | 218 | { "help", no_argument, NULL, 'h' }, |
|
| - | 219 | { NULL, no_argument, NULL, 0 } |
|
| - | 220 | }; |
|
| - | 221 | ||
| 197 | int main (int argc, char ** argv){ |
222 | int main (int argc, char ** argv){ |
| - | 223 | ||
| 198 |
|
224 | uint32_t value; |
| 199 | 225 | ||
| 200 | int verbose=0; |
226 | int verbose=0; |
| 201 | char filename[256]="file.bit"; |
227 | char filename[256]="file.bit"; |
| 202 | int c; |
228 | int c; |
| 203 | opterr = 0; |
229 | opterr = 0; |
| - | 230 | int longIndex = 0; |
|
| 204 | 231 | ||
| 205 | if (argc<2) { |
232 | if (argc<2) { |
| 206 | help(argv[0]); |
233 | help(argv[0]); |
| 207 | exit(-1); |
234 | exit(-1); |
| 208 | } |
235 | } |
| 209 | 236 | ||
| 210 | VME_START(NULL); |
237 | VME_START(NULL); |
| - | 238 | ||
| - | 239 | c = getopt_long( argc, argv, optString, longOpts, &longIndex ); |
|
| - | 240 | while( c != -1 ) |
|
| - | 241 | ||
| 211 |
|
242 | // while ((c = getopt (argc, argv, "v:xrea:csw:i:b:h")) != -1) |
| - | 243 | { |
|
| 212 | switch (c) |
244 | switch (c) |
| 213 | { |
245 | { |
| 214 | case 'v': |
246 | case 'v': |
| 215 | verbose = atoi(optarg); |
247 | verbose = atoi(optarg); |
| 216 | break; |
248 | break; |
| 217 | case |
249 | case 'x': |
| 218 | Pts_reset(verbose); |
250 | Pts_reset(verbose); |
| 219 | break; // reset |
251 | break; // reset |
| 220 | case 'e': |
252 | case 'e': |
| 221 | Pts_erase(verbose); |
253 | Pts_erase(verbose); |
| 222 | break; // erase |
254 | break; // erase |
| 223 | case 'a': |
255 | case 'a': |
| 224 | ptaddr = strtoul (optarg,NULL,0); |
256 | ptaddr = strtoul (optarg,NULL,0); |
| 225 | break; // address |
257 | break; // address |
| 226 | case 'c': |
258 | case 'c': |
| 227 | Pts_check_configure( verbose ); |
259 | Pts_check_configure( verbose ); |
| 228 | break; |
260 | break; |
| 229 | case 'w': |
261 | case 'w': |
| - | 262 | value = strtoul (optarg,NULL,0); |
|
| - | 263 | Pts_write( 0 , value ); |
|
| - | 264 | break; |
|
| - | 265 | case 'r': |
|
| - | 266 | value = 0; |
|
| - | 267 | Pts_read( 0 , &value ); |
|
| - | 268 | break; |
|
| - | 269 | case 's': |
|
| 230 | value = strtoul (optarg,NULL,0); |
270 | value = strtoul (optarg,NULL,0); |
| 231 | Pts_write_csr( verbose, value ); |
271 | Pts_write_csr( verbose, value ); |
| 232 | break; |
272 | break; |
| 233 | case 'i': |
273 | case 'i': |
| 234 | sprintf(filename,"%s",optarg); |
274 | sprintf(filename,"%s",optarg); |
| Line 243... | Line 283... | ||
| 243 | help(argv[0]); |
283 | help(argv[0]); |
| 244 | break; |
284 | break; |
| 245 | default: |
285 | default: |
| 246 | printf("Unknown command %c\n",c); |
286 | printf("Unknown command %c\n",c); |
| 247 | } |
287 | } |
| - | 288 | c = getopt_long( argc, argv, optString, longOpts, &longIndex ); |
|
| - | 289 | } |
|
| 248 | VME_STOP(); |
290 | VME_STOP(); |
| 249 | } |
291 | } |
| 250 | 292 | ||