From d786a6203e47c36cecaa1b4046939e01262d1a02 Mon Sep 17 00:00:00 2001 From: hadaq Date: Fri, 23 Apr 2010 18:45:55 +0000 Subject: [PATCH] increase buffer_size --- trbrich/trbrichcmd.c | 65 +++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/trbrich/trbrichcmd.c b/trbrich/trbrichcmd.c index 2d886dc..ffdb1c5 100644 --- a/trbrich/trbrichcmd.c +++ b/trbrich/trbrichcmd.c @@ -9,11 +9,11 @@ #include #include -#define BUFFER_SIZE (64 * 5 * 6) +#define BUFFER_SIZE (10 * (6 * 16 * 5 * 2)) #define TEMP_RESOLUTION 0.0625 -static const char trb_i2c_version[] = "$Revision: 1.5 $"; +static const char trbrichcmd_version[] = "$Revision: 1.6 $"; static const uint16_t adcm_uid_register = 0xc000; @@ -54,7 +54,7 @@ int main(int argc, char** argv) break; case 'V': printf("%s %s, using libtrbnet %s\n", - basename(argv[0]), trb_i2c_version, trbnet_version); + basename(argv[0]), trbrichcmd_version, trbnet_version); exit(EXIT_SUCCESS); break; default: @@ -183,15 +183,16 @@ int main(int argc, char** argv) } else if (strcmp(argv[optind], "adcsnoop") == 0) { /*************************************************/ - /* Read Temperatures */ + /* Read ADC-Samples */ /*************************************************/ - uint32_t *sampleBuffer = NULL; + uint32_t *sampleBuffer[16]; uint32_t *buffer = NULL; uint16_t trb_address = 0; unsigned int ch = 0; unsigned int i = 0; - + int status = 0; + if (argc - optind != 2) { usage(argv[0]); exit(EXIT_FAILURE); @@ -202,10 +203,6 @@ int main(int argc, char** argv) if ((buffer = (uint32_t*)malloc(sizeof(uint32_t) * 1025)) == NULL) { abort(); } - if ((sampleBuffer = - (uint32_t*)malloc(sizeof(uint32_t) * 1024 * 16)) == NULL) { - abort(); - } for (ch = 0; ch < 16; ch++) { uint16_t reg_address = 0xf000 + (0x800 * (ch / 8)); @@ -214,26 +211,50 @@ int main(int argc, char** argv) if (trb_register_write(trb_address, reg_address, 0x4000 | value) == -1) { trb_error("Error start sampling"); exit(EXIT_FAILURE); - } - usleep(100000); - if (trb_register_write(trb_address, adcm_uid_register, value) == -1) { + } + usleep(1000000); + if (trb_register_write(trb_address, reg_address, value) == -1) { trb_error("Error stop sampling"); exit(EXIT_FAILURE); } - if (trb_register_read_mem(trb_address, reg_address, - 0, 1024, buffer, 1025) == -1) { + status = trb_register_read_mem(trb_address, reg_address, + 0, 1024, buffer, 1025); + if (status == -1) { trb_error("Error reading sampleBuffer"); exit(EXIT_FAILURE); } - - start = ((buffer[i + 1] >> 16) & 0x3ff); + if (status != 1025) { + fprintf(stderr, "Error reading data from channel %d\n", ch); + exit(EXIT_FAILURE); + } + + if ((sampleBuffer[ch] = + (uint32_t*)malloc(sizeof(uint32_t) * 1024)) == NULL) { + abort(); + } + start = ((buffer[1] >> 16) & 0x3ff) + 1; + fprintf(stderr, "ch: %2d start=%4d 0x%08x\n", ch, start, buffer[1]); + if (start > 1024) { + fprintf(stderr, "Invalid start: %d\n", start); + exit(EXIT_FAILURE); + } + if (start == 1024) start = 0; for (i = 0; i < 1024; i++) { - sampleBuffer[ch * 1024 + i] = buffer[start + 1] & 0x0fff; + sampleBuffer[ch][i] = buffer[start + 1] & 0x3fff; start = start >= 1023 ? 0 : start + 1; } } +#if 1 + for (ch = 0; ch < 16; ch++) { + fprintf(stdout, "# channel: %2d\n", ch); + for (i = 0; i < 1024; i++) { + fprintf(stdout, "%4d %4d\n", i, sampleBuffer[ch][i]); + } + fprintf(stdout, "\n\n"); + } +#else for (i = 0; i < 1024; i++) { fprintf(stdout, "%4d ", i); for (ch = 0; ch < 16; ch++) { @@ -241,7 +262,13 @@ int main(int argc, char** argv) } fprintf(stdout, "\n"); } - +#endif + + for (ch = 0; ch < 16; ch++) { + free(sampleBuffer[ch]); + sampleBuffer[ch] = NULL; + } + } else { usage(basename(argv[0])); exit(EXIT_FAILURE); -- 2.43.0