Subversion Repositories f9daq

Rev

Rev 15 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15 Rev 81
Line 15... Line 15...
15
 
15
 
16
 
16
 
17
uint32_t ptaddr=0;
17
uint32_t ptaddr=0;
18
 
18
 
19
int Pts_write(uint32_t addr, uint32_t data ){
19
int Pts_write(uint32_t addr, uint32_t data ){
-
 
20
fprintf(stderr, "Pts_write ADDR 0x%04x  0x%04x ",addr,ptaddr+addr );
-
 
21
int nb=VME_A32D32_W(ptaddr+addr,&data);
-
 
22
fprintf(stderr, " nb=%d\n",nb);
-
 
23
return nb;
-
 
24
}
-
 
25
 
-
 
26
int Pts_Mwrite(uint32_t addr, uint32_t data ){
20
VME_A32D32_W(ptaddr+addr,&data);
27
VME_A32D32_MW(ptaddr+addr,&data);
21
return 0;
28
return 1;
22
}
29
}
23
 
30
 
24
int Pts_read(uint32_t addr, uint32_t *data ){
31
int Pts_read(uint32_t addr, uint32_t *data ){
-
 
32
fprintf(stderr, "Pts_read ADDR  0x%04x  0x%04x  ",addr,ptaddr+addr );
25
VME_A32D32_R(ptaddr+addr,data);
33
int nb=VME_A32D32_R(ptaddr+addr,data);
-
 
34
fprintf(stderr, " nb=%d\n",nb);
26
return 0;
35
return nb;
27
}
36
}
28
 
37
 
29
 
38
 
30
int Pts_erase( int verbose ) {
39
int Pts_erase( int verbose ) {
31
  uint32_t dum;
40
  uint32_t dum = 0;
32
  Pts_write( ADR_CSR1, 0 );
41
  Pts_write( ADR_CSR1, 0 );
33
  Delay(0.1);
42
  Delay(0.1);
34
  Pts_read( ADR_CSR1, &dum);
43
  Pts_read( ADR_CSR1, &dum);
35
  if( verbose ) printf( "CSR1(0x%02x) = 0x%04x\n", ADR_CSR1,
44
  if( verbose ) fprintf( stderr, "CSR1(0x%02x) = 0x%04x <<<<\n", ADR_CSR1,
36
                        dum & 0xffff );
45
                        dum & 0xffff );
37
  Pts_write( ADR_CSR1, CSR1_PROGRAM_ );
46
  Pts_write( ADR_CSR1, CSR1_PROGRAM_ );
38
  Delay(0.1);
47
  Delay(0.1);
39
  Pts_read( ADR_CSR1, &dum);
48
  Pts_read( ADR_CSR1, &dum);
40
  if( verbose ) printf( "CSR1(0x%02x) = 0x%04x\n", ADR_CSR1,
49
  if( verbose ) fprintf(stderr, "CSR1(0x%02x) = 0x%04x >>>>>\n", ADR_CSR1,
41
                        dum & 0xffff );
50
                        dum & 0xffff );
42
  return 1;
51
  return 1;
43
}
52
}
44
/*
53
/*
45
int Pts_configure( const char *filename, int mode, int verbose ) {
54
int Pts_configure( const char *filename, int mode, int verbose ) {
Line 86... Line 95...
86
      else if( isspace(c) ) continue;
95
      else if( isspace(c) ) continue;
87
      else {
96
      else {
88
        fprintf( stderr, "(%ld) illegal character : %c\n", nchar, c );
97
        fprintf( stderr, "(%ld) illegal character : %c\n", nchar, c );
89
        fclose(fp);
98
        fclose(fp);
90
        return -1;
99
        return -1;
91
      }
100
      }
92
    }
101
    }
93
  } else if(mode == SELECTMAP_MODE) {
102
  } else if(mode == SELECTMAP_MODE) {
94
    if(verbose) fprintf(stderr, "\nselectmap mode (rbt file) not supported\n");
103
    if(verbose) fprintf(stderr, "\nselectmap mode (rbt file) not supported\n");
95
    return -1;
104
    return -1;
96
  } else {
105
  } else {
97
    if(verbose) fprintf(stderr, "\nIllegal mode\n");
106
    if(verbose) fprintf(stderr, "\nIllegal mode\n");
Line 110... Line 119...
110
  unsigned long nchar = 0;
119
  unsigned long nchar = 0;
111
 
120
 
112
  if( ( fp = fopen( filename, "rb" ) ) == NULL ) {
121
  if( ( fp = fopen( filename, "rb" ) ) == NULL ) {
113
    if( verbose ) fprintf( stderr, "cannot open \"%s\"\n", filename );
122
    if( verbose ) fprintf( stderr, "cannot open \"%s\"\n", filename );
114
    return -1;
123
    return -1;
115
  }
124
  }
116
  if(verbose) printf( "file \"%s\" opened.\n", filename );
125
  if(verbose) printf( "Verbose= %d File \"%s\" opened.\n", verbose ,filename );
117
 
126
 
118
  /* ------------------------------------------------------------ *\
127
  /* ------------------------------------------------------------ *\
119
    The data for the configuration start from 0xffff_ffff_aa99_aa66
128
    The data for the configuration start from 0xffff_ffff_aa99_aa66
120
    ( cf. xapp138; we don't know the definition of the BIT file )
129
    ( cf. xapp138; we don't know the definition of the BIT file )
121
  \* ------------------------------------------------------------ */
