Facebook
From Mustard Rhinoceros, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 31
  1. #include "chains_vipSingleCam_ColorToGray_priv.h"
  2. #include <src/hlos/adas/include/chains.h>
  3. #include <src/hlos/common/chains_common.h>
  4.  
  5.  
  6. #define CAPTURE_SENSOR_WIDTH      (1280)
  7. #define CAPTURE_SENSOR_HEIGHT     (720)
  8. #define NUMBER_OF_CAM             (2)
  9. #define NUMBER_OF_PORT            (NUMBER_OF_CAM / 2)
  10.  
  11.  
  12. /**
  13.  *******************************************************************************
  14.  *
  15.  *  \brief  Use-case object
  16.  *
  17.  *        This structure contains all the LinksId's and create Params.
  18.  *        The same is passed to all create, start, stop functions.
  19.  *
  20.  *******************************************************************************
  21. */
  22. typedef struct {
  23.  
  24.     chains_vipSingleCam_ColorToGrayObj ucObj;
  25.  
  26.     UInt32  captureOutWidth;
  27.     UInt32  captureOutHeight;
  28.     UInt32  displayWidth;
  29.     UInt32  displayHeight;
  30.  
  31.     Chains_Ctrl *chainsCfg;
  32.  
  33.     VideoSensorCreateAndStartAppPrm vidSensorPrm;
  34.  
  35.     UInt32  appCtrlLinkId;
  36.  
  37.     UInt32  displayActiveChId;
  38.     /**< CH ID which is shown on display, by default 2x2 SW Mosaic
  39.      *   is shown on display
  40.      */
  41.     UInt32  numLvdsCh;
  42.     /**< Number of channels of LVDS to enable */
  43.  
  44. } Chains_vipSingleCam_ColorToGrayAppObj;
  45.  
  46. /**
  47.  *******************************************************************************
  48.  * \brief Run Time Menu string.
  49.  *******************************************************************************
  50.  */
  51. char gChains_vipSingleCam_ColorToGray_runTimeMenu[] = {
  52.     "\r\n "
  53.     "\r\n ===================="
  54.     "\r\n Chains Run-time Menu"
  55.     "\r\n ===================="
  56.     "\r\n "
  57.     "\r\n 0: Stop Chain"
  58.     "\r\n "
  59.     "\r\n 2: Pause Capture"
  60.     "\r\n 3: Resume Capture"
  61.     "\r\n "
  62.     "\r\n p: Print Performance Statistics "
  63.     "\r\n "
  64.     "\r\n Enter Choice: "
  65.     "\r\n "
  66. };
  67.  
  68. static void chains_vipSingleCam_ColorToGray_SetVpePrm(VpeLink_CreateParams *pPrm, UInt32 numLvdsCh)
  69. {
  70.     UInt32 chId;
  71.     VpeLink_ChannelParams *chPrms;
  72.     pPrm->enableOut[0] = TRUE;
  73.     for(chId = 0; chId < numLvdsCh; chId++)
  74.     {
  75.         pPrm->chParams[chId].outParams[0].width = CAPTURE_SENSOR_WIDTH;
  76.         pPrm->chParams[chId].outParams[0].height = CAPTURE_SENSOR_HEIGHT;
  77.         pPrm->chParams[chId].outParams[0].dataFormat = SYSTEM_DF_YUV422I_YUYV;
  78.         pPrm->chParams[chId].outParams[0].numBufsPerCh = 4;
  79.         chPrms = &pPrm->chParams[chId];
  80.         chPrms->scCfg.bypass = FALSE;
  81.         chPrms->scCfg.nonLinear = FALSE;
  82.         chPrms->scCfg.stripSize = 0;
  83.         chPrms->scCropCfg.cropStartX = 0;
  84.         chPrms->scCropCfg.cropStartY = 0;
  85.         chPrms->scCropCfg.cropWidth = CAPTURE_SENSOR_WIDTH;
  86.         chPrms->scCropCfg.cropHeight = CAPTURE_SENSOR_HEIGHT;
  87.     }
  88. }
  89.  
  90.  
  91. static void chains_vipSingleCam_ColorToGray_SetSelectPrm(
  92.                                       SelectLink_CreateParams *pPrm)
  93. {
  94.     pPrm->numOutQue = 1;
  95.     pPrm->outQueChInfo[0].outQueId   = 0;
  96.     pPrm->outQueChInfo[0].numOutCh   = 1;
  97.     pPrm->outQueChInfo[0].inChNum[0] = 0;
  98. }
  99.  
  100. /**
  101.  *******************************************************************************
  102.  *
  103.  * \brief   Set link Parameters
  104.  *
  105.  *          It is called in Create function of the auto generated use-case file.
  106.  *
  107.  * \param pUcObj    [IN] Auto-generated usecase object
  108.  * \param appObj    [IN] Application specific object
  109.  *
  110.  *******************************************************************************
  111. */
  112. Void chains_vipSingleCam_ColorToGray_SetAppPrms(chains_vipSingleCam_ColorToGrayObj *pUcObj, Void *appObj)
  113. {
  114.     Chains_vipSingleCam_ColorToGrayAppObj *pObj
  115.         = (Chains_vipSingleCam_ColorToGrayAppObj*)appObj;
  116.  
  117.     UInt32 portId[VIDEO_SENSOR_MAX_LVDS_CAMERAS];
  118.  
  119.     pObj->displayActiveChId = 0;
  120.  
  121.     pObj->numLvdsCh = NUMBER_OF_CAM;
  122.  
  123.     pObj->captureOutWidth  = CAPTURE_SENSOR_WIDTH;
  124.     pObj->captureOutHeight = CAPTURE_SENSOR_HEIGHT;
  125.  
  126.     ChainsCommon_GetDisplayWidthHeight(
  127.         pObj->chainsCfg->displayType,
  128.         &pObj->displayWidth,
  129.         &pObj->displayHeight
  130.         );
  131.  
  132.     portId[0] = SC_VIDEO_SENSOR_1_2;
  133.  
  134.     ChainsCommon_SetCapturePrms(
  135.         &pUcObj->CapturePrm,
  136.         CAPTURE_SENSOR_WIDTH * 2,
  137.         CAPTURE_SENSOR_HEIGHT,
  138.         portId,
  139.         pObj->numLvdsCh / 2
  140.         );
  141.  
  142.     chains_vipSingleCam_ColorToGray_SetSelectPrm(&pUcObj->SelectPrm);
  143.     chains_vipSingleCam_ColorToGray_SetVpePrm(&pUcObj->VPEPrm, 1);
  144.  
  145.     ChainsCommon_SetGrpxSrcPrms(
  146.         &pUcObj->GrpxSrcPrm,
  147.         pObj->displayWidth,
  148.         pObj->displayHeight
  149.         );
  150.     pUcObj->GrpxSrcPrm.grpxBufInfo.dataFormat = SYSTEM_DF_BGRA16_4444;
  151.  
  152.     ChainsCommon_SetDisplayPrms(
  153.         &pUcObj->DisplayPrm,
  154.         &pUcObj->Display_GrpxPrm,
  155.         pObj->chainsCfg->displayType,
  156.         pObj->displayWidth,
  157.         pObj->displayHeight
  158.         );
  159.  
  160.     ChainsCommon_StartDisplayCtrl(
  161.         pObj->chainsCfg->displayType,
  162.         pObj->displayWidth,
  163.         pObj->displayHeight
  164.         );
  165.  
  166. }
  167.  
  168.  
  169. /**
  170.  *******************************************************************************
  171.  *
  172.  * \brief   Start the capture display Links
  173.  *
  174.  *          Function sends a control command to capture and display link to
  175.  *          to Start all the required links . Links are started in reverce
  176.  *          order as information of next link is required to connect.
  177.  *          System_linkStart is called with LinkId to start the links.
  178.  *
  179.  * \param   pObj  [IN] Chains_vipSingleCam_ColorToGrayObj
  180.  *
  181.  * \return  SYSTEM_LINK_STATUS_SOK on success
  182.  *
  183.  *******************************************************************************
  184. */
  185. static Void chains_vipSingleCam_ColorToGray_StartApp(Chains_vipSingleCam_ColorToGrayAppObj *pObj)
  186. {
  187.     pObj->vidSensorPrm.captureSrcId = CHAINS_CAPTURE_SRC_OV10635;
  188.     pObj->vidSensorPrm.isLVDSCaptMode = TRUE;
  189.     pObj->vidSensorPrm.numLvdsCh = 2;
  190.     pObj->vidSensorPrm.chipType = SCV;
  191.  
  192.     system("./ub964_SV.sh");
  193.  
  194.     System_linkControl(SYSTEM_LINK_ID_APP_CTRL,
  195.                                 APP_CTRL_LINK_CMD_VIDEO_SENSOR_CREATE_AND_START,
  196.                                 &pObj->vidSensorPrm,
  197.                                 sizeof(VideoSensorCreateAndStartAppPrm),
  198.                                 TRUE);
  199.  
  200.     ChainsCommon_statCollectorReset();
  201.     ChainsCommon_memPrintHeapStatus();
  202.  
  203.     chains_vipSingleCam_ColorToGray_Start(&pObj->ucObj);
  204.  
  205.     ChainsCommon_prfLoadCalcEnable(TRUE, FALSE, FALSE);
  206.  
  207. }
  208.  
  209.  
  210. /**
  211.  *******************************************************************************
  212.  *
  213.  * \brief   Delete the capture display Links
  214.  *
  215.  *          Function sends a control command to capture and display link to
  216.  *          to delete all the prior created links
  217.  *          System_linkDelete is called with LinkId to delete the links.
  218.  *
  219.  * \param   pObj   [IN]   Chains_vipSingleCam_ColorToGrayObj
  220.  *
  221.  *******************************************************************************
  222. */
  223. static Void chains_vipSingleCam_ColorToGray_StopAndDeleteApp(Chains_vipSingleCam_ColorToGrayAppObj *pObj)
  224. {
  225.     chains_vipSingleCam_ColorToGray_Stop(&pObj->ucObj);
  226.     chains_vipSingleCam_ColorToGray_Delete(&pObj->ucObj);
  227.  
  228.     ChainsCommon_StopDisplayCtrl();
  229.  
  230.     System_linkControl(SYSTEM_LINK_ID_APP_CTRL,
  231.                         APP_CTRL_LINK_CMD_VIDEO_SENSOR_STOP_AND_DELETE,
  232.                         &pObj->vidSensorPrm,
  233.                         sizeof(VideoSensorCreateAndStartAppPrm),
  234.                         TRUE);
  235.  
  236.  
  237.     /* Print the HWI, SWI and all tasks load */
  238.     /* Reset the accumulated timer ticks */
  239.     ChainsCommon_prfLoadCalcEnable(FALSE, FALSE, FALSE);
  240. }
  241.  
  242.  
  243. /**
  244.  *******************************************************************************
  245.  *
  246.  * \brief   Single Channel Capture Display usecase function
  247.  *
  248.  *          This functions executes the create, start functions
  249.  *
  250.  *          Further in a while loop displays run time menu and waits
  251.  *          for user inputs to print the statistics or to end the demo.
  252.  *
  253.  *          Once the user inputs end of demo stop and delete
  254.  *          functions are executed.
  255.  *
  256.  * \param   chainsCfg       [IN]   Chains_Ctrl
  257.  *
  258.  *******************************************************************************
  259. */
  260. Void Chains_vipSingleCam_ColorToGray(Chains_Ctrl *chainsCfg)
  261. {
  262.     char ch;
  263.     UInt32 done = FALSE;
  264.     Chains_vipSingleCam_ColorToGrayAppObj chainsObj;
  265.     Int32 status;
  266.  
  267.     chainsObj.numLvdsCh         = 0; /* KW error fix */
  268.     chainsObj.displayActiveChId = 0; /* KW error fix */
  269.  
  270.     chainsObj.chainsCfg = chainsCfg;
  271.  
  272.     chains_vipSingleCam_ColorToGray_Create(&chainsObj.ucObj, &chainsObj);
  273.  
  274.     chains_vipSingleCam_ColorToGray_StartApp(&chainsObj);
  275.  
  276.     while(!done)
  277.     {
  278.         Vps_printf(gChains_vipSingleCam_ColorToGray_runTimeMenu);
  279.  
  280.         ch = Chains_readChar();
  281.  
  282.         switch(ch)
  283.         {
  284.             case '0':
  285.                 done = TRUE;
  286.                 break;
  287.  
  288.             case '2':
  289.                 status = System_linkStop(chainsObj.ucObj.CaptureLinkID);
  290.                 UTILS_assert(status == SYSTEM_LINK_STATUS_SOK);
  291.                 break;
  292.  
  293.             case '3':
  294.                 status = System_linkStart(chainsObj.ucObj.CaptureLinkID);
  295.                 UTILS_assert(status == SYSTEM_LINK_STATUS_SOK);
  296.                 break;
  297.  
  298.             case 'p':
  299.             case 'P':
  300.                 ChainsCommon_PrintStatistics();
  301.                 chains_vipSingleCam_ColorToGray_printStatistics(&chainsObj.ucObj);
  302.                 break;
  303.             default:
  304.                 Vps_printf("\nUnsupported option '%c'. Please try again\n", ch);
  305.                 break;
  306.         }
  307.     }
  308.  
  309.     chains_vipSingleCam_ColorToGray_StopAndDeleteApp(&chainsObj);
  310. }