/* * initHelicityBoard.cc * * Created on: Nov 26, 2025 * Author: Hovanes Egiyan * * This standalone program initializes the helicity decoder board * using some hardcoded parameters. Our intention is to run this executable * right after the controller of the VME crate containing the decoder board boots. */ /* Event Buffer definitions */ #include #include #include #include extern "C" { #include "hdLib.h" #include "jvme.h" } //#define HELICITY_DECODER_ADDR 0xed0000 #define HELICITY_DECODER_ADDR 0x00980000 static int hd_found = 0; //static uint8_t fiber_input; //static uint8_t cu_input; //static uint8_t cu_output; void hd_download() { /* Initialize the library and module with its internal clock*/ // int ret = hdInit( HELICITY_DECODER_ADDR, HD_INIT_INTERNAL, 0, 0 ); // int ret = hdInit( HELICITY_DECODER_ADDR, HD_INIT_INTERNAL, 0, 1 ); // int ret = hdInit( 0, HD_INIT_INTERNAL, 0, 0 ); int ret = hdInit(HELICITY_DECODER_ADDR, HD_INIT_VXS, HD_INIT_EXTERNAL_FIBER, 0); // hdStatus(1); if ( ret == 0 ) hd_found = 1; else hd_found = 0; //if(hd_found) //{ //hdSetA32(0x10000000); hdSetA32( 0x08800000 ); hdStatus( 1 ); //} printf( "hd_download(): Executed ret=%d found=%d \n", ret, hd_found ); return; } void hd_prestart() { uint8_t blockLevel = 1; // uint8_t hd_clock, hd_clock_ret; if ( hd_found ) { // --- hallb -- /* Setting data input (0x100 = 2048 ns) and trigger latency (1000*8ns = 8000 ns) processing delays */ hdSetProcDelay( 0x100, 1000 ); hdSetBlocklevel(blockLevel); // moved from GO /* Enable the module decoder, well before triggers are enabled */ hdEnableDecoder(); // /*set i/o signals inversion if needed; 3 parameters have following meaning: fiber_input, cu_input, cu_output // (0 means no inversion, 1 means inversion)*/ // // //ret = hdSetHelicityInversion(0, 0, 0); /*reproduces old (v7) firmware (before Jan 31, 2024)*/ // /* signals on fiber inputs are reversed because of polarity-flipping // optical fanout in counting room, so we do (1,0,1); if optical fanout // replaced with non-flipping one, will change it to (0,0,1)*/ // int ret = hdSetHelicityInversion( 1, 0, 1 ); // // ret = hdGetHelicityInversion( &fiber_input, &cu_input, &cu_output ); // printf( // "\nHelicity Decoder inversion settings: fiber_input=%d, cu_input=%d, cu_output=%d (0-no flip, 1-flip)\n\n", // fiber_input, cu_input, cu_output ); // // /* set tsettle filtering: // * 0 Disabled // * 1 4 clock cycles // * 2 8 clock cycles // * 3 16 clock cycles // * 4 24 clock cycles // * 5 32 clock cycles // * 6 64 clock cycles // * 7 128 clock cycles */ // hd_clock = 3; // ret = hdSetTSettleFilter( hd_clock ); // ret = hdGetTSettleFilter( &hd_clock_ret ); // printf( "\nHD T-settle filtering: set %d, read back %d\n\n", hd_clock, hd_clock_ret ); hdStatus( 0 ); } printf( "hd_prestart(): Executed \n" ); return; } void hd_go() { /* Get the current Block Level */ //blockLevel = tiGetCurrentBlockLevel(); //printf("rocGo: Block Level set to %d\n",blockLevel); /* Enable/Set Block Level on modules, if needed, here */ hdEnable(); hdStatus( 0 ); printf( "hd_go(): Executed \n" ); return; } int main( int argc, char *argv[] ) { // This code is expected to run at the powering up of the crate to set some // default parameters on the helicity decoder board. vmeOpenDefaultWindows(); // Simply run the functions that are run during download, prestart, and go. hd_download(); hd_prestart(); hd_go(); return (0); }