iLLD_TC27xC  1.0
IfxCif_Cam.h
Go to the documentation of this file.
1 /**
2  * \file IfxCif_Cam.h
3  * \brief CIF CAM details
4  * \ingroup IfxLld_Cif
5  *
6  * \version iLLD_0_1_0_10
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  * \defgroup IfxLld_Cif_Cam Cam
25  * \ingroup IfxLld_Cif
26  * \defgroup IfxLld_Cif_Cam_camEnumerations Camera Enumerations
27  * \ingroup IfxLld_Cif_Cam
28  * \defgroup IfxLld_Cif_Cam_camFunctions Camera Functions
29  * \ingroup IfxLld_Cif_Cam
30  * \defgroup IfxLld_Cif_Cam_camStructures Camera Structures
31  * \ingroup IfxLld_Cif_Cam
32  */
33 
34 #ifndef IFXCIF_CAM_H
35 #define IFXCIF_CAM_H 1
36 
37 /******************************************************************************/
38 /*----------------------------------Includes----------------------------------*/
39 /******************************************************************************/
40 
41 #include "Cif/Std/IfxCif.h"
42 #include "Emem/Std/IfxEmem.h"
43 
44 /******************************************************************************/
45 /*-----------------------------------Macros-----------------------------------*/
46 /******************************************************************************/
47 
48 #define IFXCIF_CAM_MEM_ALIGN_SIZE (64)
49 
50 #define IFXCIF_CAM_MEM_GAPSIZE 0x0
51 
52 /******************************************************************************/
53 /*--------------------------------Enumerations--------------------------------*/
54 /******************************************************************************/
55 
56 /** \addtogroup IfxLld_Cif_Cam_camEnumerations
57  * \{ */
58 /** \brief CIF ISP mode
59  */
60 typedef enum
61 {
62  IfxCif_Cam_IspMode_undefined = -1, /**< \brief undefined */
63  IfxCif_Cam_IspMode_raw = 0, /**< \brief raw */
64  IfxCif_Cam_IspMode_yuvInterleaved = 1, /**< \brief yuv interleaved */
65  IfxCif_Cam_IspMode_yuvPlanar = 2 /**< \brief yuv planar */
67 
68 /** \brief Driver acquisition state
69  */
70 typedef enum
71 {
72  IfxCif_Cam_State_stopped = 0, /**< \brief stopped */
73  IfxCif_Cam_State_running = 1 /**< \brief running */
75 
76 /** \brief Driver status
77  */
78 typedef enum
79 {
80  IfxCif_Cam_Status_ok = 0, /**< \brief ok */
81  IfxCif_Cam_Status_notEnoughMemory = 1, /**< \brief not enough Memory */
82  IfxCif_Cam_Status_cameraCommError = 2, /**< \brief camera comm Error */
83  IfxCif_Cam_Status_notAvailable = 3 /**< \brief not available */
85 
86 /** \} */
87 
88 /******************************************************************************/
89 /*-----------------------------Data Structures--------------------------------*/
90 /******************************************************************************/
91 
92 /** \addtogroup IfxLld_Cif_Cam_camStructures
93  * \{ */
94 typedef struct
95 {
96  uint8 length; /**< \brief length */
97  const uint8 *entry; /**< \brief entry */
99 
100 /** \} */
101 
102 /** \addtogroup IfxLld_Cif_Cam_camStructures
103  * \{ */
104 /** \brief Single component JPEG tables
105  */
106 typedef struct
107 {
108  IfxCif_Cam_TableInfo q; /**< \brief q */
109  IfxCif_Cam_TableInfo dc; /**< \brief dc */
110  IfxCif_Cam_TableInfo ac; /**< \brief ac */
112 
113 /** \brief Picture info
114  */
115 typedef struct
116 {
117  uint16 hSize; /**< \brief horizontal (number of pixel) */
118  uint16 vSize; /**< \brief vertical (number of lines) */
119  uint16 hOffset; /**< \brief horizontal offset */
120  uint16 vOffset; /**< \brief vertical offset */
122 
123 /** \} */
124 
125 /** \addtogroup IfxLld_Cif_Cam_camStructures
126  * \{ */
127 /** \brief JPEG tables for all components
128  */
129 typedef struct
130 {
131  IfxCif_Cam_JpegTable y; /**< \brief y */
132  IfxCif_Cam_JpegTable uv; /**< \brief uv */
134 
135 /** \brief Single path memory interface configuration (used in initialisation/configuration)
136  */
137 typedef struct
138 {
139  float32 memFactor; /**< \brief multiples of frame count for memory allocation */
140  uint16 hSize; /**< \brief horizontal (number of pixel) */
141  uint16 vSize; /**< \brief vertical (number of lines) */
142  uint16 hOffset; /**< \brief horizontal offset */
143  uint16 vOffset; /**< \brief vertical offset */
144  boolean byteSwap; /**< \brief byte swapping */
146 
147 /** \brief Single path memory interface information (used in Runtime)
148  */
149 typedef struct
150 {
151  Ifx_AddressValue start; /**< \brief start address */
152  uint32 size; /**< \brief size in bytes */
153  IfxCif_Cam_PictureInfo image; /**< \brief image */
155 
156 /** \} */
157 
158 /** \addtogroup IfxLld_Cif_Cam_camStructures
159  * \{ */
160 /** \brief Common configuration
161  */
162 typedef struct
163 {
164  IfxCif_Cam_PictureInfo ispIn; /**< \brief ispIn */
165  IfxCif_Cam_MemConfig mainPath; /**< \brief main path */
166  IfxCif_Cam_MemConfig extraPaths[IFXCIF_EXTRA_PATHS]; /**< \brief extra paths */
167  IfxCif_InputInterface inputInterface; /**< \brief input interface */
168  Ifx_IsrSetting ispInterrupt; /**< \brief isp interrupt */
169  boolean debugPathEnabled; /**< \brief debug path enabled */
170  boolean watchdogEnabled; /**< \brief watchdog enabled */
171  const IfxCif_Cam_JpegTables *jpegTables; /**< \brief jpeg tables */
172  boolean jpegEnabled; /**< \brief jpeg enabled */
174 
175 /** \brief Downscaler configuration
176  */
177 typedef struct
178 {
179  boolean enabled; /**< \brief enable */
182  uint8 hFactor; /**< \brief horizontal factor to program into IfxCif_setLinearDownscalerScalingFactors() */
183  uint8 vFactor; /**< \brief vertical factor to program into IfxCif_setLinearDownscalerScalingFactors() */
184  uint8 sizeFactor; /**< \brief memory size factor, e.g. half in both H and V usually gives factor of 4 */
186 
187 /** \brief JPEG JFIF header structure
188  */
189 typedef struct
190 {
191  uint16 unknown; /**< \brief unknown */
192  uint16 app0; /**< \brief app0 */
193  uint16 length; /**< \brief length */
194  uint8 ident[5]; /**< \brief ident */
195  uint16 version; /**< \brief version */
196  uint8 density; /**< \brief density */
197  uint16 densityX; /**< \brief densityX */
198  uint16 densityY; /**< \brief densityY */
199  uint8 thumbX; /**< \brief thumbX */
200  uint8 thumbY; /**< \brief thumbY */
201  uint8 thumbData[20]; /**< \brief thumbData */
203 
204 /** \brief All paths memory partitioning
205  */
206 typedef struct
207 {
208  IfxCif_Cam_MemInfo y; /**< \brief y */
209  IfxCif_Cam_MemInfo cb; /**< \brief cb */
210  IfxCif_Cam_MemInfo cr; /**< \brief cr */
211  IfxCif_Cam_MemInfo ep[IFXCIF_EXTRA_PATHS]; /**< \brief ep */
213 
214 /** \} */
215 
216 /** \addtogroup IfxLld_Cif_Cam_camStructures
217  * \{ */
218 /** \brief Structure which is used as handle for the CIF-CAM functions.
219  * This stores cached variables useful for run-time operations.
220  */
221 typedef struct
222 {
223  IfxCif_Cam_MemAreas memAreas; /**< \brief memory area definition */
224  uint32 totalMemSize; /**< \brief total occupied memory area (in bytes) */
225  Ifx_AddressValue nextFreeAddress; /**< \brief next free storage address */
226  uint32 availMemSize; /**< \brief total available RAM space left (in bytes) */
227  Ifx_CIF *cif; /**< \brief pointer to base address of CIF module SFRs */
228  Ifx_EMEM *emem; /**< \brief pointer to base address of EMEM module SFRs */
229  IfxCif_Cam_JfifHeader *jfif; /**< \brief pointer to the last acquired JPEG header */
230  IfxCif_Cam_Status configResult; /**< \brief status of last configuration (or initialisation) */
231  IfxCif_Cam_IspMode ispMode; /**< \brief actual ISP mode */
232  boolean ispBpp; /**< \brief byte per pixel */
233 } IfxCif_Cam;
234 
235 /** \brief Camera specific configuration
236  */
237 typedef struct
238 {
239  const IfxCif_Cam_Common *common; /**< \brief pointer to common configuration */
240  IfxCif_Cam_IspMode ispMode; /**< \brief ISP mode */
241  uint16 ispRawBpp; /**< \brief bytes per pixel of the input stream */
242  IfxCif_IspSyncPolarity hSyncPolarity; /**< \brief polarity of HSYNC signal */
243  IfxCif_IspSyncPolarity vSyncPolarity; /**< \brief polarity of VSYNC signal */
244  IfxCif_IspSamplingEdge samplingEdge; /**< \brief sampling edge */
245  uint16 setupDataCount; /**< \brief number of camera-specific configuration data (in DWORDS) */
246  const uint32 *setupDataTable; /**< \brief pointer to the first entry of camera-specific configuration data */
247  const IfxCif_Cam_Downscaling *downscaling; /**< \brief downscaling settings for ExtraPath 1 */
249 
250 /** \} */
251 
252 /** \addtogroup IfxLld_Cif_Cam_camFunctions
253  * \{ */
254 
255 /******************************************************************************/
256 /*-------------------------Inline Function Prototypes-------------------------*/
257 /******************************************************************************/
258 
259 /** \brief Clear the frame reception flag
260  * \param cam cam handle
261  * \return None
262  */
264 
265 /** \brief Clear the JPEG encoder completed flag
266  * \param cam cam handle
267  * \return None
268  */
270 
271 /** \brief Convert the CPU address into BBB address
272  * \param cam cam handle
273  * \param cpuAddress Address value
274  */
276 
277 /** \brief Returns the size (in bytes) of one last acquired extra-path image data
278  * \param cam cam handle
279  * \param z Extra path
280  */
282 
283 /**
284  * \param cam cam handle
285  * \param z Extra path
286  */
288 
289 /** \brief Returns the size (in bytes) of last acquired main-path image data
290  * \param cam cam handle
291  */
293 
294 /** \brief Returns the size (in bytes) of last encoded main-path image data
295  * \param cam cam handle
296  */
298 
299 /** \brief Returns the address location of last acquired extra-path image frame data
300  * \param cam cam handle
301  * \param z Extra path
302  */
304 
305 /**
306  * \param cam cam handle
307  * \param z Extra path
308  * \param address Address Value
309  * \param size const IfxCif_Cam_MemInfo *m;
310  * *size = IfxCif_Cam_getExtraFrameSize(cam, z);
311  * *address = IfxCif_Cam_getLastExtraAddress(cam, z);
312  * m = IfxCif_Cam_getExtraPathMemInfo(cam, z);
313  * return m;
314  */
316 
317 /** \brief Returns the address location of last acquired main-path image frame data
318  * \param cam cam handle
319  * \return address location of last acquired main-path image frame data
320  */
322 
323 /**
324  * \param cam cam handle
325  * \param address Address value
326  * \param size Size
327  */
329 
330 /** \brief Returns the address location of next acquired main-path image frame data
331  * \param cam cam handle
332  */
334 
335 /** \brief Returns the address location of next acquired JPEG image frame data
336  * \param cam cam handle
337  */
339 
340 /** \brief Increment the address related to memory interface of for main-path. The address is wrapped around at the boundary of the allocated RAM size
341  * \param cam cam handle
342  * \param address Address value
343  */
345 
346 /** \brief Returns TRUE if JPEG encoding is completed
347  * \param cam cam handle
348  * \return TRUE if one frame reception is completed
349  */
351 
352 /** \brief
353  * \param cam cam handle
354  * \return TRUE if JPEG encoding is completed
355  */
357 
358 /**
359  * \param cam cam handle
360  * \return None
361  */
363 
364 /******************************************************************************/
365 /*-------------------------Global Function Prototypes-------------------------*/
366 /******************************************************************************/
367 
368 /** \brief Clear all CIF module notification flags
369  * \param cam cam handle
370  * \return None
371  */
373 
374 /** \brief Disable the JPEG encoder and route the acquisition path accordingly to the 'original' configuration, i.e. RAW or main path.
375  * \param cam cam handle
376  * \return None
377  */
379 
380 /** \brief Enable the JPEG encoder and route the acquisition path accordingly
381  * \param cam cam handle
382  * \return None
383  */
385 
386 /** \brief Returns pointer to the variable storing picture info of an extra-path
387  * \param cam cam handle
388  * \param z Extra Path
389  * \return pointer to the variable storing picture info of an extra-path
390  */
392 
393 /** \brief Returns pointer to the memory structure storing last JPEG encoding process
394  * \param cam cam handle
395  * \param address EMEM address which stores the JPEG frame
396  * \param size size of JPEG frame
397  * \return TRUE if there was new frame encoded, else FALSE
398  */
400 
401 /** \brief Initialise the CIF, EMEM, PORT, I2C and the camera itself
402  * \param cam cam handel
403  * \param config configurations structure
404  * \param initCam if TRUE camera will be reconfigured, else camera will not be reconfigured.
405  */
406 IFX_EXTERN IfxCif_Cam_Status IfxCif_Cam_init(IfxCif_Cam *cam, const IfxCif_Cam_Config *config, boolean initCam);
407 
408 /** \brief Restart capture by enabling the ISP output
409  * \param cam cam handle
410  * \param frames Number of acquisitions. Set to zero for continuous acquisition
411  * \return None
412  */
413 IFX_EXTERN void IfxCif_Cam_restartCapture(const IfxCif_Cam *cam, uint8 frames);
414 
415 /** \brief Start capture by enabling the ISP output and initialising the MI counter
416  * \param cam cam handle
417  * \param frames Number of acquisitions. Set to zero for continuous acquisition
418  * \return None
419  */
420 IFX_EXTERN void IfxCif_Cam_startCapture(const IfxCif_Cam *cam, uint8 frames);
421 
422 /** \brief Stop capture by disabling the ISP output
423  * \param cam cam handle
424  * \return None
425  */
427 
428 /** \} */
429 
430 /******************************************************************************/
431 /*---------------------Inline Function Implementations------------------------*/
432 /******************************************************************************/
433 
435 {
436  (void)cam;
437  MODULE_CIF.ISP.ICR.U = (IFX_CIF_ISP_ICR_ICR_FRAME_MSK << IFX_CIF_ISP_ICR_ICR_FRAME_OFF);
438 }
439 
440 
442 {
443  (void)cam;
444  MODULE_CIF.JPE.STATUS_ICR.U = (IFX_CIF_JPE_STATUS_ICR_ENCODE_DONE_MSK << IFX_CIF_JPE_STATUS_ICR_ENCODE_DONE_OFF);
445 }
446 
447 
449 {
450  (void)cam;
451 
452  return (Ifx_AddressValue)(((uint32)cpuAddress & 0x00FFFFFFU) + IFXEMEM_START_ADDR_BBB);
453 }
454 
455 
457 {
458  sint32 size = 0;
459 
460  if (z <= IfxCif_ExtraPath_5)
461  {
462  size = cam->memAreas.ep[z].image.hSize * cam->memAreas.ep[z].image.vSize;
463 
464  if ((cam->ispMode != IfxCif_Cam_IspMode_raw) || (cam->ispBpp > 1))
465  {
466  size = size * 2;
467  }
468  }
469  else
470  {
471  IFXCIF_DEBUG;
472  }
473 
474  return (uint32)size;
475 }
476 
477 
479 {
480  return &(cam->memAreas.ep[z]);
481 }
482 
483 
485 {
486  (void)cam;
487  sint32 size = MODULE_CIF.MI.MP_Y_OFFS_CNT_SHD.U - MODULE_CIF.MI.MP_Y_OFFS_CNT_START.U;
488 
489  if (size <= 0)
490  {
491  size += MODULE_CIF.MI.MP_Y_SIZE_INIT.U;
492  }
493 
494  return (uint32)size;
495 }
496 
497 
499 {
500  (void)cam;
501 
502  // 0x240 is size of JFIF header.
503  return 0x240 + IfxCif_Cam_getFrameSize(cam);
504 }
505 
506 
508 {
509  Ifx_AddressValue address = 0;
510 
511  if (z <= IfxCif_ExtraPath_5)
512  {
513  address = (Ifx_AddressValue)((uint32)cam->memAreas.ep[z].start + MODULE_CIF.MIEP.CH_1S[z].OFFS_CNT_START.U);
514  }
515 
516  return address;
517 }
518 
519 
521 {
522  const IfxCif_Cam_MemInfo *m;
523  *size = IfxCif_Cam_getExtraFrameSize(cam, z);
524  *address = IfxCif_Cam_getLastExtraAddress(cam, z);
525  m = IfxCif_Cam_getExtraPathMemInfo(cam, z);
526  return m;
527 }
528 
529 
531 {
532  (void)cam;
533 
534  return (Ifx_AddressValue)(IFXEMEM_START_ADDR_CPU_CACHED + MODULE_CIF.MI.MP_Y_OFFS_CNT_START.U);
535 }
536 
537 
539 {
540  const IfxCif_Cam_MemInfo *m;
541  *size = IfxCif_Cam_getFrameSize(cam);
542  *address = IfxCif_Cam_getLastFrameAddress(cam);
543  m = &(cam->memAreas.y);
544  return m;
545 }
546 
547 
549 {
550  (void)cam;
551 
552  return (Ifx_AddressValue)(IFXEMEM_START_ADDR_CPU_CACHED + MODULE_CIF.MI.MP_Y_OFFS_CNT_SHD.U);
553 }
554 
555 
557 {
559  cam->jfif = (IfxCif_Cam_JfifHeader *)address; /* note: no cast to (void *) to satisfy C++ compilers */
560  return address;
561 }
562 
563 
565 {
566  address = (Ifx_AddressValue)((uint32)address + 4U);
567 
568  if ((uint32)address >= (IFXEMEM_START_ADDR_CPU_CACHED + cam->memAreas.y.size))
569  { // back to base
571  }
572 
573  return address;
574 }
575 
576 
578 {
579  (void)cam;
580 
581  return MODULE_CIF.ISP.RIS.B.RIS_FRAME != 0;
582 }
583 
584 
586 {
587  (void)cam;
588 
589  return MODULE_CIF.JPE.STATUS_RIS.B.ENCODE_DONE != 0;
590 }
591 
592 
594 {
595  (void)cam;
598 }
599 
600 
601 #endif /* IFXCIF_CAM_H */