Rev 52 | Rev 83 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 52 | Rev 81 | ||
|---|---|---|---|
| Line 8... | Line 8... | ||
| 8 | #include "PtsModule_CVI.h" | 
            8 | #include "PtsModule_CVI.h" | 
          
| 9 | #include <utility.h>  | 
            9 | #include <utility.h>  | 
          
| 10 | #include <formatio.h>    | 
            10 | #include <formatio.h>    | 
          
| 11 | static int p1;  | 
            11 | static int p1;  | 
          
| 12 | 12 | ||
| 13 | // ./pts -a 0x1000000 -v 1 -w 2 turn LED ON | 
            13 | // sudo ./pts -a 0x1000000 -v 1 -w 2 turn LED ON | 
          
| 14 | // ./pts -a 0x1000000 -v 1 -w 1 turn LED OFF | 
            14 | // sudo ./pts -a 0x1000000 -v 1 -w 1 turn LED OFF | 
          
| - | 15 | // sudo ./ptsvmusb  -a 0x02501000  -v 2 -i a.bit -b 2 | 
          |
| 15 | #include <stdlib.h> | 
            16 | #include <stdlib.h> | 
          
| 16 | #include <stdio.h> | 
            17 | #include <stdio.h> | 
          
| 17 | 18 | ||
| 18 | #include <ctype.h> | 
            19 | #include <ctype.h> | 
          
| 19 | 20 | ||
| 20 | #include <string.h> | 
            21 | #include <string.h> | 
          
| - | 22 | ||
| - | 23 | #include "vme.h" | 
          |
| - | 24 | ||
| 21 | 25 | ||
| 22 | 26 | ||
| 23 | #ifndef CAEN_V1718  | 
            - | |
| 24 | //typedef unsigned long uint32_t; | 
            - | |
| 25 | #endif | 
            - | |
| 26 | /* | 
            - | |
| 27 | void Delay(double t){ | 
            - | |
| 28 | usleep(t*1e6); | 
            - | |
| 29 | } | 
            - | |
| 30 | */ | 
            - | |
| 31 | 27 | ||
| 32 | 28 | ||
| 33 | 29 | ||
| 34 | int verbose;  | 
            30 | int verbose;  | 
          
| 35 | uint32_t ptaddr=0;  | 
            31 | uint32_t ptaddr=0;  | 
          
| 36 | char str[255];  | 
            32 | char str[255];  | 
          
| 37 | 33 | ||
| 38 | int Pts_write(uint32_t addr, uint32_t data ){  | 
            34 | int Pts_write(uint32_t addr, uint32_t data ){  | 
          
| 39 | int i;  | 
            35 | int i;  | 
          
| 40 | VME_A32D32_W(ptaddr+addr,  | 
            36 | VME_A32D32_W(ptaddr+addr,data);  | 
          
| 41 | return 0;  | 
            37 | return 0;  | 
          
| 42 | } | 
            38 | } | 
          
| 43 | 39 | ||
| 44 | int Pts_Mwrite(uint32_t addr, uint32_t data ){  | 
            40 | int Pts_Mwrite(uint32_t addr, uint32_t data ){  | 
          
| 45 | int i;  | 
            41 | int i;  | 
          
| 46 | 
  | 
            42 | VME_MW(VME_A32, VME_D32, ptaddr+addr,data);  | 
          
| 47 | return 0;  | 
            43 | return 0;  | 
          
| 48 | } | 
            44 | } | 
          
| 49 | 45 | ||
| 50 | int Pts_read(uint32_t addr, uint32_t *data ){  | 
            46 | int Pts_read(uint32_t addr, uint32_t *data ){  | 
          
| 51 | VME_A32D32_R(ptaddr+addr,data);  | 
            47 | VME_A32D32_R(ptaddr+addr,data);  | 
          
| Line 104... | Line 100... | ||
| 104 | return -1;  | 
            100 | return -1;  | 
          
| 105 |     } | 
            101 |     } | 
          
| 106 | (c == 0xff) ? dummyword++ : (dummyword=0);  | 
            102 | (c == 0xff) ? dummyword++ : (dummyword=0);  | 
          
| 107 | } while( dummyword < 4 );  | 
            103 | } while( dummyword < 4 );  | 
          
