summaryrefslogtreecommitdiffstats
path: root/ipecamera/ipecamera.c
diff options
context:
space:
mode:
Diffstat (limited to 'ipecamera/ipecamera.c')
-rw-r--r--ipecamera/ipecamera.c55
1 files changed, 43 insertions, 12 deletions
diff --git a/ipecamera/ipecamera.c b/ipecamera/ipecamera.c
index b4bbeb8..1681f7c 100644
--- a/ipecamera/ipecamera.c
+++ b/ipecamera/ipecamera.c
@@ -124,7 +124,7 @@ pcilib_context_t *ipecamera_init(pcilib_t *pcilib) {
break;
default:
// pcilib_error("Unsupported version of firmware (%lu)", value);
- ;
+ ctx->firmware = 0;
}
#ifdef IPECAMERA_BUG_POSTPONED_READ
@@ -156,7 +156,9 @@ void ipecamera_free(pcilib_context_t *vctx) {
}
pcilib_dma_context_t *ipecamera_init_dma(pcilib_context_t *vctx) {
-// ipecamera_t *ctx = (ipecamera_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)) {
@@ -166,7 +168,11 @@ pcilib_dma_context_t *ipecamera_init_dma(pcilib_context_t *vctx) {
#ifdef IPECAMERA_DMA_R3
- return model_info->dma_api->init(vctx->pcilib, PCILIB_NWL_MODIFICATION_IPECAMERA, NULL);
+ 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
@@ -205,6 +211,11 @@ int ipecamera_reset(pcilib_context_t *vctx) {
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;
@@ -279,6 +290,11 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev
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");
@@ -286,10 +302,15 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev
}
// Allow readout and clean the FRAME_REQUEST mode if set for some reason
- SET_REG(control_reg, IPECAMERA_IDLE|IPECAMERA_READOUT_FLAG);
+ GET_REG(control_reg, value);
+ SET_REG(control_reg, value|IPECAMERA_READOUT_FLAG);
usleep(IPECAMERA_SLEEP_TIME);
- CHECK_STATUS_REG();
- if (err) return err;
+ 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;
@@ -447,7 +468,7 @@ int ipecamera_start(pcilib_context_t *vctx, pcilib_event_t event_mask, pcilib_ev
// 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;
+ case 2 ... 3: ctx->n_preproc -= 1; break;
default: ctx->n_preproc -= 2; break;
}
@@ -576,7 +597,11 @@ int ipecamera_stop(pcilib_context_t *vctx, pcilib_event_flags_t flags) {
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;
@@ -625,7 +650,12 @@ int ipecamera_trigger(pcilib_context_t *vctx, pcilib_event_t event, size_t trigg
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);
@@ -638,11 +668,12 @@ int ipecamera_trigger(pcilib_context_t *vctx, pcilib_event_t event, size_t trigg
GET_REG(status3_reg, value);
} while (value&0x20000000);
*/
-
- SET_REG(control_reg, IPECAMERA_FRAME_REQUEST|IPECAMERA_READOUT_FLAG);
+
+ 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, IPECAMERA_IDLE|IPECAMERA_READOUT_FLAG);
+ SET_REG(control_reg, value);
pcilib_calc_deadline(&ctx->next_trigger, IPECAMERA_NEXT_FRAME_DELAY);