diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-05-02 00:36:09 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-05-02 00:36:09 +0200 |
commit | 6d3c61711bfe6524272bbde591e3494e0346a7da (patch) | |
tree | 086032b8036532898f9a9d4822f9f4b0a31f2b6f /cmosis.c | |
parent | 993fb64bcbf75d2c447b718dff862c2124fbb062 (diff) | |
download | ipecamera-6d3c61711bfe6524272bbde591e3494e0346a7da.tar.gz ipecamera-6d3c61711bfe6524272bbde591e3494e0346a7da.tar.bz2 ipecamera-6d3c61711bfe6524272bbde591e3494e0346a7da.tar.xz ipecamera-6d3c61711bfe6524272bbde591e3494e0346a7da.zip |
Cleanup
Diffstat (limited to 'cmosis.c')
-rw-r--r-- | cmosis.c | 75 |
1 files changed, 29 insertions, 46 deletions
@@ -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; } |