| 108 | 104 | ||
| 109 | //  const long byte_per_dot = BYTE_PER_DOT; | 
            - | |
| 110 | //  unsigned long nchar = 0; | 
            - | |
| 111 | if( mode == SLAVESERIAL_MODE ) {  | 
            105 | if( mode == SLAVESERIAL_MODE ) {  | 
          
| 112 | if(verbose) SetCtrlVal(p1,P1_RESPONSE,"slave serial mode");  | 
            106 | if(verbose) SetCtrlVal(p1,P1_RESPONSE,"slave serial mode");  | 
          
| 113 | Pts_write( ADR_MODE, mode );  | 
            107 | Pts_write( ADR_MODE, mode );  | 
          
| 114 | Pts_erase( verbose );  | 
            108 | Pts_erase( verbose );  | 
          
| 115 | for( j=0; j<32; j++ ) Pts_write( ADR_CFG, 0x1 );  | 
            109 | for( j=0; j<32; j++ ) Pts_write( ADR_CFG, 0x1 );  | 
          
| Line 123... | Line 117... | ||
| 123 |     } | 
            117 |     } | 
          
| 124 | } else if( mode == SELECTMAP_MODE ) {  | 
            118 | } else if( mode == SELECTMAP_MODE ) {  | 
          
| 125 | if( verbose ) SetCtrlVal(p1,P1_RESPONSE,"select map mode\n");  | 
            119 | if( verbose ) SetCtrlVal(p1,P1_RESPONSE,"select map mode\n");  | 
          
| 126 | Pts_write( ADR_MODE, SELECTMAP_MODE );  | 
            120 | Pts_write( ADR_MODE, SELECTMAP_MODE );  | 
          
| 127 | Pts_erase( verbose );  | 
            121 | Pts_erase( verbose );  | 
          
| - | 122 | VME_MWRST();  | 
          |
| 128 | for( j=0; j<4; j++ )  | 
            123 | for( j=0; j<4; j++ ) Pts_Mwrite( ADR_CFG, 0xff );  | 
          
| - | 124 | VME_MWEXEC();  | 
          |
| - | 125 | ||
| 129 | VME_MWRST();  | 
            126 | VME_MWRST();  | 
          
| 130 | while( (c=getc(fp))!=EOF ){  | 
            127 | while( (c=getc(fp))!=EOF ){  | 
          
| 131 | int cc = 0;  | 
            128 | int cc = 0;  | 
          
| 132 | for(j=0; j<8; j++) cc |= ((c&(1<<j))>>j)<<(7-j);  | 
            129 | for(j=0; j<8; j++) cc |= ((c&(1<<j))>>j)<<(7-j);  | 
          
| 133 | Pts_Mwrite( ADR_CFG, cc );  | 
            130 | Pts_Mwrite( ADR_CFG, cc );  | 
          
| Line 138... | Line 135... | ||
| 138 | sprintf( str,"#");  | 
            135 | sprintf( str,"#");  | 
          
| 139 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
            136 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
          
| 140 |       }   | 
            137 |       }   | 
          
| 141 |     } | 
            138 |     } | 
          
| 142 | VME_MWEXEC();  | 
            139 | VME_MWEXEC();  | 
          
| 143 | } else {  | 
            140 | } else {  | 
          
| 144 | if(verbose) {  | 
            141 | if(verbose) {  | 
          
| 145 | sprintf(str, "\nIllegal mode\n");  | 
            142 | sprintf(str, "\nIllegal mode\n");  | 
          
| 146 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
            143 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
          
| 147 |     }   | 
            144 |     }   | 
          
| 148 | return -1;  | 
            145 | return -1;  | 
          
| 149 |   } | 
            146 |   } | 
          
| 150 | if(verbose) {  | 
            147 | if(verbose) {  | 
          
| 151 | sprintf(str,"\ntotal %ld bits\n", nchar);  | 
            148 | sprintf(str,"\ntotal %ld bits\n", nchar);  | 
          
| 152 | 149 | ||
| 153 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
            150 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
          
| 154 |   }     | 
            151 |   }     | 
          
| Line 177... | Line 174... | ||
| 177 | Pts_write(ADR_CSR0,1);  | 
            174 | Pts_write(ADR_CSR0,1);  | 
          
