/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 pcitool/cli.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-09-24 02:28:45 UTC
  • mfrom: (305.1.19 views)
  • Revision ID: csa@suren.me-20150924022845-p7hc8lh8v0q48g0r
Finalyze XML support and provide initial support for views (only descriptions so far)

Show diffs side-by-side

added added

removed removed

Lines of Context:
192
192
    {"output",                  required_argument, 0, OPT_OUTPUT },
193
193
    {"timeout",                 required_argument, 0, OPT_TIMEOUT },
194
194
    {"iterations",              required_argument, 0, OPT_ITERATIONS },
195
 
    {"info",                    no_argument, 0, OPT_INFO },
 
195
    {"info",                    optional_argument, 0, OPT_INFO },
196
196
    {"list",                    no_argument, 0, OPT_LIST },
197
197
    {"reset",                   no_argument, 0, OPT_RESET },
198
198
    {"benchmark",               optional_argument, 0, OPT_BENCHMARK },
257
257
"Usage:\n"
258
258
" %s <mode> [options] [hex data]\n"
259
259
"  Modes:\n"
260
 
"   -i                          - Device Info\n"
 
260
"   -i [target]                 - Device or Register (target) Info\n"
261
261
"   -l[l]                       - List (detailed) Data Banks & Registers\n"
262
262
"   -r <addr|reg|dmaX>          - Read Data/Register\n"
263
263
"   -w <addr|reg|dmaX>          - Write Data/Register\n"
572
572
    }
573
573
}
574
574
 
575
 
void Info(pcilib_t *handle, const pcilib_model_description_t *model_info) {
 
575
void RegisterInfo(pcilib_t *handle, pcilib_register_t reg) {
 
576
    int err;
 
577
    pcilib_register_value_t val;
 
578
 
 
579
    const pcilib_model_description_t *model_info = pcilib_get_model_description(handle);
 
580
    const pcilib_register_description_t *r = &model_info->registers[reg];
 
581
    pcilib_register_bank_t bank = pcilib_find_register_bank_by_addr(handle, r->bank);
 
582
    const pcilib_register_bank_description_t *b = &model_info->banks[bank];
 
583
 
 
584
    err = pcilib_read_register_by_id(handle, reg, &val);
 
585
    
 
586
 
 
587
    printf("%s/%s\n", b->name, r->name);
 
588
    printf("  Current value: ");
 
589
    if (err) printf("error %i", err);
 
590
    else printf(b->format, val);
 
591
 
 
592
    if (r->mode&PCILIB_REGISTER_W) {
 
593
        printf(" (default: ");
 
594
        printf(b->format, r->defvalue);
 
595
        printf(")");
 
596
    }
 
597
    printf("\n");
 
598
 
 
599
    printf("  Address      : 0x%x [%u:%u]\n", r->addr, r->offset, r->offset + r->bits);
 
600
    printf("  Access       : ");
 
601
    if ((r->mode&PCILIB_REGISTER_RW) == 0) printf("-");
 
602
    if (r->mode&PCILIB_REGISTER_R) printf("R");
 
603
    if (r->mode&PCILIB_REGISTER_W) printf("W");
 
604
    if (r->mode&PCILIB_REGISTER_W1C) printf("/reset");
 
605
    if (r->mode&PCILIB_REGISTER_W1I) printf("/invert");
 
606
    printf("\n");
 
607
 
 
608
 
 
609
    if (r->description)
 
610
        printf("  Description  : %s\n", r->description);
 
611
 
 
612
    if (r->views) {
 
613
        int i;
 
614
        printf("\nSupported Views:\n");
 
615
        for (i = 0; r->views[i].name; i++) {
 
616
            pcilib_view_t view = pcilib_find_view_by_name(handle, r->views[i].view);
 
617
            if (view == PCILIB_VIEW_INVALID) continue;
 
618
 
 
619
            const pcilib_view_description_t *v = model_info->views[view];
 
620
 
 
621
            printf("  View %s (", r->views[i].name);
 
622
            switch (v->type) {
 
623
                case PCILIB_TYPE_STRING:
 
624
                    printf("char*");
 
625
                    break;
 
626
                case PCILIB_TYPE_DOUBLE:
 
627
                    printf("double");
 
628
                    break;
 
629
                default:
 
630
                    printf("unknown");
 
631
            }
 
632
            printf(")\n");
 
633
 
 
634
            if (v->unit) {
 
635
                pcilib_unit_t unit = pcilib_find_unit_by_name(handle, v->unit);
 
636
 
 
637
                printf("    Supported units: %s", v->unit);
 
638
 
 
639
                if (unit != PCILIB_UNIT_INVALID) {
 
640
                    int j;
 
641
                    const pcilib_unit_description_t *u = &model_info->units[unit];
 
642
 
 
643
                    for (j = 0; u->transforms[j].unit; j++)
 
644
                        printf(", %s", u->transforms[j].unit);
 
645
                }
 
646
                printf("\n");
 
647
            }
 
648
 
 
649
            if (v->description)
 
650
                printf("    Description    : %s\n", v->description);
 
651
        }
 
652
    }
 
653
 
 
654
 
 
655
//    printf("Type: %s". r->rw
 
656
}
 
657
 
 
658
void Info(pcilib_t *handle, const pcilib_model_description_t *model_info, const char *target) {
576
659
    int i, j;
577
660
    DIR *dir;
578
661
    void *plugin;
595
678
    if (board_info)
596
679
        printf(" Interrupt - Pin: %i, Line: %i\n", board_info->interrupt_pin, board_info->interrupt_line);
597
680
 
 
681
    printf("\n");
 
682
 
 
683
    if (target) {
 
684
        pcilib_register_t reg;
 
685
        
 
686
        reg = pcilib_find_register(handle, NULL, target);
 
687
        if (reg != PCILIB_REGISTER_INVALID) 
 
688
            return RegisterInfo(handle, reg);
 
689
        
 
690
        Error(" No register %s is found", target);
 
691
    }
 
692
 
598
693
    List(handle, model_info, (char*)-1, 0);
599
694
 
600
 
    printf("\n");
601
695
    printf("Available models:\n");
602
696
 
603
697
    dir = opendir(path);
2656
2750
    const char *dma_channel = NULL;
2657
2751
    const char *use = NULL;
2658
2752
    const char *lock = NULL;
 
2753
    const char *info_target = NULL;
2659
2754
    size_t block = (size_t)-1;
2660
2755
    pcilib_irq_type_t irq_type = PCILIB_IRQ_TYPE_ALL;
2661
2756
    pcilib_irq_hw_source_t irq_source =  PCILIB_IRQ_SOURCE_DEFAULT;
2693
2788
            case OPT_INFO:
2694
2789
                if (mode != MODE_INVALID) Usage(argc, argv, "Multiple operations are not supported");
2695
2790
 
 
2791
                if (optarg) info_target = optarg;
 
2792
                else if ((optind < argc)&&(argv[optind][0] != '-')) info_target = argv[optind++];
 
2793
 
2696
2794
                mode = MODE_INFO;
2697
2795
            break;
2698
2796
            case OPT_LIST:
3328
3426
 
3329
3427
    switch (mode) {
3330
3428
     case MODE_INFO:
3331
 
        Info(handle, model_info);
 
3429
        Info(handle, model_info, info_target);
3332
3430
     break;
3333
3431
     case MODE_LIST:
3334
3432
        List(handle, model_info, bank, details);