RTEMS 6.1-rc6
Loading...
Searching...
No Matches
fsl_csi.h
1/*
2 * Copyright 2017-2021 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _FSL_CSI_H_
10#define _FSL_CSI_H_
11
12#include "fsl_common.h"
13
19/*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
25#define FSL_CSI_DRIVER_VERSION (MAKE_VERSION(2, 1, 5))
28#define CSI_REG_CR1(base) (base)->CR1
29#define CSI_REG_CR2(base) (base)->CR2
30#define CSI_REG_CR3(base) (base)->CR3
31#define CSI_REG_CR18(base) (base)->CR18
32#define CSI_REG_SR(base) (base)->SR
33#define CSI_REG_DMASA_FB1(base) (base)->DMASA_FB1
34#define CSI_REG_DMASA_FB2(base) (base)->DMASA_FB2
35#define CSI_REG_IMAG_PARA(base) (base)->IMAG_PARA
36#define CSI_REG_FBUF_PARA(base) (base)->FBUF_PARA
37
39#ifndef CSI_DRIVER_QUEUE_SIZE
40#define CSI_DRIVER_QUEUE_SIZE 4U
41#endif
42
44#ifndef CSI_DRIVER_FRAG_MODE
45#define CSI_DRIVER_FRAG_MODE 0U
46#endif
47
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/*
56 * The queue max size is 254, so that the queue element index could use `uint8_t`.
57 */
58#if (CSI_DRIVER_ACTUAL_QUEUE_SIZE > 254)
59#error Required queue size is too large
60#endif
61
62/*
63 * The interrupt enable bits are in registers CSICR1[16:31], CSICR3[0:7],
64 * and CSICR18[2:9]. So merge them into an uint32_t value, place CSICR18 control
65 * bits to [8:15].
66 */
67#define CSI_CR1_INT_EN_MASK 0xFFFF0000U
68#define CSI_CR3_INT_EN_MASK 0x000000FFU
69#define CSI_CR18_INT_EN_MASK 0x0000FF00U
70
71#if ((~CSI_CR1_INT_EN_MASK) & \
72 (CSI_CR1_EOF_INT_EN_MASK | CSI_CR1_COF_INT_EN_MASK | CSI_CR1_SF_OR_INTEN_MASK | CSI_CR1_RF_OR_INTEN_MASK | \
73 CSI_CR1_SFF_DMA_DONE_INTEN_MASK | CSI_CR1_STATFF_INTEN_MASK | CSI_CR1_FB2_DMA_DONE_INTEN_MASK | \
74 CSI_CR1_FB1_DMA_DONE_INTEN_MASK | CSI_CR1_RXFF_INTEN_MASK | CSI_CR1_SOF_INTEN_MASK))
75#error CSI_CR1_INT_EN_MASK could not cover all interrupt bits in CSICR1.
76#endif
77
78#if ((~CSI_CR3_INT_EN_MASK) & (CSI_CR3_ECC_INT_EN_MASK | CSI_CR3_HRESP_ERR_EN_MASK))
79#error CSI_CR3_INT_EN_MASK could not cover all interrupt bits in CSICR3.
80#endif
81
82#if ((~CSI_CR18_INT_EN_MASK) & \
83 ((CSI_CR18_FIELD0_DONE_IE_MASK | CSI_CR18_DMA_FIELD1_DONE_IE_MASK | CSI_CR18_BASEADDR_CHANGE_ERROR_IE_MASK) \
84 << 6U))
85#error CSI_CR18_INT_EN_MASK could not cover all interrupt bits in CSICR18.
86#endif
87
89enum
90{
95};
96
102typedef enum _csi_work_mode
103{
108
112typedef enum _csi_data_bus
113{
118
121{
123 kCSI_HsyncActiveHigh = CSI_CR1_HSYNC_POL_MASK,
124 kCSI_DataLatchOnRisingEdge = CSI_CR1_REDGE_MASK,
127 kCSI_VsyncActiveLow = CSI_CR1_SOF_POL_MASK,
128};
129
131typedef struct _csi_config
132{
133 uint16_t width;
134 uint16_t height;
135 uint32_t polarityFlags;
146
148typedef enum _csi_fifo
149{
150 kCSI_RxFifo = (1U << 0U),
151 kCSI_StatFifo = (1U << 1U),
152 kCSI_AllFifo = 0x01 | 0x02,
154
157{
158 kCSI_EndOfFrameInterruptEnable = CSI_CR1_EOF_INT_EN_MASK,
159 kCSI_ChangeOfFieldInterruptEnable = CSI_CR1_COF_INT_EN_MASK,
160 kCSI_StatFifoOverrunInterruptEnable = CSI_CR1_SF_OR_INTEN_MASK,
161 kCSI_RxFifoOverrunInterruptEnable = CSI_CR1_RF_OR_INTEN_MASK,
162 kCSI_StatFifoDmaDoneInterruptEnable = CSI_CR1_SFF_DMA_DONE_INTEN_MASK,
163 kCSI_StatFifoFullInterruptEnable = CSI_CR1_STATFF_INTEN_MASK,
164 kCSI_RxBuffer1DmaDoneInterruptEnable = CSI_CR1_FB2_DMA_DONE_INTEN_MASK,
165 kCSI_RxBuffer0DmaDoneInterruptEnable = CSI_CR1_FB1_DMA_DONE_INTEN_MASK,
166 kCSI_RxFifoFullInterruptEnable = CSI_CR1_RXFF_INTEN_MASK,
167 kCSI_StartOfFrameInterruptEnable = CSI_CR1_SOF_INTEN_MASK,
169 kCSI_EccErrorInterruptEnable = CSI_CR3_ECC_INT_EN_MASK,
170 kCSI_AhbResErrorInterruptEnable = CSI_CR3_HRESP_ERR_EN_MASK,
173 kCSI_BaseAddrChangeErrorInterruptEnable = CSI_CR18_BASEADDR_CHANGE_ERROR_IE_MASK << 6U,
174
175 kCSI_Field0DoneInterruptEnable = CSI_CR18_FIELD0_DONE_IE_MASK << 6U,
176 kCSI_Field1DoneInterruptEnable = CSI_CR18_DMA_FIELD1_DONE_IE_MASK << 6U,
177};
178
198{
199 kCSI_RxFifoDataReadyFlag = CSI_SR_DRDY_MASK,
200 kCSI_EccErrorFlag = CSI_SR_ECC_INT_MASK,
201 kCSI_AhbResErrorFlag = CSI_SR_HRESP_ERR_INT_MASK,
202 kCSI_ChangeOfFieldFlag = CSI_SR_COF_INT_MASK,
203 kCSI_Field0PresentFlag = CSI_SR_F1_INT_MASK,
204 kCSI_Field1PresentFlag = CSI_SR_F2_INT_MASK,
205 kCSI_StartOfFrameFlag = CSI_SR_SOF_INT_MASK,
206 kCSI_EndOfFrameFlag = CSI_SR_EOF_INT_MASK,
207 kCSI_RxFifoFullFlag = CSI_SR_RxFF_INT_MASK,
208 kCSI_RxBuffer1DmaDoneFlag = CSI_SR_DMA_TSF_DONE_FB2_MASK,
209 kCSI_RxBuffer0DmaDoneFlag = CSI_SR_DMA_TSF_DONE_FB1_MASK,
210 kCSI_StatFifoFullFlag = CSI_SR_STATFF_INT_MASK,
211 kCSI_StatFifoDmaDoneFlag = CSI_SR_DMA_TSF_DONE_SFF_MASK,
212 kCSI_StatFifoOverrunFlag = CSI_SR_SF_OR_INT_MASK,
213 kCSI_RxFifoOverrunFlag = CSI_SR_RF_OR_INT_MASK,
214 kCSI_Field0DoneFlag = CSI_SR_DMA_FIELD0_DONE_MASK,
215 kCSI_Field1DoneFlag = CSI_SR_DMA_FIELD1_DONE_MASK,
216 kCSI_BaseAddrChangeErrorFlag = CSI_SR_BASEADDR_CHHANGE_ERROR_MASK,
218};
219
220/* Forward declaration of the handle typedef. */
221typedef struct _csi_handle csi_handle_t;
222
229typedef void (*csi_transfer_callback_t)(CSI_Type *base, csi_handle_t *handle, status_t status, void *userData);
230
237{
238 uint32_t frameBufferQueue[CSI_DRIVER_ACTUAL_QUEUE_SIZE];
240 volatile uint8_t queueWriteIdx;
241 volatile uint8_t queueReadIdx;
242 void *volatile emptyBuffer;
243 volatile uint8_t emptyBufferCnt;
245 volatile uint8_t activeBufferNum;
247 volatile bool transferStarted;
250 void *userData;
251};
252
253#if CSI_DRIVER_FRAG_MODE
254
256typedef enum _csi_frag_input_pixel_format
257{
258 kCSI_FragInputRGB565 = 0,
259 kCSI_FragInputYUYV,
260 kCSI_FragInputUYVY,
261} csi_frag_input_pixel_format_t;
262
264typedef struct _csi_frag_config
265{
266 uint16_t width;
267 uint16_t height;
268 uint32_t polarityFlags;
269 csi_work_mode_t workMode;
270 csi_data_bus_t dataBus;
271 bool useExtVsync;
273 csi_frag_input_pixel_format_t inputFormat;
275 uint32_t dmaBufferAddr0;
276 uint32_t dmaBufferAddr1;
277 uint16_t dmaBufferLine;
280 bool isDmaBufferCachable;
281} csi_frag_config_t;
282
283/* Forward declaration of the handle typedef. */
284typedef struct _csi_frag_handle csi_frag_handle_t;
285
292typedef void (*csi_frag_transfer_callback_t)(CSI_Type *base,
293 csi_frag_handle_t *handle,
294 status_t status,
295 void *userData);
296
300typedef void (*csi_frag_copy_func_t)(void *pDest, const void *pSrc, size_t cnt);
301
303struct _csi_frag_handle
304{
305 uint16_t width;
306 uint16_t height;
307 uint16_t maxLinePerFrag;
308 uint16_t linePerFrag;
309 uint16_t dmaBytePerLine;
310 uint16_t datBytePerLine;
311 uint16_t dmaCurLine;
312 uint16_t windowULX;
313 uint16_t windowULY;
314 uint16_t windowLRX;
315 uint16_t windowLRY;
316 uint32_t outputBuffer;
317 uint32_t datCurWriteAddr;
318 csi_frag_input_pixel_format_t inputFormat;
320 csi_frag_transfer_callback_t callback;
321 void *userData;
322 csi_frag_copy_func_t copyFunc;
323 bool isDmaBufferCachable;
324};
325
327typedef struct _csi_frag_window
328{
329 uint16_t windowULX;
330 uint16_t windowULY;
331 uint16_t windowLRX;
332 uint16_t windowLRY;
333} csi_frag_window_t;
334
336typedef struct _csi_frag_capture_config
337{
338 bool outputGrayScale;
339 uint32_t buffer;
340 csi_frag_window_t *window;
342} csi_frag_capture_config_t;
343
344#endif /* CSI_DRIVER_FRAG_MODE */
345
346/*******************************************************************************
347 * API
348 ******************************************************************************/
349
350#if defined(__cplusplus)
351extern "C" {
352#endif
353
371
379void CSI_Deinit(CSI_Type *base);
380
388void CSI_Reset(CSI_Type *base);
389
409
410/* @} */
411
425void CSI_ClearFifo(CSI_Type *base, csi_fifo_t fifo);
426
440void CSI_ReflashFifoDma(CSI_Type *base, csi_fifo_t fifo);
441
449void CSI_EnableFifoDmaRequest(CSI_Type *base, csi_fifo_t fifo, bool enable);
450
456static inline void CSI_Start(CSI_Type *base)
457{
459 CSI_REG_CR18(base) |= CSI_CR18_CSI_ENABLE_MASK;
460}
461
467static inline void CSI_Stop(CSI_Type *base)
468{
469 CSI_REG_CR18(base) &= ~CSI_CR18_CSI_ENABLE_MASK;
471}
472
480void CSI_SetRxBufferAddr(CSI_Type *base, uint8_t index, uint32_t addr);
481/* @} */
482
494void CSI_EnableInterrupts(CSI_Type *base, uint32_t mask);
495
502void CSI_DisableInterrupts(CSI_Type *base, uint32_t mask);
503
504/* @} */
505
517static inline uint32_t CSI_GetStatusFlags(CSI_Type *base)
518{
519 return CSI_REG_SR(base);
520}
521
537static inline void CSI_ClearStatusFlags(CSI_Type *base, uint32_t statusMask)
538{
539 CSI_REG_SR(base) = statusMask;
540}
541/* @} */
542
543#if !CSI_DRIVER_FRAG_MODE
563 csi_handle_t *handle,
565 void *userData);
566
582
596
611status_t CSI_TransferSubmitEmptyBuffer(CSI_Type *base, csi_handle_t *handle, uint32_t frameBuffer);
612
628status_t CSI_TransferGetFullBuffer(CSI_Type *base, csi_handle_t *handle, uint32_t *frameBuffer);
629
639void CSI_TransferHandleIRQ(CSI_Type *base, csi_handle_t *handle);
640/* @} */
641
642#else
643
656void CSI_FragModeInit(CSI_Type *base);
657
665void CSI_FragModeDeinit(CSI_Type *base);
666
679status_t CSI_FragModeCreateHandle(CSI_Type *base,
680 csi_frag_handle_t *handle,
681 const csi_frag_config_t *config,
682 csi_frag_transfer_callback_t callback,
683 void *userData);
684
695status_t CSI_FragModeTransferCaptureImage(CSI_Type *base,
696 csi_frag_handle_t *handle,
697 const csi_frag_capture_config_t *config);
698
707void CSI_FragModeTransferAbortCaptureImage(CSI_Type *base, csi_frag_handle_t *handle);
708
718void CSI_FragModeTransferHandleIRQ(CSI_Type *base, csi_frag_handle_t *handle);
719
720/* @} */
721
722#endif /* CSI_DRIVER_FRAG_MODE */
723
724#if defined(__cplusplus)
725}
726#endif
727
730#endif /* _FSL_CSI_H_ */
#define CSI_CR1_CCIR_EN(x)
Definition: MIMXRT1052.h:10642
#define CSI_CR1_GCLK_MODE(x)
Definition: MIMXRT1052.h:10608
volatile uint8_t queueWriteIdx
Definition: fsl_csi.h:240
void CSI_SetRxBufferAddr(CSI_Type *base, uint8_t index, uint32_t addr)
Set the RX frame buffer address.
Definition: fsl_csi.c:478
_csi_data_bus
CSI data bus witdh.
Definition: fsl_csi.h:113
void CSI_EnableFifoDmaRequest(CSI_Type *base, csi_fifo_t fifo, bool enable)
Enable or disable the CSI FIFO DMA request.
Definition: fsl_csi.c:572
void CSI_Deinit(CSI_Type *base)
De-initialize the CSI.
Definition: fsl_csi.c:380
status_t CSI_TransferGetFullBuffer(CSI_Type *base, csi_handle_t *handle, uint32_t *frameBuffer)
Get one full frame buffer from queue.
Definition: fsl_csi.c:805
volatile uint8_t queueReadIdx
Definition: fsl_csi.h:241
void CSI_EnableInterrupts(CSI_Type *base, uint32_t mask)
Enables CSI interrupt requests.
Definition: fsl_csi.c:602
_csi_interrupt_enable
CSI feature interrupt source.
Definition: fsl_csi.h:157
void CSI_GetDefaultConfig(csi_config_t *config)
Get the default configuration for to initialize the CSI.
Definition: fsl_csi.c:454
void * userData
Definition: fsl_csi.h:250
enum _csi_data_bus csi_data_bus_t
CSI data bus witdh.
uint8_t bytesPerPixel
Definition: fsl_csi.h:136
volatile bool transferStarted
Definition: fsl_csi.h:247
_csi_work_mode
CSI work mode.
Definition: fsl_csi.h:103
bool useExtVsync
Definition: fsl_csi.h:143
status_t CSI_TransferStart(CSI_Type *base, csi_handle_t *handle)
Start the transfer using transactional functions.
Definition: fsl_csi.c:678
status_t CSI_Init(CSI_Type *base, const csi_config_t *config)
Initialize the CSI.
Definition: fsl_csi.c:279
csi_transfer_callback_t callback
Definition: fsl_csi.h:249
void *volatile emptyBuffer
Definition: fsl_csi.h:242
struct _csi_config csi_config_t
Configuration to initialize the CSI module.
status_t CSI_TransferSubmitEmptyBuffer(CSI_Type *base, csi_handle_t *handle, uint32_t frameBuffer)
Submit empty frame buffer to queue.
Definition: fsl_csi.c:773
enum _csi_fifo csi_fifo_t
The CSI FIFO, used for FIFO operation.
uint16_t linePitch_Bytes
Definition: fsl_csi.h:140
void CSI_TransferHandleIRQ(CSI_Type *base, csi_handle_t *handle)
CSI IRQ handle function.
Definition: fsl_csi.c:848
uint16_t width
Definition: fsl_csi.h:133
uint32_t polarityFlags
Definition: fsl_csi.h:135
void CSI_ClearFifo(CSI_Type *base, csi_fifo_t fifo)
Clear the CSI FIFO.
Definition: fsl_csi.c:500
volatile uint8_t activeBufferNum
Definition: fsl_csi.h:245
void CSI_DisableInterrupts(CSI_Type *base, uint32_t mask)
Disable CSI interrupt requests.
Definition: fsl_csi.c:615
void CSI_Reset(CSI_Type *base)
Reset the CSI.
Definition: fsl_csi.c:397
void CSI_ReflashFifoDma(CSI_Type *base, csi_fifo_t fifo)
Reflash the CSI FIFO DMA.
Definition: fsl_csi.c:543
status_t CSI_TransferStop(CSI_Type *base, csi_handle_t *handle)
Stop the transfer using transactional functions.
Definition: fsl_csi.c:730
_csi_fifo
The CSI FIFO, used for FIFO operation.
Definition: fsl_csi.h:149
void(* csi_transfer_callback_t)(CSI_Type *base, csi_handle_t *handle, status_t status, void *userData)
CSI transfer callback function.
Definition: fsl_csi.h:229
_csi_flags
CSI status flags.
Definition: fsl_csi.h:198
uint16_t height
Definition: fsl_csi.h:134
csi_data_bus_t dataBus
Definition: fsl_csi.h:142
volatile uint8_t emptyBufferCnt
Definition: fsl_csi.h:243
csi_work_mode_t workMode
Definition: fsl_csi.h:141
uint32_t frameBufferQueue[CSI_DRIVER_ACTUAL_QUEUE_SIZE]
Definition: fsl_csi.h:238
enum _csi_work_mode csi_work_mode_t
CSI work mode.
_csi_polarity_flags
CSI signal polarity.
Definition: fsl_csi.h:121
status_t CSI_TransferCreateHandle(CSI_Type *base, csi_handle_t *handle, csi_transfer_callback_t callback, void *userData)
Initializes the CSI handle.
Definition: fsl_csi.c:636
@ kCSI_DataBus16Bit
Definition: fsl_csi.h:115
@ kCSI_DataBus24Bit
Definition: fsl_csi.h:116
@ kCSI_DataBus8Bit
Definition: fsl_csi.h:114
@ kCSI_StartOfFrameInterruptEnable
Definition: fsl_csi.h:167
@ kCSI_StatFifoFullInterruptEnable
Definition: fsl_csi.h:163
@ kCSI_RxFifoFullInterruptEnable
Definition: fsl_csi.h:166
@ kCSI_EccErrorInterruptEnable
Definition: fsl_csi.h:169
@ kCSI_BaseAddrChangeErrorInterruptEnable
Definition: fsl_csi.h:173
@ kCSI_Field1DoneInterruptEnable
Definition: fsl_csi.h:176
@ kCSI_Field0DoneInterruptEnable
Definition: fsl_csi.h:175
@ kCSI_EndOfFrameInterruptEnable
Definition: fsl_csi.h:158
@ kCSI_StatFifoDmaDoneInterruptEnable
Definition: fsl_csi.h:162
@ kCSI_RxBuffer0DmaDoneInterruptEnable
Definition: fsl_csi.h:165
@ kCSI_RxBuffer1DmaDoneInterruptEnable
Definition: fsl_csi.h:164
@ kCSI_RxFifoOverrunInterruptEnable
Definition: fsl_csi.h:161
@ kCSI_ChangeOfFieldInterruptEnable
Definition: fsl_csi.h:159
@ kCSI_StatFifoOverrunInterruptEnable
Definition: fsl_csi.h:160
@ kCSI_AhbResErrorInterruptEnable
Definition: fsl_csi.h:170
@ kCSI_GatedClockMode
Definition: fsl_csi.h:104
@ kCSI_CCIR656ProgressiveMode
Definition: fsl_csi.h:106
@ kCSI_NonGatedClockMode
Definition: fsl_csi.h:105
@ kStatus_CSI_NoEmptyBuffer
Definition: fsl_csi.h:91
@ kStatus_CSI_NoFullBuffer
Definition: fsl_csi.h:92
@ kStatus_CSI_QueueFull
Definition: fsl_csi.h:93
@ kStatus_CSI_FrameDone
Definition: fsl_csi.h:94
@ kCSI_RxFifo
Definition: fsl_csi.h:150
@ kCSI_StatFifo
Definition: fsl_csi.h:151
@ kCSI_AllFifo
Definition: fsl_csi.h:152
@ kCSI_StatFifoOverrunFlag
Definition: fsl_csi.h:212
@ kCSI_StartOfFrameFlag
Definition: fsl_csi.h:205
@ kCSI_Field1PresentFlag
Definition: fsl_csi.h:204
@ kCSI_BaseAddrChangeErrorFlag
Definition: fsl_csi.h:216
@ kCSI_Field0DoneFlag
Definition: fsl_csi.h:214
@ kCSI_RxBuffer1DmaDoneFlag
Definition: fsl_csi.h:208
@ kCSI_RxBuffer0DmaDoneFlag
Definition: fsl_csi.h:209
@ kCSI_RxFifoDataReadyFlag
Definition: fsl_csi.h:199
@ kCSI_EccErrorFlag
Definition: fsl_csi.h:200
@ kCSI_Field1DoneFlag
Definition: fsl_csi.h:215
@ kCSI_StatFifoFullFlag
Definition: fsl_csi.h:210
@ kCSI_StatFifoDmaDoneFlag
Definition: fsl_csi.h:211
@ kCSI_AhbResErrorFlag
Definition: fsl_csi.h:201
@ kCSI_RxFifoOverrunFlag
Definition: fsl_csi.h:213
@ kCSI_Field0PresentFlag
Definition: fsl_csi.h:203
@ kCSI_RxFifoFullFlag
Definition: fsl_csi.h:207
@ kCSI_ChangeOfFieldFlag
Definition: fsl_csi.h:202
@ kCSI_EndOfFrameFlag
Definition: fsl_csi.h:206
@ kCSI_VsyncActiveHigh
Definition: fsl_csi.h:126
@ kCSI_DataLatchOnFallingEdge
Definition: fsl_csi.h:125
@ kCSI_VsyncActiveLow
Definition: fsl_csi.h:127
@ kCSI_HsyncActiveLow
Definition: fsl_csi.h:122
@ kCSI_DataLatchOnRisingEdge
Definition: fsl_csi.h:124
@ kCSI_HsyncActiveHigh
Definition: fsl_csi.h:123
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:225
#define MAKE_STATUS(group, code)
Construct a status code value from a group and code number.
Definition: fsl_common.h:47
@ kStatusGroup_CSI
Definition: fsl_common.h:112
Definition: MIMXRT1052.h:10538
Configuration to initialize the CSI module.
Definition: fsl_csi.h:132
CSI handle structure.
Definition: fsl_csi.h:237
Definition: deflate.c:114