Bug Fix: PDK-3358
[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     SemaphoreP_Handle   printSem;
145     /**< Semaphore to protect print buffer. */
146 } Fdm_Object;
148 #if defined (FVID2_CFG_TRACE_ENABLE)
149 typedef struct
151     uint32_t    coreId;
152     char        printBuf[REMOTE_DEBUG_SERVER_PRINT_BUF_LEN];
153 } RemoteDebug_ServerObj;
154 #endif
156 /* ========================================================================== */
157 /*                          Function Declarations                             */
158 /* ========================================================================== */
159 /**
160  *  Below ifdef __cplusplus is added so that C++ build passes without
161  *  typecasting. This is because the prototype is build as C type
162  *  whereas this file is build as CPP file. Hence we get C++ build error.
163  *  Also if tyecasting is used, then we get MisraC error Rule 11.1.
164  */
165 #ifdef __cplusplus
166 extern "C" {
167 #endif
168 static int32_t fdmDriverCbFxn(void *fdmData);
169 static int32_t fdmDriverErrCbFxn(void *fdmData, void *errList);
170 static Fdm_Driver *fdmAllocDriverObject(void);
171 static int32_t fdmFreeDriverObject(const Fvid2_DrvOps *drvOps);
172 static Fdm_Channel *fdmAllocChannelObject(void);
173 static int32_t fdmFreeChannelObject(Fdm_Channel *channel);
174 #ifdef __cplusplus
176 #endif
178 /* ========================================================================== */
179 /*                            Global Variables                                */
180 /* ========================================================================== */
182 #if defined (FVID2_CFG_TRACE_ENABLE)
183 static RemoteDebug_ServerObj gRemoteDebug_serverObj = {0};
184 #endif
186 /** \brief FDM init params. */
187 static Fvid2_InitPrms   gFdmInitPrms = {NULL};
189 /** \brief FDM objects. */
190 static Fdm_Object        gFdmObj;
192 /** \brief FVID2 standard information table. */
193 static Fvid2_ModeInfo    gFdmStdInfoTable[] =
195     /* Standard, FrameWidth, FrameHeight, ScanFormat, PixelClock (KHz), FPS */
196     {FVID2_STD_NTSC,           720U,  480U,  FVID2_SF_INTERLACED, 27000U,   30U,
197      0U, 0U, 0U, 0U, 0U, 0U},
198     {FVID2_STD_PAL,            720U,  576U,  FVID2_SF_INTERLACED, 27000U,   25U,
199      0U, 0U, 0U, 0U, 0U, 0U},
200     {FVID2_STD_480I,           720U,  480U,  FVID2_SF_INTERLACED, 27000U,   30U,
201      0U, 0U, 0U, 0U, 0U, 0U},
202     {FVID2_STD_576I,           720U,  576U,  FVID2_SF_INTERLACED, 27000U,   25U,
203      0U, 0U, 0U, 0U, 0U, 0U},
204     {FVID2_STD_480P,           720U,  480U,  FVID2_SF_PROGRESSIVE,27000U,   60U,
205      0U, 0U, 0U, 0U, 0U, 0U},
206     {FVID2_STD_576P,           720U,  576U,  FVID2_SF_PROGRESSIVE,27000U,   50U,
207      0U, 0U, 0U, 0U, 0U, 0U},
208     {FVID2_STD_720P_60,        1280U, 720U,  FVID2_SF_PROGRESSIVE,74250U,   60U,
209      0U, 0U, 0U, 0U, 0U, 0U},
210     {FVID2_STD_720P_50,        1280U, 720U,  FVID2_SF_PROGRESSIVE,74250U,   50U,
211      0U, 0U, 0U, 0U, 0U, 0U},
212     {FVID2_STD_1080I_60,       1920U, 1080U, FVID2_SF_INTERLACED, 74250U,   30U,
213      0U, 0U, 0U, 0U, 0U, 0U},
214     {FVID2_STD_1080I_50,       1920U, 1080U, FVID2_SF_INTERLACED, 74250U,   25U,
215      0U, 0U, 0U, 0U, 0U, 0U},
216     {FVID2_STD_1080P_60,       1920U, 1080U, FVID2_SF_PROGRESSIVE,148500U,  60U,
217      0U, 0U, 0U, 0U, 0U, 0U},
218     {FVID2_STD_1080P_50,       1920U, 1080U, FVID2_SF_PROGRESSIVE,148500U,  50U,
219      0U, 0U, 0U, 0U, 0U, 0U},
220     {FVID2_STD_1080P_24,       1920U, 1080U, FVID2_SF_PROGRESSIVE,74250U,   24U,
221      0U, 0U, 0U, 0U, 0U, 0U},
222     {FVID2_STD_1080P_30,       1920U, 1080U, FVID2_SF_PROGRESSIVE,74250U,   30U,
223      0U, 0U, 0U, 0U, 0U, 0U},
224     {FVID2_STD_VGA_60,         640U,  480U,  FVID2_SF_PROGRESSIVE,25175U,   60U,
225      0U, 0U, 0U, 0U, 0U, 0U},
226     {FVID2_STD_VGA_72,         640U,  480U,  FVID2_SF_PROGRESSIVE,31500U,   72U,
227      0U, 0U, 0U, 0U, 0U, 0U},
228     {FVID2_STD_VGA_75,         640U,  480U,  FVID2_SF_PROGRESSIVE,31500U,   75U,
229      0U, 0U, 0U, 0U, 0U, 0U},
230     {FVID2_STD_VGA_85,         640U,  480U,  FVID2_SF_PROGRESSIVE,36000U,   85U,
231      0U, 0U, 0U, 0U, 0U, 0U},
232     {FVID2_STD_WVGA_60,        800U,  480U,  FVID2_SF_PROGRESSIVE,33500U,   60U,
233      0U, 0U, 0U, 0U, 0U, 0U},
234     {FVID2_STD_SVGA_60,        800U,  600U,  FVID2_SF_PROGRESSIVE,40000U,   60U,
235      0U, 0U, 0U, 0U, 0U, 0U},
236     {FVID2_STD_SVGA_72,        800U,  600U,  FVID2_SF_PROGRESSIVE,50000U,   72U,
237      0U, 0U, 0U, 0U, 0U, 0U},
238     {FVID2_STD_SVGA_75,        800U,  600U,  FVID2_SF_PROGRESSIVE,49500U,   75U,
239      0U, 0U, 0U, 0U, 0U, 0U},
240     {FVID2_STD_SVGA_85,        800U,  600U,  FVID2_SF_PROGRESSIVE,56250U,   85U,
241      0U, 0U, 0U, 0U, 0U, 0U},
242     {FVID2_STD_WSVGA_70,       1024U, 600U,  FVID2_SF_PROGRESSIVE,50800U,   70U,
243      0U, 0U, 0U, 0U, 0U, 0U},
244     {FVID2_STD_XGA_60,         1024U, 768U,  FVID2_SF_PROGRESSIVE,65000U,   60U,
245      0U, 0U, 0U, 0U, 0U, 0U},
246     {FVID2_STD_XGA_DSS_TDM_60, 1024U, 768U,  FVID2_SF_PROGRESSIVE,64000U,   60U,
247      0U, 0U, 0U, 0U, 0U, 0U},
248     {FVID2_STD_XGA_70,         1024U, 768U,  FVID2_SF_PROGRESSIVE,75000U,   70U,
249      0U, 0U, 0U, 0U, 0U, 0U},
250     {FVID2_STD_XGA_75,         1024U, 768U,  FVID2_SF_PROGRESSIVE,78750U,   75U,
251      0U, 0U, 0U, 0U, 0U, 0U},
252     {FVID2_STD_XGA_85,         1024U, 768U,  FVID2_SF_PROGRESSIVE,94500U,   85U,
253      0U, 0U, 0U, 0U, 0U, 0U},
254     {FVID2_STD_WXGA_30,        1280U, 800U,  FVID2_SF_PROGRESSIVE,34125U,   30U,
255      0U, 0U, 0U, 0U, 0U, 0U},
256     {FVID2_STD_WXGA_60,        1280U, 800U,  FVID2_SF_PROGRESSIVE,83500U,   60U,
257      0U, 0U, 0U, 0U, 0U, 0U},
258     {FVID2_STD_WXGA_75,        1280U, 800U,  FVID2_SF_PROGRESSIVE,102250U,  75U,
259      0U, 0U, 0U, 0U, 0U, 0U},
260     {FVID2_STD_WXGA_85,        1280U, 800U,  FVID2_SF_PROGRESSIVE,117500U,  85U,
261      0U, 0U, 0U, 0U, 0U, 0U},
262     {FVID2_STD_1440_900_60,    1440U, 900U,  FVID2_SF_PROGRESSIVE,106500U,  60U,
263      0U, 0U, 0U, 0U, 0U, 0U},
264     {FVID2_STD_1368_768_60,    1368U, 768U,  FVID2_SF_PROGRESSIVE,85860U,   60U,
265      0U, 0U, 0U, 0U, 0U, 0U},
266     {FVID2_STD_1366_768_60,    1366U, 768U,  FVID2_SF_PROGRESSIVE,85500U,   60U,
267      0U, 0U, 0U, 0U, 0U, 0U},
268     {FVID2_STD_1360_768_60,    1360U, 768U,  FVID2_SF_PROGRESSIVE,85500U,   60U,
269      0U, 0U, 0U, 0U, 0U, 0U},
270     {FVID2_STD_SXGA_60,        1280U, 1024U, FVID2_SF_PROGRESSIVE,108000U,  60U,
271      0U, 0U, 0U, 0U, 0U, 0U},
272     {FVID2_STD_SXGA_75,        1280U, 1024U, FVID2_SF_PROGRESSIVE,135000U,  75U,
273      0U, 0U, 0U, 0U, 0U, 0U},
274     {FVID2_STD_SXGA_85,        1280U, 1024U, FVID2_SF_PROGRESSIVE,157500U,  85U,
275      0U, 0U, 0U, 0U, 0U, 0U},
276     {FVID2_STD_WSXGAP_60,      1680U, 1050U, FVID2_SF_PROGRESSIVE,146250U,  60U,
277      0U, 0U, 0U, 0U, 0U, 0U},
278     {FVID2_STD_SXGAP_60,       1400U, 1050U, FVID2_SF_PROGRESSIVE,121750U,  60U,
279      0U, 0U, 0U, 0U, 0U, 0U},
280     {FVID2_STD_SXGAP_75,       1400U, 1050U, FVID2_SF_PROGRESSIVE,156000U,  75U,
281      0U, 0U, 0U, 0U, 0U, 0U},
282     {FVID2_STD_UXGA_60,        1600U, 1200U, FVID2_SF_PROGRESSIVE,162000U,  60U,
283      0U, 0U, 0U, 0U, 0U, 0U},
284     {FVID2_STD_WXGA_5x3_30,    1280U, 800U,  FVID2_SF_PROGRESSIVE,34125U,   30U,
285      0U, 0U, 0U, 0U, 0U, 0U},
286     {FVID2_STD_WXGA_5x3_60,    1280U, 800U,  FVID2_SF_PROGRESSIVE,68250U,   60U,
287      0U, 0U, 0U, 0U, 0U, 0U},
288     {FVID2_STD_WXGA_5x3_75,    1280U, 800U,  FVID2_SF_PROGRESSIVE,102250U,  75U,
289      0U, 0U, 0U, 0U, 0U, 0U}
290 };
292 /** \brief Data format string table. */
293 static Fdm_DataFmtString gFdmDataFmtStrTable[] =
295     {FVID2_DF_YUV422I_UYVY,           "YUV422I_UYVY"          },
296     {FVID2_DF_YUV422I_YUYV,           "YUV422I_YUYV"          },
297     {FVID2_DF_YUV422I_YVYU,           "YUV422I_YVYU"          },
298     {FVID2_DF_YUV422I_VYUY,           "YUV422I_VYUY"          },
299     {FVID2_DF_YUV422SP_UV,            "YUV422SP_UV"           },
300     {FVID2_DF_YUV422SP_VU,            "YUV422SP_VU"           },
301     {FVID2_DF_YUV422P,                "YUV422P"               },
302     {FVID2_DF_YUV420SP_UV,            "YUV420SP_UV"           },
303     {FVID2_DF_YUV420SP_VU,            "YUV420SP_VU"           },
304     {FVID2_DF_YUV420P,                "YUV420P"               },
305     {FVID2_DF_YUV444P,                "YUV444P"               },
306     {FVID2_DF_YUV444I,                "YUV444I"               },
307     {FVID2_DF_RGB16_565,              "RGB16_565"             },
308     {FVID2_DF_ARGB16_1555,            "ARGB16_1555"           },
309     {FVID2_DF_RGBA16_5551,            "RGBA16_5551"           },
310     {FVID2_DF_ARGB16_4444,            "ARGB16_4444"           },
311     {FVID2_DF_RGBA16_4444,            "RGBA16_4444"           },
312     {FVID2_DF_BGRX_4444,              "RGBX12_4444"           },
313     {FVID2_DF_XBGR_4444,              "XRGB12_4444"           },
314     {FVID2_DF_ARGB24_6666,            "ARGB24_6666"           },
315     {FVID2_DF_RGBA24_6666,            "RGBA24_6666"           },
316     {FVID2_DF_RGB24_888,              "RGB24_888"             },
317     {FVID2_DF_XBGR24_8888,            "XBGR24_8888"           },
318     {FVID2_DF_RGBX24_8888,            "RGBX24_8888"           },
319     {FVID2_DF_BGRX24_8888,            "BGRX24_8888"           },
320     {FVID2_DF_ARGB32_8888,            "ARGB32_8888"           },
321     {FVID2_DF_RGBA32_8888,            "RGBA32_8888"           },
322     {FVID2_DF_BGR16_565,              "BGR16_565"             },
323     {FVID2_DF_ABGR16_1555,            "ABGR16_1555"           },
324     {FVID2_DF_ABGR16_4444,            "ABGR16_4444"           },
325     {FVID2_DF_BGRA16_5551,            "BGRA16_5551"           },
326     {FVID2_DF_BGRA16_4444,            "BGRA16_4444"           },
327     {FVID2_DF_AGBR16_1555,            "AGBR16_1555"           },
328     {FVID2_DF_AGBR16_4444,            "AGBR16_4444"           },
329     {FVID2_DF_XGBR16_1555,            "XGBR16_1555"           },
330     {FVID2_DF_BGRX16_5551,            "BGRX16_5551"           },
331     {FVID2_DF_ABGR24_6666,            "ABGR24_6666"           },
332     {FVID2_DF_BGR24_888,              "BGR24_888"             },
333     {FVID2_DF_ABGR32_8888,            "ABGR32_8888"           },
334     {FVID2_DF_BGRA24_6666,            "BGRA24_6666"           },
335     {FVID2_DF_BGRA32_8888,            "BGRA32_8888"           },
336     {FVID2_DF_BITMAP8,                "BITMAP8"               },
337     {FVID2_DF_BITMAP4_LOWER,          "BITMAP4_LOWER"         },
338     {FVID2_DF_BITMAP4_UPPER,          "BITMAP4_UPPER"         },
339     {FVID2_DF_BITMAP2_OFFSET0,        "BITMAP2_OFFSET0"       },
340     {FVID2_DF_BITMAP2_OFFSET1,        "BITMAP2_OFFSET1"       },
341     {FVID2_DF_BITMAP2_OFFSET2,        "BITMAP2_OFFSET2"       },
342     {FVID2_DF_BITMAP2_OFFSET3,        "BITMAP2_OFFSET3"       },
343     {FVID2_DF_BITMAP1_OFFSET0,        "BITMAP1_OFFSET0"       },
344     {FVID2_DF_BITMAP1_OFFSET1,        "BITMAP1_OFFSET1"       },
345     {FVID2_DF_BITMAP1_OFFSET2,        "BITMAP1_OFFSET2"       },
346     {FVID2_DF_BITMAP1_OFFSET3,        "BITMAP1_OFFSET3"       },
347     {FVID2_DF_BITMAP1_OFFSET4,        "BITMAP1_OFFSET4"       },
348     {FVID2_DF_BITMAP1_OFFSET5,        "BITMAP1_OFFSET5"       },
349     {FVID2_DF_BITMAP1_OFFSET6,        "BITMAP1_OFFSET6"       },
350     {FVID2_DF_BITMAP1_OFFSET7,        "BITMAP1_OFFSET7"       },
351     {FVID2_DF_BITMAP8_BGRA32,         "BITMAP8_BGRA32"        },
352     {FVID2_DF_BITMAP4_BGRA32_LOWER,   "BITMAP4_BGRA32_LOWER"  },
353     {FVID2_DF_BITMAP4_BGRA32_UPPER,   "BITMAP4_BGRA32_UPPER"  },
354     {FVID2_DF_BITMAP2_BGRA32_OFFSET0, "BITMAP2_BGRA32_OFFSET0"},
355     {FVID2_DF_BITMAP2_BGRA32_OFFSET1, "BITMAP2_BGRA32_OFFSET1"},
356     {FVID2_DF_BITMAP2_BGRA32_OFFSET2, "BITMAP2_BGRA32_OFFSET2"},
357     {FVID2_DF_BITMAP2_BGRA32_OFFSET3, "BITMAP2_BGRA32_OFFSET3"},
358     {FVID2_DF_BITMAP1_BGRA32_OFFSET0, "BITMAP1_BGRA32_OFFSET0"},
359     {FVID2_DF_BITMAP1_BGRA32_OFFSET1, "BITMAP1_BGRA32_OFFSET1"},
360     {FVID2_DF_BITMAP1_BGRA32_OFFSET2, "BITMAP1_BGRA32_OFFSET2"},
361     {FVID2_DF_BITMAP1_BGRA32_OFFSET3, "BITMAP1_BGRA32_OFFSET3"},
362     {FVID2_DF_BITMAP1_BGRA32_OFFSET4, "BITMAP1_BGRA32_OFFSET4"},
363     {FVID2_DF_BITMAP1_BGRA32_OFFSET5, "BITMAP1_BGRA32_OFFSET5"},
364     {FVID2_DF_BITMAP1_BGRA32_OFFSET6, "BITMAP1_BGRA32_OFFSET6"},
365     {FVID2_DF_BITMAP1_BGRA32_OFFSET7, "BITMAP1_BGRA32_OFFSET7"},
366     {FVID2_DF_BAYER_RAW,              "BAYER_RAW"             },
367     {FVID2_DF_BAYER_GRBG,             "BAYER_GRBG"            },
368     {FVID2_DF_BAYER_RGGB,             "BAYER_RGGB"            },
369     {FVID2_DF_BAYER_BGGR,             "BAYER_BGGR"            },
370     {FVID2_DF_BAYER_GBRG,             "BAYER_GBRG"            },
371     {FVID2_DF_RAW_VBI,                "RAW_VBI"               },
372     {FVID2_DF_RAW24,                  "RAW24"                 },
373     {FVID2_DF_RAW16,                  "RAW16"                 },
374     {FVID2_DF_RAW08,                  "RAW08"                 },
375     {FVID2_DF_BGRX32_8888,            "BGRX32_8888"           },
376     {FVID2_DF_BGRA16_1555,            "BGRA16_1555"           },
377     {FVID2_DF_BGRX16_1555,            "BGRX16_1555"           },
378     {FVID2_DF_BGRA32_1010102,         "BGRA32_1010102"        },
379     {FVID2_DF_BGRX32_1010102,         "BGRX32_1010102"        },
380     {FVID2_DF_RGBA32_1010102,         "RGBA32_1010102"        },
381     {FVID2_DF_RGBX32_1010102,         "RGBX32_1010102"        },
382     {FVID2_DF_BGRA64_16161616,        "BGRA64_16161616"       },
383     {FVID2_DF_BGRX64_16161616,        "BGRX64_16161616"       },
384     {FVID2_DF_ABGR64_16161616,        "ABGR64_16161616"       },
385     {FVID2_DF_XBGR64_16161616,        "XBGR64_16161616"       },
386     {FVID2_DF_XRGB32_8888,            "XRGB32_8888"           },
387     {FVID2_DF_RGBX16_4444,            "RGBX16_4444"           },
388     {FVID2_DF_BGR16_565_A8,           "BRG16_565_A8"          },
389     {FVID2_DF_RGB16_565_A8,           "RGB16_565_A8"          },
390     {FVID2_DF_MISC,                   "MISC"                  },
391     {FVID2_DF_INVALID,                "INVALID"               },
392 };
394 /** \brief Standard string table. */
395 static Fdm_StdString     gFdmStdStrTable[] =
397     {FVID2_STD_NTSC,            "NTSC"           },
398     {FVID2_STD_PAL,             "PAL"            },
399     {FVID2_STD_480I,            "480I"           },
400     {FVID2_STD_576I,            "576I"           },
401     {FVID2_STD_CIF,             "CIF"            },
402     {FVID2_STD_HALF_D1,         "HALF_D1"        },
403     {FVID2_STD_D1,              "D1"             },
404     {FVID2_STD_480P,            "480P"           },
405     {FVID2_STD_576P,            "576P"           },
406     {FVID2_STD_720P_60,         "720P60"         },
407     {FVID2_STD_720P_50,         "720P50"         },
408     {FVID2_STD_1080I_60,        "1080I60"        },
409     {FVID2_STD_1080I_50,        "1080I50"        },
410     {FVID2_STD_1080P_60,        "1080P60"        },
411     {FVID2_STD_1080P_50,        "1080P50"        },
412     {FVID2_STD_1080P_24,        "1080P24"        },
413     {FVID2_STD_1080P_30,        "1080P30"        },
414     {FVID2_STD_VGA_60,          "VGA60"          },
415     {FVID2_STD_VGA_72,          "VGA72"          },
416     {FVID2_STD_VGA_75,          "VGA75"          },
417     {FVID2_STD_VGA_85,          "VGA85"          },
418     {FVID2_STD_WVGA_60,         "WVGA60"         },
419     {FVID2_STD_SVGA_60,         "SVGA60"         },
420     {FVID2_STD_SVGA_72,         "SVGA72"         },
421     {FVID2_STD_SVGA_75,         "SVGA75"         },
422     {FVID2_STD_SVGA_85,         "SVGA85"         },
423     {FVID2_STD_WSVGA_70,        "WSVGA70"        },
424     {FVID2_STD_XGA_60,          "XGA60"          },
425     {FVID2_STD_XGA_DSS_TDM_60,  "XGA_DSS_TDM_60" },
426     {FVID2_STD_XGA_70,          "XGA70"          },
427     {FVID2_STD_XGA_75,          "XGA75"          },
428     {FVID2_STD_XGA_85,          "XGA85"          },
429     {FVID2_STD_WXGA_30,         "WXGA30"         },
430     {FVID2_STD_WXGA_60,         "WXGA60"         },
431     {FVID2_STD_WXGA_75,         "WXGA75"         },
432     {FVID2_STD_WXGA_85,         "WXGA85"         },
433     {FVID2_STD_1440_900_60,     "1440X900@60"    },
434     {FVID2_STD_1368_768_60,     "1368X768@60"    },
435     {FVID2_STD_1366_768_60,     "1366X768@60"    },
436     {FVID2_STD_1360_768_60,     "1360X768@60"    },
437     {FVID2_STD_SXGA_60,         "SXGA60"         },
438     {FVID2_STD_SXGA_75,         "SXGA75"         },
439     {FVID2_STD_SXGA_85,         "SXGA85"         },
440     {FVID2_STD_WSXGAP_60,       "WSXGAP60"       },
441     {FVID2_STD_SXGAP_60,        "SXGAP60"        },
442     {FVID2_STD_SXGAP_75,        "SXGAP75"        },
443     {FVID2_STD_UXGA_60,         "UXGA60"         },
444     {FVID2_STD_MUX_2CH_D1,      "MUX_2CH_D1"     },
445     {FVID2_STD_MUX_2CH_HALF_D1, "MUX_2CH_HALF_D1"},
446     {FVID2_STD_MUX_2CH_CIF,     "MUX_2CH_CIF"    },
447     {FVID2_STD_MUX_4CH_D1,      "MUX_4CH_D1"     },
448     {FVID2_STD_MUX_4CH_CIF,     "MUX_4CH_CIF"    },
449     {FVID2_STD_MUX_4CH_HALF_D1, "MUX_4CH_HALF_D1"},
450     {FVID2_STD_MUX_8CH_CIF,     "MUX_8CH_CIF"    },
451     {FVID2_STD_MUX_8CH_HALF_D1, "MUX_8CH_HALF_D1"},
452     {FVID2_STD_WXGA_5x3_30,     "WXGA_5x3_30"    },
453     {FVID2_STD_WXGA_5x3_60,     "WXGA_5x3_60"    },
454     {FVID2_STD_WXGA_5x3_75,     "WXGA_5x3_75"    },
455     {FVID2_STD_AUTO_DETECT,     "AUTO_DETECT"    },
456     {FVID2_STD_CUSTOM,          "CUSTOM"         },
457 };
459 /* ========================================================================== */
460 /*                          Function Definitions                              */
461 /* ========================================================================== */
463 /**
464  *  Fvid2_init
465  *  \brief FVID2 init function.
466  *
467  *  Initializes the drivers and the hardware.
468  *  This function should be called before calling any of driver API's.
469  *
470  *  \param arg          Not used currently. Meant for future purpose.
471  *
472  *  \return             Returns 0 on success else returns error value.
473  */
474 int32_t Fvid2_init(const Fvid2_InitPrms *initPrms)
476     uint32_t cnt;
477     int32_t  retVal = FVID2_SOK;
478     int32_t  initValue;
479     SemaphoreP_Params params;
481     Fvid2InitPrms_init(&gFdmInitPrms);
482     if (NULL != initPrms)
483     {
484         Fvid2Utils_memcpy(&gFdmInitPrms, initPrms, sizeof (gFdmInitPrms));
485     }
487     /* Init all global variables to zero */
488     Fvid2Utils_memset(&gFdmObj, 0U, sizeof (gFdmObj));
490     /* Mark pool flags as free */
491     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
492     {
493         gFdmObj.fdmDriverObjects[cnt].isUsed = (uint32_t) FALSE;
494     }
495     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_CH_OBJS; cnt++)
496     {
497         gFdmObj.fdmChannelObjects[cnt].isUsed = (uint32_t) FALSE;
498     }
500     gFdmObj.versionString = FVID2_VERSION_STRING;
501     gFdmObj.versionNumber = FVID2_VERSION_NUMBER;
503     /* Allocate lock semaphore */
504     SemaphoreP_Params_init(&params);
505     params.mode = SemaphoreP_Mode_BINARY;
506     initValue       = 1;
507     gFdmObj.lockSem = SemaphoreP_create(initValue, &params);
508     if (NULL == gFdmObj.lockSem)
509     {
510         GT_0trace(Fvid2Trace, GT_ERR, "FVID2 semaphore create failed!!\r\n");
511         retVal = FVID2_EALLOC;
512     }
513     SemaphoreP_Params_init(&params);
514     params.mode = SemaphoreP_Mode_BINARY;
515     initValue       = 1;
516     gFdmObj.printSem = SemaphoreP_create(initValue, &params);
517     if (NULL == gFdmObj.printSem)
518     {
519         GT_0trace(Fvid2Trace, GT_ERR, "FVID2 semaphore create failed!!\r\n");
520         retVal = FVID2_EALLOC;
521     }
523     /* Free-up memory if error occurs */
524     if (FVID2_SOK != retVal)
525     {
526         Fvid2_deInit(NULL);
527     }
529     return (retVal);
532 /**
533  *  Fvid2_deInit
534  *  \brief FVID2 deinit function.
535  *
536  *  Uninitializes the drivers and the hardware.
537  *
538  *  \param arg          Not used currently. Meant for future purpose.
539  *
540  *  \return             Returns 0 on success else returns error value.
541  */
542 int32_t Fvid2_deInit(void *args)
544     int32_t retVal = FVID2_SOK;
546     /* Delete the lock semaphore */
547     if (NULL != gFdmObj.lockSem)
548     {
549         SemaphoreP_delete(gFdmObj.lockSem);
550         gFdmObj.lockSem = NULL;
551     }
552     if (NULL != gFdmObj.printSem)
553     {
554         SemaphoreP_delete(gFdmObj.printSem);
555         gFdmObj.printSem = NULL;
556     }
558     return (retVal);
561 /**
562  *  Fvid2_getVersionString
563  *  \brief Get the FVID2 driver version in string form. This API can be
564  *  called before calling #Fvid2_init().
565  *
566  *  \return             Returns pointer to FVID2 version string.
567  */
568 const char *Fvid2_getVersionString(void)
570     return (FVID2_VERSION_STRING);
573 /**
574  *  Fvid2_getVersionNumber
575  *  \brief Get the FVID2 driver version in number form. This API can be
576  *  called before calling #Fvid2_init().
577  *
578  *  \return             FVID2 version number.
579  */
580 uint32_t Fvid2_getVersionNumber(void)
582     return (FVID2_VERSION_NUMBER);
585 /**
586  *  Fvid2_registerDriver
587  *  \brief FVID2 register driver function.
588  */
589 int32_t Fvid2_registerDriver(const Fvid2_DrvOps *drvOps)
591     int32_t     retVal = FVID2_SOK;
592     Fdm_Driver *drv;
593     uint32_t    cnt;
595     /* Check for NULL pointers */
596     OSAL_Assert(NULL == drvOps);
598     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
600     /* Check whether the driver is already registered */
601     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
602     {
603         if (TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed)
604         {
605             /* Check for NULL pointers */
606             OSAL_Assert(NULL == gFdmObj.fdmDriverObjects[cnt].drvOps);
608             if (drvOps->drvId == gFdmObj.fdmDriverObjects[cnt].drvOps->drvId)
609             {
610                 GT_0trace(Fvid2Trace, GT_ERR,
611                           "Driver with same id already registered!!\r\n");
612                 retVal = FVID2_EDRIVER_INUSE;
613                 break;
614             }
615         }
616     }
618     if (FVID2_SOK == retVal)
619     {
620         /* Get a free driver object */
621         drv = fdmAllocDriverObject();
622         if (NULL != drv)
623         {
624             drv->drvOps   = drvOps;
625             drv->numOpens = 0U;
626         }
627         else
628         {
629             GT_0trace(Fvid2Trace, GT_ERR, "Alloc driver object failed!!\r\n");
630             retVal = FVID2_EALLOC;
631         }
632     }
634     SemaphoreP_post(gFdmObj.lockSem);
636     return (retVal);
639 /**
640  *  Fvid2_unRegisterDriver
641  *  \brief FVID2 unregister driver function.
642  */
643 int32_t Fvid2_unRegisterDriver(const Fvid2_DrvOps *drvOps)
645     int32_t retVal = FVID2_EFAIL;
647     /* Check for NULL pointers */
648     OSAL_Assert(NULL == drvOps);
650     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
652     /* Free the driver object */
653     retVal = fdmFreeDriverObject(drvOps);
655     SemaphoreP_post(gFdmObj.lockSem);
657     return (retVal);
660 /**
661  *  Fvid2_create
662  *  \brief Opens the driver identified by the driver ID.
663  */
664 Fvid2_Handle Fvid2_create(uint32_t              drvId,
665                           uint32_t              instanceId,
666                           void                 *createArgs,
667                           void                 *createStatusArgs,
668                           const Fvid2_CbParams *cbParams)
670     Fdm_Driver       *drv = NULL;
671     uint32_t          cnt;
672     Fdrv_Handle       drvHandle = NULL;
673     Fdm_Channel      *channel   = NULL;
674     Fvid2_DrvCbParams fdmCbParams, *tempCbParams;
676     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
678     /* Get the matching driver object */
679     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
680     {
681         if (TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed)
682         {
683             /* Check for NULL pointers */
684             OSAL_Assert(NULL == gFdmObj.fdmDriverObjects[cnt].drvOps);
686             if (drvId == gFdmObj.fdmDriverObjects[cnt].drvOps->drvId)
687             {
688                 drv = &gFdmObj.fdmDriverObjects[cnt];
689                 /* Allocate channel object */
690                 channel = fdmAllocChannelObject();
691                 break;
692             }
693         }
694     }
696     if (NULL != channel)
697     {
698         if (NULL != drv->drvOps->createFxn)
699         {
700             if (NULL != cbParams)
701             {
702                 if (NULL != cbParams->cbFxn)
703                 {
704                     fdmCbParams.fdmCbFxn = &fdmDriverCbFxn;
705                 }
706                 else
707                 {
708                     fdmCbParams.fdmCbFxn = NULL;
709                 }
710                 if (NULL != cbParams->errCbFxn)
711                 {
712                     fdmCbParams.fdmErrCbFxn = &fdmDriverErrCbFxn;
713                 }
714                 else
715                 {
716                     fdmCbParams.fdmErrCbFxn = NULL;
717                 }
719                 fdmCbParams.handle   = channel;
720                 fdmCbParams.errList  = cbParams->errList;
721                 fdmCbParams.fdmData  = channel;
722                 tempCbParams         = &fdmCbParams;
723             }
724             else
725             {
726                 tempCbParams = NULL;
727             }
729             /* Call the driver's create function */
730             drvHandle = drv->drvOps->createFxn(
731                 drvId,
732                 instanceId,
733                 createArgs,
734                 createStatusArgs,
735                 tempCbParams);
736         }
737         else
738         {
739             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
740         }
742         if (NULL != drvHandle)
743         {
744             drv->numOpens++;
746             channel->drv       = drv;
747             channel->drvHandle = drvHandle;
748             Fvid2CbParams_init(&channel->cbParams);
749             if (NULL != cbParams)
750             {
751                 Fvid2Utils_memcpy(
752                     &channel->cbParams,
753                     cbParams,
754                     sizeof (Fvid2_CbParams));
755             }
756         }
757         else
758         {
759             GT_0trace(Fvid2Trace, GT_ERR, "Driver create failed!!\r\n");
761             /* Free the allocated channel object */
762             fdmFreeChannelObject(channel);
763             channel = NULL;
764         }
765     }
766     else
767     {
768         GT_0trace(Fvid2Trace, GT_ERR, "EALLOC: Invalid driver ID!!\r\n");
769     }
771     SemaphoreP_post(gFdmObj.lockSem);
773     return (channel);
776 /**
777  *  Fvid2_delete
778  *  \brief Application calls Fvid2_delete to close the logical channel
779  *  associated with FVID2 handle.
780  */
781 int32_t Fvid2_delete(Fvid2_Handle handle, void *deleteArgs)
783     int32_t      retVal = FVID2_SOK;
784     Fdm_Channel *channel;
786     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
788     if (NULL != handle)
789     {
790         channel = (Fdm_Channel *) handle;
792         /* Check for NULL pointers */
793         OSAL_Assert(NULL == channel->drv);
794         OSAL_Assert(NULL == channel->drv->drvOps);
796         if (NULL != channel->drv->drvOps->deleteFxn)
797         {
798             /* Call the driver's delete function */
799             retVal = channel->drv->drvOps->deleteFxn(
800                 channel->drvHandle,
801                 deleteArgs);
802         }
803         else
804         {
805             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
806         }
808         channel->drv->numOpens--;
809         /* Free the allocated channel object */
810         channel->drv               = NULL;
811         channel->drvHandle         = NULL;
812         channel->cbParams.cbFxn    = NULL;
813         channel->cbParams.errCbFxn = NULL;
814         channel->cbParams.errList  = NULL;
815         channel->cbParams.appData  = NULL;
816         fdmFreeChannelObject(channel);
817     }
818     else
819     {
820         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
821         retVal = FVID2_EBADARGS;
822     }
824     SemaphoreP_post(gFdmObj.lockSem);
826     return (retVal);
829 /**
830  *  Fvid2_control
831  *  \brief An application calls Fvid2_control to send device-specific control
832  *  commands to the video driver.
833  */
834 int32_t Fvid2_control(Fvid2_Handle  handle,
835                       uint32_t      cmd,
836                       void         *cmdArgs,
837                       void         *cmdStatusArgs)
839     int32_t      retVal = FVID2_SOK;
840     Fdm_Channel *channel;
842     if (NULL != handle)
843     {
844         channel = (Fdm_Channel *) handle;
846         /* Check for NULL pointers */
847         OSAL_Assert(NULL == channel->drv);
848         OSAL_Assert(NULL == channel->drv->drvOps);
850         if (NULL != channel->drv->drvOps->controlFxn)
851         {
852             /* Call the driver's control function */
853             retVal = channel->drv->drvOps->controlFxn(
854                 channel->drvHandle,
855                 cmd,
856                 cmdArgs,
857                 cmdStatusArgs);
858         }
859         else
860         {
861             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
862             retVal = FVID2_EUNSUPPORTED_OPS;
863         }
864     }
865     else
866     {
867         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
868         retVal = FVID2_EBADARGS;
869     }
871     return (retVal);
874 /**
875  *  Fvid2_queue
876  *  \brief An application calls Fvid2_queue to submit a video buffer to the
877  *  video device driver.
878  *  This is used in capture/display drivers.
879  */
880 int32_t Fvid2_queue(Fvid2_Handle     handle,
881                     Fvid2_FrameList *frameList,
882                     uint32_t         streamId)
884     int32_t      retVal = FVID2_SOK;
885     Fdm_Channel *channel;
887     if (NULL != handle)
888     {
889         channel = (Fdm_Channel *) handle;
891         /* Check for NULL pointers */
892         OSAL_Assert(NULL == channel->drv);
893         OSAL_Assert(NULL == channel->drv->drvOps);
895         if (NULL != channel->drv->drvOps->queueFxn)
896         {
897             /* Call the driver's queue function */
898             retVal = channel->drv->drvOps->queueFxn(
899                 channel->drvHandle,
900                 frameList,
901                 streamId);
902         }
903         else
904         {
905             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
906             retVal = FVID2_EUNSUPPORTED_OPS;
907         }
908     }
909     else
910     {
911         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
912         retVal = FVID2_EBADARGS;
913     }
915     return (retVal);
918 /**
919  *  Fvid2_dequeue
920  *  \brief An application calls Fvid2_dequeue to request the video device
921  *  driver to give ownership of a video buffer.
922  *  This is used in capture/display drivers.
923  */
924 int32_t Fvid2_dequeue(Fvid2_Handle      handle,
925                       Fvid2_FrameList  *frameList,
926                       uint32_t          streamId,
927                       uint32_t          timeout)
929     int32_t      retVal = FVID2_SOK;
930     Fdm_Channel *channel;
932     if (NULL != handle)
933     {
934         channel = (Fdm_Channel *) handle;
936         /* Check for NULL pointers */
937         OSAL_Assert(NULL == channel->drv);
938         OSAL_Assert(NULL == channel->drv->drvOps);
940         if (NULL != channel->drv->drvOps->dequeueFxn)
941         {
942             /* Call the driver's dequeue function */
943             retVal = channel->drv->drvOps->dequeueFxn(
944                 channel->drvHandle,
945                 frameList,
946                 streamId,
947                 timeout);
948         }
949         else
950         {
951             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
952             retVal = FVID2_EUNSUPPORTED_OPS;
953         }
954     }
955     else
956     {
957         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
958         retVal = FVID2_EBADARGS;
959     }
961     return (retVal);
964 /**
965  *  Fvid2_processRequest
966  *  \brief An application calls Fvid2_processRequest to submit a video buffer
967  *  to the video device driver.
968  */
969 int32_t Fvid2_processRequest(Fvid2_Handle     handle,
970                              Fvid2_FrameList *inFrameList,
971                              Fvid2_FrameList *outFrameList)
973     int32_t      retVal = FVID2_SOK;
974     Fdm_Channel *channel;
976     if (NULL != handle)
977     {
978         channel = (Fdm_Channel *) handle;
980         /* Check for NULL pointers */
981         OSAL_Assert(NULL == channel->drv);
982         OSAL_Assert(NULL == channel->drv->drvOps);
984         if (NULL != channel->drv->drvOps->processRequestFxn)
985         {
986             /* Call the driver's process frame function */
987             retVal = channel->drv->drvOps->processRequestFxn(
988                 channel->drvHandle,
989                 inFrameList,
990                 outFrameList);
991         }
992         else
993         {
994             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
995             retVal = FVID2_EUNSUPPORTED_OPS;
996         }
997     }
998     else
999     {
1000         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
1001         retVal = FVID2_EBADARGS;
1002     }
1004     return (retVal);
1007 /**
1008  *  Fvid2_getProcessedRequest
1009  *  \brief An application calls Fvid2_getProcessedRequest to request the video
1010  *  device driver to give ownership of a video buffer.
1011  */
1012 int32_t Fvid2_getProcessedRequest(Fvid2_Handle     handle,
1013                                   Fvid2_FrameList *inFrameList,
1014                                   Fvid2_FrameList *outFrameList,
1015                                   uint32_t         timeout)
1017     int32_t      retVal = FVID2_SOK;
1018     Fdm_Channel *channel;
1020     if (NULL != handle)
1021     {
1022         channel = (Fdm_Channel *) handle;
1024         /* Check for NULL pointers */
1025         OSAL_Assert(NULL == channel->drv);
1026         OSAL_Assert(NULL == channel->drv->drvOps);
1028         if (NULL != channel->drv->drvOps->getProcessedRequestFxn)
1029         {
1030             /* Call the driver's get process frame function */
1031             retVal = channel->drv->drvOps->getProcessedRequestFxn(
1032                 channel->drvHandle,
1033                 inFrameList,
1034                 outFrameList,
1035                 timeout);
1036         }
1037         else
1038         {
1039             GT_0trace(Fvid2Trace, GT_ERR, "Driver Ops not supported!!\r\n");
1040             retVal = FVID2_EUNSUPPORTED_OPS;
1041         }
1042     }
1043     else
1044     {
1045         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
1046         retVal = FVID2_EBADARGS;
1047     }
1049     return (retVal);
1052 /**
1053  *  Fvid2_getModeInfo
1054  *  \brief Function to get the information about various FVID2 modes/standards.
1055  */
1056 int32_t Fvid2_getModeInfo(Fvid2_ModeInfo *modeInfo)
1058     int32_t         retVal = FVID2_SOK;
1059     uint32_t        entryCnt;
1060     Fvid2_ModeInfo *matchedEntry = NULL;
1062     if (NULL != modeInfo)
1063     {
1064         for (entryCnt = 0U; entryCnt < FDM_NUM_STD_INFO_ENTRIES; entryCnt++)
1065         {
1066             if (gFdmStdInfoTable[entryCnt].standard == modeInfo->standard)
1067             {
1068                 matchedEntry = &gFdmStdInfoTable[entryCnt];
1069                 break;
1070             }
1071         }
1073         if (NULL == matchedEntry)
1074         {
1075             GT_0trace(Fvid2Trace, GT_ERR, "Unsupported standard!!\r\n");
1076             retVal = FVID2_EINVALID_PARAMS;
1077         }
1078         else
1079         {
1080             Fvid2Utils_memcpy(modeInfo, matchedEntry, sizeof (Fvid2_ModeInfo));
1081         }
1082     }
1083     else
1084     {
1085         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
1086         retVal = FVID2_EBADARGS;
1087     }
1089     return (retVal);
1092 /**
1093  *  \brief Function to get the name of the data format in printable string.
1094  *
1095  *  \param dataFmt      [IN] Data format to get the name.
1096  *                           For valid values see #Fvid2_DataFormat.
1097  *
1098  *  \return Returns a const pointer to the string. If the data format is not
1099  *  known, then it return the string as "UNKNOWN".
1100  */
1101 const char *Fvid2_getDataFmtString(uint32_t dataFmt)
1103     uint32_t    entryCnt;
1104     const char *dataFmtStr = NULL;
1106     for (entryCnt = 0U; entryCnt < FDM_NUM_DATA_FMT_STR_ENTRIES; entryCnt++)
1107     {
1108         if (gFdmDataFmtStrTable[entryCnt].dataFmt == dataFmt)
1109         {
1110             dataFmtStr = gFdmDataFmtStrTable[entryCnt].dataFmtStr;
1111             break;
1112         }
1113     }
1115     if (NULL == dataFmtStr)
1116     {
1117         dataFmtStr = "UNKNOWN";
1118     }
1120     return (dataFmtStr);
1123 /**
1124  *  \brief Function to get the name of the standard in printable string.
1125  *
1126  *  \param standard     [IN] Standard to get the name.
1127  *                           For valid values see #Fvid2_Standard.
1128  *
1129  *  \return Returns a const pointer to the string. If the standard is not
1130  *  known, then it return the string as "UNKNOWN".
1131  */
1132 const char *Fvid2_getStandardString(uint32_t standard)
1134     uint32_t    entryCnt;
1135     const char *stdStr = NULL;
1137     for (entryCnt = 0U; entryCnt < FDM_NUM_STD_STR_ENTRIES; entryCnt++)
1138     {
1139         if (gFdmStdStrTable[entryCnt].standard == standard)
1140         {
1141             stdStr = gFdmStdStrTable[entryCnt].stdStr;
1142             break;
1143         }
1144     }
1146     if (NULL == stdStr)
1147     {
1148         stdStr = "UNKNOWN";
1149     }
1151     return (stdStr);
1154 /**
1155  *  Fvid2_checkFrameList
1156  *  \brief Checks the FVID2 frame list for error and returns appropriate error.
1157  *  This is used by the drivers and not by the application.
1158  */
1159 int32_t Fvid2_checkFrameList(const Fvid2_FrameList *frameList,
1160                              uint32_t maxFrames)
1162     int32_t  retVal = FVID2_SOK;
1163     uint32_t frmCnt;
1165     /* Check for NULL pointer */
1166     if (NULL == frameList)
1167     {
1168         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
1169         retVal = FVID2_EBADARGS;
1170     }
1171     else
1172     {
1173         /* Check whether num frames is within range */
1174         if (frameList->numFrames > maxFrames)
1175         {
1176             GT_0trace(Fvid2Trace, GT_ERR, "Number of frames exceeds max!!\r\n");
1177             retVal = FVID2_EOUT_OF_RANGE;
1178         }
1180         /* Check whether num frames is within range */
1181         if (frameList->numFrames > FVID2_MAX_FRAME_PTR)
1182         {
1183             GT_0trace(Fvid2Trace, GT_ERR,
1184                       "Number of frames exceeds FVID2 max!!\r\n");
1185             retVal = FVID2_EOUT_OF_RANGE;
1186         }
1188         /* Check whether num frames is zero */
1189         if (0U == frameList->numFrames)
1190         {
1191             GT_0trace(Fvid2Trace, GT_ERR, "Number of frames is zero!!\r\n");
1192             retVal = FVID2_EOUT_OF_RANGE;
1193         }
1195         if (FVID2_SOK == retVal)
1196         {
1197             /* Check the individual frame pointers */
1198             for (frmCnt = 0U; frmCnt < frameList->numFrames; frmCnt++)
1199             {
1200                 /* Check for NULL pointer */
1201                 if (NULL == frameList->frames[frmCnt])
1202                 {
1203                     GT_0trace(Fvid2Trace, GT_ERR,
1204                               "EBADARGS: NULL pointer!!\r\n");
1205                     retVal = FVID2_EBADARGS;
1206                     break;
1207                 }
1208             }
1209         }
1210     }
1212     return (retVal);
1215 /**
1216  *  Fvid2_checkDqFrameList
1217  *  \brief Checks the FVID2 frame list of dequeue call for error and returns
1218  *  appropriate error. For dequeue operation, the frame pointers in the frames
1219  *  should not be checked as this will be filled by the driver.
1220  *  This is used by the drivers and not by the application.
1221  */
1222 int32_t Fvid2_checkDqFrameList(const Fvid2_FrameList *frameList,
1223                                uint32_t               maxFrames)
1225     int32_t retVal = FVID2_SOK;
1227     /* Check for NULL pointer */
1228     if (NULL == frameList)
1229     {
1230         GT_0trace(Fvid2Trace, GT_ERR, "EBADARGS: NULL pointer!!\r\n");
1231         retVal = FVID2_EBADARGS;
1232     }
1233     else
1234     {
1235         /* Check whether max frames is within range */
1236         if (maxFrames > FVID2_MAX_FRAME_PTR)
1237         {
1238             GT_0trace(Fvid2Trace, GT_ERR,
1239                       "Number of frames exceeds FVID2 max!!\r\n");
1240             retVal = FVID2_EOUT_OF_RANGE;
1241         }
1242     }
1244     return (retVal);
1247 /**
1248  *  Fvid2_copyFrameList
1249  *  \brief Copies the source frame list to the destination frame list.
1250  *  This also resets the frame pointers from the source frame list.
1251  *  This is used by the drivers and not by the application.
1252  */
1253 void Fvid2_copyFrameList(Fvid2_FrameList *dest, Fvid2_FrameList *src)
1255     uint32_t frmCnt;
1257     /* Check for NULL pointers */
1258     OSAL_Assert(NULL == dest);
1259     OSAL_Assert(NULL == src);
1260     OSAL_Assert(src->numFrames >= FVID2_MAX_FRAME_PTR);
1262     dest->numFrames  = src->numFrames;
1263     dest->drvData    = src->drvData;
1265     /* Copy the individual frames */
1266     for (frmCnt = 0U; frmCnt < src->numFrames; frmCnt++)
1267     {
1268         dest->frames[frmCnt] = src->frames[frmCnt];
1269         src->frames[frmCnt]  = NULL;
1270     }
1272     return;
1275 /**
1276  *  Fvid2_duplicateFrameList
1277  *  \brief Duplicate the source frame list to the destination frame list.
1278  *  This does not reset the frame pointers from the source frame list.
1279  *  This is used by the drivers and not by the application.
1280  */
1281 void Fvid2_duplicateFrameList(Fvid2_FrameList *dest, const Fvid2_FrameList *src)
1283     uint32_t frmCnt;
1285     /* Check for NULL pointers */
1286     OSAL_Assert(NULL == dest);
1287     OSAL_Assert(NULL == src);
1288     OSAL_Assert(src->numFrames >= FVID2_MAX_FRAME_PTR);
1290     dest->numFrames  = src->numFrames;
1291     dest->drvData    = src->drvData;
1293     /* Duplicate the individual frames */
1294     for (frmCnt = 0U; frmCnt < src->numFrames; frmCnt++)
1295     {
1296         dest->frames[frmCnt] = src->frames[frmCnt];
1297     }
1299     return;
1302 /**
1303  *  fdmDriverCbFxn
1304  *  \brief FVID2 driver manager driver callback function. Whenever the drivers
1305  *  wants to call the application callback function, this function will be
1306  *  called by the driver and FDM will in turn call the application callback
1307  *  function.
1308  *  This is used by the drivers and not by the application.
1309  */
1310 static int32_t fdmDriverCbFxn(void *fdmData)
1312     int32_t      retVal;
1313     Fdm_Channel *channel;
1315     /* Check for NULL pointers */
1316     OSAL_Assert(NULL == fdmData);
1318     channel = (Fdm_Channel *) fdmData;
1319     OSAL_Assert(NULL == channel->cbParams.cbFxn);
1320     retVal = channel->cbParams.cbFxn(channel, channel->cbParams.appData);
1322     return (retVal);
1325 /**
1326  *  fdmDriverErrCbFxn
1327  *  \brief FVID2 driver manager driver error callback function.
1328  *  Whenever the drivers wants to call the application error callback function,
1329  *  this function will be called by the driver and FDM will in turn call the
1330  *  application error callback function.
1331  *  This is used by the drivers and not by the application.
1332  */
1333 static int32_t fdmDriverErrCbFxn(void *fdmData, void *errList)
1335     int32_t      retVal;
1336     Fdm_Channel *channel;
1338     /* Check for NULL pointers */
1339     OSAL_Assert(NULL == fdmData);
1341     channel = (Fdm_Channel *) fdmData;
1342     OSAL_Assert(NULL == channel->cbParams.errCbFxn);
1343     retVal =
1344         channel->cbParams.errCbFxn(channel, channel->cbParams.appData, errList);
1346     return (retVal);
1349 /**
1350  *  fdmAllocDriverObject
1351  *  \brief Allocate memory for driver object from static memory pool.
1352  *  Returns NULL if memory pool is full.
1353  */
1354 static Fdm_Driver *fdmAllocDriverObject(void)
1356     uint32_t    cnt;
1357     Fdm_Driver *drv = NULL;
1359     /* Get a free driver object */
1360     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
1361     {
1362         if (FALSE == gFdmObj.fdmDriverObjects[cnt].isUsed)
1363         {
1364             drv         = &gFdmObj.fdmDriverObjects[cnt];
1365             drv->isUsed = (uint32_t) TRUE;
1366             break;
1367         }
1368     }
1370     return (drv);
1373 /**
1374  *  fdmFreeDriverObject
1375  *  \brief Free-up the memory allocated for driver object.
1376  */
1377 static int32_t fdmFreeDriverObject(const Fvid2_DrvOps *drvOps)
1379     uint32_t cnt;
1380     int32_t  retVal = FVID2_EFAIL;
1382     /* Check for NULL pointers */
1383     OSAL_Assert(NULL == drvOps);
1385     /* Free the driver object */
1386     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
1387     {
1388         if ((TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed) &&
1389             (drvOps == gFdmObj.fdmDriverObjects[cnt].drvOps))
1390         {
1391             if (0u == gFdmObj.fdmDriverObjects[cnt].numOpens)
1392             {
1393                 gFdmObj.fdmDriverObjects[cnt].isUsed   = (uint32_t) FALSE;
1394                 gFdmObj.fdmDriverObjects[cnt].drvOps   = NULL;
1395                 gFdmObj.fdmDriverObjects[cnt].numOpens = 0u;
1396                 retVal = FVID2_SOK;
1397             }
1398             else
1399             {
1400                 GT_0trace(Fvid2Trace, GT_ERR, "Driver in use!!\r\n");
1401                 retVal = FVID2_EDEVICE_INUSE;
1402             }
1403             break;
1404         }
1405     }
1407     if (FVID2_EFAIL == retVal)
1408     {
1409         GT_0trace(Fvid2Trace, GT_ERR, "Driver ops not found!!\r\n");
1410     }
1412     return (retVal);
1415 /**
1416  *  fdmAllocChannelObject
1417  *  \brief Allocate memory for channel object from static memory pool.
1418  *  Returns NULL if memory pool is full.
1419  */
1420 static Fdm_Channel *fdmAllocChannelObject(void)
1422     uint32_t       cnt;
1423     Fdm_Channel *channel = NULL;
1425     /* Get a free channel object */
1426     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_CH_OBJS; cnt++)
1427     {
1428         if (FALSE == gFdmObj.fdmChannelObjects[cnt].isUsed)
1429         {
1430             channel         = &gFdmObj.fdmChannelObjects[cnt];
1431             channel->isUsed = (uint32_t) TRUE;
1432             break;
1433         }
1434     }
1436     return (channel);
1439 /**
1440  *  fdmFreeChannelObject
1441  *  \brief Free-up the memory allocated for channel object.
1442  */
1443 static int32_t fdmFreeChannelObject(Fdm_Channel *channel)
1445     int32_t retVal = FVID2_EALLOC;
1447     /* Check for NULL pointers */
1448     OSAL_Assert(NULL == channel);
1450     /* Free the channel object */
1451     if (TRUE == channel->isUsed)
1452     {
1453         channel->isUsed = (uint32_t) FALSE;
1454         retVal          = FVID2_SOK;
1455     }
1456     else
1457     {
1458         GT_0trace(Fvid2Trace, GT_ERR,
1459                   "Freeing a channel object not in use!!\r\n");
1460     }
1462     return (retVal);
1465 void Fvid2_printf(const char *format, ...)
1467 #if defined (FVID2_CFG_TRACE_ENABLE)
1468     va_list     vaArgPtr;
1469     char       *buf = NULL;
1471     SemaphoreP_pend(gFdmObj.printSem, SemaphoreP_WAIT_FOREVER);
1473     buf = &gRemoteDebug_serverObj.printBuf[0];
1474     va_start(vaArgPtr, format);
1475     vsnprintf(buf, REMOTE_DEBUG_SERVER_PRINT_BUF_LEN,
1476               (const char *) format, vaArgPtr);
1477     va_end(vaArgPtr);
1479     if(gFdmInitPrms.printFxn != NULL)
1480     {
1481         gFdmInitPrms.printFxn(buf);
1482     }
1484     SemaphoreP_post(gFdmObj.printSem);
1485 #endif
1486     return;