summaryrefslogtreecommitdiffstats
path: root/ipecamera
diff options
context:
space:
mode:
Diffstat (limited to 'ipecamera')
-rw-r--r--ipecamera/CMakeLists.txt12
-rw-r--r--ipecamera/data.c272
-rw-r--r--ipecamera/data.h6
-rw-r--r--ipecamera/events.c160
-rw-r--r--ipecamera/events.h5
-rw-r--r--ipecamera/ipecamera.c678
-rw-r--r--ipecamera/ipecamera.h38
-rw-r--r--ipecamera/model.c211
-rw-r--r--ipecamera/model.h179
-rw-r--r--ipecamera/private.h149
-rw-r--r--ipecamera/public.h25
-rw-r--r--ipecamera/reader.c268
-rw-r--r--ipecamera/reader.h8
13 files changed, 0 insertions, 2011 deletions
diff --git a/ipecamera/CMakeLists.txt b/ipecamera/CMakeLists.txt
deleted file mode 100644
index 5b536f2..0000000
--- a/ipecamera/CMakeLists.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-include_directories(
- ${CMAKE_SOURCE_DIR}
- ${UFODECODE_INCLUDE_DIRS}
-)
-
-set(HEADERS ${HEADERS} ipecamera.h model.h reader.h events.h data.h public.h private.h)
-
-add_library(ipecamera STATIC ipecamera.c model.c reader.c events.c data.c)
-
-install(FILES ipecamera.h
- DESTINATION include
-)
diff --git a/ipecamera/data.c b/ipecamera/data.c
deleted file mode 100644
index 115d12e..0000000
--- a/ipecamera/data.c
+++ /dev/null
@@ -1,272 +0,0 @@
-#define _BSD_SOURCE
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/time.h>
-#include <pthread.h>
-#include <assert.h>
-
-#include <ufodecode.h>
-
-#include "../tools.h"
-#include "../error.h"
-
-#include "pcilib.h"
-#include "private.h"
-#include "data.h"
-
-// DS: Currently, on event_id overflow we are assuming the buffer is lost
-static int ipecamera_resolve_event_id(ipecamera_t *ctx, pcilib_event_id_t evid) {
- pcilib_event_id_t diff;
-
- if (evid > ctx->event_id) {
- diff = (((pcilib_event_id_t)-1) - ctx->event_id) + evid;
- if (diff >= ctx->buffer_size) return -1;
- } else {
- diff = ctx->event_id - evid;
- if (diff >= ctx->buffer_size) return -1;
- }
-
- // DS: Request buffer_size to be power of 2 and replace to shifts (just recompute in set_buffer_size)
- return (evid - 1) % ctx->buffer_size;
-}
-
-inline static int ipecamera_decode_frame(ipecamera_t *ctx, pcilib_event_id_t event_id) {
- int err = 0;
- size_t res;
- uint16_t *pixels;
-
- int buf_ptr = ipecamera_resolve_event_id(ctx, event_id);
- if (buf_ptr < 0) return PCILIB_ERROR_TIMEOUT;
-
- if (ctx->frame[buf_ptr].event.image_ready) return 0;
-
- if (ctx->frame[buf_ptr].event.info.flags&PCILIB_EVENT_INFO_FLAG_BROKEN) {
- err = PCILIB_ERROR_INVALID_DATA;
- ctx->frame[buf_ptr].event.image_broken = err;
- goto ready;
- }
-
-
- 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));
- res = ufo_decoder_decode_frame(ctx->ipedec, ctx->buffer + buf_ptr * ctx->padded_size, ctx->raw_size, pixels, &ctx->frame[buf_ptr].event.meta);
- if (!res) {
- err = PCILIB_ERROR_FAILED;
- ctx->frame[buf_ptr].event.image_broken = err;
- goto ready;
- }
-
- ctx->frame[buf_ptr].event.image_broken = 0;
-
-ready:
- ctx->frame[buf_ptr].event.image_ready = 1;
-
- if (ipecamera_resolve_event_id(ctx, event_id) < 0) {
- ctx->frame[buf_ptr].event.image_ready = 0;
- return PCILIB_ERROR_TIMEOUT;
- }
-
- return err;
-}
-
-static int ipecamera_get_next_buffer_to_process(ipecamera_t *ctx, pcilib_event_id_t *evid) {
- int res;
-
- if (ctx->preproc_id == ctx->event_id) return -1;
-
- if (ctx->preproc)
- pthread_mutex_lock(&ctx->preproc_mutex);
-
- if (ctx->preproc_id == ctx->event_id) {
- if (ctx->preproc)
- pthread_mutex_unlock(&ctx->preproc_mutex);
- return -1;
- }
-
- if ((ctx->event_id - ctx->preproc_id) > (ctx->buffer_size - IPECAMERA_RESERVE_BUFFERS)) ctx->preproc_id = ctx->event_id - (ctx->buffer_size - 1 - IPECAMERA_RESERVE_BUFFERS - 1);
-
- res = ctx->preproc_id%ctx->buffer_size;
-
- if (pthread_rwlock_trywrlock(&ctx->frame[res].mutex)) {
- pthread_mutex_unlock(&ctx->preproc_mutex);
- return -1;
- }
-
- *evid = ++ctx->preproc_id;
-
- if (ctx->preproc)
- pthread_mutex_unlock(&ctx->preproc_mutex);
-
- return res;
-}
-
-
-void *ipecamera_preproc_thread(void *user) {
- int buf_ptr;
- pcilib_event_id_t evid;
-
- ipecamera_preprocessor_t *preproc = (ipecamera_preprocessor_t*)user;
- ipecamera_t *ctx = preproc->ipecamera;
-
- while (ctx->run_preprocessors) {
- buf_ptr = ipecamera_get_next_buffer_to_process(ctx, &evid);
- if (buf_ptr < 0) {
- usleep(IPECAMERA_NOFRAME_PREPROC_SLEEP);
- continue;
- }
-
- ipecamera_decode_frame(ctx, evid);
-
- pthread_rwlock_unlock(&ctx->frame[buf_ptr].mutex);
- }
-
- return NULL;
-}
-
-static int ipecamera_get_frame(ipecamera_t *ctx, pcilib_event_id_t event_id) {
- int err;
- int buf_ptr = (event_id - 1) % ctx->buffer_size;
-
- if (ctx->preproc) {
- if (ctx->frame[buf_ptr].event.image_broken)
- return ctx->frame[buf_ptr].event.image_broken;
- } else {
- pthread_rwlock_rdlock(&ctx->frame[buf_ptr].mutex);
-
- err = ipecamera_decode_frame(ctx, event_id);
-
- if (err) {
- pthread_rwlock_unlock(&ctx->frame[buf_ptr].mutex);
- return err;
- }
-
- return 0;
- }
-
-
- while (!ctx->frame[buf_ptr].event.image_ready) {
- usleep(IPECAMERA_NOFRAME_PREPROC_SLEEP);
-
- buf_ptr = ipecamera_resolve_event_id(ctx, event_id);
- if (buf_ptr < 0) return PCILIB_ERROR_OVERWRITTEN;
- }
-
- pthread_rwlock_rdlock(&ctx->frame[buf_ptr].mutex);
-
- buf_ptr = ipecamera_resolve_event_id(ctx, event_id);
- if ((buf_ptr < 0)||(!ctx->frame[buf_ptr].event.image_ready)) {
- pthread_rwlock_unlock(&ctx->frame[buf_ptr].mutex);
- return PCILIB_ERROR_OVERWRITTEN;
- }
-
- return 0;
-}
-
-
-/*
- We will lock the data for non-raw data to prevent ocasional overwritting. The
- raw data will be overwritten by the reader thread anyway and we can't do
- anything to prevent it for performance reasons.
-*/
-int 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 **ret) {
- int err;
- int buf_ptr;
- size_t raw_size;
- ipecamera_t *ctx = (ipecamera_t*)vctx;
-
- void *data = *ret;
-
- if (!ctx) {
- pcilib_error("IPECamera imaging is not initialized");
- return PCILIB_ERROR_NOTINITIALIZED;
- }
-
- buf_ptr = ipecamera_resolve_event_id(ctx, event_id);
- if (buf_ptr < 0) return PCILIB_ERROR_OVERWRITTEN;
-
- switch ((ipecamera_data_type_t)data_type) {
- case IPECAMERA_RAW_DATA:
- raw_size = ctx->frame[buf_ptr].event.raw_size;
- if (data) {
- if ((!size)||(*size < raw_size)) return PCILIB_ERROR_TOOBIG;
- memcpy(data, ctx->buffer + buf_ptr * ctx->padded_size, raw_size);
- if (ipecamera_resolve_event_id(ctx, event_id) < 0) return PCILIB_ERROR_OVERWRITTEN;
- *size = raw_size;
- return 0;
- }
- if (size) *size = raw_size;
- *ret = ctx->buffer + buf_ptr * ctx->padded_size;
- return 0;
- case IPECAMERA_IMAGE_DATA:
- err = ipecamera_get_frame(ctx, event_id);
- if (err) return err;
-
- if (data) {
- if ((!size)||(*size < ctx->image_size * sizeof(ipecamera_pixel_t))) return PCILIB_ERROR_TOOBIG;
- memcpy(data, ctx->image + buf_ptr * ctx->image_size, ctx->image_size * sizeof(ipecamera_pixel_t));
- pthread_rwlock_unlock(&ctx->frame[buf_ptr].mutex);
- *size = ctx->image_size * sizeof(ipecamera_pixel_t);
- return 0;
- }
-
- if (size) *size = ctx->image_size * sizeof(ipecamera_pixel_t);
- *ret = ctx->image + buf_ptr * ctx->image_size;
- return 0;
- case IPECAMERA_CHANGE_MASK:
- err = ipecamera_get_frame(ctx, event_id);
- if (err) return err;
-
- if (data) {
- if ((!size)||(*size < ctx->dim.height * sizeof(ipecamera_change_mask_t))) return PCILIB_ERROR_TOOBIG;
- memcpy(data, ctx->image + buf_ptr * ctx->dim.height, ctx->dim.height * sizeof(ipecamera_change_mask_t));
- pthread_rwlock_unlock(&ctx->frame[buf_ptr].mutex);
- *size = ctx->dim.height * sizeof(ipecamera_change_mask_t);
- return 0;
- }
-
- if (size) *size = ctx->dim.height * sizeof(ipecamera_change_mask_t);
- *ret = ctx->cmask + buf_ptr * ctx->dim.height;
- return 0;
- case IPECAMERA_DIMENSIONS:
- if (size) *size = sizeof(ipecamera_image_dimensions_t);
- ret = (void*)&ctx->dim;
- return 0;
- case IPECAMERA_IMAGE_REGION:
- case IPECAMERA_PACKED_IMAGE:
- // Shall we return complete image or only changed parts?
- case IPECAMERA_PACKED_LINE:
- case IPECAMERA_PACKED_PAYLOAD:
- pcilib_error("Support for data type (%li) is not implemented yet", data_type);
- return PCILIB_ERROR_NOTSUPPORTED;
- default:
- pcilib_error("Unknown data type (%li) is requested", data_type);
- return PCILIB_ERROR_INVALID_REQUEST;
- }
-}
-
-
-/*
- We will unlock non-raw data and check if the raw data is not overwritten yet
-*/
-int ipecamera_return(pcilib_context_t *vctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, void *data) {
- ipecamera_t *ctx = (ipecamera_t*)vctx;
-
- if (!ctx) {
- pcilib_error("IPECamera imaging is not initialized");
- return PCILIB_ERROR_NOTINITIALIZED;
-
- }
-
- if ((ipecamera_data_type_t)data_type == IPECAMERA_RAW_DATA) {
- if (ipecamera_resolve_event_id(ctx, event_id) < 0) return PCILIB_ERROR_OVERWRITTEN;
- } else {
- int buf_ptr = (event_id - 1) % ctx->buffer_size;
- pthread_rwlock_unlock(&ctx->frame[buf_ptr].mutex);
- }
-
- return 0;
-}
diff --git a/ipecamera/data.h b/ipecamera/data.h
deleted file mode 100644
index 846cb78..0000000
--- a/ipecamera/data.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _IPECAMERA_DATA_H
-#define _IPECAMERA_DATA_H
-
-void *ipecamera_preproc_thread(void *user);
-
-#endif /* _IPECAMERA_DATA_H */
diff --git a/ipecamera/events.c b/ipecamera/events.c
deleted file mode 100644
index 3253fc5..0000000
--- a/ipecamera/events.c
+++ /dev/null
@@ -1,160 +0,0 @@
-#define _BSD_SOURCE
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/time.h>
-#include <pthread.h>
-#include <assert.h>
-
-#include <ufodecode.h>
-
-#include "../tools.h"
-#include "../error.h"
-
-#include "pcilib.h"
-#include "public.h"
-#include "private.h"
-#include "events.h"
-
-int ipecamera_stream(pcilib_context_t *vctx, pcilib_event_callback_t callback, void *user) {
- int run_flag = 1;
- int res, err = 0;
- int do_stop = 0;
-
- ipecamera_event_info_t info;
- ipecamera_t *ctx = (ipecamera_t*)vctx;
-
- if (!ctx) {
- pcilib_error("IPECamera imaging is not initialized");
- return PCILIB_ERROR_NOTINITIALIZED;
- }
-
- ctx->streaming = 1;
- ctx->run_streamer = 1;
-
- if (!ctx->started) {
- err = ipecamera_start(vctx, PCILIB_EVENTS_ALL, PCILIB_EVENT_FLAGS_DEFAULT);
- if (err) {
- ctx->streaming = 0;
- return err;
- }
-
- do_stop = 1;
- }
-
- if (ctx->parse_data) {
- // This loop iterates while the generation
- while ((run_flag)&&((ctx->run_streamer)||(ctx->reported_id != ctx->event_id))) {
-#ifdef IPECAMERA_ANNOUNCE_READY
- while (((!ctx->preproc)&&(ctx->reported_id != ctx->event_id))||((ctx->preproc)&&(ctx->reported_id != ctx->preproc_id))) {
-#else /* IPECAMERA_ANNOUNCE_READY */
- while (ctx->reported_id != ctx->event_id) {
-#endif /* IPECAMERA_ANNOUNCE_READY */
- 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);
- else ++ctx->reported_id;
-
- memcpy(&info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(ipecamera_event_info_t));
-
- if ((ctx->event_id - ctx->reported_id) < ctx->buffer_size) {
- res = callback(ctx->reported_id, (pcilib_event_info_t*)&info, user);
- if (res <= 0) {
- if (res < 0) err = -res;
- run_flag = 0;
- break;
- }
- }
- }
- usleep(IPECAMERA_NOFRAME_SLEEP);
- }
- } else {
- while ((run_flag)&&(ctx->run_streamer)) {
- usleep(IPECAMERA_NOFRAME_SLEEP);
- }
- }
-
- ctx->streaming = 0;
-
- if (do_stop) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- }
-
-
- return err;
-}
-
-int ipecamera_next_event(pcilib_context_t *vctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, size_t info_size, pcilib_event_info_t *info) {
- struct timeval tv;
- ipecamera_t *ctx = (ipecamera_t*)vctx;
-
- if (!ctx) {
- pcilib_error("IPECamera imaging is not initialized");
- return PCILIB_ERROR_NOTINITIALIZED;
- }
-
- if (!ctx->started) {
- pcilib_error("IPECamera is not in grabbing mode");
- return PCILIB_ERROR_INVALID_REQUEST;
- }
-
- if (!ctx->parse_data) {
- pcilib_error("RAWData only mode is requested");
- return PCILIB_ERROR_INVALID_REQUEST;
- }
-
-#ifdef IPECAMERA_ANNOUNCE_READY
- if (((!ctx->preproc)&&(ctx->reported_id == ctx->event_id))||((ctx->preproc)&&(ctx->reported_id == ctx->preproc_id))) {
-#else /* IPECAMERA_ANNOUNCE_READY */
- if (ctx->reported_id == ctx->event_id) {
-#endif /* IPECAMERA_ANNOUNCE_READY */
-
- if (timeout) {
- if (timeout == PCILIB_TIMEOUT_INFINITE) {
-#ifdef IPECAMERA_ANNOUNCE_READY
- while ((((!ctx->preproc)&&(ctx->reported_id == ctx->event_id))||((ctx->preproc)&&(ctx->reported_id == ctx->preproc_id)))) {
-#else /* IPECAMERA_ANNOUNCE_READY */
- while ((ctx->reported_id == ctx->event_id)) {
-#endif /* IPECAMERA_ANNOUNCE_READY */
- usleep(IPECAMERA_NOFRAME_SLEEP);
- }
- } else {
- pcilib_calc_deadline(&tv, timeout);
-
-#ifdef IPECAMERA_ANNOUNCE_READY
- while ((ctx->started)&&(pcilib_calc_time_to_deadline(&tv) > 0)&&(((!ctx->preproc)&&(ctx->reported_id == ctx->event_id))||((ctx->preproc)&&(ctx->reported_id == ctx->preproc_id)))) {
-#else /* IPECAMERA_ANNOUNCE_READY */
- while ((ctx->started)&&(pcilib_calc_time_to_deadline(&tv) > 0)&&(ctx->reported_id == ctx->event_id)) {
-#endif /* IPECAMERA_ANNOUNCE_READY */
- usleep(IPECAMERA_NOFRAME_SLEEP);
- }
- }
- }
-
- if (ctx->reported_id == ctx->event_id) {
- return PCILIB_ERROR_TIMEOUT;
- }
-
- }
-
-retry:
- 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);
- else ++ctx->reported_id;
-
- if (evid) *evid = ctx->reported_id;
-
- if (info) {
- if (info_size >= sizeof(ipecamera_event_info_t))
- memcpy(info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(ipecamera_event_info_t));
- else if (info_size >= sizeof(pcilib_event_info_t))
- memcpy(info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(pcilib_event_info_t));
- else
- return PCILIB_ERROR_INVALID_ARGUMENT;
- }
-
- if ((ctx->event_id - ctx->reported_id) >= ctx->buffer_size) goto retry;
-
- return 0;
-}
-
diff --git a/ipecamera/events.h b/ipecamera/events.h
deleted file mode 100644
index 5268c81..0000000
--- a/ipecamera/events.h
+++ /dev/null
@@ -1,5 +0,0 @@
-#ifndef _IPECAMERA_EVENTS_H
-#define _IPECAMERA_EVENTS_H
-
-
-#endif /* _IPECAMERA_EVENTS_H */
diff --git a/ipecamera/ipecamera.c b/ipecamera/ipecamera.c
deleted file mode 100644
index fe66948..0000000
--- a/ipecamera/ipecamera.c
+++ /dev/null
@@ -1,678 +0,0 @@
-#define _IPECAMERA_IMAGE_C
-#define _BSD_SOURCE
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/time.h>
-#include <pthread.h>
-#include <assert.h>
-
-#include <ufodecode.h>
-
-#include "../tools.h"
-#include "../error.h"
-#include "../event.h"
-
-#include "pcilib.h"
-#include "private.h"
-#include "model.h"
-#include "reader.h"
-#include "events.h"
-#include "data.h"
-
-
-#include "dma/nwl.h"
-
-#define FIND_REG(var, bank, name) \
- ctx->var = pcilib_find_register(pcilib, bank, name); \
- if (ctx->var == PCILIB_REGISTER_INVALID) { \
- err = PCILIB_ERROR_NOTFOUND; \
- pcilib_error("Unable to find a %s register", name); \
- }
-
-
-#define GET_REG(reg, var) \
- if (!err) { \
- err = pcilib_read_register_by_id(pcilib, ctx->reg, &var); \
- if (err) { \
- pcilib_error("Error reading %s register", ipecamera_registers[ctx->reg].name); \
- } \
- }
-
-#define SET_REG(reg, val) \
- if (!err) { \
- err = pcilib_write_register_by_id(pcilib, ctx->reg, val); \
- if (err) { \
- pcilib_error("Error writting %s register", ipecamera_registers[ctx->reg].name); \
- } \
- }
-
-#define CHECK_REG(reg, check) \
- if (!err) { \
- err = pcilib_read_register_by_id(pcilib, ctx->reg, &value); \
- if (err) { \
- pcilib_error("Error reading %s register", ipecamera_registers[ctx->reg].name); \
- } \
- if (value != check) { \
- pcilib_error("Unexpected value (0x%lx) of register %s", value, ipecamera_registers[ctx->reg].name); \
- err = PCILIB_ERROR_INVALID_DATA; \
- } \
- }
-
-#define IPECAMERA_GET_EXPECTED_STATUS(ctx) ((ctx->firmware == 4)?IPECAMERA_EXPECTED_STATUS_4:IPECAMERA_EXPECTED_STATUS)
-#define CHECK_STATUS_REG() CHECK_REG(status_reg, IPECAMERA_GET_EXPECTED_STATUS(ctx))
-
-#define CHECK_VALUE(value, val) \
- if ((!err)&&(value != val)) { \
- pcilib_error("Unexpected value (0x%x) in data stream (0x%x is expected)", value, val); \
- err = PCILIB_ERROR_INVALID_DATA; \
- }
-
-#define CHECK_FLAG(flag, check, ...) \
- if ((!err)&&(!(check))) { \
- pcilib_error("Unexpected value (0x%x) of " flag, __VA_ARGS__); \
- err = PCILIB_ERROR_INVALID_DATA; \
- }
-
-
-pcilib_context_t *ipecamera_init(pcilib_t *pcilib) {
- int err = 0;
-
- ipecamera_t *ctx = malloc(sizeof(ipecamera_t));
-
- if (ctx) {
- pcilib_register_value_t value;
-
- 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");
-
- FIND_REG(status3_reg, "fpga", "status3");
-
- FIND_REG(n_lines_reg, "cmosis", "cmosis_number_lines");
- FIND_REG(line_reg, "cmosis", "cmosis_start1");
- FIND_REG(exposure_reg, "cmosis", "cmosis_exp_time");
- FIND_REG(flip_reg, "cmosis", "cmosis_image_flipping");
-
- FIND_REG(firmware_version_reg, "fpga", "firmware_version");
- FIND_REG(adc_resolution_reg, "fpga", "adc_resolution");
- FIND_REG(output_mode_reg, "fpga", "output_mode");
-
- 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 4:
- case 5:
- ctx->firmware = value;
- break;
- default:
-// pcilib_error("Unsupported version of firmware (%lu)", value);
- ctx->firmware = 0;
- }
-
-#ifdef IPECAMERA_BUG_POSTPONED_READ
- GET_REG(max_frames_reg, value);
- if ((value + IPECAMERA_RESERVE_BUFFERS + 3) > ctx->buffer_size) {
- ctx->buffer_size = (value + 1) + IPECAMERA_RESERVE_BUFFERS + 2;
- }
-#endif /* IPECAMERA_BUG_POSTPONED_READ */
-
-
- ctx->rdma = PCILIB_DMA_ENGINE_INVALID;
- ctx->wdma = PCILIB_DMA_ENGINE_INVALID;
-
- if (err) {
- free(ctx);
- return NULL;
- }
- }
-
- return (pcilib_context_t*)ctx;
-}
-
-void ipecamera_free(pcilib_context_t *vctx) {
- if (vctx) {
- ipecamera_t *ctx = (ipecamera_t*)vctx;
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- free(ctx);
- }
-}
-
-pcilib_dma_context_t *ipecamera_init_dma(pcilib_context_t *vctx) {
-#ifdef IPECAMERA_DMA_R3
- ipecamera_t *ctx = (ipecamera_t*)vctx;
-#endif
-
- pcilib_model_description_t *model_info = pcilib_get_model_description(vctx->pcilib);
- if ((!model_info->dma_api)||(!model_info->dma_api->init)) {
- pcilib_error("The DMA engine is not configured in model");
- return NULL;
- }
-
-
-#ifdef IPECAMERA_DMA_R3
- if (ctx->firmware) {
- return model_info->dma_api->init(vctx->pcilib, PCILIB_NWL_MODIFICATION_IPECAMERA, NULL);
- } else {
- return model_info->dma_api->init(vctx->pcilib, PCILIB_DMA_MODIFICATION_DEFAULT, NULL);
- }
-#else
- return model_info->dma_api->init(vctx->pcilib, PCILIB_DMA_MODIFICATION_DEFAULT, NULL);
-#endif
-}
-
-
-int ipecamera_set_buffer_size(ipecamera_t *ctx, int size) {
- if (ctx->started) {
- pcilib_error("Can't change buffer size while grabbing");
- return PCILIB_ERROR_INVALID_REQUEST;
- }
-
- if (size < 2) {
- pcilib_error("The buffer size is too small");
- return PCILIB_ERROR_INVALID_REQUEST;
- }
-
- if (((size^(size-1)) < size) < size) {
- pcilib_error("The buffer size is not power of 2");
- }
-
- ctx->buffer_size = size;
-
- return 0;
-}
-
-int ipecamera_reset(pcilib_context_t *vctx) {
- int err = 0;
- ipecamera_t *ctx = (ipecamera_t*)vctx;
- pcilib_t *pcilib = vctx->pcilib;
-
- pcilib_register_t control, status;
- pcilib_register_value_t value;
-
- if (!ctx) {
- pcilib_error("IPECamera imaging is not initialized");
- 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;
-
- // Set Reset bit to CMOSIS
- err = pcilib_write_register_by_id(pcilib, control, 0x1e4);
- if (err) {
- pcilib_error("Error setting FPGA reset bit");
- return err;
- }
- usleep(IPECAMERA_SLEEP_TIME);
-
- // Remove Reset bit to CMOSIS
- err = pcilib_write_register_by_id(pcilib, control, 0x1e1);
- if (err) {
- pcilib_error("Error reseting FPGA reset bit");
- return err;
- }
- usleep(IPECAMERA_SLEEP_TIME);
-
- // Special settings for CMOSIS v.2
- value = 01; err = pcilib_write_register_space(pcilib, "cmosis", 115, 1, &value);
- if (err) {
- pcilib_error("Error setting CMOSIS configuration");
- return err;
- }
- usleep(IPECAMERA_SLEEP_TIME);
-
- 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);
-
- // Set default parameters
- err = pcilib_write_register_by_id(pcilib, control, IPECAMERA_IDLE);
- if (err) {
- pcilib_error("Error bringing FPGA in default mode");
- return err;
- }
-
- usleep(10000);
-
- err = pcilib_read_register_by_id(pcilib, status, &value);
- if (err) {
- pcilib_error("Error reading status register");
- return err;
- }
-
- if (value != IPECAMERA_GET_EXPECTED_STATUS(ctx)) {
- pcilib_error("Unexpected value (%lx) of status register, expected %lx", value, IPECAMERA_GET_EXPECTED_STATUS(ctx));
- return PCILIB_ERROR_VERIFY;
- }
-
- return 0;
-}
-
-
-int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_event_flags_t flags) {
- int i;
- int err = 0;
- ipecamera_t *ctx = (ipecamera_t*)vctx;
- pcilib_t *pcilib = vctx->pcilib;
- pcilib_register_value_t value;
-
- pthread_attr_t attr;
- struct sched_param sched;
-
- if (!ctx) {
- pcilib_error("IPECamera imaging is not initialized");
- 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;
- }
-
- // Allow readout and clean the FRAME_REQUEST mode if set for some reason
- GET_REG(control_reg, value);
- SET_REG(control_reg, value|IPECAMERA_READOUT_FLAG);
- usleep(IPECAMERA_SLEEP_TIME);
- if (value&0x1000) ctx->fr_mode = 1;
- else {
- ctx->fr_mode = 0;
- CHECK_STATUS_REG();
- if (err) return err;
- }
-
- ctx->event_id = 0;
- ctx->preproc_id = 0;
- ctx->reported_id = 0;
- ctx->buffer_pos = 0;
- ctx->parse_data = (flags&PCILIB_EVENT_FLAG_RAW_DATA_ONLY)?0:1;
- ctx->cur_size = 0;
-
- ctx->dim.width = IPECAMERA_WIDTH;
- ctx->dim.height = IPECAMERA_MAX_LINES;
-// GET_REG(n_lines_reg, ctx->dim.height);
-
- GET_REG(output_mode_reg, value);
- switch (value) {
- case IPECAMERA_MODE_16_CHAN_IO:
- ctx->cmosis_outputs = 16;
- break;
- case IPECAMERA_MODE_4_CHAN_IO:
- ctx->cmosis_outputs = 4;
- break;
- default:
- pcilib_error("IPECamera reporting invalid output_mode 0x%lx", value);
- return PCILIB_ERROR_INVALID_STATE;
- }
-
- ipecamera_compute_buffer_size(ctx, ctx->dim.height);
-
- ctx->raw_size = ctx->cur_raw_size;
- ctx->full_size = ctx->cur_full_size;
- ctx->padded_size = ctx->cur_padded_size;
-
- ctx->image_size = ctx->dim.width * ctx->dim.height;
-
-
- GET_REG(max_frames_reg, value);
- ctx->max_frames = value;
-
- ctx->buffer = malloc(ctx->padded_size * ctx->buffer_size);
- if (!ctx->buffer) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- pcilib_error("Unable to allocate ring buffer (%lu bytes)", ctx->padded_size * ctx->buffer_size);
- return PCILIB_ERROR_MEMORY;
- }
-
- ctx->image = (ipecamera_pixel_t*)malloc(ctx->image_size * ctx->buffer_size * sizeof(ipecamera_pixel_t));
- if (!ctx->image) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- pcilib_error("Unable to allocate image buffer (%lu bytes)", ctx->image_size * ctx->buffer_size * sizeof(ipecamera_pixel_t));
- return PCILIB_ERROR_MEMORY;
- }
-
- ctx->cmask = malloc(ctx->dim.height * ctx->buffer_size * sizeof(ipecamera_change_mask_t));
- if (!ctx->cmask) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- pcilib_error("Unable to allocate change-mask buffer");
- return PCILIB_ERROR_MEMORY;
- }
-
- ctx->frame = (ipecamera_frame_t*)malloc(ctx->buffer_size * sizeof(ipecamera_frame_t));
- if (!ctx->frame) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- pcilib_error("Unable to allocate frame-info buffer");
- return PCILIB_ERROR_MEMORY;
- }
-
- memset(ctx->frame, 0, ctx->buffer_size * sizeof(ipecamera_frame_t));
-
- for (i = 0; i < ctx->buffer_size; i++) {
- err = pthread_rwlock_init(&ctx->frame[i].mutex, NULL);
- if (err) break;
- }
-
- ctx->frame_mutex_destroy = i;
-
- if (err) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- pcilib_error("Initialization of rwlock mutexes for frame synchronization has failed");
- return PCILIB_ERROR_FAILED;
- }
-
- ctx->ipedec = ufo_decoder_new(ctx->dim.height, ctx->dim.width, NULL, 0);
- if (!ctx->ipedec) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- pcilib_error("Unable to initialize IPECamera decoder library");
- return PCILIB_ERROR_FAILED;
- }
-
- if (!err) {
- ctx->rdma = pcilib_find_dma_by_addr(vctx->pcilib, PCILIB_DMA_FROM_DEVICE, IPECAMERA_DMA_ADDRESS);
- if (ctx->rdma == PCILIB_DMA_ENGINE_INVALID) {
- err = PCILIB_ERROR_NOTFOUND;
- pcilib_error("The C2S channel of IPECamera DMA Engine (%u) is not found", IPECAMERA_DMA_ADDRESS);
- } else {
- err = pcilib_start_dma(vctx->pcilib, ctx->rdma, PCILIB_DMA_FLAGS_DEFAULT);
- if (err) {
- ctx->rdma = PCILIB_DMA_ENGINE_INVALID;
- pcilib_error("Failed to initialize C2S channel of IPECamera DMA Engine (%u)", IPECAMERA_DMA_ADDRESS);
- }
- }
- }
-
-/*
- 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
- 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 */
-
- if (vctx->params.autostop.duration) {
- gettimeofday(&ctx->autostop.timestamp, NULL);
- ctx->autostop.timestamp.tv_usec += vctx->params.autostop.duration % 1000000;
- if (ctx->autostop.timestamp.tv_usec > 999999) {
- ctx->autostop.timestamp.tv_sec += 1 + vctx->params.autostop.duration / 1000000;
- ctx->autostop.timestamp.tv_usec -= 1000000;
- } else {
- ctx->autostop.timestamp.tv_sec += vctx->params.autostop.duration / 1000000;
- }
- }
-
- if (vctx->params.autostop.max_events) {
- ctx->autostop.evid = vctx->params.autostop.max_events;
- }
-
- if ((ctx->parse_data)&&(flags&PCILIB_EVENT_FLAG_PREPROCESS)) {
- ctx->n_preproc = pcilib_get_cpu_count();
-
- // it would be greate to detect hyperthreading cores and ban them
- switch (ctx->n_preproc) {
- case 1: break;
- case 2 ... 3: ctx->n_preproc -= 1; break;
- default: ctx->n_preproc -= 2; break;
- }
-
- if ((vctx->params.parallel.max_threads)&&(vctx->params.parallel.max_threads < ctx->n_preproc))
- ctx->n_preproc = vctx->params.parallel.max_threads;
-
- ctx->preproc = (ipecamera_preprocessor_t*)malloc(ctx->n_preproc * sizeof(ipecamera_preprocessor_t));
- if (!ctx->preproc) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- pcilib_error("Unable to allocate memory for preprocessor contexts");
- return PCILIB_ERROR_MEMORY;
- }
-
- memset(ctx->preproc, 0, ctx->n_preproc * sizeof(ipecamera_preprocessor_t));
-
- err = pthread_mutex_init(&ctx->preproc_mutex, NULL);
- if (err) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- pcilib_error("Failed to initialize event mutex");
- return PCILIB_ERROR_FAILED;
- }
- ctx->preproc_mutex_destroy = 1;
-
-
- ctx->run_preprocessors = 1;
- for (i = 0; i < ctx->n_preproc; i++) {
- ctx->preproc[i].i = i;
- ctx->preproc[i].ipecamera = ctx;
- err = pthread_create(&ctx->preproc[i].thread, NULL, ipecamera_preproc_thread, ctx->preproc + i);
- if (err) {
- err = PCILIB_ERROR_FAILED;
- break;
- } else {
- ctx->preproc[i].started = 1;
- }
- }
-
- if (err) {
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- pcilib_error("Failed to schedule some of the preprocessor threads");
- return err;
- }
- } else {
- ctx->n_preproc = 0;
- }
-
- ctx->started = 1;
- ctx->run_reader = 1;
-
- pthread_attr_init(&attr);
-
- if (pthread_attr_setschedpolicy(&attr, SCHED_FIFO)) {
- pcilib_warning("Can't schedule a real-time thread, you may consider running as root");
- } else {
- sched.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1; // Let 1 priority for something really critcial
- pthread_attr_setschedparam(&attr, &sched);
- }
-
- if (pthread_create(&ctx->rthread, &attr, &ipecamera_reader_thread, (void*)ctx)) {
- ctx->started = 0;
- ipecamera_stop(vctx, PCILIB_EVENT_FLAGS_DEFAULT);
- err = PCILIB_ERROR_FAILED;
- }
-
- pthread_attr_destroy(&attr);
-
- return err;
-}
-
-
-int ipecamera_stop(pcilib_context_t *vctx, pcilib_event_flags_t flags) {
- int i;
- int err;
- void *retcode;
- ipecamera_t *ctx = (ipecamera_t*)vctx;
-
- if (!ctx) {
- pcilib_error("IPECamera imaging is not initialized");
- return PCILIB_ERROR_NOTINITIALIZED;
- }
-
- if (flags&PCILIB_EVENT_FLAG_STOP_ONLY) {
- ctx->run_reader = 0;
- return 0;
- }
-
- if (ctx->started) {
- ctx->run_reader = 0;
- err = pthread_join(ctx->rthread, &retcode);
- if (err) pcilib_error("Error joining the reader thread");
- }
-
- if (ctx->preproc) {
- ctx->run_preprocessors = 0;
-
- for (i = 0; i < ctx->n_preproc; i++) {
- if (ctx->preproc[i].started) {
- pthread_join(ctx->preproc[i].thread, &retcode);
- ctx->preproc[i].started = 0;
- }
- }
-
- if (ctx->preproc_mutex_destroy) {
- pthread_mutex_destroy(&ctx->preproc_mutex);
- ctx->preproc_mutex_destroy = 0;
- }
-
- free(ctx->preproc);
- ctx->preproc = NULL;
- }
-
- if (ctx->frame_mutex_destroy) {
- for (i = 0; i < ctx->frame_mutex_destroy; i++) {
- pthread_rwlock_destroy(&ctx->frame[i].mutex);
- }
- ctx->frame_mutex_destroy = 0;
- }
-
-
- if (ctx->wdma != PCILIB_DMA_ENGINE_INVALID) {
- pcilib_stop_dma(vctx->pcilib, ctx->wdma, PCILIB_DMA_FLAGS_DEFAULT);
- ctx->wdma = PCILIB_DMA_ENGINE_INVALID;
- }
-
- if (ctx->rdma != PCILIB_DMA_ENGINE_INVALID) {
- pcilib_stop_dma(vctx->pcilib, ctx->rdma, PCILIB_DMA_FLAGS_DEFAULT);
- ctx->rdma = PCILIB_DMA_ENGINE_INVALID;
- }
-
- while (ctx->streaming) {
- usleep(IPECAMERA_NOFRAME_SLEEP);
- }
-
- if (ctx->ipedec) {
- ufo_decoder_free(ctx->ipedec);
- ctx->ipedec = NULL;
- }
-
- if (ctx->frame) {
- free(ctx->frame);
- ctx->frame = NULL;
- }
-
- if (ctx->cmask) {
- free(ctx->cmask);
- ctx->cmask = NULL;
- }
-
- if (ctx->image) {
- free(ctx->image);
- ctx->image = NULL;
- }
-
- if (ctx->buffer) {
- free(ctx->buffer);
- ctx->buffer = NULL;
- }
-
-
- memset(&ctx->autostop, 0, sizeof(ipecamera_autostop_t));
-
- ctx->event_id = 0;
- ctx->reported_id = 0;
- ctx->buffer_pos = 0;
- ctx->started = 0;
-
- return 0;
-}
-
-
-int ipecamera_trigger(pcilib_context_t *vctx, pcilib_event_t event, size_t trigger_size, void *trigger_data) {
- int err = 0;
- pcilib_register_value_t value;
-
- ipecamera_t *ctx = (ipecamera_t*)vctx;
- pcilib_t *pcilib = vctx->pcilib;
-
- if (!ctx) {
- pcilib_error("IPECamera imaging is not initialized");
- 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);
- if (value == ctx->max_frames) {
- return PCILIB_ERROR_BUSY;
- }
-/*
- do {
- usleep(10);
- GET_REG(status3_reg, value);
- } while (value&0x20000000);
-*/
-
- GET_REG(control_reg, value);
- SET_REG(control_reg, value|IPECAMERA_FRAME_REQUEST);
- usleep(IPECAMERA_WAIT_FRAME_RCVD_TIME);
- //CHECK_REG(status_reg, IPECAMERA_EXPECTED_STATUS);
- SET_REG(control_reg, value);
-
-
- pcilib_calc_deadline(&ctx->next_trigger, IPECAMERA_NEXT_FRAME_DELAY);
-
- return 0;
-}
diff --git a/ipecamera/ipecamera.h b/ipecamera/ipecamera.h
deleted file mode 100644
index 673eea1..0000000
--- a/ipecamera/ipecamera.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef _IPECAMERA_H
-#define _IPECAMERA_H
-
-#include <ufodecode.h>
-
-typedef struct ipecamera_s ipecamera_t;
-
-typedef struct {
- unsigned int bpp; /*<< Bits per pixel (8, 16, or 32) as returned by IPECAMERA_IMAGE_DATA */
- unsigned int real_bpp; /*<< Bits per pixel as returned by camera and IPECAMERA_PACKED_IMAGE */
- unsigned int width, height;
-} ipecamera_image_dimensions_t;
-
-typedef enum {
- IPECAMERA_IMAGE_DATA = 0,
- IPECAMERA_RAW_DATA = 1,
- IPECAMERA_DIMENSIONS = 0x8000,
- IPECAMERA_IMAGE_REGION = 0x8010,
- IPECAMERA_PACKED_IMAGE = 0x8020,
- IPECAMERA_PACKED_LINE = 0x8021,
- IPECAMERA_PACKED_PAYLOAD = 0x8022,
- IPECAMERA_CHANGE_MASK = 0x8030
-} ipecamera_data_type_t;
-
-typedef uint16_t ipecamera_change_mask_t;
-typedef uint16_t ipecamera_pixel_t;
-
-typedef struct {
- pcilib_event_info_t info;
- UfoDecoderMeta meta; /**< Frame metadata declared in ufodecode.h */
- int image_ready; /**< Indicates if image data is parsed */
- int image_broken; /**< Unlike the info.flags this is bound to the reconstructed image (i.e. is not updated on rawdata overwrite) */
- size_t raw_size; /**< Indicates the actual size of raw data */
-} ipecamera_event_info_t;
-
-int ipecamera_set_buffer_size(ipecamera_t *ctx, int size);
-
-#endif /* _IPECAMERA_H */
diff --git a/ipecamera/model.c b/ipecamera/model.c
deleted file mode 100644
index e60561b..0000000
--- a/ipecamera/model.c
+++ /dev/null
@@ -1,211 +0,0 @@
-#define _BSD_SOURCE
-#define _IPECAMERA_MODEL_C
-#include <sys/time.h>
-#include <unistd.h>
-#include <assert.h>
-
-#include "../tools.h"
-#include "../error.h"
-#include "model.h"
-
-#define ADDR_MASK 0x7F00
-#define WRITE_BIT 0x8000
-#define RETRIES 10
-
-//ToDo: check bot 1 and 2 bits for READY
-#define READ_READY_BIT 0x20000
-#define READ_ERROR_BIT 0x40000
-
-#define ipecamera_datacpy(dst, src, bank) pcilib_datacpy(dst, src, 4, 1, bank->raw_endianess)
-
-//#define IPECAMERA_SIMPLIFIED_READOUT
-#define IPECAMERA_MULTIREAD
-
-//static pcilib_register_value_t ipecamera_bit_mask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
-
-int ipecamera_read(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t *value) {
- uint32_t val, tmp[4];
- char *wr, *rd;
- struct timeval start;//, cur;
- int retries = RETRIES;
-
- assert(addr < 128);
-
- wr = pcilib_resolve_register_address(ctx, bank->bar, bank->write_addr);
- rd = pcilib_resolve_register_address(ctx, bank->bar, bank->read_addr);
- if ((!rd)||(!wr)) {
- pcilib_error("Error resolving addresses of read & write registers");
- 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(PCILIB_REGISTER_TIMEOUT);
-// ipecamera_datacpy(tmp, rd, bank);
-// usleep(PCILIB_REGISTER_TIMEOUT);
- ipecamera_datacpy(wr, &val, bank);
- usleep(PCILIB_REGISTER_TIMEOUT);
-// ipecamera_datacpy(tmp, rd, bank);
-// usleep(PCILIB_REGISTER_TIMEOUT);
- ipecamera_datacpy(wr, &val, bank);
- usleep(PCILIB_REGISTER_TIMEOUT);
-#endif /* IPECAMERA_SIMPLIFIED_READOUT */
-
- gettimeofday(&start, NULL);
-
-#ifdef IPECAMERA_MULTIREAD
- usleep(PCILIB_REGISTER_TIMEOUT);
- 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)) > PCILIB_REGISTER_TIMEOUT) break;
-
- ipecamera_datacpy(&val, rd, bank);
- }
-#endif /* IPECAMERA_MULTIREAD */
-
- if ((val & READ_READY_BIT) == 0) {
- if (--retries > 0) {
- pcilib_warning("Timeout reading register value (CMOSIS %lu, status: %lx), retrying (try %i of %i)...", addr, val, RETRIES - retries, RETRIES);
- goto retry;
- }
- pcilib_error("Timeout reading register value (CMOSIS %lu, status: %lx)", addr, val);
- return PCILIB_ERROR_TIMEOUT;
- }
-
- if (val & READ_ERROR_BIT) {
-/* if (--retries > 0) {
- pcilib_warning("Error reading register (CMOSIS %lu, status: %lx), retrying (try %i of %i)...", addr, val, RETRIES - retries, RETRIES);
- goto retry;
- }*/
- pcilib_error("Error reading register value (CMOSIS %lu, status: %lx)", addr, val);
- return PCILIB_ERROR_FAILED;
- }
-
- if (((val&ADDR_MASK) >> 8) != addr) {
- 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;
- }
- 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;
-}
-
-int ipecamera_write(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t value) {
- uint32_t val, tmp[4];
- char *wr, *rd;
- struct timeval start;//, cur;
- int retries = RETRIES;
-
- assert(addr < 128);
- assert(value < 256);
-
- wr = pcilib_resolve_register_address(ctx, bank->bar, bank->write_addr);
- rd = pcilib_resolve_register_address(ctx, bank->bar, bank->read_addr);
- if ((!rd)||(!wr)) {
- pcilib_error("Error resolving addresses of read & write registers");
- 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(PCILIB_REGISTER_TIMEOUT);
-// ipecamera_datacpy(tmp, rd, bank);
-// usleep(PCILIB_REGISTER_TIMEOUT);
- ipecamera_datacpy(wr, &val, bank);
- usleep(PCILIB_REGISTER_TIMEOUT);
-// ipecamera_datacpy(tmp, rd, bank);
-// usleep(PCILIB_REGISTER_TIMEOUT);
- ipecamera_datacpy(wr, &val, bank);
- usleep(PCILIB_REGISTER_TIMEOUT);
-#endif /* IPECAMERA_SIMPLIFIED_READOUT */
-
- gettimeofday(&start, NULL);
-
-#ifdef IPECAMERA_MULTIREAD
- usleep(PCILIB_REGISTER_TIMEOUT);
- 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)) > PCILIB_REGISTER_TIMEOUT) break;
-
- ipecamera_datacpy(&val, rd, bank);
- }
-#endif /* IPECAMERA_MULTIREAD */
-
- if ((val & READ_READY_BIT) == 0) {
- 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;
- }
-
- 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) {
- 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;
- }*/
- pcilib_error("Error writting register value (CMOSIS %lu, value: %lu, status: %lx)", addr, value, val);
- return PCILIB_ERROR_FAILED;
- }
-
- if (((val&ADDR_MASK) >> 8) != addr) {
- if (--retries > 0) {
- pcilib_warning("Address verification failed during register write (CMOSIS %lu, value: %lu, status: %lx), retrying (try %i of %i)...", addr, value, val, RETRIES - retries, RETRIES);
- goto retry;
- }
- pcilib_error("Address verification failed during register write (CMOSIS %lu, value: %lu, status: %lx)", addr, value, val);
- return PCILIB_ERROR_VERIFY;
- }
-
- if ((val&0xFF/*&ipecamera_bit_mask[bits]*/) != 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/ipecamera/model.h b/ipecamera/model.h
deleted file mode 100644
index cc47891..0000000
--- a/ipecamera/model.h
+++ /dev/null
@@ -1,179 +0,0 @@
-#ifndef _IPECAMERA_MODEL_H
-#define _IPECAMERA_MODEL_H
-
-#include <stdio.h>
-
-#include "../pcilib.h"
-#include "public.h"
-
-//#define IPECAMERA_DEBUG
-
-#define IPECAMERA_DMA_R3
-#define IPECAMERA_DMA_ADDRESS 1
-#define IPECAMERA_DMA_PACKET_LENGTH 4096
-
-//#define IPECAMERA_REGISTER_SPACE 0xfeaffc00
-#define IPECAMERA_REGISTER_SPACE 0x9000
-#define IPECAMERA_REGISTER_WRITE (IPECAMERA_REGISTER_SPACE + 0)
-#define IPECAMERA_REGISTER_READ (IPECAMERA_REGISTER_WRITE + 16)
-
-#ifdef _IPECAMERA_MODEL_C
-pcilib_register_bank_description_t ipecamera_register_banks[] = {
- { PCILIB_REGISTER_BANK0, PCILIB_BAR0, 128, IPECAMERA_REGISTER_PROTOCOL, IPECAMERA_REGISTER_READ , IPECAMERA_REGISTER_WRITE, PCILIB_LITTLE_ENDIAN, 8 , PCILIB_LITTLE_ENDIAN, "%lu" , "cmosis", "CMOSIS CMV2000 Registers" },
- { PCILIB_REGISTER_BANK1, PCILIB_BAR0, 0x0200, PCILIB_DEFAULT_PROTOCOL , IPECAMERA_REGISTER_SPACE, IPECAMERA_REGISTER_SPACE, PCILIB_LITTLE_ENDIAN, 32, PCILIB_LITTLE_ENDIAN, "0x%lx", "fpga", "IPECamera Registers" },
- { PCILIB_REGISTER_BANK_DMA, PCILIB_BAR0, 0xA000, PCILIB_DEFAULT_PROTOCOL , 0, 0, PCILIB_LITTLE_ENDIAN, 32, PCILIB_LITTLE_ENDIAN, "0x%lx", "dma", "DMA Registers"},
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
-};
-
-pcilib_register_description_t ipecamera_registers[] = {
-{1, 0, 16, 1088, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_lines", ""},
-{3, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_start1", ""},
-{5, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_start2", ""},
-{7, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_start3", ""},
-{9, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_start4", ""},
-{11, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_start5", ""},
-{13, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_start6", ""},
-{15, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_start7", ""},
-{17, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_start8", ""},
-{19, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_lines1", ""},
-{21, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_lines2", ""},
-{23, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_lines3", ""},
-{25, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_lines4", ""},
-{27, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_lines5", ""},
-{29, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_lines6", ""},
-{31, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_lines7", ""},
-{33, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_lines8", ""},
-{35, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_sub_s", ""},
-{37, 0, 16, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_sub_a", ""},
-{39, 0, 1, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_color", ""},
-{40, 0, 2, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_image_flipping", ""},
-{41, 0, 2, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_exp_flags", ""},
-{42, 0, 24, 1088, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_exp_time", ""},
-{45, 0, 24, 1088, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_exp_step", ""},
-{48, 0, 24, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_exp_kp1", ""},
-{51, 0, 24, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_exp_kp2", ""},
-{54, 0, 2, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_nr_slopes", ""},
-{55, 0, 8, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_exp_seq", ""},
-{56, 0, 24, 1088, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_exp_time2", ""},
-{59, 0, 24, 1088, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_exp_step2", ""},
-{68, 0, 2, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_nr_slopes2", ""},
-{69, 0, 8, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_exp_seq2", ""},
-{70, 0, 16, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_number_frames", ""},
-{72, 0, 2, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_output_mode", ""},
-{78, 0, 12, 85, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_training_pattern", ""},
-{80, 0, 18, 0x3FFFF,0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_channel_en", ""},
-{82, 0, 3, 7, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_special_82", ""},
-{89, 0, 8, 96, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_vlow2", ""},
-{90, 0, 8, 96, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_vlow3", ""},
-{100, 0, 14, 16260, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_offset", ""},
-{102, 0, 2, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_pga", ""},
-{103, 0, 8, 32, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_adc_gain", ""},
-{111, 0, 1, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_bit_mode", ""},
-{112, 0, 2, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_adc_resolution", ""},
-{115, 0, 1, 1, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "cmosis_special_115", ""},
-/*{126, 0, 16, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK0, "temp", ""},*/
-{0x00, 0, 32, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "spi_conf_input", ""},
-{0x10, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "spi_conf_output", ""},
-{0x20, 0, 32, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "spi_clk_speed", ""},
-{0x30, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "firmware_info", ""},
-{0x30, 0, 8, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "firmware_version", ""},
-{0x30, 8, 1, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "firmware_bitmode", ""},
-{0x30, 12, 2, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "adc_resolution", ""},
-{0x30, 16, 2, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "output_mode", ""},
-{0x40, 0, 32, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "control", ""},
-{0x50, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "status", ""},
-{0x54, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "status2", ""},
-{0x58, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "status3", ""},
-{0x5c, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "fr_status", ""},
-{0x70, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "start_address", ""},
-{0x74, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "end_address", ""},
-{0x78, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "rd_address", ""},
-{0xa0, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "fr_param1", ""},
-{0xa0, 0, 10, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "fr_skip_lines", ""},
-{0xa0, 10, 11, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "fr_num_lines", ""},
-{0xa0, 21, 11, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "fr_start_address", ""},
-{0xb0, 0, 32, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "fr_param2", ""},
-{0xb0, 0, 11, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "fr_threshold_start_line", ""},
-{0xb0, 16, 10, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "fr_area_lines", ""},
-{0xc0, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "skiped_lines", ""},
-{0xd0, 0, 32, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "fr_thresholds", ""},
-{0xd0, 0, 10, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "fr_pixel_thr", ""},
-{0xd0, 10, 11, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "fr_num_pixel_thr", ""},
-{0xd0, 21, 11, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "fr_num_lines_thr", ""},
-{0x100, 0, 32, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "rawdata_pkt_addr", ""},
-{0x110, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "temperature_info", ""},
-{0x110, 0, 16, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "sensor_temperature", ""},
-{0x110, 16, 3, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "sensor_temperature_alarms", ""},
-{0x110, 19, 10, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "fpga_temperature", ""},
-{0x110, 29, 3, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "fpga_temperature_alarms", ""},
-{0x120, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "num_lines", ""},
-{0x130, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "start_line", ""},
-{0x140, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "exp_time", ""},
-{0x150, 0, 32, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "motor", ""},
-{0x150, 0, 5, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "motor_phi", ""},
-{0x150, 5, 5, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "motor_z", ""},
-{0x150, 10, 5, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "motor_y", ""},
-{0x150, 15, 5, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_RW, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "motor_x", ""},
-{0x150, 20, 8, 0, PCILIB_REGISTER_ALL_BITS, PCILIB_REGISTER_R, PCILIB_REGISTER_BITS, PCILIB_REGISTER_BANK1, "adc_gain", ""},
-{0x160, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "write_status", ""},
-{0x170, 0, 32, 0, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "num_triggers", ""},
-{0x180, 0, 32, 0x280, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "trigger_period", ""},
-{0x190, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "temperature_sample_period", ""},
-{0x1a0, 0, 32, 0x64, 0, PCILIB_REGISTER_RW, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "ddr_max_frames", ""},
-{0x1b0, 0, 32, 0, 0, PCILIB_REGISTER_R, PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK1, "ddr_num_frames", ""},
-{0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL}
-};
-
-pcilib_register_range_t ipecamera_register_ranges[] = {
- {0, 128, PCILIB_REGISTER_BANK0, 0},
- {0x9000, 0x9FFF, PCILIB_REGISTER_BANK1, -0x9000},
- {0, 0, 0, 0}
-};
-
-pcilib_event_description_t ipecamera_events[] = {
- {PCILIB_EVENT0, "new_frame", ""},
- {0, NULL, NULL}
-};
-
-pcilib_event_data_type_description_t ipecamera_data_types[] = {
- {IPECAMERA_IMAGE_DATA, PCILIB_EVENT0, "image", "16 bit pixel data" },
- {IPECAMERA_RAW_DATA, PCILIB_EVENT0, "raw", "raw data from camera" },
- {IPECAMERA_CHANGE_MASK, PCILIB_EVENT0, "cmask", "change mask" },
- {0, 0, NULL, NULL}
-};
-
-#else
-extern pcilib_register_description_t ipecamera_registers[];
-extern pcilib_register_bank_description_t ipecamera_register_banks[];
-extern pcilib_register_range_t ipecamera_register_ranges[];
-extern pcilib_event_description_t ipecamera_events[];
-extern pcilib_event_data_type_description_t ipecamera_data_types[];
-#endif
-
-#ifdef _IPECAMERA_IMAGE_C
-pcilib_event_api_description_t ipecamera_image_api = {
- "ipecamera",
-
- ipecamera_init,
- ipecamera_free,
-
- ipecamera_init_dma,
-
- ipecamera_reset,
- ipecamera_start,
- ipecamera_stop,
- ipecamera_trigger,
-
- ipecamera_stream,
- ipecamera_next_event,
- ipecamera_get,
- ipecamera_return
-};
-#else
-extern pcilib_event_api_description_t ipecamera_image_api;
-#endif
-
-int ipecamera_read(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t *value);
-int ipecamera_write(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t value);
-
-#endif /* _IPECAMERA_MODEL_H */
diff --git a/ipecamera/private.h b/ipecamera/private.h
deleted file mode 100644
index 47c80a9..0000000
--- a/ipecamera/private.h
+++ /dev/null
@@ -1,149 +0,0 @@
-#ifndef _IPECAMERA_PRIVATE_H
-#define _IPECAMERA_PRIVATE_H
-
-#include "ipecamera.h"
-
-#define IPECAMERA_BUG_EXTRA_DATA
-#define IPECAMERA_BUG_MULTIFRAME_PACKETS
-//#define IPECAMERA_BUG_INCOMPLETE_PACKETS
-//#define IPECAMERA_BUG_POSTPONED_READ
-//#define IPECAMERA_DEBUG_RAW_PACKETS "/mnt/fast/frames"
-
-//#define IPECAMERA_ANNOUNCE_READY //**< announce new event only after the reconstruction is done */
-
-#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_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_NOFRAME_SLEEP 100
-#define IPECAMERA_NOFRAME_PREPROC_SLEEP 100
-
-//#define IPECAMERA_MAX_LINES 1088
-#define IPECAMERA_MAX_LINES 2048
-#define IPECAMERA_EXPECTED_STATUS_4 0x08409FFFF
-#define IPECAMERA_EXPECTED_STATUS 0x08449FFFF
-
-#define IPECAMERA_END_OF_SEQUENCE 0x1F001001
-
-#define IPECAMERA_MAX_CHANNELS 16
-#define IPECAMERA_PIXELS_PER_CHANNEL 128
-#define IPECAMERA_WIDTH (IPECAMERA_MAX_CHANNELS * IPECAMERA_PIXELS_PER_CHANNEL)
-
-#define IPECAMERA_FRAME_REQUEST 0x1E9
-#define IPECAMERA_READOUT_FLAG 0x200
-#define IPECAMERA_READOUT 0x3E1
-#define IPECAMERA_IDLE 0x1E1
-#define IPECAMERA_START_INTERNAL_STIMULI 0x1F1
-
-#define IPECAMERA_MODE_16_CHAN_IO 0
-#define IPECAMERA_MODE_4_CHAN_IO 2
-
-#define IPECAMERA_MODE_12_BIT_ADC 2
-#define IPECAMERA_MODE_11_BIT_ADC 1
-#define IPECAMERA_MODE_10_BIT_ADC 0
-
-typedef uint32_t ipecamera_payload_t;
-
-typedef struct {
- pcilib_event_id_t evid;
- struct timeval timestamp;
-} ipecamera_autostop_t;
-
-typedef struct {
- size_t i;
- pthread_t thread;
- ipecamera_t *ipecamera;
-
- int started; /**< flag indicating that join & cleanup is required */
-} ipecamera_preprocessor_t;
-
-
-typedef struct {
- ipecamera_event_info_t event; /**< this structure is overwritten by the reader thread, we need a copy */
- pthread_rwlock_t mutex; /**< this mutex protects reconstructed buffers only, the raw data, event_info, etc. will be overwritten by reader thread anyway */
-} ipecamera_frame_t;
-
-struct ipecamera_s {
- pcilib_context_t event;
- UfoDecoder *ipedec;
-
- char *data;
- ipecamera_pixel_t *image;
- size_t size;
-
- pcilib_event_callback_t cb;
- void *cb_user;
-
- volatile pcilib_event_id_t event_id;
- volatile pcilib_event_id_t preproc_id;
- pcilib_event_id_t reported_id;
-
- pcilib_dma_engine_t rdma, wdma;
-
- pcilib_register_t packet_len_reg;
- pcilib_register_t control_reg, status_reg;
- pcilib_register_t status3_reg;
- pcilib_register_t n_lines_reg;
- uint16_t line_reg;
- pcilib_register_t exposure_reg;
- pcilib_register_t flip_reg;
-
- pcilib_register_t firmware_version_reg;
- pcilib_register_t adc_resolution_reg;
- pcilib_register_t output_mode_reg;
-
- pcilib_register_t max_frames_reg;
- pcilib_register_t num_frames_reg;
-
- int started; /**< Camera is in grabbing mode (start function is called) */
- int streaming; /**< Camera is in streaming mode (we are within stream call) */
- int parse_data; /**< Indicates if some processing of the data is required, otherwise only rawdata_callback will be called */
-
- volatile int run_reader; /**< Instructs the reader thread to stop processing */
- volatile int run_streamer; /**< Indicates request to stop streaming events and can be set by reader_thread upon exit or by user request */
- volatile int run_preprocessors; /**< Instructs preprocessors to exit */
-
- ipecamera_autostop_t autostop;
-
- struct timeval autostop_time;
- struct timeval next_trigger; /**< The minimal delay between trigger signals is mandatory, this indicates time when next trigger is possible */
-
- size_t buffer_size; /**< How many images to store */
- size_t buffer_pos; /**< Current image offset in the buffer, due to synchronization reasons should not be used outside of reader_thread */
- size_t cur_size; /**< Already written part of data in bytes */
- size_t raw_size; /**< Size of raw data in bytes */
- size_t full_size; /**< Size of raw data including the padding */
- size_t padded_size; /**< Size of buffer for raw data, including the padding for performance */
- size_t cur_raw_size; /**< Size of raw data in bytes */
- size_t cur_full_size; /**< Size of raw data including the padding */
- size_t cur_padded_size; /**< Size of buffer for raw data, including the padding for performance */
-
- size_t image_size; /**< Size of a single image in bytes */
-
- size_t max_frames; /**< Maximal number of frames what may be buffered in camera DDR memory */
- int firmware; /**< Firmware version */
- int fr_mode; /**< Fast Reject mode */
- int cmosis_outputs; /**< Number of active cmosis outputs: 4 or 16 */
- int width, height;
-
-
-// void *raw_buffer;
- void *buffer;
- ipecamera_change_mask_t *cmask;
- ipecamera_frame_t *frame;
-
-
- ipecamera_image_dimensions_t dim;
-
- pthread_t rthread;
-
- size_t n_preproc;
- ipecamera_preprocessor_t *preproc;
- pthread_mutex_t preproc_mutex;
-
- int preproc_mutex_destroy;
- int frame_mutex_destroy;
-};
-
-#endif /* _IPECAMERA_PRIVATE_H */
diff --git a/ipecamera/public.h b/ipecamera/public.h
deleted file mode 100644
index 5f494c2..0000000
--- a/ipecamera/public.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef _IPECAMERA_PUBLIC_H
-#define _IPECAMERA_PUBLIC_H
-
-#include <stdio.h>
-
-#include "ipecamera.h"
-#include "../pcilib.h"
-
-
-pcilib_context_t *ipecamera_init(pcilib_t *pcilib);
-void ipecamera_free(pcilib_context_t *ctx);
-
-pcilib_dma_context_t *ipecamera_init_dma(pcilib_context_t *ctx);
-
-int ipecamera_reset(pcilib_context_t *ctx);
-int ipecamera_start(pcilib_context_t *ctx, pcilib_event_t event_mask, pcilib_event_flags_t flags);
-int ipecamera_stop(pcilib_context_t *ctx, pcilib_event_flags_t flags);
-int ipecamera_trigger(pcilib_context_t *ctx, pcilib_event_t event, size_t trigger_size, void *trigger_data);
-int ipecamera_stream(pcilib_context_t *vctx, pcilib_event_callback_t callback, void *user);
-int ipecamera_next_event(pcilib_context_t *vctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, size_t info_size, pcilib_event_info_t *info);
-
-int ipecamera_get(pcilib_context_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t *size, void **buf);
-int ipecamera_return(pcilib_context_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, void *data);
-
-#endif /* _IPECAMERA_PUBLIC_H */
diff --git a/ipecamera/reader.c b/ipecamera/reader.c
deleted file mode 100644
index b9b7193..0000000
--- a/ipecamera/reader.c
+++ /dev/null
@@ -1,268 +0,0 @@
-#define _BSD_SOURCE
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <pthread.h>
-#include <assert.h>
-
-#include <ufodecode.h>
-
-#include "../tools.h"
-#include "../error.h"
-
-#include "pcilib.h"
-#include "model.h"
-#include "private.h"
-#include "reader.h"
-
-
-int ipecamera_compute_buffer_size(ipecamera_t *ctx, size_t lines) {
- const size_t header_size = 8 * sizeof(ipecamera_payload_t);
- const size_t footer_size = 8 * sizeof(ipecamera_payload_t);
-
- size_t line_size, raw_size, padded_blocks;
-
-
- switch (ctx->firmware) {
- case 4:
- line_size = IPECAMERA_MAX_CHANNELS * (2 + IPECAMERA_PIXELS_PER_CHANNEL / 3) * sizeof(ipecamera_payload_t);
- raw_size = header_size + lines * line_size + footer_size;
- break;
- default:
- line_size = (1 + IPECAMERA_PIXELS_PER_CHANNEL) * 32;
- raw_size = header_size + lines * line_size - 32 + footer_size;
- raw_size *= 16 / ctx->cmosis_outputs;
- }
-
- padded_blocks = raw_size / IPECAMERA_DMA_PACKET_LENGTH + ((raw_size % IPECAMERA_DMA_PACKET_LENGTH)?1:0);
-
- ctx->cur_raw_size = raw_size;
- ctx->cur_full_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
-
-#ifdef IPECAMERA_BUG_EXTRA_DATA
- ctx->cur_full_size += 8;
- padded_blocks ++;
-#endif /* IPECAMERA_BUG_EXTRA_DATA */
-
- ctx->cur_padded_size = padded_blocks * IPECAMERA_DMA_PACKET_LENGTH;
-
- return 0;
-}
-
-static inline int ipecamera_new_frame(ipecamera_t *ctx) {
- ctx->frame[ctx->buffer_pos].event.raw_size = ctx->cur_size;
-
- if (ctx->cur_size < ctx->cur_raw_size) {
- ctx->frame[ctx->buffer_pos].event.info.flags |= PCILIB_EVENT_INFO_FLAG_BROKEN;
- }
-
- ctx->buffer_pos = (++ctx->event_id) % ctx->buffer_size;
- ctx->cur_size = 0;
-
- ctx->frame[ctx->buffer_pos].event.info.type = PCILIB_EVENT0;
- ctx->frame[ctx->buffer_pos].event.info.flags = 0;
- ctx->frame[ctx->buffer_pos].event.image_ready = 0;
-
- if ((ctx->event_id == ctx->autostop.evid)&&(ctx->event_id)) {
- ctx->run_reader = 0;
- return 1;
- }
-
- if (pcilib_check_deadline(&ctx->autostop.timestamp, PCILIB_DMA_TIMEOUT)) {
- ctx->run_reader = 0;
- return 1;
- }
-
- return 0;
-}
-
-static uint32_t frame_magic[5] = { 0x51111111, 0x52222222, 0x53333333, 0x54444444, 0x55555555 };
-
-static int ipecamera_data_callback(void *user, pcilib_dma_flags_t flags, size_t bufsize, void *buf) {
- int res;
- int eof = 0;
-
-#ifdef IPECAMERA_BUG_MULTIFRAME_PACKETS
- size_t real_size;
- size_t extra_data = 0;
-#endif /* IPECAMERA_BUG_MULTIFRAME_PACKETS */
-
- ipecamera_t *ctx = (ipecamera_t*)user;
-
-#if defined(IPECAMERA_BUG_INCOMPLETE_PACKETS)||defined(IPECAMERA_BUG_MULTIFRAME_PACKETS)
- static pcilib_event_id_t invalid_frame_id = (pcilib_event_id_t)-1;
-#endif
-
-#ifdef IPECAMERA_DEBUG_RAW_PACKETS
- char fname[128];
- {
- static unsigned long packet_id = 0;
- sprintf(fname,"%s/frame%4lu", IPECAMERA_DEBUG_RAW_PACKETS, ctx->event_id);
- mkdir(fname, 0755);
- sprintf(fname,"%s/frame%4lu/frame%9lu", IPECAMERA_DEBUG_RAW_PACKETS, ctx->event_id, packet_id);
- FILE *f = fopen(fname, "w");
- if (f) {
- fwrite(buf, 1, bufsize, f);
- fclose(f);
- }
- sprintf(fname,"%s/frame%4lu/frame%9lu.invalid", IPECAMERA_DEBUG_RAW_PACKETS, ctx->event_id, packet_id++);
- }
-#endif /* IPECAMERA_DEBUG_RAW_PACKETS */
-
- if (!ctx->cur_size) {
-#if defined(IPECAMERA_BUG_INCOMPLETE_PACKETS)||defined(IPECAMERA_BUG_MULTIFRAME_PACKETS)
- size_t startpos;
- for (startpos = 0; (startpos + sizeof(frame_magic)) < bufsize; startpos += sizeof(uint32_t)) {
- if (!memcmp(buf + startpos, frame_magic, sizeof(frame_magic))) break;
- }
-
- if ((startpos + sizeof(frame_magic)) >= bufsize) {
-#ifdef IPECAMERA_DEBUG_RAW_PACKETS
- FILE *f = fopen(fname, "w");
- if (f) fclose(f);
-#endif /* IPECAMERA_DEBUG_RAW_PACKETS */
-
- 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);
- invalid_frame_id = ctx->event_id;
- }
-
- return PCILIB_STREAMING_CONTINUE;
- }
-
- if (startpos) {
- // pass padding to rawdata callback
- if (ctx->event.params.rawdata.callback) {
- res = ctx->event.params.rawdata.callback(0, NULL, PCILIB_EVENT_FLAG_RAW_DATA_ONLY, startpos, buf, ctx->event.params.rawdata.user);
- if (res <= 0) {
- if (res < 0) return res;
- ctx->run_reader = 0;
- }
- }
-
-
- buf += startpos;
- bufsize -= startpos;
- }
-#endif /* IPECAMERA_BUG_INCOMPLETE_PACKETS */
-
- if ((bufsize >= 8)&&(!memcmp(buf, frame_magic, sizeof(frame_magic)))) {
- size_t n_lines = ((uint32_t*)buf)[5] & 0x7FF;
- ipecamera_compute_buffer_size(ctx, n_lines);
-
- ctx->frame[ctx->buffer_pos].event.info.seqnum = ((uint32_t*)buf)[6] & 0x1FFFFFF;
- ctx->frame[ctx->buffer_pos].event.info.offset = (((uint32_t*)buf)[7] & 0xFFFFFF) * 80;
-
-// ctx->frame[ctx->buffer_pos].event.info.seqnum = ctx->event_id + 1;
-
- gettimeofday(&ctx->frame[ctx->buffer_pos].event.info.timestamp, NULL);
- } else {
-// pcilib_warning("Frame magic is not found, ignoring broken data...");
- return PCILIB_STREAMING_CONTINUE;
- }
- }
-
-#ifdef IPECAMERA_BUG_MULTIFRAME_PACKETS
- // for rawdata_callback with complete padding
- real_size = bufsize;
-
- if (ctx->cur_size + bufsize > ctx->cur_raw_size) {
- size_t need;
-
- for (need = ctx->cur_raw_size - ctx->cur_size; (need + sizeof(frame_magic)) < bufsize; need += sizeof(uint32_t)) {
- if (!memcmp(buf + need, frame_magic, sizeof(frame_magic))) break;
- }
-
- if ((need + sizeof(frame_magic)) < bufsize) {
- extra_data = bufsize - need;
- //bufsize = need;
- eof = 1;
- }
-
- // just rip of padding
- bufsize = ctx->cur_raw_size - ctx->cur_size;
-
-#ifdef IPECAMERA_DEBUG_RAW_PACKETS
- sprintf(fname + strlen(fname) - 8, ".partial");
- FILE *f = fopen(fname, "w");
- if (f) {
- fwrite(buf, 1, bufsize, f);
- fclose(f);
- }
-#endif /* IPECAMERA_DEBUG_RAW_PACKETS */
- }
-#endif /* IPECAMERA_BUG_MULTIFRAME_PACKETS */
-
- if (ctx->parse_data) {
- if (ctx->cur_size + bufsize > ctx->full_size) {
- pcilib_error("Unexpected event data, we are expecting at maximum (%zu) bytes, but (%zu) already read", ctx->full_size, ctx->cur_size + bufsize);
- return -PCILIB_ERROR_TOOBIG;
- }
-
- memcpy(ctx->buffer + ctx->buffer_pos * ctx->padded_size + ctx->cur_size, buf, bufsize);
- }
-
- ctx->cur_size += bufsize;
-// printf("%i: %i %i\n", ctx->buffer_pos, ctx->cur_size, bufsize);
-
- if (ctx->cur_size >= ctx->full_size) eof = 1;
-
- if (ctx->event.params.rawdata.callback) {
- res = ctx->event.params.rawdata.callback(ctx->event_id, (pcilib_event_info_t*)(ctx->frame + ctx->buffer_pos), (eof?PCILIB_EVENT_FLAG_EOF:PCILIB_EVENT_FLAGS_DEFAULT), bufsize, buf, ctx->event.params.rawdata.user);
- if (res <= 0) {
- if (res < 0) return res;
- ctx->run_reader = 0;
- }
- }
-
- if (eof) {
- if ((ipecamera_new_frame(ctx))||(!ctx->run_reader)) {
- return PCILIB_STREAMING_STOP;
- }
-
-#ifdef IPECAMERA_BUG_MULTIFRAME_PACKETS
- if (extra_data) {
- return ipecamera_data_callback(user, flags, extra_data, buf + (real_size - extra_data));
- }
-#endif /* IPECAMERA_BUG_MULTIFRAME_PACKETS */
- }
-
- return PCILIB_STREAMING_REQ_FRAGMENT;
-}
-
-void *ipecamera_reader_thread(void *user) {
- int err;
- ipecamera_t *ctx = (ipecamera_t*)user;
-
- while (ctx->run_reader) {
- err = pcilib_stream_dma(ctx->event.pcilib, ctx->rdma, 0, 0, PCILIB_DMA_FLAG_MULTIPACKET, PCILIB_DMA_TIMEOUT, &ipecamera_data_callback, user);
- if (err) {
- if (err == PCILIB_ERROR_TIMEOUT) {
- if (ctx->cur_size >= ctx->cur_raw_size) ipecamera_new_frame(ctx);
-#ifdef IPECAMERA_BUG_INCOMPLETE_PACKETS
- else if (ctx->cur_size > 0) ipecamera_new_frame(ctx);
-#endif /* IPECAMERA_BUG_INCOMPLETE_PACKETS */
- if (pcilib_check_deadline(&ctx->autostop.timestamp, PCILIB_DMA_TIMEOUT)) {
- ctx->run_reader = 0;
- break;
- }
- 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);
-
- return NULL;
-}
diff --git a/ipecamera/reader.h b/ipecamera/reader.h
deleted file mode 100644
index 5d631c0..0000000
--- a/ipecamera/reader.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef _IPECAMERA_READER_H
-#define _IPECAMERA_READER_H
-
-int ipecamera_compute_buffer_size(ipecamera_t *ctx, size_t lines);
-
-void *ipecamera_reader_thread(void *user);
-
-#endif /* _IPECAMERA_READER_H */