예제 #1
0
int main(int argc, char *argv[]) {
    board_t *board = NULL;
    int ret = 0;
    encoder_module_t enc;

    if (argc == 1) {
        print_short_usage();
        return 0;
    }
    if (process_cmd_line(argc, argv) == -1) {
        return -1;
    }

    board_access.verbose = verbose_flag;

    if (anyio_init(&board_access) != 0) {     // init library
        return -1;
    }
    ret = anyio_find_dev(&board_access);      // find board
    if (ret < 0) {
        return -1;
    }
    board = anyio_get_dev(&board_access, 1);  // if found the get board handle
    if (board == NULL) {
        printf("No %s board found\n", board_access.device_name);
        return -1;
    }

    board->open(board);                 // open board for communication
    board->print_info(board);           // print what card it is 
    hm2_read_idrom(&(board->llio.hm2));     // read hostmot2 idrom

    ret = encoder_init(&enc, board, instance, delay);   // init encoder 'instance' module on 'board'
    if (ret < 0) {
        goto fail0;
    }

    while (1) {
        encoder_read(&enc);             // read encoder 
        printf("tsc = %u, raw_counts = %u, velocity = %.2f\n", enc.global_time_stamp, enc.raw_counts, enc.velocity);
        usleep(delay*1000);             // wait delay ms
    }

    encoder_cleanup(&enc);              // cleanup enocder module
    
fail0:
    board->close(board);                // close board communication

    anyio_cleanup(&board_access);             // close library

    return 0;
}
예제 #2
0
int main(int argc, char *argv[]) {
    int ret = 0;

    if (argc == 1) {
        print_short_usage();
        return 0;
    }
    if (process_cmd_line(argc, argv) == -1)
        return -1;

    if (info_flag == 1) {
        anyio_bitfile_print_info(bitfile_name, 1);
    } else if (device_flag == 1) {
        board_t *board = NULL;

        access.verbose = verbose_flag;
        access.recover = recover_flag;
        access.address = addr_flag;

        if (anyio_init(&access) != 0)
            exit(1);
        ret = anyio_find_dev(&access);
        if (ret < 0) {
            return -1;
        }
        board = anyio_get_dev(&access, 1);
        if (board == NULL) {
            printf("No %s board found\n", access.device_name);
            return -1;
        }

        board->open(board);

        if (readhmid_flag == 1) {
            anyio_dev_print_hm2_info(board, xml_flag);
        } else if (sserial_flag == 1) {
            anyio_dev_print_sserial_info(board);
        } else if (rpo_flag == 1) {
            u32 data;

            board->llio.read(&(board->llio), rpo_addr, &data, sizeof(u32));
            printf("%08X\n", data);
        } else if (wpo_flag == 1) {
            board->llio.write(&(board->llio), wpo_addr, &wpo_data, sizeof(u32));
        } else if (set_flag == 1) {
            ret = anyio_dev_set_remote_ip(board, lbp16_set_ip_addr);
        } else if (write_flag == 1) {
            ret = anyio_dev_write_flash(board, bitfile_name, fallback_flag);
            if (reload_flag == 1) {
                ret = anyio_dev_reload(board, fallback_flag);
                if (ret == -1) {
                    printf("\nYou must power cycle the hardware to load a new firmware.\n");
                }
            } else {
                printf("\nYou must power cycle the hardware or use the --reload command to load a new firmware.\n");
            }
        } else if (verify_flag == 1) {
            ret = anyio_dev_verify_flash(board, bitfile_name, fallback_flag);
        } else if (program_flag == 1) {
            ret = anyio_dev_program_fpga(board, bitfile_name);
        } else if (reload_flag == 1) {
            anyio_dev_reload(board, fallback_flag);
        } else if (reset_flag == 1) {
            anyio_dev_reset(board);
        } else {
           board->print_info(board);
        }
        board->close(board);
        anyio_cleanup(&access);
    } else {
        printf("No action requested. Please specify at least --device or --info.\n");
    }
    return ret;
}