Subversion Repositories f9daq

Rev

Rev 52 | Rev 83 | Go to most recent revision | Show entire file | Regard 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,&data);
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
VME_A32D32_MW(ptaddr+addr,&data);
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 81... Line 77...
81
  unsigned long nchar = 0;
77
  unsigned long nchar = 0;
82
 
78
 
83
  if( ( fp = fopen( filename, "rb" ) ) == NULL ) {
79
  if( ( fp = fopen( filename, "rb" ) ) == NULL ) {
84
    if( verbose ) {
80
    if( verbose ) {
85
      sprintf( str, "cannot open \"%s\"\n", filename );
81
      sprintf( str, "cannot open \"%s\"\n", filename );
86
    SetCtrlVal (p1, P1_RESPONSE, str);
82
    SetCtrlVal (p1, P1_RESPONSE, str);
87
        }
83
        }
88
    return -1;
84
    return -1;
89
  }
85
  }
90
  if(verbose) sprintf( str, "file \"%s\" opened.\n", filename );
86
  if(verbose) sprintf( str, "file \"%s\" opened.\n", filename );
91
 
87
 
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 );
116
    while( (c=getc(fp))!=EOF ){
110
    while( (c=getc(fp))!=EOF ){
117
      for( j=0; j<8; j++ ) Pts_write( ADR_CFG, (c>>(7-j))&0x1 );
111
      for( j=0; j<8; j++ ) Pts_write( ADR_CFG, (c>>(7-j))&0x1 );
118
      nchar++;
112
      nchar++;
119
      if( verbose && nchar%byte_per_dot==0 ) {
113
      if( verbose && nchar%byte_per_dot==0 ) {
120
        sprintf( str,"#");
114
        sprintf( str,"#");
121
        SetCtrlVal(p1,P1_RESPONSE,str);
115
        SetCtrlVal(p1,P1_RESPONSE,str);
122
      }  
116
      }  
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++ ) Pts_write( ADR_CFG, 0xff );
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 157... Line 154...
157
}
154
}
158
 
155
 
159
int Pts_check_configure( int verbose ) {
156
int Pts_check_configure( int verbose ) {
160
  uint32_t csr1_value;
157
  uint32_t csr1_value;
161
  Pts_read(ADR_CSR1,&csr1_value);
158
  Pts_read(ADR_CSR1,&csr1_value);
162
  if(verbose) {
159
  if(verbose) {
163
      sprintf( str,"CSR1(0x%02x)=0x%04x\n",ADR_CSR1,csr1_value&0xffff);
160
      sprintf( str,"CSR1(0x%02x)=0x%04x\n",ADR_CSR1,csr1_value&0xffff);
164
   
161
   
165
      SetCtrlVal(p1,P1_RESPONSE,str);
162
      SetCtrlVal(p1,P1_RESPONSE,str);
166
  }    
163
  }    
167
  if(csr1_value&CSR1_DONE) {
164
  if(csr1_value&CSR1_DONE) {
168
    if(verbose) SetCtrlVal(p1,P1_RESPONSE, "configure complete.\n");
165
    if(verbose) SetCtrlVal(p1,P1_RESPONSE, "configure complete.\n");
169
    return 1;
166
    return 1;
170
  } else {
167
  } else {
171
    if(verbose)  SetCtrlVal(p1,P1_RESPONSE,"configure not complete.");
168
    if(verbose)  SetCtrlVal(p1,P1_RESPONSE,"configure not complete.");
172
    return -1;
169
    return -1;
173
  }
170
  }
174
}
171
}
175
 
172
 
176
int Pts_reset( int verbose ) {
173
int Pts_reset( int verbose ) {
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 ) {
188
    sprintf( str,"Pts_write_csr 0x%08x\n", value  );
185
    sprintf( str,"Pts_write_csr 0x%08x\n", value  );
189
    SetCtrlVal(p1,P1_RESPONSE,str);
186
    SetCtrlVal(p1,P1_RESPONSE,str);
190
  }  
187
  }  
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);
203
 SetCtrlVal(p1,P1_RESPONSE,str);
