fsl_csi.h 21 KB

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