FVID2 build fix and fixed review comments
[keystone-rtos/fvid2.git] / src / fvid2_drvMgr.c
1 /*
2  *  Copyright (c) Texas Instruments Incorporated 2012-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 #include <fvid2_drvMgr.h>
46 #include <ti/osal/osal.h>
47 /* This is needed for memset/memcpy */
48 #include <string.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 /* ========================================================================== */
67 /*                         Structure Declarations                             */
68 /* ========================================================================== */
70 /**
71  *  struct Fdm_Driver
72  *  \brief Structure to store driver information.
73  */
74 typedef struct
75 {
76     const Fvid2_DrvOps *drvOps;
77     /**< Driver operation table pointer. */
78     uint32_t            numOpens;
79     /**< Number of times the driver is opened using create API. */
80     uint32_t            isUsed;
81     /**< Flag indicating whether the object is used or not. */
82 } Fdm_Driver;
84 /**
85  *  struct Fdm_Channel
86  *  \brief Structure to store channel information.
87  */
88 typedef struct
89 {
90     Fdm_Driver         *drv;
91     /**< Pointer to the driver object to which this channel is created. */
92     Fdrv_Handle         drvHandle;
93     /**< Driver handle returned by the actual driver. */
94     Fvid2_CbParams      cbParams;
95     /**< Application call back parameters. */
96     uint32_t            isUsed;
97     /**< Flag indicating whether the object is used or not. */
98 } Fdm_Channel;
100 /**
101  *  struct Fdm_DataFmtString
102  *  \brief Structure to store data format and string pair.
103  */
104 typedef struct
106     Fvid2_DataFormat    dataFmt;
107     /**< Data format. */
108     const char         *dataFmtStr;
109     /**< Pointer to data format string. */
110 } Fdm_DataFmtString;
112 /**
113  *  struct Fdm_StdString
114  *  \brief Structure to store standard and string pair.
115  */
116 typedef struct
118     Fvid2_Standard      standard;
119     /**< Standard. */
120     const char         *stdStr;
121     /**< Pointer to data format string. */
122 } Fdm_StdString;
124 /**
125  *  struct Fdm_Object
126  *  \brief Struture to store all global objects.
127  */
128 typedef struct
130     char               *versionString;
131     /**< FVID2 drivers version number as string. */
132     uint32_t            versionNumber;
133     /**< FVID2 drivers version number as string. */
134     Fdm_Driver          fdmDriverObjects[FVID2_CFG_FDM_NUM_DRV_OBJS];
135     /**< FDM Driver objects. */
136     Fdm_Channel         fdmChannelObjects[FVID2_CFG_FDM_NUM_CH_OBJS];
137     /**< FDM Channel objects. */
138     SemaphoreP_Handle   lockSem;
139     /**< Semaphore to protect function calls and other memory allocation. */
140 } Fdm_Object;
142 /* ========================================================================== */
143 /*                          Function Declarations                             */
144 /* ========================================================================== */
145 /**
146  *  Below ifdef __cplusplus is added so that C++ build passes without
147  *  typecasting. This is because the prototype is build as C type
148  *  whereas this file is build as CPP file. Hence we get C++ build error.
149  *  Also if tyecasting is used, then we get MisraC error Rule 11.1.
150  */
151 #ifdef __cplusplus
152 extern "C" {
153 #endif
154 static int32_t fdmDriverCbFxn(void *fdmData);
155 static int32_t fdmDriverErrCbFxn(void *fdmData, void *errList);
156 static Fdm_Driver *fdmAllocDriverObject(void);
157 static int32_t fdmFreeDriverObject(const Fvid2_DrvOps *drvOps);
158 static Fdm_Channel *fdmAllocChannelObject(void);
159 static int32_t fdmFreeChannelObject(Fdm_Channel *channel);
160 static void Fvid2_printf(const char *format, ...);
161 static void Fvid2_memset(void *mem, int32_t ch, uint32_t byteCount);
162 static void Fvid2_memcpy(void *dest, const void *src, uint32_t byteCount);
163 #ifdef __cplusplus
165 #endif
167 /* ========================================================================== */
168 /*                            Global Variables                                */
169 /* ========================================================================== */
171 /** \brief FDM objects. */
172 static Fdm_Object        gFdmObj;
174 /** \brief FVID2 standard information table. */
175 static Fvid2_ModeInfo    gFdmStdInfoTable[] =
177     /* Standard, FrameWidth, FrameHeight, ScanFormat, PixelClock (KHz), FPS */
178     {FVID2_STD_NTSC,           720U,  480U,  FVID2_SF_INTERLACED, 27000U,   30U,
179      0U, 0U, 0U, 0U, 0U, 0U},
180     {FVID2_STD_PAL,            720U,  576U,  FVID2_SF_INTERLACED, 27000U,   25U,
181      0U, 0U, 0U, 0U, 0U, 0U},
182     {FVID2_STD_480I,           720U,  480U,  FVID2_SF_INTERLACED, 27000U,   30U,
183      0U, 0U, 0U, 0U, 0U, 0U},
184     {FVID2_STD_576I,           720U,  576U,  FVID2_SF_INTERLACED, 27000U,   25U,
185      0U, 0U, 0U, 0U, 0U, 0U},
186     {FVID2_STD_480P,           720U,  480U,  FVID2_SF_PROGRESSIVE,27000U,   60U,
187      0U, 0U, 0U, 0U, 0U, 0U},
188     {FVID2_STD_576P,           720U,  576U,  FVID2_SF_PROGRESSIVE,27000U,   50U,
189      0U, 0U, 0U, 0U, 0U, 0U},
190     {FVID2_STD_720P_60,        1280U, 720U,  FVID2_SF_PROGRESSIVE,74250U,   60U,
191      0U, 0U, 0U, 0U, 0U, 0U},
192     {FVID2_STD_720P_50,        1280U, 720U,  FVID2_SF_PROGRESSIVE,74250U,   50U,
193      0U, 0U, 0U, 0U, 0U, 0U},
194     {FVID2_STD_1080I_60,       1920U, 1080U, FVID2_SF_INTERLACED, 74250U,   30U,
195      0U, 0U, 0U, 0U, 0U, 0U},
196     {FVID2_STD_1080I_50,       1920U, 1080U, FVID2_SF_INTERLACED, 74250U,   25U,
197      0U, 0U, 0U, 0U, 0U, 0U},
198     {FVID2_STD_1080P_60,       1920U, 1080U, FVID2_SF_PROGRESSIVE,148500U,  60U,
199      0U, 0U, 0U, 0U, 0U, 0U},
200     {FVID2_STD_1080P_50,       1920U, 1080U, FVID2_SF_PROGRESSIVE,148500U,  50U,
201      0U, 0U, 0U, 0U, 0U, 0U},
202     {FVID2_STD_1080P_24,       1920U, 1080U, FVID2_SF_PROGRESSIVE,74250U,   24U,
203      0U, 0U, 0U, 0U, 0U, 0U},
204     {FVID2_STD_1080P_30,       1920U, 1080U, FVID2_SF_PROGRESSIVE,74250U,   30U,
205      0U, 0U, 0U, 0U, 0U, 0U},
206     {FVID2_STD_VGA_60,         640U,  480U,  FVID2_SF_PROGRESSIVE,25175U,   60U,
207      0U, 0U, 0U, 0U, 0U, 0U},
208     {FVID2_STD_VGA_72,         640U,  480U,  FVID2_SF_PROGRESSIVE,31500U,   72U,
209      0U, 0U, 0U, 0U, 0U, 0U},
210     {FVID2_STD_VGA_75,         640U,  480U,  FVID2_SF_PROGRESSIVE,31500U,   75U,
211      0U, 0U, 0U, 0U, 0U, 0U},
212     {FVID2_STD_VGA_85,         640U,  480U,  FVID2_SF_PROGRESSIVE,36000U,   85U,
213      0U, 0U, 0U, 0U, 0U, 0U},
214     {FVID2_STD_WVGA_60,        800U,  480U,  FVID2_SF_PROGRESSIVE,33500U,   60U,
215      0U, 0U, 0U, 0U, 0U, 0U},
216     {FVID2_STD_SVGA_60,        800U,  600U,  FVID2_SF_PROGRESSIVE,40000U,   60U,
217      0U, 0U, 0U, 0U, 0U, 0U},
218     {FVID2_STD_SVGA_72,        800U,  600U,  FVID2_SF_PROGRESSIVE,50000U,   72U,
219      0U, 0U, 0U, 0U, 0U, 0U},
220     {FVID2_STD_SVGA_75,        800U,  600U,  FVID2_SF_PROGRESSIVE,49500U,   75U,
221      0U, 0U, 0U, 0U, 0U, 0U},
222     {FVID2_STD_SVGA_85,        800U,  600U,  FVID2_SF_PROGRESSIVE,56250U,   85U,
223      0U, 0U, 0U, 0U, 0U, 0U},
224     {FVID2_STD_WSVGA_70,       1024U, 600U,  FVID2_SF_PROGRESSIVE,50800U,   70U,
225      0U, 0U, 0U, 0U, 0U, 0U},
226     {FVID2_STD_XGA_60,         1024U, 768U,  FVID2_SF_PROGRESSIVE,65000U,   60U,
227      0U, 0U, 0U, 0U, 0U, 0U},
228     {FVID2_STD_XGA_DSS_TDM_60, 1024U, 768U,  FVID2_SF_PROGRESSIVE,64000U,   60U,
229      0U, 0U, 0U, 0U, 0U, 0U},
230     {FVID2_STD_XGA_70,         1024U, 768U,  FVID2_SF_PROGRESSIVE,75000U,   70U,
231      0U, 0U, 0U, 0U, 0U, 0U},
232     {FVID2_STD_XGA_75,         1024U, 768U,  FVID2_SF_PROGRESSIVE,78750U,   75U,
233      0U, 0U, 0U, 0U, 0U, 0U},
234     {FVID2_STD_XGA_85,         1024U, 768U,  FVID2_SF_PROGRESSIVE,94500U,   85U,
235      0U, 0U, 0U, 0U, 0U, 0U},
236     {FVID2_STD_WXGA_30,        1280U, 800U,  FVID2_SF_PROGRESSIVE,34125U,   30U,
237      0U, 0U, 0U, 0U, 0U, 0U},
238     {FVID2_STD_WXGA_60,        1280U, 800U,  FVID2_SF_PROGRESSIVE,83500U,   60U,
239      0U, 0U, 0U, 0U, 0U, 0U},
240     {FVID2_STD_WXGA_75,        1280U, 800U,  FVID2_SF_PROGRESSIVE,102250U,  75U,
241      0U, 0U, 0U, 0U, 0U, 0U},
242     {FVID2_STD_WXGA_85,        1280U, 800U,  FVID2_SF_PROGRESSIVE,117500U,  85U,
243      0U, 0U, 0U, 0U, 0U, 0U},
244     {FVID2_STD_1440_900_60,    1440U, 900U,  FVID2_SF_PROGRESSIVE,106500U,  60U,
245      0U, 0U, 0U, 0U, 0U, 0U},
246     {FVID2_STD_1368_768_60,    1368U, 768U,  FVID2_SF_PROGRESSIVE,85860U,   60U,
247      0U, 0U, 0U, 0U, 0U, 0U},
248     {FVID2_STD_1366_768_60,    1366U, 768U,  FVID2_SF_PROGRESSIVE,85500U,   60U,
249      0U, 0U, 0U, 0U, 0U, 0U},
250     {FVID2_STD_1360_768_60,    1360U, 768U,  FVID2_SF_PROGRESSIVE,85500U,   60U,
251      0U, 0U, 0U, 0U, 0U, 0U},
252     {FVID2_STD_SXGA_60,        1280U, 1024U, FVID2_SF_PROGRESSIVE,108000U,  60U,
253      0U, 0U, 0U, 0U, 0U, 0U},
254     {FVID2_STD_SXGA_75,        1280U, 1024U, FVID2_SF_PROGRESSIVE,135000U,  75U,
255      0U, 0U, 0U, 0U, 0U, 0U},
256     {FVID2_STD_SXGA_85,        1280U, 1024U, FVID2_SF_PROGRESSIVE,157500U,  85U,
257      0U, 0U, 0U, 0U, 0U, 0U},
258     {FVID2_STD_WSXGAP_60,      1680U, 1050U, FVID2_SF_PROGRESSIVE,146250U,  60U,
259      0U, 0U, 0U, 0U, 0U, 0U},
260     {FVID2_STD_SXGAP_60,       1400U, 1050U, FVID2_SF_PROGRESSIVE,121750U,  60U,
261      0U, 0U, 0U, 0U, 0U, 0U},
262     {FVID2_STD_SXGAP_75,       1400U, 1050U, FVID2_SF_PROGRESSIVE,156000U,  75U,
263      0U, 0U, 0U, 0U, 0U, 0U},
264     {FVID2_STD_UXGA_60,        1600U, 1200U, FVID2_SF_PROGRESSIVE,162000U,  60U,
265      0U, 0U, 0U, 0U, 0U, 0U},
266     {FVID2_STD_WXGA_5x3_30,    1280U, 800U,  FVID2_SF_PROGRESSIVE,34125U,   30U,
267      0U, 0U, 0U, 0U, 0U, 0U},
268     {FVID2_STD_WXGA_5x3_60,    1280U, 800U,  FVID2_SF_PROGRESSIVE,68250U,   60U,
269      0U, 0U, 0U, 0U, 0U, 0U},
270     {FVID2_STD_WXGA_5x3_75,    1280U, 800U,  FVID2_SF_PROGRESSIVE,102250U,  75U,
271      0U, 0U, 0U, 0U, 0U, 0U}
272 };
274 /** \brief Data format string table. */
275 static Fdm_DataFmtString gFdmDataFmtStrTable[] =
277     {FVID2_DF_YUV422I_UYVY,           "YUV422I_UYVY"          },
278     {FVID2_DF_YUV422I_YUYV,           "YUV422I_YUYV"          },
279     {FVID2_DF_YUV422I_YVYU,           "YUV422I_YVYU"          },
280     {FVID2_DF_YUV422I_VYUY,           "YUV422I_VYUY"          },
281     {FVID2_DF_YUV422SP_UV,            "YUV422SP_UV"           },
282     {FVID2_DF_YUV422SP_VU,            "YUV422SP_VU"           },
283     {FVID2_DF_YUV422P,                "YUV422P"               },
284     {FVID2_DF_YUV420SP_UV,            "YUV420SP_UV"           },
285     {FVID2_DF_YUV420SP_VU,            "YUV420SP_VU"           },
286     {FVID2_DF_YUV420P,                "YUV420P"               },
287     {FVID2_DF_YUV444P,                "YUV444P"               },
288     {FVID2_DF_YUV444I,                "YUV444I"               },
289     {FVID2_DF_RGB16_565,              "RGB16_565"             },
290     {FVID2_DF_ARGB16_1555,            "ARGB16_1555"           },
291     {FVID2_DF_RGBA16_5551,            "RGBA16_5551"           },
292     {FVID2_DF_ARGB16_4444,            "ARGB16_4444"           },
293     {FVID2_DF_RGBA16_4444,            "RGBA16_4444"           },
294     {FVID2_DF_BGRX_4444,              "RGBX12_4444"           },
295     {FVID2_DF_XBGR_4444,              "XRGB12_4444"           },
296     {FVID2_DF_ARGB24_6666,            "ARGB24_6666"           },
297     {FVID2_DF_RGBA24_6666,            "RGBA24_6666"           },
298     {FVID2_DF_RGB24_888,              "RGB24_888"             },
299     {FVID2_DF_XBGR24_8888,            "XBGR24_8888"           },
300     {FVID2_DF_RGBX24_8888,            "RGBX24_8888"           },
301     {FVID2_DF_BGRX24_8888,            "BGRX24_8888"           },
302     {FVID2_DF_ARGB32_8888,            "ARGB32_8888"           },
303     {FVID2_DF_RGBA32_8888,            "RGBA32_8888"           },
304     {FVID2_DF_BGR16_565,              "BGR16_565"             },
305     {FVID2_DF_ABGR16_1555,            "ABGR16_1555"           },
306     {FVID2_DF_ABGR16_4444,            "ABGR16_4444"           },
307     {FVID2_DF_BGRA16_5551,            "BGRA16_5551"           },
308     {FVID2_DF_BGRA16_4444,            "BGRA16_4444"           },
309     {FVID2_DF_AGBR16_1555,            "AGBR16_1555"           },
310     {FVID2_DF_AGBR16_4444,            "AGBR16_4444"           },
311     {FVID2_DF_XGBR16_1555,            "XGBR16_1555"           },
312     {FVID2_DF_BGRX16_5551,            "BGRX16_5551"           },
313     {FVID2_DF_ABGR24_6666,            "ABGR24_6666"           },
314     {FVID2_DF_BGR24_888,              "BGR24_888"             },
315     {FVID2_DF_ABGR32_8888,            "ABGR32_8888"           },
316     {FVID2_DF_BGRA24_6666,            "BGRA24_6666"           },
317     {FVID2_DF_BGRA32_8888,            "BGRA32_8888"           },
318     {FVID2_DF_BITMAP8,                "BITMAP8"               },
319     {FVID2_DF_BITMAP4_LOWER,          "BITMAP4_LOWER"         },
320     {FVID2_DF_BITMAP4_UPPER,          "BITMAP4_UPPER"         },
321     {FVID2_DF_BITMAP2_OFFSET0,        "BITMAP2_OFFSET0"       },
322     {FVID2_DF_BITMAP2_OFFSET1,        "BITMAP2_OFFSET1"       },
323     {FVID2_DF_BITMAP2_OFFSET2,        "BITMAP2_OFFSET2"       },
324     {FVID2_DF_BITMAP2_OFFSET3,        "BITMAP2_OFFSET3"       },
325     {FVID2_DF_BITMAP1_OFFSET0,        "BITMAP1_OFFSET0"       },
326     {FVID2_DF_BITMAP1_OFFSET1,        "BITMAP1_OFFSET1"       },
327     {FVID2_DF_BITMAP1_OFFSET2,        "BITMAP1_OFFSET2"       },
328     {FVID2_DF_BITMAP1_OFFSET3,        "BITMAP1_OFFSET3"       },
329     {FVID2_DF_BITMAP1_OFFSET4,        "BITMAP1_OFFSET4"       },
330     {FVID2_DF_BITMAP1_OFFSET5,        "BITMAP1_OFFSET5"       },
331     {FVID2_DF_BITMAP1_OFFSET6,        "BITMAP1_OFFSET6"       },
332     {FVID2_DF_BITMAP1_OFFSET7,        "BITMAP1_OFFSET7"       },
333     {FVID2_DF_BITMAP8_BGRA32,         "BITMAP8_BGRA32"        },
334     {FVID2_DF_BITMAP4_BGRA32_LOWER,   "BITMAP4_BGRA32_LOWER"  },
335     {FVID2_DF_BITMAP4_BGRA32_UPPER,   "BITMAP4_BGRA32_UPPER"  },
336     {FVID2_DF_BITMAP2_BGRA32_OFFSET0, "BITMAP2_BGRA32_OFFSET0"},
337     {FVID2_DF_BITMAP2_BGRA32_OFFSET1, "BITMAP2_BGRA32_OFFSET1"},
338     {FVID2_DF_BITMAP2_BGRA32_OFFSET2, "BITMAP2_BGRA32_OFFSET2"},
339     {FVID2_DF_BITMAP2_BGRA32_OFFSET3, "BITMAP2_BGRA32_OFFSET3"},
340     {FVID2_DF_BITMAP1_BGRA32_OFFSET0, "BITMAP1_BGRA32_OFFSET0"},
341     {FVID2_DF_BITMAP1_BGRA32_OFFSET1, "BITMAP1_BGRA32_OFFSET1"},
342     {FVID2_DF_BITMAP1_BGRA32_OFFSET2, "BITMAP1_BGRA32_OFFSET2"},
343     {FVID2_DF_BITMAP1_BGRA32_OFFSET3, "BITMAP1_BGRA32_OFFSET3"},
344     {FVID2_DF_BITMAP1_BGRA32_OFFSET4, "BITMAP1_BGRA32_OFFSET4"},
345     {FVID2_DF_BITMAP1_BGRA32_OFFSET5, "BITMAP1_BGRA32_OFFSET5"},
346     {FVID2_DF_BITMAP1_BGRA32_OFFSET6, "BITMAP1_BGRA32_OFFSET6"},
347     {FVID2_DF_BITMAP1_BGRA32_OFFSET7, "BITMAP1_BGRA32_OFFSET7"},
348     {FVID2_DF_BAYER_RAW,              "BAYER_RAW"             },
349     {FVID2_DF_BAYER_GRBG,             "BAYER_GRBG"            },
350     {FVID2_DF_BAYER_RGGB,             "BAYER_RGGB"            },
351     {FVID2_DF_BAYER_BGGR,             "BAYER_BGGR"            },
352     {FVID2_DF_BAYER_GBRG,             "BAYER_GBRG"            },
353     {FVID2_DF_RAW_VBI,                "RAW_VBI"               },
354     {FVID2_DF_RAW24,                  "RAW24"                 },
355     {FVID2_DF_RAW16,                  "RAW16"                 },
356     {FVID2_DF_RAW08,                  "RAW08"                 },
357     {FVID2_DF_BGRX32_8888,            "BGRX32_8888"           },
358     {FVID2_DF_BGRA16_1555,            "BGRA16_1555"           },
359     {FVID2_DF_BGRX16_1555,            "BGRX16_1555"           },
360     {FVID2_DF_BGRA32_1010102,         "BGRA32_1010102"        },
361     {FVID2_DF_BGRX32_1010102,         "BGRX32_1010102"        },
362     {FVID2_DF_RGBA32_1010102,         "RGBA32_1010102"        },
363     {FVID2_DF_RGBX32_1010102,         "RGBX32_1010102"        },
364     {FVID2_DF_BGRA64_16161616,        "BGRA64_16161616"       },
365     {FVID2_DF_BGRX64_16161616,        "BGRX64_16161616"       },
366     {FVID2_DF_ABGR64_16161616,        "ABGR64_16161616"       },
367     {FVID2_DF_XBGR64_16161616,        "XBGR64_16161616"       },
368     {FVID2_DF_XRGB32_8888,            "XRGB32_8888"           },
369     {FVID2_DF_RGBX16_4444,            "RGBX16_4444"           },
370     {FVID2_DF_BGR16_565_A8,           "BRG16_565_A8"          },
371     {FVID2_DF_RGB16_565_A8,           "RGB16_565_A8"          },
372     {FVID2_DF_MISC,                   "MISC"                  },
373     {FVID2_DF_INVALID,                "INVALID"               },
374 };
376 /** \brief Standard string table. */
377 static Fdm_StdString     gFdmStdStrTable[] =
379     {FVID2_STD_NTSC,            "NTSC"           },
380     {FVID2_STD_PAL,             "PAL"            },
381     {FVID2_STD_480I,            "480I"           },
382     {FVID2_STD_576I,            "576I"           },
383     {FVID2_STD_CIF,             "CIF"            },
384     {FVID2_STD_HALF_D1,         "HALF_D1"        },
385     {FVID2_STD_D1,              "D1"             },
386     {FVID2_STD_480P,            "480P"           },
387     {FVID2_STD_576P,            "576P"           },
388     {FVID2_STD_720P_60,         "720P60"         },
389     {FVID2_STD_720P_50,         "720P50"         },
390     {FVID2_STD_1080I_60,        "1080I60"        },
391     {FVID2_STD_1080I_50,        "1080I50"        },
392     {FVID2_STD_1080P_60,        "1080P60"        },
393     {FVID2_STD_1080P_50,        "1080P50"        },
394     {FVID2_STD_1080P_24,        "1080P24"        },
395     {FVID2_STD_1080P_30,        "1080P30"        },
396     {FVID2_STD_VGA_60,          "VGA60"          },
397     {FVID2_STD_VGA_72,          "VGA72"          },
398     {FVID2_STD_VGA_75,          "VGA75"          },
399     {FVID2_STD_VGA_85,          "VGA85"          },
400     {FVID2_STD_WVGA_60,         "WVGA60"         },
401     {FVID2_STD_SVGA_60,         "SVGA60"         },
402     {FVID2_STD_SVGA_72,         "SVGA72"         },
403     {FVID2_STD_SVGA_75,         "SVGA75"         },
404     {FVID2_STD_SVGA_85,         "SVGA85"         },
405     {FVID2_STD_WSVGA_70,        "WSVGA70"        },
406     {FVID2_STD_XGA_60,          "XGA60"          },
407     {FVID2_STD_XGA_DSS_TDM_60,  "XGA_DSS_TDM_60" },
408     {FVID2_STD_XGA_70,          "XGA70"          },
409     {FVID2_STD_XGA_75,          "XGA75"          },
410     {FVID2_STD_XGA_85,          "XGA85"          },
411     {FVID2_STD_WXGA_30,         "WXGA30"         },
412     {FVID2_STD_WXGA_60,         "WXGA60"         },
413     {FVID2_STD_WXGA_75,         "WXGA75"         },
414     {FVID2_STD_WXGA_85,         "WXGA85"         },
415     {FVID2_STD_1440_900_60,     "1440X900@60"    },
416     {FVID2_STD_1368_768_60,     "1368X768@60"    },
417     {FVID2_STD_1366_768_60,     "1366X768@60"    },
418     {FVID2_STD_1360_768_60,     "1360X768@60"    },
419     {FVID2_STD_SXGA_60,         "SXGA60"         },
420     {FVID2_STD_SXGA_75,         "SXGA75"         },
421     {FVID2_STD_SXGA_85,         "SXGA85"         },
422     {FVID2_STD_WSXGAP_60,       "WSXGAP60"       },
423     {FVID2_STD_SXGAP_60,        "SXGAP60"        },
424     {FVID2_STD_SXGAP_75,        "SXGAP75"        },
425     {FVID2_STD_UXGA_60,         "UXGA60"         },
426     {FVID2_STD_MUX_2CH_D1,      "MUX_2CH_D1"     },
427     {FVID2_STD_MUX_2CH_HALF_D1, "MUX_2CH_HALF_D1"},
428     {FVID2_STD_MUX_2CH_CIF,     "MUX_2CH_CIF"    },
429     {FVID2_STD_MUX_4CH_D1,      "MUX_4CH_D1"     },
430     {FVID2_STD_MUX_4CH_CIF,     "MUX_4CH_CIF"    },
431     {FVID2_STD_MUX_4CH_HALF_D1, "MUX_4CH_HALF_D1"},
432     {FVID2_STD_MUX_8CH_CIF,     "MUX_8CH_CIF"    },
433     {FVID2_STD_MUX_8CH_HALF_D1, "MUX_8CH_HALF_D1"},
434     {FVID2_STD_WXGA_5x3_30,     "WXGA_5x3_30"    },
435     {FVID2_STD_WXGA_5x3_60,     "WXGA_5x3_60"    },
436     {FVID2_STD_WXGA_5x3_75,     "WXGA_5x3_75"    },
437     {FVID2_STD_AUTO_DETECT,     "AUTO_DETECT"    },
438     {FVID2_STD_CUSTOM,          "CUSTOM"         },
439 };
441 /* ========================================================================== */
442 /*                          Function Definitions                              */
443 /* ========================================================================== */
445 /**
446  *  Fvid2_init
447  *  \brief FVID2 init function.
448  *
449  *  Initializes the drivers and the hardware.
450  *  This function should be called before calling any of driver API's.
451  *
452  *  \param arg          Not used currently. Meant for future purpose.
453  *
454  *  \return             Returns 0 on success else returns error value.
455  */
456 int32_t Fvid2_init(void *args)
458     uint32_t cnt;
459     int32_t  retVal = FVID2_SOK;
460     int32_t  initValue;
461     SemaphoreP_Params params;
463     /* Init all global variables to zero */
464     Fvid2_memset(&gFdmObj, 0U, sizeof (gFdmObj));
466     /* Mark pool flags as free */
467     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
468     {
469         gFdmObj.fdmDriverObjects[cnt].isUsed = (uint32_t) FALSE;
470     }
471     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_CH_OBJS; cnt++)
472     {
473         gFdmObj.fdmChannelObjects[cnt].isUsed = (uint32_t) FALSE;
474     }
476     gFdmObj.versionString = FVID2_VERSION_STRING;
477     gFdmObj.versionNumber = FVID2_VERSION_NUMBER;
479     /* Allocate lock semaphore */
480     SemaphoreP_Params_init(&params);
481     params.mode = SemaphoreP_Mode_BINARY;
482     initValue       = 1;
483     gFdmObj.lockSem = SemaphoreP_create(initValue, &params);
484     if (NULL == gFdmObj.lockSem)
485     {
486         Fvid2_printf("FVID2 semaphore create failed!!\r\n");
487         retVal = FVID2_EALLOC;
488     }
490     /* Free-up memory if error occurs */
491     if (FVID2_SOK != retVal)
492     {
493         Fvid2_deInit(NULL);
494     }
496     return (retVal);
499 /**
500  *  Fvid2_deInit
501  *  \brief FVID2 deinit function.
502  *
503  *  Uninitializes the drivers and the hardware.
504  *
505  *  \param arg          Not used currently. Meant for future purpose.
506  *
507  *  \return             Returns 0 on success else returns error value.
508  */
509 int32_t Fvid2_deInit(void *args)
511     int32_t retVal = FVID2_SOK;
513     /* Delete the lock semaphore */
514     if (NULL != gFdmObj.lockSem)
515     {
516         SemaphoreP_delete(gFdmObj.lockSem);
517         gFdmObj.lockSem = NULL;
518     }
520     return (retVal);
523 /**
524  *  Fvid2_getVersionString
525  *  \brief Get the FVID2 driver version in string form. This API can be
526  *  called before calling #Fvid2_init().
527  *
528  *  \return             Returns pointer to FVID2 version string.
529  */
530 const char *Fvid2_getVersionString(void)
532     return (FVID2_VERSION_STRING);
535 /**
536  *  Fvid2_getVersionNumber
537  *  \brief Get the FVID2 driver version in number form. This API can be
538  *  called before calling #Fvid2_init().
539  *
540  *  \return             FVID2 version number.
541  */
542 uint32_t Fvid2_getVersionNumber(void)
544     return (FVID2_VERSION_NUMBER);
547 /**
548  *  Fvid2_registerDriver
549  *  \brief FVID2 register driver function.
550  */
551 int32_t Fvid2_registerDriver(const Fvid2_DrvOps *drvOps)
553     int32_t     retVal = FVID2_SOK;
554     Fdm_Driver *drv;
555     uint32_t    cnt;
557     /* Check for NULL pointers */
558     OSAL_Assert(NULL == drvOps);
560     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
562     /* Check whether the driver is already registered */
563     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
564     {
565         if (TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed)
566         {
567             /* Check for NULL pointers */
568             OSAL_Assert(NULL == gFdmObj.fdmDriverObjects[cnt].drvOps);
570             if (drvOps->drvId == gFdmObj.fdmDriverObjects[cnt].drvOps->drvId)
571             {
572                 Fvid2_printf("Driver with same id already registered!!\r\n");
573                 retVal = FVID2_EDRIVER_INUSE;
574                 break;
575             }
576         }
577     }
579     if (FVID2_SOK == retVal)
580     {
581         /* Get a free driver object */
582         drv = fdmAllocDriverObject();
583         if (NULL != drv)
584         {
585             drv->drvOps   = drvOps;
586             drv->numOpens = 0U;
587         }
588         else
589         {
590             Fvid2_printf("Alloc driver object failed!!\r\n");
591             retVal = FVID2_EALLOC;
592         }
593     }
595     SemaphoreP_post(gFdmObj.lockSem);
597     return (retVal);
600 /**
601  *  Fvid2_unRegisterDriver
602  *  \brief FVID2 unregister driver function.
603  */
604 int32_t Fvid2_unRegisterDriver(const Fvid2_DrvOps *drvOps)
606     int32_t retVal = FVID2_EFAIL;
608     /* Check for NULL pointers */
609     OSAL_Assert(NULL == drvOps);
611     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
613     /* Free the driver object */
614     retVal = fdmFreeDriverObject(drvOps);
616     SemaphoreP_post(gFdmObj.lockSem);
618     return (retVal);
621 /**
622  *  Fvid2_create
623  *  \brief Opens the driver identified by the driver ID.
624  */
625 Fvid2_Handle Fvid2_create(uint32_t              drvId,
626                           uint32_t              instanceId,
627                           void                 *createArgs,
628                           void                 *createStatusArgs,
629                           const Fvid2_CbParams *cbParams)
631     Fdm_Driver       *drv = NULL;
632     uint32_t          cnt;
633     Fdrv_Handle       drvHandle = NULL;
634     Fdm_Channel      *channel   = NULL;
635     Fvid2_DrvCbParams fdmCbParams, *tempCbParams;
637     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
639     /* Get the matching driver object */
640     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
641     {
642         if (TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed)
643         {
644             /* Check for NULL pointers */
645             OSAL_Assert(NULL == gFdmObj.fdmDriverObjects[cnt].drvOps);
647             if (drvId == gFdmObj.fdmDriverObjects[cnt].drvOps->drvId)
648             {
649                 drv = &gFdmObj.fdmDriverObjects[cnt];
650                 /* Allocate channel object */
651                 channel = fdmAllocChannelObject();
652                 break;
653             }
654         }
655     }
657     if (NULL != channel)
658     {
659         if (NULL != drv->drvOps->createFxn)
660         {
661             if (NULL != cbParams)
662             {
663                 if (NULL != cbParams->cbFxn)
664                 {
665                     fdmCbParams.fdmCbFxn = &fdmDriverCbFxn;
666                 }
667                 else
668                 {
669                     fdmCbParams.fdmCbFxn = NULL;
670                 }
671                 if (NULL != cbParams->errCbFxn)
672                 {
673                     fdmCbParams.fdmErrCbFxn = &fdmDriverErrCbFxn;
674                 }
675                 else
676                 {
677                     fdmCbParams.fdmErrCbFxn = NULL;
678                 }
680                 fdmCbParams.handle   = channel;
681                 fdmCbParams.errList  = cbParams->errList;
682                 fdmCbParams.fdmData  = channel;
683                 tempCbParams         = &fdmCbParams;
684             }
685             else
686             {
687                 tempCbParams = NULL;
688             }
690             /* Call the driver's create function */
691             drvHandle = drv->drvOps->createFxn(
692                 drvId,
693                 instanceId,
694                 createArgs,
695                 createStatusArgs,
696                 tempCbParams);
697         }
698         else
699         {
700             Fvid2_printf("Driver Ops not supported!!\r\n");
701         }
703         if (NULL != drvHandle)
704         {
705             drv->numOpens++;
707             channel->drv       = drv;
708             channel->drvHandle = drvHandle;
709             Fvid2CbParams_init(&channel->cbParams);
710             if (NULL != cbParams)
711             {
712                 Fvid2_memcpy(
713                     &channel->cbParams,
714                     cbParams,
715                     sizeof (Fvid2_CbParams));
716             }
717         }
718         else
719         {
720             Fvid2_printf("Driver create failed!!\r\n");
722             /* Free the allocated channel object */
723             fdmFreeChannelObject(channel);
724             channel = NULL;
725         }
726     }
727     else
728     {
729         Fvid2_printf("EALLOC: Invalid driver ID!!\r\n");
730     }
732     SemaphoreP_post(gFdmObj.lockSem);
734     return (channel);
737 /**
738  *  Fvid2_delete
739  *  \brief Application calls Fvid2_delete to close the logical channel
740  *  associated with FVID2 handle.
741  */
742 int32_t Fvid2_delete(Fvid2_Handle handle, void *deleteArgs)
744     int32_t      retVal = FVID2_SOK;
745     Fdm_Channel *channel;
747     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
749     if (NULL != handle)
750     {
751         channel = (Fdm_Channel *) handle;
753         /* Check for NULL pointers */
754         OSAL_Assert(NULL == channel->drv);
755         OSAL_Assert(NULL == channel->drv->drvOps);
757         if (NULL != channel->drv->drvOps->deleteFxn)
758         {
759             /* Call the driver's delete function */
760             retVal = channel->drv->drvOps->deleteFxn(
761                 channel->drvHandle,
762                 deleteArgs);
763         }
764         else
765         {
766             Fvid2_printf("Driver Ops not supported!!\r\n");
767         }
769         channel->drv->numOpens--;
770         /* Free the allocated channel object */
771         channel->drv               = NULL;
772         channel->drvHandle         = NULL;
773         channel->cbParams.cbFxn    = NULL;
774         channel->cbParams.errCbFxn = NULL;
775         channel->cbParams.errList  = NULL;
776         channel->cbParams.appData  = NULL;
777         fdmFreeChannelObject(channel);
778     }
779     else
780     {
781         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
782         retVal = FVID2_EBADARGS;
783     }
785     SemaphoreP_post(gFdmObj.lockSem);
787     return (retVal);
790 /**
791  *  Fvid2_control
792  *  \brief An application calls Fvid2_control to send device-specific control
793  *  commands to the video driver.
794  */
795 int32_t Fvid2_control(Fvid2_Handle  handle,
796                       uint32_t      cmd,
797                       void         *cmdArgs,
798                       void         *cmdStatusArgs)
800     int32_t      retVal = FVID2_SOK;
801     Fdm_Channel *channel;
803     if (NULL != handle)
804     {
805         channel = (Fdm_Channel *) handle;
807         /* Check for NULL pointers */
808         OSAL_Assert(NULL == channel->drv);
809         OSAL_Assert(NULL == channel->drv->drvOps);
811         if (NULL != channel->drv->drvOps->controlFxn)
812         {
813             /* Call the driver's control function */
814             retVal = channel->drv->drvOps->controlFxn(
815                 channel->drvHandle,
816                 cmd,
817                 cmdArgs,
818                 cmdStatusArgs);
819         }
820         else
821         {
822             Fvid2_printf("Driver Ops not supported!!\r\n");
823             retVal = FVID2_EUNSUPPORTED_OPS;
824         }
825     }
826     else
827     {
828         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
829         retVal = FVID2_EBADARGS;
830     }
832     return (retVal);
835 /**
836  *  Fvid2_queue
837  *  \brief An application calls Fvid2_queue to submit a video buffer to the
838  *  video device driver.
839  *  This is used in capture/display drivers.
840  */
841 int32_t Fvid2_queue(Fvid2_Handle     handle,
842                     Fvid2_FrameList *frameList,
843                     uint32_t         streamId)
845     int32_t      retVal = FVID2_SOK;
846     Fdm_Channel *channel;
848     if (NULL != handle)
849     {
850         channel = (Fdm_Channel *) handle;
852         /* Check for NULL pointers */
853         OSAL_Assert(NULL == channel->drv);
854         OSAL_Assert(NULL == channel->drv->drvOps);
856         if (NULL != channel->drv->drvOps->queueFxn)
857         {
858             /* Call the driver's queue function */
859             retVal = channel->drv->drvOps->queueFxn(
860                 channel->drvHandle,
861                 frameList,
862                 streamId);
863         }
864         else
865         {
866             Fvid2_printf("Driver Ops not supported!!\r\n");
867             retVal = FVID2_EUNSUPPORTED_OPS;
868         }
869     }
870     else
871     {
872         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
873         retVal = FVID2_EBADARGS;
874     }
876     return (retVal);
879 /**
880  *  Fvid2_dequeue
881  *  \brief An application calls Fvid2_dequeue to request the video device
882  *  driver to give ownership of a video buffer.
883  *  This is used in capture/display drivers.
884  */
885 int32_t Fvid2_dequeue(Fvid2_Handle      handle,
886                       Fvid2_FrameList  *frameList,
887                       uint32_t          streamId,
888                       uint32_t          timeout)
890     int32_t      retVal = FVID2_SOK;
891     Fdm_Channel *channel;
893     if (NULL != handle)
894     {
895         channel = (Fdm_Channel *) handle;
897         /* Check for NULL pointers */
898         OSAL_Assert(NULL == channel->drv);
899         OSAL_Assert(NULL == channel->drv->drvOps);
901         if (NULL != channel->drv->drvOps->dequeueFxn)
902         {
903             /* Call the driver's dequeue function */
904             retVal = channel->drv->drvOps->dequeueFxn(
905                 channel->drvHandle,
906                 frameList,
907                 streamId,
908                 timeout);
909         }
910         else
911         {
912             Fvid2_printf("Driver Ops not supported!!\r\n");
913             retVal = FVID2_EUNSUPPORTED_OPS;
914         }
915     }
916     else
917     {
918         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
919         retVal = FVID2_EBADARGS;
920     }
922     return (retVal);
925 /**
926  *  Fvid2_processRequest
927  *  \brief An application calls Fvid2_processRequest to submit a video buffer
928  *  to the video device driver.
929  */
930 int32_t Fvid2_processRequest(Fvid2_Handle     handle,
931                              Fvid2_FrameList *inFrameList,
932                              Fvid2_FrameList *outFrameList)
934     int32_t      retVal = FVID2_SOK;
935     Fdm_Channel *channel;
937     if (NULL != handle)
938     {
939         channel = (Fdm_Channel *) handle;
941         /* Check for NULL pointers */
942         OSAL_Assert(NULL == channel->drv);
943         OSAL_Assert(NULL == channel->drv->drvOps);
945         if (NULL != channel->drv->drvOps->processRequestFxn)
946         {
947             /* Call the driver's process frame function */
948             retVal = channel->drv->drvOps->processRequestFxn(
949                 channel->drvHandle,
950                 inFrameList,
951                 outFrameList);
952         }
953         else
954         {
955             Fvid2_printf("Driver Ops not supported!!\r\n");
956             retVal = FVID2_EUNSUPPORTED_OPS;
957         }
958     }
959     else
960     {
961         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
962         retVal = FVID2_EBADARGS;
963     }
965     return (retVal);
968 /**
969  *  Fvid2_getProcessedRequest
970  *  \brief An application calls Fvid2_getProcessedRequest to request the video
971  *  device driver to give ownership of a video buffer.
972  */
973 int32_t Fvid2_getProcessedRequest(Fvid2_Handle     handle,
974                                   Fvid2_FrameList *inFrameList,
975                                   Fvid2_FrameList *outFrameList,
976                                   uint32_t         timeout)
978     int32_t      retVal = FVID2_SOK;
979     Fdm_Channel *channel;
981     if (NULL != handle)
982     {
983         channel = (Fdm_Channel *) handle;
985         /* Check for NULL pointers */
986         OSAL_Assert(NULL == channel->drv);
987         OSAL_Assert(NULL == channel->drv->drvOps);
989         if (NULL != channel->drv->drvOps->getProcessedRequestFxn)
990         {
991             /* Call the driver's get process frame function */
992             retVal = channel->drv->drvOps->getProcessedRequestFxn(
993                 channel->drvHandle,
994                 inFrameList,
995                 outFrameList,
996                 timeout);
997         }
998         else
999         {
1000             Fvid2_printf("Driver Ops not supported!!\r\n");
1001             retVal = FVID2_EUNSUPPORTED_OPS;
1002         }
1003     }
1004     else
1005     {
1006         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1007         retVal = FVID2_EBADARGS;
1008     }
1010     return (retVal);
1013 /**
1014  *  Fvid2_getModeInfo
1015  *  \brief Function to get the information about various FVID2 modes/standards.
1016  */
1017 int32_t Fvid2_getModeInfo(Fvid2_ModeInfo *modeInfo)
1019     int32_t         retVal = FVID2_SOK;
1020     uint32_t        entryCnt;
1021     Fvid2_ModeInfo *matchedEntry = NULL;
1023     if (NULL != modeInfo)
1024     {
1025         for (entryCnt = 0U; entryCnt < FDM_NUM_STD_INFO_ENTRIES; entryCnt++)
1026         {
1027             if (gFdmStdInfoTable[entryCnt].standard == modeInfo->standard)
1028             {
1029                 matchedEntry = &gFdmStdInfoTable[entryCnt];
1030                 break;
1031             }
1032         }
1034         if (NULL == matchedEntry)
1035         {
1036             Fvid2_printf("Unsupported standard!!\r\n");
1037             retVal = FVID2_EINVALID_PARAMS;
1038         }
1039         else
1040         {
1041             Fvid2_memcpy(modeInfo, matchedEntry, sizeof (Fvid2_ModeInfo));
1042         }
1043     }
1044     else
1045     {
1046         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1047         retVal = FVID2_EBADARGS;
1048     }
1050     return (retVal);
1053 /**
1054  *  \brief Function to get the name of the data format in printable string.
1055  *
1056  *  \param dataFmt      [IN] Data format to get the name.
1057  *                           For valid values see #Fvid2_DataFormat.
1058  *
1059  *  \return Returns a const pointer to the string. If the data format is not
1060  *  known, then it return the string as "UNKNOWN".
1061  */
1062 const char *Fvid2_getDataFmtString(uint32_t dataFmt)
1064     uint32_t    entryCnt;
1065     const char *dataFmtStr = NULL;
1067     for (entryCnt = 0U; entryCnt < FDM_NUM_DATA_FMT_STR_ENTRIES; entryCnt++)
1068     {
1069         if (gFdmDataFmtStrTable[entryCnt].dataFmt == dataFmt)
1070         {
1071             dataFmtStr = gFdmDataFmtStrTable[entryCnt].dataFmtStr;
1072             break;
1073         }
1074     }
1076     if (NULL == dataFmtStr)
1077     {
1078         dataFmtStr = "UNKNOWN";
1079     }
1081     return (dataFmtStr);
1084 /**
1085  *  \brief Function to get the name of the standard in printable string.
1086  *
1087  *  \param standard     [IN] Standard to get the name.
1088  *                           For valid values see #Fvid2_Standard.
1089  *
1090  *  \return Returns a const pointer to the string. If the standard is not
1091  *  known, then it return the string as "UNKNOWN".
1092  */
1093 const char *Fvid2_getStandardString(uint32_t standard)
1095     uint32_t    entryCnt;
1096     const char *stdStr = NULL;
1098     for (entryCnt = 0U; entryCnt < FDM_NUM_STD_STR_ENTRIES; entryCnt++)
1099     {
1100         if (gFdmStdStrTable[entryCnt].standard == standard)
1101         {
1102             stdStr = gFdmStdStrTable[entryCnt].stdStr;
1103             break;
1104         }
1105     }
1107     if (NULL == stdStr)
1108     {
1109         stdStr = "UNKNOWN";
1110     }
1112     return (stdStr);
1115 /**
1116  *  Fvid2_checkFrameList
1117  *  \brief Checks the FVID2 frame list for error and returns appropriate error.
1118  *  This is used by the drivers and not by the application.
1119  */
1120 int32_t Fvid2_checkFrameList(const Fvid2_FrameList *frameList,
1121                              uint32_t maxFrames)
1123     int32_t  retVal = FVID2_SOK;
1124     uint32_t frmCnt;
1126     /* Check for NULL pointer */
1127     if (NULL == frameList)
1128     {
1129         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1130         retVal = FVID2_EBADARGS;
1131     }
1132     else
1133     {
1134         /* Check whether num frames is within range */
1135         if (frameList->numFrames > maxFrames)
1136         {
1137             Fvid2_printf("Number of frames exceeds max!!\r\n");
1138             retVal = FVID2_EOUT_OF_RANGE;
1139         }
1141         /* Check whether num frames is within range */
1142         if (frameList->numFrames > FVID2_MAX_FRAME_PTR)
1143         {
1144             Fvid2_printf("Number of frames exceeds FVID2 max!!\r\n");
1145             retVal = FVID2_EOUT_OF_RANGE;
1146         }
1148         /* Check whether num frames is zero */
1149         if (0U == frameList->numFrames)
1150         {
1151             Fvid2_printf("Number of frames is zero!!\r\n");
1152             retVal = FVID2_EOUT_OF_RANGE;
1153         }
1155         if (FVID2_SOK == retVal)
1156         {
1157             /* Check the individual frame pointers */
1158             for (frmCnt = 0U; frmCnt < frameList->numFrames; frmCnt++)
1159             {
1160                 /* Check for NULL pointer */
1161                 if (NULL == frameList->frames[frmCnt])
1162                 {
1163                     Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1164                     retVal = FVID2_EBADARGS;
1165                     break;
1166                 }
1167             }
1168         }
1169     }
1171     return (retVal);
1174 /**
1175  *  Fvid2_checkDqFrameList
1176  *  \brief Checks the FVID2 frame list of dequeue call for error and returns
1177  *  appropriate error. For dequeue operation, the frame pointers in the frames
1178  *  should not be checked as this will be filled by the driver.
1179  *  This is used by the drivers and not by the application.
1180  */
1181 int32_t Fvid2_checkDqFrameList(const Fvid2_FrameList *frameList,
1182                                uint32_t               maxFrames)
1184     int32_t retVal = FVID2_SOK;
1186     /* Check for NULL pointer */
1187     if (NULL == frameList)
1188     {
1189         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1190         retVal = FVID2_EBADARGS;
1191     }
1192     else
1193     {
1194         /* Check whether max frames is within range */
1195         if (maxFrames > FVID2_MAX_FRAME_PTR)
1196         {
1197             Fvid2_printf("Number of frames exceeds FVID2 max!!\r\n");
1198             retVal = FVID2_EOUT_OF_RANGE;
1199         }
1200     }
1202     return (retVal);
1205 /**
1206  *  Fvid2_copyFrameList
1207  *  \brief Copies the source frame list to the destination frame list.
1208  *  This also resets the frame pointers from the source frame list.
1209  *  This is used by the drivers and not by the application.
1210  */
1211 void Fvid2_copyFrameList(Fvid2_FrameList *dest, Fvid2_FrameList *src)
1213     uint32_t frmCnt;
1215     /* Check for NULL pointers */
1216     OSAL_Assert(NULL == dest);
1217     OSAL_Assert(NULL == src);
1218     OSAL_Assert(src->numFrames >= FVID2_MAX_FRAME_PTR);
1220     dest->numFrames  = src->numFrames;
1221     dest->drvData    = src->drvData;
1223     /* Copy the individual frames */
1224     for (frmCnt = 0U; frmCnt < src->numFrames; frmCnt++)
1225     {
1226         dest->frames[frmCnt] = src->frames[frmCnt];
1227         src->frames[frmCnt]  = NULL;
1228     }
1230     return;
1233 /**
1234  *  Fvid2_duplicateFrameList
1235  *  \brief Duplicate the source frame list to the destination frame list.
1236  *  This does not reset the frame pointers from the source frame list.
1237  *  This is used by the drivers and not by the application.
1238  */
1239 void Fvid2_duplicateFrameList(Fvid2_FrameList *dest, const Fvid2_FrameList *src)
1241     uint32_t frmCnt;
1243     /* Check for NULL pointers */
1244     OSAL_Assert(NULL == dest);
1245     OSAL_Assert(NULL == src);
1246     OSAL_Assert(src->numFrames >= FVID2_MAX_FRAME_PTR);
1248     dest->numFrames  = src->numFrames;
1249     dest->drvData    = src->drvData;
1251     /* Duplicate the individual frames */
1252     for (frmCnt = 0U; frmCnt < src->numFrames; frmCnt++)
1253     {
1254         dest->frames[frmCnt] = src->frames[frmCnt];
1255     }
1257     return;
1260 /**
1261  *  fdmDriverCbFxn
1262  *  \brief FVID2 driver manager driver callback function. Whenever the drivers
1263  *  wants to call the application callback function, this function will be
1264  *  called by the driver and FDM will in turn call the application callback
1265  *  function.
1266  *  This is used by the drivers and not by the application.
1267  */
1268 static int32_t fdmDriverCbFxn(void *fdmData)
1270     int32_t      retVal;
1271     Fdm_Channel *channel;
1273     /* Check for NULL pointers */
1274     OSAL_Assert(NULL == fdmData);
1276     channel = (Fdm_Channel *) fdmData;
1277     OSAL_Assert(NULL == channel->cbParams.cbFxn);
1278     retVal = channel->cbParams.cbFxn(channel, channel->cbParams.appData);
1280     return (retVal);
1283 /**
1284  *  fdmDriverErrCbFxn
1285  *  \brief FVID2 driver manager driver error callback function.
1286  *  Whenever the drivers wants to call the application error callback function,
1287  *  this function will be called by the driver and FDM will in turn call the
1288  *  application error callback function.
1289  *  This is used by the drivers and not by the application.
1290  */
1291 static int32_t fdmDriverErrCbFxn(void *fdmData, void *errList)
1293     int32_t      retVal;
1294     Fdm_Channel *channel;
1296     /* Check for NULL pointers */
1297     OSAL_Assert(NULL == fdmData);
1299     channel = (Fdm_Channel *) fdmData;
1300     OSAL_Assert(NULL == channel->cbParams.errCbFxn);
1301     retVal =
1302         channel->cbParams.errCbFxn(channel, channel->cbParams.appData, errList);
1304     return (retVal);
1307 /**
1308  *  fdmAllocDriverObject
1309  *  \brief Allocate memory for driver object from static memory pool.
1310  *  Returns NULL if memory pool is full.
1311  */
1312 static Fdm_Driver *fdmAllocDriverObject(void)
1314     uint32_t    cnt;
1315     Fdm_Driver *drv = NULL;
1317     /* Get a free driver object */
1318     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
1319     {
1320         if (FALSE == gFdmObj.fdmDriverObjects[cnt].isUsed)
1321         {
1322             drv         = &gFdmObj.fdmDriverObjects[cnt];
1323             drv->isUsed = (uint32_t) TRUE;
1324             break;
1325         }
1326     }
1328     return (drv);
1331 /**
1332  *  fdmFreeDriverObject
1333  *  \brief Free-up the memory allocated for driver object.
1334  */
1335 static int32_t fdmFreeDriverObject(const Fvid2_DrvOps *drvOps)
1337     uint32_t cnt;
1338     int32_t  retVal = FVID2_EFAIL;
1340     /* Check for NULL pointers */
1341     OSAL_Assert(NULL == drvOps);
1343     /* Free the driver object */
1344     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
1345     {
1346         if ((TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed) &&
1347             (drvOps == gFdmObj.fdmDriverObjects[cnt].drvOps))
1348         {
1349             if (0u == gFdmObj.fdmDriverObjects[cnt].numOpens)
1350             {
1351                 gFdmObj.fdmDriverObjects[cnt].isUsed   = (uint32_t) FALSE;
1352                 gFdmObj.fdmDriverObjects[cnt].drvOps   = NULL;
1353                 gFdmObj.fdmDriverObjects[cnt].numOpens = 0u;
1354                 retVal = FVID2_SOK;
1355             }
1356             else
1357             {
1358                 Fvid2_printf("Driver in use!!\r\n");
1359                 retVal = FVID2_EDEVICE_INUSE;
1360             }
1361             break;
1362         }
1363     }
1365     if (FVID2_EFAIL == retVal)
1366     {
1367         Fvid2_printf("Driver ops not found!!\r\n");
1368     }
1370     return (retVal);
1373 /**
1374  *  fdmAllocChannelObject
1375  *  \brief Allocate memory for channel object from static memory pool.
1376  *  Returns NULL if memory pool is full.
1377  */
1378 static Fdm_Channel *fdmAllocChannelObject(void)
1380     uint32_t       cnt;
1381     Fdm_Channel *channel = NULL;
1383     /* Get a free channel object */
1384     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_CH_OBJS; cnt++)
1385     {
1386         if (FALSE == gFdmObj.fdmChannelObjects[cnt].isUsed)
1387         {
1388             channel         = &gFdmObj.fdmChannelObjects[cnt];
1389             channel->isUsed = (uint32_t) TRUE;
1390             break;
1391         }
1392     }
1394     return (channel);
1397 /**
1398  *  fdmFreeChannelObject
1399  *  \brief Free-up the memory allocated for channel object.
1400  */
1401 static int32_t fdmFreeChannelObject(Fdm_Channel *channel)
1403     int32_t retVal = FVID2_EALLOC;
1405     /* Check for NULL pointers */
1406     OSAL_Assert(NULL == channel);
1408     /* Free the channel object */
1409     if (TRUE == channel->isUsed)
1410     {
1411         channel->isUsed = (uint32_t) FALSE;
1412         retVal          = FVID2_SOK;
1413     }
1414     else
1415     {
1416         Fvid2_printf("Freeing a channel object not in use!!\r\n");
1417     }
1419     return (retVal);
1422 static void Fvid2_printf(const char *format, ...)
1424     return;
1427 static void Fvid2_memset(void *mem, int32_t ch, uint32_t byteCount)
1429     memset(mem, ch, byteCount);
1430     return;
1433 static void Fvid2_memcpy(void *dest, const void *src, uint32_t byteCount)
1435     memcpy(dest, src, byteCount);
1436     return;