From 359180fdc943c46720bf6d523b0048a70c6078f0 Mon Sep 17 00:00:00 2001 From: hadaq Date: Wed, 11 Nov 2009 22:19:13 +0000 Subject: [PATCH] new adcsnoop function added --- trbrich/trbrichcmd.c | 72 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/trbrich/trbrichcmd.c b/trbrich/trbrichcmd.c index dad5946..2d886dc 100644 --- a/trbrich/trbrichcmd.c +++ b/trbrich/trbrichcmd.c @@ -13,7 +13,7 @@ #define TEMP_RESOLUTION 0.0625 -static const char trb_i2c_version[] = "$Revision: 1.4 $"; +static const char trb_i2c_version[] = "$Revision: 1.5 $"; static const uint16_t adcm_uid_register = 0xc000; @@ -24,8 +24,12 @@ void usage(const char *progName) printf(" -h give this help\n"); printf(" -V Version number\n"); printf("\nCommands:\n"); - printf(" uid -> read uids from APV-FrondEnds\n"); - printf(" temp -> read temperatures from APV-FrondEnds\n"); + printf(" uid " + "-> read uids from APV-FrondEnds\n"); + printf(" temp " + "-> read temperatures from APV-FrondEnds\n"); + printf(" adcsnoop " + "-> ADC Snifer Tool\n"); } /* ------ MAIN ---------------------------------------------------------- */ @@ -176,6 +180,68 @@ int main(int argc, char** argv) printf("\n"); } + } else if (strcmp(argv[optind], "adcsnoop") == 0) { + + /*************************************************/ + /* Read Temperatures */ + /*************************************************/ + + uint32_t *sampleBuffer = NULL; + uint32_t *buffer = NULL; + uint16_t trb_address = 0; + unsigned int ch = 0; + unsigned int i = 0; + + if (argc - optind != 2) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + + trb_address = (uint16_t)strtoul(argv[optind + 1], NULL, 0); + + 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)); + uint32_t value = (ch % 8); + uint32_t start = 0; + 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) { + trb_error("Error stop sampling"); + exit(EXIT_FAILURE); + } + + if (trb_register_read_mem(trb_address, reg_address, + 0, 1024, buffer, 1025) == -1) { + trb_error("Error reading sampleBuffer"); + exit(EXIT_FAILURE); + } + + start = ((buffer[i + 1] >> 16) & 0x3ff); + for (i = 0; i < 1024; i++) { + sampleBuffer[ch * 1024 + i] = buffer[start + 1] & 0x0fff; + start = start >= 1023 ? 0 : start + 1; + } + } + + for (i = 0; i < 1024; i++) { + fprintf(stdout, "%4d ", i); + for (ch = 0; ch < 16; ch++) { + fprintf(stdout, " %4d", sampleBuffer[ch * 1024 + i]); + } + fprintf(stdout, "\n"); + } + } else { usage(basename(argv[0])); exit(EXIT_FAILURE); -- 2.43.0