128
157
{"read", optional_argument, 0, OPT_READ },
129
158
{"write", optional_argument, 0, OPT_WRITE },
130
159
{"grab", optional_argument, 0, OPT_GRAB },
160
{"trigger", optional_argument, 0, OPT_TRIGGER },
161
{"data", required_argument, 0, OPT_DATA_TYPE },
162
{"event", required_argument, 0, OPT_EVENT },
163
{"run-time", required_argument, 0, OPT_RUN_TIME },
164
{"trigger-rate", required_argument, 0, OPT_TRIGGER_RATE },
165
{"trigger-time", required_argument, 0, OPT_TRIGGER_TIME },
166
{"format", required_argument, 0, OPT_FORMAT },
167
{"buffer", optional_argument, 0, OPT_BUFFER },
131
168
{"start-dma", required_argument, 0, OPT_START_DMA },
132
169
{"stop-dma", optional_argument, 0, OPT_STOP_DMA },
133
170
{"list-dma-engines", no_argument, 0, OPT_LIST_DMA },
168
205
" -l[l] - List (detailed) Data Banks & Registers\n"
169
206
" -r <addr|reg|dmaX> - Read Data/Register\n"
170
207
" -w <addr|reg|dmaX> - Write Data/Register\n"
171
" -g [event] - Grab Event\n"
172
208
" --benchmark <barX|dmaX> - Performance Evaluation\n"
173
209
" --reset - Reset board\n"
174
210
" --help - Help message\n"
213
" --trigger [event] - Trigger Events\n"
214
" -g [event] - Grab Events\n"
177
217
" --start-dma <num>[r|w] - Start specified DMA engine\n"
178
218
" --stop-dma [num[r|w]] - Stop specified engine or DMA subsystem\n"
203
243
" -o <file> - Append output to file (default: stdout)\n"
204
244
" -t <timeout> - Timeout in microseconds\n"
247
" --event <evt> - Specifies event for trigger and grab modes\n"
248
" --data <type> - Data type to request for the events\n"
249
" --run-time <us> - Grab/trigger events during the specified time\n"
250
" --trigger-rate <tps> - Generate tps triggers per second\n"
251
" --trigger-time <us> - Specifies delay between triggers in microseconds\n"
252
" -s <num|unlimited> - Number of events to grab and trigger\n"
253
" --format [type] - Specifies how event data should be stored\n"
254
" raw - Just write all events sequentially\n"
255
" add_header - Prefix events with 256 bit header\n"
256
" ringfs - Write to RingFS\n"
257
" --buffer [size] - Request data buffering, size in MB\n"
206
259
" DMA Options:\n"
207
260
" --multipacket - Read multiple packets\n"
208
261
" --wait - Wait until data arrives\n"
239
292
void List(pcilib_t *handle, pcilib_model_description_t *model_info, const char *bank, int details) {
241
294
pcilib_register_bank_description_t *banks;
242
295
pcilib_register_description_t *registers;
243
296
pcilib_event_description_t *events;
297
pcilib_event_data_type_description_t *types;
245
299
const pcilib_board_info_t *board_info = pcilib_get_board_info(handle);
246
300
const pcilib_dma_info_t *dma_info = pcilib_get_dma_info(handle);
367
424
if ((events[i].description)&&(events[i].description[0])) {
368
425
printf(": %s", events[i].description);
429
for (j = 0; types[j].name; j++) {
430
if (types[j].evid & events[i].evid) {
431
printf("\n %s", types[j].name);
432
if ((types[j].description)&&(types[j].description[0])) {
433
printf(": %s", types[j].description);
1001
int Grab(pcilib_t *handle, const char *event, FILE *o) {
1071
pcilib_event_t event;
1072
pcilib_event_data_type_t data;
1076
size_t trigger_time;
1081
int GrabCallback(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *user) {
1005
1084
size_t size, written;
1007
// ignoring event for now
1009
err = pcilib_grab(handle, PCILIB_EVENTS_ALL, &size, &data, PCILIB_TIMEOUT_TRIGGER);
1011
Error("Grabbing event is failed");
1086
GRABContext *ctx = (GRABContext*)user;
1087
pcilib_t *handle = ctx->handle;
1088
FILE *o = ctx->output;
1090
data = pcilib_get_data(handle, ctx->event, ctx->data, &size);
1091
if (!data) Error("Internal Error: No data is provided to event callback");
1014
1093
if (o) printf("Writting %zu bytes into file...\n", size);
1015
1094
else o = stdout;
1020
1099
else Error("Write failed");
1102
pcilib_return_data(handle, ctx->event, data);
1105
printf("data callback: %lu\n", event_id);
1108
int raw_data(pcilib_event_id_t event_id, pcilib_event_info_t *info, pcilib_event_flags_t flags, size_t size, void *data, void *user) {
1109
// printf("%i\n", event_id);
1112
void *Trigger(void *user) {
1113
GRABContext *ctx = (GRABContext*)user;
1115
pcilib_trigger(ctx->handle, PCILIB_EVENT0, 0, NULL);
1117
pcilib_trigger(ctx->handle, PCILIB_EVENT0, 0, NULL);
1122
int TriggerAndGrab(pcilib_t *handle, GRAB_MODE grab_mode, const char *event, const char *data_type, size_t num, size_t run_time, size_t trigger_time, PARTITION partition, FORMAT format, size_t buffer_size, FILE *ofile) {
1126
size_t size, written;
1128
pthread_t trigger_thread;
1130
ctx.handle = handle;
1132
ctx.event = PCILIB_EVENT0;
1133
ctx.run_time = run_time;
1134
ctx.trigger_time = trigger_time;
1138
// ignoring event for now
1139
pcilib_configure_autostop(handle, 2, 1000000);//PCILIB_TIMEOUT_TRIGGER);
1140
pcilib_configure_rawdata_callback(handle, &raw_data, NULL);
1142
err = pcilib_start(handle, PCILIB_EVENTS_ALL, PCILIB_EVENT_FLAGS_DEFAULT);
1143
if (err) Error("Failed to start event engine, error %i", err);
1145
if (pthread_create(&trigger_thread, NULL, Trigger, (void*)&ctx))
1146
Error("Error starting trigger thread");
1149
err = pcilib_stream(handle, &GrabCallback, &ctx);
1150
if (err) Error("Error streaming events, error %i", err);
1152
pcilib_stop(handle, PCILIB_EVENT_FLAGS_DEFAULT);
1155
err = pcilib_grab(handle, PCILIB_EVENTS_ALL, &size, &data, PCILIB_TIMEOUT_TRIGGER);
1157
Error("Grabbing event is failed");
1161
pthread_join(trigger_thread, NULL);
1167
int Trigger(pcilib_t *handle, const char *event, size_t triggers, size_t run_time, size_t trigger_time) {
1027
1171
int StartStopDMA(pcilib_t *handle, pcilib_model_description_t *model_info, pcilib_dma_engine_addr_t dma, pcilib_dma_direction_t dma_direction, int start) {
1029
1173
pcilib_dma_engine_t dmaid;
1568
1721
else if ((optind < argc)&&(argv[optind][0] != '-')) addr = argv[optind++];
1571
if (mode != MODE_INVALID) Usage(argc, argv, "Multiple operations are not supported");
1574
if (optarg) event = optarg;
1575
else if ((optind < argc)&&(argv[optind][0] != '-')) event = argv[optind++];
1724
if ((mode != MODE_INVALID)&&((mode != MODE_GRAB)||(grab_mode&GRAB_MODE_GRAB))) Usage(argc, argv, "Multiple operations are not supported");
1727
grab_mode |= GRAB_MODE_GRAB;
1730
if (optarg) stmp = optarg;
1731
else if ((optind < argc)&&(argv[optind][0] != '-')) stmp = argv[optind++];
1734
if ((event)&&(strcasecmp(stmp,event))) Usage(argc, argv, "Redefinition of considered event");
1739
if ((mode != MODE_INVALID)&&((mode != MODE_GRAB)||(grab_mode&GRAB_MODE_TRIGGER))) Usage(argc, argv, "Multiple operations are not supported");
1742
grab_mode |= GRAB_MODE_TRIGGER;
1745
if (optarg) stmp = optarg;
1746
else if ((optind < argc)&&(argv[optind][0] != '-')) stmp = argv[optind++];
1749
if ((event)&&(strcasecmp(stmp,event))) Usage(argc, argv, "Redefinition of considered event");
1577
1753
case OPT_LIST_DMA:
1578
1754
if (mode != MODE_INVALID) Usage(argc, argv, "Multiple operations are not supported");
1710
1886
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &size) != 1))
1711
Usage(argc, argv, "Invalid size is specified (%s)", optarg);
1887
if (strcasecmp(optarg, "unlimited"))
1888
Usage(argc, argv, "Invalid size is specified (%s)", optarg);
1714
1894
case OPT_ENDIANESS:
1733
1913
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &iterations) != 1))
1734
1914
Usage(argc, argv, "Invalid number of iterations is specified (%s)", optarg);
1923
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &run_time) != 1))
1924
Usage(argc, argv, "Invalid timeout is specified (%s)", optarg);
1926
case OPT_TRIGGER_TIME:
1927
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &trigger_time) != 1))
1928
Usage(argc, argv, "Invalid trigger-time is specified (%s)", optarg);
1930
case OPT_TRIGGER_RATE:
1931
if ((!isnumber(optarg))||(sscanf(optarg, "%zu", &ztmp) != 1))
1932
Usage(argc, argv, "Invalid trigger-rate is specified (%s)", optarg);
1934
trigger_time = 1000000 / ztmp + (1000000 % ztmp)?1:0;
1937
if (optarg) num_offset = optarg;
1938
else if ((optind < argc)&&(argv[optind][0] != '-')) num_offset = argv[optind++];
1939
else num_offset = NULL;
1942
if ((!isnumber(num_offset))||(sscanf(num_offset, "%zu", &buffer) != 1))
1943
Usage(argc, argv, "Invalid buffer size is specified (%s)", num_offset);
1944
buffer *= 1024 * 1024;
1946
buffer = get_free_memory();
1947
if (buffer < 256) Error("Not enough free memory (%lz MB) for buffering", buffer / 1024 / 1024);
1949
buffer -= 128 + buffer/16;
1953
if (!strcasecmp(optarg, "add_header")) format = FORMAT_HEADER;
1954
else if (!strcasecmp(optarg, "ringfs")) format = FORMAT_RINGFS;
1955
else if (strcasecmp(optarg, "raw")) Error("Invalid format (%s) is specified", optarg);
1736
1957
case OPT_QUIETE:
2094
if (mode == MODE_GRAB) {
2097
if (!get_file_fs(output, 127, fsname)) {
2098
if (!strcmp(fsname, "ext4")) partition = PARTITION_EXT4;
2099
else if (!strcmp(fsname, "raw")) partition = PARTITION_RAW;
2104
if (mode != MODE_GRAB) {
2105
if (size == (size_t)-1)
2106
Usage(argc, argv, "Unlimited size is not supported in selected operation mode");
1874
2110
if ((bank)&&(amode == ACCESS_DMA)) {
1931
2167
pcilib_reset(handle);
1933
2169
case MODE_GRAB:
1934
Grab(handle, event, ofile);
2170
TriggerAndGrab(handle, grab_mode, event, data_type, size, run_time, trigger_time, partition, format, buffer, ofile);
1936
2172
case MODE_LIST_DMA:
1937
2173
ListDMA(handle, fpga_device, model_info);