/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to cli.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-03-09 15:55:27 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: csa@dside.dyndns.org-20110309155527-7ui77xsz2f7ms0b8
Support for FPGA registers

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#define BLOCK_SIZE 8
37
37
#define BENCHMARK_ITERATIONS 128
38
38
 
 
39
#define isnumber pcilib_isnumber
 
40
#define isxnumber pcilib_isxnumber
39
41
 
40
42
 
41
43
typedef uint8_t access_t;
471
473
            case 4: res = sscanf(data[i], "%x", ((uint32_t*)buf)+i); break;
472
474
            case 8: res = sscanf(data[i], "%lx", ((uint64_t*)buf)+i); break;
473
475
        }
474
 
        
475
 
        if (res != 1) Error("Can't parse data value at poition %i, (%s) is not valid hex number", i, data[i]);
 
476
        if ((res != 1)||(!isxnumber(data[i]))) Error("Can't parse data value at poition %i, (%s) is not valid hex number", i, data[i]);
476
477
    }
477
478
 
478
479
    if (endianess) pcilib_swap(buf, buf, abs(access), n);
502
503
 
503
504
    for (i = 0; i < n; i++) {
504
505
        res = sscanf(data[i], "%lx", &value);
505
 
        if (res != 1) Error("Can't parse data value at poition %i, (%s) is not valid hex number", i, data[i]);
 
506
        if ((res != 1)||(!isxnumber(data[i]))) Error("Can't parse data value at poition %i, (%s) is not valid hex number", i, data[i]);
506
507
        buf[i] = value;
507
508
    }
508
509
 
530
531
    unsigned long val;
531
532
    pcilib_register_value_t value;
532
533
    
533
 
    if (sscanf(*data, "%li", &val) != 1) {
 
534
    if ((!isnumber(*data))||(sscanf(*data, "%li", &val) != 1)) {
534
535
        Error("Can't parse data value (%s) is not valid decimal number", data[i]);
535
536
    }
536
537
 
621
622
//              else bar = itmp;
622
623
            break;
623
624
            case OPT_ACCESS:
624
 
                if (sscanf(optarg, "%li", &itmp) != 1) access = 0;
 
625
                if ((!isnumber(optarg))||(sscanf(optarg, "%li", &itmp) != 1)) access = 0;
625
626
                switch (itmp) {
626
627
                    case 8: access = 1; break;
627
628
                    case 16: access = 2; break;
631
632
                }       
632
633
            break;
633
634
            case OPT_SIZE:
634
 
                if (sscanf(optarg, "%zu", &size) != 1)
 
635
                if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &size) != 1))
635
636
                    Usage(argc, argv, "Invalid size is specified (%s)", optarg);
636
637
            break;
637
638
            case OPT_ENDIANESS:
678
679
    }
679
680
 
680
681
    if (addr) {
681
 
        if (sscanf(addr, "%lx", &start) == 1) {
 
682
        if ((isxnumber(addr))&&(sscanf(addr, "%lx", &start) == 1)) {
682
683
                // check if the address in the register range
683
684
            pcilib_register_range_t *ranges =  pcilib_model[model].ranges;
684
685
 
702
703
            case MODE_BENCHMARK:
703
704
            case MODE_READ:
704
705
            case MODE_WRITE:
705
 
                if ((sscanf(bank,"%li", &itmp) != 1)||(itmp < 0)||(itmp >= PCILIB_MAX_BANKS)) 
 
706
                if ((!isnumber(bank))||(sscanf(bank,"%li", &itmp) != 1)||(itmp < 0)||(itmp >= PCILIB_MAX_BANKS)) 
706
707
                    Usage(argc, argv, "Invalid data bank (%s) is specified", bank);
707
708
                else bar = itmp;
708
709
            break;