200
 SetCtrlVal(p1,P1_RESPONSE,str);
204
 sprintf(str,"Usage: %s -a ptsaddr -v verbose -c  .... Pts_check_configure\n", argv);
201
 sprintf(str,"Usage: %s -a ptsaddr -v verbose -c  .... Pts_check_configure\n", argv);
205
 SetCtrlVal(p1,P1_RESPONSE,str);
202
 SetCtrlVal(p1,P1_RESPONSE,str);
206
 sprintf(str,"Usage: %s -a ptsaddr -v verbose -r  .... vme read\n", argv);
203
 sprintf(str,"Usage: %s -a ptsaddr -v verbose -r  .... vme read\n", argv);
207
 SetCtrlVal(p1,P1_RESPONSE,str);
204
 SetCtrlVal(p1,P1_RESPONSE,str);
208
 sprintf(str,"Usage: %s -a ptsaddr -v verbose -w value .... vme write\n", argv);
205
 sprintf(str,"Usage: %s -a ptsaddr -v verbose -w value .... vme write\n", argv);
209
 SetCtrlVal(p1,P1_RESPONSE,str);
206
 SetCtrlVal(p1,P1_RESPONSE,str);
210
 sprintf(str,"Usage: %s -a ptsaddr -v verbose -s value .... Pts_write_csr\n", argv);
207
 sprintf(str,"Usage: %s -a ptsaddr -v verbose -s value .... Pts_write_csr\n", argv);
Line 212... Line 209...
212
 sprintf(str,"Example: %s  --address  0x1000000 --verbose 1 --erase\n", argv);
209
 sprintf(str,"Example: %s  --address  0x1000000 --verbose 1 --erase\n", argv);
213
 SetCtrlVal(p1,P1_RESPONSE,str);
210
 SetCtrlVal(p1,P1_RESPONSE,str);
214
 sprintf(str,"Example: %s --address  0x1000000 --verbose 1 --input pts_scaler.bit --load-bit 2\n", argv);
211
 sprintf(str,"Example: %s --address  0x1000000 --verbose 1 --input pts_scaler.bit --load-bit 2\n", argv);
215
 SetCtrlVal(p1,P1_RESPONSE,str);
212
 SetCtrlVal(p1,P1_RESPONSE,str);
216
 sprintf(str,"Example: %s --address  0x1000004 --write-csr 0x7600\n", argv);SetCtrlVal(p1,P1_RESPONSE,str);
213
 sprintf(str,"Example: %s --address  0x1000004 --write-csr 0x7600\n", argv);SetCtrlVal(p1,P1_RESPONSE,str);
217
}
214
}
218
 
215
 
219
 
216
 
220
 
217
 
221
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
218
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
222
                       LPSTR lpszCmdLine, int nCmdShow)
219
                       LPSTR lpszCmdLine, int nCmdShow)
223
{
220
{
224
    char saddr[255];
221
    char saddr[255];
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
        VME_START(NULL);
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 248... Line 245...
248
                }
245
                }
249
        return 0;
246
        return 0;
250
}
247
}
251
 
248
 
252
int CVICALLBACK Erase (int panel, int control, int event,
249
int CVICALLBACK Erase (int panel, int control, int event,
253
                void *callbackData, int eventData1, int eventData2)
250
                void *callbackData, int eventData1, int eventData2)
254
{
251
{
255
        switch (event)
252
        switch (event)
256
                {
253
                {
257
                case EVENT_COMMIT:
254
                case EVENT_COMMIT:
258
                         Pts_erase(verbose);  
255
                         Pts_erase(verbose);  
259
                        break;
256
                        break;
260
                }
257
                }
261
        return 0;
258
        return 0;
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 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
}