From 6d3c61711bfe6524272bbde591e3494e0346a7da Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Sat, 2 May 2015 00:36:09 +0200 Subject: Cleanup --- ToDo | 6 +++++ base.c | 84 ++++++++++++++++----------------------------------------------- cmosis.c | 75 ++++++++++++++++++++++---------------------------------- data.c | 7 ++---- private.h | 40 ++++++++++++++++++------------ reader.c | 14 ++++------- 6 files changed, 87 insertions(+), 139 deletions(-) create mode 100644 ToDo diff --git a/ToDo b/ToDo new file mode 100644 index 0000000..a0ff257 --- /dev/null +++ b/ToDo @@ -0,0 +1,6 @@ + - Bring back sanity control (what to check?) + After pcilib_start, pcilib_reset, pcilib_trigger + - Implement proper reset function (what shall be in?) + - Detect actual max_lines (How?) + - When computing time for next trigger we should take into + the account: exposure time + hw readout time (complete formula) diff --git a/base.c b/base.c index 6a24bda..5336ab3 100644 --- a/base.c +++ b/base.c @@ -89,11 +89,9 @@ pcilib_context_t *ipecamera_init(pcilib_t *pcilib) { memset(ctx, 0, sizeof(ipecamera_t)); ctx->buffer_size = IPECAMERA_DEFAULT_BUFFER_SIZE; + ctx->dim.bpp = sizeof(ipecamera_pixel_t) * 8; - // We need DMA engine initialized to resolve DMA registers -// FIND_REG(packet_len_reg, "fpga", "xrawdata_packet_length"); - FIND_REG(status_reg, "fpga", "status"); FIND_REG(control_reg, "fpga", "control"); @@ -112,7 +110,6 @@ pcilib_context_t *ipecamera_init(pcilib_t *pcilib) { FIND_REG(max_frames_reg, "fpga", "ddr_max_frames"); FIND_REG(num_frames_reg, "fpga", "ddr_num_frames"); - GET_REG(firmware_version_reg, value); switch (value) { case 5: @@ -123,12 +120,15 @@ pcilib_context_t *ipecamera_init(pcilib_t *pcilib) { pcilib_warning("Unsupported version of firmware (%lu)", value); } -#ifdef IPECAMERA_BUG_POSTPONED_READ +#ifdef IPECAMERA_ADJUST_BUFFER_SIZE GET_REG(max_frames_reg, value); if ((value + IPECAMERA_RESERVE_BUFFERS + 3) > ctx->buffer_size) { + int val, bits = 0; ctx->buffer_size = (value + 1) + IPECAMERA_RESERVE_BUFFERS + 2; + for (val = ctx->buffer_size; val; val = val >> 1) bits++; + ctx->buffer_size = 1 << bits; } -#endif /* IPECAMERA_BUG_POSTPONED_READ */ +#endif /* IPECAMERA_ADJUST_BUFFER_SIZE */ ctx->rdma = PCILIB_DMA_ENGINE_INVALID; @@ -201,11 +201,6 @@ int ipecamera_reset(pcilib_context_t *vctx) { return PCILIB_ERROR_NOTINITIALIZED; } - if (!ctx->firmware) { - pcilib_warning("Unsupported version of firmware (%lu)", ctx->firmware); - return 0; - } - pcilib = vctx->pcilib; control = ctx->control_reg; status = ctx->status_reg; @@ -216,7 +211,7 @@ int ipecamera_reset(pcilib_context_t *vctx) { pcilib_error("Error setting FPGA reset bit"); return err; } - usleep(IPECAMERA_SLEEP_TIME); + usleep(IPECAMERA_CMOSIS_RESET_DELAY); // Remove Reset bit to CMOSIS err = pcilib_write_register_by_id(pcilib, control, 0x1e1); @@ -224,7 +219,7 @@ int ipecamera_reset(pcilib_context_t *vctx) { pcilib_error("Error reseting FPGA reset bit"); return err; } - usleep(IPECAMERA_SLEEP_TIME); + usleep(IPECAMERA_CMOSIS_REGISTER_DELAY); // Special settings for CMOSIS v.2 value = 01; err = pcilib_write_register_space(pcilib, "cmosis", 115, 1, &value); @@ -232,14 +227,14 @@ int ipecamera_reset(pcilib_context_t *vctx) { pcilib_error("Error setting CMOSIS configuration"); return err; } - usleep(IPECAMERA_SLEEP_TIME); + usleep(IPECAMERA_CMOSIS_REGISTER_DELAY); value = 07; err = pcilib_write_register_space(pcilib, "cmosis", 82, 1, &value); if (err) { pcilib_error("Error setting CMOSIS configuration"); return err; } - usleep(IPECAMERA_SLEEP_TIME); + usleep(IPECAMERA_CMOSIS_REGISTER_DELAY); // Set default parameters err = pcilib_write_register_by_id(pcilib, control, IPECAMERA_IDLE); @@ -261,9 +256,7 @@ int ipecamera_reset(pcilib_context_t *vctx) { return PCILIB_ERROR_VERIFY; } - // DS: Get rid of pending DMA data - - return 0; + return pcilib_skip_dma(vctx->pcilib, ctx->rdma); } @@ -285,11 +278,6 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev return PCILIB_ERROR_NOTINITIALIZED; } - if (!ctx->firmware) { - pcilib_error("Unsupported version of firmware (%lu)", ctx->firmware); - return PCILIB_ERROR_INVALID_REQUEST; - } - if (ctx->started) { pcilib_error("IPECamera grabbing is already started"); return PCILIB_ERROR_INVALID_REQUEST; @@ -394,40 +382,19 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev } } -/* - if (!err) { - ctx->wdma = pcilib_find_dma_by_addr(vctx->pcilib, PCILIB_DMA_TO_DEVICE, IPECAMERA_DMA_ADDRESS); - if (ctx->wdma == PCILIB_DMA_ENGINE_INVALID) { - err = PCILIB_ERROR_NOTFOUND; - pcilib_error("The S2C channel of IPECamera DMA Engine (%u) is not found", IPECAMERA_DMA_ADDRESS); - } else { - err = pcilib_start_dma(vctx->pcilib, ctx->wdma, PCILIB_DMA_FLAGS_DEFAULT); - if (err) { - ctx->wdma = PCILIB_DMA_ENGINE_INVALID; - pcilib_error("Failed to initialize S2C channel of IPECamera DMA Engine (%u)", IPECAMERA_DMA_ADDRESS); - } - } - } -*/ - -/* - SET_REG(packet_len_reg, IPECAMERA_DMA_PACKET_LENGTH); -*/ - if (err) { ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT); return err; } - // Clean DMA -#ifndef IPECAMERA_BUG_POSTPONED_READ +#ifdef IPECAMERA_CLEAN_ON_START err = pcilib_skip_dma(vctx->pcilib, ctx->rdma); if (err) { ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT); pcilib_error("Can't start grabbing, device continuously writes unexpected data using DMA engine"); return err; } -#endif /* ! IPECAMERA_BUG_POSTPONED_READ */ +#endif /* IPECAMERA_CLEAN_ON_START */ if (vctx->params.autostop.duration) { gettimeofday(&ctx->autostop.timestamp, NULL); @@ -635,11 +602,6 @@ int ipecamera_trigger(pcilib_context_t *vctx, pcilib_event_t event, size_t trigg return PCILIB_ERROR_NOTINITIALIZED; } - if (!ctx->firmware) { - pcilib_error("Unsupported version of firmware (%lu)", ctx->firmware); - return PCILIB_ERROR_INVALID_REQUEST; - } - pcilib_sleep_until_deadline(&ctx->next_trigger); /* GET_REG(num_frames_reg, value); @@ -650,16 +612,13 @@ int ipecamera_trigger(pcilib_context_t *vctx, pcilib_event_t event, size_t trigg GET_REG(status2_reg, value); if (value&0x40000000) { -// printf("%x\n", value); -// GET_REG(status3_reg, value); -// printf("3: %x\n", value); -// GET_REG(status_reg, value); -// printf("1: %x\n", value); - -#ifdef IPECAMERA_TRIGGER_WAIT_IDLE - if (IPECAMERA_TRIGGER_WAIT_IDLE) { + if (value == 0xffffffff) + pcilib_info("Failed to read status2_reg while triggering"); + +#ifdef IPECAMERA_TRIGGER_TIMEOUT + if (IPECAMERA_TRIGGER_TIMEOUT) { struct timeval deadline; - pcilib_calc_deadline(&deadline, IPECAMERA_TRIGGER_WAIT_IDLE); + pcilib_calc_deadline(&deadline, IPECAMERA_TRIGGER_TIMEOUT); do { usleep(IPECAMERA_READ_STATUS_DELAY); GET_REG(status2_reg, value); @@ -672,11 +631,10 @@ int ipecamera_trigger(pcilib_context_t *vctx, pcilib_event_t event, size_t trigg GET_REG(control_reg, value); SET_REG(control_reg, value|IPECAMERA_FRAME_REQUEST); - usleep(IPECAMERA_WAIT_FRAME_RCVD_TIME); - //DS: CHECK_REG(status_reg, IPECAMERA_EXPECTED_STATUS); + usleep(IPECAMERA_TRIGGER_DELAY); SET_REG(control_reg, value); - // We need to compute it differently, on top of that add exposure time and the time FPGA takes to read frame from CMOSIS + // DS: We need to compute it differently, on top of that add exposure time and the time FPGA takes to read frame from CMOSIS pcilib_calc_deadline(&ctx->next_trigger, IPECAMERA_NEXT_FRAME_DELAY); return 0; diff --git a/cmosis.c b/cmosis.c index a8a2251..4199148 100644 --- a/cmosis.c +++ b/cmosis.c @@ -22,14 +22,13 @@ #define ipecamera_datacpy(dst, src, bank) pcilib_datacpy(dst, src, 4, 1, bank->raw_endianess) //#define IPECAMERA_SIMPLIFIED_READOUT +//#define IPECAMERA_RETRY_ERRORS #define IPECAMERA_MULTIREAD -//static pcilib_register_value_t ipecamera_bit_mask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 }; - int ipecamera_cmosis_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx, pcilib_register_addr_t addr, pcilib_register_value_t *value) { uint32_t val, tmp[4]; char *wr, *rd; - struct timeval start;//, cur; + struct timeval start; int retries = RETRIES; const pcilib_register_bank_description_t *bank = bank_ctx->bank; @@ -42,35 +41,23 @@ int ipecamera_cmosis_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ct return PCILIB_ERROR_INVALID_ADDRESS; } - //printf("%i %x %p %p\n", addr, val, wr, rd); - -/* -#ifdef IPECAMERA_SIMPLIFIED_READOUT - ipecamera_datacpy(tmp, rd, bank); -#endif -*/ - retry: val = (addr << 8); ipecamera_datacpy(wr, &val, bank); #ifdef IPECAMERA_SIMPLIFIED_READOUT - usleep(IPECAMERA_REGISTER_TIMEOUT); -// ipecamera_datacpy(tmp, rd, bank); -// usleep(IPECAMERA_REGISTER_TIMEOUT); + usleep(IPECAMERA_SPI_REGISTER_DELAY); ipecamera_datacpy(wr, &val, bank); - usleep(IPECAMERA_REGISTER_TIMEOUT); -// ipecamera_datacpy(tmp, rd, bank); -// usleep(IPECAMERA_REGISTER_TIMEOUT); + usleep(IPECAMERA_SPI_REGISTER_DELAY); ipecamera_datacpy(wr, &val, bank); - usleep(IPECAMERA_REGISTER_TIMEOUT); + usleep(IPECAMERA_SPI_REGISTER_DELAY); #endif /* IPECAMERA_SIMPLIFIED_READOUT */ gettimeofday(&start, NULL); #ifdef IPECAMERA_MULTIREAD - usleep(IPECAMERA_REGISTER_TIMEOUT); + usleep(IPECAMERA_SPI_REGISTER_DELAY); pcilib_datacpy(tmp, rd, 4, 4, bank->raw_endianess); val = tmp[0]; #else /* IPECAMERA_MULTIREAD */ @@ -78,7 +65,7 @@ retry: while ((val & READ_READY_BIT) == 0) { gettimeofday(&cur, NULL); - if (((cur.tv_sec - start.tv_sec)*1000000 + (cur.tv_usec - start.tv_usec)) > IPECAMERA_REGISTER_TIMEOUT) break; + if (((cur.tv_sec - start.tv_sec)*1000000 + (cur.tv_usec - start.tv_usec)) > IPECAMERA_SPI_REGISTER_DELAY) break; ipecamera_datacpy(&val, rd, bank); } @@ -94,24 +81,29 @@ retry: } if (val & READ_ERROR_BIT) { -/* if (--retries > 0) { +#ifdef IPECAMERA_RETRY_ERRORS + if (--retries > 0) { pcilib_warning("Error reading register (CMOSIS %lu, status: %lx), retrying (try %i of %i)...", addr, val, RETRIES - retries, RETRIES); goto retry; - }*/ + } +#endif /* IPECAMERA_RETRY_ERRORS */ + pcilib_error("Error reading register value (CMOSIS %lu, status: %lx)", addr, val); return PCILIB_ERROR_FAILED; } if (((val&ADDR_MASK) >> 8) != addr) { +#ifdef IPECAMERA_RETRY_ERRORS if (--retries > 0) { pcilib_warning("Address verification failed during register read (CMOSIS %lu, status: %lx), retrying (try %i of %i)...", addr, val, RETRIES - retries, RETRIES); goto retry; } +#endif /* IPECAMERA_RETRY_ERRORS */ + pcilib_error("Address verification failed during register read (CMOSIS %lu, status: %lx)", addr, val); return PCILIB_ERROR_VERIFY; } -// *value = val&ipecamera_bit_mask[bits]; *value = val&0xFF; return 0; @@ -120,7 +112,7 @@ retry: int ipecamera_cmosis_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx, pcilib_register_addr_t addr, pcilib_register_value_t value) { uint32_t val, tmp[4]; char *wr, *rd; - struct timeval start;//, cur; + struct timeval start; int retries = RETRIES; const pcilib_register_bank_description_t *bank = bank_ctx->bank; @@ -134,61 +126,54 @@ int ipecamera_cmosis_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank_c return PCILIB_ERROR_INVALID_ADDRESS; } - //printf("%i %x %p %p\n", addr, val, wr, rd); - -/* -#ifdef IPECAMERA_SIMPLIFIED_READOUT - ipecamera_datacpy(tmp, rd, bank); -#endif -*/ - retry: val = WRITE_BIT|(addr << 8)|(value&0xFF); ipecamera_datacpy(wr, &val, bank); #ifdef IPECAMERA_SIMPLIFIED_READOUT - usleep(IPECAMERA_REGISTER_TIMEOUT); -// ipecamera_datacpy(tmp, rd, bank); -// usleep(IPECAMERA_REGISTER_TIMEOUT); + usleep(IPECAMERA_SPI_REGISTER_DELAY); ipecamera_datacpy(wr, &val, bank); - usleep(IPECAMERA_REGISTER_TIMEOUT); -// ipecamera_datacpy(tmp, rd, bank); -// usleep(IPECAMERA_REGISTER_TIMEOUT); + usleep(IPECAMERA_SPI_REGISTER_DELAY); ipecamera_datacpy(wr, &val, bank); - usleep(IPECAMERA_REGISTER_TIMEOUT); + usleep(IPECAMERA_SPI_REGISTER_DELAY); #endif /* IPECAMERA_SIMPLIFIED_READOUT */ gettimeofday(&start, NULL); #ifdef IPECAMERA_MULTIREAD - usleep(IPECAMERA_REGISTER_TIMEOUT); + usleep(IPECAMERA_SPI_REGISTER_DELAY); pcilib_datacpy(tmp, rd, 4, 4, bank->raw_endianess); val = tmp[0]; #else /* IPECAMERA_MULTIREAD */ ipecamera_datacpy(&val, rd, bank); while ((val & READ_READY_BIT) == 0) { gettimeofday(&cur, NULL); - if (((cur.tv_sec - start.tv_sec)*1000000 + (cur.tv_usec - start.tv_usec)) > IPECAMERA_REGISTER_TIMEOUT) break; + if (((cur.tv_sec - start.tv_sec)*1000000 + (cur.tv_usec - start.tv_usec)) > IPECAMERA_SPI_REGISTER_DELAY) break; ipecamera_datacpy(&val, rd, bank); } #endif /* IPECAMERA_MULTIREAD */ if ((val & READ_READY_BIT) == 0) { +#ifdef IPECAMERA_RETRY_ERRORS if (--retries > 0) { pcilib_warning("Timeout occured during register write (CMOSIS %lu, value: %lu, status: %lx), retrying (try %i of %i)...", addr, value, val, RETRIES - retries, RETRIES); goto retry; } +#endif /* IPECAMERA_RETRY_ERRORS */ pcilib_error("Timeout writting register value (CMOSIS %lu, value: %lu, status: %lx)", addr, value, val); return PCILIB_ERROR_TIMEOUT; } if (val & READ_ERROR_BIT) { -/* if (--retries > 0) { +#ifdef IPECAMERA_RETRY_ERRORS + if (--retries > 0) { pcilib_warning("Register write has failed (CMOSIS %lu, value: %lu, status: %lx), retrying (try %i of %i)...", addr, value, val, RETRIES - retries, RETRIES); goto retry; - }*/ + } +#endif /* IPECAMERA_RETRY_ERRORS */ + pcilib_error("Error writting register value (CMOSIS %lu, value: %lu, status: %lx)", addr, value, val); return PCILIB_ERROR_FAILED; } @@ -202,13 +187,11 @@ retry: return PCILIB_ERROR_VERIFY; } - if ((val&0xFF/*&ipecamera_bit_mask[bits]*/) != value) { + if ((val&0xFF) != value) { pcilib_error("Value verification failed during register read (CMOSIS %lu, value: %lu != %lu)", addr, val/*&ipecamera_bit_mask[bits]*/, value); return PCILIB_ERROR_VERIFY; } - //printf("%i\n", val&ipecamera_bit_mask[bits]); - return 0; } diff --git a/data.c b/data.c index 50d431a..dc61234 100644 --- a/data.c +++ b/data.c @@ -54,11 +54,8 @@ inline static int ipecamera_decode_frame(ipecamera_t *ctx, pcilib_event_id_t eve pixels = ctx->image + buf_ptr * ctx->image_size; memset(ctx->cmask + ctx->buffer_pos * ctx->dim.height, 0, ctx->dim.height * sizeof(ipecamera_change_mask_t)); -/* printf("decoding %lx...\n", ctx->raw_size); - FILE *f = fopen("/mnt/frame.xxx", "w"); - fwrite(ctx->buffer + buf_ptr * ctx->padded_size, 1, ctx->roi_raw_size, f); - fclose(f); - printf("%lu\n", ctx->raw_size);*/ + ipecamera_debug_buffer(RAW_FRAMES, ctx->frame[buf_ptr].event.raw_size, ctx->buffer + buf_ptr * ctx->padded_size, PCILIB_DEBUG_BUFFER_MKDIR, "raw_frame.%4lu", ctx->event_id); + res = ufo_decoder_decode_frame(ctx->ipedec, ctx->buffer + buf_ptr * ctx->padded_size, ctx->frame[buf_ptr].event.raw_size, pixels, &ctx->frame[buf_ptr].event.meta); if (!res) { ipecamera_debug_buffer(BROKEN_FRAMES, ctx->frame[buf_ptr].event.raw_size, ctx->buffer + buf_ptr * ctx->padded_size, PCILIB_DEBUG_BUFFER_MKDIR, "broken_frame.%4lu", ctx->event_id); diff --git a/private.h b/private.h index 2d3fa86..a7d39e2 100644 --- a/private.h +++ b/private.h @@ -6,32 +6,33 @@ #include #include "ipecamera.h" -//#define IPECAMERA_BUG_MISSING_PAYLOAD //**< CMOSIS fails to provide a first payload for each frame, therefore the frame is 32 bit shorter */ -#define IPECAMERA_BUG_MULTIFRAME_PACKETS //**< This is by design, start of packet comes directly after the end of last one in streaming mode */ -//#define IPECAMERA_BUG_INCOMPLETE_PACKETS //**< Support incomplete packets, i.e. check for frame magic even if full frame size is not reached yet (slow) */ -#define IPECAMERA_BUG_POSTPONED_READ -//#define IPECAMERA_ANNOUNCE_READY //**< announce new event only after the reconstruction is done */ - #define IPECAMERA_DEBUG - #ifdef IPECAMERA_DEBUG +//# define IPECAMERA_DEBUG_RAW_FRAMES # define IPECAMERA_DEBUG_BROKEN_FRAMES # define IPECAMERA_DEBUG_RAW_PACKETS #endif /* IPECAMERA_DEBUG */ -#define IPECAMERA_REGISTER_TIMEOUT 10000 //**< us */ -#define IPECAMERA_DMA_TIMEOUT 50000 //**< us */ +//#define IPECAMERA_BUG_MISSING_PAYLOAD //**< CMOSIS fails to provide a first payload for each frame, therefore the frame is 32 bit shorter */ +#define IPECAMERA_BUG_MULTIFRAME_PACKETS //**< This is by design, start of packet comes directly after the end of last one in streaming mode */ +//#define IPECAMERA_BUG_INCOMPLETE_PACKETS //**< Support incomplete packets, i.e. check for frame magic even if full frame size is not reached yet (slow) */ +//#define IPECAMERA_ANNOUNCE_READY //**< Announce new event only after the reconstruction is done */ +//#define IPECAMERA_CLEAN_ON_START //**< Read all the data from DMA before starting of recording */ +#define IPECAMERA_ADJUST_BUFFER_SIZE //**< Adjust default buffer size based on the hardware capabilities */ #define IPECAMERA_DEFAULT_BUFFER_SIZE 64 //**< should be power of 2 */ #define IPECAMERA_RESERVE_BUFFERS 2 //**< Return Frame is Lost error, if requested frame will be overwritten after specified number of frames -#define IPECAMERA_SLEEP_TIME 250000 //**< Michele thinks 250 should be enough, but reset failing in this case */ + +#define IPECAMERA_DMA_TIMEOUT 50000 //**< Default DMA timeout */ +#define IPECAMERA_TRIGGER_TIMEOUT 200000 //**< In trigger call allow specified timeout for camera to get out of busy state. Set 0 to fail immideatly */ +#define IPECAMERA_CMOSIS_RESET_DELAY 250000 //**< Michele thinks 250 should be enough, but reset failing in this case */ +#define IPECAMERA_CMOSIS_REGISTER_DELAY 250000 //**< Michele thinks 250 should be enough, but reset failing in this case */ +#define IPECAMERA_SPI_REGISTER_DELAY 10000 //**< Delay between consequitive access to the registers */ #define IPECAMERA_NEXT_FRAME_DELAY 1000 //**< Michele requires 30000 to sync between End Of Readout and next Frame Req */ -#define IPECAMERA_WAIT_FRAME_RCVD_TIME 0 //**< by Uros ,wait 6 ms */ -#define IPECAMERA_TRIGGER_WAIT_IDLE 200000 //**< In trigger call allow specified timeout for camera to get out of busy state. Set 0 to fail immideatly */ +#define IPECAMERA_TRIGGER_DELAY 0 //**< Defines how long the trigger bits should be set */ #define IPECAMERA_READ_STATUS_DELAY 1000 //**< According to Uros, 1ms delay needed before consequitive reads from status registers */ - -#define IPECAMERA_NOFRAME_SLEEP 100 -#define IPECAMERA_NOFRAME_PREPROC_SLEEP 100 +#define IPECAMERA_NOFRAME_SLEEP 100 //**< Sleep while polling for a new frame in reader */ +#define IPECAMERA_NOFRAME_PREPROC_SLEEP 100 //**< Sleep while polling for a new frame in pre-processor */ //#define IPECAMERA_MAX_LINES 1088 #define IPECAMERA_MAX_LINES 2048 @@ -55,6 +56,14 @@ #define IPECAMERA_MODE_11_BIT_ADC 1 #define IPECAMERA_MODE_10_BIT_ADC 0 +#ifdef IPECAMERA_DEBUG_RAW_FRAMES +# define IPECAMERA_DEBUG_RAW_FRAMES_MESSAGE(function, ...) pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__) +# define IPECAMERA_DEBUG_RAW_FRAMES_BUFFER(function, ...) pcilib_debug_data_buffer (#function, __VA_ARGS__) +#else /* IPECAMERA_DEBUG_RAW_FRAMES */ +# define IPECAMERA_DEBUG_RAW_FRAMES_MESSAGE(function, ...) +# define IPECAMERA_DEBUG_RAW_FRAMES_BUFFER(function, ...) +#endif /* IPECAMERA_DEBUG_RAW_FRAMES */ + #ifdef IPECAMERA_DEBUG_BROKEN_FRAMES # define IPECAMERA_DEBUG_BROKEN_FRAMES_MESSAGE(function, ...) pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__) # define IPECAMERA_DEBUG_BROKEN_FRAMES_BUFFER(function, ...) pcilib_debug_data_buffer (#function, __VA_ARGS__) @@ -116,7 +125,6 @@ struct ipecamera_s { pcilib_dma_engine_t rdma, wdma; - pcilib_register_t packet_len_reg; pcilib_register_t control_reg, status_reg; pcilib_register_t status2_reg, status3_reg; pcilib_register_t n_lines_reg; diff --git a/reader.c b/reader.c index 533a5a2..0364608 100644 --- a/reader.c +++ b/reader.c @@ -110,7 +110,7 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t ipecamera_debug_buffer(RAW_PACKETS, bufsize, NULL, 0, "frame%4lu/frame%9lu.invalid", ctx->event_id, packet_id); if (invalid_frame_id != ctx->event_id) { -// pcilib_warning("No frame magic in DMA packet of %u bytes, current event %lu", bufsize, ctx->event_id); + pcilib_info("No frame magic in DMA packet of %u bytes, current event %lu", bufsize, ctx->event_id); invalid_frame_id = ctx->event_id; } @@ -141,7 +141,7 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t ctx->frame[ctx->buffer_pos].event.info.offset = (((uint32_t*)buf)[7] & 0xFFFFFF) * 80; gettimeofday(&ctx->frame[ctx->buffer_pos].event.info.timestamp, NULL); } else { -// pcilib_warning("Frame magic is not found, ignoring broken data..."); + pcilib_info("Frame magic is not found, ignoring broken data..."); return PCILIB_STREAMING_CONTINUE; } } @@ -159,7 +159,6 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t if ((need + sizeof(frame_magic)) < bufsize) { extra_data = bufsize - need; - //bufsize = need; eof = 1; } @@ -180,7 +179,6 @@ static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t } ctx->cur_size += bufsize; -// printf("%i: %i %i\n", ctx->buffer_pos, ctx->cur_size, bufsize); if (ctx->cur_size >= ctx->roi_raw_size) { eof = 1; @@ -227,15 +225,13 @@ void *ipecamera_reader_thread(void *user) { } usleep(IPECAMERA_NOFRAME_SLEEP); } else pcilib_error("DMA error while reading IPECamera frames, error: %i", err); - } //else printf("no error\n"); - - //usleep(1000); + } } ctx->run_streamer = 0; -// if (ctx->cur_size) -// pcilib_error("partialy read frame after stop signal, %zu bytes in the buffer", ctx->cur_size); + if (ctx->cur_size) + pcilib_info("partialy read frame after stop signal, %zu bytes in the buffer", ctx->cur_size); return NULL; } -- cgit v1.2.3