fsl_csi.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /*
  2. * Copyright (c) 2017, NXP Semiconductors, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_CSI_H_
  31. #define _FSL_CSI_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup csi_driver
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. /*! @name Driver version */
  41. /*@{*/
  42. #define FSL_CSI_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  43. /*@}*/
  44. /*! @brief Size of the frame buffer queue used in CSI transactional function. */
  45. #ifndef CSI_DRIVER_QUEUE_SIZE
  46. #define CSI_DRIVER_QUEUE_SIZE 4U
  47. #endif
  48. /*
  49. * There is one empty room in queue, used to distinguish whether the queue
  50. * is full or empty. When header equals tail, the queue is empty; when header
  51. * equals tail + 1, the queue is full.
  52. */
  53. #define CSI_DRIVER_ACTUAL_QUEUE_SIZE (CSI_DRIVER_QUEUE_SIZE + 1U)
  54. /*
  55. * The interrupt enable bits are in registers CSICR1[16:31], CSICR3[0:7],
  56. * and CSICR18[2:9]. So merge them into an uint32_t value, place CSICR18 control
  57. * bits to [8:15].
  58. */
  59. #define CSI_CSICR1_INT_EN_MASK 0xFFFF0000U
  60. #define CSI_CSICR3_INT_EN_MASK 0x000000FFU
  61. #define CSI_CSICR18_INT_EN_MASK 0x0000FF00U
  62. #if ((~CSI_CSICR1_INT_EN_MASK) & \
  63. (CSI_CSICR1_EOF_INT_EN_MASK | CSI_CSICR1_COF_INT_EN_MASK | CSI_CSICR1_SF_OR_INTEN_MASK | \
  64. CSI_CSICR1_RF_OR_INTEN_MASK | CSI_CSICR1_SFF_DMA_DONE_INTEN_MASK | CSI_CSICR1_STATFF_INTEN_MASK | \
  65. CSI_CSICR1_FB2_DMA_DONE_INTEN_MASK | CSI_CSICR1_FB1_DMA_DONE_INTEN_MASK | CSI_CSICR1_RXFF_INTEN_MASK | \
  66. CSI_CSICR1_SOF_INTEN_MASK))
  67. #error CSI_CSICR1_INT_EN_MASK could not cover all interrupt bits in CSICR1.
  68. #endif
  69. #if ((~CSI_CSICR3_INT_EN_MASK) & (CSI_CSICR3_ECC_INT_EN_MASK | CSI_CSICR3_HRESP_ERR_EN_MASK))
  70. #error CSI_CSICR3_INT_EN_MASK could not cover all interrupt bits in CSICR3.
  71. #endif
  72. #if ((~CSI_CSICR18_INT_EN_MASK) & ((CSI_CSICR18_FIELD0_DONE_IE_MASK | CSI_CSICR18_DMA_FIELD1_DONE_IE_MASK | CSI_CSICR18_BASEADDR_CHANGE_ERROR_IE_MASK) << 6U))
  73. #error CSI_CSICR18_INT_EN_MASK could not cover all interrupt bits in CSICR18.
  74. #endif
  75. /*! @brief Error codes for the CSI driver. */
  76. enum _csi_status
  77. {
  78. kStatus_CSI_NoEmptyBuffer = MAKE_STATUS(kStatusGroup_CSI, 0), /*!< No empty frame buffer in queue to load to CSI. */
  79. kStatus_CSI_NoFullBuffer = MAKE_STATUS(kStatusGroup_CSI, 1), /*!< No full frame buffer in queue to read out. */
  80. kStatus_CSI_QueueFull = MAKE_STATUS(kStatusGroup_CSI, 2), /*!< Queue is full, no room to save new empty buffer. */
  81. kStatus_CSI_FrameDone = MAKE_STATUS(kStatusGroup_CSI, 3), /*!< New frame received and saved to queue. */
  82. };
  83. /*!
  84. * @brief CSI work mode.
  85. *
  86. * The CCIR656 interlace mode is not supported currently.
  87. */
  88. typedef enum _csi_work_mode
  89. {
  90. kCSI_GatedClockMode = CSI_CSICR1_GCLK_MODE(1U), /*!< HSYNC, VSYNC, and PIXCLK signals are used. */
  91. kCSI_NonGatedClockMode = 0U, /*!< VSYNC, and PIXCLK signals are used. */
  92. kCSI_CCIR656ProgressiveMode = CSI_CSICR1_CCIR_EN(1U), /*!< CCIR656 progressive mode. */
  93. } csi_work_mode_t;
  94. /*!
  95. * @brief CSI data bus witdh.
  96. *
  97. * Currently only support 8-bit width.
  98. */
  99. typedef enum _csi_data_bus
  100. {
  101. kCSI_DataBus8Bit, /*!< 8-bit data bus. */
  102. } csi_data_bus_t;
  103. /*! @brief CSI signal polarity. */
  104. enum _csi_polarity_flags
  105. {
  106. kCSI_HsyncActiveLow = 0U, /*!< HSYNC is active low. */
  107. kCSI_HsyncActiveHigh = CSI_CSICR1_HSYNC_POL_MASK, /*!< HSYNC is active high. */
  108. kCSI_DataLatchOnRisingEdge = CSI_CSICR1_REDGE_MASK, /*!< Pixel data latched at rising edge of pixel clock. */
  109. kCSI_DataLatchOnFallingEdge = 0U, /*!< Pixel data latched at falling edge of pixel clock. */
  110. kCSI_VsyncActiveHigh = 0U, /*!< VSYNC is active high. */
  111. kCSI_VsyncActiveLow = CSI_CSICR1_SOF_POL_MASK, /*!< VSYNC is active low. */
  112. };
  113. /*! @brief Configuration to initialize the CSI module. */
  114. typedef struct _csi_config
  115. {
  116. uint16_t width; /*!< Pixels of the input frame. */
  117. uint16_t height; /*!< Lines of the input frame. */
  118. uint32_t polarityFlags; /*!< Timing signal polarity flags, OR'ed value of @ref _csi_polarity_flags. */
  119. uint8_t bytesPerPixel; /*!< Bytes per pixel, valid values are:
  120. - 2: Used for RGB565, YUV422, and so on.
  121. - 3: Used for packed RGB888, packed YUV444, and so on.
  122. - 4: Used for XRGB8888, XYUV444, and so on.
  123. */
  124. uint16_t linePitch_Bytes; /*!< Frame buffer line pitch, must be 8-byte aligned. */
  125. csi_work_mode_t workMode; /*!< CSI work mode. */
  126. csi_data_bus_t dataBus; /*!< Data bus width. */
  127. bool useExtVsync; /*!< In CCIR656 progressive mode, set true to use external VSYNC signal, set false
  128. to use internal VSYNC signal decoded from SOF. */
  129. } csi_config_t;
  130. /*! @brief The CSI FIFO, used for FIFO operation. */
  131. typedef enum _csi_fifo
  132. {
  133. kCSI_RxFifo = (1U << 0U), /*!< RXFIFO. */
  134. kCSI_StatFifo = (1U << 1U), /*!< STAT FIFO. */
  135. kCSI_AllFifo = 0x01 | 0x02, /*!< Both RXFIFO and STAT FIFO. */
  136. } csi_fifo_t;
  137. /*! @brief CSI feature interrupt source. */
  138. enum _csi_interrupt_enable
  139. {
  140. kCSI_EndOfFrameInterruptEnable = CSI_CSICR1_EOF_INT_EN_MASK, /*!< End of frame interrupt enable. */
  141. kCSI_ChangeOfFieldInterruptEnable = CSI_CSICR1_COF_INT_EN_MASK, /*!< Change of field interrupt enable. */
  142. kCSI_StatFifoOverrunInterruptEnable = CSI_CSICR1_SF_OR_INTEN_MASK, /*!< STAT FIFO overrun interrupt enable. */
  143. kCSI_RxFifoOverrunInterruptEnable = CSI_CSICR1_RF_OR_INTEN_MASK, /*!< RXFIFO overrun interrupt enable. */
  144. kCSI_StatFifoDmaDoneInterruptEnable =
  145. CSI_CSICR1_SFF_DMA_DONE_INTEN_MASK, /*!< STAT FIFO DMA done interrupt enable. */
  146. kCSI_StatFifoFullInterruptEnable = CSI_CSICR1_STATFF_INTEN_MASK, /*!< STAT FIFO full interrupt enable. */
  147. kCSI_RxBuffer1DmaDoneInterruptEnable =
  148. CSI_CSICR1_FB2_DMA_DONE_INTEN_MASK, /*!< RX frame buffer 1 DMA transfer done. */
  149. kCSI_RxBuffer0DmaDoneInterruptEnable =
  150. CSI_CSICR1_FB1_DMA_DONE_INTEN_MASK, /*!< RX frame buffer 0 DMA transfer done. */
  151. kCSI_RxFifoFullInterruptEnable = CSI_CSICR1_RXFF_INTEN_MASK, /*!< RXFIFO full interrupt enable. */
  152. kCSI_StartOfFrameInterruptEnable = CSI_CSICR1_SOF_INTEN_MASK, /*!< Start of frame (SOF) interrupt enable. */
  153. kCSI_EccErrorInterruptEnable = CSI_CSICR3_ECC_INT_EN_MASK, /*!< ECC error detection interrupt enable. */
  154. kCSI_AhbResErrorInterruptEnable = CSI_CSICR3_HRESP_ERR_EN_MASK, /*!< AHB response Error interrupt enable. */
  155. kCSI_BaseAddrChangeErrorInterruptEnable = CSI_CSICR18_BASEADDR_CHANGE_ERROR_IE_MASK << 6U, /*!< The DMA output buffer base address
  156. changes before DMA completed. */
  157. kCSI_Field0DoneInterruptEnable = CSI_CSICR18_FIELD0_DONE_IE_MASK << 6U, /*!< Field 0 done interrupt enable. */
  158. kCSI_Field1DoneInterruptEnable = CSI_CSICR18_DMA_FIELD1_DONE_IE_MASK << 6U, /*!< Field 1 done interrupt enable. */
  159. };
  160. /*!
  161. * @brief CSI status flags.
  162. *
  163. * The following status register flags can be cleared:
  164. * - kCSI_EccErrorFlag
  165. * - kCSI_AhbResErrorFlag
  166. * - kCSI_ChangeOfFieldFlag
  167. * - kCSI_StartOfFrameFlag
  168. * - kCSI_EndOfFrameFlag
  169. * - kCSI_RxBuffer1DmaDoneFlag
  170. * - kCSI_RxBuffer0DmaDoneFlag
  171. * - kCSI_StatFifoDmaDoneFlag
  172. * - kCSI_StatFifoOverrunFlag
  173. * - kCSI_RxFifoOverrunFlag
  174. * - kCSI_Field0DoneFlag
  175. * - kCSI_Field1DoneFlag
  176. * - kCSI_BaseAddrChangeErrorFlag
  177. */
  178. enum _csi_flags
  179. {
  180. kCSI_RxFifoDataReadyFlag = CSI_CSISR_DRDY_MASK, /*!< RXFIFO data ready. */
  181. kCSI_EccErrorFlag = CSI_CSISR_ECC_INT_MASK, /*!< ECC error detected. */
  182. kCSI_AhbResErrorFlag = CSI_CSISR_HRESP_ERR_INT_MASK, /*!< Hresponse (AHB bus response) Error. */
  183. kCSI_ChangeOfFieldFlag = CSI_CSISR_COF_INT_MASK, /*!< Change of field. */
  184. kCSI_Field0PresentFlag = CSI_CSISR_F1_INT_MASK, /*!< Field 0 present in CCIR mode. */
  185. kCSI_Field1PresentFlag = CSI_CSISR_F2_INT_MASK, /*!< Field 1 present in CCIR mode. */
  186. kCSI_StartOfFrameFlag = CSI_CSISR_SOF_INT_MASK, /*!< Start of frame (SOF) detected. */
  187. kCSI_EndOfFrameFlag = CSI_CSISR_EOF_INT_MASK, /*!< End of frame (EOF) detected. */
  188. kCSI_RxFifoFullFlag = CSI_CSISR_RxFF_INT_MASK, /*!< RXFIFO full (Number of data reaches trigger level). */
  189. kCSI_RxBuffer1DmaDoneFlag = CSI_CSISR_DMA_TSF_DONE_FB2_MASK, /*!< RX frame buffer 1 DMA transfer done. */
  190. kCSI_RxBuffer0DmaDoneFlag = CSI_CSISR_DMA_TSF_DONE_FB1_MASK, /*!< RX frame buffer 0 DMA transfer done. */
  191. kCSI_StatFifoFullFlag = CSI_CSISR_STATFF_INT_MASK, /*!< STAT FIFO full (Reach trigger level). */
  192. kCSI_StatFifoDmaDoneFlag = CSI_CSISR_DMA_TSF_DONE_SFF_MASK, /*!< STAT FIFO DMA transfer done. */
  193. kCSI_StatFifoOverrunFlag = CSI_CSISR_SF_OR_INT_MASK, /*!< STAT FIFO overrun. */
  194. kCSI_RxFifoOverrunFlag = CSI_CSISR_RF_OR_INT_MASK, /*!< RXFIFO overrun. */
  195. kCSI_Field0DoneFlag = CSI_CSISR_DMA_FIELD0_DONE_MASK, /*!< Field 0 transfer done. */
  196. kCSI_Field1DoneFlag = CSI_CSISR_DMA_FIELD1_DONE_MASK, /*!< Field 1 transfer done. */
  197. kCSI_BaseAddrChangeErrorFlag = CSI_CSISR_BASEADDR_CHHANGE_ERROR_MASK, /*!< The DMA output buffer base address
  198. changes before DMA completed. */
  199. };
  200. /* Forward declaration of the handle typedef. */
  201. typedef struct _csi_handle csi_handle_t;
  202. /*!
  203. * @brief CSI transfer callback function.
  204. *
  205. * When a new frame is received and saved to the frame buffer queue, the callback
  206. * is called and the pass the status @ref kStatus_CSI_FrameDone to upper layer.
  207. */
  208. typedef void (*csi_transfer_callback_t)(CSI_Type *base, csi_handle_t *handle, status_t status, void *userData);
  209. /*!
  210. * @brief CSI handle structure.
  211. *
  212. * Please see the user guide for the details of the CSI driver queue mechanism.
  213. */
  214. struct _csi_handle
  215. {
  216. uint32_t frameBufferQueue[CSI_DRIVER_ACTUAL_QUEUE_SIZE]; /*!< Frame buffer queue. */
  217. volatile uint8_t queueUserReadIdx; /*!< Application gets full-filled frame buffer from this index. */
  218. volatile uint8_t queueUserWriteIdx; /*!< Application puts empty frame buffer to this index. */
  219. volatile uint8_t queueDrvReadIdx; /*!< Driver gets empty frame buffer from this index. */
  220. volatile uint8_t queueDrvWriteIdx; /*!< Driver puts the full-filled frame buffer to this index. */
  221. volatile uint8_t activeBufferNum; /*!< How many frame buffers are in progres currently. */
  222. volatile uint8_t nextBufferIdx; /*!< The CSI frame buffer index to use for next frame. */
  223. volatile bool transferStarted; /*!< User has called @ref CSI_TransferStart to start frame receiving. */
  224. volatile bool transferOnGoing; /*!< CSI is working and receiving incoming frames. */
  225. csi_transfer_callback_t callback; /*!< Callback function. */
  226. void *userData; /*!< CSI callback function parameter.*/
  227. };
  228. /*******************************************************************************
  229. * API
  230. ******************************************************************************/
  231. #if defined(__cplusplus)
  232. extern "C" {
  233. #endif
  234. /*!
  235. * @name Initialization and deinitialization
  236. * @{
  237. */
  238. /*!
  239. * @brief Initialize the CSI.
  240. *
  241. * This function enables the CSI peripheral clock, and resets the CSI registers.
  242. *
  243. * @param base CSI peripheral base address.
  244. * @param config Pointer to the configuration structure.
  245. *
  246. * @retval kStatus_Success Initialize successfully.
  247. * @retval kStatus_InvalidArgument Initialize failed because of invalid argument.
  248. */
  249. status_t CSI_Init(CSI_Type *base, const csi_config_t *config);
  250. /*!
  251. * @brief De-initialize the CSI.
  252. *
  253. * This function disables the CSI peripheral clock.
  254. *
  255. * @param base CSI peripheral base address.
  256. */
  257. void CSI_Deinit(CSI_Type *base);
  258. /*!
  259. * @brief Reset the CSI.
  260. *
  261. * This function resets the CSI peripheral registers to default status.
  262. *
  263. * @param base CSI peripheral base address.
  264. */
  265. void CSI_Reset(CSI_Type *base);
  266. /*!
  267. * @brief Get the default configuration for to initialize the CSI.
  268. *
  269. * The default configuration value is:
  270. *
  271. * @code
  272. config->width = 320U;
  273. config->height = 240U;
  274. config->polarityFlags = kCSI_HsyncActiveHigh | kCSI_DataLatchOnRisingEdge;
  275. config->bytesPerPixel = 2U;
  276. config->linePitch_Bytes = 320U * 2U;
  277. config->workMode = kCSI_GatedClockMode;
  278. config->dataBus = kCSI_DataBus8Bit;
  279. config->useExtVsync = true;
  280. @endcode
  281. *
  282. * @param config Pointer to the CSI configuration.
  283. */
  284. void CSI_GetDefaultConfig(csi_config_t *config);
  285. /* @} */
  286. /*!
  287. * @name Module operation
  288. * @{
  289. */
  290. /*!
  291. * @brief Clear the CSI FIFO.
  292. *
  293. * This function clears the CSI FIFO.
  294. *
  295. * @param base CSI peripheral base address.
  296. * @param fifo The FIFO to clear.
  297. */
  298. void CSI_ClearFifo(CSI_Type *base, csi_fifo_t fifo);
  299. /*!
  300. * @brief Reflash the CSI FIFO DMA.
  301. *
  302. * This function reflashes the CSI FIFO DMA.
  303. *
  304. * For RXFIFO, there are two frame buffers. When the CSI module started, it saves
  305. * the frames to frame buffer 0 then frame buffer 1, the two buffers will be
  306. * written by turns. After reflash DMA using this function, the CSI is reset to
  307. * save frame to buffer 0.
  308. *
  309. * @param base CSI peripheral base address.
  310. * @param fifo The FIFO DMA to reflash.
  311. */
  312. void CSI_ReflashFifoDma(CSI_Type *base, csi_fifo_t fifo);
  313. /*!
  314. * @brief Enable or disable the CSI FIFO DMA request.
  315. *
  316. * @param base CSI peripheral base address.
  317. * @param fifo The FIFO DMA reques to enable or disable.
  318. * @param enable True to enable, false to disable.
  319. */
  320. void CSI_EnableFifoDmaRequest(CSI_Type *base, csi_fifo_t fifo, bool enable);
  321. /*!
  322. * @brief Start to receive data.
  323. *
  324. * @param base CSI peripheral base address.
  325. */
  326. static inline void CSI_Start(CSI_Type *base)
  327. {
  328. CSI_EnableFifoDmaRequest(base, kCSI_RxFifo, true);
  329. base->CSICR18 |= CSI_CSICR18_CSI_ENABLE_MASK;
  330. }
  331. /*!
  332. * @brief Stop to receiving data.
  333. *
  334. * @param base CSI peripheral base address.
  335. */
  336. static inline void CSI_Stop(CSI_Type *base)
  337. {
  338. base->CSICR18 &= ~CSI_CSICR18_CSI_ENABLE_MASK;
  339. CSI_EnableFifoDmaRequest(base, kCSI_RxFifo, false);
  340. }
  341. /*!
  342. * @brief Set the RX frame buffer address.
  343. *
  344. * @param base CSI peripheral base address.
  345. * @param index Buffer index.
  346. * @param addr Frame buffer address to set.
  347. */
  348. void CSI_SetRxBufferAddr(CSI_Type *base, uint8_t index, uint32_t addr);
  349. /* @} */
  350. /*!
  351. * @name Interrupts
  352. * @{
  353. */
  354. /*!
  355. * @brief Enables CSI interrupt requests.
  356. *
  357. * @param base CSI peripheral base address.
  358. * @param mask The interrupts to enable, pass in as OR'ed value of @ref _csi_interrupt_enable.
  359. */
  360. void CSI_EnableInterrupts(CSI_Type *base, uint32_t mask);
  361. /*!
  362. * @brief Disable CSI interrupt requests.
  363. *
  364. * @param base CSI peripheral base address.
  365. * @param mask The interrupts to disable, pass in as OR'ed value of @ref _csi_interrupt_enable.
  366. */
  367. void CSI_DisableInterrupts(CSI_Type *base, uint32_t mask);
  368. /* @} */
  369. /*!
  370. * @name Status
  371. * @{
  372. */
  373. /*!
  374. * @brief Gets the CSI status flags.
  375. *
  376. * @param base CSI peripheral base address.
  377. * @return status flag, it is OR'ed value of @ref _csi_flags.
  378. */
  379. static inline uint32_t CSI_GetStatusFlags(CSI_Type *base)
  380. {
  381. return base->CSISR;
  382. }
  383. /*!
  384. * @brief Clears the CSI status flag.
  385. *
  386. * The flags to clear are passed in as OR'ed value of @ref _csi_flags. The following
  387. * flags are cleared automatically by hardware:
  388. *
  389. * - @ref kCSI_RxFifoFullFlag,
  390. * - @ref kCSI_StatFifoFullFlag,
  391. * - @ref kCSI_Field0PresentFlag,
  392. * - @ref kCSI_Field1PresentFlag,
  393. * - @ref kCSI_RxFifoDataReadyFlag,
  394. *
  395. * @param base CSI peripheral base address.
  396. * @param statusMask The status flags mask, OR'ed value of @ref _csi_flags.
  397. */
  398. static inline void CSI_ClearStatusFlags(CSI_Type *base, uint32_t statusMask)
  399. {
  400. base->CSISR = statusMask;
  401. }
  402. /* @} */
  403. /*!
  404. * @name Transactional
  405. * @{
  406. */
  407. /*!
  408. * @brief Initializes the CSI handle.
  409. *
  410. * This function initializes CSI handle, it should be called before any other
  411. * CSI transactional functions.
  412. *
  413. * @param base CSI peripheral base address.
  414. * @param handle Pointer to the handle structure.
  415. * @param callback Callback function for CSI transfer.
  416. * @param userData Callback function parameter.
  417. *
  418. * @retval kStatus_Success Handle created successfully.
  419. */
  420. status_t CSI_TransferCreateHandle(CSI_Type *base,
  421. csi_handle_t *handle,
  422. csi_transfer_callback_t callback,
  423. void *userData);
  424. /*!
  425. * @brief Start the transfer using transactional functions.
  426. *
  427. * When the empty frame buffers have been submit to CSI driver using function
  428. * @ref CSI_TransferSubmitEmptyBuffer, user could call this function to start
  429. * the transfer. The incoming frame will be saved to the empty frame buffer,
  430. * and user could be optionally notified through callback function.
  431. *
  432. * @param base CSI peripheral base address.
  433. * @param handle Pointer to the handle structure.
  434. *
  435. * @retval kStatus_Success Started successfully.
  436. * @retval kStatus_CSI_NoEmptyBuffer Could not start because no empty frame buffer in queue.
  437. */
  438. status_t CSI_TransferStart(CSI_Type *base, csi_handle_t *handle);
  439. /*!
  440. * @brief Stop the transfer using transactional functions.
  441. *
  442. * The driver does not clean the full frame buffers in queue. In other words, after
  443. * calling this function, user still could get the full frame buffers in queue
  444. * using function @ref CSI_TransferGetFullBuffer.
  445. *
  446. * @param base CSI peripheral base address.
  447. * @param handle Pointer to the handle structure.
  448. *
  449. * @retval kStatus_Success Stoped successfully.
  450. */
  451. status_t CSI_TransferStop(CSI_Type *base, csi_handle_t *handle);
  452. /*!
  453. * @brief Submit empty frame buffer to queue.
  454. *
  455. * This function could be called before @ref CSI_TransferStart or after @ref
  456. * CSI_TransferStart. If there is no room in queue to store the empty frame
  457. * buffer, this function returns error.
  458. *
  459. * @param base CSI peripheral base address.
  460. * @param handle Pointer to the handle structure.
  461. * @param frameBuffer Empty frame buffer to submit.
  462. *
  463. * @retval kStatus_Success Started successfully.
  464. * @retval kStatus_CSI_QueueFull Could not submit because there is no room in queue.
  465. */
  466. status_t CSI_TransferSubmitEmptyBuffer(CSI_Type *base, csi_handle_t *handle, uint32_t frameBuffer);
  467. /*!
  468. * @brief Get one full frame buffer from queue.
  469. *
  470. * After the transfer started using function @ref CSI_TransferStart, the incoming
  471. * frames will be saved to the empty frame buffers in queue. This function gets
  472. * the full-filled frame buffer from the queue. If there is no full frame buffer
  473. * in queue, this function returns error.
  474. *
  475. * @param base CSI peripheral base address.
  476. * @param handle Pointer to the handle structure.
  477. * @param frameBuffer Full frame buffer.
  478. *
  479. * @retval kStatus_Success Started successfully.
  480. * @retval kStatus_CSI_NoFullBuffer There is no full frame buffer in queue.
  481. */
  482. status_t CSI_TransferGetFullBuffer(CSI_Type *base, csi_handle_t *handle, uint32_t *frameBuffer);
  483. /*!
  484. * @brief CSI IRQ handle function.
  485. *
  486. * This function handles the CSI IRQ request to work with CSI driver transactional
  487. * APIs.
  488. *
  489. * @param base CSI peripheral base address.
  490. * @param handle CSI handle pointer.
  491. */
  492. void CSI_TransferHandleIRQ(CSI_Type *base, csi_handle_t *handle);
  493. /* @} */
  494. #if defined(__cplusplus)
  495. }
  496. #endif
  497. /*! @}*/
  498. #endif /* _FSL_CSI_H_ */