]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
updated user-buffer handling
authorhadaq <hadaq>
Tue, 20 Oct 2009 21:27:59 +0000 (21:27 +0000)
committerhadaq <hadaq>
Tue, 20 Oct 2009 21:27:59 +0000 (21:27 +0000)
libtrbnet/trbcmd.c

index 15677cf7a57224c13e2ef67a3f7f24a860f1db3c..46bc0a8022eb289eb46d19e0d40ee27c96b37f44 100644 (file)
 
 static int hexMode = HEXMODE;
 
-static const char trbcmd_version[] = "$Revision: 2.28 $";
+static const char trbcmd_version[] = "$Revision: 2.29 $";
+
+/* ---- User Buffers --------------------------------------------------- */
+
+#define NUM_ENDPOINTS 512   
+#define READ_MEM_BUFFER_SIZE (NUM_ENDPOINTS * (32768 + 2))
+#define READ_IPU_BUFFER_SIZE (10 * 1024)   
 
 /* ------ MAIN ---------------------------------------------------------- */
 
@@ -64,7 +70,6 @@ void usage(const char *progName)
 
 #define CMD_SIZE 256
 #define CMD_MAX_NUM 10
-#define READ_MEM_SIZE 1048576
 
 int main(int argc, char ** argv)
 {
@@ -257,7 +262,7 @@ int main(int argc, char ** argv)
         /*******************************************/
 
         int status = 0;
-        uint32_t data[256];
+        uint32_t *data = NULL;
         int i;
     
         if (cmdLen != 3) {
@@ -279,8 +284,12 @@ int main(int argc, char ** argv)
                   "reg_address: 0x%04x\n",
                   trb_address, reg_address);
         }
-    
-        status = trb_register_read(trb_address, reg_address, data, 256);
+        
+        data = (uint32_t*) malloc(sizeof(uint32_t) * NUM_ENDPOINTS * 2);
+        if (data == NULL) abort();
+                
+        status = trb_register_read(trb_address, reg_address, 
+                                   data, NUM_ENDPOINTS * 2);
         if (status == -1) {
           if (scriptFile != NULL) {
             fprintf(stderr, "Line #%d: ", lineCtr);
@@ -345,11 +354,12 @@ int main(int argc, char ** argv)
                   trb_address, reg_address, size, option);
         }
     
-        if ((data = malloc(sizeof(uint32_t) * READ_MEM_SIZE)) == NULL) abort();
+        data = (uint32_t*)malloc(sizeof(uint32_t) * READ_MEM_BUFFER_SIZE);
+        if (data == NULL) abort();
     
         status = 
           trb_register_read_mem(trb_address, reg_address, option, 
-                                size, data, READ_MEM_SIZE);
+                                size, data, READ_MEM_BUFFER_SIZE);
         if (status == -1) {
           if (scriptFile != NULL) {
             fprintf(stderr, "Line #%d: ", lineCtr);
@@ -425,13 +435,14 @@ int main(int argc, char ** argv)
           }
         }
     
-        if ((data = malloc(sizeof(uint32_t) * dataSize)) == NULL) abort();
+        data = (uint32_t*)malloc(sizeof(uint32_t) * dataSize);
+        if (data == NULL) abort();
+        
         while (getline(&line, &len, file) != -1) {
           if (size >= dataSize) {
             dataSize += 64;
-            if ((data = realloc(data, sizeof(uint32_t) * dataSize)) == NULL) {
-              abort();
-            }
+            data = (uint32_t*)realloc(data, sizeof(uint32_t) * dataSize);
+            if (data == NULL)  abort();
           }
           data[size++] = strtoul(line, NULL, hexMode == 1 ? 16 : 0);
         }
@@ -477,7 +488,7 @@ int main(int argc, char ** argv)
         /* ReadUId                                 */
         /*******************************************/
     
-        uint32_t uidBuffer[512];
+        uint32_t *uidBuffer = NULL;
         int status;
         int i;
         
@@ -498,8 +509,11 @@ int main(int argc, char ** argv)
                   "Command: READ_UID: trb_address: 0x%04x\n",
                   trb_address);
         }
-    
-        status = trb_read_uid(trb_address, uidBuffer, 128);
+        
+        uidBuffer = (uint32_t*)malloc(sizeof(uint32_t) * NUM_ENDPOINTS * 4);
+        if (uidBuffer == NULL) abort();
+        
+        status = trb_read_uid(trb_address, uidBuffer, NUM_ENDPOINTS * 4);
         if (status == -1) {
           if (scriptFile != NULL) {
             fprintf(stderr, "Line #%d: ", lineCtr);
@@ -784,7 +798,7 @@ int main(int argc, char ** argv)
         /* IPU channel readout                     */
         /*******************************************/
     
-        uint32_t buffer[4096];
+        uint32_t *buffer = NULL;
         uint8_t type = 0;
         uint8_t random = 0;
         uint8_t info = 0;
@@ -816,7 +830,12 @@ int main(int argc, char ** argv)
                   "number: 0x%04x\n",
                   type, random, info, number);
         }
-        status = trb_ipu_data_read(type, info, random, number, buffer, 4096);
+        
+        buffer = (uint32_t*)malloc(sizeof(uint32_t) * READ_IPU_BUFFER_SIZE);
+        if (buffer == NULL) abort();
+
+        status = trb_ipu_data_read(type, info, random, number,
+                                   buffer, READ_IPU_BUFFER_SIZE);
         if (status == -1) {
           if (scriptFile != NULL) {
             fprintf(stderr, "Line #%d: ", lineCtr);