]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/board/diag/csirx/src/csirx_test_tpr12.c
PDK-8403: Board: Workaround for CSI-Rx DSP baremetal interrupt issue on TPR12 EVM
[processor-sdk/pdk.git] / packages / ti / board / diag / csirx / src / csirx_test_tpr12.c
1 /******************************************************************************
2 * Copyright (c) 2020 Texas Instruments Incorporated - http://www.ti.com
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *****************************************************************************/
35 /**
36  *  \file   csirx_test_tpr12.c
37  *
38  *  \brief  csirx diagnostic test file.
39  *
40  *  Targeted Functionality: Verification of csirx interface by receiving fixed
41  *                          pattern data from Radar sensor.
42  *
43  *  Operation: This test verifies CSIRX interface by receiving the userDefinedMapping
44  *          user defined from IWR143 radar sensor.
45  *
46  *  Supported SoCs: TPR12.
47  *
48  *  Supported Platforms: tp12_evm.
49  */
51 #ifdef USE_BIOS
52 /* XDCtools Header files */
53 #include <xdc/std.h>
54 #include <xdc/cfg/global.h>
55 #include <xdc/runtime/System.h>
56 #include <stdio.h>
57 #include <ti/sysbios/knl/Task.h>
59 /* BIOS Header files */
60 #include <ti/sysbios/BIOS.h>
61 #include <xdc/runtime/Error.h>
62 #else
63 #ifdef BUILD_C66X_1
64 /* !! HACK to workaround c66x OSAL baremetal issue with not enabling Hwi interrupt associated with EventCombiner */
65 /* Osal baremetal lib for c66x does not enable the Hwi interrupt number when Osal_enableInterrupt is called.
66  * This is correct behaviour but the issue is when registering interrupt the Hwi interrupt number is not
67  * enabled if Osal_registerInterrupt enableIntr param is set to FALSE> This iswrong and the Hwi interrupt
68  * number should be enabled irrespective of a particular eventCombiner event is enabled or not.
69  * Until this is fixed in c6xx osal baremetal library, adding hack in application to enable the interrupt
70  */
71 #include <ti/osal/src/nonos/Nonos_config.h>
72 #define CSIRX_C66X_COMMON_ISR_HWI_INT_NUM                                                         (6U)
73 #endif
74 #endif /* #ifdef USE_BIOS */
77 #include <csirx_test_tpr12.h>
79 BoardDaig_State gTestState = {0};
80 volatile bool gFrameReceived = 0;
81 uint32_t gErrorCode = 0;
82 uint32_t gFrameCounter = 0;
84 #define BOARD_DIAG_CSIRX_A_TEST             (1U)
85 #define BOARD_DIAG_TEST_BUF_INIT_PATTERN    (0xBE)
86 #define BOARD_DIAG_TEST_PAYLOAD_PATTERN_NUM_BYTES_PER_FRAME (128U)
87 #define BOARD_DIAG_INIT_PATTERN_SIZE        (BOARD_DIAG_PING_OR_PONG_BUF_SIZE_ALIGNED + 32U)
88 /* Ping */
89 #pragma DATA_SECTION(testPingBufL3, ".l3ram");
90 uint8_t testPingBufL3[BOARD_DIAG_INIT_PATTERN_SIZE]       \
91         __attribute__ ((aligned(BOARD_DIAG_PING_PONG_ALIGNMENT)));
93 #pragma DATA_SECTION(testPingBufHWA, ".hwaram");
94 uint8_t testPingBufHWA[BOARD_DIAG_INIT_PATTERN_SIZE]       \
95         __attribute__ ((aligned(BOARD_DIAG_PING_PONG_ALIGNMENT)));
97 #pragma DATA_SECTION(testPingBufL2, ".l2ram");
98 uint8_t testPingBufL2[BOARD_DIAG_INIT_PATTERN_SIZE]       \
99         __attribute__ ((aligned(BOARD_DIAG_PING_PONG_ALIGNMENT)));
101 /* Pong */
102 #pragma DATA_SECTION(testPongBufL3, ".l3ram");
103 uint8_t testPongBufL3[BOARD_DIAG_INIT_PATTERN_SIZE]       \
104         __attribute__ ((aligned(BOARD_DIAG_PING_PONG_ALIGNMENT)));
106 #pragma DATA_SECTION(testPongBufHWA, ".hwaram");
107 uint8_t testPongBufHWA[BOARD_DIAG_INIT_PATTERN_SIZE]       \
108         __attribute__ ((aligned(BOARD_DIAG_PING_PONG_ALIGNMENT)));
110 #pragma DATA_SECTION(testPongBufL2, ".l2ram");
111 uint8_t testPongBufL2[BOARD_DIAG_INIT_PATTERN_SIZE]       \
112         __attribute__ ((aligned(BOARD_DIAG_PING_PONG_ALIGNMENT)));
114 /**
115  *  \brief    Used to read the payload data from the ping-pong buffers
116  *            This function comapres the data received from the buffers
117  *            to expected value.
118  *
119  *  \param    handle              [IN]     CSIRX Handler
120  *
121  *  \return   NULL
122  *
123  */
124 void BoardDiag_CheckPayloadReceived(CSIRX_Handle handle)
126     uint32_t numBytes = 0;
127     uint32_t buffer, bufIndx = 0;
128     uint8_t *buf;
130     gErrorCode = CSIRX_getContextReceivedBuffer(handle, BOARD_DIAG_TEST_CONTEXT, &buffer);
131     DebugP_assert(gErrorCode == CSIRX_NO_ERROR);
132     buffer = CSL_globToLocAddr(buffer);
133     buf = (uint8_t *)buffer;
134     CacheP_Inv(buf,BOARD_DIAG_PING_OR_PONG_BUF_SIZE_ALIGNED);
135 #if defined(PAYLOAD_PATTERN_CHECK)
136     for(numBytes = 0; numBytes < BOARD_DIAG_PING_OR_PONG_BUF_SIZE_ALIGNED; numBytes++)
137     {
138         if(buf[bufIndx++] != BOARD_DIAG_TEST_PATTERN)
139         {
140             gTestState.isReceivedPayloadCorrect = false;
141             printf("Frame - %d is invalid\n",
142             gTestState.contextIRQcounts[BOARD_DIAG_TEST_CONTEXT].frameEndCodeDetect);
143             break;
144         }
145     }
146 #else
147     numBytes = BOARD_DIAG_PING_OR_PONG_BUF_SIZE_ALIGNED;
148     bufIndx = BOARD_DIAG_PING_OR_PONG_BUF_SIZE_ALIGNED;
149 #endif
150     if (numBytes == BOARD_DIAG_PING_OR_PONG_BUF_SIZE_ALIGNED)
151     {
152         for (; numBytes < (BOARD_DIAG_INIT_PATTERN_SIZE);numBytes++)
153         {
154             if(buf[bufIndx++] != BOARD_DIAG_TEST_BUF_INIT_PATTERN)
155             {
156                 gTestState.isReceivedPayloadCorrect = false;
157                 printf("Buffer corruption - %d is invalid\n",
158                 gTestState.contextIRQcounts[BOARD_DIAG_TEST_CONTEXT].frameEndCodeDetect);
159                 break;
160             }
161         }
162     }
165 /**
166  *  \brief    Callback function for common.irq interrupt, generated when
167  *            end of frame code and line code detected.
168  *
169  *  \param    handle              [IN]     CSIRX Handler
170  *            arg                 [IN]     CALLBACK function argument
171  *            IRQ                 [OUT]    CSIRX common irq
172  *
173  */
174 void BoardDiag_commonCallback(CSIRX_Handle handle, uint32_t arg,
175                               CSIRX_CommonIRQ_t *IRQ)
177     uint8_t i;
178     uint32_t frameCounter =
179     gTestState.contextIRQcounts[BOARD_DIAG_TEST_CONTEXT].frameEndCodeDetect + 1;
181     DebugP_assert(handle != NULL);
182     DebugP_assert(arg == BOARD_DIAG_TEST_COMMON_CB_ARG);
183     gTestState.callbackCount.common++;
185     gTestState.IRQ.common = *IRQ;
187     /* Counts book-keeping */
188     if(IRQ->isOCPerror == true)
189     {
190         gTestState.commonIRQcount.isOCPerror++;
191     }
192     if(IRQ->isComplexIOerror == true)
193     {
194         gTestState.commonIRQcount.isComplexIOerror++;
195     }
196     if(IRQ->isFIFOoverflow == true)
197     {
198         gTestState.commonIRQcount.isFIFOoverflow++;
199     }
201     if(IRQ->isComplexIOerror)
202     {
203         gErrorCode = CSIRX_getComplexIOlanesIRQ(handle,
204                                                &gTestState.IRQ.complexIOlanes);
205         if(gErrorCode != CSIRX_NO_ERROR)
206         {
207             DebugP_log1("Error occured while recieving the frame-%d\n", frameCounter);
208         }
209         DebugP_assert(gErrorCode == CSIRX_NO_ERROR);
211         gErrorCode = CSIRX_clearAllcomplexIOlanesIRQ(handle);
212         DebugP_assert(gErrorCode == CSIRX_NO_ERROR);
213     }
215     for(i = 0; i < CSIRX_NUM_CONTEXTS; i++)
216     {
217         if(IRQ->isContext[i] == true)
218         {
219             gErrorCode = CSIRX_getContextIRQ(handle, i,
220                                             &gTestState.IRQ.context[i]);
221             DebugP_assert(gErrorCode == CSIRX_NO_ERROR);
223             if(gTestState.IRQ.context[i].isFrameEndCodeDetect == true)
224             {
225                 gTestState.contextIRQcounts[i].frameEndCodeDetect++;
226                   /* Single frame is received */
227                 gFrameReceived = true;
229             }
231             if(gTestState.IRQ.context[i].isLineEndCodeDetect == true)
232             {
233                 gTestState.contextIRQcounts[i].lineEndCodeDetect++;
234             }
236             gErrorCode = CSIRX_clearAllcontextIRQ(handle, i);
237             DebugP_assert(gErrorCode == CSIRX_NO_ERROR);
238         }
239     }
242 void BoardDiag_CheckStateError(bool *isTestPass)
244     if(gTestState.commonIRQcount.isOCPerror != 0)
245     {
246         printf("OCP error has occured %d number of times \n", gTestState.commonIRQcount.isOCPerror);
247         *isTestPass = false;
248     }
249     if(gTestState.commonIRQcount.isComplexIOerror != 0)
250     {
251         printf("Complex IO error has occured %d number of times \n", gTestState.commonIRQcount.isComplexIOerror);
252         *isTestPass = false;
253     }
254     if(gTestState.commonIRQcount.isFIFOoverflow != 0)
255     {
256         printf("FIFO Overflow error has occured %d number of times \n",gTestState.commonIRQcount.isFIFOoverflow);
257         *isTestPass = false;
258     }
261 void BoardDiag_combinedEOFcallback(CSIRX_Handle handle, uint32_t arg)
263     DebugP_assert(handle != NULL);
264     DebugP_assert(arg == BOARD_DIAG_TEST_COMBINED_EOF_CB_ARG);
265     gTestState.callbackCount.combinedEOF++;
268 Board_DiagConfig testConfig =
270     /* DDR clock set to 300 MHz */
271     .DPHYcfg.ddrClockInHz = 300000000U,
272     .DPHYcfg.isClockMissingDetectionEnabled = true,
273     .DPHYcfg.triggerEscapeCode[0] = 0x0,
274     .DPHYcfg.triggerEscapeCode[1] = 0x0,
275     .DPHYcfg.triggerEscapeCode[2] = 0x0,
276     .DPHYcfg.triggerEscapeCode[3] = 0x0,
278     .complexIOcfg.lanesConfig.dataLane[0].polarity = 0,
279     .complexIOcfg.lanesConfig.dataLane[0].position = CSIRX_LANE_POSITION_1,
280     .complexIOcfg.lanesConfig.dataLane[1].polarity = 0,
281     .complexIOcfg.lanesConfig.dataLane[1].position = CSIRX_LANE_POSITION_2,
282     .complexIOcfg.lanesConfig.dataLane[2].polarity = 0,
283     .complexIOcfg.lanesConfig.dataLane[2].position = CSIRX_LANE_POSITION_4,
284     .complexIOcfg.lanesConfig.dataLane[3].polarity = 0,
285     .complexIOcfg.lanesConfig.dataLane[3].position = CSIRX_LANE_POSITION_5,
286     .complexIOcfg.lanesConfig.clockLane.polarity = 0,
287     .complexIOcfg.lanesConfig.clockLane.position = CSIRX_LANE_POSITION_3,
288     .complexIOcfg.lanesIRQ.isAllLanesULPMenter = true,
289     .complexIOcfg.lanesIRQ.isAllLanesULPMexit = true,
290     .complexIOcfg.lanesIRQ.dataLane[0].isStateTransitionToULPM = true,
291     .complexIOcfg.lanesIRQ.dataLane[0].isControlError = true,
292     .complexIOcfg.lanesIRQ.dataLane[0].isEscapeEntryError = true,
293     .complexIOcfg.lanesIRQ.dataLane[0].isStartOfTransmisionSyncError = true,
294     .complexIOcfg.lanesIRQ.dataLane[0].isStartOfTransmisionError = true,
295     .complexIOcfg.lanesIRQ.dataLane[1].isStateTransitionToULPM = true,
296     .complexIOcfg.lanesIRQ.dataLane[1].isControlError = true,
297     .complexIOcfg.lanesIRQ.dataLane[1].isEscapeEntryError = true,
298     .complexIOcfg.lanesIRQ.dataLane[1].isStartOfTransmisionSyncError = true,
299     .complexIOcfg.lanesIRQ.dataLane[1].isStartOfTransmisionError = true,
300     .complexIOcfg.lanesIRQ.dataLane[2].isStateTransitionToULPM = true,
301     .complexIOcfg.lanesIRQ.dataLane[2].isControlError = true,
302     .complexIOcfg.lanesIRQ.dataLane[2].isEscapeEntryError = true,
303     .complexIOcfg.lanesIRQ.dataLane[2].isStartOfTransmisionSyncError = true,
304     .complexIOcfg.lanesIRQ.dataLane[2].isStartOfTransmisionError = true,
305     .complexIOcfg.lanesIRQ.dataLane[3].isStateTransitionToULPM = true,
306     .complexIOcfg.lanesIRQ.dataLane[3].isControlError = true,
307     .complexIOcfg.lanesIRQ.dataLane[3].isEscapeEntryError = true,
308     .complexIOcfg.lanesIRQ.dataLane[3].isStartOfTransmisionSyncError = true,
309     .complexIOcfg.lanesIRQ.dataLane[3].isStartOfTransmisionError = true,
310     .complexIOcfg.lanesIRQ.clockLane.isStateTransitionToULPM = true,
311     .complexIOcfg.lanesIRQ.clockLane.isControlError = true,
312     .complexIOcfg.lanesIRQ.clockLane.isEscapeEntryError = true,
313     .complexIOcfg.lanesIRQ.clockLane.isStartOfTransmisionSyncError = true,
314     .complexIOcfg.lanesIRQ.clockLane.isStartOfTransmisionError = true,
316     .commonCfg.isSoftStoppingOnInterfaceDisable = true,
317     .commonCfg.isECCenabled = false,
318     .commonCfg.isEXP16SignExtensionEnabled = false,
319     .commonCfg.isBurstSizeExpand = false,
320     .commonCfg.isNonPostedWrites = true,
321     .commonCfg.isOCPautoIdle = true,
322     .commonCfg.stopStateFSMtimeoutInNanoSecs = 200000U,
323     .commonCfg.burstSize = 8,
324     .commonCfg.endianness = CSIRX_ALL_LITTLE_ENDIAN,
325     .commonCfg.startOfFrameIRQ0contextId = BOARD_DIAG_TEST_CONTEXT,
326     .commonCfg.startOfFrameIRQ1contextId = 0,
327     .commonCfg.endOfFrameIRQ0contextId = BOARD_DIAG_TEST_CONTEXT,
328     .commonCfg.endOfFrameIRQ1contextId = 0,
329     .commonCfg.IRQ.isOCPerror = true,
330     .commonCfg.IRQ.isGenericShortPacketReceive = false,
331     .commonCfg.IRQ.isECConeBitShortPacketErrorCorrect = false,
332     .commonCfg.IRQ.isECCmoreThanOneBitCannotCorrect = false,
333     .commonCfg.IRQ.isComplexIOerror = true,
334     .commonCfg.IRQ.isFIFOoverflow = true,
335     .commonCfg.IRQ.isContext[0] = false,
336     .commonCfg.IRQ.isContext[1] = false,
337     .commonCfg.IRQ.isContext[2] = false,
338     .commonCfg.IRQ.isContext[3] = false,
339     .commonCfg.IRQ.isContext[4] = false,
340     .commonCfg.IRQ.isContext[5] = false,
341     .commonCfg.IRQ.isContext[6] = false,
342     .commonCfg.IRQ.isContext[7] = false,
343     .commonCfg.IRQcallbacks.common.fxn = BoardDiag_commonCallback,
344     .commonCfg.IRQcallbacks.common.arg = BOARD_DIAG_TEST_COMMON_CB_ARG,
345     .commonCfg.IRQcallbacks.combinedEndOfLine.fxn = NULL,
346     .commonCfg.IRQcallbacks.combinedEndOfLine.arg = 0,
347 #ifdef BUILD_DSP_1
348     .commonCfg.IRQcallbacks.combinedEndOfFrame.fxn = NULL,
349     .commonCfg.IRQcallbacks.combinedEndOfFrame.arg = 0,
350 #else
351     .commonCfg.IRQcallbacks.combinedEndOfFrame.fxn =
352         BoardDiag_combinedEOFcallback,
353     .commonCfg.IRQcallbacks.combinedEndOfFrame.arg =
354         BOARD_DIAG_TEST_COMBINED_EOF_CB_ARG,
355 #endif
356     .commonCfg.IRQcallbacks.startOfFrameIRQ0.fxn = NULL,
357     .commonCfg.IRQcallbacks.startOfFrameIRQ0.arg = 0,
358     .commonCfg.IRQcallbacks.startOfFrameIRQ1.fxn = NULL,
359     .commonCfg.IRQcallbacks.startOfFrameIRQ1.arg = 0,
360     .commonCfg.IRQcallbacks.endOfFrameIRQ0.fxn = NULL,
361     .commonCfg.IRQcallbacks.endOfFrameIRQ0.arg = 0,
362     .commonCfg.IRQcallbacks.endOfFrameIRQ1.fxn = NULL,
363     .commonCfg.IRQcallbacks.endOfFrameIRQ1.arg = 0,
365     .contextCfg.virtualChannelId = BOARD_DIAG_TEST_VC,
366     .contextCfg.format = BOARD_DIAG_TEST_FORMAT,
367     .contextCfg.userDefinedMapping = BOARD_DIAG_TEST_USER_DEFINED_MAPPING,
368     .contextCfg.isByteSwapEnabled = false,
369     .contextCfg.isGenericEnabled = false,
370     .contextCfg.isTranscodingEnabled = false,
371     .contextCfg.transcodeConfig.transcodeFormat =
372                                 CSIRX_TRANSCODE_FORMAT_NO_TRANSCODE,
373     .contextCfg.transcodeConfig.isHorizontalDownscalingBy2Enabled = false,
374     .contextCfg.transcodeConfig.crop.horizontalCount = 0,
375     .contextCfg.transcodeConfig.crop.horizontalSkip = 0,
376     .contextCfg.transcodeConfig.crop.verticalCount = 0,
377     .contextCfg.transcodeConfig.crop.verticalSkip = 0,
378     .contextCfg.alpha = 0,
379     .contextCfg.pingPongConfig.pingPongSwitchMode = CSIRX_PING_PONG_FRAME_SWITCHING,
380     .contextCfg.pingPongConfig.numFramesForFrameBasedPingPongSwitching = 1,
381     .contextCfg.pingPongConfig.lineOffset =
382                             CSIRX_LINEOFFSET_CONTIGUOUS_STORAGE,
383     .contextCfg.pingPongConfig.pingAddress = NULL,
384     .contextCfg.pingPongConfig.pongAddress = NULL,
385     .contextCfg.numFramesToAcquire = CSIRX_NUM_FRAMES_TO_ACQUIRE_INFINITE,
386     .contextCfg.IRQ.isNumLines = false,
387     .contextCfg.isNumLinesForIRQmoduloWithinFrame = false,
388     .contextCfg.numLinesForIRQ = 0,
389     .contextCfg.IRQ.isFramesToAcquire = false,
390     .contextCfg.IRQ.isPayloadChecksumMismatch = false,
391     .contextCfg.IRQ.isFrameStartCodeDetect = true,
392     .contextCfg.IRQ.isFrameEndCodeDetect = true,
393     .contextCfg.IRQ.isLineStartCodeDetect = false,
394     .contextCfg.IRQ.isLineEndCodeDetect = true,
395     .contextCfg.IRQ.isECConeBitLongPacketCorrect = false,
396     .contextCfg.endOfLineIRQcallback.fxn = NULL,
397     .contextCfg.endOfLineIRQcallback.arg = NULL,
398     .contextCfg.isEndOfFramePulseEnabled = true,
399     .contextCfg.isEndOfLinePulseEnabled = false,
400     .contextCfg.isChecksumEnabled = true
401 };
403 /**
404  *  \brief    Initialize the ping pong buffers to reset values
405  *  \param    pingBuf   [OUT]    Ping buffer
406  *            pongBuf   [OUT]    Pong buffer
407  *            sizeBuf   [OUT]    Size of the buffer
408  *
409  * \retval
410  *      none
411  */
412 void BoardDiag_InitBuf(uint32_t pingBuf, uint32_t pongBuf, uint32_t sizeBuf)
414     /* initialize ping/pong bufs to known failing pattern */
415     memset((void *)pingBuf, BOARD_DIAG_TEST_BUF_INIT_PATTERN, sizeBuf);
416     CacheP_wbInv((void *)pingBuf, sizeBuf);
417     memset((void *)pongBuf, BOARD_DIAG_TEST_BUF_INIT_PATTERN, sizeBuf);
418     CacheP_wbInv((void *)pongBuf, sizeBuf);
421 /**
422  *  \brief    This function initializes test state variable.
423  */
424 void BoardDiag_TestInit(void)
426     memset(&gTestState, 0, sizeof(gTestState));
428     gTestState.isReceivedPayloadCorrect = true;
432 /**
433  *  \brief    Gets test buffer address from a bunch of input parameters
434  *  \param    BoardDiag_RAMtype   [IN]    Type of buffer RAM
435  *            buf                 [OUT]   Pointer to where the buffer address is returned
436  *            isPing              [IN]    true if ping buffer else pong buffer
437  *
438  *
439  *  \retval
440  *      none
441  */
442 void BoardDiag_getBuf(BoardDiag_RAMtype bufRAMtype, uint32_t *buf, bool isPing)
444     if(isPing == true)
445     {
446         switch(bufRAMtype)
447         {
448         case BOARD_DIAG_L3RAM:
449             *buf = (uint32_t) &testPingBufL3;
450             break;
451         case BOARD_DIAG_HWARAM:
452             *buf = (uint32_t) &testPingBufHWA;
453             break;
454         case BOARD_DIAG_L2RAM:
455             *buf = (uint32_t) &testPingBufL2;
456             break;
457         }
458     }
459     else
460     {
461         switch(bufRAMtype)
462         {
463         case BOARD_DIAG_L3RAM:
464             *buf = (uint32_t) &testPongBufL3;
465             break;
466         case BOARD_DIAG_HWARAM:
467             *buf = (uint32_t) &testPongBufHWA;
468             break;
469         case BOARD_DIAG_L2RAM:
470             *buf = (uint32_t) &testPongBufL2;
471             break;
472         }
473     }
476 /**
477  *  \brief    The function performs the CSI-Rx Diagnostic
478  *            test.
479  *
480  *  \return   int8_t
481  *               0 - in case of success
482  *              -1 - in case of failure.
483  *
484  */
485 bool BoardDiag_CsirxTestRun(uint8_t instanceId)
487     CSIRX_Handle         handle;
488     int32_t errorCode;
489     uint32_t pingBuf, pongBuf;
490     CSIRX_InstanceInfo_t instanceInfo;
491     bool isTestPass = true;
492     CSL_rcss_rcmRegs *rcss_rcm = (CSL_rcss_rcmRegs *)CSL_RCSS_RCM_U_BASE;
493     volatile bool isComplexIOresetDone, isForceRxModeDeasserted;
494     volatile uint32_t numComplexIOresetDonePolls, numComplexIOPowerStatusPolls,
495              numForceRxModeDeassertedPolls;
496     volatile uint8_t isComplexIOpowerStatus;
497     volatile bool isForceRxModeOnComplexIOdeasserted;
499     /* get ping-pong buffer addresses based on the RAM type and context */
500     BoardDiag_getBuf(BOARD_DIAG_HWARAM, &pingBuf, true);
501     BoardDiag_getBuf(BOARD_DIAG_HWARAM, &pongBuf, false);
503     BoardDiag_InitBuf(pingBuf, pongBuf, BOARD_DIAG_INIT_PATTERN_SIZE);
504     /* initialize the ping-pong buffers */
505     BoardDiag_TestInit();
507     CSL_FINS(rcss_rcm->RCSS_CSI2A_RST_CTRL, RCSS_RCM_RCSS_CSI2A_RST_CTRL_RCSS_CSI2A_RST_CTRL_ASSERT, 0x7);
509     CSL_FINS(rcss_rcm->RCSS_CSI2A_RST_CTRL, RCSS_RCM_RCSS_CSI2A_RST_CTRL_RCSS_CSI2A_RST_CTRL_ASSERT, 0U);
512     /* Initialize CSIRX */
513     errorCode = CSIRX_init();
514     if(errorCode != CSIRX_NO_ERROR)
515     {
516         printf("CSIRX_init failed with errorCode = %d\n", errorCode);
517         isTestPass = false;
518         return isTestPass;
519     }
521     /* Open the CSI Instance */
522     handle = CSIRX_open(instanceId, NULL, &errorCode, &instanceInfo);
523     if(handle == NULL)
524     {
525         if(errorCode == CSIRX_E_INVALID__INSTANCE_ID)
526         {
527             printf("Csirx Instance not supported\n");
528         }
529         else
530         {
531             printf("Unable to open the csirx Instance, erorCode = %d\n", errorCode);
532         }
533         isTestPass = false;
534         return isTestPass;
535     }
536     DebugP_log3("Instance opened, Revision = %d.%d, Number of "
537             "Contexts = %d\n", instanceInfo.majorRevisionId,
538             instanceInfo.minorRevisionId,
539             instanceInfo.numContexts);
541     /* reset csi */
542     errorCode = CSIRX_reset(handle);
543     if(errorCode != CSIRX_NO_ERROR)
544     {
545         printf("CSIRX_reset failed, errorCode = %d\n", errorCode);
546         isTestPass = false;
547         return isTestPass;
548     }
549     /* config complex IO - lanes and IRQ */
550     errorCode = CSIRX_configComplexIO(handle, &testConfig.complexIOcfg);
551     if(errorCode != CSIRX_NO_ERROR)
552     {
553         printf("CSIRX_configComplexIO failed, errorCode = %d\n",
554                     errorCode);
555         isTestPass = false;
556         return isTestPass;
557     }
559     /* deassert complex IO reset */
560     errorCode = CSIRX_deassertComplexIOreset(handle);
561     if(errorCode != CSIRX_NO_ERROR)
562     {
563         printf("CSIRX_deassertComplexIOreset failed, errorCode = %d\n",
564                     errorCode);
565         isTestPass = false;
566         return isTestPass;
567     }
569     /* config DPHY */
570     errorCode = CSIRX_configDPHY(handle, &testConfig.DPHYcfg);
571     if(errorCode != CSIRX_NO_ERROR)
572     {
573         printf("CSIRX_configDPHY failed, errorCode = %d\n", errorCode);
574         isTestPass = false;
575         return isTestPass;
576     }
578     errorCode = CSIRX_setComplexIOpowerCommand(handle, 1);
579     if(errorCode != CSIRX_NO_ERROR)
580     {
581         printf("CSIRX_setComplexIOpowerCommand failed, errorCode = %d\n",
582                     errorCode);
583         isTestPass = false;
584         return isTestPass;
585     }
587     numComplexIOPowerStatusPolls = 0;
588     do
589     {
590         errorCode = CSIRX_getComplexIOpowerStatus(handle,
591                                             (uint8_t*)&isComplexIOpowerStatus);
592         if(errorCode != CSIRX_NO_ERROR)
593         {
594             printf("CSIRX_getComplexIOpowerStatus failed, errorCode = "
595             " %d\n", errorCode);
596             isTestPass = false;
597         return isTestPass;
598         }
599         if (isComplexIOpowerStatus == 0)
600         {
601             Osal_delay(1);
602         }
603         numComplexIOPowerStatusPolls++;
604     } while((isComplexIOpowerStatus == 0));
605     printf("Complex IO Powered up.Run AWR FE binrary config now\n");
606     /* config common */
607     testConfig.commonCfg.IRQ.isContext[BOARD_DIAG_TEST_CONTEXT] = true,
608     errorCode = CSIRX_configCommon(handle, &testConfig.commonCfg);
609     if(errorCode != CSIRX_NO_ERROR)
610     {
611         printf("CSIRX_configCommon failed, errorCode = %d\n", errorCode);
612         isTestPass = false;
613         return isTestPass;
614     }
615 #ifndef USE_BIOS
616 #ifdef BUILD_C66X_1
617     /* !! HACK to workaround c66x OSAL baremetal issue with not enabling Hwi interrupt associated with EventCombiner */
618     /* Osal baremetal lib for c66x does not enable the Hwi interrupt number when Osal_enableInterrupt is called.
619      * This is correct behaviour but the issue is when registering interrupt the Hwi interrupt number is not
620      * enabled if Osal_registerInterrupt enableIntr param is set to FALSE> This iswrong and the Hwi interrupt
621      * number should be enabled irrespective of a particular eventCombiner event is enabled or not.
622      * Until this is fixed in c6xx osal baremetal library, adding hack in application to enable the interrupt
623      */
624     OsalArch_enableInterrupt(CSIRX_C66X_COMMON_ISR_HWI_INT_NUM);
625 #endif
626 #endif
627     /* config contexts */
628     /* assign ping pong address */
629     testConfig.contextCfg.pingPongConfig.pingAddress =
630             (uint32_t) CSL_locToGlobAddr(pingBuf);
631     testConfig.contextCfg.pingPongConfig.pongAddress =
632             (uint32_t) CSL_locToGlobAddr(pongBuf);
634     errorCode = CSIRX_configContext(handle, BOARD_DIAG_TEST_CONTEXT,
635                                 &testConfig.contextCfg);
636     if(errorCode != CSIRX_NO_ERROR)
637     {
638         printf("CSIRX_configContext failed, errorCode = %d\n", errorCode);
639         
640         isTestPass = false;
641         return isTestPass;
642     }
644     /* enable context */
645     errorCode = CSIRX_enableContext(handle, BOARD_DIAG_TEST_CONTEXT);
646     if(errorCode != CSIRX_NO_ERROR)
647     {
648         printf("CSIRX_enableContext failed, errorCode = %d\n", errorCode);
649         isTestPass = false;
650         return isTestPass;
651     }
653     /* enable interface */
654     errorCode = CSIRX_enableInterface(handle);
655     if(errorCode != CSIRX_NO_ERROR)
656     {
657         printf("CSIRX_enableInterface failed, errorCode = %d\n",
658                     errorCode);
659         isTestPass = false;
660         return isTestPass;
661     }
663     /* Wait until complex IO reset complete */
664     numComplexIOresetDonePolls = 0;
665     do
666     {
667         errorCode = CSIRX_isComplexIOresetDone(handle,
668                                             (bool *)&isComplexIOresetDone);
669         if(errorCode != CSIRX_NO_ERROR)
670         {
671             printf("CSIRX_isComplexIOresetDone failed, errorCode = "
672             " %d\n", errorCode);
673             isTestPass = false;
674             return isTestPass;
675         }
676         if (isComplexIOresetDone == false)
677         {
678             /* NOTE: This delay should be much smaller than frame time, default BIOS tick = 1 ms */
679             Osal_delay(1);
680         }
681         numComplexIOresetDonePolls++;
682     }while((isComplexIOresetDone == false));
684     if(isComplexIOresetDone == false)
685     {
686         printf("CSIRX_isComplexIOresetDone attempts exceeded\n");
687         isTestPass = false;
688         return isTestPass;
689     }
691     /*Wait csirx receive the data */
692     while(gFrameCounter !=
693           BOARD_DIAG_TEST_NUM_FRAMES)
694     {
695         if(gFrameReceived)
696         {
697             /* TODO: Added global variable counter to check the while loop is not optimized */
698             gFrameCounter++;
699             BoardDiag_CheckPayloadReceived(handle);
700             DebugP_log1("Frame - %d received\n" ,
701             gTestState.contextIRQcounts[BOARD_DIAG_TEST_CONTEXT].frameEndCodeDetect);
702             gFrameReceived = false;
704             /* Test is considered as failed even if any one of the frame
705                received is invalid */
706             if(isTestPass != false)
707             {
708                 isTestPass = isTestPass & gTestState.isReceivedPayloadCorrect;
709             }
710         }
711         Osal_delay(1);
712     }
714     if(gFrameCounter != BOARD_DIAG_TEST_NUM_FRAMES)
715     {
716         printf("Number of frames recieved does not match\n");
717         isTestPass = false;
718     }
720     BoardDiag_CheckStateError(&isTestPass);
722     /* disable context */
723     errorCode = CSIRX_disableContext(handle, BOARD_DIAG_TEST_CONTEXT);
724     if(errorCode != CSIRX_NO_ERROR)
725     {
726         printf("CSIRX_disableContext failed,errorCode = %d\n", errorCode);
727         isTestPass = false;
728         return isTestPass;
729     }
731     /* disable interface */
732     errorCode = CSIRX_disableInterface(handle);
733     if(errorCode != CSIRX_NO_ERROR)
734     {
735         printf("CSIRX_disableInterface failed, errorCode = %d\n",
736                     errorCode);
737         isTestPass = false;
738         return isTestPass;
739     }
741     /* close instance */
742     errorCode = CSIRX_close(handle);
743     if(errorCode != CSIRX_NO_ERROR)
744     {
745         printf("CSIRX_close failed, errorCode = %d\n", errorCode);
746         isTestPass = false;
747         return isTestPass;
748     }
750     return(isTestPass);
753 /**
754  *  \brief    The function performs the CSIRX Diagnostic
755  *            test.
756  *
757  *  \return   int8_t
758  *               0 - in case of success
759  *              -1 - in case of failure.
760  *
761  */
762 #ifdef USE_BIOS
763 int8_t BoardDiag_CsirxTest(UArg arg0, UArg arg1)
764 #else
765 int8_t BoardDiag_CsirxTest(void)
766 #endif
768     uint8_t result;
769     /* TPR12_TODO: Update this to menu based after initial testing */
770 #if defined (BOARD_DIAG_CSIRX_A_TEST)
771     uint8_t instanceId = CSIRX_INST_ID_FIRST;
772 #else
773     uint8_t instanceId = CSIRX_INST_ID_LAST;
774 #endif
775     char instName[25];
777     printf("\n**********************************************\n");
778     printf  ("*                CSI-Rx Test                 *\n");
779     printf  ("**********************************************\n");
781     CSIRX_getInstanceName(instanceId, &instName[0], sizeof(instName));
783     printf("Receiving data from CSIRX instance #%d: %s\n", instanceId,
784                  instName);
786     result = BoardDiag_CsirxTestRun(instanceId);
787     if(result != true)
788     {
789         printf("Failed to receive data from CSIRX instance #%d\n",
790                     instanceId);
791         return -1;
792     }
793     else
794     {
795         printf("CSIRX diag test passed\n");
796     }
797     printf("csirx test finished\n");
799     return 0;
803 /**
804  *  \brief   CSIRX Diagnostic test main function
805  *
806  *  \return  int - CSIRX Diagnostic test status.
807  *             0 - in case of success
808  *            -1 - in case of failure.
809  *
810  */
811 int main (void)
813     Board_STATUS status;
814     Board_initCfg boardCfg;
816 #ifdef USE_BIOS
817     Task_Handle task;
818     Error_Block eb;
820     Error_init(&eb);
821     task = Task_create((Task_FuncPtr)BoardDiag_CsirxTest, NULL, &eb);
822     if (task == NULL) {
823         System_printf("Task_create() failed!\n");
824         BIOS_exit(0);
825     }
826 #else
827     int8_t ret;
828 #endif
830 #ifdef PDK_RAW_BOOT
831     boardCfg = BOARD_INIT_MODULE_CLOCK |
832                BOARD_INIT_PINMUX_CONFIG |
833                BOARD_INIT_UART_STDIO;
834 #else
835     boardCfg = BOARD_INIT_PINMUX_CONFIG | BOARD_INIT_UART_STDIO | BOARD_INIT_MODULE_CLOCK;
836 #endif
838     status = Board_init(boardCfg);
839     if(status != BOARD_SOK)
840     {
841         return -1;
842     }
844 #ifdef USE_BIOS
845     /* Start BIOS */
846     BIOS_start();
847 #else
848     ret = BoardDiag_CsirxTest();
849     if(ret != 0)
850     {
851         printf("\nCSIRX Test Failed\n");
852         return -1;
853     }
854     else
855     {
856         printf("\nCSIRX Test Passed\n");
857     }
858 #endif
860     return 0;