예제 #1
0
int FastCCD::uploadFirmware(void){
  int _status = 0;

  char path[256];
  getStringParam(FastCCDFirmwarePath, sizeof(path), path);
  setIntegerParam(FastCCDFirmwareUpload, 1);

  // Power off the cin

  setStringParam(ADStatusMessage, "Powering CIN OFF");
  callParamCallbacks();
  if(cin_ctl_pwr(&cin_ctl_port, 0)){
    goto error;
  }

  sleep(5);
  getCameraStatus();

  // Power on the cin

  setStringParam(ADStatusMessage, "Powering CIN ON");
  callParamCallbacks();
  if(cin_ctl_pwr(&cin_ctl_port, 1)){
    goto error;
  }

  sleep(5);
  getCameraStatus();

  setStringParam(ADStatusMessage, "Uploading Firmware to CIN");
  callParamCallbacks();
  _status |= cin_ctl_load_firmware(&cin_ctl_port, 
                                  &cin_ctl_port_stream, path);
 
  if(!_status){
    _status |= cin_ctl_set_fabric_address(&cin_ctl_port, (char *)cinFabricIP);
    _status |= cin_data_send_magic();
  }

  setIntegerParam(FastCCDFirmwareUpload, 0);

error:

  if(_status){
    setStringParam(ADStatusMessage, "ERROR Uploading Firmware");
  } else {
    setStringParam(ADStatusMessage, "Firmware uploaded to CIN");
  }

  return _status;
}
예제 #2
0
int main(){

	/*Set directory for CIN configuration files*/ 
	char fpga_config_dir[]="/home/swilkins/Repos/lbl-fastccds/CIN_1kFSCCD_BINARY/";

	/*Set CIN FPGA configuration file*/   
	char fpga_configfile[]="top_frame_fpga-v1019j.bit";

	/*Set CIN configuration file*/ 
  char cin_config_dir[] = "/home/swilkins/Repos/lbl-fastccds/CameraConfigFiles/";

	char cin_configfile_waveform[] = "2013_Nov_30-200MHz_CCD_timing.txt";

	/*Create Path to files*/
	char cin_fpga_config[1024];
	char cin_waveform_config[1024];
	sprintf(cin_fpga_config,"%s%s", fpga_config_dir,fpga_configfile);
	sprintf(cin_waveform_config,"%s%s", cin_config_dir,cin_configfile_waveform);

	/*Set control ports*/	
	struct cin_port cp[2];
	
	cin_ctl_init_port(&cp[0], 0, CIN_CTL_SVR_PORT, CIN_CTL_CLI_PORT);
	cin_ctl_init_port(&cp[1], 0, CIN_CTL_SVR_FRMW_PORT, CIN_CTL_CLI_FRMW_PORT);

  fprintf(stderr, "Powering OFF CIN ............................");
	cin_ctl_pwr(&cp[0], 0);
	sleep(2);
  fprintf(stderr, " DONE\n");  

  fprintf(stderr, "Powering ON CIN .............................");
	cin_ctl_pwr(&cp[0], 1);
	sleep(2);
  fprintf(stderr, " DONE\n");

  fprintf(stderr, "Powering ON CIN Front Panel .................");
	cin_ctl_fp_pwr(&cp[0], 1);
	sleep(2);
  fprintf(stderr, " DONE\n");

  //fprintf(stderr, "\n");
  //cin_ctl_fpga_status_t fpga_status;
  //cin_ctl_get_cfg_fpga_status(&cp[0], &fpga_status);
  //cin_ctl_display_fpga_status(stderr, &fpga_status);
  //fprintf(stderr, "\n");
  //uint16_t dcm;
  //cin_ctl_get_dcm_status(&cp[0], &dcm);
  //cin_ctl_display_dcm_status(stderr, &dcm);
  //fprintf(stderr, "\n");

  int tries = 5;
  while(tries){
    fprintf(stderr, "Loading Firmware ............................");
		if(cin_ctl_load_firmware(&cp[0],&cp[1],cin_fpga_config)){
      fprintf(stderr, "FAILED.\n");
    } else {
      break;
    }
    tries--;
  }
  
  if(tries){  
    fprintf(stderr, " DONE\n");
  }

  fprintf(stderr, "Setting fabric IP address ...................");
  cin_ctl_set_fabric_address(&cp[0], "10.23.5.127");
  fprintf(stderr, " DONE\n");

  //fprintf(stderr, "\n");
  //cin_ctl_get_cfg_fpga_status(&cp[0], &fpga_status);
  //cin_ctl_display_fpga_status(stderr, &fpga_status);
  //cin_ctl_get_dcm_status(&cp[0], &dcm);
  //cin_ctl_display_dcm_status(stderr, &dcm);
  //fprintf(stderr, "\n");

  // This appears to be broken
  //int fclk;
	//cin_ctl_get_fclk(&cp[0], &fclk);			

  cin_ctl_pwr_mon_t pwr_values;
  int pwr;
  cin_ctl_get_power_status(&cp[0], 1, &pwr, &pwr_values);
  fprintf(stderr, "\n");
  cin_ctl_display_pwr(stderr, &pwr_values);
  fprintf(stderr, "\n");

/************************* FCCD Configuration **************************/	

  fprintf(stderr, "Loading FPGA Clock Configuration ............");
  cin_ctl_load_config(&cp[0],cin_waveform_config);		//Load FCCD clock configuration
  fprintf(stderr, " DONE\n");

	//sleep(3);
	
	//cin_load_config(&cp[0],cin_fcric_config);		//Load CIN fcric Configuration
	//sleep(3);
	
	//cin_load_config(&cp[0],cin_bias_config);		//Load FCCD bias Configuration
	//sleep(3);

/**********************************************************************/		

  cin_ctl_close_port(&cp[0]);
  cin_ctl_close_port(&cp[1]);

  fprintf(stderr, "\n\n");
	return 0;				
}
예제 #3
0
/** Called when asyn clients call pasynInt32->write().
  * This function performs actions for some parameters, including ADAcquire, ADBinX, etc.
  * For all parameters it sets the value in the parameter library and calls any registered callbacks..
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Value to write. */
asynStatus FastCCD::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
    int function = pasynUser->reason;

    asynStatus status = asynSuccess;
    static const char *functionName = "writeInt32";

    //Set in param lib so the user sees a readback straight away. Save a backup in case of errors.
    setIntegerParam(function, value);

    int _status = 0; // For return of cin functions

    if(function == ADAcquire){
      if(value){ // User clicked 'Start' button

         // Send the hardware a start trigger command
         int n_images, t_mode, i_mode;
         double t_exp, t_period;

         getIntegerParam(ADTriggerMode, &t_mode);
         getIntegerParam(ADImageMode, &i_mode);
         getIntegerParam(ADNumImages, &n_images);
         getDoubleParam(ADAcquireTime, &t_exp);
         getDoubleParam(ADAcquirePeriod, &t_period);

         switch(i_mode) {
           case ADImageSingle:
             this->framesRemaining = 1;
             n_images = 1;
             break;
           case ADImageMultiple:
             this->framesRemaining = n_images;
             break;
           case ADImageContinuous:
             this->framesRemaining = -1;
             n_images = 0;
             break;
         }

         if(t_mode == 0){
           _status |= cin_ctl_set_cycle_time(&cin_ctl_port, (float)t_period);
           _status |= cin_ctl_set_exposure_time(&cin_ctl_port, (float)t_exp);
           if(!_status){
             _status |= cin_ctl_int_trigger_start(&cin_ctl_port, n_images);
           }
         } else {
           _status |= cin_ctl_ext_trigger_start(&cin_ctl_port, t_mode);
         }

         if(!_status){
           setIntegerParam(ADAcquire, 1);
           setIntegerParam(ADStatus, ADStatusAcquire);
           setParamStatus(ADAcquire, asynSuccess);
           setParamStatus(ADStatus, asynSuccess);
         } else {
           setIntegerParam(ADAcquire, 1);
           setIntegerParam(ADStatus, ADStatusIdle);
           setParamStatus(ADAcquire, asynError);
           setParamStatus(ADStatus, asynError);
         }

      } else {
         // Send the hardware a stop trigger command
         if(!cin_ctl_int_trigger_stop(&cin_ctl_port)){
           setIntegerParam(ADStatus, ADStatusIdle);
           setIntegerParam(ADAcquire, 0);
         }
         if(!cin_ctl_ext_trigger_stop(&cin_ctl_port)){
           setIntegerParam(ADStatus, ADStatusIdle);
           setIntegerParam(ADAcquire, 0);
         }
      }

    } else if (function == FastCCDFirmwareUpload) {

      uploadFirmware();
      epicsEventSignal(statusEvent);

    } else if (function == FastCCDClockUpload) {

      _status = uploadConfig(FastCCDClockUpload, FastCCDClockPath);

    } else if (function == FastCCDBiasUpload) {

      _status = uploadConfig(FastCCDBiasUpload, FastCCDBiasPath);

    } else if (function == FastCCDFCRICUpload) {

      _status = uploadConfig(FastCCDFCRICUpload, FastCCDFCRICPath);

    } else if (function == FastCCDPower) {

      if(value) {
        _status |= cin_ctl_pwr(&cin_ctl_port, 1);
      } else {
        _status |= cin_ctl_pwr(&cin_ctl_port, 0);
      }

      epicsEventSignal(statusEvent);

    } else if (function == FastCCDFPPower) {

      if(value) {
        _status |= cin_ctl_fp_pwr(&cin_ctl_port, 1);
      } else {
        _status |= cin_ctl_fp_pwr(&cin_ctl_port, 0);
      }

      epicsEventSignal(statusEvent);

    } else if (function == FastCCDCameraPower) {

      if(value){
        _status |= cin_ctl_set_camera_pwr(&cin_ctl_port, 1);
      } else {
        _status |= cin_ctl_set_camera_pwr(&cin_ctl_port, 0);
      }

      epicsEventSignal(statusEvent);

    } else if ((function == FastCCDMux1) || (function == FastCCDMux2)) {

      int _val, _val1, _val2;
      getIntegerParam(FastCCDMux1, &_val1);
      getIntegerParam(FastCCDMux2, &_val2);
      _val = (_val2 << 4) | _val1;
      _status |= cin_ctl_set_mux(&cin_ctl_port, _val);   

      epicsEventSignal(statusEvent);

    } else if (function == FastCCDResetStats) {

      cin_data_reset_stats();

    } else if ((function == ADSizeY) || (function == FastCCDOverscan)) {

      // The Y size changed, change the descramble routine
      int _val1, _val2;
      getIntegerParam(ADSizeY, &_val1);
      getIntegerParam(FastCCDOverscan, &_val2);
      _status |= cin_data_set_descramble_params(_val1, _val2);

      // Read back to check all OK

      int _x, _y;
      cin_data_get_descramble_params(&_val1, &_val2, &_x, &_y);
      setIntegerParam(ADSizeX, _x);
      setIntegerParam(ADSizeY, _y);

    } else if (function == FastCCDFclk) {

      _status |= cin_ctl_set_fclk(&cin_ctl_port, value);
      epicsEventSignal(statusEvent);

    } else if (function == FastCCDFCRICGain){

      _status |= cin_ctl_set_fcric_gain(&cin_ctl_port, value);

    } else {
      status = ADDriver::writeInt32(pasynUser, value);
    }

    if(_status){
      status = asynError;
      setParamStatus(function, asynError);
    } else {
      setParamStatus(function, asynSuccess);
    }

    if (status) {
      asynPrint(pasynUser, ASYN_TRACE_ERROR,
            "%s:%s: error, status=%d function=%d, value=%d\n",
            driverName, functionName, status, function, value);
    } else {
      asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
            "%s:%s: function=%d, value=%d\n",
            driverName, functionName, function, value);
    }

    /* Do callbacks so higher layers see any changes */
    callParamCallbacks();

    return status;
}