From: hadaq Date: Wed, 21 Jul 2010 00:28:05 +0000 (+0000) Subject: added sync_apv X-Git-Tag: v6.0~238 X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=49f2ee9786f31bdfe9cf9ff03f01e5cbf5adf0ce;p=trbnettools.git added sync_apv --- diff --git a/trbrich/trbrichcmd.c b/trbrich/trbrichcmd.c index d99b866..10fea91 100644 --- a/trbrich/trbrichcmd.c +++ b/trbrich/trbrichcmd.c @@ -13,7 +13,9 @@ #define TEMP_RESOLUTION 0.0625 -static const char trbrichcmd_version[] = "$Revision: 1.9 $"; +static const uint16_t BroadCastRich = 0xfffb; + +static const char trbrichcmd_version[] = "$Revision: 1.10 $"; static const uint16_t adcm_uid_register = 0xc000; @@ -25,13 +27,16 @@ void usage(const char *progName) printf(" -V Version number\n"); printf("\nCommands:\n"); printf(" uid " - "-> read uids from APV-FrondEnds\n" - " (default-Address:0xfffb)\n"); + "-> read uids from APVS (default-Addr: 0x%04x)\n", + BroadCastRich); printf(" temp " - "-> read temperatures from APV-FrondEnds\n" - " (default-Address:0xfffb)\n"); - printf(" adcsnoop " + "-> read temperatures from APVS (default-Addr: 0x%04x)\n", + BroadCastRich); + printf(" adcsnoop trb_address " "-> ADC Sniffer Tool\n"); + printf(" sync_apv " + "-> Synchronize APVS (default-Addr: 0x%04x)\n", + BroadCastRich); } /* ------ MAIN ---------------------------------------------------------- */ @@ -77,7 +82,7 @@ int main(int argc, char** argv) /*************************************************/ /* Read UIDs */ /*************************************************/ - + uint32_t *buffer = NULL; uint32_t *tmp = NULL; uint32_t *end = NULL; @@ -117,10 +122,14 @@ int main(int argc, char** argv) tmp++; for (i = 0, ctr = 0; (i < len) && (tmp < end); i += 4, tmp += 4, ctr++) { if ((tmp[2] & 0x8000) > 0 ) { + + printf("%02d 0x%08x%08x\n", ctr, tmp[1], tmp[0]); } else { printf("%02d ------------------\n", ctr); } + + } printf("\n"); } @@ -135,7 +144,7 @@ int main(int argc, char** argv) uint32_t *tmp = NULL; uint32_t *end = NULL; int status = 0; - uint16_t trb_address = 0xfffb; + uint16_t trb_address = BroadCastRich; if (argc - optind == 2) { trb_address = (uint16_t)strtoul(argv[optind + 1], NULL, 0); @@ -270,7 +279,65 @@ int main(int argc, char** argv) free(sampleBuffer[ch]); sampleBuffer[ch] = NULL; } + + } else if (strcmp(argv[optind], "sync_apv") == 0) { + /*************************************************/ + /* Synchronize APVS */ + /*************************************************/ + uint32_t *buffer = NULL; + uint32_t *tmp = NULL; + uint32_t *end = NULL; + + uint16_t trb_address = BroadCastRich; + int status = 0; + unsigned int timeOut = 0; + + if (argc - optind == 2) { + trb_address = (uint16_t)strtoul(argv[optind + 1], NULL, 0); + } else if (argc - optind > 2) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + if ((buffer = (uint32_t*)malloc(sizeof(uint32_t) * BUFFER_SIZE)) == NULL) { + abort(); + } + + while (timeOut < 3) { + if (trb_register_write(trb_address, 0x20, 0x80000000) == -1) { + trb_error("Error sync_apv failed sync"); + exit(EXIT_FAILURE); + } + + status = trb_register_read_mem(trb_address, 0xb000, 0, 15, + buffer, BUFFER_SIZE); + if (status == -1) { + trb_error("Error sync_apv failed read status"); + exit(EXIT_FAILURE); + } + + tmp = buffer; + end = buffer + status; + while (tmp < end) { + unsigned int len = *tmp >> 16; + uint16_t endPoint = *tmp & 0xffff; + unsigned int i; + unsigned int ctr; + tmp++; + for (i = 0, ctr = 0; (i < len) && (tmp < end); i++, tmp ++, ctr++) { + if (!(((*tmp >> 29) == 0x8) || + ((*tmp >> 29) == 0x1))) { + fprintf(stderr, + "TimeOut: %d Sync Failed on EndPoint: " + "0x%04x APV#: %02d\n", + timeOut, endPoint, ((*tmp >> 16) &0xf)); + } + } + } + timeOut++; + } + free(buffer); + } else { usage(basename(argv[0])); exit(EXIT_FAILURE);