ext: hal: nxp: mcux: csi: Fix double buffering capture

In case of double buffering (two capture buffers), the CSI is
frequently starved because of a lack of buffer in the active pool.

You can find below an example of double buffering scenario:

                FREE_BUF  ACTIVE_BUF
start:              0          2
frame0_complete:    0          1  (no buffer to load in active)
resubmit_frame0:    1          1
frame1_complete:    1          0  (CSI stopped, active buf = 0)
resubmit_frame1:    2          0
                    0    ->    2  (CSI restarted)

This patch solves this issue by loading buffer to active at submit
time.

                FREE_BUF  ACTIVE_BUF
start:              0          2
frame0_complete:    0          1
resubmit_frame0:    1          1
                    0    ->    2  (Direct load to active)
frame1_complete:    0          1
resubmit_frame1:    1          1
                    0    ->    2
...

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
This commit is contained in:
Loic Poulain 2019-03-20 12:21:45 +01:00 committed by Kumar Gala
commit d9be3f21f4

View file

@ -697,6 +697,14 @@ status_t CSI_TransferSubmitEmptyBuffer(CSI_Type *base, csi_handle_t *handle, uin
handle->frameBufferQueue[handle->queueUserWriteIdx] = frameBuffer;
handle->queueUserWriteIdx = CSI_TransferIncreaseQueueIdx(handle->queueUserWriteIdx);
/*
* If transfer is ongoing and an active slot is available, Load the buffer
* now to prevent buffer starvation during next TransferHandleIRQ event.
*/
if (handle->transferOnGoing && handle->activeBufferNum < CSI_MAX_ACTIVE_FRAME_NUM) {
CSI_TransferLoadBufferToDevice(base, handle);
}
base->CSICR1 = csicr1;
if (handle->transferStarted)