130
  \* ------------------------------------------------------------ */
Line 125... Line 134...
125
      if(verbose) fprintf(stderr, "EOF detected. Exit.\n");
134
      if(verbose) fprintf(stderr, "EOF detected. Exit.\n");
126
      return -1;
135
      return -1;
127
    }
136
    }
128
    (c == 0xff) ? dummyword++ : (dummyword=0);
137
    (c == 0xff) ? dummyword++ : (dummyword=0);
129
  } while( dummyword < 4 );
138
  } while( dummyword < 4 );
130
 
139
 
131
//  const long byte_per_dot = BYTE_PER_DOT;
140
//  const long byte_per_dot = BYTE_PER_DOT;
132
//  unsigned long nchar = 0;
141
//  unsigned long nchar = 0;
-
 
142
 
133
  if( mode == SLAVESERIAL_MODE ) {
143
  if( mode == SLAVESERIAL_MODE ) {
134
    if(verbose) puts("slave serial mode");
144
    if(verbose)  fprintf(stderr, "slave serial mode");
135
    Pts_write( ADR_MODE, mode );
145
    Pts_write( ADR_MODE, mode );
136
    Pts_erase( verbose );
146
    Pts_erase( verbose );
137
    for( j=0; j<32; j++ ) Pts_write( ADR_CFG, 0x1 );
147
    for( j=0; j<32; j++ ) Pts_write( ADR_CFG, 0x1 );
-
 
148
    while(!feof(fp))
-
 
149
     {
-
 
150
      int nb = fread(&c,1,1,fp);
-
 
151
      if (nb<=0) continue;
138
    while( (c=getc(fp))!=EOF ){
152
    //while( (c=getc(fp))!=EOF ){
139
      for( j=0; j<8; j++ ) Pts_write( ADR_CFG, (c>>(7-j))&0x1 );
153
      for( j=0; j<8; j++ ) Pts_write( ADR_CFG, (c>>(7-j))&0x1 );
140
      nchar++;
154
      nchar++;
141
      if( verbose && nchar%byte_per_dot==0 ) putchar('.');
155
      if( verbose && nchar%byte_per_dot==0 ) putchar('.');
142
    }
156
    }
143
  } else if( mode == SELECTMAP_MODE ) {
157
  } else if( mode == SELECTMAP_MODE ) {
144
    if( verbose ) puts("select map mode");
158
    if( verbose )  fprintf(stderr, "select map mode ....");
-
 
159
     
145
    Pts_write( ADR_MODE, SELECTMAP_MODE );
160
    Pts_write( ADR_MODE, SELECTMAP_MODE );
146
    Pts_erase( verbose );
161
    Pts_erase( verbose );
-
 
162
 
-
 
163
    fprintf(stderr, "-------------\n");
-
 
164
 
-
 
165
    //if( verbose )  fprintf(stderr, "program ....\n");
-
 
166
     
-
 
167
    for( j=0; j<4; j++ ) {
-
 
168
      fprintf(stderr, "%d ------------\n", j);
147
    for( j=0; j<4; j++ ) Pts_write( ADR_CFG, 0xff );
169
      Pts_write( ADR_CFG, 0xff );
-
 
170
    }
-
 
171
    fprintf(stderr, "at line %d -------------\n", __LINE__);
-
 
172
    VME_MWRST();
-
 
173
    while(!feof(fp))
-
 
174
     {
-
 
175
      int nb = fread(&c,1,1,fp);
-
 
176
      if (nb<=0) continue;
148
    while( (c=getc(fp))!=EOF ){
177
   // while ( (c=getc(fp))!=EOF ){
-
 
178
      if (feof(fp)) {
-
 
179
        if(verbose) fprintf(stderr, "feof detected. Exit.\n");
-
 
180
        return -1;
-
 
181
      }
149
      int cc = 0;
182
      int cc = 0;
150
      for(j=0; j<8; j++) cc |= ((c&(1<<j))>>j)<<(7-j);
183
      for(j=0; j<8; j++) cc |= ((c&(1<<j))>>j)<<(7-j);
-
 
184
      //fprintf(stderr, "s");
151
      Pts_write( ADR_CFG, cc );
185
      Pts_Mwrite( ADR_CFG, cc );
152
      nchar++;
186
      nchar++;
153
      if( verbose && nchar%byte_per_dot==0 ) putchar('.');
187
      if( verbose && nchar%byte_per_dot==0 ) {
-
 
188
        fprintf(stderr, "#");
-
 
189
        VME_MWEXEC();
-
 
190
        VME_MWRST();
-
 
191
        fprintf(stderr, ".");
-
 
192
      }
154
    }
193
    }
155
  } else {
194
  } else {
156
    if(verbose) fprintf(stderr, "\nIllegal mode\n");
195
    if(verbose) fprintf(stderr, "\nIllegal mode\n");
157
    return -1;
196
    return -1;
158
  }
197
  }