| 178 | if( verbose ) {  | 
            175 | if( verbose ) {  | 
          
| 179 | sprintf( str, "CSR0(0x%02x) = 0x01\n", ADR_CSR0 );  | 
            176 | sprintf( str, "CSR0(0x%02x) = 0x01\n", ADR_CSR0 );  | 
          
| 180 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
            177 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
          
| 181 |   }   | 
            178 |   }   | 
          
| 182 | return 1;  | 
            179 | return 1;  | 
          
| 183 | } | 
            180 | } | 
          
| 184 | 181 | ||
| 185 | int Pts_write_csr( int verbose, uint32_t value ) {  | 
            182 | int Pts_write_csr( int verbose, uint32_t value ) {  | 
          
| 186 | Pts_write(ADR_CSR0,value);  | 
            183 | Pts_write(ADR_CSR0,value);  | 
          
| 187 | if( verbose ) {  | 
            184 | if( verbose ) {  | 
          
| Line 191... | Line 188... | ||
| 191 | return 1;  | 
            188 | return 1;  | 
          
| 192 | } | 
            189 | } | 
          
| 193 | 190 | ||
| 194 | 191 | ||
| 195 | void help(char *argv){  | 
            192 | void help(char *argv){  | 
          
| 196 | sprintf(str,"Usage: %s -a ptsaddr -v verbose -c .... Pts_check_configure\n", argv);  | 
            193 | sprintf(str,"Usage: %s -a ptsaddr -v verbose -c .... Pts_check_configure\n", argv);  | 
          
| 197 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
            194 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
          
| 198 | sprintf(str,"Usage: %s -a ptsaddr -v verbose -i filename -b mode (2) ... Pts_configure_bit\n", argv);  | 
            195 | sprintf(str,"Usage: %s -a ptsaddr -v verbose -i filename -b mode (2) ... Pts_configure_bit\n", argv);  | 
          
| 199 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
            196 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
          
| 200 | sprintf(str,"Usage: %s -a ptsaddr -v verbose -e .... Pts_erase\n", argv);  | 
            197 | sprintf(str,"Usage: %s -a ptsaddr -v verbose -e .... Pts_erase\n", argv);  | 
          
| 201 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
            198 | SetCtrlVal(p1,P1_RESPONSE,str);  | 
          
| 202 | sprintf(str,"Usage: %s -a ptsaddr -v verbose -x .... Pts_reset\n", argv);  | 
            199 | sprintf(str,"Usage: %s -a ptsaddr -v verbose -x .... Pts_reset\n", argv);  | 
          
| Line 225... | Line 222... | ||
| 225 | if (InitCVIRTE (hInstance, 0, 0) == 0)  | 
            222 | if (InitCVIRTE (hInstance, 0, 0) == 0)  | 
          
| 226 | return -1; /* out of memory */  | 
            223 | return -1; /* out of memory */  | 
          
| 227 | if ((p1 = LoadPanel (0, "PtsModule_CVI.uir", P1)) < 0)  | 
            224 | if ((p1 = LoadPanel (0, "PtsModule_CVI.uir", P1)) < 0)  | 
          
| 228 | return -1;  | 
            225 | return -1;  | 
          
| 229 | DisplayPanel (p1);  | 
            226 | DisplayPanel (p1);  | 
          
| 230 | 
  | 
            227 | |
| 231 | GetCtrlVal(p1,P1_VERBOSE,&verbose);  | 
            228 | GetCtrlVal(p1,P1_VERBOSE,&verbose);  | 
          
| 232 | GetCtrlVal(p1,P1_ADDRESS,saddr);  | 
            229 | GetCtrlVal(p1,P1_ADDRESS,saddr);  | 
          
| 233 | ptaddr = strtoul (saddr,NULL,0);  | 
            230 | ptaddr = strtoul (saddr,NULL,0);  | 
          
| 234 | RunUserInterface ();  | 
            231 | RunUserInterface ();  | 
          
| 235 | DiscardPanel (p1);  | 
            232 | DiscardPanel (p1);  | 
          
| Line 269... | Line 266... | ||
| 269 | switch (event)  | 
            266 | switch (event)  | 
          
| 270 |                 { | 
            267 |                 { | 
          
| 271 | case EVENT_COMMIT:  | 
            268 | case EVENT_COMMIT:  | 
          
| 272 | GetCtrlVal(p1,P1_FIRMWARE,filename);  | 
            269 | GetCtrlVal(p1,P1_FIRMWARE,filename);  | 
          
| 273 | GetCtrlVal(p1,P1_MODE,&mode);  | 
            270 | GetCtrlVal(p1,P1_MODE,&mode);  | 
          
| 274 | 271 | if(VME_CONNECTED() >=0 ) {  | 
          |
| 275 | Pts_configure_bit( filename, mode, verbose );  | 
            272 | Pts_configure_bit( filename, mode, verbose );  | 
          
| - | 273 | } else {  | 
          |
| - | 274 | MessagePopup ("Warning", "Connect VME!!");  | 
          |
| - | 275 |                          }   | 
          |
| 276 | break;  | 
            276 | break;  | 
          
| 277 |                 } | 
            277 |                 } | 
          
| 278 | return 0;  | 
            278 | return 0;  | 
          
| 279 | } | 
            279 | } | 
          
| 280 | 280 | ||
| Line 303... | Line 303... | ||
| 303 | GetCtrlVal(p1,P1_OFFSET,saddr);  | 
            303 | GetCtrlVal(p1,P1_OFFSET,saddr);  | 
          
| 304 | offset = strtoul (saddr,NULL,0);  | 
            304 | offset = strtoul (saddr,NULL,0);  | 
          
| 305 | Pts_read( offset , &value );  | 
            305 | Pts_read( offset , &value );  | 
          
| 306 | if( verbose ) {  | 
            306 | if( verbose ) {  | 
          
| 307 | sprintf(str, "VME Read addr 0x%0x+0x%0x response 0x%0x\n", ptaddr, offset, value );  | 
            307 | sprintf(str, "VME Read addr 0x%0x+0x%0x response 0x%0x\n", ptaddr, offset, value );  | 
          
| 308 | SetCtrlVal (p1, P1_RESPONSE, str);  | 
            308 | SetCtrlVal (p1, P1_RESPONSE, str);  | 
          
| 309 |             } | 
            309 |             } | 
          
| 310 | break;  | 
            310 | break;  | 
          
| 311 |                 } | 
            311 |                 } | 
          
