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