Newer
Older
// File for Belle2 slow control access with PCIe40
#include "pcie40_b2slc.h"
#include <unistd.h>
#include "pcie40_ecs.h"
/* ---------------------------------------------------------------------- *\
readfee8
returns -1 in case of error
\* ---------------------------------------------------------------------- */
int pcie40_readfee8( int dev , int adr) {
// PCIe40
if ( ( adr <=0 ) || ( adr > 0x7F ) ) return -1 ;
// Reset the FIFO
unsigned ret = 0 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD ,
1 << SLC_WFIFO_RESET_BIT ) ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
if ( ret != 0 ) return -1 ;
// Fill the FIFO with the requested information: write MSB first
int data_word_1 =
( 0x73 ) | ( 0x07 << 8 ) | ( adr << 16 ) | ( 0x0c << 24 ) ;
int data_word_2 = ( 0x08 ) ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_MSB ,
(int) ( data_word_2 & 0xFFFFFFFF ) ) ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_LSB ,
(int) ( data_word_1 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
return 0 ;
// Wait for the result to come back
int i ;
for ( i=0 ; i<10 ; i++ ) {
usleep( 10 ) ; //10 ms
ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_STATUS ) ;
if ( ret == 0x11 ) break;
}
// Read the value
ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_ADD );
return ret;
}
//==============================================================================
// Write 8b
//==============================================================================
if ( ( adr <= 0 ) || ( adr > 0x7F ) ) return -1 ;
int ret ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD ,
1 << SLC_WFIFO_RESET_BIT ) ;
if ( ret != 0 ) return -1 ;
int data_word_1 =
( 0x73 ) | ( 0x0a << 8 ) | ( adr << 16 ) | ( ( val & 0xFF ) << 24 ) ;
int data_word_2 = ( 0x08 << 0 ) ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_MSB ,
(int) ( data_word_1 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_LSB ,
(int) ( data_word_2 & 0xFFFFFFFF ) ) ;
//==============================================================================
// Read 32b
//==============================================================================
// PCIe40
if ( ( adr <=0 ) || ( adr > 0x7F ) ) return -1 ;
// Reset the FIFO
unsigned ret = 0 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD ,
1 << SLC_WFIFO_RESET_BIT ) ;
if ( ret != 0 ) return -1 ;
// Fill the FIFO with the requested information
int data_word_1 =
( 0x73 ) | ( 0x0c << 8 ) | ( ( adr & 0xFF ) << 16 ) |
( ( ( adr & 0xFF00 ) >> 8 ) << 24 ) ;
int data_word_2 = ( 0x04 << 24 ) | ( 0x04 << 16 ) | ( 0x0c0c ) ;
//
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_MSB ,
( data_word_1 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_LSB ,
( data_word_2 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
int data_word_3 =
( 0x73 ) | ( 0x0c << 8 ) | ( 0x0c << 16 ) | ( 0x0c << 24 ) ;
int data_word_4 = ( 0x08 << 24 ) | ( 0x02 << 16 ) | ( 0x0c0c ) ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_MSB ,
( data_word_3 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_LSB ,
( data_word_4 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
// Wait for the result to come back
int i ;
for ( i=0 ; i<10 ; i++ ) {
usleep( 10 ) ; //10 ms
ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_STATUS ) ;
if ( ret == 0x11 ) break;
}
if (i == 10) return -1;
// Read the value
ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_ADD );
return ret;
//==============================================================================
// Read 32b
//==============================================================================
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// PCIe40
if ( ( adr <=0 ) || ( adr > 0x7F ) ) return -1 ;
// Reset the FIFO
unsigned ret = 0 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD ,
1 << SLC_WFIFO_RESET_BIT ) ;
if ( ret != 0 ) return -1 ;
// Fill the FIFO with the requested information
int data_word_1 =
( 0x73 ) | ( 0x0b << 8 ) | ( ( adr & 0xFF ) << 16 ) |
( ( ( adr & 0xFF00 ) >> 8 ) << 24 ) ;
int data_word_2 = ( 0x04 << 24 ) | ( 0x04 << 16 )
| ( val & 0xFF ) | ( ( ( val & 0xFF00 ) >> 8 ) << 8 );
//
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_MSB ,
( data_word_1 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_LSB ,
( data_word_2 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
int data_word_3 =
( 0x73 ) | ( 0x0c << 8 ) | ( ( ( val & 0xFF0000 ) >> 16 ) << 16 ) |
( ( (val & 0xFF000000 ) >> 24 ) << 24 ) ;
int data_word_4 = ( 0x08 << 24 ) | ( 0x02 << 16 ) | ( 0x0c0c ) ;
//
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_MSB ,
( data_word_3 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD_LSB ,
( data_word_4 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
// Wait for the result to come back
int i ;
for ( i=0 ; i<10 ; i++ ) {
usleep( 10 ) ; //10 ms
ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_STATUS ) ;
if ( ret == 0x11 ) break;
}
if (i == 10) return -1;
// Read the value
ret = ecs_read( dev , SLC_BAR , SLC_RFIFO_ADD );
return ret;