c709238313b250bc43614af4880a5b9382e7e9d3
[keystone-rtos/fvid2.git] / src / fvid2_drvMgr.c
1 /*
2  *  Copyright (c) Texas Instruments Incorporated 2018
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions
6  *  are met:
7  *
8  *    Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  *    Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the
14  *    distribution.
15  *
16  *    Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
33 /**
34  *  \file fvid2_drvMgr.c
35  *
36  *  \brief FVID2 driver manager layer.
37  *  This file implements driver management functionality.
38  *
39  */
41 /* ========================================================================== */
42 /*                             Include Files                                  */
43 /* ========================================================================== */
45 /* This is needed for vsnprintf */
46 #include <stdio.h>
47 #include <stdarg.h>
48 #include <ti/drv/fvid2/include/fvid2_drvMgr.h>
50 /* ========================================================================== */
51 /*                           Macros & Typedefs                                */
52 /* ========================================================================== */
54 /** \brief Number of entries in FVID2 standard info table. */
55 #define FDM_NUM_STD_INFO_ENTRIES        (sizeof (gFdmStdInfoTable) / \
56                                          sizeof (Fvid2_ModeInfo))
58 /** \brief Number of entries in FVID2 standard info table. */
59 #define FDM_NUM_DATA_FMT_STR_ENTRIES    (sizeof (gFdmDataFmtStrTable) / \
60                                          sizeof (Fdm_DataFmtString))
62 /** \brief Number of entries in FVID2 standard info table. */
63 #define FDM_NUM_STD_STR_ENTRIES         (sizeof (gFdmStdStrTable) / \
64                                          sizeof (Fdm_StdString))
66 #if defined (FVID2_CFG_TRACE_ENABLE)
67 #define REMOTE_DEBUG_SERVER_PRINT_BUF_LEN        (uint32_t) (1024U * 2U)
68 #endif
70 /* ========================================================================== */
71 /*                         Structure Declarations                             */
72 /* ========================================================================== */
74 /**
75  *  struct Fdm_Driver
76  *  \brief Structure to store driver information.
77  */
78 typedef struct
79 {
80     const Fvid2_DrvOps *drvOps;
81     /**< Driver operation table pointer. */
82     uint32_t            numOpens;
83     /**< Number of times the driver is opened using create API. */
84     uint32_t            isUsed;
85     /**< Flag indicating whether the object is used or not. */
86 } Fdm_Driver;
88 /**
89  *  struct Fdm_Channel
90  *  \brief Structure to store channel information.
91  */
92 typedef struct
93 {
94     Fdm_Driver         *drv;
95     /**< Pointer to the driver object to which this channel is created. */
96     Fdrv_Handle         drvHandle;
97     /**< Driver handle returned by the actual driver. */
98     Fvid2_CbParams      cbParams;
99     /**< Application call back parameters. */
100     uint32_t            isUsed;
101     /**< Flag indicating whether the object is used or not. */
102 } Fdm_Channel;
104 /**
105  *  struct Fdm_DataFmtString
106  *  \brief Structure to store data format and string pair.
107  */
108 typedef struct
110     uint32_t      dataFmt;
111     /**< Data format. Refer \ref Fvid2_DataFormat*/
112     const char    *dataFmtStr;
113     /**< Pointer to data format string. */
114 } Fdm_DataFmtString;
116 /**
117  *  struct Fdm_StdString
118  *  \brief Structure to store standard and string pair.
119  */
120 typedef struct
122     uint32_t      standard;
123     /**< Standard. Refer \ref Fvid2_Standard */
124     const char    *stdStr;
125     /**< Pointer to data format string. */
126 } Fdm_StdString;
128 /**
129  *  struct Fdm_Object
130  *  \brief Struture to store all global objects.
131  */
132 typedef struct
134     char               *versionString;
135     /**< FVID2 drivers version number as string. */
136     uint32_t            versionNumber;
137     /**< FVID2 drivers version number as string. */
138     Fdm_Driver          fdmDriverObjects[FVID2_CFG_FDM_NUM_DRV_OBJS];
139     /**< FDM Driver objects. */
140     Fdm_Channel         fdmChannelObjects[FVID2_CFG_FDM_NUM_CH_OBJS];
141     /**< FDM Channel objects. */
142     SemaphoreP_Handle   lockSem;
143     /**< Semaphore to protect function calls and other memory allocation. */
144 } Fdm_Object;
146 #if defined (FVID2_CFG_TRACE_ENABLE)
147 typedef struct
149     uint32_t    coreId;
150     char        printBuf[REMOTE_DEBUG_SERVER_PRINT_BUF_LEN];
151 } RemoteDebug_ServerObj;
152 #endif
154 /* ========================================================================== */
155 /*                          Function Declarations                             */
156 /* ========================================================================== */
157 /**
158  *  Below ifdef __cplusplus is added so that C++ build passes without
159  *  typecasting. This is because the prototype is build as C type
160  *  whereas this file is build as CPP file. Hence we get C++ build error.
161  *  Also if tyecasting is used, then we get MisraC error Rule 11.1.
162  */
163 #ifdef __cplusplus
164 extern "C" {
165 #endif
166 static int32_t fdmDriverCbFxn(void *fdmData);
167 static int32_t fdmDriverErrCbFxn(void *fdmData, void *errList);
168 static Fdm_Driver *fdmAllocDriverObject(void);
169 static int32_t fdmFreeDriverObject(const Fvid2_DrvOps *drvOps);
170 static Fdm_Channel *fdmAllocChannelObject(void);
171 static int32_t fdmFreeChannelObject(Fdm_Channel *channel);
172 #ifdef __cplusplus
174 #endif
176 /* ========================================================================== */
177 /*                            Global Variables                                */
178 /* ========================================================================== */
180 #if defined (FVID2_CFG_TRACE_ENABLE)
181 static RemoteDebug_ServerObj gRemoteDebug_serverObj = {0};
182 #endif
184 /** \brief FDM init params. */
185 static Fvid2_InitPrms   gFdmInitPrms = {NULL};
187 /** \brief FDM objects. */
188 static Fdm_Object        gFdmObj;
190 /** \brief FVID2 standard information table. */
191 static Fvid2_ModeInfo    gFdmStdInfoTable[] =
193     /* Standard, FrameWidth, FrameHeight, ScanFormat, PixelClock (KHz), FPS */
194     {FVID2_STD_NTSC,           720U,  480U,  FVID2_SF_INTERLACED, 27000U,   30U,
195      0U, 0U, 0U, 0U, 0U, 0U},
196     {FVID2_STD_PAL,            720U,  576U,  FVID2_SF_INTERLACED, 27000U,   25U,
197      0U, 0U, 0U, 0U, 0U, 0U},
198     {FVID2_STD_480I,           720U,  480U,  FVID2_SF_INTERLACED, 27000U,   30U,
199      0U, 0U, 0U, 0U, 0U, 0U},
200     {FVID2_STD_576I,           720U,  576U,  FVID2_SF_INTERLACED, 27000U,   25U,
201      0U, 0U, 0U, 0U, 0U, 0U},
202     {FVID2_STD_480P,           720U,  480U,  FVID2_SF_PROGRESSIVE,27000U,   60U,
203      0U, 0U, 0U, 0U, 0U, 0U},
204     {FVID2_STD_576P,           720U,  576U,  FVID2_SF_PROGRESSIVE,27000U,   50U,
205      0U, 0U, 0U, 0U, 0U, 0U},
206     {FVID2_STD_720P_60,        1280U, 720U,  FVID2_SF_PROGRESSIVE,74250U,   60U,
207      0U, 0U, 0U, 0U, 0U, 0U},
208     {FVID2_STD_720P_50,        1280U, 720U,  FVID2_SF_PROGRESSIVE,74250U,   50U,
209      0U, 0U, 0U, 0U, 0U, 0U},
210     {FVID2_STD_1080I_60,       1920U, 1080U, FVID2_SF_INTERLACED, 74250U,   30U,
211      0U, 0U, 0U, 0U, 0U, 0U},
212     {FVID2_STD_1080I_50,       1920U, 1080U, FVID2_SF_INTERLACED, 74250U,   25U,
213      0U, 0U, 0U, 0U, 0U, 0U},
214     {FVID2_STD_1080P_60,       1920U, 1080U, FVID2_SF_PROGRESSIVE,148500U,  60U,
215      0U, 0U, 0U, 0U, 0U, 0U},
216     {FVID2_STD_1080P_50,       1920U, 1080U, FVID2_SF_PROGRESSIVE,148500U,  50U,
217      0U, 0U, 0U, 0U, 0U, 0U},
218     {FVID2_STD_1080P_24,       1920U, 1080U, FVID2_SF_PROGRESSIVE,74250U,   24U,
219      0U, 0U, 0U, 0U, 0U, 0U},
220     {FVID2_STD_1080P_30,       1920U, 1080U, FVID2_SF_PROGRESSIVE,74250U,   30U,
221      0U, 0U, 0U, 0U, 0U, 0U},
222     {FVID2_STD_VGA_60,         640U,  480U,  FVID2_SF_PROGRESSIVE,25175U,   60U,
223      0U, 0U, 0U, 0U, 0U, 0U},
224     {FVID2_STD_VGA_72,         640U,  480U,  FVID2_SF_PROGRESSIVE,31500U,   72U,
225      0U, 0U, 0U, 0U, 0U, 0U},
226     {FVID2_STD_VGA_75,         640U,  480U,  FVID2_SF_PROGRESSIVE,31500U,   75U,
227      0U, 0U, 0U, 0U, 0U, 0U},
228     {FVID2_STD_VGA_85,         640U,  480U,  FVID2_SF_PROGRESSIVE,36000U,   85U,
229      0U, 0U, 0U, 0U, 0U, 0U},
230     {FVID2_STD_WVGA_60,        800U,  480U,  FVID2_SF_PROGRESSIVE,33500U,   60U,
231      0U, 0U, 0U, 0U, 0U, 0U},
232     {FVID2_STD_SVGA_60,        800U,  600U,  FVID2_SF_PROGRESSIVE,40000U,   60U,
233      0U, 0U, 0U, 0U, 0U, 0U},
234     {FVID2_STD_SVGA_72,        800U,  600U,  FVID2_SF_PROGRESSIVE,50000U,   72U,
235      0U, 0U, 0U, 0U, 0U, 0U},
236     {FVID2_STD_SVGA_75,        800U,  600U,  FVID2_SF_PROGRESSIVE,49500U,   75U,
237      0U, 0U, 0U, 0U, 0U, 0U},
238     {FVID2_STD_SVGA_85,        800U,  600U,  FVID2_SF_PROGRESSIVE,56250U,   85U,
239      0U, 0U, 0U, 0U, 0U, 0U},
240     {FVID2_STD_WSVGA_70,       1024U, 600U,  FVID2_SF_PROGRESSIVE,50800U,   70U,
241      0U, 0U, 0U, 0U, 0U, 0U},
242     {FVID2_STD_XGA_60,         1024U, 768U,  FVID2_SF_PROGRESSIVE,65000U,   60U,
243      0U, 0U, 0U, 0U, 0U, 0U},
244     {FVID2_STD_XGA_DSS_TDM_60, 1024U, 768U,  FVID2_SF_PROGRESSIVE,64000U,   60U,
245      0U, 0U, 0U, 0U, 0U, 0U},
246     {FVID2_STD_XGA_70,         1024U, 768U,  FVID2_SF_PROGRESSIVE,75000U,   70U,
247      0U, 0U, 0U, 0U, 0U, 0U},
248     {FVID2_STD_XGA_75,         1024U, 768U,  FVID2_SF_PROGRESSIVE,78750U,   75U,
249      0U, 0U, 0U, 0U, 0U, 0U},
250     {FVID2_STD_XGA_85,         1024U, 768U,  FVID2_SF_PROGRESSIVE,94500U,   85U,
251      0U, 0U, 0U, 0U, 0U, 0U},
252     {FVID2_STD_WXGA_30,        1280U, 800U,  FVID2_SF_PROGRESSIVE,34125U,   30U,
253      0U, 0U, 0U, 0U, 0U, 0U},
254     {FVID2_STD_WXGA_60,        1280U, 800U,  FVID2_SF_PROGRESSIVE,83500U,   60U,
255      0U, 0U, 0U, 0U, 0U, 0U},
256     {FVID2_STD_WXGA_75,        1280U, 800U,  FVID2_SF_PROGRESSIVE,102250U,  75U,
257      0U, 0U, 0U, 0U, 0U, 0U},
258     {FVID2_STD_WXGA_85,        1280U, 800U,  FVID2_SF_PROGRESSIVE,117500U,  85U,
259      0U, 0U, 0U, 0U, 0U, 0U},
260     {FVID2_STD_1440_900_60,    1440U, 900U,  FVID2_SF_PROGRESSIVE,106500U,  60U,
261      0U, 0U, 0U, 0U, 0U, 0U},
262     {FVID2_STD_1368_768_60,    1368U, 768U,  FVID2_SF_PROGRESSIVE,85860U,   60U,
263      0U, 0U, 0U, 0U, 0U, 0U},
264     {FVID2_STD_1366_768_60,    1366U, 768U,  FVID2_SF_PROGRESSIVE,85500U,   60U,
265      0U, 0U, 0U, 0U, 0U, 0U},
266     {FVID2_STD_1360_768_60,    1360U, 768U,  FVID2_SF_PROGRESSIVE,85500U,   60U,
267      0U, 0U, 0U, 0U, 0U, 0U},
268     {FVID2_STD_SXGA_60,        1280U, 1024U, FVID2_SF_PROGRESSIVE,108000U,  60U,
269      0U, 0U, 0U, 0U, 0U, 0U},
270     {FVID2_STD_SXGA_75,        1280U, 1024U, FVID2_SF_PROGRESSIVE,135000U,  75U,
271      0U, 0U, 0U, 0U, 0U, 0U},
272     {FVID2_STD_SXGA_85,        1280U, 1024U, FVID2_SF_PROGRESSIVE,157500U,  85U,
273      0U, 0U, 0U, 0U, 0U, 0U},
274     {FVID2_STD_WSXGAP_60,      1680U, 1050U, FVID2_SF_PROGRESSIVE,146250U,  60U,
275      0U, 0U, 0U, 0U, 0U, 0U},
276     {FVID2_STD_SXGAP_60,       1400U, 1050U, FVID2_SF_PROGRESSIVE,121750U,  60U,
277      0U, 0U, 0U, 0U, 0U, 0U},
278     {FVID2_STD_SXGAP_75,       1400U, 1050U, FVID2_SF_PROGRESSIVE,156000U,  75U,
279      0U, 0U, 0U, 0U, 0U, 0U},
280     {FVID2_STD_UXGA_60,        1600U, 1200U, FVID2_SF_PROGRESSIVE,162000U,  60U,
281      0U, 0U, 0U, 0U, 0U, 0U},
282     {FVID2_STD_WXGA_5x3_30,    1280U, 800U,  FVID2_SF_PROGRESSIVE,34125U,   30U,
283      0U, 0U, 0U, 0U, 0U, 0U},
284     {FVID2_STD_WXGA_5x3_60,    1280U, 800U,  FVID2_SF_PROGRESSIVE,68250U,   60U,
285      0U, 0U, 0U, 0U, 0U, 0U},
286     {FVID2_STD_WXGA_5x3_75,    1280U, 800U,  FVID2_SF_PROGRESSIVE,102250U,  75U,
287      0U, 0U, 0U, 0U, 0U, 0U}
288 };
290 /** \brief Data format string table. */
291 static Fdm_DataFmtString gFdmDataFmtStrTable[] =
293     {FVID2_DF_YUV422I_UYVY,           "YUV422I_UYVY"          },
294     {FVID2_DF_YUV422I_YUYV,           "YUV422I_YUYV"          },
295     {FVID2_DF_YUV422I_YVYU,           "YUV422I_YVYU"          },
296     {FVID2_DF_YUV422I_VYUY,           "YUV422I_VYUY"          },
297     {FVID2_DF_YUV422SP_UV,            "YUV422SP_UV"           },
298     {FVID2_DF_YUV422SP_VU,            "YUV422SP_VU"           },
299     {FVID2_DF_YUV422P,                "YUV422P"               },
300     {FVID2_DF_YUV420SP_UV,            "YUV420SP_UV"           },
301     {FVID2_DF_YUV420SP_VU,            "YUV420SP_VU"           },
302     {FVID2_DF_YUV420P,                "YUV420P"               },
303     {FVID2_DF_YUV444P,                "YUV444P"               },
304     {FVID2_DF_YUV444I,                "YUV444I"               },
305     {FVID2_DF_RGB16_565,              "RGB16_565"             },
306     {FVID2_DF_ARGB16_1555,            "ARGB16_1555"           },
307     {FVID2_DF_RGBA16_5551,            "RGBA16_5551"           },
308     {FVID2_DF_ARGB16_4444,            "ARGB16_4444"           },
309     {FVID2_DF_RGBA16_4444,            "RGBA16_4444"           },
310     {FVID2_DF_BGRX_4444,              "RGBX12_4444"           },
311     {FVID2_DF_XBGR_4444,              "XRGB12_4444"           },
312     {FVID2_DF_ARGB24_6666,            "ARGB24_6666"           },
313     {FVID2_DF_RGBA24_6666,            "RGBA24_6666"           },
314     {FVID2_DF_RGB24_888,              "RGB24_888"             },
315     {FVID2_DF_XBGR24_8888,            "XBGR24_8888"           },
316     {FVID2_DF_RGBX24_8888,            "RGBX24_8888"           },
317     {FVID2_DF_BGRX24_8888,            "BGRX24_8888"           },
318     {FVID2_DF_ARGB32_8888,            "ARGB32_8888"           },
319     {FVID2_DF_RGBA32_8888,            "RGBA32_8888"           },
320     {FVID2_DF_BGR16_565,              "BGR16_565"             },
321     {FVID2_DF_ABGR16_1555,            "ABGR16_1555"           },
322     {FVID2_DF_ABGR16_4444,            "ABGR16_4444"           },
323     {FVID2_DF_BGRA16_5551,            "BGRA16_5551"           },
324     {FVID2_DF_BGRA16_4444,            "BGRA16_4444"           },
325     {FVID2_DF_AGBR16_1555,            "AGBR16_1555"           },
326     {FVID2_DF_AGBR16_4444,            "AGBR16_4444"           },
327     {FVID2_DF_XGBR16_1555,            "XGBR16_1555"           },
328     {FVID2_DF_BGRX16_5551,            "BGRX16_5551"           },
329     {FVID2_DF_ABGR24_6666,            "ABGR24_6666"           },
330     {FVID2_DF_BGR24_888,              "BGR24_888"             },
331     {FVID2_DF_ABGR32_8888,            "ABGR32_8888"           },
332     {FVID2_DF_BGRA24_6666,            "BGRA24_6666"           },
333     {FVID2_DF_BGRA32_8888,            "BGRA32_8888"           },
334     {FVID2_DF_BITMAP8,                "BITMAP8"               },
335     {FVID2_DF_BITMAP4_LOWER,          "BITMAP4_LOWER"         },
336     {FVID2_DF_BITMAP4_UPPER,          "BITMAP4_UPPER"         },
337     {FVID2_DF_BITMAP2_OFFSET0,        "BITMAP2_OFFSET0"       },
338     {FVID2_DF_BITMAP2_OFFSET1,        "BITMAP2_OFFSET1"       },
339     {FVID2_DF_BITMAP2_OFFSET2,        "BITMAP2_OFFSET2"       },
340     {FVID2_DF_BITMAP2_OFFSET3,        "BITMAP2_OFFSET3"       },
341     {FVID2_DF_BITMAP1_OFFSET0,        "BITMAP1_OFFSET0"       },
342     {FVID2_DF_BITMAP1_OFFSET1,        "BITMAP1_OFFSET1"       },
343     {FVID2_DF_BITMAP1_OFFSET2,        "BITMAP1_OFFSET2"       },
344     {FVID2_DF_BITMAP1_OFFSET3,        "BITMAP1_OFFSET3"       },
345     {FVID2_DF_BITMAP1_OFFSET4,        "BITMAP1_OFFSET4"       },
346     {FVID2_DF_BITMAP1_OFFSET5,        "BITMAP1_OFFSET5"       },
347     {FVID2_DF_BITMAP1_OFFSET6,        "BITMAP1_OFFSET6"       },
348     {FVID2_DF_BITMAP1_OFFSET7,        "BITMAP1_OFFSET7"       },
349     {FVID2_DF_BITMAP8_BGRA32,         "BITMAP8_BGRA32"        },
350     {FVID2_DF_BITMAP4_BGRA32_LOWER,   "BITMAP4_BGRA32_LOWER"  },
351     {FVID2_DF_BITMAP4_BGRA32_UPPER,   "BITMAP4_BGRA32_UPPER"  },
352     {FVID2_DF_BITMAP2_BGRA32_OFFSET0, "BITMAP2_BGRA32_OFFSET0"},
353     {FVID2_DF_BITMAP2_BGRA32_OFFSET1, "BITMAP2_BGRA32_OFFSET1"},
354     {FVID2_DF_BITMAP2_BGRA32_OFFSET2, "BITMAP2_BGRA32_OFFSET2"},
355     {FVID2_DF_BITMAP2_BGRA32_OFFSET3, "BITMAP2_BGRA32_OFFSET3"},
356     {FVID2_DF_BITMAP1_BGRA32_OFFSET0, "BITMAP1_BGRA32_OFFSET0"},
357     {FVID2_DF_BITMAP1_BGRA32_OFFSET1, "BITMAP1_BGRA32_OFFSET1"},
358     {FVID2_DF_BITMAP1_BGRA32_OFFSET2, "BITMAP1_BGRA32_OFFSET2"},
359     {FVID2_DF_BITMAP1_BGRA32_OFFSET3, "BITMAP1_BGRA32_OFFSET3"},
360     {FVID2_DF_BITMAP1_BGRA32_OFFSET4, "BITMAP1_BGRA32_OFFSET4"},
361     {FVID2_DF_BITMAP1_BGRA32_OFFSET5, "BITMAP1_BGRA32_OFFSET5"},
362     {FVID2_DF_BITMAP1_BGRA32_OFFSET6, "BITMAP1_BGRA32_OFFSET6"},
363     {FVID2_DF_BITMAP1_BGRA32_OFFSET7, "BITMAP1_BGRA32_OFFSET7"},
364     {FVID2_DF_BAYER_RAW,              "BAYER_RAW"             },
365     {FVID2_DF_BAYER_GRBG,             "BAYER_GRBG"            },
366     {FVID2_DF_BAYER_RGGB,             "BAYER_RGGB"            },
367     {FVID2_DF_BAYER_BGGR,             "BAYER_BGGR"            },
368     {FVID2_DF_BAYER_GBRG,             "BAYER_GBRG"            },
369     {FVID2_DF_RAW_VBI,                "RAW_VBI"               },
370     {FVID2_DF_RAW24,                  "RAW24"                 },
371     {FVID2_DF_RAW16,                  "RAW16"                 },
372     {FVID2_DF_RAW08,                  "RAW08"                 },
373     {FVID2_DF_BGRX32_8888,            "BGRX32_8888"           },
374     {FVID2_DF_BGRA16_1555,            "BGRA16_1555"           },
375     {FVID2_DF_BGRX16_1555,            "BGRX16_1555"           },
376     {FVID2_DF_BGRA32_1010102,         "BGRA32_1010102"        },
377     {FVID2_DF_BGRX32_1010102,         "BGRX32_1010102"        },
378     {FVID2_DF_RGBA32_1010102,         "RGBA32_1010102"        },
379     {FVID2_DF_RGBX32_1010102,         "RGBX32_1010102"        },
380     {FVID2_DF_BGRA64_16161616,        "BGRA64_16161616"       },
381     {FVID2_DF_BGRX64_16161616,        "BGRX64_16161616"       },
382     {FVID2_DF_ABGR64_16161616,        "ABGR64_16161616"       },
383     {FVID2_DF_XBGR64_16161616,        "XBGR64_16161616"       },
384     {FVID2_DF_XRGB32_8888,            "XRGB32_8888"           },
385     {FVID2_DF_RGBX16_4444,            "RGBX16_4444"           },
386     {FVID2_DF_BGR16_565_A8,           "BRG16_565_A8"          },
387     {FVID2_DF_RGB16_565_A8,           "RGB16_565_A8"          },
388     {FVID2_DF_MISC,                   "MISC"                  },
389     {FVID2_DF_INVALID,                "INVALID"               },
390 };
392 /** \brief Standard string table. */
393 static Fdm_StdString     gFdmStdStrTable[] =
395     {FVID2_STD_NTSC,            "NTSC"           },
396     {FVID2_STD_PAL,             "PAL"            },
397     {FVID2_STD_480I,            "480I"           },
398     {FVID2_STD_576I,            "576I"           },
399     {FVID2_STD_CIF,             "CIF"            },
400     {FVID2_STD_HALF_D1,         "HALF_D1"        },
401     {FVID2_STD_D1,              "D1"             },
402     {FVID2_STD_480P,            "480P"           },
403     {FVID2_STD_576P,            "576P"           },
404     {FVID2_STD_720P_60,         "720P60"         },
405     {FVID2_STD_720P_50,         "720P50"         },
406     {FVID2_STD_1080I_60,        "1080I60"        },
407     {FVID2_STD_1080I_50,        "1080I50"        },
408     {FVID2_STD_1080P_60,        "1080P60"        },
409     {FVID2_STD_1080P_50,        "1080P50"        },
410     {FVID2_STD_1080P_24,        "1080P24"        },
411     {FVID2_STD_1080P_30,        "1080P30"        },
412     {FVID2_STD_VGA_60,          "VGA60"          },
413     {FVID2_STD_VGA_72,          "VGA72"          },
414     {FVID2_STD_VGA_75,          "VGA75"          },
415     {FVID2_STD_VGA_85,          "VGA85"          },
416     {FVID2_STD_WVGA_60,         "WVGA60"         },
417     {FVID2_STD_SVGA_60,         "SVGA60"         },
418     {FVID2_STD_SVGA_72,         "SVGA72"         },
419     {FVID2_STD_SVGA_75,         "SVGA75"         },
420     {FVID2_STD_SVGA_85,         "SVGA85"         },
421     {FVID2_STD_WSVGA_70,        "WSVGA70"        },
422     {FVID2_STD_XGA_60,          "XGA60"          },
423     {FVID2_STD_XGA_DSS_TDM_60,  "XGA_DSS_TDM_60" },
424     {FVID2_STD_XGA_70,          "XGA70"          },
425     {FVID2_STD_XGA_75,          "XGA75"          },
426     {FVID2_STD_XGA_85,          "XGA85"          },
427     {FVID2_STD_WXGA_30,         "WXGA30"         },
428     {FVID2_STD_WXGA_60,         "WXGA60"         },
429     {FVID2_STD_WXGA_75,         "WXGA75"         },
430     {FVID2_STD_WXGA_85,         "WXGA85"         },
431     {FVID2_STD_1440_900_60,     "1440X900@60"    },
432     {FVID2_STD_1368_768_60,     "1368X768@60"    },
433     {FVID2_STD_1366_768_60,     "1366X768@60"    },
434     {FVID2_STD_1360_768_60,     "1360X768@60"    },
435     {FVID2_STD_SXGA_60,         "SXGA60"         },
436     {FVID2_STD_SXGA_75,         "SXGA75"         },
437     {FVID2_STD_SXGA_85,         "SXGA85"         },
438     {FVID2_STD_WSXGAP_60,       "WSXGAP60"       },
439     {FVID2_STD_SXGAP_60,        "SXGAP60"        },
440     {FVID2_STD_SXGAP_75,        "SXGAP75"        },
441     {FVID2_STD_UXGA_60,         "UXGA60"         },
442     {FVID2_STD_MUX_2CH_D1,      "MUX_2CH_D1"     },
443     {FVID2_STD_MUX_2CH_HALF_D1, "MUX_2CH_HALF_D1"},
444     {FVID2_STD_MUX_2CH_CIF,     "MUX_2CH_CIF"    },
445     {FVID2_STD_MUX_4CH_D1,      "MUX_4CH_D1"     },
446     {FVID2_STD_MUX_4CH_CIF,     "MUX_4CH_CIF"    },
447     {FVID2_STD_MUX_4CH_HALF_D1, "MUX_4CH_HALF_D1"},
448     {FVID2_STD_MUX_8CH_CIF,     "MUX_8CH_CIF"    },
449     {FVID2_STD_MUX_8CH_HALF_D1, "MUX_8CH_HALF_D1"},
450     {FVID2_STD_WXGA_5x3_30,     "WXGA_5x3_30"    },
451     {FVID2_STD_WXGA_5x3_60,     "WXGA_5x3_60"    },
452     {FVID2_STD_WXGA_5x3_75,     "WXGA_5x3_75"    },
453     {FVID2_STD_AUTO_DETECT,     "AUTO_DETECT"    },
454     {FVID2_STD_CUSTOM,          "CUSTOM"         },
455 };
457 /* ========================================================================== */
458 /*                          Function Definitions                              */
459 /* ========================================================================== */
461 /**
462  *  Fvid2_init
463  *  \brief FVID2 init function.
464  *
465  *  Initializes the drivers and the hardware.
466  *  This function should be called before calling any of driver API's.
467  *
468  *  \param arg          Not used currently. Meant for future purpose.
469  *
470  *  \return             Returns 0 on success else returns error value.
471  */
472 int32_t Fvid2_init(const Fvid2_InitPrms *initPrms)
474     uint32_t cnt;
475     int32_t  retVal = FVID2_SOK;
476     int32_t  initValue;
477     SemaphoreP_Params params;
479     Fvid2InitPrms_init(&gFdmInitPrms);
480     if (NULL != initPrms)
481     {
482         Fvid2Utils_memcpy(&gFdmInitPrms, initPrms, sizeof (gFdmInitPrms));
483     }
485     /* Init all global variables to zero */
486     Fvid2Utils_memset(&gFdmObj, 0U, sizeof (gFdmObj));
488     /* Mark pool flags as free */
489     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
490     {
491         gFdmObj.fdmDriverObjects[cnt].isUsed = (uint32_t) FALSE;
492     }
493     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_CH_OBJS; cnt++)
494     {
495         gFdmObj.fdmChannelObjects[cnt].isUsed = (uint32_t) FALSE;
496     }
498     gFdmObj.versionString = FVID2_VERSION_STRING;
499     gFdmObj.versionNumber = FVID2_VERSION_NUMBER;
501     /* Allocate lock semaphore */
502     SemaphoreP_Params_init(&params);
503     params.mode = SemaphoreP_Mode_BINARY;
504     initValue       = 1;
505     gFdmObj.lockSem = SemaphoreP_create(initValue, &params);
506     if (NULL == gFdmObj.lockSem)
507     {
508         GT_0trace(Fvid2Trace, GT_ERR, "FVID2 semaphore create failed!!\r\n");
509         retVal = FVID2_EALLOC;
510     }
512     /* Free-up memory if error occurs */
513     if (FVID2_SOK != retVal)
514     {
515         Fvid2_deInit(NULL);
516     }
518     return (retVal);
521 /**
522  *  Fvid2_deInit
523  *  \brief FVID2 deinit function.
524  *
525  *  Uninitializes the drivers and the hardware.
526  *
527  *  \param arg          Not used currently. Meant for future purpose.
528  *
529  *  \return             Returns 0 on success else returns error value.
530  */
531 int32_t Fvid2_deInit(void *args)
533     int32_t retVal = FVID2_SOK;
535     /* Delete the lock semaphore */
536     if (NULL != gFdmObj.lockSem)
537     {
538         SemaphoreP_delete(gFdmObj.lockSem);
539         gFdmObj.lockSem = NULL;
540     }
542     return (retVal);
545 /**
546  *  Fvid2_getVersionString
547  *  \brief Get the FVID2 driver version in string form. This API can be
548  *  called before calling #Fvid2_init().
549  *
550  *  \return             Returns pointer to FVID2 version string.
551  */
552 const char *Fvid2_getVersionString(void)
554     return (FVID2_VERSION_STRING);
557 /**
558  *  Fvid2_getVersionNumber
559  *  \brief Get the FVID2 driver version in number form. This API can be
560  *  called before calling #Fvid2_init().
561  *
562  *  \return             FVID2 version number.
563  */
564 uint32_t Fvid2_getVersionNumber(void)
566     return (FVID2_VERSION_NUMBER);
569 /**
570  *  Fvid2_registerDriver
571  *  \brief FVID2 register driver function.
572  */
573 int32_t Fvid2_registerDriver(const Fvid2_DrvOps *drvOps)
575     int32_t     retVal = FVID2_SOK;
576     Fdm_Driver *drv;
577     uint32_t    cnt;
579     /* Check for NULL pointers */
580     OSAL_Assert(NULL == drvOps);
582     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
584     /* Check whether the driver is already registered */
585     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
586     {
587         if (TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed)
588         {
589             /* Check for NULL pointers */
590             OSAL_Assert(NULL == gFdmObj.fdmDriverObjects[cnt].drvOps);
592             if (drvOps->drvId == gFdmObj.fdmDriverObjects[cnt].drvOps->drvId)
593             {
594                 GT_0trace(Fvid2Trace, GT_ERR,
595                           "Driver with same id already registered!!\r\n");
596                 retVal = FVID2_EDRIVER_INUSE;
597                 break;
598             }
599         }
600     }
602     if (FVID2_SOK == retVal)
603     {
604         /* Get a free driver object */
605         drv = fdmAllocDriverObject();
606         if (NULL != drv)
607         {
608             drv->drvOps   = drvOps;
609             drv->numOpens = 0U;
610         }
611         else
612         {
613             GT_0trace(Fvid2Trace, GT_ERR, "Alloc driver object failed!!\r\n");
614             retVal = FVID2_EALLOC;
615         }
616     }
618     SemaphoreP_post(gFdmObj.lockSem);
620     return (retVal);
623 /**
624  *  Fvid2_unRegisterDriver
625  *  \brief FVID2 unregister driver function.
626  */
627 int32_t Fvid2_unRegisterDriver(const Fvid2_DrvOps *drvOps)
629     int32_t retVal = FVID2_EFAIL;
631     /* Check for NULL pointers */
632     OSAL_Assert(NULL == drvOps);
634     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
636     /* Free the driver object */
637     retVal = fdmFreeDriverObject(drvOps);
639     SemaphoreP_post(gFdmObj.lockSem);
641     return (retVal);
644 /**
645  *  Fvid2_create
646  *  \brief Opens the driver identified by the driver ID.
647  */
648 Fvid2_Handle Fvid2_create(uint32_t              drvId,
649                           uint32_t              instanceId,
650                           void                 *createArgs,
651                           void                 *createStatusArgs,
652                           const Fvid2_CbParams *cbParams)
654     Fdm_Driver       *drv = NULL;
655     uint32_t          cnt;
656     Fdrv_Handle       drvHandle = NULL;
657     Fdm_Channel      *channel   = NULL;
658     Fvid2_DrvCbParams fdmCbParams, *tempCbParams;
660     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
662     /* Get the matching driver object */
663     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
664     {
665         if (TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed)
666         {
667             /* Check for NULL pointers */
668             OSAL_Assert(NULL == gFdmObj.fdmDriverObjects[cnt].drvOps);
670             if (drvId == gFdmObj.fdmDriverObjects[cnt].drvOps->drvId)
671             {
672                 drv = &gFdmObj.fdmDriverObjects[cnt];
673                 /* Allocate channel object */
674                 channel = fdmAllocChannelObject();
675                 break;
676             }
677         }
678     }
680     if (NULL != channel)
681     {
682         if (NULL != drv->drvOps->createFxn)
683         {
684             if (NULL != cbParams)
685             {
686                 if (NULL != cbParams->cbFxn)
687                 {
688                     fdmCbParams.fdmCbFxn = &fdmDriverCbFxn;
689                 }
690                 else
691                 {
692                     fdmCbParams.fdmCbFxn = NULL;
693                 }
694                 if (NULL != cbParams->errCbFxn)
695                 {
696                     fdmCbParams.fdmErrCbFxn = &fdmDriverErrCbFxn;
697                 }
698                 else
699                 {
700                     fdmCbParams.fdmErrCbFxn = NULL;
701                 }
703                 fdmCbParams.handle   = channel;
704                 fdmCbParams.errList  = cbParams->errList;
705                 fdmCbParams.fdmData  = channel;
706                 tempCbParams         = &fdmCbParams;
707             }
708             else
709             {
710                 tempCbParams = NULL;
711             }
713             /* Call the driver's create function */
714             drvHandle = drv->drvOps->createFxn(
715                 drvId,
716                 instanceId,
717                 createArgs,
718                 createStatusArgs,
719                 tempCbParams);
720         }
721         else
722         {
723             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
724         }
726         if (NULL != drvHandle)
727         {
728             drv->numOpens++;
730             channel->drv       = drv;
731             channel->drvHandle = drvHandle;
732             Fvid2CbParams_init(&channel->cbParams);
733             if (NULL != cbParams)
734             {
735                 Fvid2Utils_memcpy(
736                     &channel->cbParams,
737                     cbParams,
738                     sizeof (Fvid2_CbParams));
739             }
740         }
741         else
742         {
743             GT_0trace(Fvid2Trace, GT_ERR, "Driver create failed!!\r\n");
745             /* Free the allocated channel object */
746             fdmFreeChannelObject(channel);
747             channel = NULL;
748         }
749     }
750     else
751     {
752         GT_0trace(Fvid2Trace, GT_ERR, "EALLOC: Invalid driver ID!!\r\n");
753     }
755     SemaphoreP_post(gFdmObj.lockSem);
757     return (channel);
760 /**
761  *  Fvid2_delete
762  *  \brief Application calls Fvid2_delete to close the logical channel
763  *  associated with FVID2 handle.
764  */
765 int32_t Fvid2_delete(Fvid2_Handle handle, void *deleteArgs)
767     int32_t      retVal = FVID2_SOK;
768     Fdm_Channel *channel;
770     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
772     if (NULL != handle)
773     {
774         channel = (Fdm_Channel *) handle;
776         /* Check for NULL pointers */
777         OSAL_Assert(NULL == channel->drv);
778         OSAL_Assert(NULL == channel->drv->drvOps);
780         if (NULL != channel->drv->drvOps->deleteFxn)
781         {
782             /* Call the driver's delete function */
783             retVal = channel->drv->drvOps->deleteFxn(
784                 channel->drvHandle,
785                 deleteArgs);
786         }
787         else
788         {
789             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
790         }
792         channel->drv->numOpens--;
793         /* Free the allocated channel object */
794         channel->drv               = NULL;
795         channel->drvHandle         = NULL;
796         channel->cbParams.cbFxn    = NULL;
797         channel->cbParams.errCbFxn = NULL;
798         channel->cbParams.errList  = NULL;
799         channel->cbParams.appData  = NULL;
800         fdmFreeChannelObject(channel);
801     }
802     else
803     {
804         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
805         retVal = FVID2_EBADARGS;
806     }
808     SemaphoreP_post(gFdmObj.lockSem);
810     return (retVal);
813 /**
814  *  Fvid2_control
815  *  \brief An application calls Fvid2_control to send device-specific control
816  *  commands to the video driver.
817  */
818 int32_t Fvid2_control(Fvid2_Handle  handle,
819                       uint32_t      cmd,
820                       void         *cmdArgs,
821                       void         *cmdStatusArgs)
823     int32_t      retVal = FVID2_SOK;
824     Fdm_Channel *channel;
826     if (NULL != handle)
827     {
828         channel = (Fdm_Channel *) handle;
830         /* Check for NULL pointers */
831         OSAL_Assert(NULL == channel->drv);
832         OSAL_Assert(NULL == channel->drv->drvOps);
834         if (NULL != channel->drv->drvOps->controlFxn)
835         {
836             /* Call the driver's control function */
837             retVal = channel->drv->drvOps->controlFxn(
838                 channel->drvHandle,
839                 cmd,
840                 cmdArgs,
841                 cmdStatusArgs);
842         }
843         else
844         {
845             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
846             retVal = FVID2_EUNSUPPORTED_OPS;
847         }
848     }
849     else
850     {
851         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
852         retVal = FVID2_EBADARGS;
853     }
855     return (retVal);
858 /**
859  *  Fvid2_queue
860  *  \brief An application calls Fvid2_queue to submit a video buffer to the
861  *  video device driver.
862  *  This is used in capture/display drivers.
863  */
864 int32_t Fvid2_queue(Fvid2_Handle     handle,
865                     Fvid2_FrameList *frameList,
866                     uint32_t         streamId)
868     int32_t      retVal = FVID2_SOK;
869     Fdm_Channel *channel;
871     if (NULL != handle)
872     {
873         channel = (Fdm_Channel *) handle;
875         /* Check for NULL pointers */
876         OSAL_Assert(NULL == channel->drv);
877         OSAL_Assert(NULL == channel->drv->drvOps);
879         if (NULL != channel->drv->drvOps->queueFxn)
880         {
881             /* Call the driver's queue function */
882             retVal = channel->drv->drvOps->queueFxn(
883                 channel->drvHandle,
884                 frameList,
885                 streamId);
886         }
887         else
888         {
889             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
890             retVal = FVID2_EUNSUPPORTED_OPS;
891         }
892     }
893     else
894     {
895         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
896         retVal = FVID2_EBADARGS;
897     }
899     return (retVal);
902 /**
903  *  Fvid2_dequeue
904  *  \brief An application calls Fvid2_dequeue to request the video device
905  *  driver to give ownership of a video buffer.
906  *  This is used in capture/display drivers.
907  */
908 int32_t Fvid2_dequeue(Fvid2_Handle      handle,
909                       Fvid2_FrameList  *frameList,
910                       uint32_t          streamId,
911                       uint32_t          timeout)
913     int32_t      retVal = FVID2_SOK;
914     Fdm_Channel *channel;
916     if (NULL != handle)
917     {
918         channel = (Fdm_Channel *) handle;
920         /* Check for NULL pointers */
921         OSAL_Assert(NULL == channel->drv);
922         OSAL_Assert(NULL == channel->drv->drvOps);
924         if (NULL != channel->drv->drvOps->dequeueFxn)
925         {
926             /* Call the driver's dequeue function */
927             retVal = channel->drv->drvOps->dequeueFxn(
928                 channel->drvHandle,
929                 frameList,
930                 streamId,
931                 timeout);
932         }
933         else
934         {
935             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
936             retVal = FVID2_EUNSUPPORTED_OPS;
937         }
938     }
939     else
940     {
941         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
942         retVal = FVID2_EBADARGS;
943     }
945     return (retVal);
948 /**
949  *  Fvid2_processRequest
950  *  \brief An application calls Fvid2_processRequest to submit a video buffer
951  *  to the video device driver.
952  */
953 int32_t Fvid2_processRequest(Fvid2_Handle     handle,
954                              Fvid2_FrameList *inFrameList,
955                              Fvid2_FrameList *outFrameList)
957     int32_t      retVal = FVID2_SOK;
958     Fdm_Channel *channel;
960     if (NULL != handle)
961     {
962         channel = (Fdm_Channel *) handle;
964         /* Check for NULL pointers */
965         OSAL_Assert(NULL == channel->drv);
966         OSAL_Assert(NULL == channel->drv->drvOps);
968         if (NULL != channel->drv->drvOps->processRequestFxn)
969         {
970             /* Call the driver's process frame function */
971             retVal = channel->drv->drvOps->processRequestFxn(
972                 channel->drvHandle,
973                 inFrameList,
974                 outFrameList);
975         }
976         else
977         {
978             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
979             retVal = FVID2_EUNSUPPORTED_OPS;
980         }
981     }
982     else
983     {
984         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
985         retVal = FVID2_EBADARGS;
986     }
988     return (retVal);
991 /**
992  *  Fvid2_getProcessedRequest
993  *  \brief An application calls Fvid2_getProcessedRequest to request the video
994  *  device driver to give ownership of a video buffer.
995  */
996 int32_t Fvid2_getProcessedRequest(Fvid2_Handle     handle,
997                                   Fvid2_FrameList *inFrameList,
998                                   Fvid2_FrameList *outFrameList,
999                                   uint32_t         timeout)
1001     int32_t      retVal = FVID2_SOK;
1002     Fdm_Channel *channel;
1004     if (NULL != handle)
1005     {
1006         channel = (Fdm_Channel *) handle;
1008         /* Check for NULL pointers */
1009         OSAL_Assert(NULL == channel->drv);
1010         OSAL_Assert(NULL == channel->drv->drvOps);
1012         if (NULL != channel->drv->drvOps->getProcessedRequestFxn)
1013         {
1014             /* Call the driver's get process frame function */
1015             retVal = channel->drv->drvOps->getProcessedRequestFxn(
1016                 channel->drvHandle,
1017                 inFrameList,
1018                 outFrameList,
1019                 timeout);
1020         }
1021         else
1022         {
1023             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
1024             retVal = FVID2_EUNSUPPORTED_OPS;
1025         }
1026     }
1027     else
1028     {
1029         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
1030         retVal = FVID2_EBADARGS;
1031     }
1033     return (retVal);
1036 /**
1037  *  Fvid2_getModeInfo
1038  *  \brief Function to get the information about various FVID2 modes/standards.
1039  */
1040 int32_t Fvid2_getModeInfo(Fvid2_ModeInfo *modeInfo)
1042     int32_t         retVal = FVID2_SOK;
1043     uint32_t        entryCnt;
1044     Fvid2_ModeInfo *matchedEntry = NULL;
1046     if (NULL != modeInfo)
1047     {
1048         for (entryCnt = 0U; entryCnt < FDM_NUM_STD_INFO_ENTRIES; entryCnt++)
1049         {
1050             if (gFdmStdInfoTable[entryCnt].standard == modeInfo->standard)
1051             {
1052                 matchedEntry = &gFdmStdInfoTable[entryCnt];
1053                 break;
1054             }
1055         }
1057         if (NULL == matchedEntry)
1058         {
1059             GT_0trace(Fvid2Trace, GT_ERR, "Unsupported standard!!\r\n");
1060             retVal = FVID2_EINVALID_PARAMS;
1061         }
1062         else
1063         {
1064             Fvid2Utils_memcpy(modeInfo, matchedEntry, sizeof (Fvid2_ModeInfo));
1065         }
1066     }
1067     else
1068     {
1069         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
1070         retVal = FVID2_EBADARGS;
1071     }
1073     return (retVal);
1076 /**
1077  *  \brief Function to get the name of the data format in printable string.
1078  *
1079  *  \param dataFmt      [IN] Data format to get the name.
1080  *                           For valid values see #Fvid2_DataFormat.
1081  *
1082  *  \return Returns a const pointer to the string. If the data format is not
1083  *  known, then it return the string as "UNKNOWN".
1084  */
1085 const char *Fvid2_getDataFmtString(uint32_t dataFmt)
1087     uint32_t    entryCnt;
1088     const char *dataFmtStr = NULL;
1090     for (entryCnt = 0U; entryCnt < FDM_NUM_DATA_FMT_STR_ENTRIES; entryCnt++)
1091     {
1092         if (gFdmDataFmtStrTable[entryCnt].dataFmt == dataFmt)
1093         {
1094             dataFmtStr = gFdmDataFmtStrTable[entryCnt].dataFmtStr;
1095             break;
1096         }
1097     }
1099     if (NULL == dataFmtStr)
1100     {
1101         dataFmtStr = "UNKNOWN";
1102     }
1104     return (dataFmtStr);
1107 /**
1108  *  \brief Function to get the name of the standard in printable string.
1109  *
1110  *  \param standard     [IN] Standard to get the name.
1111  *                           For valid values see #Fvid2_Standard.
1112  *
1113  *  \return Returns a const pointer to the string. If the standard is not
1114  *  known, then it return the string as "UNKNOWN".
1115  */
1116 const char *Fvid2_getStandardString(uint32_t standard)
1118     uint32_t    entryCnt;
1119     const char *stdStr = NULL;
1121     for (entryCnt = 0U; entryCnt < FDM_NUM_STD_STR_ENTRIES; entryCnt++)
1122     {
1123         if (gFdmStdStrTable[entryCnt].standard == standard)
1124         {
1125             stdStr = gFdmStdStrTable[entryCnt].stdStr;
1126             break;
1127         }
1128     }
1130     if (NULL == stdStr)
1131     {
1132         stdStr = "UNKNOWN";
1133     }
1135     return (stdStr);
1138 /**
1139  *  Fvid2_checkFrameList
1140  *  \brief Checks the FVID2 frame list for error and returns appropriate error.
1141  *  This is used by the drivers and not by the application.
1142  */
1143 int32_t Fvid2_checkFrameList(const Fvid2_FrameList *frameList,
1144                              uint32_t maxFrames)
1146     int32_t  retVal = FVID2_SOK;
1147     uint32_t frmCnt;
1149     /* Check for NULL pointer */
1150     if (NULL == frameList)
1151     {
1152         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
1153         retVal = FVID2_EBADARGS;
1154     }
1155     else
1156     {
1157         /* Check whether num frames is within range */
1158         if (frameList->numFrames > maxFrames)
1159         {
1160             GT_0trace(Fvid2Trace, GT_ERR, "Number of frames exceeds max!!\r\n");
1161             retVal = FVID2_EOUT_OF_RANGE;
1162         }
1164         /* Check whether num frames is within range */
1165         if (frameList->numFrames > FVID2_MAX_FRAME_PTR)
1166         {
1167             GT_0trace(Fvid2Trace, GT_ERR,
1168                       "Number of frames exceeds FVID2 max!!\r\n");
1169             retVal = FVID2_EOUT_OF_RANGE;
1170         }
1172         /* Check whether num frames is zero */
1173         if (0U == frameList->numFrames)
1174         {
1175             GT_0trace(Fvid2Trace, GT_ERR, "Number of frames is zero!!\r\n");
1176             retVal = FVID2_EOUT_OF_RANGE;
1177         }
1179         if (FVID2_SOK == retVal)
1180         {
1181             /* Check the individual frame pointers */
1182             for (frmCnt = 0U; frmCnt < frameList->numFrames; frmCnt++)
1183             {
1184                 /* Check for NULL pointer */
1185                 if (NULL == frameList->frames[frmCnt])
1186                 {
1187                     GT_0trace(Fvid2Trace, GT_ERR,
1188                               "EBADARGS: NULL pointer!!\r\n");
1189                     retVal = FVID2_EBADARGS;
1190                     break;
1191                 }
1192             }
1193         }
1194     }
1196     return (retVal);
1199 /**
1200  *  Fvid2_checkDqFrameList
1201  *  \brief Checks the FVID2 frame list of dequeue call for error and returns
1202  *  appropriate error. For dequeue operation, the frame pointers in the frames
1203  *  should not be checked as this will be filled by the driver.
1204  *  This is used by the drivers and not by the application.
1205  */
1206 int32_t Fvid2_checkDqFrameList(const Fvid2_FrameList *frameList,
1207                                uint32_t               maxFrames)
1209     int32_t retVal = FVID2_SOK;
1211     /* Check for NULL pointer */
1212     if (NULL == frameList)
1213     {
1214         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
1215         retVal = FVID2_EBADARGS;
1216     }
1217     else
1218     {
1219         /* Check whether max frames is within range */
1220         if (maxFrames > FVID2_MAX_FRAME_PTR)
1221         {
1222             GT_0trace(Fvid2Trace, GT_ERR,
1223                       "Number of frames exceeds FVID2 max!!\r\n");
1224             retVal = FVID2_EOUT_OF_RANGE;
1225         }
1226     }
1228     return (retVal);
1231 /**
1232  *  Fvid2_copyFrameList
1233  *  \brief Copies the source frame list to the destination frame list.
1234  *  This also resets the frame pointers from the source frame list.
1235  *  This is used by the drivers and not by the application.
1236  */
1237 void Fvid2_copyFrameList(Fvid2_FrameList *dest, Fvid2_FrameList *src)
1239     uint32_t frmCnt;
1241     /* Check for NULL pointers */
1242     OSAL_Assert(NULL == dest);
1243     OSAL_Assert(NULL == src);
1244     OSAL_Assert(src->numFrames >= FVID2_MAX_FRAME_PTR);
1246     dest->numFrames  = src->numFrames;
1247     dest->drvData    = src->drvData;
1249     /* Copy the individual frames */
1250     for (frmCnt = 0U; frmCnt < src->numFrames; frmCnt++)
1251     {
1252         dest->frames[frmCnt] = src->frames[frmCnt];
1253         src->frames[frmCnt]  = NULL;
1254     }
1256     return;
1259 /**
1260  *  Fvid2_duplicateFrameList
1261  *  \brief Duplicate the source frame list to the destination frame list.
1262  *  This does not reset the frame pointers from the source frame list.
1263  *  This is used by the drivers and not by the application.
1264  */
1265 void Fvid2_duplicateFrameList(Fvid2_FrameList *dest, const Fvid2_FrameList *src)
1267     uint32_t frmCnt;
1269     /* Check for NULL pointers */
1270     OSAL_Assert(NULL == dest);
1271     OSAL_Assert(NULL == src);
1272     OSAL_Assert(src->numFrames >= FVID2_MAX_FRAME_PTR);
1274     dest->numFrames  = src->numFrames;
1275     dest->drvData    = src->drvData;
1277     /* Duplicate the individual frames */
1278     for (frmCnt = 0U; frmCnt < src->numFrames; frmCnt++)
1279     {
1280         dest->frames[frmCnt] = src->frames[frmCnt];
1281     }
1283     return;
1286 /**
1287  *  fdmDriverCbFxn
1288  *  \brief FVID2 driver manager driver callback function. Whenever the drivers
1289  *  wants to call the application callback function, this function will be
1290  *  called by the driver and FDM will in turn call the application callback
1291  *  function.
1292  *  This is used by the drivers and not by the application.
1293  */
1294 static int32_t fdmDriverCbFxn(void *fdmData)
1296     int32_t      retVal;
1297     Fdm_Channel *channel;
1299     /* Check for NULL pointers */
1300     OSAL_Assert(NULL == fdmData);
1302     channel = (Fdm_Channel *) fdmData;
1303     OSAL_Assert(NULL == channel->cbParams.cbFxn);
1304     retVal = channel->cbParams.cbFxn(channel, channel->cbParams.appData);
1306     return (retVal);
1309 /**
1310  *  fdmDriverErrCbFxn
1311  *  \brief FVID2 driver manager driver error callback function.
1312  *  Whenever the drivers wants to call the application error callback function,
1313  *  this function will be called by the driver and FDM will in turn call the
1314  *  application error callback function.
1315  *  This is used by the drivers and not by the application.
1316  */
1317 static int32_t fdmDriverErrCbFxn(void *fdmData, void *errList)
1319     int32_t      retVal;
1320     Fdm_Channel *channel;
1322     /* Check for NULL pointers */
1323     OSAL_Assert(NULL == fdmData);
1325     channel = (Fdm_Channel *) fdmData;
1326     OSAL_Assert(NULL == channel->cbParams.errCbFxn);
1327     retVal =
1328         channel->cbParams.errCbFxn(channel, channel->cbParams.appData, errList);
1330     return (retVal);
1333 /**
1334  *  fdmAllocDriverObject
1335  *  \brief Allocate memory for driver object from static memory pool.
1336  *  Returns NULL if memory pool is full.
1337  */
1338 static Fdm_Driver *fdmAllocDriverObject(void)
1340     uint32_t    cnt;
1341     Fdm_Driver *drv = NULL;
1343     /* Get a free driver object */
1344     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
1345     {
1346         if (FALSE == gFdmObj.fdmDriverObjects[cnt].isUsed)
1347         {
1348             drv         = &gFdmObj.fdmDriverObjects[cnt];
1349             drv->isUsed = (uint32_t) TRUE;
1350             break;
1351         }
1352     }
1354     return (drv);
1357 /**
1358  *  fdmFreeDriverObject
1359  *  \brief Free-up the memory allocated for driver object.
1360  */
1361 static int32_t fdmFreeDriverObject(const Fvid2_DrvOps *drvOps)
1363     uint32_t cnt;
1364     int32_t  retVal = FVID2_EFAIL;
1366     /* Check for NULL pointers */
1367     OSAL_Assert(NULL == drvOps);
1369     /* Free the driver object */
1370     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
1371     {
1372         if ((TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed) &&
1373             (drvOps == gFdmObj.fdmDriverObjects[cnt].drvOps))
1374         {
1375             if (0u == gFdmObj.fdmDriverObjects[cnt].numOpens)
1376             {
1377                 gFdmObj.fdmDriverObjects[cnt].isUsed   = (uint32_t) FALSE;
1378                 gFdmObj.fdmDriverObjects[cnt].drvOps   = NULL;
1379                 gFdmObj.fdmDriverObjects[cnt].numOpens = 0u;
1380                 retVal = FVID2_SOK;
1381             }
1382             else
1383             {
1384                 GT_0trace(Fvid2Trace, GT_ERR, "Driver in use!!\r\n");
1385                 retVal = FVID2_EDEVICE_INUSE;
1386             }
1387             break;
1388         }
1389     }
1391     if (FVID2_EFAIL == retVal)
1392     {
1393         GT_0trace(Fvid2Trace, GT_ERR, "Driver ops not found!!\r\n");
1394     }
1396     return (retVal);
1399 /**
1400  *  fdmAllocChannelObject
1401  *  \brief Allocate memory for channel object from static memory pool.
1402  *  Returns NULL if memory pool is full.
1403  */
1404 static Fdm_Channel *fdmAllocChannelObject(void)
1406     uint32_t       cnt;
1407     Fdm_Channel *channel = NULL;
1409     /* Get a free channel object */
1410     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_CH_OBJS; cnt++)
1411     {
1412         if (FALSE == gFdmObj.fdmChannelObjects[cnt].isUsed)
1413         {
1414             channel         = &gFdmObj.fdmChannelObjects[cnt];
1415             channel->isUsed = (uint32_t) TRUE;
1416             break;
1417         }
1418     }
1420     return (channel);
1423 /**
1424  *  fdmFreeChannelObject
1425  *  \brief Free-up the memory allocated for channel object.
1426  */
1427 static int32_t fdmFreeChannelObject(Fdm_Channel *channel)
1429     int32_t retVal = FVID2_EALLOC;
1431     /* Check for NULL pointers */
1432     OSAL_Assert(NULL == channel);
1434     /* Free the channel object */
1435     if (TRUE == channel->isUsed)
1436     {
1437         channel->isUsed = (uint32_t) FALSE;
1438         retVal          = FVID2_SOK;
1439     }
1440     else
1441     {
1442         GT_0trace(Fvid2Trace, GT_ERR,
1443                   "Freeing a channel object not in use!!\r\n");
1444     }
1446     return (retVal);
1449 void Fvid2_printf(const char *format, ...)
1451 #if defined (FVID2_CFG_TRACE_ENABLE)
1452     va_list     vaArgPtr;
1453     uintptr_t   cookie;
1454     char       *buf = NULL;
1456     cookie = HwiP_disable();
1458     buf = &gRemoteDebug_serverObj.printBuf[0];
1459     va_start(vaArgPtr, format);
1460     vsnprintf(buf, REMOTE_DEBUG_SERVER_PRINT_BUF_LEN,
1461               (const char *) format, vaArgPtr);
1462     va_end(vaArgPtr);
1464     HwiP_restore(cookie);
1466     if(gFdmInitPrms.printFxn != NULL)
1467     {
1468         gFdmInitPrms.printFxn(buf);
1469     }
1470 #endif
1471     return;