Skip to content
Snippets Groups Projects
Commit 7b2d3be3 authored by Patrick Robbe's avatar Patrick Robbe
Browse files

First version of the writestream slow control function

parent 243b38dc
Branches
Tags
2 merge requests!3Feature/BIIDAQ-73 implement write stream slow control functionality,!56links
......@@ -297,5 +297,66 @@ int pcie40_writefee32( int dev , int ch , int adr , int val ) {
}
int pcie40_writestream( int dev , int ch , char * filename ) {
return 0 ;
// PCIe40
// Check if the file exists
const char * mode = "r" ;
FILE * fp = fopen( filename , mode ) ;
if ( 0 == fp ) {
printf( "The file does not exist\n" ) ;
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 ) {
fclose( fp ) ;
return -1 ;
}
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_RESET_ADD , 0 ) ;
if ( ret != 0 ) {
fclose( fp ) ;
return -1 ;
}
// Fill the FIFO with the requested information: write MSB first
// This is a stream write -> FFFD
int data_word_1 = 0xFFFC ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + ch * 0x20 ,
(int) ( data_word_1 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) {
fclose( fp ) ;
return -1 ;
}
// Read the file
int c = 0 ;
while ((c = getc(fp)) != EOF) {
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + ch * 0x20 ,
(int) ( ( ( 0x70 << 8 ) | ( c & 0xFF ) ) &
0xFFFFFFFF ) ) ;
if ( ret != 0 ) {
fclose( fp ) ;
return -1 ;
}
}
fclose( fp ) ;
// End of the file -> 0xEEEE
int data_word_3 = 0xEEEE ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_ADD + ch * 0x20 ,
(int) ( data_word_3 & 0xFFFFFFFF ) ) ;
if ( ret != 0 ) return -1 ;
// start emit
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_START_ADD , 0 ) ;
if ( ret != 0 ) return -1 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_START_ADD ,
1 << ( SLC_WFIFO_EMIT_BIT + ch ) ) ;
if ( ret != 0 ) return -1 ;
ret = ecs_write( dev , SLC_BAR , SLC_WFIFO_START_ADD , 0 ) ;
if ( ret != 0 ) return -1 ;
return ret ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment