#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;
printf(" -h give this help\n");
printf(" -V Version number\n");
printf("\nCommands:\n");
- printf(" uid <trb_address> -> read uids from APV-FrondEnds\n");
- printf(" temp <trb_address> -> read temperatures from APV-FrondEnds\n");
+ printf(" uid <trb_address> "
+ "-> read uids from APV-FrondEnds\n");
+ printf(" temp <trb_address> "
+ "-> read temperatures from APV-FrondEnds\n");
+ printf(" adcsnoop <trb_address> "
+ "-> ADC Snifer Tool\n");
}
/* ------ MAIN ---------------------------------------------------------- */
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);