int main(int argc, char** argv) { int opt, error, c, i, len; struct sdb_device sdb; eb_status_t status; eb_socket_t socket; eb_device_t device; eb_cycle_t cycle; eb_data_t *data; /* Default arguments */ program = argv[0]; error = 0; /* Process the command-line arguments */ error = 0; while ((opt = getopt(argc, argv, "h")) != -1) { switch (opt) { case 'h': help(); return 0; case ':': case '?': error = 1; break; default: fprintf(stderr, "%s: bad getopt result\n", program); error = 1; } } if (error) return 1; if (optind + 1 != argc) { fprintf(stderr, "%s: expecting three non-optional arguments: <proto/host/port>\n", program); return 1; } if ((status = eb_socket_open(EB_ABI_CODE, 0, EB_DATAX|EB_ADDRX, &socket)) != EB_OK) die("eb_socket_open", status); if ((status = eb_device_open(socket, argv[optind], EB_DATAX|EB_ADDRX, 3, &device)) != EB_OK) die(argv[optind], status); c = 1; if ((status = eb_sdb_find_by_identity(device, GSI_ID, ROM_ID, &sdb, &c)) != EB_OK) die("eb_sdb_find_by_identity", status); if (c != 1) { fprintf(stderr, "Found %d ROM identifiers on that device\n", c); exit(1); } if ((status = eb_cycle_open(device, 0, 0, &cycle)) != EB_OK) die("eb_cycle_open", status); len = ((sdb.sdb_component.addr_last - sdb.sdb_component.addr_first) + 1) / 4; if ((data = malloc(len * sizeof(eb_data_t))) == 0) die("malloc", EB_OOM); for (i = 0; i < len; ++i) eb_cycle_read(cycle, sdb.sdb_component.addr_first + i*4, EB_DATA32|EB_BIG_ENDIAN, &data[i]); if ((status = eb_cycle_close(cycle)) != EB_OK) die("eb_cycle_close", status); for (i = 0; i < len; ++i) { printf("%c%c%c%c", (char)(data[i] >> 24) & 0xff, (char)(data[i] >> 16) & 0xff, (char)(data[i] >> 8) & 0xff, (char)(data[i] ) & 0xff); } return 0; }
int main(int argc, char** argv) { int opt, error, c, i, flags, busy; char *tail; struct sdb_device sdb[10]; struct termios tc, old; eb_status_t status; eb_socket_t socket; eb_device_t device; eb_address_t tx, rx; eb_data_t rx_data[BATCH_SIZE], tx_data, done; eb_cycle_t cycle; char byte; /* Default arguments */ program = argv[0]; error = 0; i = -1; /* Process the command-line arguments */ error = 0; while ((opt = getopt(argc, argv, "i:h")) != -1) { switch (opt) { case 'h': help(); return 0; case 'i': i = strtol(optarg, &tail, 0); if (*tail != 0) { fprintf(stderr, "%s: specify a proper number, not '%s'!\n", program, optarg); error = 1; } break; case ':': case '?': error = 1; break; default: fprintf(stderr, "%s: bad getopt result\n", program); error = 1; } } if (error) return 1; if (optind + 1 != argc) { fprintf(stderr, "%s: expecting non-optional argument: <proto/host/port>\n", program); return 1; } if ((status = eb_socket_open(EB_ABI_CODE, 0, EB_DATAX|EB_ADDRX, &socket)) != EB_OK) die("eb_socket_open", status); if ((status = eb_device_open(socket, argv[optind], EB_DATAX|EB_ADDRX, 3, &device)) != EB_OK) die(argv[optind], status); c = sizeof(sdb)/sizeof(struct sdb_device); if ((status = eb_sdb_find_by_identity(device, CERN_ID, UART_ID, &sdb[0], &c)) != EB_OK) die("eb_sdb_find_by_identity", status); if (i == -1) { if (c != 1) { fprintf(stderr, "%s: found %d UARTs on that device; pick one with -i #\n", program, c); exit(1); } else { i = 0; } } if (i >= c) { fprintf(stderr, "%s: could not find UART #%d on that device (%d total)\n", program, i, c); exit(1); } printf("Connected to uart at address %"PRIx64"\n", sdb[i].sdb_component.addr_first); tx = sdb[i].sdb_component.addr_first + VUART_TX; rx = sdb[i].sdb_component.addr_first + VUART_RX; /* disable input buffering and echo */ tcgetattr(STDIN_FD, &old); tcgetattr(STDIN_FD, &tc); tc.c_cflag = B9600 | CS8 | CLOCAL | CREAD; tc.c_iflag = IGNPAR; tc.c_oflag = 0; tc.c_lflag = 0; tc.c_cc[VMIN]=1; tc.c_cc[VTIME]=0; tcflush(STDIN_FD, TCIFLUSH); tcsetattr(STDIN_FD, TCSANOW, &tc); flags = fcntl(STDIN_FD, F_GETFL, 0); flags |= O_NONBLOCK; fcntl(STDIN_FD, F_SETFL, flags); /* be lazy and just poll for now */ busy = 0; while (1) { if (!busy) usleep(10000); /* 10ms */ /* Poll for status */ eb_cycle_open(device, 0, eb_block, &cycle); eb_cycle_read(cycle, rx, EB_BIG_ENDIAN|EB_DATA32, &rx_data[0]); eb_cycle_read(cycle, tx, EB_BIG_ENDIAN|EB_DATA32, &done); eb_cycle_close(cycle); /* Bulk read anything extra */ if ((rx_data[0] & 0x100) != 0) { eb_cycle_open(device, 0, eb_block, &cycle); for (i = 1; i < BATCH_SIZE; ++i) eb_cycle_read(cycle, rx, EB_BIG_ENDIAN|EB_DATA32, &rx_data[i]); eb_cycle_close(cycle); for (i = 0; i < BATCH_SIZE; ++i) { if ((rx_data[i] & 0x100) == 0) continue; byte = rx_data[i] & 0xFF; fputc(byte, stdout); } fflush(stdout); } busy = busy && (done & 0x100) == 0; if (!busy && read(STDIN_FD, &byte, 1) == 1) { if (byte == 3) { /* control-C */ tcsetattr(STDIN_FD, TCSANOW, &old); exit(0); } tx_data = byte; eb_device_write(device, tx, EB_BIG_ENDIAN|EB_DATA32, tx_data, eb_block, 0); busy = 1; } } return 0; }
/* ==================================================================================================== */ int main(int argc, char** argv) { /* Helpers */ int opt = 0; int dev_count = 0; bool setup_io = false; bool verbose = false; bool show_help = false; bool turn_off = false; /* Etherbone */ static eb_device_t device; eb_socket_t socket; eb_status_t status; struct sdb_device devices[WB_IO_CONTROL_MAX_DEVICES]; uint32_t wb_addr_base; /* Get the application name */ program = argv[0]; /* Parse for options */ while ((opt = getopt(argc, argv, ":svho")) != -1) { switch (opt) { case 's': { setup_io = true; break; } case 'v': { verbose = true; break; } case 'h': { show_help = true; break; } case 'o': { turn_off = true; break; } default: { printf("Unknown argument...\n"); show_help = true; break; } } } /* Get basic arguments, we need at least the device name */ if (optind + 1 == argc) { devName = argv[optind]; } else { show_help = true; printf("Incorrect non-optional arguments...\n"); } /* Show help? */ if (show_help) { vShowHelp(); return -1; } /* Open socket and device */ if ((status = eb_socket_open(EB_ABI_CODE, 0, EB_DATAX|EB_ADDRX, &socket)) != EB_OK) { vHandleEBError("eb_socket_open", status); } if ((status = eb_device_open(socket, devName, EB_DATAX|EB_ADDRX, 3, &device)) != EB_OK) { vHandleEBError(devName, status); } /* Try to find the IO CONTROL module */ dev_count = WB_IO_CONTROL_MAX_DEVICES; if ((status = eb_sdb_find_by_identity(device, WB_IO_CONTROL_VENDOR_ID, WB_IO_CONTROL_PRODUCT_ID, &devices[0], &dev_count)) != EB_OK) { vHandleEBError("eb_sdb_find_by_identity", status); } /* Did we find at least one? */ if (dev_count != WB_IO_CONTROL_MAX_DEVICES) { printf("IO CONTROL unit missing!\n"); return -1; } else { wb_addr_base = (eb_address_t)(devices[0].sdb_component.addr_first); if (verbose) { printf("Found IO CONTROL unit at 0x%08x (%d)\n", wb_addr_base, dev_count); } } /* Configure unit */ if (!turn_off) { printf("Enabling PPS...\n"); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_PPS_Mux_Set_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_PPS_Mux_Set_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_PPS_Mux_Set_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_PPS_Mux_Set_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); if (setup_io) { printf("Enabling output...\n"); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_Oe_Set_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_Oe_Set_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_Oe_Set_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_Oe_Set_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_Term_Reset_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_Term_Reset_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_Term_Reset_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_Term_Reset_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); } } else { printf("Disabling PPS...\n"); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_PPS_Mux_Reset_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_PPS_Mux_Reset_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_PPS_Mux_Reset_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_PPS_Mux_Reset_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); if (setup_io) { printf("Disabling output...\n"); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_Oe_Reset_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_Oe_Reset_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_Oe_Reset_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_Oe_Reset_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_Term_Set_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_GPIO_Term_Set_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_Term_Set_low, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); eb_device_write(device, wb_addr_base + WB_IO_CONTROL_LVDS_Term_Set_high, EB_DATA32, WB_IO_CONTROL_MASK_ALL, 0, NULL); } } /* Done */ return 0; }