309
int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_event_callback_t cb, void *user) {
359
// DS: Currently, on event_id overflow we are assuming the buffer is lost
360
static int ipecamera_resolve_event_id(ipecamera_t *ctx, pcilib_event_id_t evid) {
361
pcilib_event_id_t diff;
363
if (evid > ctx->event_id) {
364
diff = (((pcilib_event_id_t)-1) - ctx->event_id) + evid;
365
if (diff >= ctx->buffer_size) return -1;
367
diff = ctx->event_id - evid;
368
if (diff >= ctx->buffer_size) return -1;
371
// DS: Request buffer_size to be power of 2 and replace to shifts (just recompute in set_buffer_size)
372
return (evid - 1) % ctx->buffer_size;
375
static inline void ipecamera_new_frame(ipecamera_t *ctx) {
376
ctx->buffer_pos = (++ctx->event_id) % ctx->buffer_size;
379
ctx->frame_info[ctx->buffer_pos].info.type = PCILIB_EVENT0;
380
// memset(ctx->cmask + ctx->buffer_pos * ctx->dim.height, 0, ctx->dim.height * sizeof(ipecamera_change_mask_t));
383
static uint32_t frame_magic[6] = { 0x51111111, 0x52222222, 0x53333333, 0x54444444, 0x55555555, 0x56666666 };
385
static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t bufsize, void *buf) {
387
ipecamera_t *ctx = (ipecamera_t*)user;
390
if ((bufsize >= 8)&&(!memcmp(buf, frame_magic, sizeof(frame_magic)))) {
391
//if (ctx->cur_size) ipecamera_new_frame(ctx);
392
ctx->frame_info[ctx->buffer_pos].info.seqnum = ((uint32_t*)buf)[6] & 0xF0000000;
393
ctx->frame_info[ctx->buffer_pos].info.offset = ((uint32_t*)buf)[7] & 0xF0000000;
394
gettimeofday(&ctx->frame_info[ctx->buffer_pos].info.timestamp, NULL);
397
if (ctx->parse_data) {
398
if (ctx->cur_size + bufsize > ctx->full_size) {
399
pcilib_error("Unexpected event data, we are expecting at maximum (%zu) bytes, but (%zu) already read", ctx->full_size, ctx->cur_size + bufsize);
400
return -PCILIB_ERROR_TOOBIG;
403
memcpy(ctx->buffer + ctx->buffer_pos * ctx->padded_size + ctx->cur_size, buf, bufsize);
406
ctx->cur_size += bufsize;
407
// printf("%i: %i %i\n", ctx->buffer_pos, ctx->cur_size, bufsize);
409
if (ctx->cur_size >= ctx->full_size) eof = 1;
411
if (ctx->event.params.rawdata.callback) {
412
ctx->event.params.rawdata.callback(ctx->event_id, (pcilib_event_info_t*)(ctx->frame_info + ctx->buffer_pos), (eof?PCILIB_EVENT_FLAG_EOF:PCILIB_EVENT_FLAGS_DEFAULT), bufsize, buf, ctx->event.params.rawdata.user);
416
ipecamera_new_frame(ctx);
418
if ((ctx->event_id == ctx->autostop.evid)&&(ctx->event_id)) {
420
return PCILIB_STREAMING_STOP;
423
if (check_deadline(&ctx->autostop.timestamp, PCILIB_DMA_TIMEOUT)) {
425
return PCILIB_STREAMING_STOP;
429
return PCILIB_STREAMING_REQ_FRAGMENT;
432
static void *ipecamera_reader_thread(void *user) {
434
ipecamera_t *ctx = (ipecamera_t*)user;
436
while (ctx->run_reader) {
437
err = pcilib_stream_dma(ctx->event.pcilib, ctx->rdma, 0, 0, PCILIB_DMA_FLAG_MULTIPACKET, PCILIB_DMA_TIMEOUT, &ipecamera_data_callback, user);
439
if (err == PCILIB_ERROR_TIMEOUT) {
440
if (check_deadline(&ctx->autostop.timestamp, PCILIB_DMA_TIMEOUT)) {
444
usleep(IPECAMERA_NOFRAME_SLEEP);
445
} else pcilib_error("DMA error while reading IPECamera frames, error: %i", err);
451
ctx->run_streamer = 0;
453
if (ctx->cur_size) pcilib_error("partialy read frame after stop signal, %zu bytes in the buffer", ctx->cur_size);
458
int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_event_flags_t flags) {
311
460
ipecamera_t *ctx = (ipecamera_t*)vctx;
312
pcilib_t *pcilib = ctx->pcilib;
461
pcilib_t *pcilib = vctx->pcilib;
313
462
pcilib_register_value_t value;
464
const size_t chan_size = (2 + IPECAMERA_PIXELS_PER_CHANNEL / 3) * sizeof(ipecamera_payload_t);
465
const size_t line_size = (IPECAMERA_MAX_CHANNELS * chan_size);
466
const size_t header_size = 8;
467
const size_t footer_size = 8;
469
size_t padded_blocks;
472
struct sched_param sched;
316
475
pcilib_error("IPECamera imaging is not initialized");
317
476
return PCILIB_ERROR_NOTINITIALIZED;
322
481
return PCILIB_ERROR_INVALID_REQUEST;
325
// if left in FRAME_REQUEST mode
326
SET_REG(control_reg, IPECAMERA_IDLE);
485
// Allow readout and clean the FRAME_REQUEST mode if set for some reason
486
SET_REG(control_reg, IPECAMERA_IDLE|IPECAMERA_READOUT_FLAG);
327
487
usleep(IPECAMERA_SLEEP_TIME);
328
488
CHECK_REG(status_reg, IPECAMERA_EXPECTED_STATUS);
329
489
if (err) return err;
332
//#ifdef IPECAMERA_DMA_ADDRESS
333
// SET_REG(packet_len_reg, IPECAMERA_DMA_PACKET_LENGTH);
334
// if (err) return err;
335
//#endif /* IPECAMERA_DMA_ADDRESS */
340
492
ctx->event_id = 0;
341
493
ctx->reported_id = 0;
495
ctx->parse_data = (flags&PCILIB_EVENT_FLAG_RAW_DATA_ONLY)?0:1;
344
498
ctx->dim.width = IPECAMERA_WIDTH;
345
ctx->dim.height = IPECAMERA_HEIGHT; //GET_REG(lines_reg, lines);
347
ctx->buffer = malloc(ctx->dim.width * ctx->dim.height * ctx->buffer_size * sizeof(ipecamera_pixel_t));
499
GET_REG(n_lines_reg, ctx->dim.height);
501
raw_size = header_size + ctx->dim.height * line_size + footer_size;
502
padded_blocks = raw_size / IPECAMERA_DMA_PACKET_LENGTH + ((raw_size % IPECAMERA_DMA_PACKET_LENGTH)?1:0);
504
ctx->image_size = ctx->dim.width * ctx->dim.height * sizeof(ipecamera_pixel_t);
505
ctx->raw_size = raw_size;
506
ctx->full_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
508
#ifdef IPECAMERA_BUG_EXTRA_DATA
511
#endif /* IPECAMERA_BUG_EXTRA_DATA */
513
ctx->padded_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
515
ctx->buffer = malloc(ctx->padded_size * ctx->buffer_size);
348
516
if (!ctx->buffer) {
349
517
err = PCILIB_ERROR_MEMORY;
350
pcilib_error("Unable to allocate ring buffer");
518
pcilib_error("Unable to allocate ring buffer (%lu bytes)", ctx->padded_size * ctx->buffer_size);
353
522
ctx->cmask = malloc(ctx->dim.height * ctx->buffer_size * sizeof(ipecamera_change_mask_t));
354
523
if (!ctx->cmask) {
355
524
err = PCILIB_ERROR_MEMORY;
356
525
pcilib_error("Unable to allocate change-mask buffer");
529
ctx->frame_info = malloc(ctx->buffer_size * sizeof(ipecamera_event_info_t));
530
if (!ctx->frame_info) {
531
err = PCILIB_ERROR_MEMORY;
532
pcilib_error("Unable to allocate frame-info buffer");
359
536
#ifdef IPECAMERA_DMA_ADDRESS
361
ctx->rdma = pcilib_find_dma_by_addr(ctx->pcilib, PCILIB_DMA_FROM_DEVICE, IPECAMERA_DMA_ADDRESS);
538
ctx->rdma = pcilib_find_dma_by_addr(vctx->pcilib, PCILIB_DMA_FROM_DEVICE, IPECAMERA_DMA_ADDRESS);
362
539
if (ctx->rdma == PCILIB_DMA_ENGINE_INVALID) {
363
540
err = PCILIB_ERROR_NOTFOUND;
364
541
pcilib_error("The C2S channel of IPECamera DMA Engine (%u) is not found", IPECAMERA_DMA_ADDRESS);
366
err = pcilib_start_dma(ctx->pcilib, ctx->rdma, PCILIB_DMA_FLAGS_DEFAULT);
543
err = pcilib_start_dma(vctx->pcilib, ctx->rdma, PCILIB_DMA_FLAGS_DEFAULT);
368
545
ctx->rdma = PCILIB_DMA_ENGINE_INVALID;
369
546
pcilib_error("Failed to initialize C2S channel of IPECamera DMA Engine (%u)", IPECAMERA_DMA_ADDRESS);
431
665
ctx->cmask = NULL;
668
memset(&ctx->autostop, 0, sizeof(ipecamera_autostop_t));
435
670
ctx->event_id = 0;
436
671
ctx->reported_id = 0;
443
static int ipecamera_get_payload(ipecamera_t *ctx, ipecamera_pixel_t *pbuf, ipecamera_change_mask_t *cbuf, int line_req, pcilib_register_value_t size, ipecamera_payload_t *payload, pcilib_register_value_t *advance) {
448
ipecamera_payload_t info = payload[0];
449
int channel = info&0x0F; // 4 bits
450
const int line = (info>>4)&0x7FF; // 11 bits
452
const int bpp = (info>>16)&0x0F; // 4 bits
453
const int pixels = (info>>20)&0xFF; // 8 bits
454
// 2 bits are reserved
455
int header = (info>>30)&0x03; // 2 bits
462
const int chan_offset = channel * IPECAMERA_PIXELS_PER_CHANNEL;
464
ipecamera_payload_t data;
466
#ifdef IPECAMERA_REORDER_CHANNELS
467
channel = ipecamera_channel_order[channel];
469
// printf("payload, channel: %i, magick: %i, all: %lx\n", channel, header, info);
471
//printf("channel[%x] = %x (line: %i, pixels: %i)\n", info, channel, line_req, pixels);
472
CHECK_FLAG("payload header magick", header == 2, header);
473
CHECK_FLAG("pixel size, only 10 bits are supported", bpp == 10, bpp);
474
CHECK_FLAG("row number, should be %li", line == line_req, line, line_req);
475
CHECK_FLAG("channel, limited by %li output channels", channel < IPECAMERA_MAX_CHANNELS, channel, IPECAMERA_MAX_CHANNELS);
476
CHECK_FLAG("channel, duplicate entry for channel", ((*cbuf)&(1<<channel)) == 0, channel);
478
// Fixing first lines bug
479
// Matthias: Using unlikely() saves 1ms
480
if ((line < 2)&&(pixels == (IPECAMERA_PIXELS_PER_CHANNEL - 1))) {
482
pbuf[chan_offset] = 0;
484
CHECK_FLAG("number of pixels, %li is expected", pixels == IPECAMERA_PIXELS_PER_CHANNEL, pixels, IPECAMERA_PIXELS_PER_CHANNEL);
488
ppw = pixels - bytes * 3;
491
CHECK_FLAG("payload data bytes, at least %i are expected", bytes < size, size, bytes);
495
for (i = 1, pix = pix_offset; i < bytes; i++) {
497
header = (data >> 30) & 0x03;
499
CHECK_FLAG("payload data magick", header == 3, header);
503
for (j = 0; j < 3; j++, pix++) {
504
pbuf[chan_offset + pix] = (data >> (10 * (2 - j))) & 0x3FF;
508
data = payload[bytes];
509
header = (data >> 30) & 0x03;
511
CHECK_FLAG("payload data magick", header == 3, header);
512
CHECK_FLAG("payload footer magick", (data&0x3FF) == 0x55, (data&0x3FF));
518
for (j = 0; j < ppw; j++, pix++) {
519
// pbuf[channel*IPECAMERA_PIXELS_PER_CHANNEL + pix] = (data >> (10 * (ppw - j - 1))) & 0x3FF;
520
pbuf[chan_offset + pix] = (data >> (10 * (ppw - j))) & 0x3FF;
523
*cbuf |= (1 << channel);
524
*advance = bytes + 1;
529
static int ipecamera_parse_image(ipecamera_t *ctx, ipecamera_pixel_t *pbuf, ipecamera_change_mask_t *cbuf, int first_line, int n_lines, pcilib_register_value_t size, ipecamera_payload_t *linebuf) {
531
pcilib_t *pcilib = ctx->pcilib;
533
int line = first_line;
534
pcilib_register_value_t pos, advance;
537
pcilib_error("The payload is tool small, we should have at least 8 header dwords and 8 footer.");
538
return PCILIB_ERROR_INVALID_DATA;
541
CHECK_VALUE(linebuf[0], 0x51111111);
542
CHECK_VALUE(linebuf[1], 0x52222222);
543
CHECK_VALUE(linebuf[2], 0x53333333);
544
CHECK_VALUE(linebuf[3], 0x54444444);
545
CHECK_VALUE(linebuf[4], 0x55555555);
546
CHECK_VALUE(linebuf[5], 0x56666666);
547
CHECK_VALUE(linebuf[6], 0x57777777);
548
CHECK_VALUE(linebuf[7], 0x58888888);
555
err = ipecamera_get_payload(ctx, pbuf + line * ctx->dim.width, cbuf + line, line - first_line, size, linebuf + pos, &advance);
561
if (cbuf[line] == ((1<<IPECAMERA_MAX_CHANNELS)-1)) ++line;
564
CHECK_FLAG("lines read, we expect to read exactly %li lines", line == (first_line + n_lines), line - first_line, n_lines);
566
CHECK_VALUE(linebuf[pos ], 0x0AAAAAAA);
567
CHECK_VALUE(linebuf[pos+1], 0x0BBBBBBB);
568
CHECK_VALUE(linebuf[pos+2], 0x0CCCCCCC);
569
CHECK_VALUE(linebuf[pos+3], 0x0DDDDDDD);
570
CHECK_VALUE(linebuf[pos+4], 0x0EEEEEEE);
571
CHECK_VALUE(linebuf[pos+5], 0x0FFFFFFF);
572
CHECK_VALUE(linebuf[pos+6], 0x00000000);
573
CHECK_VALUE(linebuf[pos+7], 0x01111111);
578
static int ipecamera_get_image(ipecamera_t *ctx) {
583
pcilib_t *pcilib = ctx->pcilib;
586
const int max_lines = IPECAMERA_MAX_LINES;
587
const size_t line_size = (IPECAMERA_MAX_CHANNELS * (2 + IPECAMERA_PIXELS_PER_CHANNEL / 3));
588
const size_t hf_size = 16;
589
const size_t max_size = hf_size + max_lines * line_size;
590
const size_t dma_packet_len = IPECAMERA_DMA_PACKET_LENGTH / sizeof(ipecamera_payload_t);
591
size_t max_packet_size;
593
pcilib_register_value_t ptr, size, pos, advance, value;
595
ipecamera_payload_t *linebuf;
597
if (max_size%dma_packet_len) max_packet_size = max_size + dma_packet_len - (max_size%dma_packet_len);
598
else max_packet_size = max_size;
600
max_packet_size += 4096; // Some extra data?
603
linebuf = (ipecamera_payload_t*)malloc(max_packet_size * sizeof(ipecamera_payload_t));
604
if (!linebuf) return PCILIB_ERROR_MEMORY;
607
err = pcilib_skip_dma(ctx->pcilib, ctx->rdma);
609
pcilib_error("Can't start benchmark, devices continuously writes unexpected data using DMA engine");
614
#ifdef IPECAMERA_WRITE_RAW
615
FILE *f = fopen("raw/image.raw", "w");
620
buf_ptr = ctx->buf_ptr;
621
if (ctx->buf_ptr++ == ctx->buffer_size) ctx->buf_ptr = 0;
622
if (ctx->event_id++ == 0) ctx->event_id = 1;
624
//const size_t image_size = ctx->dim.width * ctx->dim.height;
625
//memset(ctx->buffer + buf_ptr * image_size, 0, image_size * sizeof(ipecamera_pixel_t));
626
memset(ctx->cmask + buf_ptr * ctx->dim.height, 0, ctx->dim.height * sizeof(ipecamera_change_mask_t));
629
for (i = 0; i < ctx->dim.height; i += max_lines) {
630
num_lines = ctx->dim.height - i;
631
if (num_lines > max_lines) num_lines = max_lines;
633
SET_REG(n_lines_reg, num_lines);
634
SET_REG(line_reg, i);
636
SET_REG(control_reg, IPECAMERA_FRAME_REQUEST);
637
usleep(IPECAMERA_WAIT_FRAME_RCVD_TIME);
638
CHECK_REG(status_reg, IPECAMERA_EXPECTED_STATUS);
639
SET_REG(control_reg, IPECAMERA_IDLE);
641
#ifndef IPECAMERA_DMA_ADDRESS
642
GET_REG(start_reg, ptr);
643
GET_REG(end_reg, size);
648
CHECK_FLAG("data size", (size > 0)&&(size <= max_size), size);
649
#endif /* IPECAMERA_DMA_ADDRESS */
654
SET_REG(control_reg, IPECAMERA_READOUT);
655
// sync between End Of Readout and next Frame Req
656
usleep(IPECAMERA_NEXT_FRAME_DELAY);
660
// pcilib_start_dma(ctx->pcilib, ctx->rdma, PCILIB_DMA_FLAG_PERSISTENT);
661
// pcilib_stop_dma(ctx->pcilib, ctx->rdma, PCILIB_DMA_FLAGS_DEFAULT);
662
// pcilib_start_dma(ctx->pcilib, ctx->rdma, PCILIB_DMA_FLAGS_DEFAULT);
665
#ifdef IPECAMERA_DMA_ADDRESS
668
err = pcilib_read_dma(ctx->pcilib, ctx->rdma, 0, max_packet_size * sizeof(ipecamera_payload_t) - size, ((uint8_t*)linebuf) + size, &bytes_read);
670
// printf("%lu %lu\n", bytes_read, size);
671
} while ((err == 0)&&(size < max_packet_size * sizeof(ipecamera_payload_t)));
674
#ifdef DEBUG_HARDWARE
676
printf("===========Lines: %i - %i =========================\n", i, i + num_lines - 1);
677
err = pcilib_read_register(ctx->pcilib, NULL, "status", ®val);
678
printf("Status1: %i 0x%lx\n", err, regval);
679
err = pcilib_read_register(ctx->pcilib, NULL, "start_address", ®val);
680
printf("Start address: %i 0x%lx\n", err, regval);
681
err = pcilib_read_register(ctx->pcilib, NULL, "end_address", ®val);
682
printf("End address: %i 0x%lx\n", err, regval);
683
err = pcilib_read_register(ctx->pcilib, NULL, "last_write_address", ®val);
684
printf("Status2: %i 0x%lx\n", err, regval);
685
err = pcilib_read_register(ctx->pcilib, NULL, "last_write_value", ®val);
686
printf("Status3: %i 0x%lx\n", err, regval);
687
err = pcilib_read_register(ctx->pcilib, NULL, "reg9160", ®val);
688
printf("Add_rd_ddr: %i 0x%lx\n", err, regval);
689
#endif /* DEBUG_HARDWARE */
692
if (err == PCILIB_ERROR_TIMEOUT) {
693
if (size > 0) err = 0;
695
#ifdef IPECAMERA_DEBUG
696
pcilib_warning("There is no data received from IPE Camera for lines: %i to %i", i, i + num_lines - 1);
698
SET_REG(control_reg, IPECAMERA_IDLE);
700
#else /* IPECAMERA_DEBUG */
701
pcilib_error("There is no data received from IPE Camera");
703
#endif /* IPECAMERA_DEBUG */
705
} else pcilib_error("DMA read from IPE Camera have failed");
707
#ifdef IPECAMERA_DEBUG
708
pcilib_warning("There is no data received from IPE Camera for lines: %i to %i", i, i + num_lines - 1);
709
SET_REG(control_reg, IPECAMERA_IDLE);
711
#else /* IPECAMERA_DEBUG */
712
pcilib_warning("There is no data received from IPE Camera for lines: %i to %i", i, i + num_lines - 1);
714
#endif /* IPECAMERA_DEBUG */
717
pcilib_warning("Reading lines %i to %i: got %i bytes from DMA", i, i + num_lines - 1, size);
718
#else /* IPECAMERA_DMA_ADDRESS */
719
pcilib_warning("Reading lines %i to %i: %i %i", i, i + num_lines - 1, ptr, size);
720
pcilib_datacpy(linebuf, ctx->data + ptr, sizeof(ipecamera_payload_t), size, pcilib_model[PCILIB_MODEL_IPECAMERA].endianess);
721
#endif /* IPECAMERA_DMA_ADDRESS */
723
SET_REG(control_reg, IPECAMERA_IDLE);
724
// usleep(IPECAMERA_SLEEP_TIME);
725
CHECK_REG(status_reg, IPECAMERA_EXPECTED_STATUS);
729
#ifdef IPECAMERA_WRITE_RAW
731
sprintf(fname, "raw/line%04i", i);
732
FILE *f = fopen(fname, "w");
734
#ifdef IPECAMERA_DMA_ADDRESS
735
(void)fwrite(linebuf, sizeof(ipecamera_payload_t), size / sizeof(ipecamera_payload_t), f);
736
#else /* IPECAMERA_DMA_ADDRESS */
737
(void)fwrite(linebuf, sizeof(ipecamera_payload_t), size, f);
738
#endif /* IPECAMERA_DMA_ADDRESS */
743
#ifdef IPECAMERA_DMA_ADDRESS
744
if (size < (hf_size + max_lines * line_size) * sizeof(ipecamera_payload_t)) {
745
pcilib_error("We are expecting at least %zu bytes, but only %lu are read", (hf_size + num_lines * line_size)*sizeof(ipecamera_payload_t), size);
746
err = PCILIB_ERROR_INVALID_DATA;
750
size = hf_size + max_lines * line_size;
751
#endif /* IPECAMERA_DMA_ADDRESS */
754
err = ipecamera_parse_image(ctx, ctx->buffer + buf_ptr * ctx->dim.width * ctx->dim.height, ctx->cmask + buf_ptr * ctx->dim.height, i, num_lines, size, linebuf);
757
#ifdef IPECAMERA_WRITE_RAW
758
f = fopen("raw/image.raw", "a+");
760
fwrite(ctx->buffer + buf_ptr * ctx->dim.width * ctx->dim.height + i * ctx->dim.width, sizeof(ipecamera_pixel_t), num_lines * ctx->dim.width, f);
772
679
int ipecamera_trigger(pcilib_context_t *vctx, pcilib_event_t event, size_t trigger_size, void *trigger_data) {
681
pcilib_register_value_t value;
775
683
ipecamera_t *ctx = (ipecamera_t*)vctx;
684
pcilib_t *pcilib = vctx->pcilib;
778
687
pcilib_error("IPECamera imaging is not initialized");
798
static int ipecamera_resolve_event_id(ipecamera_t *ctx, pcilib_event_id_t evid) {
801
if ((!evid)||(evid > ctx->event_id)) return -1;
803
diff = ctx->event_id - evid;
804
buf_ptr = ctx->buf_ptr - diff - 1;
806
buf_ptr += ctx->buffer_size;
807
if (buf_ptr < 0) return -1;
813
pcilib_event_id_t ipecamera_next_event(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_timeout_t timeout) {
720
int ipecamera_stream(pcilib_context_t *vctx, pcilib_event_callback_t callback, void *user) {
815
723
pcilib_event_id_t reported;
816
724
ipecamera_t *ctx = (ipecamera_t*)vctx;
819
pcilib_error("IPECamera imaging is not initialized");
820
return PCILIB_EVENT_ID_INVALID;
824
pcilib_error("IPECamera is not in grabbing state");
825
return PCILIB_EVENT_ID_INVALID;
828
if ((!ctx->event_id)||(ctx->reported_id == ctx->event_id)) {
728
struct timeval stream_stop;
731
pcilib_error("IPECamera imaging is not initialized");
732
return PCILIB_ERROR_NOTINITIALIZED;
736
ctx->run_streamer = 1;
739
err = ipecamera_start(vctx, PCILIB_EVENTS_ALL, PCILIB_EVENT_FLAGS_DEFAULT);
742
pcilib_error("IPECamera is not in grabbing state");
743
return PCILIB_ERROR_INVALID_STATE;
749
// This loop iterates while the generation
750
while ((ctx->run_streamer)||(ctx->reported_id != ctx->event_id)) {
751
while (ctx->reported_id != ctx->event_id) {
752
if ((ctx->event_id - ctx->reported_id) > (ctx->buffer_size - IPECAMERA_RESERVE_BUFFERS)) ctx->reported_id = ctx->event_id - (ctx->buffer_size - 1) - IPECAMERA_RESERVE_BUFFERS;
753
else ++ctx->reported_id;
755
callback(ctx->reported_id, (pcilib_event_info_t*)(ctx->frame_info + (ctx->reported_id%ctx->buffer_size)), user);
757
usleep(IPECAMERA_NOFRAME_SLEEP);
763
ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
772
int ipecamera_next_event(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_timeout_t timeout, pcilib_event_id_t *evid, pcilib_event_info_t **info) {
774
ipecamera_t *ctx = (ipecamera_t*)vctx;
777
pcilib_error("IPECamera imaging is not initialized");
778
return PCILIB_ERROR_NOTINITIALIZED;
782
pcilib_error("IPECamera is not in grabbing mode");
783
return PCILIB_ERROR_INVALID_REQUEST;
786
if (ctx->reported_id == ctx->event_id) {
830
// We should wait here for the specified timeout
788
calc_deadline(&tv, timeout);
790
while ((calc_time_to_deadline(&tv) > 0)&&(ctx->reported_id == ctx->event_id))
791
usleep(IPECAMERA_NOFRAME_SLEEP);
832
return PCILIB_EVENT_ID_INVALID;
835
// We had an overflow in event counting
836
if (ctx->reported_id > ctx->event_id) {
838
if (++ctx->reported_id == 0) ctx->reported_id = 1;
839
} while (ipecamera_resolve_event_id(ctx, ctx->reported_id) < 0);
841
if ((ctx->event_id - ctx->reported_id) > ctx->buffer_size) ctx->reported_id = ctx->event_id - (ctx->buffer_size - 1);
842
else ++ctx->reported_id;
794
if (ctx->reported_id == ctx->event_id) return PCILIB_ERROR_TIMEOUT;
797
if ((ctx->event_id - ctx->reported_id) > (ctx->buffer_size - IPECAMERA_RESERVE_BUFFERS)) ctx->reported_id = ctx->event_id - (ctx->buffer_size - 1) - IPECAMERA_RESERVE_BUFFERS;
798
else ++ctx->reported_id;
845
800
return ctx->reported_id;
848
void* ipecamera_get(pcilib_context_t *vctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t *size) {
804
void* ipecamera_get(pcilib_context_t *vctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t *size, void *data) {
850
806
ipecamera_t *ctx = (ipecamera_t*)vctx;