#include <trbnet.h>
#include <trberror.h>
-#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;
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:
} 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);
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));
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++) {
}
fprintf(stdout, "\n");
}
-
+#endif
+
+ for (ch = 0; ch < 16; ch++) {
+ free(sampleBuffer[ch]);
+ sampleBuffer[ch] = NULL;
+ }
+
} else {
usage(basename(argv[0]));
exit(EXIT_FAILURE);