コード例 #1
0
ファイル: fmc_imageon_utils.c プロジェクト: CprE488/MP-2
// Main FMC-IMAGEON initialization function. Add your code here.
int fmc_imageon_enable( camera_config_t *config )
{
   int ret;

   xil_printf("\n\r");
   xil_printf("------------------------------------------------\n\r");
   xil_printf("--    FMC-IMAGEON Camera Application (MP-2)   --\n\r");
   xil_printf("------------------------------------------------\n\r");
   xil_printf("\n\r");

   config->bVerbose = 1;
   config->vita_aec = 0;       // off
   config->vita_again = 0;     // 1.0
   config->vita_dgain = 128;   // 1.0
   config->vita_exposure = 90; // 90% of frame period


   xil_printf("FMC-IPMI Initialization ...\n\r");
   ret = fmc_iic_axi_init(&(config->fmc_ipmi_iic), "FMC-IPMI I2C Controller", config->uBaseAddr_IIC_FmcIpmi);
   if (!ret ) {
      xil_printf("ERROR: Failed to open FMC-IIC driver,\n\r");
      exit(1);
   }


   // FMC Module Validation
   if (fmc_ipmi_detect(&(config->fmc_ipmi_iic), "FMC-IMAGEON", FMC_ID_ALL)) {
      fmc_ipmi_enable( &(config->fmc_ipmi_iic), FMC_ID_SLOT1 );
   }
   else {
	   xil_printf("ERROR: Failed to validate FMC-IPMI I2C Controller.\n\r");
       exit(1);
   }


   xil_printf("FMC-IMAGEON I2C Initialization ...\n\r");
   ret = fmc_iic_axi_init(&(config->fmc_imageon_iic), "FMC-IMAGEON I2C Controller", config->uBaseAddr_IIC_FmcImageon);
   if (!ret) {
      xil_printf( "ERROR: Failed to open FMC-IIC driver\n\r");
      exit(1);
   }

   xil_printf("FMC-IMAGEON Video Clock Initialization ...\n\r");
   fmc_imageon_init(&(config->fmc_imageon), "FMC-IMAGEON", &(config->fmc_imageon_iic));
   fmc_imageon_vclk_init( &(config->fmc_imageon) );
   fmc_imageon_vclk_config( &(config->fmc_imageon), FMC_IMAGEON_VCLK_FREQ_148_500_000);

   xil_printf("Resetting clock generator ...\n\r");
   reset_dcms(config);

   // Initialize Video Output Timing
   xil_printf("Initializing Video Output for 1080P60 ...\n\r");

   config->hdmio_width  = 1920;
   config->hdmio_height = 1080;
   config->hdmio_timing.IsHDMI        = 0; // DVI Mode
   config->hdmio_timing.IsEncrypted   = 0;
   config->hdmio_timing.IsInterlaced  = 0;
   config->hdmio_timing.ColorDepth    = 8;
   config->hdmio_timing.HActiveVideo  = 1920;
   config->hdmio_timing.HFrontPorch   =   88;
   config->hdmio_timing.HSyncWidth    =   44;
   config->hdmio_timing.HSyncPolarity =    1;
   config->hdmio_timing.HBackPorch    =  148;
   config->hdmio_timing.VActiveVideo  = 1080;
   config->hdmio_timing.VFrontPorch   =    4;
   config->hdmio_timing.VSyncWidth    =    5;
   config->hdmio_timing.VSyncPolarity =    1;
   config->hdmio_timing.VBackPorch    =   36;

   if (config->bVerbose) {
  	   xil_printf("ADV7511 Video Output Information\n\r");
    	   xil_printf( "\tHSYNC Timing     = hav=%04d, hfp=%02d, hsw=%02d(hsp=%d), hbp=%03d\n\r",
      			   config->hdmio_timing.HActiveVideo,
      			   config->hdmio_timing.HFrontPorch,
      			   config->hdmio_timing.HSyncWidth, config->hdmio_timing.HSyncPolarity,
      			   config->hdmio_timing.HBackPorch);
    	   xil_printf( "\tVSYNC Timing     = vav=%04d, vfp=%02d, vsw=%02d(vsp=%d), vbp=%03d\n\r",
    			   config->hdmio_timing.VActiveVideo,
    			   config->hdmio_timing.VFrontPorch,
    			   config->hdmio_timing.VSyncWidth, config->hdmio_timing.VSyncPolarity,
    			   config->hdmio_timing.VBackPorch);
    	   xil_printf( "\tVideo Dimensions = %d x %d\n\r", config->hdmio_width, config->hdmio_height );

   }

   config->hdmio_resolution = vres_detect(config->hdmio_width, config->hdmio_height);
   xil_printf("\tVideo Resolution = %s\n\r", vres_get_name(config->hdmio_resolution));

   xil_printf( "Video Generator Configuration ...\n\r");
   vgen_init( &(config->vtc_tpg), config->uDeviceId_VTC_tpg);
   vgen_config( &(config->vtc_tpg ), config->hdmio_resolution, 1);


   // FMC-IMAGEON HDMI Output Initialization
   xil_printf( "FMC-IMAGEON HDMI Output Initialization ...\n\r" );
   ret = fmc_imageon_hdmio_init(&(config->fmc_imageon), 1, &(config->hdmio_timing), 0);
   if (!ret) {
      xil_printf("ERROR : Failed to init FMC-IMAGEON HDMI Output Interface\n\r");
      exit(0);
   }


   // FMC-IMAGEON VITA Receiver Initialization
   xil_printf( "FMC-IMAGEON VITA Receiver Initialization ...\n\r" );
   fmc_imageon_vita_receiver_init( &(config->vita_receiver), "VITA-2000", config->uBaseAddr_VITA_Receiver );
   config->vita_receiver.uManualTap = 25;
   fmc_imageon_vita_receiver_spi_config( &(config->vita_receiver), (50000000/10000000) );


   xil_printf("Video Detector Configuration ...\n\r");
   vdet_init(&(config->vtc_ipipe), config->uDeviceId_VTC_ipipe);
   vdet_config(&(config->vtc_ipipe), config->hdmio_resolution, 1);


   // Initialize the Video Sources
   //fmc_imageon_enable_tpg(config);
   int vita_enabled;
   int vita_enable_attempt=1;
   do {
	  xil_printf("\r\n\n\nFMC_IMAGEON_ENABLE_VITA, attempt %d\r\n\n\n", vita_enable_attempt++);
	  vita_enabled = fmc_imageon_enable_vita(config);
   } while(vita_enabled != 0);
   fmc_imageon_enable_ipipe(config);


   // Enable spread-spectrum clocking (SSC)
   enable_ssc(config);

   // Clear frame stores
   Xuint32 i;
   Xuint32 storage_size = config->uNumFrames_HdmiFrameBuffer * ((1920*1080)<<1);
   volatile Xuint32 *pStorageMem = (Xuint32 *)config->uBaseAddr_MEM_HdmiFrameBuffer;

   // Frame #1 - Red pixels
   for (i = 0; i < storage_size / config->uNumFrames_HdmiFrameBuffer; i += 4) {
	   *pStorageMem++ = 0xF0525A52;
   }
   // Frame #2 - Green pixels
   for (i = 0; i < storage_size / config->uNumFrames_HdmiFrameBuffer; i += 4) {
	   *pStorageMem++ = 0x36912291;
   }
   // Frame #3 - Blue pixels
   for (i = 0; i < storage_size / config->uNumFrames_HdmiFrameBuffer; i += 4) {
	   *pStorageMem++ = 0x6E29F029;
   }


   // Initialize Output Side of AXI VDMA
   xil_printf( "Video DMA (Output Side) Initialization ...\n\r" );
   vfb_common_init(
      config->uDeviceId_VDMA_HdmiFrameBuffer, // uDeviceId
      &(config->vdma_hdmi)                    // pAxiVdma
      );
   vfb_tx_init(
      &(config->vdma_hdmi),                   // pAxiVdma
      &(config->vdmacfg_hdmi_read),           // pReadCfg
      config->hdmio_resolution,               // uVideoResolution
      config->hdmio_resolution,               // uStorageResolution
      config->uBaseAddr_MEM_HdmiFrameBuffer,  // uMemAddr
      config->uNumFrames_HdmiFrameBuffer      // uNumFrames
      );

   // Initialize Input Side of AXI VDMA
   xil_printf( "Video DMA (Input Side) Initialization ...\n\r" );
   vfb_rx_init(
      &(config->vdma_hdmi),                   // pAxiVdma
      &(config->vdmacfg_hdmi_write),          // pWriteCfg
      config->hdmio_resolution,               // uVideoResolution
      config->hdmio_resolution,               // uStorageResolution
      config->uBaseAddr_MEM_HdmiFrameBuffer,  // uMemAddr
      config->uNumFrames_HdmiFrameBuffer      // uNumFrames
      );

   sleep(64); // Version of sleep() we are using is off by 64X.

   // Status of AXI VDMA
   vfb_dump_registers( &(config->vdma_hdmi) );
   if ( vfb_check_errors( &(config->vdma_hdmi), 1/*clear errors, if any*/ ) ) {
      vfb_dump_registers( &(config->vdma_hdmi) );
   }

   xil_printf("\n\r");
   xil_printf( "Done\n\r" );
   xil_printf("\n\r");

   return 0;
}
int fmc_imageon_vita_passthrough_init( fmc_imageon_vita_passthrough_t *pDemo )
{
   int ret;
   Xuint32 timeout = 100;
   Xuint32 iterations = 0;

   printf("\n\r");
   printf("------------------------------------------------------\n\r");
   printf("--          FMC-IMAGEON VITA Pass-Through           --\n\r");
   printf("------------------------------------------------------\n\r");
   printf("\n\r");

   printf( "FMC-IMAGEON Initialization ...\n\r" );

   ret = fmc_iic_xps_init(&(pDemo->fmc_imageon_iic),"FMC-IMAGEON I2C Controller", pDemo->uBaseAddr_IIC_FmcImageon );
   if ( !ret )
   {
      printf( "ERROR : Failed to open FMC-IIC driver\n\r" );
      exit(0);
   }

   fmc_imageon_init(&(pDemo->fmc_imageon), "FMC-IMAGEON", &(pDemo->fmc_imageon_iic));
   pDemo->fmc_imageon.bVerbose = pDemo->bVerbose;

   // Configure Video Clock Synthesizer
   printf( "Video Clock Synthesizer Configuration ...\n\r" );
   fmc_imageon_vclk_init( &(pDemo->fmc_imageon) );
   fmc_imageon_vclk_config( &(pDemo->fmc_imageon), FMC_IMAGEON_VCLK_FREQ_148_500_000);
   sleep(1);

   // Set HDMI output to 1080P60
   pDemo->hdmio_resolution = VIDEO_RESOLUTION_1080P;
   pDemo->hdmio_width  = 1920;
   pDemo->hdmio_height = 1080;

   //pDemo->hdmio_timing.IsHDMI        = 1; // HDMI Mode
   pDemo->hdmio_timing.IsHDMI        = 0; // DVI Mode
   pDemo->hdmio_timing.IsEncrypted   = 0;
   pDemo->hdmio_timing.IsInterlaced  = 0;
   pDemo->hdmio_timing.ColorDepth    = 8;

   pDemo->hdmio_timing.HActiveVideo  = 1920;
   pDemo->hdmio_timing.HFrontPorch   =   88;
   pDemo->hdmio_timing.HSyncWidth    =   44;
   pDemo->hdmio_timing.HSyncPolarity =    1;
   pDemo->hdmio_timing.HBackPorch    =  148;

   pDemo->hdmio_timing.VActiveVideo  = 1080;
   pDemo->hdmio_timing.VFrontPorch   =    4;
   pDemo->hdmio_timing.VSyncWidth    =    5;
   pDemo->hdmio_timing.VSyncPolarity =    1;
   pDemo->hdmio_timing.VBackPorch    =   36;

   printf( "ADV7511 Video Output Information\n\r" );
   printf( "\tVideo Output     = %s", pDemo->hdmio_timing.IsHDMI ? "HDMI" : "DVI" );
   printf( "%s", pDemo->hdmio_timing.IsEncrypted ? ", HDCP Encrypted" : "" );
   printf( ", %s\n\r", pDemo->hdmio_timing.IsInterlaced ? "Interlaced" : "Progressive" );
   printf( "\tColor Depth      = %d bits per channel\n\r", pDemo->hdmio_timing.ColorDepth );
   printf( "\tHSYNC Timing     = hav=%04d, hfp=%02d, hsw=%02d(hsp=%d), hbp=%03d\n\r",
      pDemo->hdmio_timing.HActiveVideo,
      pDemo->hdmio_timing.HFrontPorch,
      pDemo->hdmio_timing.HSyncWidth, pDemo->hdmio_timing.HSyncPolarity,
      pDemo->hdmio_timing.HBackPorch
      );
   printf( "\tVSYNC Timing     = vav=%04d, vfp=%02d, vsw=%02d(vsp=%d), vbp=%03d\n\r",
      pDemo->hdmio_timing.VActiveVideo,
      pDemo->hdmio_timing.VFrontPorch,
      pDemo->hdmio_timing.VSyncWidth, pDemo->hdmio_timing.VSyncPolarity,
      pDemo->hdmio_timing.VBackPorch
      );
   printf( "\tVideo Dimensions = %d x %d\n\r", pDemo->hdmio_width, pDemo->hdmio_height );

   printf( "HDMI Output Initialization ...\n\r" );
   ret = fmc_imageon_hdmio_init( &(pDemo->fmc_imageon),
 	                             1,                      // hdmioEnable = 1
 	                             &(pDemo->hdmio_timing), // pTiming
 	                             0                       // waitHPD = 0
 	                             );
   if ( !ret )
   {
      printf( "ERROR : Failed to init HDMI Output Interface\n\r" );
      exit(0);
   }

  while (1)
  {

   if ( iterations > 0 )
   {
      printf( "\n\rPress ENTER to re-start ...\n\r" );
      getchar();
   }
   iterations++;

   // FMC-IMAGEON VITA Receiver Initialization
   printf( "FMC-IMAGEON VITA Receiver Initialization ...\n\r" );
   onsemi_vita_init( &(pDemo->vita_receiver), "VITA-2000", pDemo->uBaseAddr_VITA_SPI, pDemo->uBaseAddr_VITA_CAM );
   pDemo->vita_receiver.uManualTap = 25;
   printf( "FMC-IMAGEON VITA SPI Config for 10MHz ...\n\r" );
   // axi4lite_0_clk = 50MHz
   onsemi_vita_spi_config( &(pDemo->vita_receiver), (50000000/10000000) );

   // VITA-2000 Initialization
   printf( "FMC-IMAGEON VITA Initialization ...\n\r" );
   ret = onsemi_vita_sensor_initialize( &(pDemo->vita_receiver), SENSOR_INIT_ENABLE, 1 ); // Be verbose
   if ( ret == 0 )
   {
       printf( "VITA sensor failed to initialize ...\n\r" );
      //return -1;
      return XST_SUCCESS;
   }

   sleep(1);

   printf( "FMC-IMAGEON VITA Configuration for 1080P60 timing ...\n\r" );
   ret = onsemi_vita_sensor_1080P60( &(pDemo->vita_receiver), pDemo->bVerbose );
   if ( ret == 0 )
   {
      printf( "VITA sensor failed to configure for 1080P60 timing ...\n\r" );
      //return -1;
      return XST_SUCCESS;
   }

   sleep(1);
   onsemi_vita_get_status( &(pDemo->vita_receiver), &(pDemo->vita_status_t1), 0 );
   sleep(1);
   onsemi_vita_get_status( &(pDemo->vita_receiver), &(pDemo->vita_status_t2), 0 );
   //
   printf( "VITA Status = \n\r" );
   printf("\tImage Width  = %d\n\r", pDemo->vita_status_t1.cntImagePixels * 4 );
   printf("\tImage Height = %d\n\r", pDemo->vita_status_t1.cntImageLines  );
   printf("\tFrame Rate   = %d frames/sec\n\r", pDemo->vita_status_t2.cntFrames - pDemo->vita_status_t1.cntFrames );
   printf("\tCRC Status   = %X\n\r", pDemo->vita_status_t2.crcStatus );

   if ( pDemo->bVerbose )
   {
   	onsemi_vita_get_status( &(pDemo->vita_receiver), &(pDemo->vita_status_t2), 1 );
   }

#if 0
   // accept 1920x1080 resolution
   if ( (pDemo->vita_status_t1.cntImagePixels * 4)==1920 && (pDemo->vita_status_t1.cntImageLines)==1080 )
   {
   	// accept 60-64fps range
   	if ( (pDemo->vita_status_t2.cntFrames - pDemo->vita_status_t1.cntFrames)>=60 && (pDemo->vita_status_t2.cntFrames - pDemo->vita_status_t1.cntFrames)<=64 )
   	{
           ; //break;
   	}
   }
#endif


#if defined(XPAR_XVTC_NUM_INSTANCES)
   // Configure VTC on output data path
   printf( "Video Timing Controller (generator) Initialization ...\n\r" );
   vgen_init( &(pDemo->vtc_hdmio_generator), pDemo->uDeviceId_VTC_HdmioGenerator );
   vgen_config( &(pDemo->vtc_hdmio_generator), pDemo->hdmio_resolution, 1 );
#endif

//#if defined(XPAR_CFA_NUM_INSTANCES)
#if defined(XPAR_CFA_0_BASEADDR)
   printf( "Color Filter Array Interpolation (CFA) Initialization ...\n\r" );
   pDemo->pCfa_config = XCfa_LookupConfig(pDemo->uDeviceId_CFA);
   XCfa_CfgInitialize(&(pDemo->cfa), pDemo->pCfa_config, pDemo->pCfa_config->BaseAddress);
   XCfa_Reset( &(pDemo->cfa) );
   XCfa_SetBayerPhase( &(pDemo->cfa), XCFA_RGRG_COMBINATION );
   XCfa_RegUpdateEnable( &(pDemo->cfa) );
   XCfa_Enable( &(pDemo->cfa) );
   printf("\tCFA done\r\n");
#endif

   printf("\n\r");
   printf( "Done\n\r" );
   printf("\n\r");

   sleep(1);
  }

   return 0;
}