| 312 | return 0;  | 
            312 | return 0;  | 
          
| 313 | } | 
            313 | } | 
          
| Line 466... | Line 466... | ||
| 466 |                 } | 
            466 |                 } | 
          
| 467 |                           } | 
            467 |                           } | 
          
| 468 |                         }   | 
            468 |                         }   | 
          
| 469 | break;  | 
            469 | break;  | 
          
| 470 |                                                   } | 
            470 |                                                   } | 
          
| - | 471 |         } | 
          |
| - | 472 | return 0;  | 
          |
| - | 473 | } | 
          |
| - | 474 | ||
| - | 475 | int CVICALLBACK Connect (int panel, int control, int event,  | 
          |
| - | 476 | void *callbackData, int eventData1, int eventData2)  | 
          |
| - | 477 | { | 
          |
| - | 478 | int interface = 0;  | 
          |
| - | 479 | switch (event)  | 
          |
| - | 480 |         { | 
          |
| - | 481 | ||
| - | 482 | case EVENT_COMMIT:  | 
          |
| - | 483 | GetCtrlVal (p1, P1_VMEINTERFACE, &interface);  | 
          |
| - | 484 | VME_START(interface);  | 
          |
| - | 485 | break;  | 
          |
| - | 486 |         } | 
          |
| - | 487 | return 0;  | 
          |
| - | 488 | } | 
          |
| - | 489 | ||
| - | 490 | int CVICALLBACK Disconnect (int panel, int control, int event,  | 
          |
| - | 491 | void *callbackData, int eventData1, int eventData2)  | 
          |
| - | 492 | { | 
          |
| - | 493 | switch (event)  | 
          |
| - | 494 |         { | 
          |
| - | 495 | case EVENT_COMMIT:  | 
          |
| - | 496 | VME_STOP();  | 
          |
| - | 497 | break;  | 
          |
| 471 |         } | 
            498 |         } | 
          
| 472 | return 0;  | 
            499 | return 0;  | 
          
| 473 | } | 
            500 | } |