159
  if(verbose) printf("\ntotal %ld bits\n", nchar);
198
  if(verbose) fprintf(stderr, "\ntotal %ld bits\n", nchar);
160
  fclose(fp);
199
  if (fp) fclose(fp);
161
  return Pts_check_configure( verbose );
200
  return Pts_check_configure( verbose );
162
}
201
}
163
 
202
 
164
int Pts_check_configure( int verbose ) {
203
int Pts_check_configure( int verbose ) {
165
  uint32_t csr1_value;
204
  uint32_t csr1_value;
166
  Pts_read(ADR_CSR1,&csr1_value);
205
  Pts_read(ADR_CSR1,&csr1_value);
167
  if(verbose) printf("CSR1(0x%02x)=0x%04x\n",ADR_CSR1,csr1_value&0xffff);
206
  if(verbose) printf("CSR1(0x%02x)=0x%04x\n",ADR_CSR1,csr1_value&0xffff);
168
  if(csr1_value&CSR1_DONE) {
207
  if(csr1_value&CSR1_DONE) {
169
    if(verbose) puts("configure complete.");
208
    if(verbose)  fprintf(stderr, "configure complete.\n");
170
    return 1;
209
    return 1;
171
  } else {
210
  } else {
172
    if(verbose) puts("configure not complete.");
211
    if(verbose)  fprintf(stderr, "configure not complete.\n");
173
    return -1;
212
    return -1;
174
  }
213
  }
175
}
214
}
176
 
215
 
177
int Pts_reset( int verbose ) {
216
int Pts_reset( int verbose ) {