commit 31598db32d47ed921d5dad94efe3beb2155bebd3
Author: Nikhil Dasan <n-dasan@ti.com>
Date:   Mon Aug 8 12:19:47 2022 +0530

    Frame Freeze Detection
    
    Signed-off-by: Nikhil Dasan <n-dasan@ti.com>

diff --git a/kernels_j7/hwa/display/vx_display_target.c b/kernels_j7/hwa/display/vx_display_target.c
index 242389d..f6d5b24 100755
--- a/kernels_j7/hwa/display/vx_display_target.c
+++ b/kernels_j7/hwa/display/vx_display_target.c
@@ -105,6 +105,8 @@ typedef struct
     /**< Create time parameters */
     Dss_DispCreateStatus createStatus;
     /**< Create status returned by driver during Fvid2_create() */
+    Dss_DispPipeSafetyChkParams safetyChkParams;
+    /**< DSS safety check parameters*/
     Dss_DispParams dispParams;
     /**< DSS display parameters */
     Fvid2_Handle drvHandle;
@@ -155,6 +157,7 @@ static vx_status tivxDisplayExtractFvid2Format(
     tivxDisplayParams *dispPrms, tivx_display_params_t *inDispPrms,
     const tivx_obj_desc_image_t *obj_desc_img, Fvid2_Format *format);
 static int32_t tivxDisplayCallback(Fvid2_Handle handle, void *appData);
