diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-04-13 20:35:32 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2011-04-13 20:35:32 +0200 |
commit | 60d848702add727b1c6c8da3c079439fd129eca1 (patch) | |
tree | 255d4c7652cf080f04b26bb2918872b836d5666b /ipecamera | |
parent | 90863f962229312a5d29453425a5884571a6bccc (diff) | |
download | pcitool-60d848702add727b1c6c8da3c079439fd129eca1.tar.gz pcitool-60d848702add727b1c6c8da3c079439fd129eca1.tar.bz2 pcitool-60d848702add727b1c6c8da3c079439fd129eca1.tar.xz pcitool-60d848702add727b1c6c8da3c079439fd129eca1.zip |
Support simplified mode (slow) of writting CMOSIS sensors: issue 3 writes + delays and when start looking for status
Diffstat (limited to 'ipecamera')
-rw-r--r-- | ipecamera/model.c | 107 |
1 files changed, 84 insertions, 23 deletions
diff --git a/ipecamera/model.c b/ipecamera/model.c index 4e475b1..4830cf2 100644 --- a/ipecamera/model.c +++ b/ipecamera/model.c @@ -1,5 +1,7 @@ +#define _BSD_SOURCE #define _IPECAMERA_MODEL_C #include <sys/time.h> +#include <unistd.h> #include <assert.h> #include "../tools.h" @@ -10,18 +12,27 @@ #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 + 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, uint8_t bits, pcilib_register_value_t *value) { - uint32_t val; + uint32_t val, tmp; char *wr, *rd; struct timeval start, cur; int retries = RETRIES; + +/* +#ifdef IPECAMERA_SIMPLIFIED_READOUT + uint32_t tmp; +#endif +*/ assert(addr < 128); @@ -32,13 +43,31 @@ int ipecamera_read(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcil 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); - - //printf("%i %x %p %p\n", addr, val, wr, rd); - + 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 + gettimeofday(&start, NULL); ipecamera_datacpy(&val, rd, bank); @@ -50,27 +79,32 @@ retry: } if ((val & READ_READY_BIT) == 0) { - pcilib_error("Timeout reading register value"); + 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) { - pcilib_error("Error reading register value"); +/* 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, retrying (try %i of %i)...", RETRIES - retries, RETRIES); + 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"); + pcilib_error("Address verification failed during register read (CMOSIS %lu, status: %lx)", addr, val); return PCILIB_ERROR_VERIFY; } - -// printf("%i\n", val&ipecamera_bit_mask[bits]); - *value = val&ipecamera_bit_mask[bits]; return 0; @@ -81,7 +115,13 @@ int ipecamera_write(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pci char *wr, *rd; struct timeval start, cur; int retries = RETRIES; - + +/* +#ifdef IPECAMERA_SIMPLIFIED_READOUT + uint32_t tmp; +#endif +*/ + assert(addr < 128); assert(value < 256); @@ -92,13 +132,30 @@ int ipecamera_write(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pci 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); - - //printf("%i %x %p %p\n", addr, val, wr, rd); - 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 + gettimeofday(&start, NULL); ipecamera_datacpy(&val, rd, bank); @@ -111,30 +168,34 @@ retry: if ((val & READ_READY_BIT) == 0) { if (--retries > 0) { - pcilib_warning("Timeout occured during register write, retrying (try %i of %i)...", RETRIES - retries, RETRIES); + 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"); + pcilib_error("Timeout writting register value (CMOSIS %lu, value: %lu, status: %lx)", addr, value, val); return PCILIB_ERROR_TIMEOUT; } if (val & READ_ERROR_BIT) { - pcilib_error("Error writting register value"); +/* 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, retrying (try %i of %i)...", RETRIES - retries, RETRIES); + 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"); + pcilib_error("Address verification failed during register write (CMOSIS %lu, value: %lu, status: %lx)", addr, value, val); return PCILIB_ERROR_VERIFY; } if ((val&ipecamera_bit_mask[bits]) != value) { - pcilib_error("Value verification failed during register read (%lu != %lu)", val&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; } |