Added FVID2 driver manager
[keystone-rtos/fvid2.git] / src / fvid2_drvMgr.c
1 /* =============================================================================
2  *   Copyright (c) Texas Instruments Incorporated 2012-2015
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 <csl_fvid2_dataTypes.h>
47 #include <fvid2_drvMgr.h>
48 #include <ti/osal/osal.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              numOpens;
79     /**< Number of times the driver is opened using create API. */
80     UInt32              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         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            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 fdmDriverCbFxn(Ptr fdmData, Ptr reserved);
155 static Int32 fdmDriverErrCbFxn(Ptr fdmData, void *errList, Ptr reserved);
156 static Fdm_Driver *fdmAllocDriverObject(void);
157 static Int32 fdmFreeDriverObject(const Fvid2_DrvOps *drvOps);
158 static Fdm_Channel *fdmAllocChannelObject(void);
159 static Int32 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
166 /* ========================================================================== */
167 /*                            Global Variables                                */
168 /* ========================================================================== */
170 /** \brief FDM objects. */
171 static Fdm_Object        gFdmObj;
173 /** \brief FVID2 standard information table. */
174 static Fvid2_ModeInfo    gFdmStdInfoTable[] =
176     /* Standard, FrameWidth, FrameHeight, ScanFormat, PixelClock (KHz), FPS,
177      * Reserved */
178     {FVID2_STD_NTSC,           720U,  480U,  FVID2_SF_INTERLACED,
179      27000U,
180      30U,
181      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
182     {FVID2_STD_PAL,            720U,  576U,  FVID2_SF_INTERLACED, 27000U,   25U,
183      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
184     {FVID2_STD_480I,           720U,  480U,  FVID2_SF_INTERLACED, 27000U,   30U,
185      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
186     {FVID2_STD_576I,           720U,  576U,  FVID2_SF_INTERLACED, 27000U,   25U,
187      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
188     {FVID2_STD_480P,           720U,  480U,  FVID2_SF_PROGRESSIVE,27000U,   60U,
189      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
190     {FVID2_STD_576P,           720U,  576U,  FVID2_SF_PROGRESSIVE,27000U,   50U,
191      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
192     {FVID2_STD_720P_60,        1280U, 720U,  FVID2_SF_PROGRESSIVE,74250U,   60U,
193      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
194     {FVID2_STD_720P_50,        1280U, 720U,  FVID2_SF_PROGRESSIVE,74250U,   50U,
195      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
196     {FVID2_STD_1080I_60,       1920U, 1080U, FVID2_SF_INTERLACED, 74250U,   30U,
197      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
198     {FVID2_STD_1080I_50,       1920U, 1080U, FVID2_SF_INTERLACED, 74250U,   25U,
199      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
200     {FVID2_STD_1080P_60,       1920U, 1080U, FVID2_SF_PROGRESSIVE,148500U,  60U,
201      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
202     {FVID2_STD_1080P_50,       1920U, 1080U, FVID2_SF_PROGRESSIVE,148500U,  50U,
203      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
204     {FVID2_STD_1080P_24,       1920U, 1080U, FVID2_SF_PROGRESSIVE,74250U,   24U,
205      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
206     {FVID2_STD_1080P_30,       1920U, 1080U, FVID2_SF_PROGRESSIVE,74250U,   30U,
207      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
208     {FVID2_STD_VGA_60,         640U,  480U,  FVID2_SF_PROGRESSIVE,25175U,   60U,
209      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
210     {FVID2_STD_VGA_72,         640U,  480U,  FVID2_SF_PROGRESSIVE,31500U,   72U,
211      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
212     {FVID2_STD_VGA_75,         640U,  480U,  FVID2_SF_PROGRESSIVE,31500U,   75U,
213      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
214     {FVID2_STD_VGA_85,         640U,  480U,  FVID2_SF_PROGRESSIVE,36000U,   85U,
215      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
216     {FVID2_STD_WVGA_60,        800U,  480U,  FVID2_SF_PROGRESSIVE,33500U,   60U,
217      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
218     {FVID2_STD_SVGA_60,        800U,  600U,  FVID2_SF_PROGRESSIVE,40000U,   60U,
219      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
220     {FVID2_STD_SVGA_72,        800U,  600U,  FVID2_SF_PROGRESSIVE,50000U,   72U,
221      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
222     {FVID2_STD_SVGA_75,        800U,  600U,  FVID2_SF_PROGRESSIVE,49500U,   75U,
223      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
224     {FVID2_STD_SVGA_85,        800U,  600U,  FVID2_SF_PROGRESSIVE,56250U,   85U,
225      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
226     {FVID2_STD_WSVGA_70,       1024U, 600U,  FVID2_SF_PROGRESSIVE,50800U,   70U,
227      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
228     {FVID2_STD_XGA_60,         1024U, 768U,  FVID2_SF_PROGRESSIVE,65000U,   60U,
229      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
230     {FVID2_STD_XGA_DSS_TDM_60, 1024U, 768U,  FVID2_SF_PROGRESSIVE,64000U,   60U,
231      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
232     {FVID2_STD_XGA_70,         1024U, 768U,  FVID2_SF_PROGRESSIVE,75000U,   70U,
233      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
234     {FVID2_STD_XGA_75,         1024U, 768U,  FVID2_SF_PROGRESSIVE,78750U,   75U,
235      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
236     {FVID2_STD_XGA_85,         1024U, 768U,  FVID2_SF_PROGRESSIVE,94500U,   85U,
237      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
238     {FVID2_STD_WXGA_30,        1280U, 800U,  FVID2_SF_PROGRESSIVE,34125U,   30U,
239      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
240     {FVID2_STD_WXGA_60,        1280U, 800U,  FVID2_SF_PROGRESSIVE,83500U,   60U,
241      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
242     {FVID2_STD_WXGA_75,        1280U, 800U,  FVID2_SF_PROGRESSIVE,102250U,  75U,
243      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
244     {FVID2_STD_WXGA_85,        1280U, 800U,  FVID2_SF_PROGRESSIVE,117500U,  85U,
245      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
246     {FVID2_STD_1440_900_60,    1440U, 900U,  FVID2_SF_PROGRESSIVE,106500U,  60U,
247      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
248     {FVID2_STD_1368_768_60,    1368U, 768U,  FVID2_SF_PROGRESSIVE,85860U,   60U,
249      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
250     {FVID2_STD_1366_768_60,    1366U, 768U,  FVID2_SF_PROGRESSIVE,85500U,   60U,
251      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
252     {FVID2_STD_1360_768_60,    1360U, 768U,  FVID2_SF_PROGRESSIVE,85500U,   60U,
253      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
254     {FVID2_STD_SXGA_60,        1280U, 1024U, FVID2_SF_PROGRESSIVE,108000U,  60U,
255      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
256     {FVID2_STD_SXGA_75,        1280U, 1024U, FVID2_SF_PROGRESSIVE,135000U,  75U,
257      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
258     {FVID2_STD_SXGA_85,        1280U, 1024U, FVID2_SF_PROGRESSIVE,157500U,  85U,
259      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
260     {FVID2_STD_WSXGAP_60,      1680U, 1050U, FVID2_SF_PROGRESSIVE,146250U,  60U,
261      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
262     {FVID2_STD_SXGAP_60,       1400U, 1050U, FVID2_SF_PROGRESSIVE,121750U,  60U,
263      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
264     {FVID2_STD_SXGAP_75,       1400U, 1050U, FVID2_SF_PROGRESSIVE,156000U,  75U,
265      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
266     {FVID2_STD_UXGA_60,        1600U, 1200U, FVID2_SF_PROGRESSIVE,162000U,  60U,
267      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
268     {FVID2_STD_WXGA_5x3_30,    1280U, 800U,  FVID2_SF_PROGRESSIVE,34125U,   30U,
269      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
270     {FVID2_STD_WXGA_5x3_60,    1280U, 800U,  FVID2_SF_PROGRESSIVE,68250U,   60U,
271      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}},
272     {FVID2_STD_WXGA_5x3_75,    1280U, 800U,  FVID2_SF_PROGRESSIVE,102250U,  75U,
273      0U, 0U, 0U, 0U, 0U, 0U,{0U,                       0U,    0U,    0U}}
274 };
276 /** \brief Data format string table. */
277 static Fdm_DataFmtString gFdmDataFmtStrTable[] =
279     {FVID2_DF_YUV422I_UYVY,           "YUV422I_UYVY"          },
280     {FVID2_DF_YUV422I_YUYV,           "YUV422I_YUYV"          },
281     {FVID2_DF_YUV422I_YVYU,           "YUV422I_YVYU"          },
282     {FVID2_DF_YUV422I_VYUY,           "YUV422I_VYUY"          },
283     {FVID2_DF_YUV422SP_UV,            "YUV422SP_UV"           },
284     {FVID2_DF_YUV422SP_VU,            "YUV422SP_VU"           },
285     {FVID2_DF_YUV422P,                "YUV422P"               },
286     {FVID2_DF_YUV420SP_UV,            "YUV420SP_UV"           },
287     {FVID2_DF_YUV420SP_VU,            "YUV420SP_VU"           },
288     {FVID2_DF_YUV420P,                "YUV420P"               },
289     {FVID2_DF_YUV444P,                "YUV444P"               },
290     {FVID2_DF_YUV444I,                "YUV444I"               },
291     {FVID2_DF_RGB16_565,              "RGB16_565"             },
292     {FVID2_DF_ARGB16_1555,            "ARGB16_1555"           },
293     {FVID2_DF_RGBA16_5551,            "RGBA16_5551"           },
294     {FVID2_DF_ARGB16_4444,            "ARGB16_4444"           },
295     {FVID2_DF_RGBA16_4444,            "RGBA16_4444"           },
296     {FVID2_DF_BGRX_4444,              "RGBX12_4444"           },
297     {FVID2_DF_XBGR_4444,              "XRGB12_4444"           },
298     {FVID2_DF_ARGB24_6666,            "ARGB24_6666"           },
299     {FVID2_DF_RGBA24_6666,            "RGBA24_6666"           },
300     {FVID2_DF_RGB24_888,              "RGB24_888"             },
301     {FVID2_DF_XBGR24_8888,            "XBGR24_8888"           },
302     {FVID2_DF_RGBX24_8888,            "RGBX24_8888"           },
303     {FVID2_DF_BGRX24_8888,            "BGRX24_8888"           },
304     {FVID2_DF_ARGB32_8888,            "ARGB32_8888"           },
305     {FVID2_DF_RGBA32_8888,            "RGBA32_8888"           },
306     {FVID2_DF_BGR16_565,              "BGR16_565"             },
307     {FVID2_DF_ABGR16_1555,            "ABGR16_1555"           },
308     {FVID2_DF_ABGR16_4444,            "ABGR16_4444"           },
309     {FVID2_DF_BGRA16_5551,            "BGRA16_5551"           },
310     {FVID2_DF_BGRA16_4444,            "BGRA16_4444"           },
311     {FVID2_DF_AGBR16_1555,            "AGBR16_1555"           },
312     {FVID2_DF_AGBR16_4444,            "AGBR16_4444"           },
313     {FVID2_DF_XGBR16_1555,            "XGBR16_1555"           },
314     {FVID2_DF_BGRX16_5551,            "BGRX16_5551"           },
315     {FVID2_DF_ABGR24_6666,            "ABGR24_6666"           },
316     {FVID2_DF_BGR24_888,              "BGR24_888"             },
317     {FVID2_DF_ABGR32_8888,            "ABGR32_8888"           },
318     {FVID2_DF_BGRA24_6666,            "BGRA24_6666"           },
319     {FVID2_DF_BGRA32_8888,            "BGRA32_8888"           },
320     {FVID2_DF_BITMAP8,                "BITMAP8"               },
321     {FVID2_DF_BITMAP4_LOWER,          "BITMAP4_LOWER"         },
322     {FVID2_DF_BITMAP4_UPPER,          "BITMAP4_UPPER"         },
323     {FVID2_DF_BITMAP2_OFFSET0,        "BITMAP2_OFFSET0"       },
324     {FVID2_DF_BITMAP2_OFFSET1,        "BITMAP2_OFFSET1"       },
325     {FVID2_DF_BITMAP2_OFFSET2,        "BITMAP2_OFFSET2"       },
326     {FVID2_DF_BITMAP2_OFFSET3,        "BITMAP2_OFFSET3"       },
327     {FVID2_DF_BITMAP1_OFFSET0,        "BITMAP1_OFFSET0"       },
328     {FVID2_DF_BITMAP1_OFFSET1,        "BITMAP1_OFFSET1"       },
329     {FVID2_DF_BITMAP1_OFFSET2,        "BITMAP1_OFFSET2"       },
330     {FVID2_DF_BITMAP1_OFFSET3,        "BITMAP1_OFFSET3"       },
331     {FVID2_DF_BITMAP1_OFFSET4,        "BITMAP1_OFFSET4"       },
332     {FVID2_DF_BITMAP1_OFFSET5,        "BITMAP1_OFFSET5"       },
333     {FVID2_DF_BITMAP1_OFFSET6,        "BITMAP1_OFFSET6"       },
334     {FVID2_DF_BITMAP1_OFFSET7,        "BITMAP1_OFFSET7"       },
335     {FVID2_DF_BITMAP8_BGRA32,         "BITMAP8_BGRA32"        },
336     {FVID2_DF_BITMAP4_BGRA32_LOWER,   "BITMAP4_BGRA32_LOWER"  },
337     {FVID2_DF_BITMAP4_BGRA32_UPPER,   "BITMAP4_BGRA32_UPPER"  },
338     {FVID2_DF_BITMAP2_BGRA32_OFFSET0, "BITMAP2_BGRA32_OFFSET0"},
339     {FVID2_DF_BITMAP2_BGRA32_OFFSET1, "BITMAP2_BGRA32_OFFSET1"},
340     {FVID2_DF_BITMAP2_BGRA32_OFFSET2, "BITMAP2_BGRA32_OFFSET2"},
341     {FVID2_DF_BITMAP2_BGRA32_OFFSET3, "BITMAP2_BGRA32_OFFSET3"},
342     {FVID2_DF_BITMAP1_BGRA32_OFFSET0, "BITMAP1_BGRA32_OFFSET0"},
343     {FVID2_DF_BITMAP1_BGRA32_OFFSET1, "BITMAP1_BGRA32_OFFSET1"},
344     {FVID2_DF_BITMAP1_BGRA32_OFFSET2, "BITMAP1_BGRA32_OFFSET2"},
345     {FVID2_DF_BITMAP1_BGRA32_OFFSET3, "BITMAP1_BGRA32_OFFSET3"},
346     {FVID2_DF_BITMAP1_BGRA32_OFFSET4, "BITMAP1_BGRA32_OFFSET4"},
347     {FVID2_DF_BITMAP1_BGRA32_OFFSET5, "BITMAP1_BGRA32_OFFSET5"},
348     {FVID2_DF_BITMAP1_BGRA32_OFFSET6, "BITMAP1_BGRA32_OFFSET6"},
349     {FVID2_DF_BITMAP1_BGRA32_OFFSET7, "BITMAP1_BGRA32_OFFSET7"},
350     {FVID2_DF_BAYER_RAW,              "BAYER_RAW"             },
351     {FVID2_DF_BAYER_GRBG,             "BAYER_GRBG"            },
352     {FVID2_DF_BAYER_RGGB,             "BAYER_RGGB"            },
353     {FVID2_DF_BAYER_BGGR,             "BAYER_BGGR"            },
354     {FVID2_DF_BAYER_GBRG,             "BAYER_GBRG"            },
355     {FVID2_DF_RAW_VBI,                "RAW_VBI"               },
356     {FVID2_DF_RAW24,                  "RAW24"                 },
357     {FVID2_DF_RAW16,                  "RAW16"                 },
358     {FVID2_DF_RAW08,                  "RAW08"                 },
359     {FVID2_DF_BGRX32_8888,            "BGRX32_8888"           },
360     {FVID2_DF_BGRA16_1555,            "BGRA16_1555"           },
361     {FVID2_DF_BGRX16_1555,            "BGRX16_1555"           },
362     {FVID2_DF_BGRA32_1010102,         "BGRA32_1010102"        },
363     {FVID2_DF_BGRX32_1010102,         "BGRX32_1010102"        },
364     {FVID2_DF_RGBA32_1010102,         "RGBA32_1010102"        },
365     {FVID2_DF_RGBX32_1010102,         "RGBX32_1010102"        },
366     {FVID2_DF_BGRA64_16161616,        "BGRA64_16161616"       },
367     {FVID2_DF_BGRX64_16161616,        "BGRX64_16161616"       },
368     {FVID2_DF_ABGR64_16161616,        "ABGR64_16161616"       },
369     {FVID2_DF_XBGR64_16161616,        "XBGR64_16161616"       },
370     {FVID2_DF_XRGB32_8888,            "XRGB32_8888"           },
371     {FVID2_DF_RGBX16_4444,            "RGBX16_4444"           },
372     {FVID2_DF_BGR16_565_A8,           "BRG16_565_A8"          },
373     {FVID2_DF_RGB16_565_A8,           "RGB16_565_A8"          },
374     {FVID2_DF_MISC,                   "MISC"                  },
375     {FVID2_DF_INVALID,                "INVALID"               },
376 };
378 /** \brief Standard string table. */
379 static Fdm_StdString     gFdmStdStrTable[] =
381     {FVID2_STD_NTSC,            "NTSC"           },
382     {FVID2_STD_PAL,             "PAL"            },
383     {FVID2_STD_480I,            "480I"           },
384     {FVID2_STD_576I,            "576I"           },
385     {FVID2_STD_CIF,             "CIF"            },
386     {FVID2_STD_HALF_D1,         "HALF_D1"        },
387     {FVID2_STD_D1,              "D1"             },
388     {FVID2_STD_480P,            "480P"           },
389     {FVID2_STD_576P,            "576P"           },
390     {FVID2_STD_720P_60,         "720P60"         },
391     {FVID2_STD_720P_50,         "720P50"         },
392     {FVID2_STD_1080I_60,        "1080I60"        },
393     {FVID2_STD_1080I_50,        "1080I50"        },
394     {FVID2_STD_1080P_60,        "1080P60"        },
395     {FVID2_STD_1080P_50,        "1080P50"        },
396     {FVID2_STD_1080P_24,        "1080P24"        },
397     {FVID2_STD_1080P_30,        "1080P30"        },
398     {FVID2_STD_VGA_60,          "VGA60"          },
399     {FVID2_STD_VGA_72,          "VGA72"          },
400     {FVID2_STD_VGA_75,          "VGA75"          },
401     {FVID2_STD_VGA_85,          "VGA85"          },
402     {FVID2_STD_WVGA_60,         "WVGA60"         },
403     {FVID2_STD_SVGA_60,         "SVGA60"         },
404     {FVID2_STD_SVGA_72,         "SVGA72"         },
405     {FVID2_STD_SVGA_75,         "SVGA75"         },
406     {FVID2_STD_SVGA_85,         "SVGA85"         },
407     {FVID2_STD_WSVGA_70,        "WSVGA70"        },
408     {FVID2_STD_XGA_60,          "XGA60"          },
409     {FVID2_STD_XGA_DSS_TDM_60,  "XGA_DSS_TDM_60" },
410     {FVID2_STD_XGA_70,          "XGA70"          },
411     {FVID2_STD_XGA_75,          "XGA75"          },
412     {FVID2_STD_XGA_85,          "XGA85"          },
413     {FVID2_STD_WXGA_30,         "WXGA30"         },
414     {FVID2_STD_WXGA_60,         "WXGA60"         },
415     {FVID2_STD_WXGA_75,         "WXGA75"         },
416     {FVID2_STD_WXGA_85,         "WXGA85"         },
417     {FVID2_STD_1440_900_60,     "1440X900@60"    },
418     {FVID2_STD_1368_768_60,     "1368X768@60"    },
419     {FVID2_STD_1366_768_60,     "1366X768@60"    },
420     {FVID2_STD_1360_768_60,     "1360X768@60"    },
421     {FVID2_STD_SXGA_60,         "SXGA60"         },
422     {FVID2_STD_SXGA_75,         "SXGA75"         },
423     {FVID2_STD_SXGA_85,         "SXGA85"         },
424     {FVID2_STD_WSXGAP_60,       "WSXGAP60"       },
425     {FVID2_STD_SXGAP_60,        "SXGAP60"        },
426     {FVID2_STD_SXGAP_75,        "SXGAP75"        },
427     {FVID2_STD_UXGA_60,         "UXGA60"         },
428     {FVID2_STD_MUX_2CH_D1,      "MUX_2CH_D1"     },
429     {FVID2_STD_MUX_2CH_HALF_D1, "MUX_2CH_HALF_D1"},
430     {FVID2_STD_MUX_2CH_CIF,     "MUX_2CH_CIF"    },
431     {FVID2_STD_MUX_4CH_D1,      "MUX_4CH_D1"     },
432     {FVID2_STD_MUX_4CH_CIF,     "MUX_4CH_CIF"    },
433     {FVID2_STD_MUX_4CH_HALF_D1, "MUX_4CH_HALF_D1"},
434     {FVID2_STD_MUX_8CH_CIF,     "MUX_8CH_CIF"    },
435     {FVID2_STD_MUX_8CH_HALF_D1, "MUX_8CH_HALF_D1"},
436     {FVID2_STD_WXGA_5x3_30,     "WXGA_5x3_30"    },
437     {FVID2_STD_WXGA_5x3_60,     "WXGA_5x3_60"    },
438     {FVID2_STD_WXGA_5x3_75,     "WXGA_5x3_75"    },
439     {FVID2_STD_AUTO_DETECT,     "AUTO_DETECT"    },
440     {FVID2_STD_CUSTOM,          "CUSTOM"         },
441 };
443 /* ========================================================================== */
444 /*                          Function Definitions                              */
445 /* ========================================================================== */
447 /**
448  *  Fvid2_init
449  *  \brief FVID2 init function.
450  *
451  *  Initializes the drivers and the hardware.
452  *  This function should be called before calling any of driver API's.
453  *
454  *  \param arg          Not used currently. Meant for future purpose.
455  *
456  *  \return             Returns 0 on success else returns error value.
457  */
458 Int32 Fvid2_init(Ptr args)
460     UInt32 cnt;
461     Int32  retVal = FVID2_SOK;
462     Int32  initValue;
463     SemaphoreP_Params params;
465     /* Init all global variables to zero */
466     Fvid2_memset(&gFdmObj, 0U, sizeof (gFdmObj));
468     /* Mark pool flags as free */
469     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
470     {
471         gFdmObj.fdmDriverObjects[cnt].isUsed = (UInt32) FALSE;
472     }
473     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_CH_OBJS; cnt++)
474     {
475         gFdmObj.fdmChannelObjects[cnt].isUsed = (UInt32) FALSE;
476     }
478     gFdmObj.versionString = FVID2_VERSION_STRING;
479     gFdmObj.versionNumber = FVID2_VERSION_NUMBER;
481     /* Allocate lock semaphore */
482     SemaphoreP_Params_init(&params);
483     params.mode = SemaphoreP_Mode_BINARY;
484     initValue       = 1;
485     gFdmObj.lockSem = SemaphoreP_create(initValue, &params);
486     if (NULL == gFdmObj.lockSem)
487     {
488         Fvid2_printf("FVID2 semaphore create failed!!\r\n");
489         retVal = FVID2_EALLOC;
490     }
492     /* Free-up memory if error occurs */
493     if (FVID2_SOK != retVal)
494     {
495         Fvid2_deInit(NULL);
496     }
498     return (retVal);
501 /**
502  *  Fvid2_deInit
503  *  \brief FVID2 deinit function.
504  *
505  *  Uninitializes the drivers and the hardware.
506  *
507  *  \param arg          Not used currently. Meant for future purpose.
508  *
509  *  \return             Returns 0 on success else returns error value.
510  */
511 Int32 Fvid2_deInit(Ptr args)
513     Int32 retVal = FVID2_SOK;
515     /* Delete the lock semaphore */
516     if (NULL != gFdmObj.lockSem)
517     {
518         SemaphoreP_delete(gFdmObj.lockSem);
519         gFdmObj.lockSem = NULL;
520     }
522     return (retVal);
525 /**
526  *  Fvid2_getVersionString
527  *  \brief Get the FVID2 driver version in string form. This API can be
528  *  called before calling #Fvid2_init().
529  *
530  *  \return             Returns pointer to FVID2 version string.
531  */
532 const Char *Fvid2_getVersionString(void)
534     return (FVID2_VERSION_STRING);
537 /**
538  *  Fvid2_getVersionNumber
539  *  \brief Get the FVID2 driver version in number form. This API can be
540  *  called before calling #Fvid2_init().
541  *
542  *  \return             FVID2 version number.
543  */
544 UInt32 Fvid2_getVersionNumber(void)
546     return (FVID2_VERSION_NUMBER);
549 /**
550  *  Fvid2_registerDriver
551  *  \brief FVID2 register driver function.
552  */
553 Int32 Fvid2_registerDriver(const Fvid2_DrvOps *drvOps)
555     Int32       retVal = FVID2_SOK;
556     Fdm_Driver *drv;
557     UInt32      cnt;
559     /* Check for NULL pointers */
560     OSAL_Assert(NULL == drvOps);
562     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
564     /* Check whether the driver is already registered */
565     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
566     {
567         if (TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed)
568         {
569             /* Check for NULL pointers */
570             OSAL_Assert(NULL == gFdmObj.fdmDriverObjects[cnt].drvOps);
572             if (drvOps->drvId == gFdmObj.fdmDriverObjects[cnt].drvOps->drvId)
573             {
574                 Fvid2_printf("Driver with same id already registered!!\r\n");
575                 retVal = FVID2_EDRIVER_INUSE;
576                 break;
577             }
578         }
579     }
581     if (FVID2_SOK == retVal)
582     {
583         /* Get a free driver object */
584         drv = fdmAllocDriverObject();
585         if (NULL != drv)
586         {
587             drv->drvOps   = drvOps;
588             drv->numOpens = 0U;
589         }
590         else
591         {
592             Fvid2_printf("Alloc driver object failed!!\r\n");
593             retVal = FVID2_EALLOC;
594         }
595     }
597     SemaphoreP_post(gFdmObj.lockSem);
599     return (retVal);
602 /**
603  *  Fvid2_unRegisterDriver
604  *  \brief FVID2 unregister driver function.
605  */
606 Int32 Fvid2_unRegisterDriver(const Fvid2_DrvOps *drvOps)
608     Int32 retVal = FVID2_EFAIL;
610     /* Check for NULL pointers */
611     OSAL_Assert(NULL == drvOps);
613     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
615     /* Free the driver object */
616     retVal = fdmFreeDriverObject(drvOps);
618     SemaphoreP_post(gFdmObj.lockSem);
620     return (retVal);
623 /**
624  *  Fvid2_create
625  *  \brief Opens the driver identified by the driver ID.
626  */
627 Fvid2_Handle Fvid2_create(UInt32                drvId,
628                           UInt32                instanceId,
629                           Ptr                   createArgs,
630                           Ptr                   createStatusArgs,
631                           const Fvid2_CbParams *cbParams)
633     Fdm_Driver       *drv = NULL;
634     UInt32            cnt;
635     Fdrv_Handle       drvHandle = NULL;
636     Fdm_Channel      *channel   = NULL;
637     Fvid2_DrvCbParams fdmCbParams, *tempCbParams;
639     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
641     /* Get the matching driver object */
642     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
643     {
644         if (TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed)
645         {
646             /* Check for NULL pointers */
647             OSAL_Assert(NULL == gFdmObj.fdmDriverObjects[cnt].drvOps);
649             if (drvId == gFdmObj.fdmDriverObjects[cnt].drvOps->drvId)
650             {
651                 drv = &gFdmObj.fdmDriverObjects[cnt];
652                 /* Allocate channel object */
653                 channel = fdmAllocChannelObject();
654                 break;
655             }
656         }
657     }
659     if (NULL != channel)
660     {
661         if (NULL != drv->drvOps->createFxn)
662         {
663             if (NULL != cbParams)
664             {
665                 if (NULL != cbParams->cbFxn)
666                 {
667                     fdmCbParams.fdmCbFxn = &fdmDriverCbFxn;
668                 }
669                 else
670                 {
671                     fdmCbParams.fdmCbFxn = NULL;
672                 }
673                 if (NULL != cbParams->errCbFxn)
674                 {
675                     fdmCbParams.fdmErrCbFxn = &fdmDriverErrCbFxn;
676                 }
677                 else
678                 {
679                     fdmCbParams.fdmErrCbFxn = NULL;
680                 }
682                 fdmCbParams.handle   = channel;
683                 fdmCbParams.errList  = cbParams->errList;
684                 fdmCbParams.fdmData  = channel;
685                 fdmCbParams.reserved = cbParams->reserved;
686                 tempCbParams         = &fdmCbParams;
687             }
688             else
689             {
690                 tempCbParams = NULL;
691             }
693             /* Call the driver's create function */
694             drvHandle = drv->drvOps->createFxn(
695                 drvId,
696                 instanceId,
697                 createArgs,
698                 createStatusArgs,
699                 tempCbParams);
700         }
701         else
702         {
703             Fvid2_printf("Driver Ops not supported!!\r\n");
704         }
706         if (NULL != drvHandle)
707         {
708             drv->numOpens++;
710             channel->drv       = drv;
711             channel->drvHandle = drvHandle;
712             Fvid2CbParams_init(&channel->cbParams);
713             if (NULL != cbParams)
714             {
715                 Fvid2_memcpy(
716                     &channel->cbParams,
717                     cbParams,
718                     sizeof (Fvid2_CbParams));
719             }
720         }
721         else
722         {
723             Fvid2_printf("Driver create failed!!\r\n");
725             /* Free the allocated channel object */
726             fdmFreeChannelObject(channel);
727             channel = NULL;
728         }
729     }
730     else
731     {
732         Fvid2_printf("EALLOC: Invalid driver ID!!\r\n");
733     }
735     SemaphoreP_post(gFdmObj.lockSem);
737     return (channel);
740 /**
741  *  Fvid2_delete
742  *  \brief Application calls Fvid2_delete to close the logical channel
743  *  associated with FVID2 handle.
744  */
745 Int32 Fvid2_delete(Fvid2_Handle handle, Ptr deleteArgs)
747     Int32        retVal = FVID2_SOK;
748     Fdm_Channel *channel;
750     SemaphoreP_pend(gFdmObj.lockSem, SemaphoreP_WAIT_FOREVER);
752     if (NULL != handle)
753     {
754         channel = (Fdm_Channel *) handle;
756         /* Check for NULL pointers */
757         OSAL_Assert(NULL == channel->drv);
758         OSAL_Assert(NULL == channel->drv->drvOps);
760         if (NULL != channel->drv->drvOps->deleteFxn)
761         {
762             /* Call the driver's delete function */
763             retVal = channel->drv->drvOps->deleteFxn(
764                 channel->drvHandle,
765                 deleteArgs);
766         }
767         else
768         {
769             Fvid2_printf("Driver Ops not supported!!\r\n");
770         }
772         channel->drv->numOpens--;
773         /* Free the allocated channel object */
774         channel->drv               = NULL;
775         channel->drvHandle         = NULL;
776         channel->cbParams.cbFxn    = NULL;
777         channel->cbParams.errCbFxn = NULL;
778         channel->cbParams.errList  = NULL;
779         channel->cbParams.appData  = NULL;
780         channel->cbParams.reserved = NULL;
781         fdmFreeChannelObject(channel);
782     }
783     else
784     {
785         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
786         retVal = FVID2_EBADARGS;
787     }
789     SemaphoreP_post(gFdmObj.lockSem);
791     return (retVal);
794 /**
795  *  Fvid2_control
796  *  \brief An application calls Fvid2_control to send device-specific control
797  *  commands to the video driver.
798  */
799 Int32 Fvid2_control(Fvid2_Handle handle,
800                     UInt32       cmd,
801                     Ptr          cmdArgs,
802                     Ptr          cmdStatusArgs)
804     Int32        retVal = FVID2_SOK;
805     Fdm_Channel *channel;
807     if (NULL != handle)
808     {
809         channel = (Fdm_Channel *) handle;
811         /* Check for NULL pointers */
812         OSAL_Assert(NULL == channel->drv);
813         OSAL_Assert(NULL == channel->drv->drvOps);
815         if (NULL != channel->drv->drvOps->controlFxn)
816         {
817             /* Call the driver's control function */
818             retVal = channel->drv->drvOps->controlFxn(
819                 channel->drvHandle,
820                 cmd,
821                 cmdArgs,
822                 cmdStatusArgs);
823         }
824         else
825         {
826             Fvid2_printf("Driver Ops not supported!!\r\n");
827             retVal = FVID2_EUNSUPPORTED_OPS;
828         }
829     }
830     else
831     {
832         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
833         retVal = FVID2_EBADARGS;
834     }
836     return (retVal);
839 /**
840  *  Fvid2_queue
841  *  \brief An application calls Fvid2_queue to submit a video buffer to the
842  *  video device driver.
843  *  This is used in capture/display drivers.
844  */
845 Int32 Fvid2_queue(Fvid2_Handle     handle,
846                   Fvid2_FrameList *frameList,
847                   UInt32           streamId)
849     Int32        retVal = FVID2_SOK;
850     Fdm_Channel *channel;
852     if (NULL != handle)
853     {
854         channel = (Fdm_Channel *) handle;
856         /* Check for NULL pointers */
857         OSAL_Assert(NULL == channel->drv);
858         OSAL_Assert(NULL == channel->drv->drvOps);
860         if (NULL != channel->drv->drvOps->queueFxn)
861         {
862             /* Call the driver's queue function */
863             retVal = channel->drv->drvOps->queueFxn(
864                 channel->drvHandle,
865                 frameList,
866                 streamId);
867         }
868         else
869         {
870             Fvid2_printf("Driver Ops not supported!!\r\n");
871             retVal = FVID2_EUNSUPPORTED_OPS;
872         }
873     }
874     else
875     {
876         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
877         retVal = FVID2_EBADARGS;
878     }
880     return (retVal);
883 /**
884  *  Fvid2_dequeue
885  *  \brief An application calls Fvid2_dequeue to request the video device
886  *  driver to give ownership of a video buffer.
887  *  This is used in capture/display drivers.
888  */
889 Int32 Fvid2_dequeue(Fvid2_Handle     handle,
890                     Fvid2_FrameList *frameList,
891                     UInt32           streamId,
892                     UInt32           timeout)
894     Int32        retVal = FVID2_SOK;
895     Fdm_Channel *channel;
897     if (NULL != handle)
898     {
899         channel = (Fdm_Channel *) handle;
901         /* Check for NULL pointers */
902         OSAL_Assert(NULL == channel->drv);
903         OSAL_Assert(NULL == channel->drv->drvOps);
905         if (NULL != channel->drv->drvOps->dequeueFxn)
906         {
907             /* Call the driver's dequeue function */
908             retVal = channel->drv->drvOps->dequeueFxn(
909                 channel->drvHandle,
910                 frameList,
911                 streamId,
912                 timeout);
913         }
914         else
915         {
916             Fvid2_printf("Driver Ops not supported!!\r\n");
917             retVal = FVID2_EUNSUPPORTED_OPS;
918         }
919     }
920     else
921     {
922         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
923         retVal = FVID2_EBADARGS;
924     }
926     return (retVal);
929 /**
930  *  Fvid2_processRequest
931  *  \brief An application calls Fvid2_processRequest to submit a video buffer
932  *  to the video device driver.
933  */
934 Int32 Fvid2_processRequest(Fvid2_Handle     handle,
935                            Fvid2_FrameList *inFrameList,
936                            Fvid2_FrameList *outFrameList)
938     Int32        retVal = FVID2_SOK;
939     Fdm_Channel *channel;
941     if (NULL != handle)
942     {
943         channel = (Fdm_Channel *) handle;
945         /* Check for NULL pointers */
946         OSAL_Assert(NULL == channel->drv);
947         OSAL_Assert(NULL == channel->drv->drvOps);
949         if (NULL != channel->drv->drvOps->processRequestFxn)
950         {
951             /* Call the driver's process frame function */
952             retVal = channel->drv->drvOps->processRequestFxn(
953                 channel->drvHandle,
954                 inFrameList,
955                 outFrameList);
956         }
957         else
958         {
959             Fvid2_printf("Driver Ops not supported!!\r\n");
960             retVal = FVID2_EUNSUPPORTED_OPS;
961         }
962     }
963     else
964     {
965         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
966         retVal = FVID2_EBADARGS;
967     }
969     return (retVal);
972 /**
973  *  Fvid2_getProcessedRequest
974  *  \brief An application calls Fvid2_getProcessedRequest to request the video
975  *  device driver to give ownership of a video buffer.
976  */
977 Int32 Fvid2_getProcessedRequest(Fvid2_Handle     handle,
978                                 Fvid2_FrameList *inFrameList,
979                                 Fvid2_FrameList *outFrameList,
980                                 UInt32           timeout)
982     Int32        retVal = FVID2_SOK;
983     Fdm_Channel *channel;
985     if (NULL != handle)
986     {
987         channel = (Fdm_Channel *) handle;
989         /* Check for NULL pointers */
990         OSAL_Assert(NULL == channel->drv);
991         OSAL_Assert(NULL == channel->drv->drvOps);
993         if (NULL != channel->drv->drvOps->getProcessedRequestFxn)
994         {
995             /* Call the driver's get process frame function */
996             retVal = channel->drv->drvOps->getProcessedRequestFxn(
997                 channel->drvHandle,
998                 inFrameList,
999                 outFrameList,
1000                 timeout);
1001         }
1002         else
1003         {
1004             Fvid2_printf("Driver Ops not supported!!\r\n");
1005             retVal = FVID2_EUNSUPPORTED_OPS;
1006         }
1007     }
1008     else
1009     {
1010         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1011         retVal = FVID2_EBADARGS;
1012     }
1014     return (retVal);
1017 /**
1018  *  Fvid2_getModeInfo
1019  *  \brief Function to get the information about various FVID2 modes/standards.
1020  */
1021 Int32 Fvid2_getModeInfo(Fvid2_ModeInfo *modeInfo)
1023     Int32           retVal = FVID2_SOK;
1024     UInt32          entryCnt;
1025     Fvid2_ModeInfo *matchedEntry = NULL;
1027     if (NULL != modeInfo)
1028     {
1029         for (entryCnt = 0U; entryCnt < FDM_NUM_STD_INFO_ENTRIES; entryCnt++)
1030         {
1031             if (gFdmStdInfoTable[entryCnt].standard == modeInfo->standard)
1032             {
1033                 matchedEntry = &gFdmStdInfoTable[entryCnt];
1034                 break;
1035             }
1036         }
1038         if (NULL == matchedEntry)
1039         {
1040             Fvid2_printf("Unsupported standard!!\r\n");
1041             retVal = FVID2_EINVALID_PARAMS;
1042         }
1043         else
1044         {
1045             Fvid2_memcpy(modeInfo, matchedEntry, sizeof (Fvid2_ModeInfo));
1046         }
1047     }
1048     else
1049     {
1050         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1051         retVal = FVID2_EBADARGS;
1052     }
1054     return (retVal);
1057 /**
1058  *  \brief Function to get the name of the data format in printable string.
1059  *
1060  *  \param dataFmt      [IN] Data format to get the name.
1061  *                           For valid values see #Fvid2_DataFormat.
1062  *
1063  *  \return Returns a const pointer to the string. If the data format is not
1064  *  known, then it return the string as "UNKNOWN".
1065  */
1066 const Char *Fvid2_getDataFmtString(UInt32 dataFmt)
1068     UInt32      entryCnt;
1069     const Char *dataFmtStr = NULL;
1071     for (entryCnt = 0U; entryCnt < FDM_NUM_DATA_FMT_STR_ENTRIES; entryCnt++)
1072     {
1073         if (gFdmDataFmtStrTable[entryCnt].dataFmt == dataFmt)
1074         {
1075             dataFmtStr = gFdmDataFmtStrTable[entryCnt].dataFmtStr;
1076             break;
1077         }
1078     }
1080     if (NULL == dataFmtStr)
1081     {
1082         dataFmtStr = "UNKNOWN";
1083     }
1085     return (dataFmtStr);
1088 /**
1089  *  \brief Function to get the name of the standard in printable string.
1090  *
1091  *  \param standard     [IN] Standard to get the name.
1092  *                           For valid values see #Fvid2_Standard.
1093  *
1094  *  \return Returns a const pointer to the string. If the standard is not
1095  *  known, then it return the string as "UNKNOWN".
1096  */
1097 const Char *Fvid2_getStandardString(UInt32 standard)
1099     UInt32      entryCnt;
1100     const Char *stdStr = NULL;
1102     for (entryCnt = 0U; entryCnt < FDM_NUM_STD_STR_ENTRIES; entryCnt++)
1103     {
1104         if (gFdmStdStrTable[entryCnt].standard == standard)
1105         {
1106             stdStr = gFdmStdStrTable[entryCnt].stdStr;
1107             break;
1108         }
1109     }
1111     if (NULL == stdStr)
1112     {
1113         stdStr = "UNKNOWN";
1114     }
1116     return (stdStr);
1119 /**
1120  *  Fvid2_checkFrameList
1121  *  \brief Checks the FVID2 frame list for error and returns appropriate error.
1122  *  This is used by the drivers and not by the application.
1123  */
1124 Int32 Fvid2_checkFrameList(const Fvid2_FrameList *frameList, UInt32 maxFrames)
1126     Int32  retVal = FVID2_SOK;
1127     UInt32 frmCnt;
1129     /* Check for NULL pointer */
1130     if (NULL == frameList)
1131     {
1132         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1133         retVal = FVID2_EBADARGS;
1134     }
1135     else
1136     {
1137         /* Check whether num frames is within range */
1138         if (frameList->numFrames > maxFrames)
1139         {
1140             Fvid2_printf("Number of frames exceeds max!!\r\n");
1141             retVal = FVID2_EOUT_OF_RANGE;
1142         }
1144         /* Check whether num frames is within range */
1145         if (frameList->numFrames > FVID2_MAX_FRAME_PTR)
1146         {
1147             Fvid2_printf("Number of frames exceeds FVID2 max!!\r\n");
1148             retVal = FVID2_EOUT_OF_RANGE;
1149         }
1151         /* Check whether num frames is zero */
1152         if (0U == frameList->numFrames)
1153         {
1154             Fvid2_printf("Number of frames is zero!!\r\n");
1155             retVal = FVID2_EOUT_OF_RANGE;
1156         }
1158         if (FVID2_SOK == retVal)
1159         {
1160             /* Check the individual frame pointers */
1161             for (frmCnt = 0U; frmCnt < frameList->numFrames; frmCnt++)
1162             {
1163                 /* Check for NULL pointer */
1164                 if (NULL == frameList->frames[frmCnt])
1165                 {
1166                     Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1167                     retVal = FVID2_EBADARGS;
1168                     break;
1169                 }
1170             }
1171         }
1172     }
1174     return (retVal);
1177 /**
1178  *  Fvid2_checkDqFrameList
1179  *  \brief Checks the FVID2 frame list of dequeue call for error and returns
1180  *  appropriate error. For dequeue operation, the frame pointers in the frames
1181  *  should not be checked as this will be filled by the driver.
1182  *  This is used by the drivers and not by the application.
1183  */
1184 Int32 Fvid2_checkDqFrameList(const Fvid2_FrameList *frameList,
1185                              UInt32                 maxFrames)
1187     Int32 retVal = FVID2_SOK;
1189     /* Check for NULL pointer */
1190     if (NULL == frameList)
1191     {
1192         Fvid2_printf("EBADARGS: NULL pointer!!\r\n");
1193         retVal = FVID2_EBADARGS;
1194     }
1195     else
1196     {
1197         /* Check whether max frames is within range */
1198         if (maxFrames > FVID2_MAX_FRAME_PTR)
1199         {
1200             Fvid2_printf("Number of frames exceeds FVID2 max!!\r\n");
1201             retVal = FVID2_EOUT_OF_RANGE;
1202         }
1203     }
1205     return (retVal);
1208 /**
1209  *  Fvid2_copyFrameList
1210  *  \brief Copies the source frame list to the destination frame list.
1211  *  This also resets the frame pointers from the source frame list.
1212  *  This is used by the drivers and not by the application.
1213  */
1214 void Fvid2_copyFrameList(Fvid2_FrameList *dest, Fvid2_FrameList *src)
1216     UInt32 frmCnt;
1218     /* Check for NULL pointers */
1219     OSAL_Assert(NULL == dest);
1220     OSAL_Assert(NULL == src);
1221     OSAL_Assert(src->numFrames >= FVID2_MAX_FRAME_PTR);
1223     dest->numFrames  = src->numFrames;
1224     dest->drvData    = src->drvData;
1225     dest->reserved   = src->reserved;
1227     /* Copy the individual frames */
1228     for (frmCnt = 0U; frmCnt < src->numFrames; frmCnt++)
1229     {
1230         dest->frames[frmCnt] = src->frames[frmCnt];
1231         src->frames[frmCnt]  = NULL;
1232     }
1234     return;
1237 /**
1238  *  Fvid2_duplicateFrameList
1239  *  \brief Duplicate the source frame list to the destination frame list.
1240  *  This does not reset the frame pointers from the source frame list.
1241  *  This is used by the drivers and not by the application.
1242  */
1243 void Fvid2_duplicateFrameList(Fvid2_FrameList *dest, const Fvid2_FrameList *src)
1245     UInt32 frmCnt;
1247     /* Check for NULL pointers */
1248     OSAL_Assert(NULL == dest);
1249     OSAL_Assert(NULL == src);
1250     OSAL_Assert(src->numFrames >= FVID2_MAX_FRAME_PTR);
1252     dest->numFrames  = src->numFrames;
1253     dest->drvData    = src->drvData;
1254     dest->reserved   = src->reserved;
1256     /* Duplicate the individual frames */
1257     for (frmCnt = 0U; frmCnt < src->numFrames; frmCnt++)
1258     {
1259         dest->frames[frmCnt] = src->frames[frmCnt];
1260     }
1262     return;
1265 /**
1266  *  fdmDriverCbFxn
1267  *  \brief FVID2 driver manager driver callback function. Whenever the drivers
1268  *  wants to call the application callback function, this function will be
1269  *  called by the driver and FDM will in turn call the application callback
1270  *  function.
1271  *  This is used by the drivers and not by the application.
1272  */
1273 static Int32 fdmDriverCbFxn(Ptr fdmData, Ptr reserved)
1275     Int32        retVal;
1276     Fdm_Channel *channel;
1278     /* Check for NULL pointers */
1279     OSAL_Assert(NULL == fdmData);
1281     channel = (Fdm_Channel *) fdmData;
1282     OSAL_Assert(NULL == channel->cbParams.cbFxn);
1283     retVal = channel->cbParams.cbFxn(channel, channel->cbParams.appData, NULL);
1285     return (retVal);
1288 /**
1289  *  fdmDriverErrCbFxn
1290  *  \brief FVID2 driver manager driver error callback function.
1291  *  Whenever the drivers wants to call the application error callback function,
1292  *  this function will be called by the driver and FDM will in turn call the
1293  *  application error callback function.
1294  *  This is used by the drivers and not by the application.
1295  */
1296 static Int32 fdmDriverErrCbFxn(Ptr fdmData, void *errList, Ptr reserved)
1298     Int32        retVal;
1299     Fdm_Channel *channel;
1301     /* Check for NULL pointers */
1302     OSAL_Assert(NULL == fdmData);
1304     channel = (Fdm_Channel *) fdmData;
1305     OSAL_Assert(NULL == channel->cbParams.errCbFxn);
1306     retVal = channel->cbParams.errCbFxn(
1307         channel,
1308         channel->cbParams.appData,
1309         errList,
1310         NULL);
1312     return (retVal);
1315 /**
1316  *  fdmAllocDriverObject
1317  *  \brief Allocate memory for driver object from static memory pool.
1318  *  Returns NULL if memory pool is full.
1319  */
1320 static Fdm_Driver *fdmAllocDriverObject(void)
1322     UInt32      cnt;
1323     Fdm_Driver *drv = NULL;
1325     /* Get a free driver object */
1326     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
1327     {
1328         if (FALSE == gFdmObj.fdmDriverObjects[cnt].isUsed)
1329         {
1330             drv         = &gFdmObj.fdmDriverObjects[cnt];
1331             drv->isUsed = (UInt32) TRUE;
1332             break;
1333         }
1334     }
1336     return (drv);
1339 /**
1340  *  fdmFreeDriverObject
1341  *  \brief Free-up the memory allocated for driver object.
1342  */
1343 static Int32 fdmFreeDriverObject(const Fvid2_DrvOps *drvOps)
1345     UInt32 cnt;
1346     Int32  retVal = FVID2_EFAIL;
1348     /* Check for NULL pointers */
1349     OSAL_Assert(NULL == drvOps);
1351     /* Free the driver object */
1352     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_DRV_OBJS; cnt++)
1353     {
1354         if ((TRUE == gFdmObj.fdmDriverObjects[cnt].isUsed) &&
1355             (drvOps == gFdmObj.fdmDriverObjects[cnt].drvOps))
1356         {
1357             if (0u == gFdmObj.fdmDriverObjects[cnt].numOpens)
1358             {
1359                 gFdmObj.fdmDriverObjects[cnt].isUsed   = (UInt32) FALSE;
1360                 gFdmObj.fdmDriverObjects[cnt].drvOps   = NULL;
1361                 gFdmObj.fdmDriverObjects[cnt].numOpens = 0u;
1362                 retVal = FVID2_SOK;
1363             }
1364             else
1365             {
1366                 Fvid2_printf("Driver in use!!\r\n");
1367                 retVal = FVID2_EDEVICE_INUSE;
1368             }
1369             break;
1370         }
1371     }
1373     if (FVID2_EFAIL == retVal)
1374     {
1375         Fvid2_printf("Driver ops not found!!\r\n");
1376     }
1378     return (retVal);
1381 /**
1382  *  fdmAllocChannelObject
1383  *  \brief Allocate memory for channel object from static memory pool.
1384  *  Returns NULL if memory pool is full.
1385  */
1386 static Fdm_Channel *fdmAllocChannelObject(void)
1388     UInt32       cnt;
1389     Fdm_Channel *channel = NULL;
1391     /* Get a free channel object */
1392     for (cnt = 0u; cnt < FVID2_CFG_FDM_NUM_CH_OBJS; cnt++)
1393     {
1394         if (FALSE == gFdmObj.fdmChannelObjects[cnt].isUsed)
1395         {
1396             channel         = &gFdmObj.fdmChannelObjects[cnt];
1397             channel->isUsed = (UInt32) TRUE;
1398             break;
1399         }
1400     }
1402     return (channel);
1405 /**
1406  *  fdmFreeChannelObject
1407  *  \brief Free-up the memory allocated for channel object.
1408  */
1409 static Int32 fdmFreeChannelObject(Fdm_Channel *channel)
1411     Int32 retVal = FVID2_EALLOC;
1413     /* Check for NULL pointers */
1414     OSAL_Assert(NULL == channel);
1416     /* Free the channel object */
1417     if (TRUE == channel->isUsed)
1418     {
1419         channel->isUsed = (UInt32) FALSE;
1420         retVal          = FVID2_SOK;
1421     }
1422     else
1423     {
1424         Fvid2_printf("Freeing a channel object not in use!!\r\n");
1425     }
1427     return (retVal);
1432 static void Fvid2_printf(const char *format, ...)
1434     return;
1437 static void Fvid2_memset(void *mem, int32_t ch, uint32_t byteCount)
1439     memset(mem, ch, byteCount);
1440     return;
1443 static void Fvid2_memcpy(void *dest, const void *src, uint32_t byteCount)
1445     memcpy(dest, src, byteCount);
1446     return;