+static void tivxDisplaySafetyCallback(uint32_t capturedSign, void *appData);
 static uint32_t tivxDisplayGetPipeType(uint32_t drvId);
 static int32_t tivxDisplayGetImageSize(const tivx_obj_desc_image_t *obj_desc_image,
                                        uint32_t *copySize0,
@@ -173,6 +176,8 @@ static vx_status tivxDisplaySwitchChannel(tivxDisplayParams *dispPrms,
     const tivx_obj_desc_user_data_object_t *usr_data_obj);
 static vx_status tivxDisplaySetCropParams(tivxDisplayParams *dispPrms,
     const tivx_obj_desc_user_data_object_t *usr_data_obj);
+static vx_status tivxDisplaySetPipeSafetyParams(tivxDisplayParams *dispPrms,
+    const tivx_obj_desc_user_data_object_t *usr_data_obj);
 
 static vx_status tivxDisplaySwitchChannel(tivxDisplayParams *dispPrms,
     const tivx_obj_desc_user_data_object_t *usr_data_obj)
@@ -251,6 +256,62 @@ static vx_status tivxDisplaySetCropParams(tivxDisplayParams *dispPrms,
     return (status);
 }
 
+static vx_status tivxDisplaySetPipeSafetyParams(tivxDisplayParams *dispPrms,
+    const tivx_obj_desc_user_data_object_t *usr_data_obj)
+{
+    vx_status                             status = (vx_status)VX_SUCCESS;
+    tivx_display_safety_check_params_t   *ch_prms = NULL;
+    void                                 *target_ptr;
+    int32_t                               fvid2_status = FVID2_SOK;
+
+    if (NULL != usr_data_obj)
+    {
+        target_ptr = tivxMemShared2TargetPtr(&usr_data_obj->mem_ptr);
+
+        tivxCheckStatus(&status, tivxMemBufferMap(target_ptr, usr_data_obj->mem_size,
+            (vx_enum)VX_MEMORY_TYPE_HOST, (vx_enum)VX_READ_ONLY));
+
+        if (sizeof(tivx_display_safety_check_params_t) == usr_data_obj->mem_size)
+        {
+            ch_prms = (tivx_display_safety_check_params_t *)target_ptr;
+            dispPrms->safetyChkParams.safetyChkCfg.safetyChkEnable = ch_prms->safetyChkEnable;
+            dispPrms->safetyChkParams.safetyChkCfg.safetyChkMode = ch_prms->safetyChkMode;
+            dispPrms->safetyChkParams.safetyChkCfg.seedSelectEnable = ch_prms->seedSelectEnable;
+            dispPrms->safetyChkParams.safetyChkCfg.thresholdValue = ch_prms->thresholdValue;
+            dispPrms->safetyChkParams.safetyChkCfg.regionPos.startX = ch_prms->regionPos.startX;
+            dispPrms->safetyChkParams.safetyChkCfg.regionPos.startY = ch_prms->regionPos.startY;
+            dispPrms->safetyChkParams.safetyChkCfg.regionSize.width = ch_prms->regionSize.width;
+            dispPrms->safetyChkParams.safetyChkCfg.regionSize.height = ch_prms->regionSize.height;
+            dispPrms->safetyChkParams.safetyErrCbFxn = tivxDisplaySafetyCallback;
+            dispPrms->safetyChkParams.appData = (void *)(&ch_prms->disp_prm);
+            fvid2_status = Fvid2_control(dispPrms->drvHandle,
+                                   IOCTL_DSS_DISP_SET_PIPE_SAFETY_CHK_PARAMS,
+                                   &dispPrms->safetyChkParams,
+                                   NULL);
+            if(FVID2_SOK != fvid2_status)
+            {
+                status = (vx_status)VX_FAILURE;
+                VX_PRINT(VX_ZONE_ERROR, "DISPLAY: ERROR: Display Set Parameters Failed!\r\n");
+            }
+        }
+        else
+        {
+            VX_PRINT(VX_ZONE_ERROR, "Invalid Size \n");
+            status = (vx_status)VX_ERROR_INVALID_PARAMETERS;
+        }
+
+        tivxCheckStatus(&status, tivxMemBufferUnmap(target_ptr, usr_data_obj->mem_size,
+            (vx_enum)VX_MEMORY_TYPE_HOST, (vx_enum)VX_READ_ONLY));
+    }
+    else
+    {
+        VX_PRINT(VX_ZONE_ERROR, "User Data Object is NULL \n");
+        status = (vx_status)VX_ERROR_INVALID_PARAMETERS;
+    }
+
+    return (status);
+}
+
 static vx_status tivxDisplayExtractFvid2Format(
     tivxDisplayParams *dispPrms, tivx_display_params_t *inDispPrms,
     const tivx_obj_desc_image_t *obj_desc_img, Fvid2_Format *format)
@@ -398,6 +459,27 @@ static vx_status tivxDisplayAllocChromaBuff(tivxDisplayParams *dispPrms,
     return (status);
 }
 
+static void tivxDisplaySafetyCallback(uint32_t capturedSign,
+                                       void *appData)
+{
+    vx_status status = (vx_status)VX_SUCCESS;
+
+    tivx_display_params_t *params;
+
+    if(NULL != appData)
+    {
+        params = (tivx_display_params_t *)appData;
+        if(params->pipeId == 0U)
+        {
+            VX_PRINT(VX_ZONE_ERROR, "DISPLAY: Safety(Freeze Frame) Callback: VID1\r\n");
+        }
+        if(params->pipeId == 2U)
+        {
+            VX_PRINT(VX_ZONE_ERROR, "DISPLAY: Safety(Freeze Frame) Callback: VID2\r\n");
+        }
+    }
+}
+
 static void tivxDisplayFreeChromaBuff(tivxDisplayParams *dispPrms)
 {
     if (dispPrms->chromaBufSize > 0u)
@@ -838,6 +920,12 @@ static vx_status VX_CALLBACK tivxDisplayControl(
                     (tivx_obj_desc_user_data_object_t *)obj_desc[0U]);
                 break;
             }
+            case TIVX_DISPLAY_SET_PIPE_SAFETY_CHK_PARAMS:
+            {
+                status = tivxDisplaySetPipeSafetyParams(dispPrms,
+                    (tivx_obj_desc_user_data_object_t *)obj_desc[0U]);
+                break;
+            }
             default:
             {
                 VX_PRINT(VX_ZONE_ERROR, "Invalid Command Id\n");
diff --git a/kernels_j7/hwa/host/vx_display_host.c b/kernels_j7/hwa/host/vx_display_host.c
index 4be6a3b..33e8198 100755
--- a/kernels_j7/hwa/host/vx_display_host.c
+++ b/kernels_j7/hwa/host/vx_display_host.c
@@ -187,6 +187,19 @@ static vx_status VX_CALLBACK tivxAddKernelDisplayInitialize(vx_node node,
     return status;
 }
 
+void tivx_dss_safety_chk_params_init(tivx_display_safety_check_params_t *params)
+{
+    params->safetyChkEnable = 0U;
+    params->safetyChkMode = 0U;
+    params->seedSelectEnable = 0U;
+    params->thresholdValue = 0U;
+    params->frameSkip = 0U;
+    params->regionPos.startX = 0U;
+    params->regionPos.startY = 0U;
+    params->regionSize.width = 0U;
+    params->regionSize.height = 0U;
+}
+
 vx_status tivxAddKernelDisplay(vx_context context)
 {
     vx_kernel kernel;
diff --git a/kernels_j7/include/TI/j7_display.h b/kernels_j7/include/TI/j7_display.h
index 9018078..bccb64f 100755
--- a/kernels_j7/include/TI/j7_display.h
+++ b/kernels_j7/include/TI/j7_display.h
@@ -127,6 +127,18 @@ extern "C" {
  */
 #define TIVX_DISPLAY_SET_CROP_PARAMS        (0x30000001u)
 
+/*! \brief Control Command to set the Safety check parameters.
+ *
+ *         The display node supports frame freeze detection and data
+ *         signature check capabilities for each display pipe.
+ *
+ *         This control command uses pointer to structure
+ *         tivx_display_safety_check_params_t as an input argument.
+ *
+ *  \ingroup group_vision_function_display
+ */
+#define TIVX_DISPLAY_SET_PIPE_SAFETY_CHK_PARAMS   (0x30000002u)
+
 /*********************************
  *      Display Defines
  *********************************/
@@ -196,6 +208,82 @@ typedef struct
 } tivx_display_select_channel_params_t;
 
 
+/**
+ *  struct PosConfig
+ *  \brief Structure containing position configuration.
+ */
+typedef struct
+{
+    uint32_t startX;
+    /**< Horizontal offset from which picture needs to be positioned. */
+    uint32_t startY;
+    /**< Vertical offset from which picture needs to be positioned. */
+} PosConfig;
+
+/**
+ *  struct SizeConfig
+ *  \brief Structure containing size configuration.
+ */
+typedef struct
+{
+    uint32_t width;
+    /**< Width of the picture. */
+    uint32_t height;
+    /**< Height of the picture. */
+} SizeConfig;
+
+
+/*! \brief The configuration data structure for setting safety check parameters
+ *
+ *  \ingroup group_vision_function_display
+ */
+typedef struct
+{
+    uint32_t safetyChkEnable;
+    /**< Safety check Enable for the region
+     *   FALSE: Disable Safety Check
+     *   TRUE: Enable Safety Check */
+    uint32_t safetyChkMode;
+    /**< Mode of operation of the safety check module
+     *   For valid values see \ref CSL_DssSafetyChkMode */
+    uint32_t seedSelectEnable;
+    /**< Initial seed selection control
+     *   FALSE: Initial seed is always 0xFFFFFFFF
+     *   TRUE:  Initial seed is defined by SAFETY_LFSR_SEED */
+    uint32_t thresholdValue;
+    /**< Allowed maximum number of frames with the same frame signature.
+     *   When the freeze frame counter reaches thresholdValue+1, a freeze
+     *   frame detection will occur */
+    uint32_t frameSkip;
+    /**< Indicates which frames to be skipped while doing safety checks
+     *   For valid values see \ref CSL_DssSafetyChkFrameSkip */
+    PosConfig regionPos;
+    /**< Position of the safety region described using #PosConfig
+     *
+     *   <b>startX</b>:<br>
+     *   X position of the layer
+     *   The first pixel on the left of the screen has the X-position 0 <br>
+     *
+     *   <b>startY</b>:<br>
+     *   Y position of the layer
+     *   The first pixel at the top has the Y-position 0 <br>
+     */
+    SizeConfig regionSize;
+    /**< Size of the safety region described using #SizeConfig
+     *
+     *   <b>width</b>:<br>
+     *   Width of the safety region
+     *   One pixel wide region has value of 0 <br>
+     *
+     *   <b>height</b>:<br>
+     *   Height of the safety region
+     *   One pixel height region has value of 0 <br>
+     */
+    tivx_display_params_t disp_prm;
+    /**< Private data of application */
+
+} tivx_display_safety_check_params_t;
+
 /*********************************
  *      Function Prototypes
  *********************************/
@@ -212,6 +300,16 @@ void tivxRegisterHwaTargetDisplayKernels(void);
  */
 void tivxUnRegisterHwaTargetDisplayKernels(void);
 
+/*!
+ * \brief Function to initialize DSS safety check parameters
+ *        This initializes parameters to default values.
+ *        This is used for control command: \ref TIVX_DISPLAY_SET_PIPE_SAFETY_CHK_PARAMS
+ *
+ * \param params          [IN] Pointer to DSS safety check parameter structure
+ *
+ * \ingroup group_vision_function_display
+ */
+void tivx_dss_safety_chk_params_init(tivx_display_safety_check_params_t *params);
 
 /*! \brief [Graph] Creates a DSS Display Node.
  *
