rl_driver.c
1 /****************************************************************************************
2  * FileName : rl_driver.c
3  *
4  * Description : This file implements the mmwave radar Host Communication
5  * Protocol
6  *
7  ****************************************************************************************
8  * (C) Copyright 2014, Texas Instruments Incorporated. - TI web address www.ti.com
9  *---------------------------------------------------------------------------------------
10  *
11  * Redistribution and use in source and binary forms, with or without modification,
12  * are permitted provided that the following conditions are met:
13  *
14  * Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  *
17  * Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  *
21  * Neither the name of Texas Instruments Incorporated nor the names of its
22  * contributors may be used to endorse or promote products derived from this
23  * software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38  /*
39  ****************************************************************************************
40  * Revision History :
41  *---------------------------------------------------------------------------------------
42  * Version Date Author Defect No Description
43  *---------------------------------------------------------------------------------------
44  * 0.1.0 12May2015 Kaushal Kukkar - Initial Version
45  *
46  * 0.5.2 23Sep2016 Kaushal Kukkar AUTORADAR-541 xWR1642 Support
47  *
48  * 0.6.0 15Nov2016 Kaushal Kukkar AUTORADAR-666 Logging Feature
49  * Kaushal Kukkar AUTORADAR-716 Cascade API change
50  *
51  * 0.7.0 11May2017 Kaushal Kukkar MMWSDK-362 LDRA static analysis Issue Fix
52  *
53  * 0.8.6 24Jul2017 Jitendra Gupta MMWL-25 Support for 2K Message size
54  * Kaushal Kukkar MMWL-23 Big Endian Support
55  *
56  * 0.9.1 - Jitendra Gupta MMWL-5 Code size optimization
57  *
58  * 1.2.2 14Feb2019 Pavan Penikalapati MMWL-159 Fixed log prints in rlDeviceAddDevices
59  *
60  * 1.2.5.15 15Jul2019 Pavan Penikalapati MMWL-217 Flush mechanism fix, when SYNC for ACK
61  * corrupted.
62  ****************************************************************************************
63  */
64 
65 /******************************************************************************
66  * INCLUDE FILES
67  ******************************************************************************
68  */
69 #include <stdlib.h>
70 #include <string.h>
71 #include <ti/control/mmwavelink/mmwavelink.h>
72 #include <ti/control/mmwavelink/include/rl_driver.h>
73 #include <ti/control/mmwavelink/include/rl_messages.h>
74 #include <ti/control/mmwavelink/include/rl_controller.h>
75 #include <ti/control/mmwavelink/include/rl_protocol.h>
76 #include <ti/control/mmwavelink/include/rl_trace.h>
77 
78 /****************************************************************************************
79 * MACRO DEFINITIONS
80 ****************************************************************************************
81 */
82 /* Check if Interrupt is pending */
83 #define RL_PENDING_RX_MSG(driverData, index) \
84  (((driverData)->rxIrqCnt[(index)]) != ((driverData)->rxDoneCnt[(index)]))
85 
86 /* mmwave radar Communication Interface Read/Write */
87 #define RL_IF_WRITE(fd,pBuff,len) \
88  rl_driverData.clientCtx.comIfCb.rlComIfWrite((fd),(pBuff),(len))
89 #define RL_IF_READ(fd,pBuff,len) \
90  rl_driverData.clientCtx.comIfCb.rlComIfRead((fd),(pBuff),(len))
91 
92 
93 /* mmwave radar Communication Interface Read/Write Error Check */
94 #define RL_IF_WRITE_CHECK(fd,pBuff,len) \
95  {\
96  if (((rlInt32_t)(len)) != RL_IF_WRITE((fd), (pBuff), (len)))\
97  {\
98  return RL_RET_CODE_RADAR_IF_ERROR;\
99  }\
100  }
101 #define RL_IF_READ_CHECK(fd,pBuff,len) \
102  {\
103  if (((rlInt32_t)(len)) != RL_IF_READ((fd), (pBuff), (len)))\
104  {\
105  return RL_RET_CODE_RADAR_IF_ERROR;\
106  }\
107  }
108 
109 /* MAX Retry of SYNC Match */
110 #define RL_SYNC_SCAN_THRESHOLD (252U)
111 
112 /* mmWaveLink Header Opcode Class */
113 #define RL_RHCP_HDR_OPCODE_CLASS(ptr) \
114  (rlUInt8_t) (((rlProtHeader_t *)(ptr))->opcode.b2MsgType)
115 
116 /* mmWaveLink Header Payload */
117 #define RL_RHCP_HDR_PL_LENGTH(ptr) (((rlProtHeader_t *)(ptr))->len)
118 
119 #define PATTERN_NOT_MATCHED ((rlInt32_t)0x0)
120 #define SYNC_PATTERN_MATCHED ((rlInt32_t)0x1)
121 #define CNYS_PATTERN_MATCHED ((rlInt32_t)0x2)
122 
123 /* Protocol SYNC Patterns */
124 #define D2H_SYNC_PATTERN_1 (0xDCBAU)
125 #define D2H_SYNC_PATTERN_2 (0xABCDU)
126 #define H2D_SYNC_PATTERN_1 (0x1234U)
127 #define H2D_SYNC_PATTERN_2 (0x4321U)
128 #define H2D_CNYS_PATTERN_1 (0x5678U)
129 #define H2D_CNYS_PATTERN_2 (0x8765U)
130 
131 /******************************************************************************
132  * GLOBAL VARIABLES/DATA-TYPES DEFINITIONS
133  ******************************************************************************
134  */
135 
136 /* mmwave radar Driver global structure */
137 #ifdef ccs
138 #pragma DATA_ALIGN(rl_driverData, 4);
139 #endif
140 static rlDriverData_t rl_driverData = {0};
141 
142 /* mmwave radar Driver Command/Response Buffer */
143 #ifdef ccs
144 #pragma DATA_ALIGN(rl_txMsg, 8);
145 #endif
146 rlRhcpMsg_t rl_txMsg[RL_CASCADE_NUM_DEVICES] = {0};
147 #ifdef ccs
148 #pragma DATA_ALIGN(rl_rxMsg, 8);
149 #endif
150 rlRhcpMsg_t rl_rxMsg[RL_CASCADE_NUM_DEVICES] = {0};
151 
152 /******************************************************************************
153  * FUNCTION PROTOTYPES
154  ******************************************************************************
155  */
156 static rlReturnVal_t rlDriverOriginDirCheck(rlUInt8_t deviceRunId, rlUInt8_t dataDir);
157 static rlUInt8_t rlDriverReceiveSync(rlComIfHdl_t comIfHdl, rlUInt8_t syncBuf[],
158  rlInt32_t *syncType);
159 static rlReturnVal_t rlDriverClientCbCheck(rlClientCbs_t clientCb);
160 static rlReturnVal_t rlDriverOsiCbCheck(rlClientCbs_t clientCb);
161 static rlReturnVal_t rlDriverCmdWriter(rlUInt8_t devIndex, rlDriverMsg_t* outMsg);
162 
163 
164 /******************************************************************************
165  * FUNCTION DEFINITIONS
166  ******************************************************************************
167  */
168 
176 /* SourceId : */
177 /* DesignId : */
178 /* Requirements : */
179 void rlDriverShiftDWord(rlUInt8_t buf[])
180 {
181  rlUInt8_t shiftIdx;
182 
183  /* shift each byte in recevied byte array */
184  for (shiftIdx = 0U; shiftIdx < 7U; shiftIdx++)
185  {
186  /* overwritting each data byte with next data byte of array */
187  buf[shiftIdx] = buf[shiftIdx + 1U];
188  }
189 
190  /* set last byte to zero */
191  buf[7U] = 0U;
192 }
193 
207 /* DesignId : */
208 /* Requirements : AUTORADAR_REQ-774 */
209 rlReturnVal_t rlDriverCalCRC(rlUInt8_t* data, rlUInt16_t dataLen,
210  rlUInt8_t crcType, rlUInt8_t crc[RL_CRC_LEN_MAX])
211 {
212  rlReturnVal_t retVal;
213 
214  RL_LOGV_ARG0("rlDriverCalCRC starts...\n");
215 
216  /* check if API is defined by the application during powerOn */
217  if (rl_driverData.clientCtx.crcCb.rlComputeCRC != NULL)
218  {
219  /* compute CRC on given data */
220  retVal = rl_driverData.clientCtx.crcCb.rlComputeCRC(data, dataLen, crcType, &crc[0U]);
221  }
222  else
223  {
224  /* set error code if CRC compute API is not set by Application */
225  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
226  }
227  RL_LOGV_ARG0("rlDriverCalCRC ends...\n");
228 
229  return retVal;
230 }
231 
246 /* DesignId : */
247 /* Requirements : AUTORADAR_REQ-780 */
248 rlReturnVal_t rlDriverVerifyCRC(rlUInt8_t* data, rlUInt16_t dataLen,
249  rlUInt8_t crcType, rlUInt8_t crc[RL_CRC_LEN_MAX])
250 {
251  rlUInt8_t indx;
252  rlUInt8_t crcByte[RL_CRC_LEN_MAX];
253  rlReturnVal_t retVal = RL_RET_CODE_OK;
254 
255  RL_LOGV_ARG0("rlDriverVerifyCRC starts...\n");
256 
257  /* compute CRC on given data */
258  if (RL_RET_CODE_OK != rl_driverData.clientCtx.crcCb.rlComputeCRC(data, dataLen, \
259  crcType, &crcByte[0U]))
260  {
261  /* set error code if CRC callback returns non-zero */
262  retVal += RL_RET_CODE_RADAR_IF_ERROR;
263  }
264  else
265  {
266  /* compare computed and received CRC value */
267  for (indx = 0U; indx < (2U << crcType); indx++)
268  {
269  if (crcByte[indx] != crc[indx])
270  {
271  /* set error code if computed and received CRC value mismatched */
272  retVal += RL_RET_CODE_CRC_FAILED;
273  break;
274  }
275  }
276  }
277  RL_LOGV_ARG0("rlDriverVerifyCRC ends...\n");
278 
279  return retVal;
280 }
281 
294 /* DesignId : */
295 /* Requirements : AUTORADAR_REQ-774, AUTORADAR_REQ-777 */
296 rlReturnVal_t rlDriverCalChkSum(rlProtHeader_t* hdrData, rlUInt8_t len,
297  rlUInt16_t* checksum)
298 {
299  /* TBD - MISRA compliant Checksum code */
300  rlUInt32_t checkSumVal = 0U;
301  rlUInt8_t *localGenHdr = (rlUInt8_t *)hdrData;
302  rlReturnVal_t retVal;
303 
304  RL_LOGV_ARG0("rlDriverCalChkSum starts...\n");
305 
306  /* if received data pointer is not NULL */
307  if (localGenHdr != RL_NULL_PTR)
308  {
309  /* if length is 2 or more bytes */
310  while (len > 1U)
311  {
312  /* AR_CODE_REVIEW MR:R.11.2 <APPROVED> "Pointer conversion
313  * from data array
314  * to calculate Checksum" */
315  /*LDRA_INSPECTED 94 S */
316  /*LDRA_INSPECTED 95 S */
317  checkSumVal += *((rlUInt16_t*) localGenHdr);
318  localGenHdr += 2U;
319 
320  /* If high order bit set, fold */
321  if ((checkSumVal & 0x80000000U) != 0U)
322  {
323  checkSumVal = (checkSumVal & 0xFFFFU) + (checkSumVal >> 16U);
324  }
325  /* decrement length by 2 as checkSum is calculated on each 2 bytes */
326  len -= 2U;
327  }
328  /* Take care of left over byte */
329  if (len > 0U)
330  {
331  checkSumVal += (rlUInt32_t) (*((rlUInt8_t *)localGenHdr));
332  }
333  /* Add all half words to calcuated SUM */
334  while ((checkSumVal >> 16U) != 0U)
335  {
336  checkSumVal = (checkSumVal & 0xFFFFU) + (checkSumVal >> 16U);
337  }
338  RL_LOGV_ARG1("Final checksum 0x%X\n", *checksum);
339 
340  /* Calculate Checksum as compliment of the SUM */
341  *(checksum) = (rlUInt16_t)~checkSumVal;
342  retVal = RL_RET_CODE_OK;
343  }
344  else
345  {
346  retVal = RL_RET_CODE_FATAL_ERROR;
347  }
348 
349  RL_LOGV_ARG0("rlDriverCalChkSum ends...\n");
350 
351  return retVal;
352 }
353 
354 
364 /* DesignId : */
365 /* Requirements : AUTORADAR_REQ-777 */
366 rlReturnVal_t rlDriverValidateHdr(rlProtHeader_t protHdr)
367 {
368  rlReturnVal_t retVal;
369  rlUInt16_t checkSum = 0U;
370 
371  /* Calculate checksum*/
372  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Checksum is getting updated in called function" */
373  /*LDRA_INSPECTED 8 D */
374  if (RL_RET_CODE_OK != rlDriverCalChkSum(&protHdr, ((rlUInt8_t)(RHCP_HEADER_LEN - 2U)),
375  &checkSum))
376  {
377  /* Set error code if checksum callback returns non-zero value */
378  retVal = RL_RET_CODE_RADAR_IF_ERROR;
379  }
380  else
381  {
382  /* Compare calcualted and received checksum*/
383  if (protHdr.chksum != checkSum)
384  {
385  /* Checksum doesn't match, return error*/
386  retVal = RL_RET_CODE_CHKSUM_FAILED;
387  RL_LOGE_ARG0("Checksum validation failed for header\n");
388  }
389  else
390  {
391  /* checksum successfully matched */
392  RL_LOGD_ARG0("Checksum validation is successful\n");
393  retVal= RL_RET_CODE_OK;
394  }
395  }
396 
397  return retVal;
398 }
399 
410 /* DesignId : */
411 /* Requirements : */
412 rlUInt8_t rlDeviceIdentifyCmdDir(rlUInt16_t msgId, rlUInt8_t platform)
413 {
414  rlUInt8_t cmdDir;
415 
416  RL_LOGV_ARG0("rlDeviceIdentifyCmdDir starts...\n");
417 
418  /* if MsgId is for radarSS */
419  if ((RL_RF_RESP_ERROR_MSG < msgId) && (RL_RF_ASYNC_EVENT_MSG > msgId))
420  {
421  /* if mmWaveLink is running on MSS */
422  if (RL_PLATFORM_MSS == platform)
423  {
424  cmdDir = RL_API_DIR_MSS_TO_BSS;
425  }
426  /* if mmWaveLink is running on Host */
427  else if (RL_PLATFORM_HOST == platform)
428  {
429  cmdDir = RL_API_DIR_HOST_TO_BSS;
430  }
431  /* if mmWaveLink is running on DSS */
432  else
433  {
434  cmdDir = RL_API_DIR_DSS_TO_BSS;
435  }
436  RL_LOGV_ARG1("cmdDir for radarSS = %d (1:host2Bss, 10:dss2Bss, 8:mss2bss)\n",\
437  cmdDir);
438  }
439  /* if MsgId is for MSS */
440  else if ((RL_DEV_POWERUP_MSG <= msgId) && (RL_DEV_ASYNC_EVENT_MSG > msgId))
441  {
442  /* if mmWaveLink is running on Host */
443  if (RL_PLATFORM_HOST == platform)
444  {
445  /* MsgId for MSS need not send to MSS itself */
446  cmdDir = RL_API_DIR_HOST_TO_MSS;
447  }
448  else
449  {
450  /* If MSS wants to configure these MsgID to DSS */
451  cmdDir = RL_API_DIR_MSS_TO_DSS;
452  }
453  RL_LOGV_ARG1("cmdDir for MSS = %d (5:host2Mss, 12:dss2Mss)\n", cmdDir);
454  }
455  /* if msgId is for DSS */
456  else if ((RL_DSP_RESERVED0_MSG <= msgId) && (RL_DSP_ASYNC_EVENT_MSG > msgId))
457  {
458  /* MsgId for DSS need not send to DSS itself */
459 
460  /* if mmWaveLink is running on MSS */
461  if (RL_PLATFORM_MSS == platform)
462  {
463  /* set direction MSS_TO_DSS */
464  cmdDir = RL_API_DIR_MSS_TO_DSS;
465  }
466  /* if mmWaveLink is running on Host */
467  else
468  {
469  /* set direction HOST_TO_DSS */
470  cmdDir = RL_API_DIR_HOST_TO_DSS;
471  }
472  RL_LOGV_ARG1("cmdDir for DSS = %d (11:Mss2Dss, 3:hostDss)\n", cmdDir);
473  }
474  else
475  {
476  /* set direction INVALID */
477  cmdDir = RL_API_DIR_INVALID;
478  RL_LOGE_ARG1("rlDeviceIdentifyCmdDir: Invalid cmd, platform: [%d]\n", platform);
479  }
480  RL_LOGV_ARG0("rlDeviceIdentifyCmdDir ends...\n");
481 
482  return cmdDir;
483 }
484 
498 /* DesignId : */
499 /* Requirements : AUTORADAR_REQ-783 */
500 rlReturnVal_t rlDriverAsyncEventHandler(rlUInt8_t devIndex,
501  rlUInt16_t nsbc, rlUInt8_t *payload,
502  rlUInt16_t payloadLen)
503 {
504  rlUInt16_t indx;
505  rlUInt16_t sbLen = 0U;
506  rlUInt16_t sbcId = 0U;
507  rlUInt16_t recSbsLen = 0U;
508  rlReturnVal_t retVal = RL_RET_CODE_OK;
509  rlUInt8_t *payldAddr = payload;
510 
511  RL_LOGV_ARG0("rlDriverAsyncEventHandler starts...\n");
512 
513  /* Lood for all the Events Sub Block and call event handler */
514  for (indx = 0U; indx < nsbc; indx++)
515  {
516  /* check for payload pointer for NULL */
517  if ((payldAddr == RL_NULL_PTR) || (recSbsLen > payloadLen))
518  {
519  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Error value set on top of default value" */
520  /*LDRA_INSPECTED 8 D */
521  retVal = RL_RET_CODE_FATAL_ERROR;
522  break;
523  }
524  /* Read Sub Block Id */
525  rlGetSubBlockId(payldAddr, &sbcId);
526 
527  /* Read Sub Block Len */
528  rlGetSubBlockLen(payldAddr, &sbLen);
529 
530  /* Call Application registered callback to indicate event*/
531  if (RL_NULL_PTR != rl_driverData.clientCtx.eventCb.rlAsyncEvent)
532  {
533  /* Call event handler and pass event payload */
534  /* AR_CODE_REVIEW MR:R.18.1,R.18.4 <APPROVED> "pointer arithmetic required" */
535  /*LDRA_INSPECTED 567 S */
536  /*LDRA_INSPECTED 87 S */
537  rl_driverData.clientCtx.eventCb.rlAsyncEvent(devIndex, sbcId, \
538  ((rlUInt16_t)(sbLen - RL_MIN_SBC_LEN)),\
539  (payldAddr + RL_SBC_PL_INDEX));
540  /* Increase received payload length*/
541  recSbsLen += (sbLen);
542 
543  /* increment payload address */
544  payldAddr += sbLen;
545  }
546  }
547  RL_LOGV_ARG0("rlDriverAsyncEventHandler ends...\n");
548 
549  return retVal;
550 }
551 
563 /* DesignId : */
564 /* Requirements : AUTORADAR_REQ-777 */
565 void rlDriverHostIrqHandler(rlUInt8_t deviceIndex, void *pValue)
566 {
567  rlUInt8_t tempVar;
568  /* get rlDriver global structure pointer */
569  rlDriverData_t* rlDrvData = rlDriverGetHandle();
570 
571  RL_LOGDB_ARG1("Device [%d] Host IRQ High\r", deviceIndex);
572  RL_LOGV_ARG0("rlDriverHostIrqHandler starts...\n");
573 
574  /* check for NULL pointer */
575  if (pValue == RL_NULL_PTR)
576  {
577  /* No Argument Passed */
578  RL_LOGD_ARG0("rlDriverHostIrqHandler Input arg is NULL\n");
579  }
580 
581  /* Mask the Interrupt - Required if interrupt is Level triggered*/
582  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData is pointer to a global strcture,
583  can't be NULL" */
584  /*LDRA_INSPECTED 45 D */
585  if ((RL_NULL_PTR != rlDrvData->clientCtx.devCtrlCb.rlDeviceMaskHostIrq)\
586  && ((rlComIfHdl_t)RL_NULL_PTR != rlDrvData->commDevIdx.comIfHdl[deviceIndex]))
587  {
588  /* Mask Host IRQ */
589  rlDrvData->clientCtx.devCtrlCb.rlDeviceMaskHostIrq((rlComIfHdl_t) \
590  rlDrvData->commDevIdx.comIfHdl[deviceIndex]);
591  RL_LOGD_ARG0("rlDriverHostIrqHandler Mask the Interrupt\n");
592  }
593 
594  /* Increment the Irq count*/
595  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "storing incremented value to global structure" */
596  /*LDRA_INSPECTED 105 D */
597  rlDrvData->rxIrqCnt[deviceIndex] = (rlDrvData->rxIrqCnt[deviceIndex] + 1U);
598 
599  /* store deviceIndex in Global */
600  rlDrvData->commDevIdx.rlDevIndex[deviceIndex] = deviceIndex;
601 
602  tempVar = (rlDrvData->isCmdRespWaited[deviceIndex] | \
603  rlDrvData->isRespWriteWaited[deviceIndex]);
604  /* Check if command transaction is in progress*/
605  if (RL_TRUE == tempVar)
606  {
607  /* Release command response wait semaphore to unblock command thread*/
608  (void)rlDrvData->clientCtx.osiCb.sem.rlOsiSemSignal(
609  &rlDrvData->cmdSem[deviceIndex]);
610  RL_LOGD_ARG0("rlDriverHostIrqHandler Release command response \n");
611  }
612  else
613  {
614  /* No response is expected, Add to the Spawn queue to be hanled
615  * in different context*/
616  (void)rlDrvData->clientCtx.osiCb.queue.rlOsiSpawn(
617  (RL_P_OSI_SPAWN_ENTRY)rlDriverMsgReadSpawnCtx,
618  &rlDrvData->commDevIdx.rlDevIndex[deviceIndex], 0);
619  RL_LOGD_ARG0("rlDriverHostIrqHandler No response is expected \n");
620  }
621 
622  RL_LOGV_ARG0("rlDriverHostIrqHandler ends...\n");
623 
624  return;
625 }
626 
637 rlReturnVal_t rlDriverProcRdMsg(rlUInt8_t devIdx, rlReturnVal_t inVal)
638 {
639  /* get rlDriver global structure pointer */
640  rlDriverData_t* rlDrvData = rlDriverGetHandle();
641  rlReturnVal_t retVal;
642 
643  /* Increment IRQ done IR*/
644  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData is pointer to a global strcture,
645  can't be NULL" */
646  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "storing incremented value to global structure" */
647  /*LDRA_INSPECTED 105 D */
648  /*LDRA_INSPECTED 45 D */
649  rlDrvData->rxDoneCnt[devIdx] = (rlDrvData->rxDoneCnt[devIdx] + 1U);
650 
651  /* Check received message class*/
652  switch (rlDrvData->funcParams[devIdx].rxMsgClass)
653  {
654  case RL_API_CLASS_ASYNC:
655  /* If CRC check passed then only parse Async Event */
656  if (inVal == RL_RET_CODE_OK)
657  {
658  /* parse received Async Event Message */
659  /*LDRA_INSPECTED 95 S */
660  retVal = rlDriverAsyncEventHandler(devIdx,\
661  rlDrvData->funcParams[devIdx].asyncEvt.evtMsg.hdr.nsbc,\
662  (rlUInt8_t *)&rlDrvData->funcParams[devIdx].asyncEvt.evtMsg.payload[0],\
663  (rlUInt16_t)(rlDrvData->funcParams[devIdx].asyncEvt.evtMsg.hdr.len - \
664  RHCP_HEADER_LEN));
665  }
666  else
667  {
668  rlUInt16_t errPayload[RL_MIN_SBC_LEN + 4U];
669  /* Generate local payload containing [SBID+SBLEN+error value] */
670  errPayload[0] = ((RL_MMWL_ASYNC_EVENT_MSG * RL_MAX_SB_IN_MSG) +\
671  RL_MMWL_AE_MISMATCH_REPORT);
672  errPayload[1] = (RL_MIN_SBC_LEN + 4U);
673 
674  /* Copy last return value[error] to payload of this async event msg */
675  (void)memcpy(&errPayload[2], (rlUInt8_t*) &inVal, sizeof(rlReturnVal_t));
676 
677  /* Send error Async Event message to application containing error value */
678  /* AR_CODE_REVIEW MR:R.10.3 <INSPECTED> "All param types are matching to function
679  argument type. LDRA tool issue." */
680  /*LDRA_INSPECTED 458 S */
681  retVal = rlDriverAsyncEventHandler(devIdx, 1U,\
682  (rlUInt8_t *)&errPayload[0],\
683  (rlUInt16_t)(RL_MIN_SBC_LEN + 4U));
684  }
685  break;
686  case RL_API_CLASS_NACK:
687  /* These types are legal in this context. Do nothing */
688  retVal = RL_RET_CODE_OK;
689  break;
690  case RL_API_CLASS_RSP:
691  /* Command response is illegal in this context. */
692  retVal = RL_RET_CODE_OK;
693  break;
694  /* if mmWaveLink is running on MSS/DSS and receives command from other Core/HOST */
695  case RL_API_CLASS_CMD:
696  case RL_API_CLASS_BYPASS:
697  {
698  /* Check if command parser API callback is assigned by the application */
699  if (rl_driverData.clientCtx.cmdParserCb.rlCmdParser != RL_NULL_PTR)
700  {
701  /* invoke callback to parse the received command packet */
702  (void)rl_driverData.clientCtx.cmdParserCb.rlCmdParser(
703  rlDrvData->funcParams[devIdx].rxMsgClass, inVal);
704  }
705  else
706  {
707  /* do nothing */
708  }
709  retVal = RL_RET_CODE_OK;
710  }
711  break;
712  case RL_API_CLASS_MAX:
713  /* do nothing */
714  retVal = RL_RET_CODE_OK;
715  break;
716  default:
717  /* set error code */
718  retVal = RL_RET_CODE_PROTOCOL_ERROR;
719  RL_LOGE_ARG0("rlDriverProcRdMsg, Rl protocol error\n");
720  break;
721  }
722 
723  return retVal;
724 }
725 
735 /* DesignId : */
736 /* Requirements : AUTORADAR_REQ-782, AUTORADAR_REQ-1038 */
737 rlReturnVal_t rlDriverMsgReadSpawnCtx(const void *pValue)
738 {
739  rlReturnVal_t retVal, msgRdRetVal;
740  rlUInt8_t deviceIndex;
741  rlUInt8_t lclRxIrqCnt, lclRxDoneCnt;
742  /* get rlDriver global structure pointer */
743  rlDriverData_t* rlDrvData = rlDriverGetHandle();
744 
745  RL_LOGV_ARG0("rlDriverMsgReadSpawnCtx starts...\n");
746 
747  /* check for NULL pointer */
748  if (pValue == RL_NULL_PTR)
749  {
750  /* No Argument Passed */
751  deviceIndex = 0U;
752  RL_LOGE_ARG0("rlDriverMsgReadSpawnCtx Input arg is NULL\n");
753  }
754  else
755  {
756  /* argument passed is Device Index */
757  deviceIndex = *(const rlUInt8_t*)pValue;
758  }
759 
760  /* This function pointer is always being checked on powerOn and mmwavelink
761  fails poweron with error return value, in this failure case no API call is allowed */
762 
763  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData is pointer to a global strcture,
764  can't be NULL" */
765  /*LDRA_INSPECTED 45 D */
766  if (RL_RET_CODE_OK != rlDrvData->clientCtx.osiCb.mutex.rlOsiMutexLock
767  (&rlDrvData->devMutex[deviceIndex], (rlOsiTime_t)RL_OSI_WAIT_FOREVER))
768  {
769  rlUInt16_t errPayload[RL_MIN_SBC_LEN + 4U];
770  rlReturnVal_t inVal;
771  rlReturnVal_t* ptrData;
772 
773  /* Generate local payload containing [SBID+SBLEN+error value] */
774  errPayload[0] = ((RL_MMWL_ASYNC_EVENT_MSG * RL_MAX_SB_IN_MSG) +\
775  RL_MMWL_AE_INTERNALERR_REPORT);
776  errPayload[1] = (RL_MIN_SBC_LEN + 4U);
777 
778  /* If MutexLock returns non-zero then treat this as error and set error code to inVal */
779  inVal = RL_RET_CODE_RADAR_OSIF_ERROR;
780 
781  ptrData = &inVal;
782  if (RL_NULL_PTR != ptrData)
783  {
784  /* Copy last return value[error] to payload of this async event msg */
785  /* AR_CODE_REVIEW MR:R.21.17 <INSPECTED> "Local variable and array can't be null.
786  LDRA tool issue." */
787  /*LDRA_INSPECTED 140 D */
788  (void)memcpy((void*)&errPayload[2], (void*)ptrData, sizeof(rlReturnVal_t));
789  }
790 
791  /* Send error Async Event message to application containing error value */
792  /* AR_CODE_REVIEW MR:R.10.3 <INSPECTED> "All param types are matching to function
793  argument type. LDRA tool issue." */
794  /*LDRA_INSPECTED 458 S */
795  retVal = rlDriverAsyncEventHandler(deviceIndex, 1U,\
796  (rlUInt8_t *)&errPayload[0],\
797  (rlUInt16_t)(RL_MIN_SBC_LEN + 4U));
798  }
799  else
800  {
801  /* Messages might have been read by CmdResp context. Therefore after getting LockObj,
802  check again where the Pending Rx Msg is still present. */
803  lclRxIrqCnt = rlDrvData->rxIrqCnt[deviceIndex];
804  lclRxDoneCnt = rlDrvData->rxDoneCnt[deviceIndex];
805 
806  /* unlock Mutex if all Received IRQ are handled i.e. DONE */
807  if (lclRxIrqCnt == lclRxDoneCnt)
808  {
809  (void)rlDrvData->clientCtx.osiCb.mutex.rlOsiMutexUnLock(
810  &rlDrvData->devMutex[deviceIndex]);
811  RL_LOGD_ARG0("rlDriverMsgReadSpawnCtx, RxIrqCnt is equal to RxDoneCnt\n");
812  retVal = RL_RET_CODE_OK;
813  }
814  else
815  {
816  /* Receive data over communication channel*/
817  /* AR_CODE_REVIEW MR:D.4.7,R.17.7 <APPROVED> "variable is used in next function
818  call" */
819  /*LDRA_INSPECTED 91 D */
820  msgRdRetVal = rlDriverMsgRead(rlDrvData, deviceIndex);
821  /* process received message */
822  retVal = rlDriverProcRdMsg(deviceIndex, msgRdRetVal);
823 
824  /* Unlock Global Mutex */
825  (void)rlDrvData->clientCtx.osiCb.mutex.rlOsiMutexUnLock
826  (&rlDrvData->devMutex[deviceIndex]);
827  }
828  }
829  RL_LOGV_ARG0("rlDriverMsgReadSpawnCtx ends...\n");
830 
831  return retVal;
832 }
833 
846 rlReturnVal_t rlDriverMsgCmdReply(rlDriverData_t* rlDrvData, rlUInt8_t devIndex)
847 {
848  rlReturnVal_t retVal, retStatus;
849  rlUInt8_t tempVar;
850 
851  RL_LOGV_ARG0("rlDriverMsgCmdReply starts...\n");
852 
853  /* Receive data over communication channel */
854  retStatus = rlDriverMsgRead(rlDrvData, devIndex);
855 
856  /* Data received successfully */
857  rlDrvData->rxDoneCnt[devIndex]++;
858 
859  if (RL_RET_CODE_OK != (rlInt32_t)retStatus)
860  {
861  /* If Async event message has some issue then notify to the
862  * application with the error value */
863  if (RL_API_CLASS_ASYNC == rlDrvData->funcParams[devIndex].rxMsgClass)
864  {
865  rlUInt16_t errPayload[RL_MIN_SBC_LEN + 4U];
866  /* Generate local payload with [SBID+SBLEN+Error_value] */
867  errPayload[0] = ((RL_MMWL_ASYNC_EVENT_MSG * RL_MAX_SB_IN_MSG) +\
868  RL_MMWL_AE_MISMATCH_REPORT);
869  errPayload[1] = (RL_MIN_SBC_LEN + 4U);
870 
871  (void)memcpy(&errPayload[2], (rlUInt8_t*)&retStatus, sizeof(rlReturnVal_t));
872 
873  /* Send error Async Event message to application containing error value */
874  /* AR_CODE_REVIEW MR:R.10.3 <INSPECTED> "All param types are matching to function
875  argument type. LDRA tool issue." */
876  /*LDRA_INSPECTED 458 S */
877  (void)rlDriverAsyncEventHandler(devIndex, 1U,\
878  (rlUInt8_t *)&errPayload[0],\
879  (rlUInt16_t)(RL_MIN_SBC_LEN + 4U));
880 
881  if (retStatus == RL_RET_CODE_CRC_FAILED)
882  {
883  /* In case CRC failed for the actual async event
884  then in the CMD context wait for response msg */
885  retStatus = RL_RET_CODE_OK;
886  }
887  }
888 
889  /* Error in received data, return error */
890  retVal = retStatus;
891  RL_LOGE_ARG0("Error in received data\n");
892  }
893  else
894  {
895  /* Check received message class */
896  if (RL_API_CLASS_RSP == rlDrvData->funcParams[devIndex].rxMsgClass)
897  {
898  /* Command response received, clear the Wait flag to exit loop */
899  tempVar = RL_FALSE;
900  rlDrvData->isCmdRespWaited[devIndex] = tempVar;
901 
902  /* check if received msg-ID doesn't match with CMD msg-ID */
903  if (rl_rxMsg[devIndex].hdr.opcode.b10MsgId != rl_txMsg[devIndex].hdr.opcode.b10MsgId)
904  {
905  /* set error code if MsgId of response doesn't match with CMD msg ID */
906  retVal = RL_RET_CODE_MSGID_MISMATCHED;
907  RL_LOGE_ARG0("Msg id is mis-matched\n");
908  }
909  else
910  {
911  if (rl_rxMsg[devIndex].hdr.flags.b4SeqNum != rl_txMsg[devIndex].hdr.flags.b4SeqNum)
912  {
913  retVal = RL_RET_CODE_RX_SEQ_NUM_NOT_MATCH;
914  RL_LOGV_ARG0("ACK sequence number is not matching with CMD sequence number\n");
915  }
916  else
917  {
918  /* response sequence number matches with CMD sequence number */
919  retVal = RL_RET_CODE_OK;
920  }
921  }
922 
923  /* In case CmdResp has been read without waiting on cmdSem that */
924  /* Sem object. That to prevent old signal to be processed. */
925  /* Clear the Semaphore */
926  rlDrvData->clientCtx.osiCb.sem.rlOsiSemWait
927  (&(rlDrvData->cmdSem[devIndex]), (rlOsiTime_t)RL_OSI_NO_WAIT);
928  }
929  else if (RL_API_CLASS_ASYNC == rlDrvData->funcParams[devIndex].rxMsgClass)
930  {
931  /* Async event received when command response is awaited,
932  Handle the event and keep waiting for the response*/
933  /* AR_CODE_REVIEW MR:R.10.3 <APPROVED> "All parameter types are matching to function
934  argument type. LDRA tool issue." */
935  /*LDRA_INSPECTED 458 S */
936  /*LDRA_INSPECTED 95 S */
937  (void)rlDriverAsyncEventHandler(devIndex, \
938  rlDrvData->funcParams[devIndex].asyncEvt.evtMsg.hdr.nsbc, \
939  (rlUInt8_t *)&rlDrvData->funcParams[devIndex].asyncEvt.evtMsg.payload[0],
940  (rlUInt16_t)(rlDrvData->funcParams[devIndex].asyncEvt.evtMsg.hdr.len - \
941  RHCP_HEADER_LEN));
942  retVal = RL_RET_CODE_OK;
943 
944  /* If CRC check fails, the Async Event is Ignored */
945  }
946  else if (RL_API_CLASS_NACK == rlDrvData->funcParams[devIndex].rxMsgClass)
947  {
948  /* If NACK received for the CMD sent, set CMD Response Wait TAG to FALSE */
949  tempVar = RL_FALSE;
950  rlDrvData->isCmdRespWaited[devIndex] = tempVar;
951  /* set error code to CRC Failed */
952  retVal = RL_RET_CODE_NACK_ERROR;
953  RL_LOGE_ARG0("CMD CRC check fails, device sends NACK\n");
954  }
955  else
956  {
957  /* Invalid Class*/
958  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
959  RL_LOGE_ARG0("Invalid Class\n");
960  }
961  }
962  RL_LOGV_ARG0("rlDriverMsgCmdReply ends...\n");
963 
964  return retVal;
965 }
966 
967 
978 /* DesignId : MMWL_DesignId_102 */
979 /* Requirements : AUTORADAR_REQ-782, AUTORADAR_REQ-1038 */
980 rlReturnVal_t rlDriverMsgReadCmdCtx(rlUInt8_t devIndex)
981 {
982  rlReturnVal_t retVal;
983  rlDriverData_t* rlDrvData = rlDriverGetHandle();
984 
985  RL_LOGV_ARG0("rlDriverMsgReadCmdCtx starts...\n");
986  /* check for NULL pointer */
987  if (RL_NULL_PTR == rlDrvData)
988  {
989  retVal = RL_RET_CODE_FATAL_ERROR;
990  }
991  else
992  {
993  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Return value is being set under different
994  conditions, where it's set with default value first" */
995  /*LDRA_INSPECTED 8 D */
996 
997  retVal = RL_RET_CODE_OK;
998  /* after command response is received and isCmdRespWaited flag is set FALSE, it is
999  necessary to read out all Async messages in Commands context, because slave device
1000  could have dispatched some Async messages before receiving the command */
1001 
1002  /* AR_CODE_REVIEW MR:D.2.1 <APPROVED> "This is function must loop till
1003  * command response is received successfully or retry timer expires ,
1004  * if any Hw hang then WDT reset recovers from this error" */
1005  /*LDRA_INSPECTED 28 D */
1006  while ((RL_TRUE == rlDrvData->isCmdRespWaited[devIndex]) && (RL_RET_CODE_OK == retVal))
1007  {
1008  if (RL_PENDING_RX_MSG(rlDrvData, devIndex))
1009  {
1010  /* init to illegal value and verify it's overwritten with the
1011  * valid one */
1012  rlDrvData->funcParams[devIndex].rxMsgClass = RL_API_CLASS_MAX;
1013 
1014  /* Receive data over communication channel */
1015  retVal += rlDriverMsgCmdReply(rlDrvData, devIndex);
1016  }
1017  /* AR_CODE_REVIEW MR:D.2.1 <APPROVED> "This is function must loop till
1018  * command response is received successfully or retry timer expires,
1019  * if any Hw hang then WDT reset recovers from this error" */
1020  /*LDRA_INSPECTED 28 D */
1021  else
1022  {
1023  /* cmdSem will be signaled by IRQ */
1024  if (RL_RET_CODE_OK != rlDrvData->clientCtx.osiCb.sem.rlOsiSemWait(
1025  &(rlDrvData->cmdSem[devIndex]),
1026  (rlOsiTime_t)rlDrvData->clientCtx.ackTimeout))
1027  {
1028  /* setCmd Response Wait Tag to False when timer expires */
1029  rlDrvData->isCmdRespWaited[devIndex] = RL_FALSE;
1030 
1031  RL_LOGE_ARG0("CmdSem should be signaled by IRQ but respTimeout\n");
1032  retVal += RL_RET_CODE_RESP_TIMEOUT;
1033  break;
1034  }
1035  }
1036  }
1037 
1038  /* if any Rx Msg is pending to process and ACK Timout error hasn't happend */
1039  if (RL_PENDING_RX_MSG(rlDrvData, devIndex) && (retVal != RL_RET_CODE_FATAL_ERROR) \
1040  && (rlDrvData->isCmdRespWaited[devIndex] == RL_FALSE))
1041  {
1042  /* Spawn a thread/task to read pending Rx Msg */
1043  if (rlDrvData->clientCtx.osiCb.queue.rlOsiSpawn
1044  ((RL_P_OSI_SPAWN_ENTRY)rlDriverMsgReadSpawnCtx, \
1045  &rlDrvData->commDevIdx.rlDevIndex[devIndex], 0U) != RL_RET_CODE_OK)
1046  {
1047  retVal = RL_RET_CODE_RADAR_OSIF_ERROR;
1048  }
1049  }
1050  }
1051  RL_LOGV_ARG0("rlDriverMsgReadCmdCtx ends...\n");
1052 
1053  return retVal;
1054 }
1055 
1069 /* DesignId : */
1070 /* Requirements : */
1071 static rlReturnVal_t rlDriverOriginDirCheck(rlUInt8_t deviceRunId,
1072  rlUInt8_t dataDir)
1073 {
1074  rlReturnVal_t retVal;
1075 
1076  RL_LOGV_ARG0("rlDriverOriginDirCheck starts...\n");
1077 
1078  switch (deviceRunId)
1079  {
1080  /* if mmWaveLink instance is running on Host */
1081  case RL_PLATFORM_HOST:
1082  if ((RL_API_DIR_BSS_TO_HOST == dataDir) ||
1083  (RL_API_DIR_MSS_TO_HOST == dataDir) ||
1084  (RL_API_DIR_DSS_TO_HOST == dataDir))
1085  {
1086  /* set OK to return value, i.e. requested DataDir is correct
1087  as per running instance of mmWaveLink */
1088  retVal = RL_RET_CODE_OK;
1089  }
1090  else
1091  {
1092  /* request DataDir is invalid as per running instance of mmWaveLink */
1093  retVal = RL_RET_CODE_INVALID_INPUT;
1094  }
1095  break;
1096  /* if mmWaveLink instance is running on MSS */
1097  case RL_PLATFORM_MSS:
1098  if ((RL_API_DIR_BSS_TO_MSS == dataDir) ||
1099  (RL_API_DIR_DSS_TO_MSS == dataDir) ||
1100  (RL_API_DIR_HOST_TO_MSS == dataDir))
1101  {
1102  /* set OK to return value, i.e. requested DataDir is correct
1103  as per running instance of mmWaveLink */
1104  retVal = RL_RET_CODE_OK;
1105  }
1106  else
1107  {
1108  /* request DataDir is invalid as per running instance of mmWaveLink */
1109  retVal = RL_RET_CODE_INVALID_INPUT;
1110  }
1111  break;
1112  /* if mmWaveLink instance is running on DSS */
1113  case RL_PLATFORM_DSS:
1114  /* if Data direction is towards DSS */
1115  if ((RL_API_DIR_BSS_TO_DSS == dataDir) ||
1116  (RL_API_DIR_MSS_TO_DSS == dataDir) ||
1117  (RL_API_DIR_HOST_TO_DSS == dataDir))
1118  {
1119  /* set OK to return value, i.e. requested DataDir is correct
1120  as per running instance of mmWaveLink */
1121  retVal = RL_RET_CODE_OK;
1122  }
1123  else
1124  {
1125  /* request DataDir is invalid as per running instance of mmWaveLink */
1126  retVal = RL_RET_CODE_INVALID_INPUT;
1127  }
1128  break;
1129  default:
1130  /* Invalid: set error code */
1131  retVal = RL_RET_CODE_INVALID_INPUT;
1132  RL_LOGE_ARG2("Unknown platform %d, retVal = %d\n", \
1133  dataDir, retVal);
1134  break;
1135  }
1136  RL_LOGV_ARG0("rlDriverOriginDirCheck ends...\n");
1137 
1138  return retVal;
1139 }
1140 
1141 rlReturnVal_t rlDriverRdVerifyMsg(rlReadBuf_t readBuf, rlUInt8_t devIndex)
1142 {
1143  rlUInt16_t rxLengthRecv;
1144  rlReturnVal_t retVal, readRetVal;
1145  rlUInt16_t payloadLen, msgCrcLen, msgCrcType;
1146  rlUInt8_t isCrcPresent;
1147 
1148  /* get Received Message length excluding SYNC */
1149  rxLengthRecv = RL_RHCP_HDR_PL_LENGTH(&(readBuf.syncHeader.protHdr));
1150 
1151  /* check if received msg length is under valid Msg size */
1152  if (rxLengthRecv >= (RL_MAX_SIZE_MSG - SYNC_PATTERN_LEN))
1153  {
1154  retVal = RL_RET_CODE_PROTOCOL_ERROR;
1155  }
1156  else
1157  {
1158  rlRhcpMsg_t *rhcpMsg;
1159 
1160  /* Get Rx Message Class from received buffer header */
1161  /* Process Header Here - Verify each field */
1162  rl_driverData.funcParams[devIndex].rxMsgClass =
1163  RL_RHCP_HDR_OPCODE_CLASS(&(readBuf.syncHeader.protHdr));
1164 
1165  /* get the Payload Value removing Header length from Rx Msg Length */
1166  payloadLen = rxLengthRecv - (rlUInt16_t)RHCP_HEADER_LEN;
1167 
1168  if (RL_API_CLASS_ASYNC == rl_driverData.funcParams[devIndex].rxMsgClass)
1169  {
1170  /* Get RHCP message structure pointer */
1171  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData is pointer to a global
1172  structure, can't be NULL" */
1173  /*LDRA_INSPECTED 45 D */
1174  rhcpMsg = &rl_driverData.funcParams[devIndex].asyncEvt.evtMsg;
1175  }
1176  else
1177  {
1178  /* Get RHCP message structure pointer */
1179  rhcpMsg = &rl_rxMsg[devIndex];
1180  }
1181 
1182  /* copy header to global structure */
1183  rhcpMsg->hdr = readBuf.syncHeader.protHdr;
1184  /* Copy SYNC from Communication Channel*/
1185  rhcpMsg->syncPattern = readBuf.syncHeader.syncPattern;
1186 
1187  /* Check whether CRC is present*/
1188  if (rhcpMsg->hdr.flags.b2Crc != 0U)
1189  {
1190  /* if CRC is not present in Msg the reset crc variables */
1191  isCrcPresent = RL_FALSE;
1192  msgCrcLen = 0U;
1193  msgCrcType = 0U;
1194  }
1195  else
1196  {
1197  isCrcPresent = RL_TRUE;
1198  /* It may be size 2/4/8 based on 16/32/64 bit */
1199  msgCrcType = rhcpMsg->hdr.flags.b2CrcLen;
1200  /* set CRC length in bytes based on CRC Type */
1201  msgCrcLen = (2U << (msgCrcType & 0x3U));
1202  }
1203  /* Calculate payload length from header legnth*/
1204  payloadLen = ((isCrcPresent == RL_TRUE) ? (payloadLen - msgCrcLen) : payloadLen);
1205 
1206  /* This is an Response/AsyncEvent message. Read the rest of it. */
1207  if (payloadLen > 0U)
1208  {
1209  if (RL_IF_READ(rl_driverData.commDevIdx.comIfHdl[devIndex],
1210  &rhcpMsg->payload[0U], payloadLen) != (rlInt32_t)payloadLen)
1211  {
1212  /* If Read from Communication channel failed then set Error code */
1213  readRetVal = RL_RET_CODE_RADAR_IF_ERROR;
1214  }
1215  else
1216  {
1217  readRetVal = RL_RET_CODE_OK;
1218  }
1219 #if !(RL_DISABLE_LOGGING)
1220  rlLogSpiReadWrite(devIndex, &rhcpMsg->payload[0U], payloadLen, \
1221  RL_SPI_LOG_READ);
1222 #endif
1223  }
1224  else
1225  {
1226  readRetVal = RL_RET_CODE_OK;
1227  }
1228 
1229  /* If CRC is present - Read and verify*/
1230  if ((isCrcPresent == RL_TRUE) && (readRetVal == RL_RET_CODE_OK))
1231  {
1232  /* Read the CRC Bytes */
1233  if (RL_IF_READ(rl_driverData.commDevIdx.comIfHdl[devIndex],
1234  rl_driverData.funcParams[devIndex].msgCRC,
1235  msgCrcLen) != (rlInt32_t)msgCrcLen)
1236  {
1237  /* Set the error code if read data fails */
1238  retVal = RL_RET_CODE_RADAR_IF_ERROR;
1239  }
1240  else
1241  {
1242  (void)memcpy(&rhcpMsg->payload[payloadLen], \
1243  &rl_driverData.funcParams[devIndex].msgCRC[0U], msgCrcLen);
1244  /* Check if CRC is enabled from the application and it's type
1245  matched with received MSG CRC type */
1246  if ((rl_driverData.clientCtx.crcType != (rlUInt8_t)RL_CRC_TYPE_NO_CRC) && \
1247  (rl_driverData.clientCtx.crcType == (rlUInt8_t)msgCrcType))
1248  {
1249  /* Validate CRC first as Opcode might be corrupt as well */
1250  /* AR_CODE_REVIEW MR:R.10.3 <APPROVED> "All parameter types are matching to
1251  function argument type. LDRA tool issue." */
1252  /*LDRA_INSPECTED 458 S */
1253  retVal = rlDriverVerifyCRC((rlUInt8_t*)&rhcpMsg->hdr, (rxLengthRecv - \
1254  msgCrcLen), (rlUInt8_t)(msgCrcType), \
1255  rl_driverData.funcParams[devIndex].msgCRC);
1256  }
1257  else
1258  {
1259  retVal = RL_RET_CODE_OK;
1260  }
1261  }
1262 #if !(RL_DISABLE_LOGGING)
1263  rlLogSpiReadWrite(devIndex, rl_driverData.funcParams[devIndex].msgCRC, msgCrcLen,\
1264  RL_SPI_LOG_READ);
1265 #endif
1266  }
1267  else
1268  {
1269  retVal = RL_RET_CODE_OK;
1270  }
1271  }
1272 
1273  return retVal;
1274 }
1275 
1287 /* DesignId : MMWL_DesignId_026 */
1288 /* Requirements : AUTORADAR_REQ-777, AUTORADAR_REQ-779 */
1289 rlReturnVal_t rlDriverMsgRead(rlDriverData_t* rlDrvData, rlUInt8_t devIndex)
1290 {
1291  rlReturnVal_t retVal, hdrRetVal;
1292  rlReadBuf_t readBuf = {0};
1293  rlUInt16_t payloadLen;
1294 
1295  RL_LOGV_ARG0("rlDriverMsgRead starts...\n");
1296  /* check for NULL pointer */
1297  if (RL_NULL_PTR == rlDrvData)
1298  {
1299  /* set error code */
1300  retVal = RL_RET_CODE_FATAL_ERROR;
1301  }
1302  else
1303  {
1304  rlReturnVal_t hdrType;
1305 
1306  /* Read message Header from given device index */
1307  hdrType = rlDriverRxHdrRead(readBuf.tempBuf,
1308  rlDrvData->commDevIdx.comIfHdl[devIndex]);
1309  RL_LOGV_ARG1("rlDriverRxHdrRead return val = %d\n", hdrType);
1310 
1311  /* if it's not CNYS pattern then calculate checksum before consuming or
1312  * forwarding to other core */
1313  if (SYNC_PATTERN_MATCHED == (rlInt32_t)(hdrType))
1314  {
1315  /* Verify Checksum, return value 0/-7 (RL_RET_CODE_CHKSUM_FAILED) */
1316  hdrRetVal = rlDriverValidateHdr(readBuf.syncHeader.protHdr);
1317 
1318  /* Received msg can be command/response/async_event
1319  * and it is destined to the same device where this mmWaveLink ir running
1320  */
1321  if ((RL_RET_CODE_OK == hdrRetVal) && (RL_RET_CODE_OK == \
1322  rlDriverOriginDirCheck(rlDrvData->clientCtx.platform,
1323  (rlUInt8_t)readBuf.syncHeader.protHdr.opcode.b4Direction)))
1324  {
1325  retVal = rlDriverRdVerifyMsg(readBuf, devIndex);
1326  }
1327  else if (RL_RET_CODE_OK == hdrRetVal)
1328  {
1329  rlDrvData->funcParams[devIndex].rxMsgClass = RL_API_CLASS_BYPASS;
1330  /* if rcvd data is not meant for the device where mmWaveLink is running,
1331  * Then pass data to intended destination; Assumption: byPass of
1332  * Data will happening in MSS only
1333  */
1334  rl_rxMsg[devIndex].syncPattern = readBuf.syncHeader.syncPattern;
1335  rl_rxMsg[devIndex].hdr = readBuf.syncHeader.protHdr;
1336 
1337  /* this length includes the CRC field also */
1338  payloadLen = readBuf.syncHeader.protHdr.len - (rlUInt16_t)RHCP_HEADER_LEN;
1339 
1340  /* read full data before writing to destination COMM handle */
1341  if (RL_IF_READ(rlDrvData->commDevIdx.comIfHdl[devIndex], \
1342  &rl_rxMsg[devIndex].payload[0], payloadLen) != (rlInt32_t)payloadLen)
1343  {
1344  /* Set error code if read is failed */
1345  retVal = RL_RET_CODE_RADAR_IF_ERROR;
1346  }
1347  else
1348  {
1349  /* Set as passed if data read returns zero */
1350  retVal = RL_RET_CODE_OK;
1351  }
1352 #if !(RL_DISABLE_LOGGING)
1353  rlLogSpiReadWrite(devIndex, &rl_rxMsg[devIndex].payload[0], payloadLen,\
1354  RL_SPI_LOG_READ);
1355 #endif
1356  }
1357  /* If checksum mismatched of the received message and link is running on
1358  Host then it needs to flush the AWR device's MibSPI RAM so that MSS
1359  can re-sync its buffer pointer */
1360  else if ((RL_RET_CODE_CHKSUM_FAILED == hdrRetVal) && \
1361  (rl_driverData.clientCtx.platform == RL_PLATFORM_HOST))
1362  {
1363  rlUInt16_t dummyToFlushSpi[8U] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
1364  0xFFFF, 0xFFFF, 0xFFFF};
1365  rlUInt16_t readCnt;
1366  /* Get the CRC Length what is configured */
1367  rlUInt16_t msgCrcLen = (2U << (rl_driverData.clientCtx.crcType & 0x3U));
1368 
1369  /* Read 240 bytes from SPI buff to allign MSS SPI_RX DMA with HOST TX buff */
1370  for (readCnt = 1U; readCnt < (SYNC_PATTERN_LEN + RHCP_HEADER_LEN); readCnt++)
1371  {
1372  (void)RL_IF_READ(rlDrvData->commDevIdx.comIfHdl[devIndex],
1373  (rlUInt8_t*)&dummyToFlushSpi[0U], (SYNC_PATTERN_LEN + \
1374  RHCP_HEADER_LEN));
1375  }
1376 #if !(RL_DISABLE_LOGGING)
1377  rlLogSpiReadWrite(devIndex,
1378  (rlUInt8_t*)&dummyToFlushSpi[0U], (SYNC_PATTERN_LEN + \
1379  RHCP_HEADER_LEN), RL_SPI_LOG_READ);
1380 #endif
1381  /* Check whether CRC is present read it from MibSPI buff */
1382  if (rl_txMsg[devIndex].hdr.flags.b2Crc == 0U)
1383  {
1384  /* Read remaining data to clear SPI buffer */
1385  (void)RL_IF_READ(rlDrvData->commDevIdx.comIfHdl[devIndex],
1386  (rlUInt8_t*)&dummyToFlushSpi[0U], msgCrcLen);
1387  }
1388 #if !(RL_DISABLE_LOGGING)
1389  rlLogSpiReadWrite(devIndex, (rlUInt8_t*)&dummyToFlushSpi[0U], msgCrcLen,\
1390  RL_SPI_LOG_READ);
1391 #endif
1392  /* In case Checksum of header is corrupted MMWL will create internal Async event
1393  message to Notify the application about checksum failure */
1394  rl_driverData.funcParams[devIndex].rxMsgClass = RL_API_CLASS_ASYNC;
1395 
1396  /* Set header Validate function return value to retVal */
1397  retVal = hdrRetVal;
1398  }
1399  else
1400  {
1401  /* Set header Validate function return value to retVal */
1402  retVal = hdrRetVal;
1403  /* In case CRC/Checksum is corrupted then store RxMsg Class with Async event */
1404  rl_driverData.funcParams[devIndex].rxMsgClass =
1405  RL_RHCP_HDR_OPCODE_CLASS(&(readBuf.syncHeader.protHdr));
1406  }
1407  }
1408  /* In case mmWaveLink instance is running on MSS, it may receive CNYS from Host Over SPI */
1409  else if (CNYS_PATTERN_MATCHED == (rlInt32_t)(hdrType))
1410  {
1411  /* Check callback is assigned by the application */
1412  if (rl_driverData.clientCtx.cmdParserCb.rlPostCnysStep != RL_NULL_PTR)
1413  {
1414  /* invoke function to complete the task required after receiving CNYS */
1415  retVal = rl_driverData.clientCtx.cmdParserCb.rlPostCnysStep(devIndex);
1416  }
1417  else
1418  {
1419  /* Set error code if callback is NULL */
1420  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1421  }
1422  }
1423  else
1424  {
1425  retVal = hdrType;
1426  /* If timeout for HostIRQ down then notify this to Host via AsyncEvent */
1427  if (hdrType == RL_RET_CODE_HOSTIRQ_TIMEOUT)
1428  {
1429  rl_driverData.funcParams[devIndex].rxMsgClass = RL_API_CLASS_ASYNC;
1430  }
1431  else
1432  {
1433  /* In case CRC/Checksum is corrupted then store RxMsg Class with Async event */
1434  rl_driverData.funcParams[devIndex].rxMsgClass =
1435  RL_RHCP_HDR_OPCODE_CLASS(&(readBuf.syncHeader.protHdr));
1436  }
1437  }
1438 
1439  /* Unmask Interrupt call */
1440  if ((RL_NULL_PTR != rlDrvData->clientCtx.devCtrlCb.rlDeviceUnMaskHostIrq) &&\
1441  (retVal != RL_RET_CODE_FATAL_ERROR))
1442  {
1443  /* Un Mask Interrupt */
1445  rlDrvData->commDevIdx.comIfHdl[devIndex]);
1446  RL_LOGD_ARG0("rlDriverMsgRead Unmask Interrupt call\n");
1447  }
1448  }
1449 
1450  RL_LOGV_ARG0("rlDriverMsgRead ends...\n");
1451 
1452  return retVal;
1453 }
1454 
1467 /* DesignId : MMWL_DesignId_025 */
1468 /* Requirements : AUTORADAR_REQ_772, AUTORADAR_REQ-774 */
1469 rlReturnVal_t rlDriverMsgWrite(rlDriverData_t* rlDrvData, rlUInt8_t devIndex,
1470  rlComIfHdl_t comIfHdl)
1471 {
1472  rlReturnVal_t retVal;
1473 
1474  RL_LOGV_ARG0("rlDriverMsgWrite starts...\n");
1475 
1476  /* check for NULL pointer */
1477  if (((rlComIfHdl_t)RL_NULL != comIfHdl) && (rlDrvData != RL_NULL_PTR))
1478  {
1479  rlUInt16_t checkSum = 0U, msgCrcLen;
1480  rlUInt16_t payloadLen;
1481  rlUInt16_t tempLen;
1482  /* Calculate Checksum */
1483  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Checksum is getting updated in called function" */
1484  /*LDRA_INSPECTED 8 D */
1485  (void)rlDriverCalChkSum(&rl_txMsg[devIndex].hdr, ((rlUInt8_t)(RHCP_HEADER_LEN - 2U)),
1486  &checkSum);
1487  rl_txMsg[devIndex].hdr.chksum = checkSum;
1488 
1489  /* get Payload length removing Header length from Msg Length */
1490  payloadLen = rl_txMsg[devIndex].hdr.len - (rlUInt16_t)RHCP_HEADER_LEN;
1491  RL_LOGV_ARG1("API Dir = %d \n", rl_txMsg[devIndex].hdr.opcode.b4Direction);
1492 
1493  /* check for Data Direction to choose Sync Pattern */
1494  if ((RL_API_DIR_DSS_TO_HOST == rl_txMsg[devIndex].hdr.opcode.b4Direction) || \
1495  (RL_API_DIR_MSS_TO_HOST == rl_txMsg[devIndex].hdr.opcode.b4Direction) || \
1496  (RL_API_DIR_DSS_TO_MSS == rl_txMsg[devIndex].hdr.opcode.b4Direction))
1497  {
1498  /* set device to Host Sync Pattern */
1499  rl_txMsg[devIndex].syncPattern.sync1 = D2H_SYNC_PATTERN_1;
1500  rl_txMsg[devIndex].syncPattern.sync2 = D2H_SYNC_PATTERN_2;
1501  }
1502  else
1503  {
1504  /* set Host to device Sync Pattern */
1505  rl_txMsg[devIndex].syncPattern.sync1 = H2D_SYNC_PATTERN_1;
1506  rl_txMsg[devIndex].syncPattern.sync2 = H2D_SYNC_PATTERN_2;
1507  }
1508 
1509  /* Check if CRC is enabled, Calculate and update payload length*/
1510  if (rl_txMsg[devIndex].hdr.flags.b2Crc == RL_HDR_FLAG_CRC)
1511  {
1512  /* It may be size 2/4/8 based on 16/32/64 bit */
1513  msgCrcLen = (2U << (rlDrvData->clientCtx.crcType & 0x3U));
1514  /* compute CRC */
1515  /* AR_CODE_REVIEW MR:R.10.3 <INSPECTED> "All param types are matching to function
1516  argument type. LDRA tool issue." */
1517  /*LDRA_INSPECTED 458 S */
1518  (void)rlDriverCalCRC((rlUInt8_t *)&rl_txMsg[devIndex].hdr,\
1519  (rl_txMsg[devIndex].hdr.len - msgCrcLen),
1520  (rlUInt8_t)rlDrvData->clientCtx.crcType,
1521  &rlDrvData->funcParams[devIndex].msgCRC[0]);
1522  /* copy computed CRC to Tx Msg buffer */
1523  (void)memcpy((rlUInt8_t*)(&rl_txMsg[devIndex].payload[payloadLen - msgCrcLen]),
1524  (rlUInt8_t*)&(rlDrvData->funcParams[devIndex].msgCRC[0]), msgCrcLen);
1525  }
1526  tempLen = ((rlUInt16_t)(SYNC_PATTERN_LEN + RHCP_HEADER_LEN) + payloadLen);
1527 
1528  /* write Tx Msg to destination either over Mailbox internal to
1529  mmWave device or to External Host Over SPI */
1530  if (RL_IF_WRITE(comIfHdl, ((rlUInt8_t *)&rl_txMsg[devIndex]), \
1531  tempLen) != (rlInt32_t)tempLen)
1532  {
1533  /* set error code */
1534  retVal = RL_RET_CODE_RADAR_IF_ERROR;
1535  }
1536  else
1537  {
1538  /* set Error code as OK */
1539  retVal = RL_RET_CODE_OK;
1540  }
1541 #if !(RL_DISABLE_LOGGING)
1542  rlLogSpiReadWrite(devIndex, ((rlUInt8_t *)&rl_txMsg[devIndex]), tempLen, \
1543  RL_SPI_LOG_WRITE);
1544 #endif
1545  }
1546  else
1547  {
1548  /* set error code if pointers are NULL */
1549  retVal = RL_RET_CODE_FATAL_ERROR;
1550  }
1551  RL_LOGV_ARG0("rlDriverMsgWrite ends...\n");
1552 
1553  return retVal;
1554 }
1555 
1569 /* DesignId : */
1570 /* Requirements : AUTORADAR_REQ-777 */
1571 static rlUInt8_t rlDriverReceiveSync(rlComIfHdl_t comIfHdl, rlUInt8_t syncBuf[],
1572  rlInt32_t *syncType)
1573 {
1574  rlUInt8_t count = 0;
1575  rlInt32_t retVal;
1576  rlSyncPattern_t recSyncPattern = {0U, 0U};
1577  rlReturnVal_t errVal;
1578 
1579  RL_LOGV_ARG0("rlDriverReceiveSync starts...\n");
1580 
1581  /* check for NULL pointer */
1582  if (syncType != (rlInt32_t*)RL_NULL)
1583  {
1584  /* Read 4 bytes SYNC Pattern) */
1585  if (RL_IF_READ(comIfHdl, &syncBuf[0U], (rlUInt16_t)SYNC_PATTERN_LEN) != \
1586  (rlInt32_t)SYNC_PATTERN_LEN)
1587  {
1588  /* set error code */
1589  errVal = RL_RET_CODE_RADAR_IF_ERROR;
1590  }
1591  else
1592  {
1593  /* if SYNC pattern has been read properly then copy it */
1594  (void)memcpy(&recSyncPattern, &syncBuf[0U], SYNC_PATTERN_LEN);
1595  errVal = RL_RET_CODE_OK;
1596  }
1597 #if !(RL_DISABLE_LOGGING)
1598  rlLogSpiReadWrite(*((rlUInt8_t*)comIfHdl), &syncBuf[0U], \
1599  (rlUInt16_t)SYNC_PATTERN_LEN, RL_SPI_LOG_READ);
1600 #endif
1601  retVal = PATTERN_NOT_MATCHED;
1602 
1603  /* Wait for SYNC_PATTERN from the device (when mmWaveLink is running on Ext Host*/
1604  while (((retVal) == (rlInt32_t)PATTERN_NOT_MATCHED) && (errVal == RL_RET_CODE_OK))
1605  {
1606  /* check if matched with SYNC pattern Host-to-device or device-to-Host */
1607  if (((recSyncPattern.sync1 == H2D_SYNC_PATTERN_1) &&
1608  (recSyncPattern.sync2 == H2D_SYNC_PATTERN_2) ) || \
1609  ((recSyncPattern.sync1 == D2H_SYNC_PATTERN_1) &&
1610  (recSyncPattern.sync2 == D2H_SYNC_PATTERN_2)))
1611  {
1612  /* set to SYNC Matched flag if H2D or D2H SYNC pattern is matching
1613  for big/little endian data */
1614  retVal = SYNC_PATTERN_MATCHED;
1615  }
1616  else
1617  {
1618  /* if mmwavelink running on device and connect to Host over SPI then
1619  it may recieve CNYS to send data */
1620  if ((recSyncPattern.sync1 == H2D_CNYS_PATTERN_1) &&
1621  (recSyncPattern.sync2 == H2D_CNYS_PATTERN_2))
1622  {
1623  /* set to CNYS Matched flag if H2D CNYS pattern is matching
1624  for big/little endian data */
1625  retVal = CNYS_PATTERN_MATCHED;
1626  }
1627  /* check if count is beyond SYNC Scan threshold */
1628  else if (count >= (rlUInt16_t)RL_SYNC_SCAN_THRESHOLD)
1629  {
1630  rlUInt16_t crcLen = (2U << (rl_driverData.clientCtx.crcType & 0x3U));
1631  /* If pattern not found then read few extra bytes (CRC Len) to make
1632  whole read count [4n+CRCLen] aligned */
1633  if (RL_IF_READ(comIfHdl, &syncBuf[SYNC_PATTERN_LEN], (rlUInt16_t)crcLen) != \
1634  (rlInt32_t)crcLen)
1635  {
1636  /* Set error code to terminate this loop */
1637  errVal += RL_RET_CODE_RADAR_IF_ERROR;
1638  }
1639  else
1640  {
1641  /* Set error code to terminate this loop */
1642  errVal += RL_RET_CODE_PROTOCOL_ERROR;
1643  }
1644 #if !(RL_DISABLE_LOGGING)
1645  rlLogSpiReadWrite(*((rlUInt8_t*)comIfHdl), \
1646  &syncBuf[SYNC_PATTERN_LEN], (rlUInt16_t)crcLen, \
1647  RL_SPI_LOG_READ);
1648 #endif
1649  }
1650  else
1651  {
1652  /* Read next 4 bytes to Low 4 bytes of buffer */
1653  if (0 == (count % SYNC_PATTERN_LEN))
1654  {
1655  /* Read 4 bytes SYNC Pattern) */
1656  if (RL_IF_READ(comIfHdl, &syncBuf[SYNC_PATTERN_LEN],\
1657  (rlUInt16_t)SYNC_PATTERN_LEN) != \
1658  (rlInt32_t)SYNC_PATTERN_LEN)
1659  {
1660  /* Set error code to terminate this loop */
1661  errVal += RL_RET_CODE_RADAR_IF_ERROR;
1662  break;
1663  }
1664 #if !(RL_DISABLE_LOGGING)
1665  rlLogSpiReadWrite(*((rlUInt8_t*)comIfHdl), \
1666  &syncBuf[SYNC_PATTERN_LEN], (rlUInt16_t)SYNC_PATTERN_LEN, \
1667  RL_SPI_LOG_READ);
1668 #endif
1669  }
1670  /* Shift Buffer Up for checking if the sync is shifted */
1671  rlDriverShiftDWord(syncBuf);
1672  /* copy data to recv sync pattern to compare further */
1673  (void)memcpy(&recSyncPattern, &syncBuf[0U], SYNC_PATTERN_LEN);
1674  /* increment read counter */
1675  count++;
1676  }
1677  }
1678  }
1679 
1680  if (errVal == RL_RET_CODE_OK)
1681  {
1682  *(syncType) = retVal;
1683  }
1684  else
1685  {
1686  *(syncType) = errVal;
1687  }
1688  }
1689  count %= SYNC_PATTERN_LEN;
1690  RL_LOGV_ARG1("rlDriverReceiveSync, count = %d\n", count);
1691  RL_LOGV_ARG0("rlDriverReceiveSync ends...\n");
1692 
1693  return count;
1694 }
1695 
1706 /* DesignId : */
1707 /* Requirements : AUTORADAR_REQ-777 */
1708 /*AR_CODE_REVIEW MR:R.2.2 <APPROVED> "errVal is re initialized under different
1709  if else conditions based on what the error is" */
1710 /*LDRA_INSPECTED 8 D */
1711 rlReturnVal_t rlDriverRxHdrRead(rlUInt8_t hdrBuf[RHCP_HEADER_LEN], rlComIfHdl_t comIfHdl)
1712 {
1713  /* syncBuf: it should be 2/4 byte aligned, as in the application where
1714  * it uses DMA to Rd/Wr DMA might have limitation of src/dest address
1715  * alignement
1716  */
1717  rlUInt8_t syncBuf[SYNC_PATTERN_LEN * 2] = {0U};
1718  /* This buffer contains CNYS pattern (4Bytes) and 12Bytes of dummy sequence.
1719  Host writes this buffer in response to Host-IRQ raised by AWR device to indicate
1720  that device can now write response/async event data to its SPI buffer which will
1721  be read by Host.
1722  */
1723  rlUInt16_t cnysBuf[8U] = {H2D_CNYS_PATTERN_1, H2D_CNYS_PATTERN_2,
1724  0xFFFFU, 0xFFFFU, 0xFFFFU, 0xFFFFU, 0xFFFFU, 0xFFFFU};
1725  rlInt32_t syncType = PATTERN_NOT_MATCHED;
1726  rlUInt8_t syncCnt;
1727  rlInt32_t errVal;
1728 
1729  RL_LOGV_ARG0("rlDriverRxHdrRead starts...\n");
1730 
1731  /* check for NULL pointer */
1732  if ((rlComIfHdl_t)RL_NULL == comIfHdl)
1733  {
1734  errVal = RL_RET_CODE_FATAL_ERROR;
1735  syncType += errVal;
1736  }
1737  else
1738  {
1739  /* If mmWaveLink is running on Ext Host */
1740  if (rl_driverData.clientCtx.platform == RL_PLATFORM_HOST)
1741  {
1742  /* Write CNYS pattern to mmWave Radar */
1743  if (RL_IF_WRITE(comIfHdl,
1744  (rlUInt8_t*)&cnysBuf[0U], (rlUInt16_t)(SYNC_PATTERN_LEN+ RHCP_HEADER_LEN)) !=\
1745  (rlInt32_t)(SYNC_PATTERN_LEN + RHCP_HEADER_LEN))
1746  {
1747  /* Set error code if data write function fails to write SYNC pattern */
1748  errVal = RL_RET_CODE_RADAR_IF_ERROR;
1749  }
1750  else
1751  {
1752  errVal = RL_RET_CODE_OK;
1753  }
1754 #if !(RL_DISABLE_LOGGING)
1755  rlLogSpiReadWrite(*((rlUInt8_t*)comIfHdl),
1756  (rlUInt8_t*)&cnysBuf[0U], (rlUInt16_t)(SYNC_PATTERN_LEN+ RHCP_HEADER_LEN),\
1757  RL_SPI_LOG_WRITE);
1758 #endif
1759 
1760  RL_LOGV_ARG2("Platform = %d, delay = %d \n",\
1761  rl_driverData.clientCtx.platform, \
1762  rl_driverData.clientCtx.timerCb.rlDelay);
1763  /* Need to wait till host Irq is down */
1764  /* Check if Host Irq Status can be polled, else use fixed delay */
1765  if ((rl_driverData.clientCtx.devCtrlCb.rlDeviceWaitIrqStatus != NULL) &&
1766  (rl_driverData.clientCtx.devCtrlCb.rlDeviceWaitIrqStatus(comIfHdl,
1767  0U) != RL_RET_CODE_OK) && (errVal == RL_RET_CODE_OK))
1768  {
1769  /* If IRQ polling timed out then re-write the CNYS pattern to mmwave Radar */
1770  if (RL_IF_WRITE(comIfHdl,
1771  (rlUInt8_t*)&cnysBuf[0U], (rlUInt16_t)(SYNC_PATTERN_LEN+ RHCP_HEADER_LEN)) !=\
1772  (rlInt32_t)(SYNC_PATTERN_LEN + RHCP_HEADER_LEN))
1773  {
1774  /* Set error code if data write function fails to write SYNC pattern */
1775  errVal += RL_RET_CODE_RADAR_IF_ERROR;
1776  }
1777  else
1778  {
1779  if (rl_driverData.clientCtx.devCtrlCb.rlDeviceWaitIrqStatus(comIfHdl, 0U) != 0)
1780  {
1781  errVal += RL_RET_CODE_HOSTIRQ_TIMEOUT;
1782  }
1783  }
1784 #if !(RL_DISABLE_LOGGING)
1785  rlLogSpiReadWrite(*((rlUInt8_t*)comIfHdl),
1786  (rlUInt8_t*)&cnysBuf[0U], (rlUInt16_t)(SYNC_PATTERN_LEN+ RHCP_HEADER_LEN),\
1787  RL_SPI_LOG_WRITE);
1788 #endif
1789  }
1790  else
1791  {
1792  /* Check if Delay callback is present and invoke */
1793  if (rl_driverData.clientCtx.timerCb.rlDelay != RL_NULL_PTR)
1794  {
1795  /* add 1 mSec delay */
1796  (void)rl_driverData.clientCtx.timerCb.rlDelay(1U);
1797  }
1798  }
1799  }
1800  else
1801  {
1802  errVal = RL_RET_CODE_OK;
1803  }
1804 
1805  if (errVal == RL_RET_CODE_OK)
1806  {
1807  RL_LOGDB_ARG1("Device [%d] Host IRQ Low\r", *((rlUInt8_t*)comIfHdl));
1808  /* AR_CODE_REVIEW MR:D.4.7 <APPROVED> "syncCnt is used when pattern is matched to
1809  copy and read data" */
1810  /*LDRA_INSPECTED 91 D */
1811  syncCnt = rlDriverReceiveSync(comIfHdl, &syncBuf[0U], &syncType);
1812  RL_LOGV_ARG1("syncType = %d \n", syncType);
1813 
1814  if ((CNYS_PATTERN_MATCHED == syncType) || (SYNC_PATTERN_MATCHED == syncType))
1815  {
1816  rlUInt16_t tempLen;
1817  rlUInt8_t* payloadBuf;
1818  /* copying shifted data to hdrBuf */
1819  payloadBuf = &syncBuf[0U];
1820  if (RL_NULL_PTR != payloadBuf)
1821  {
1822  /* AR_CODE_REVIEW MR:R.21.17 <INSPECTED> "Local array can't be null.
1823  LDRA tool issue." */
1824  /*LDRA_INSPECTED 140 D */
1825  (void)memcpy(&hdrBuf[0], payloadBuf, (SYNC_PATTERN_LEN + syncCnt));
1826  }
1827  tempLen = RHCP_HEADER_LEN - (0x00FFU & syncCnt);
1828  /* Here we've read Sync Pattern. Read the remaining header */
1829  if (RL_IF_READ(comIfHdl, (&hdrBuf[(SYNC_PATTERN_LEN + syncCnt)]), \
1830  tempLen) != (rlInt32_t)tempLen)
1831  {
1832  syncType += RL_RET_CODE_RADAR_IF_ERROR;
1833  }
1834 #if !(RL_DISABLE_LOGGING)
1835  rlLogSpiReadWrite(*((rlUInt8_t*)comIfHdl), \
1836  (&hdrBuf[(SYNC_PATTERN_LEN + syncCnt)]), tempLen,\
1837  RL_SPI_LOG_READ);
1838 #endif
1839  }
1840  else
1841  {
1842  /* do nothing */
1843  RL_LOGD_ARG0("do nothing ");
1844  }
1845  }
1846  else
1847  {
1848  syncType += errVal;
1849  }
1850 
1851  }
1852 
1853  RL_LOGV_ARG0("rlDriverRxHdrRead ends...\n");
1854 
1855  return syncType;
1856 }
1857 
1866 /* DesignId : MMWL_DesignId_002 */
1867 /* Requirements : AUTORADAR_REQ-784 */
1868 rlReturnVal_t rlDriverOsiInit(void)
1869 {
1870  rlReturnVal_t retVal;
1871  rlInt32_t funcRetVal = RL_RET_CODE_OK;
1872  rlUInt8_t index;
1873  rlInt8_t CmdSemStr[9] = "CmdSem_";
1874  rlInt8_t devMutexStr[11] = "devMutex_";
1875 
1876  for (index = 0U; index < RL_CASCADE_NUM_DEVICES; index++)
1877  {
1878  /* Create Command Semaphore */
1879  /* AR_CODE_REVIEW MR:R.10.8 <INSPECTED> "conversion required" */
1880  /*LDRA_INSPECTED 444 S */
1881  CmdSemStr[7] = (rlInt8_t)(index+48U);
1882  /* AR_CODE_REVIEW MR:R.18.1 <INSPECTED> "Array size not exceeded. Tool issue" */
1883  /*LDRA_INSPECTED 69 X */
1884  CmdSemStr[8] = (rlInt8_t)'\0';
1885  funcRetVal += rl_driverData.clientCtx.osiCb.sem.rlOsiSemCreate(
1886  &rl_driverData.cmdSem[index], CmdSemStr);
1887 
1888  /* Create Command Mutex */
1889  /* AR_CODE_REVIEW MR:R.10.8 <INSPECTED> "conversion required" */
1890  /*LDRA_INSPECTED 444 S */
1891  devMutexStr[9] = (rlInt8_t)(index+48U);
1892  /* AR_CODE_REVIEW MR:R.18.1 <INSPECTED> "Array size not exceeded. Tool issue" */
1893  /*LDRA_INSPECTED 69 X */
1894  devMutexStr[10] = (rlInt8_t)'\0';
1895  funcRetVal += rl_driverData.clientCtx.osiCb.mutex.rlOsiMutexCreate(
1896  &rl_driverData.devMutex[index], devMutexStr);
1897  }
1898 
1899  /* check for above function call return value */
1900  if (funcRetVal != RL_RET_CODE_OK)
1901  {
1902  /* set error code */
1903  retVal = RL_RET_CODE_RADAR_OSIF_ERROR;
1904  }
1905  else
1906  {
1907  retVal = RL_RET_CODE_OK;
1908  }
1909 
1910  return retVal;
1911 }
1912 
1913 static rlReturnVal_t rlDriverOsiCbCheck(rlClientCbs_t clientCb)
1914 {
1915  rlReturnVal_t retVal;
1916 
1917  /* Check if application has passed mutex interace functions */
1918  if ((RL_NULL_PTR == clientCb.osiCb.mutex.rlOsiMutexCreate) ||
1919  (RL_NULL_PTR == clientCb.osiCb.mutex.rlOsiMutexLock ) ||
1920  (RL_NULL_PTR == clientCb.osiCb.mutex.rlOsiMutexUnLock) ||
1921  (RL_NULL_PTR == clientCb.osiCb.mutex.rlOsiMutexDelete))
1922  {
1923  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1924  }
1925  /* Check if application has passed semaphore interface functions */
1926  else if ((RL_NULL_PTR == clientCb.osiCb.sem.rlOsiSemCreate) ||
1927  (RL_NULL_PTR == clientCb.osiCb.sem.rlOsiSemWait ) ||
1928  (RL_NULL_PTR == clientCb.osiCb.sem.rlOsiSemSignal) ||
1929  (RL_NULL_PTR == clientCb.osiCb.sem.rlOsiSemDelete))
1930  {
1931  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1932  }
1933  /* Check if application has passed communication interface functions */
1934  else if ((RL_NULL_PTR == (void*)clientCb.comIfCb.rlComIfOpen ) ||
1935  (RL_NULL_PTR == clientCb.comIfCb.rlComIfClose) ||
1936  (RL_NULL_PTR == clientCb.comIfCb.rlComIfRead ) ||
1937  (RL_NULL_PTR == clientCb.comIfCb.rlComIfWrite))
1938  {
1939  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1940  }
1941  else
1942  {
1943  /* if no error then set return value as OK */
1944  retVal = RL_RET_CODE_OK;
1945  }
1946 
1947  return retVal;
1948 }
1949 
1959 static rlReturnVal_t rlDriverClientCbCheck(rlClientCbs_t clientCb)
1960 {
1961  rlReturnVal_t retVal;
1962 
1963  if (RL_RET_CODE_OK != rlDriverOsiCbCheck(clientCb))
1964  {
1965  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1966  }
1967  /* Check if application has passed device interace functions */
1968  else if ((RL_NULL_PTR == clientCb.eventCb.rlAsyncEvent ) ||
1969  (RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceDisable ) ||
1970  (RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceEnable ) ||
1971  (RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceMaskHostIrq ))
1972  {
1973  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1974  }
1975  /* When mmWaveLink instance is running on HOST, check for interface for IRQ and delay */
1976  else if (((clientCb.platform == RL_PLATFORM_HOST) &&
1977  (((RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceWaitIrqStatus) &&
1978  (RL_NULL_PTR == clientCb.timerCb.rlDelay)))) ||
1979  (RL_NULL_PTR == clientCb.osiCb.queue.rlOsiSpawn))
1980  {
1981  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1982  }
1983  /* If CRC is enabled from application then check for CRC compute interface function */
1984  else if ((RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceUnMaskHostIrq) ||
1985  (RL_NULL_PTR == clientCb.devCtrlCb.rlRegisterInterruptHandler) ||
1986  ((RL_CRC_TYPE_NO_CRC != clientCb.crcType) &&
1987  (RL_NULL_PTR == clientCb.crcCb.rlComputeCRC)))
1988  {
1989  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1990  }
1991  else
1992  {
1993  retVal = RL_RET_CODE_OK;
1994  }
1995 
1996  return retVal;
1997 }
1998 
2010 /* DesignId : MMWL_DesignId_003 */
2011 /* Requirements : AUTORADAR_REQ-707 */
2012 rlReturnVal_t rlDriverInit(rlUInt8_t deviceMap, rlClientCbs_t clientCb)
2013 {
2014  rlReturnVal_t retVal, cbCheck;
2015  rlUInt8_t index = 0U;
2016 
2017  /* check for all interface APIs passed by the Application */
2018  cbCheck = rlDriverClientCbCheck(clientCb);
2019 
2020  if (RL_RET_CODE_OK != cbCheck)
2021  {
2022  retVal = cbCheck;
2023  }
2024  /* Initialize Driver Global Data */
2025  else if (deviceMap <= ((1U << RL_DEVICE_CONNECTED_MAX) - 0x1U))
2026  {
2027  /* Initialize Driver Global Data */
2028  for (; index < RL_DEVICE_CONNECTED_MAX; index++)
2029  {
2030  rl_driverData.isCmdRespWaited[index] = RL_FALSE;
2031  rl_driverData.isRespWriteWaited[index] = RL_FALSE;
2032  rl_driverData.rxDoneCnt[index] = 0U;
2033  rl_driverData.rxIrqCnt[index] = 0U;
2034  }
2035  /* Initialize Tx/Rx message pointers */
2036  for (index = 0U; index < RL_CASCADE_NUM_DEVICES; index++)
2037  {
2038  rl_driverData.txMsgPtr[index] = &rl_txMsg[index];
2039  rl_driverData.rxMsgPtr[index] = &rl_rxMsg[index];
2040  }
2041 
2042  /*Copy Client Context Info*/
2043  rl_driverData.clientCtx = clientCb;
2044  /* Store deviceMap */
2045  rl_driverData.deviceMap = deviceMap;
2046  /* Set command retry count */
2047  rl_driverData.retryCount = RL_API_CMD_RETRY_COUNT;
2048 
2049  /* intialize and stitch all OS interfaces */
2050  retVal = rlDriverOsiInit();
2051 
2052 #if !(RL_DISABLE_LOGGING)
2053  if (RL_RET_CODE_OK == retVal)
2054  {
2055  /*All callback copied in global strcuture, Init log parameter */
2056  retVal += rlLogInit();
2057  RL_LOGV_ARG0("Logging is enabled \n");
2058  }
2059 #endif
2060  index = 0U;
2061 
2062  do
2063  {
2064  /* If deviceIndex is set in devceMap requested by application */
2065  if (((deviceMap & (1U << index)) != 0U) && (retVal == RL_RET_CODE_OK))
2066  {
2067  /* reset to zero sequence number for that deviceIndex */
2068  rl_driverData.cmdSeqNum[index] = 0U;
2069  /* store the deviceIndex in a global structure */
2070  rl_driverData.commDevIdx.rlDevIndex[index] = index;
2071  /* Open communication interface handle */
2072  rl_driverData.commDevIdx.comIfHdl[index] =
2073  rl_driverData.clientCtx.comIfCb.rlComIfOpen(index, 0U);
2074 
2075  /* check for NULL pointer */
2076  if ((rlComIfHdl_t)RL_NULL_PTR == rl_driverData.commDevIdx.comIfHdl[index])
2077  {
2078  retVal += RL_RET_CODE_RADAR_IF_ERROR;
2079  }
2080  else
2081  {
2082  /* Register Host Interrupt Handler */
2083  if (rl_driverData.clientCtx.devCtrlCb.rlRegisterInterruptHandler(\
2084  index, (RL_P_EVENT_HANDLER)rlDriverHostIrqHandler, \
2085  (void*)RL_NULL) != RL_RET_CODE_OK)
2086  {
2087  retVal +=RL_RET_CODE_RADAR_IF_ERROR;
2088  }
2089  }
2090  /* Get next Device Map based on index */
2091  deviceMap &= ~(1U << index);
2092 
2093  /* check for any error */
2094  if (retVal != RL_RET_CODE_OK)
2095  {
2096  /* If error occured then break from this loop */
2097  break;
2098  }
2099  }
2100  /* increment Device Index */
2101  index++;
2102  }
2103  while ((deviceMap != 0U) && (index < RL_DEVICE_CONNECTED_MAX));
2104  }
2105  else
2106  {
2107  retVal = RL_RET_CODE_INVALID_INPUT;
2108  RL_LOGE_ARG0("Invaid input argument\n");
2109  }
2110 
2111  /* If no error during deviceInit then set the flag to 1 */
2112  if (retVal == RL_RET_CODE_OK)
2113  {
2114  rl_driverData.isDriverInitialized = 1U;
2115  RL_LOGD_ARG0("Driver init flag is set\n");
2116  }
2117  else
2118  {
2119  RL_LOGE_ARG0("rlDriverInit, Init failed\n");
2120  }
2121  return retVal;
2122 }
2123 
2134 /* DesignId : */
2135 /* Requirements : */
2136 rlReturnVal_t rlDriverAddDevice(rlUInt8_t deviceMap)
2137 {
2138  rlReturnVal_t retVal;
2139  rlUInt8_t index = 0U;
2140 
2141  RL_LOGV_ARG0("rlDriverAddDevice starts\n");
2142 
2143  if ((rl_driverData.isDriverInitialized != (rlUInt8_t)0U) && \
2144  (deviceMap <= ((1U << RL_DEVICE_CONNECTED_MAX) - 0x1U)))
2145  {
2146  /* Add to the global device map */
2147  rl_driverData.deviceMap |= deviceMap;
2148 
2149  do
2150  {
2151  /* If deviceIndex is set in devceMap requested by application */
2152  if ((deviceMap & (1U << index)) != 0U)
2153  {
2154  /* reset to zero sequence number for that deviceIndex */
2155  rl_driverData.cmdSeqNum[index] = 0U;
2156  /* store the deviceIndex in a global structure */
2157  rl_driverData.commDevIdx.rlDevIndex[index] = index;
2158  /* Open communication interface handle */
2159  rl_driverData.commDevIdx.comIfHdl[index] = \
2160  rl_driverData.clientCtx.comIfCb.rlComIfOpen(index, 0U);
2161 
2162  if ((rlComIfHdl_t)RL_NULL_PTR != rl_driverData.commDevIdx.comIfHdl[index])
2163  {
2164  /* register Interrupt handler */
2165  if ((rl_driverData.clientCtx.devCtrlCb.rlRegisterInterruptHandler(\
2166  index, (RL_P_EVENT_HANDLER)rlDriverHostIrqHandler, \
2167  (void*)RL_NULL) != RL_RET_CODE_OK) ||
2168  (rl_driverData.clientCtx.devCtrlCb.rlDeviceEnable(index) < 0))
2169  {
2170  /* set the error code */
2171  retVal = RL_RET_CODE_RADAR_IF_ERROR;
2172  }
2173  else
2174  {
2175  retVal = RL_RET_CODE_OK;
2176  }
2177  }
2178  else
2179  {
2180  retVal =RL_RET_CODE_RADAR_IF_ERROR;
2181  }
2182  deviceMap &= ~(1U << index);
2183  }
2184  else
2185  {
2186  retVal = RL_RET_CODE_OK;
2187  }
2188 
2189  /* break the loop if any error occured during above callbacks */
2190  if (RL_RET_CODE_OK != retVal)
2191  {
2192  break;
2193  }
2194  /* increment device index */
2195  index++;
2196  }
2197  while ((deviceMap != 0U) && (index < RL_DEVICE_CONNECTED_MAX));
2198  }
2199  else
2200  {
2201  if (deviceMap > ((1U << RL_DEVICE_CONNECTED_MAX) - 0x1U))
2202  {
2203  retVal = RL_RET_CODE_INVALID_INPUT;
2204  RL_LOGE_ARG0("Invalid input argument\n");
2205  }
2206  else
2207  {
2208  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
2209  RL_LOGE_ARG0("rlDriverAddDevice, Invalid state \n");
2210  }
2211  }
2212  RL_LOGV_ARG0("rlDriverAddDevice completes\n");
2213 
2214  return retVal;
2215 }
2216 
2227 /* DesignId : */
2228 /* Requirements : */
2229 rlReturnVal_t rlDriverRemoveDevices(rlUInt8_t deviceMap)
2230 {
2231  rlUInt8_t index;
2232  rlReturnVal_t retVal = RL_RET_CODE_OK;
2233 
2234  RL_LOGV_ARG0("rlDriverRemoveDevices starts...\n");
2235 
2236  /* Clear the device map from driver data */
2237  rl_driverData.deviceMap &= ~deviceMap;
2238 
2239  for (index = 0U; ((deviceMap != 0U) && (index < RL_DEVICE_CONNECTED_MAX));\
2240  index++)
2241  {
2242  if ((deviceMap & (1U << index)) != 0U)
2243  {
2244  /* Close mmwave radar device communication Channel */
2245  if (rl_driverData.commDevIdx.comIfHdl[index] != RL_NULL_PTR)
2246  {
2247  retVal += rl_driverData.clientCtx.comIfCb.rlComIfClose( \
2248  rl_driverData.commDevIdx.comIfHdl[index]);
2249  rl_driverData.commDevIdx.comIfHdl[index] = RL_NULL_PTR;
2250  }
2251 
2252  /* Un Register Interrupt Handler */
2253  (void)rl_driverData.clientCtx.devCtrlCb.rlRegisterInterruptHandler(
2254  index, RL_NULL, RL_NULL);
2255 
2256  deviceMap &= ~(1U << index);
2257  }
2258  }
2259  RL_LOGV_ARG0("rlDriverRemoveDevices completes\n");
2260  return retVal;
2261 }
2262 
2272 /* DesignId : */
2273 /* Requirements : AUTORADAR_REQ-711 */
2274 rlReturnVal_t rlDriverDeInit(void)
2275 {
2276  rlUInt8_t index, devCnt;
2277  rlUInt8_t deviceMap = rl_driverData.deviceMap;
2278  rlReturnVal_t retVal = RL_RET_CODE_OK;
2279 
2280  RL_LOGV_ARG0("rlDriverDeInit starts...\n");
2281 
2282  for (index = 0U; ((deviceMap != 0U) && (index < RL_DEVICE_CONNECTED_MAX));\
2283  index++)
2284  {
2285  if ((deviceMap & (1U << index)) != 0U)
2286  {
2287  /* Close mmwave radar device communication Channel */
2288  if (rl_driverData.commDevIdx.comIfHdl[index] != RL_NULL_PTR)
2289  {
2290  retVal += rl_driverData.clientCtx.comIfCb.rlComIfClose( \
2291  rl_driverData.commDevIdx.comIfHdl[index]);
2292  rl_driverData.commDevIdx.comIfHdl[index] = RL_NULL_PTR;
2293  }
2294 
2295  /* Un Register Interrupt Handler */
2296  (void)rl_driverData.clientCtx.devCtrlCb.rlRegisterInterruptHandler(
2297  index, RL_NULL, RL_NULL);
2298 
2299  deviceMap &= ~(1U << index);
2300  }
2301  }
2302  /* Destroy per command mutexes */
2303  for (devCnt = 0U; devCnt < RL_CASCADE_NUM_DEVICES; devCnt++)
2304  {
2305  /* AR_CODE_REVIEW MR:D.4.1 <REVIEWED> "function Pointer is being checked
2306  in rlDriverOsiCbCheck " */
2307  /*LDRA_INSPECTED 128 D */
2308  retVal += rl_driverData.clientCtx.osiCb.mutex.rlOsiMutexDelete(
2309  &rl_driverData.devMutex[devCnt]);
2310  rl_driverData.devMutex[devCnt] = RL_NULL_PTR;
2311 
2312  RL_LOGD_ARG0("Destroy Per CMD Mutex\n");
2313 
2314  /* Destroy Command Semaphore */
2315  if (rl_driverData.cmdSem[devCnt] != RL_NULL_PTR)
2316  {
2317  retVal += rl_driverData.clientCtx.osiCb.sem.rlOsiSemDelete(\
2318  &rl_driverData.cmdSem[devCnt]);
2319  rl_driverData.cmdSem[devCnt] = RL_NULL_PTR;
2320  RL_LOGD_ARG0("Destroy Command Semaphore\n");
2321  }
2322  }
2323 
2324  rl_driverData.deviceMap = 0U;
2325  rl_driverData.isDriverInitialized = 0U;
2326  RL_LOGV_ARG0("rlDriverDeInit ends...\n");
2327 
2328  return retVal;
2329 }
2330 
2339 /* DesignId : */
2340 /* Requirements : */
2342 {
2343  /* return driverData pointer/handle */
2344  return (&rl_driverData);
2345 }
2346 
2355 /* DesignId : */
2356 /* Requirements : */
2357 rlUInt8_t rlDriverGetPlatformId(void)
2358 {
2359  RL_LOGV_ARG0("rlDriverGetPlatformId is called \n");
2360  /* return platform ID */
2361  return (rl_driverData.clientCtx.platform);
2362 }
2363 
2364 
2373 /* DesignId : */
2374 /* Requirements : */
2376 {
2377  RL_LOGV_ARG0("rlDriverGetArDeviceType is called \n");
2378  /* return AWR device Type */
2379  return (rl_driverData.clientCtx.arDevType);
2380 }
2381 
2392 /* DesignId : */
2393 /* Requirements : */
2394 rlReturnVal_t rlDriverIsDeviceMapValid(rlUInt8_t deviceMap)
2395 {
2396  rlUInt8_t storedDevMap;
2397  rlReturnVal_t retVal;
2398 
2399  RL_LOGV_ARG0("rlDriverIsDeviceMapValid starts \n");
2400 
2401  /* get the no. of connected device */
2402  storedDevMap = rl_driverData.deviceMap;
2403 
2404  if ((storedDevMap & deviceMap) != 0U)
2405  {
2406  /* set return value to success */
2407  retVal = 0;
2408  }
2409  else
2410  {
2411  /* set return value to failure */
2412  retVal = -1;
2413  RL_LOGE_ARG0("Device map is In-valid \n");
2414  }
2415  RL_LOGV_ARG0("rlDriverIsDeviceMapValid ends \n");
2416 
2417  return retVal;
2418 }
2419 
2432 /* DesignId : MMWL_DesignId_024 */
2433 /* Requirements : AUTORADAR_REQ-774 */
2434 /*AR_CODE_REVIEW MR:R.2.2 <APPROVED> "payloadLen is re initialized after each pass to the
2435  rlGetSubBlock fucntion as it is passed again to the function" */
2436 /*LDRA_INSPECTED 8 D */
2437 rlReturnVal_t rlDriverWaitForResponse(rlUInt8_t devIndex,
2438  rlDriverMsg_t* outMsg)
2439 {
2440  rlUInt16_t rspChunks;
2441  rlPayloadSb_t errorSB;
2442  rlReturnVal_t retVal, retVal1;
2443  rlUInt16_t indx;
2444  rlUInt8_t payloadLen = 0U;
2445 
2446  RL_LOGV_ARG0("rlDriverWaitForResponse starts... \n");
2447 
2448  do
2449  {
2450  /* Wait for Host Interrupt and Read the Response */
2451  retVal1 = rlDriverMsgReadCmdCtx(devIndex);
2452  if (RL_RET_CODE_OK == retVal1)
2453  {
2454  /* Get number of chunks in the response */
2455  rspChunks = rl_rxMsg[devIndex].hdr.remChunks;
2456 
2457  /* Check if Number of Sub Block doesn't exceed expected number */
2458  if (outMsg->opcode.nsbc >= rl_rxMsg[devIndex].hdr.nsbc)
2459  {
2460  outMsg->opcode.nsbc = rl_rxMsg[devIndex].hdr.nsbc;
2461  /* Loop for number of chunks and copy payload */
2462  for (indx = 0U; indx < (outMsg->opcode.nsbc); indx++)
2463  {
2464  /* Copy Payload to output variable*/
2465  /* AR_CODE_REVIEW MR:R.18.4 <APPROVED> "pointer arithmetic required" */
2466  /*LDRA_INSPECTED 87 S */
2467  (void)rlGetSubBlock(rl_rxMsg[devIndex].payload + payloadLen,
2468  &(outMsg->subblocks[indx].sbid),
2469  &(outMsg->subblocks[indx].len),
2470  outMsg->subblocks[indx].pSblkData);
2471  payloadLen += (rlUInt8_t)(outMsg->subblocks[indx].len);
2472 
2473  }
2474  }
2475  retVal = retVal1;
2476  }
2477  else if (RL_RET_CODE_MSGID_MISMATCHED == retVal1)
2478  {
2479  /* Number of Sub Block is unexpected. Error Case */
2480  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function.
2481  LDRA Tool Issue" */
2482  /*LDRA_INSPECTED 105 D */
2483  rlErrorResp_t errMsgSbData = {(rlSysNRespType_t)0U, (rlUInt16_t)0U};
2484  /* Initialize with zero which will set with valid value in next function call */
2485  errorSB.sbid = 0U;
2486  errorSB.len = 0U;
2487  errorSB.pSblkData = (rlUInt8_t* )&errMsgSbData;
2488 
2489  /* Copy Payload to local variable*/
2490  /* AR_CODE_REVIEW MR:R.18.4 <APPROVED> "pointer arithmetic required" */
2491  /*LDRA_INSPECTED 87 S */
2492  (void)rlGetSubBlock(rl_rxMsg[devIndex].payload + payloadLen,
2493  &(errorSB.sbid), &(errorSB.len),
2494  errorSB.pSblkData);
2495 
2496  /* Return Error to indicate command failure */
2497  retVal = (rlReturnVal_t)(errMsgSbData.errorType);
2498  rspChunks = 0U;
2499 
2500  RL_LOGE_ARG0("msg id mis-match, command failure\n");
2501 
2502  }
2503  else
2504  {
2505  /* Timeout in receiving response*/
2506  rspChunks = 0U;
2507  retVal = retVal1;
2508  RL_LOGE_ARG0("Timeout in receiving response\n");
2509  }
2510  }
2511  while (rspChunks > 0U);
2512 
2513  RL_LOGV_ARG0("rlDriverWaitForResponse ends... \n");
2514 
2515  return retVal;
2516 }
2517 
2518 static rlReturnVal_t rlDriverCmdWriter(rlUInt8_t devIndex, rlDriverMsg_t* outMsg)
2519 {
2520  rlReturnVal_t retVal;
2521  rlUInt8_t retryCount = 0U;
2522  rlDriverData_t *rlDrvData = rlDriverGetHandle();
2523  rlUInt8_t isPayloadValid = RL_FALSE, isNackRetry = RL_FALSE;
2524 
2525  do
2526  {
2527  if ((retryCount != 0U) && (isNackRetry == RL_FALSE))
2528  {
2529  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by
2530  other function" */
2531  /*LDRA_INSPECTED 105 D */
2532  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData Can't be NULL" */
2533  /*LDRA_INSPECTED 45 D */
2534  rlDrvData->txMsgPtr[devIndex]->hdr.flags.b2RetryFlag = RL_HDR_FLAG_RETRY;
2535  }
2536  retryCount++;
2537 
2538  if ( rlDrvData->clientCtx.ackTimeout != 0U)
2539  {
2540  /* Set flag to true and check for it in Host IRQ handler routine*/
2541  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by
2542  other function" */
2543  /*LDRA_INSPECTED 105 D */
2544  rlDrvData->isCmdRespWaited[devIndex] = RL_TRUE;
2545  }
2546  /* send the command to mmWave Radar device */
2547  retVal = rlDriverMsgWrite(rlDrvData, devIndex, rlDrvData->commDevIdx.comIfHdl[devIndex]);
2548 
2549  if (RL_RET_CODE_OK == retVal)
2550  {
2551  /* Check if It needs to wait for ACK*/
2552  if (rlDrvData->clientCtx.ackTimeout != 0U)
2553  {
2554  /* wait for respond */
2555  retVal += rlDriverWaitForResponse(devIndex, outMsg);
2556  RL_LOGD_ARG0("rlDriverCmdWriter, wait for respond\n");
2557  }
2558 
2559  /* Response received Successfully */
2560  if ((RL_RET_CODE_OK == retVal) || \
2561  ((RL_RET_CODE_CRC_FAILED != retVal) && \
2562  (RL_RET_CODE_RESP_TIMEOUT != retVal)))
2563  {
2564  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by
2565  other function" */
2566  /*LDRA_INSPECTED 105 D */
2567  rlDrvData->isCmdRespWaited[devIndex] = RL_FALSE;
2568  /* Increment the Sequence Number */
2569  rlDrvData->cmdSeqNum[devIndex]++;
2570  /* If device sends NACK then mmWaveLink needs to resend same
2571  command with incremented seqNum but no RETRY-Flag */
2572  if (RL_RET_CODE_NACK_ERROR == retVal)
2573  {
2574  /* Set the flag */
2575  isNackRetry = RL_TRUE;
2576  /* Modulo on cmdSeqNum (4Bits field) and fill Command Sequence Number */
2577  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used
2578  by other function" */
2579  /*LDRA_INSPECTED 105 D */
2580  /*LDRA_INSPECTED 8 D */
2581  rlDrvData->txMsgPtr[devIndex]->hdr.flags.b4SeqNum =
2582  rlDrvData->cmdSeqNum[devIndex] % 16U;
2583  }
2584  else
2585  {
2586  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Set to TRUE for valid payload" */
2587  /*LDRA_INSPECTED 8 D */
2588  isPayloadValid = RL_TRUE;
2589  /* Reset the flag */
2590  isNackRetry = RL_FALSE;
2591  }
2592  }
2593  else
2594  {
2595  /* if return value is not NACK_ERROR then reset this flag */
2596  isNackRetry = RL_FALSE;
2597  }
2598  }
2599  else
2600  {
2601  /* Error in command message write */
2602  if (rlDrvData->clientCtx.ackTimeout != 0U)
2603  {
2604  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by
2605  other function" */
2606  /*LDRA_INSPECTED 105 D */
2607  rlDrvData->isCmdRespWaited[devIndex] = RL_FALSE;
2608  }
2609  RL_LOGE_ARG0("rlDriverCmdWriter, Error in cmd msg write\n");
2610  break;
2611  }
2612  }
2613  while ((retryCount < (rl_driverData.retryCount + 1U)) && (isPayloadValid == RL_FALSE));
2614 
2615  return retVal;
2616 }
2617 
2629 /* DesignId : MMWL_DesignId_023 */
2630 /* Requirements : AUTORADAR_REQ-772, AUTORADAR_REQ-774, AUTORADAR_REQ-775, AUTORADAR_REQ-778,\
2631  AUTORADAR_REQ-781 */
2632 rlReturnVal_t rlDriverCmdSendRetry(rlUInt8_t devIndex, rlDriverMsg_t* outMsg)
2633 {
2634  rlReturnVal_t retVal;
2635  rlDriverData_t *rlDrvData = rlDriverGetHandle();
2636 
2637  if (rlDrvData == RL_NULL)
2638  {
2639  retVal = RL_RET_CODE_FATAL_ERROR;
2640  }
2641  else
2642  {
2643  retVal = RL_RET_CODE_OK;
2644  }
2645 
2646  /* Send Command to Device connected and wait for response one by one */
2647  /* AR_CODE_REVIEW MR:D.2.1 <APPROVED> "This loop terminates when it sends commands to all
2648  * connected devices or when any of devices returns -ve response" */
2649  /*LDRA_INSPECTED 28 D */
2650  /* Fill Command Sequence Number */
2651  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by other function" */
2652  /*LDRA_INSPECTED 105 D */
2653  /*LDRA_INSPECTED 8 D */
2654  rlDrvData->txMsgPtr[devIndex]->hdr.flags.b4SeqNum =
2655  rlDrvData->cmdSeqNum[devIndex] % 16U;
2656 
2657  /* Write command to slave device */
2658  retVal += rlDriverCmdWriter(devIndex, outMsg);
2659 
2660  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by other function" */
2661  /*LDRA_INSPECTED 105 D */
2662  rlDrvData->isCmdRespWaited[devIndex] = RL_FALSE;
2663 
2664  return retVal;
2665 }
2666 
2677 /* DesignId : MMWL_DesignId_023 */
2678 /* Requirements : AUTORADAR_REQ-772, AUTORADAR_REQ-774, AUTORADAR_REQ-776 */
2679 static void rlDriverAppendDummyByte(rlUInt8_t devIndex)
2680 {
2681  rlUInt8_t protAlignSize;
2682  rlUInt16_t msgCrcLen;
2683 
2684  rl_txMsg[devIndex].hdr.flags.b2CrcLen = rl_driverData.clientCtx.crcType;
2685 
2686  /* It may be size 2/4/8 based on 16/32/64 bit */
2687  msgCrcLen = (2U << (rl_driverData.clientCtx.crcType & 0x3U));
2688 
2689  protAlignSize = (rl_driverData.clientCtx.crcType < RL_CRC_TYPE_64BIT_ISO) ? \
2690  RL_PAYLOAD_MSG_4BYTE_MULT : RL_PAYLOAD_MSG_8BYTE_MULT;
2691 
2692  /* cmd pointer is assigned to rl_rxMsg, which can't be NULL as it's global structure. */
2693  if (rl_driverData.txMsgPtr[devIndex] != RL_NULL_PTR)
2694  {
2695  /* Add Padding Byte to payload - This is required before CRC calculation*/
2696  if ((rl_driverData.txMsgPtr[devIndex]->hdr.len % protAlignSize) != 0U)
2697  {
2698  /* AR_CODE_REVIEW MR:R.18.1,R.18.4 <APPROVED> "pointer arithmetic required" */
2699  /*LDRA_INSPECTED 567 S */
2700  /* AR_CODE_REVIEW MR:R.10.3 <APPROVED> "All parameter types are matching to
2701  function argument type. LDRA tool issue." */
2702  /*LDRA_INSPECTED 458 S */
2703  /*LDRA_INSPECTED 87 S */
2704  /* AR_CODE_REVIEW MR:R.11.1 <INSPECTED> "Conversion required." */
2705  /*LDRA_INSPECTED 95 S */
2706  /*LDRA_INSPECTED 440 S */
2707  /*LDRA_INSPECTED 93 S */
2708  (void)rlAppendDummy((rlUInt8_t*)(((rlUInt8_t*)rl_driverData.txMsgPtr[devIndex]) + \
2709  rl_driverData.txMsgPtr[devIndex]->hdr.len + SYNC_PATTERN_LEN), \
2710  (rlUInt8_t)(protAlignSize - \
2711  (rlUInt8_t)(rl_driverData.txMsgPtr[devIndex]->hdr.len % protAlignSize)));
2712  rl_driverData.txMsgPtr[devIndex]->hdr.len += (rlUInt16_t)(protAlignSize - \
2713  (rlUInt16_t)(rl_driverData.txMsgPtr[devIndex]->hdr.len % protAlignSize));
2714  }
2715  /* add on crc length to header length field */
2716  rl_driverData.txMsgPtr[devIndex]->hdr.len += msgCrcLen;
2717  }
2718  return;
2719 }
2720 
2737 /* DesignId : MMWL_DesignId_023 */
2738 /* Requirements : AUTORADAR_REQ-772, AUTORADAR_REQ-774, AUTORADAR_REQ-776 */
2739 rlReturnVal_t rlDriverCmdInvoke(rlUInt8_t deviceMap, rlDriverMsg_t inMsg,
2740  rlDriverMsg_t* outMsg)
2741 {
2742  rlReturnVal_t retVal = RL_RET_CODE_OK;
2743  rlUInt8_t devIndex = 0U;
2744  rlUInt16_t indx;
2745  rlUInt16_t payloadLen;
2746 
2747  RL_LOGV_ARG0("rlDriverCmdInvoke starts... \n");
2748 
2749  if (rl_driverData.isDriverInitialized != (rlUInt8_t)0U)
2750  {
2751  /* AR_CODE_REVIEW MR:R.2.1 <APPROVED> "This loop terminates when it sends commands to all
2752  * connected devices or when any of devices returns -ve response" */
2753  /*LDRA_INSPECTED 28 D */
2754  while ((deviceMap != 0U) && (RL_RET_CODE_OK == retVal))
2755  {
2756  if ((deviceMap & (1U << devIndex)) != 0U)
2757  {
2758  /* If Mutex lock is failed then return with error code */
2759  if (RL_RET_CODE_OK != rl_driverData.clientCtx.osiCb.mutex.rlOsiMutexLock
2760  (&(rl_driverData.devMutex[devIndex]), (rlOsiTime_t)RL_OSI_WAIT_FOREVER))
2761  {
2762  /* If MutexLock returns non-zero then treat this as error and
2763  set error code to retVal */
2764  retVal = RL_RET_CODE_RADAR_OSIF_ERROR;
2765  }
2766  else
2767  {
2768  rlReturnVal_t retVal1 = RL_RET_CODE_OK;
2769 
2770  payloadLen = 0U;
2771  /* Fill Command Header */
2772  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Some of variables are re-assigned based
2773  on different conditions."*/
2774  /*LDRA_INSPECTED 8 D */
2775  rl_txMsg[devIndex].hdr.opcode.b4Direction = inMsg.opcode.dir;
2776  rl_txMsg[devIndex].hdr.opcode.b2MsgType = inMsg.opcode.msgType;
2777  rl_txMsg[devIndex].hdr.opcode.b10MsgId = \
2778  ((rl_txMsg[devIndex].hdr.opcode.b10MsgId & 0x000U)|\
2779  (inMsg.opcode.msgId & 0x3FFU));
2780  rl_txMsg[devIndex].hdr.remChunks = inMsg.remChunks;
2781  rl_txMsg[devIndex].hdr.nsbc = inMsg.opcode.nsbc;
2782  rl_txMsg[devIndex].hdr.flags.b2AckFlag = 0U;
2783  rl_txMsg[devIndex].hdr.flags.b2Crc = 0U;
2784  rl_txMsg[devIndex].hdr.flags.b2CrcLen = 0U;
2785  rl_txMsg[devIndex].hdr.flags.b2RetryFlag = 0U;
2786  rl_txMsg[devIndex].hdr.flags.b4SeqNum = 0U;
2787  rl_txMsg[devIndex].hdr.flags.b4Version = 0U;
2788 
2789  /* Fill Payload */
2790  for (indx = 0U; indx < inMsg.opcode.nsbc; indx++)
2791  {
2792  /* append all subblock len, id and data to one global structure */
2793  retVal1 += rlAppendSubBlock(&rl_txMsg[devIndex].payload[payloadLen],
2794  inMsg.subblocks[indx].sbid,
2795  inMsg.subblocks[indx].len,
2796  inMsg.subblocks[indx].pSblkData);
2797  /* increment payload length as appending each sub-block data in a
2798  message */
2799  payloadLen += inMsg.subblocks[indx].len + \
2800  (rlUInt16_t)(RL_SBC_ID_SIZE + RL_SBC_LEN_SIZE);
2801  if (RL_RET_CODE_OK != retVal1)
2802  {
2803  break;
2804  }
2805  }
2806 
2807  /* if above for loop is not terminated due to any error */
2808  if (indx == inMsg.opcode.nsbc)
2809  {
2810  rl_txMsg[devIndex].hdr.len = RHCP_HEADER_LEN + payloadLen;
2811 
2812  /* Check if ACK is Requested*/
2813  if (rl_driverData.clientCtx.ackTimeout == 0U)
2814  {
2815  /* No ACK Requested */
2816  rl_txMsg[devIndex].hdr.flags.b2AckFlag = RL_HDR_FLAG_NO_ACK;
2817  }
2818 
2819  /* Check if CRC is required to be sent*/
2820  if (rl_driverData.clientCtx.crcType == RL_CRC_TYPE_NO_CRC)
2821  {
2822  /* CRC Not Included */
2823  rl_txMsg[devIndex].hdr.flags.b2Crc = RL_HDR_FLAG_NO_CRC;
2824  }
2825 
2826  /* Append Dummy Bytes if CRC is present */
2827  if (rl_txMsg[devIndex].hdr.flags.b2Crc == RL_HDR_FLAG_CRC)
2828  {
2829  rlDriverAppendDummyByte(devIndex);
2830  }
2831 
2832  retVal = rlDriverCmdSendRetry(devIndex, outMsg);
2833  /* Release the per CMD Mutex */
2834  (void)rl_driverData.clientCtx.osiCb.mutex.rlOsiMutexUnLock(\
2835  &(rl_driverData.devMutex[devIndex]));
2836  }
2837  else
2838  {
2839  retVal = retVal1;
2840  }
2841  }
2842  deviceMap &= ~(1U << devIndex);
2843  } /* End if */
2844  devIndex++;
2845  } /* End while */
2846  }
2847  else
2848  {
2849  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
2850  RL_LOGE_ARG0("rlDriverCmdInvoke, Invalid input \n");
2851  }
2852 
2853  RL_LOGV_ARG0("rlDriverCmdInvoke ends... \n");
2854 
2855  return retVal;
2856 }
2857 
2867 rlReturnVal_t rlDriverConfigureCrc(rlCrcType_t crcType)
2868 {
2869  rlReturnVal_t retVal;
2870 
2871  RL_LOGV_ARG0("rlDriverConfigureCrc starts... \n");
2872  /* Check if driver is initialized */
2873  if (rl_driverData.isDriverInitialized == 1U)
2874  {
2875  /* Set CRC Type to global structure */
2876  rl_driverData.clientCtx.crcType = crcType;
2877  RL_LOGD_ARG0("rlDriverConfigureCrc is success\n");
2878  retVal = RL_RET_CODE_OK;
2879  }
2880  else
2881  {
2882  /* if driver is not initialized then return and error value */
2883  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
2884  }
2885  RL_LOGV_ARG0("rlDriverConfigureCrc ends... \n");
2886 
2887  return retVal;
2888 }
2889 
2899 /* DesignId : */
2900 /* Requirements : */
2901 rlReturnVal_t rlDriverConfigureAckTimeout(rlUInt32_t ackTimeout)
2902 {
2903  rlReturnVal_t retVal;
2904 
2905  RL_LOGV_ARG0("rlDriverConfigureAckTimeout starts... \n");
2906  /* Check if driver is initialized */
2907  if (rl_driverData.isDriverInitialized == 1U)
2908  {
2909  /* set ACK timeout to global structure */
2910  rl_driverData.clientCtx.ackTimeout = ackTimeout;
2911  RL_LOGD_ARG0("rlDriverConfigureAckTimeout is success\n");
2912  retVal = RL_RET_CODE_OK;
2913  }
2914  else
2915  {
2916  /* if driver is not initialized then return and error value */
2917  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
2918  }
2919  RL_LOGV_ARG0("rlDriverConfigureAckTimeout ends... \n");
2920 
2921  return retVal;
2922 }
2923 
2934 /* DesignId : */
2935 /* Requirements : */
2936 rlPrintFptr rlGetLogFptr(rlUInt8_t dbgLevel)
2937 {
2938  rlPrintFptr retFuncPtr;
2939  if (dbgLevel > 0U)
2940  {
2941  /* If debug level is valid the set debug function pointer */
2942  retFuncPtr = rl_driverData.logObj.rlPrintAr[dbgLevel - (rlUInt8_t)1U];
2943  }
2944  else
2945  {
2946  /* If debug level is valid the set debug function pointer to NULL */
2947  retFuncPtr = RL_NULL_PTR;
2948  }
2949 
2950  return retFuncPtr;
2951 }
2952 
2962 /* DesignId : MMWL_DesignId_031 */
2963 /* Requirements : AUTORADAR_REQ-712 */
2964 rlReturnVal_t rlLogInit(void)
2965 {
2966  rlReturnVal_t retVal;
2967  rlDriverData_t* rlDrvData = &rl_driverData;
2968  rlPrintFptr fPtr;
2969  rlUInt8_t level, idx;
2970  /* store debug level to local variable */
2971  level = rlDrvData->clientCtx.dbgCb.dbgLevel;
2972  /* store Function pointer to local variable */
2973  fPtr = rlDrvData->clientCtx.dbgCb.rlPrint;
2974 
2975  /* check for Function pointer for NON-NULL */
2976  if (fPtr != RL_NULL_PTR)
2977  {
2978  switch (level)
2979  {
2980  case RL_DBG_LEVEL_VERBOSE :
2981  case RL_DBG_LEVEL_DEBUG :
2982  case RL_DBG_LEVEL_INFO :
2983  case RL_DBG_LEVEL_WARNING :
2984  case RL_DBG_LEVEL_ERROR :
2985  case RL_DBG_LEVEL_DATABYTE:
2986  for (idx = level; idx > RL_DBG_LEVEL_NONE; idx--)
2987  {
2988  rlDrvData->logObj.rlPrintAr[idx - 1U] = fPtr;
2989  }
2990  break;
2991  case RL_DBG_LEVEL_NONE :
2992  {
2993  (void)fPtr("INFO: MMWAVELINK Logging is disabled\n");
2994  /* reset all function pointers to NULL */
2995  (void)memset(&rlDrvData->logObj.rlPrintAr[0], 0U, sizeof(rlLogCtx_t));
2996  break;
2997  }
2998  default :
2999  {
3000  (void)fPtr("INFO: Invalid MMWAVELINK Logging, hence disbled\n");
3001  /* if dbgLevel is set beyond expected value then assign NONE */
3002  rlDrvData->clientCtx.dbgCb.dbgLevel = RL_DBG_LEVEL_NONE;
3003 
3004  /* reset all function pointers to NULL */
3005  (void)memset(&rlDrvData->logObj.rlPrintAr[0], 0U, sizeof(rlLogCtx_t));
3006  break;
3007  }
3008  }
3009  retVal = RL_RET_CODE_OK;
3010  }
3011  else
3012  {
3013  /* reset all function pointers to NULL */
3014  (void)memset(&rlDrvData->logObj.rlPrintAr[0], 0U, sizeof(rlLogCtx_t));
3015  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
3016  }
3017 
3018  return retVal;
3019 }
3020 
3033 void rlDriverConstructInMsg(rlUInt16_t msgId, rlDriverMsg_t* inMsg, rlPayloadSb_t* payloadPtr)
3034 {
3035  /* check for NULL pointer */
3036  if (inMsg != NULL)
3037  {
3038  rlUInt8_t cmdDir;
3039  /* Set Command Header Opcode */
3040  inMsg->opcode.nsbc = 1U;
3041  inMsg->opcode.msgType = RL_API_CLASS_CMD;
3042  inMsg->opcode.msgId = msgId;
3043  inMsg->remChunks = 0U;
3044  /* get command direction based on requested MsgId */
3045  cmdDir = rlDeviceIdentifyCmdDir(msgId, rlDriverGetPlatformId());
3046  inMsg->opcode.dir = cmdDir;
3047  inMsg->subblocks = payloadPtr;
3048  }
3049  else
3050  {
3051  /* Error: iutMsg is sent as NULL */
3052  RL_LOGV_ARG0("rlDriverConstructInMsg construct InMsg failed!!!\n");
3053  }
3054 }
3055 
3068 void rlDriverConstructOutMsg(rlUInt16_t numSblk, rlDriverMsg_t* outMsg,
3069  rlPayloadSb_t* payloadPtr)
3070 {
3071  /* check for NULL pointer */
3072  if (outMsg != NULL)
3073  {
3074  /* Set num of sub-block to outMsg Opcode field */
3075  outMsg->opcode.nsbc = numSblk;
3076  /* assign payload pointer to subblock ot outMsg */
3077  outMsg->subblocks = payloadPtr;
3078  }
3079  else
3080  {
3081  /* Error: outMsg is sent as NULL */
3082  RL_LOGV_ARG0("rlDriverConstructOutMsg construct OutMsg failed!!!\n");
3083  }
3084 }
3085 
3099 void rlDriverFillPayload(rlUInt16_t msgId, rlUInt16_t sbcID, rlPayloadSb_t* payloadPtr,
3100  rlUInt8_t* data, rlUInt16_t inLen)
3101 {
3102  /* check for NULL pointer */
3103  if (payloadPtr != NULL)
3104  {
3105  /* get Unique Sub-Block ID and asign it to Command Sub Block */
3106  payloadPtr->sbid = (rlUInt16_t)RL_GET_UNIQUE_SBID(msgId, sbcID);
3107 
3108  /* set Command Sub-block length to sizeof command strcuture type */
3109  payloadPtr->len = inLen;
3110  /* set sub-block data pointer to payload structure */
3111  payloadPtr->pSblkData = data;
3112  }
3113  else
3114  {
3115  RL_LOGV_ARG0("rlDriverFillPayload data fill failed!!!\n");
3116  }
3117 }
3118 
3132 rlReturnVal_t rlDriverExecuteGetApi(rlUInt8_t deviceMap, rlUInt16_t msgId,
3133  rlUInt16_t sbcID, rlUInt8_t *msgData, rlUInt16_t inLen)
3134 {
3135  /*LDRA waiver 8 D - DD data flow anomalies found- */
3136  rlReturnVal_t retVal;
3137  /* Initialize Command and Response Sub Blocks */
3138  /* Initialize in-message structure to zero */
3139  rlDriverMsg_t inMsg = {0};
3140  /* Initialize out-message structure to zero */
3141  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function. LDRA Tool Issue" */
3142  /*LDRA_INSPECTED 105 D */
3143  rlDriverMsg_t outMsg = {0};
3144  /* Initialize in-payload sub-block structure to zero */
3145  rlPayloadSb_t inPayloadSb = {0};
3146  /* Initialize out-payload sub-block structure to zero */
3147  rlPayloadSb_t outPayloadSb = {0};
3148 
3149  /* Construct command packet */
3150  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function. LDRA Tool Issue" */
3151  /*LDRA_INSPECTED 8 D */
3152  rlDriverConstructInMsg(msgId, &inMsg, &inPayloadSb);
3153 
3154  /* Fill in-message Payload */
3155  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function. LDRA Tool Issue" */
3156  /*LDRA_INSPECTED 105 D */
3157  rlDriverFillPayload(msgId, sbcID, &inPayloadSb, NULL , 0U);
3158 
3159  /* Construct response packet */
3160  rlDriverConstructOutMsg(1U, &outMsg, &outPayloadSb);
3161 
3162  /* Fill out-message Payload */
3163  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function. LDRA Tool Issue" */
3164  /*LDRA_INSPECTED 105 D */
3165  rlDriverFillPayload(0U, 0U, &outPayloadSb, msgData, inLen);
3166 
3167  /* Send Command to mmWave Radar Device */
3168  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "Can't be NULL" */
3169  /*LDRA_INSPECTED 45 D */
3170  retVal = rlDriverCmdInvoke(deviceMap, inMsg, &outMsg);
3171 
3172  return retVal;
3173 }
3174 
3188 rlReturnVal_t rlDriverExecuteSetApi(rlUInt8_t deviceMap, rlUInt16_t msgId,
3189  rlUInt16_t sbcID, rlUInt8_t *msgData, rlUInt16_t inLen)
3190 {
3191  /*LDRA waiver 8 D - DD data flow anomalies found- */
3192  rlReturnVal_t retVal;
3193  /* Initialize in-message structure to zero */
3194  rlDriverMsg_t inMsg = {0};
3195  /* Initialize out-message structure to zero */
3196  rlDriverMsg_t outMsg = {0};
3197  /* Initialize in-payload sub-block structure to zero */
3198  rlPayloadSb_t inPayloadSb = {0};
3199 
3200  /* Construct command packet */
3201  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are updated in other function.
3202  LDRA Tool Issue" */
3203  /*LDRA_INSPECTED 8 D */
3204  rlDriverConstructInMsg(msgId, &inMsg, &inPayloadSb);
3205 
3206  /* Fill in-message Payload */
3207  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function.
3208  LDRA Tool Issue" */
3209  /*LDRA_INSPECTED 105 D */
3210  rlDriverFillPayload(msgId, sbcID, &inPayloadSb, msgData, inLen);
3211 
3212  /* Send Command to mmWave Radar Device */
3213  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "Can't be NULL" */
3214  /*LDRA_INSPECTED 45 D */
3215  retVal = rlDriverCmdInvoke(deviceMap, inMsg, &outMsg);
3216 
3217  return retVal;
3218 }
3219 
3230 rlReturnVal_t rlDriverSetRetryCount(rlUInt8_t retryCnt)
3231 {
3232  rlReturnVal_t retVal;
3233 
3234  RL_LOGV_ARG0("rlDriverSetRetryCount starts... \n");
3235  /* Check if driver is initialized */
3236  if (rl_driverData.isDriverInitialized == 1U)
3237  {
3238  if (retryCnt <= RL_API_CMD_RETRY_COUNT)
3239  {
3240  /* set command retry count to global structure */
3241  rl_driverData.retryCount = retryCnt;
3242  RL_LOGD_ARG0("rlDriverSetRetryCount is success\n");
3243  retVal = RL_RET_CODE_OK;
3244  }
3245  else
3246  {
3247  /* Retry count can be set to max pre-defined value,
3248  * else return an error
3249  */
3250  retVal = RL_RET_CODE_INVALID_INPUT;
3251  }
3252  }
3253  else
3254  {
3255  /* if driver is not initialized then return and error value */
3256  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
3257  }
3258  RL_LOGV_ARG0("rlDriverSetRetryCount ends... \n");
3259 
3260  return retVal;
3261 }
3262 
3276 /*AR_CODE_REVIEW MR:D.2.2 <INSPECTED> "offset is used for the tempBuff" */
3277 /*LDRA_INSPECTED 65 D *//*LDRA_INSPECTED 8 D */
3278 void rlLogSpiReadWrite(rlUInt8_t deviceIdx, rlUInt8_t *pBuffer, \
3279  rlUInt32_t BufferLength, rlUInt8_t readEn)
3280 {
3281  rlUInt8_t tempBuff[2048] = {0};
3282  rlInt32_t offset = 0, index = 0, tempIdx;
3283 
3284  while (index < (rlInt32_t)BufferLength)
3285  {
3286  /*AR_CODE_REVIEW MR:R.18.1 <INSPECTED> "Accessing pointer as array"*/
3287  /*LDRA_INSPECTED 436 S *//*LDRA_INSPECTED 436 S *//*LDRA_INSPECTED 124 D */
3288  tempIdx = sprintf((rlInt8_t*)&tempBuff[offset], "0x%02X%02X ", \
3289  pBuffer[index + 1], pBuffer[index]);
3290  offset += tempIdx;
3291  index += 2;
3292  }
3293  sprintf((rlInt8_t*)&tempBuff[offset], "\r");
3294 
3295  if (readEn == RL_SPI_LOG_WRITE)
3296  {
3297  RL_LOGDB_ARG2("Device [%d] [WR]%s", deviceIdx, tempBuff);
3298  }
3299  else
3300  {
3301  RL_LOGDB_ARG2("Device [%d] [RD]%s", deviceIdx, tempBuff);
3302  }
3303 }
3304 
3305 /*
3306  * END OF rl_driver.c FILE
3307  */
rlReturnVal_t rlDriverMsgWrite(rlDriverData_t *rlDrvData, rlUInt8_t devIndex, rlComIfHdl_t comIfHdl)
Write command header and payload data over communication channel.
Definition: rl_driver.c:1469
rlReturnVal_t rlDriverMsgReadCmdCtx(rlUInt8_t devIndex)
Wait and handle command response.
Definition: rl_driver.c:980
rlUInt16_t b2MsgType
Msg Type.
Definition: rl_protocol.h:108
rlUInt16_t b2Crc
00 - CRC present, 11 - CRC not Present
Definition: rl_protocol.h:157
rlOsiCbs_t osiCb
Operating System Callback.
Definition: mmwavelink.h:1538
mmWaveLink client callback structure
Definition: mmwavelink.h:1529
volatile rlUInt8_t isCmdRespWaited[RL_DEVICE_CONNECTED_MAX]
Driver Command Wait Flag.
Definition: rl_driver.h:258
rlUInt8_t dir
Message Direction.
Definition: rl_driver.h:337
rlRhcpMsg_t * txMsgPtr[RL_CASCADE_NUM_DEVICES]
Tx message buffer pointer.
Definition: rl_driver.h:307
rlInt32_t(* rlDeviceEnable)(rlUInt8_t deviceIndex)
Bring mmWave radar device out of Reset.
Definition: mmwavelink.h:1404
rlReturnVal_t rlDriverMsgCmdReply(rlDriverData_t *rlDrvData, rlUInt8_t devIndex)
Wait and handle command response.
Definition: rl_driver.c:846
rlUInt8_t rlDeviceIdentifyCmdDir(rlUInt16_t msgId, rlUInt8_t platform)
Get the direction of command packet based on MsgID and platform.
Definition: rl_driver.c:412
rlReturnVal_t rlDriverConfigureCrc(rlCrcType_t crcType)
Configures the CRC Type in mmwavelink Driver.
Definition: rl_driver.c:2867
rlUInt8_t platform
0x0: mmWaveLink runs on Ext Host, 0x1: mmWaveLink runs on MSS, 0x2: mmWaveLink runs on DSS
Definition: mmwavelink.h:1575
void rlLogSpiReadWrite(rlUInt8_t deviceIdx, rlUInt8_t *pBuffer, rlUInt32_t BufferLength, rlUInt8_t readEn)
: Logging SPI Read/Write command
Definition: rl_driver.c:3278
rlOpcode_t opcode
rlUInt16_t, rlApiActionType,rlApiGetSetType
Definition: rl_protocol.h:214
volatile rlUInt8_t rxIrqCnt[RL_DEVICE_CONNECTED_MAX]
Driver Host Interrupt count.
Definition: rl_driver.h:266
rlUInt8_t msgType
Message Class.
Definition: rl_driver.h:341
void rlDriverConstructOutMsg(rlUInt16_t numSblk, rlDriverMsg_t *outMsg, rlPayloadSb_t *payloadPtr)
: Construct command packet based on given message-ID and payload
Definition: rl_driver.c:3068
rlUInt8_t rlDevIndex[RL_DEVICE_CONNECTED_MAX]
stores device Index
Definition: rl_driver.h:227
rlUInt32_t ackTimeout
ACK wait timeout in Milliseconds, 0 - No ACK Configuration of the timeout should consider interrupt l...
Definition: mmwavelink.h:1569
rlUInt16_t msgId
Message Id.
Definition: rl_driver.h:345
rlUInt16_t cmdSeqNum[RL_DEVICE_CONNECTED_MAX]
Driver command sequnce number.
Definition: rl_driver.h:274
rlOsiMsgQCbs_t queue
OS message queue/Spawn callback functions.
Definition: mmwavelink.h:1315
rlUInt8_t rlDriverGetPlatformId(void)
Returns RL Platform ID (i.e. where mmWaveLink is executing)
Definition: rl_driver.c:2357
volatile rlUInt8_t rxDoneCnt[RL_DEVICE_CONNECTED_MAX]
Driver serviced Host Interrupt count.
Definition: rl_driver.h:270
rlUInt16_t b2CrcLen
Length of CRC appended to the message 00 16-bit CRC 01 32-bit CRC 10 64-bit CRC 11 Reserved.
Definition: rl_protocol.h:165
rlLogCtx_t logObj
As per debug level callback functions will be assinged.
Definition: rl_driver.h:298
rlUInt8_t isRespWriteWaited[RL_DEVICE_CONNECTED_MAX]
if writing a data waits for Host IRQ
Definition: rl_driver.h:262
rlReturnVal_t rlDriverCalCRC(rlUInt8_t *data, rlUInt16_t dataLen, rlUInt8_t crcType, rlUInt8_t crc[RL_CRC_LEN_MAX])
Calculates 16bit/32bit/64bit CRC.
Definition: rl_driver.c:209
rlComIfCbs_t comIfCb
Comunication Interface Callback.
Definition: mmwavelink.h:1534
rlOsiSemCbs_t sem
Semaphore callback functions.
Definition: mmwavelink.h:1311
rlRhcpMsg_t * rxMsgPtr[RL_CASCADE_NUM_DEVICES]
Rx message buffer pointer.
Definition: rl_driver.h:311
rlReturnVal_t rlDriverValidateHdr(rlProtHeader_t protHdr)
Validates the header by comparing Checksum.
Definition: rl_driver.c:366
rlOsiMutexCbs_t mutex
Mutex callback functions.
Definition: mmwavelink.h:1307
rlDbgCb_t dbgCb
Debug Callback, required to receive Debug information.
Definition: mmwavelink.h:1584
rlUInt16_t b4SeqNum
Sequence Number.
Definition: rl_protocol.h:169
rlUInt8_t arDevType
xWR1243/AWR2243/xWR6243 + HOST = 0x0, xWR1443 MSS = 0x1, xWR1642 MSS/DSS = 0x2, xWR1843 MSS/DSS = 0...
Definition: mmwavelink.h:1580
rlUInt16_t b2AckFlag
00- ACK requested, 11 - No ACK Requested
Definition: rl_protocol.h:149
rlInt32_t(* rlComIfRead)(rlComIfHdl_t fd, rlUInt8_t *pBuff, rlUInt16_t len)
Read Data from Communication interface.
Definition: mmwavelink.h:1109
rlOsiSemHdl_t cmdSem[RL_CASCADE_NUM_DEVICES]
Driver Command Wait Semaphore.
Definition: rl_driver.h:286
void rlDriverConstructInMsg(rlUInt16_t msgId, rlDriverMsg_t *inMsg, rlPayloadSb_t *payloadPtr)
: Construct command packet (inMsg) based on given message-ID and payload
Definition: rl_driver.c:3033
mmwave radar Driver Global Structure
Definition: rl_driver.h:241
rlReturnVal_t rlDriverCmdSendRetry(rlUInt8_t devIndex, rlDriverMsg_t *outMsg)
: Send command and wait for response
Definition: rl_driver.c:2632
rlComIfHdl_t comIfHdl[RL_DEVICE_CONNECTED_MAX]
Communication Interface Handles.
Definition: rl_driver.h:223
rlUInt8_t isDriverInitialized
Driver Status.
Definition: rl_driver.h:250
rlReturnVal_t rlDriverMsgRead(rlDriverData_t *rlDrvData, rlUInt8_t devIndex)
Receive and validate protocol header and payload.
Definition: rl_driver.c:1289
rlUInt16_t nsbc
Number of Sub Blocks in Payload.
Definition: rl_driver.h:349
rlInt32_t(* rlComIfClose)(rlComIfHdl_t fd)
Close the Communication interface.
Definition: mmwavelink.h:1137
mmwave Logging functions
Definition: rl_driver.h:233
rlUInt16_t b4Direction
Direction.
Definition: rl_protocol.h:104
rlEventCbs_t eventCb
Event Callback, required to receive notification.
Definition: mmwavelink.h:1542
rlComIfHdl_t(* rlComIfOpen)(rlUInt8_t deviceIndex, rlUInt32_t flags)
Open Communication interface.
Definition: mmwavelink.h:1094
rlReturnVal_t rlDriverExecuteGetApi(rlUInt8_t deviceMap, rlUInt16_t msgId, rlUInt16_t sbcID, rlUInt8_t *msgData, rlUInt16_t inLen)
: Construct get message and invoke command.
Definition: rl_driver.c:3132
rlUInt8_t dbgLevel
User needs to set debug level such as error, warning, debug, verbose.
Definition: mmwavelink.h:1523
rlReturnVal_t rlDriverSetRetryCount(rlUInt8_t retryCnt)
: Set the retry count for re-sending command
Definition: rl_driver.c:3230
rlReturnVal_t rlDriverRxHdrRead(rlUInt8_t hdrBuf[RHCP_HEADER_LEN], rlComIfHdl_t comIfHdl)
Read SYNC and Header from communication channel.
Definition: rl_driver.c:1711
rlUInt8_t rlDriverGetArDeviceType(void)
Returns AR device type which mmWavelink is communicating.
Definition: rl_driver.c:2375
mmwave radar Driver Protocol header read buffer
Definition: rl_driver.h:323
rlOsiMutexHdl_t devMutex[RL_CASCADE_NUM_DEVICES]
Driver Global Lock Mutex.
Definition: rl_driver.h:282
rlReturnVal_t rlDriverDeInit(void)
De Initializes the mmwave radar Driver.
Definition: rl_driver.c:2274
void(* rlDeviceMaskHostIrq)(rlComIfHdl_t fd)
Masks Host Interrupt.
Definition: mmwavelink.h:1430
rlDriverData_t * rlDriverGetHandle(void)
Returns mmwave radar Driver Global Structure.
Definition: rl_driver.c:2341
void rlDriverHostIrqHandler(rlUInt8_t deviceIndex, void *pValue)
Interrupt Service Routine to handle host interrupt from mmwave radar device.
Definition: rl_driver.c:565
rlReturnVal_t rlDriverAsyncEventHandler(rlUInt8_t devIndex, rlUInt16_t nsbc, rlUInt8_t *payload, rlUInt16_t payloadLen)
Handles asynchronous response/error from mmwave radar device.
Definition: rl_driver.c:500
RHCP Payload Structure.
Definition: rl_driver.h:161
rlReturnVal_t rlDriverCmdInvoke(rlUInt8_t deviceMap, rlDriverMsg_t inMsg, rlDriverMsg_t *outMsg)
Invokes a command to mmwave radar Device. Implements mmwave radar Host Communication Protocol(RHCP)
Definition: rl_driver.c:2739
RHCP protocol header structure.
Definition: rl_protocol.h:209
mmwave radar Driver Payload
Definition: rl_driver.h:355
rlTimerCbs_t timerCb
Timer Callback, required when ACK is enabled.
Definition: mmwavelink.h:1550
rlCrcCbs_t crcCb
CRC Callback, required when CRC is enabled.
Definition: mmwavelink.h:1559
void rlDriverFillPayload(rlUInt16_t msgId, rlUInt16_t sbcID, rlPayloadSb_t *payloadPtr, rlUInt8_t *data, rlUInt16_t inLen)
: Fill payload based on given message-ID, sub-block ID and data.
Definition: rl_driver.c:3099
rlUInt16_t b2RetryFlag
00- No Retry, 11 - Retry
Definition: rl_protocol.h:145
rlReturnVal_t rlDriverConfigureAckTimeout(rlUInt32_t ackTimeout)
Configures the Acknowledgement timeout in mmwavelink Driver.
Definition: rl_driver.c:2901
void(* rlAsyncEvent)(rlUInt8_t devIndex, rlUInt16_t subId, rlUInt16_t subLen, rlUInt8_t *payload)
Reports Asynchronous events from mmwave radar device such as device status, exceptions etc.
Definition: mmwavelink.h:1338
rlReturnVal_t rlDriverOsiInit(void)
Initializes the OSI layer abstraction for mmwavelink.
Definition: rl_driver.c:1868
rlUInt16_t b10MsgId
Message ID.
Definition: rl_protocol.h:112
rlReturnVal_t rlDriverVerifyCRC(rlUInt8_t *data, rlUInt16_t dataLen, rlUInt8_t crcType, rlUInt8_t crc[RL_CRC_LEN_MAX])
Compares received CRC with Calculated CRC.
Definition: rl_driver.c:248
rlReturnVal_t rlDriverRemoveDevices(rlUInt8_t deviceMap)
Disconnects the mmwave radar devices.
Definition: rl_driver.c:2229
rlFunctionParams_t funcParams[RL_CASCADE_NUM_DEVICES]
Current API parameters.
Definition: rl_driver.h:246
rlInt32_t(* rlComIfWrite)(rlComIfHdl_t fd, rlUInt8_t *pBuff, rlUInt16_t len)
Write Data over Communication interface.
Definition: mmwavelink.h:1124
rlInt32_t(* rlDeviceDisable)(rlUInt8_t deviceIndex)
Power off mmWave radar device.
Definition: mmwavelink.h:1418
void(* rlDeviceUnMaskHostIrq)(rlComIfHdl_t fd)
Unmask Host Interrupt.
Definition: mmwavelink.h:1442
rlSysNRespType_t errorType
Definition: rl_protocol.h:74
rlUInt8_t retryCount
Retry count for re-sending command if device doesn't send response within timeout or device sends NAC...
Definition: rl_driver.h:303
rlClientCbs_t clientCtx
Client context.
Definition: rl_driver.h:294
rlDeviceCtrlCbs_t devCtrlCb
Device Control Callback.
Definition: mmwavelink.h:1546
rlReturnVal_t rlDriverAddDevice(rlUInt8_t deviceMap)
Adds mmwave radar device.
Definition: rl_driver.c:2136
RHCP message structure.
Definition: rl_protocol.h:225
mmWaveLink API Error Sub block structure
Definition: rl_protocol.h:69
rlCrcType_t crcType
CRC Types rlCrcType_t 16/32/64.
Definition: mmwavelink.h:1563
rlReturnVal_t rlDriverWaitForResponse(rlUInt8_t devIndex, rlDriverMsg_t *outMsg)
: Wait for Device's response
Definition: rl_driver.c:2437
rlUInt8_t deviceMap
Bitmap of devices connected radarSS/DSS Mailbox in case of 16xx autonomous.
Definition: rl_driver.h:254
rlUInt16_t b4Version
0000 - Invalid, 0001 - 1111 - Valid Range
Definition: rl_protocol.h:153
rlReturnVal_t rlDriverProcRdMsg(rlUInt8_t devIdx, rlReturnVal_t inVal)
Process received message for Async event message.
Definition: rl_driver.c:637
RHCP SYNC Pattern Structure.
Definition: rl_protocol.h:85
rlComDevInx_t commDevIdx
Communication handle and device-index for deifferent devices connected to Host.
Definition: rl_driver.h:278
void rlDriverShiftDWord(rlUInt8_t buf[])
Shifts one byte in the byte array.
Definition: rl_driver.c:179
rlCmdParserCbs_t cmdParserCb
Call back for parsing the Command received at MSS from the Host TI Internal Use only.
Definition: mmwavelink.h:1555
rlReturnVal_t rlDriverExecuteSetApi(rlUInt8_t deviceMap, rlUInt16_t msgId, rlUInt16_t sbcID, rlUInt8_t *msgData, rlUInt16_t inLen)
: Construct set message and invoke command.
Definition: rl_driver.c:3188
rlReturnVal_t rlDriverIsDeviceMapValid(rlUInt8_t deviceMap)
Checks if given deviecMap is valid wrt to global DeviceMap set to mmWaveLink.
Definition: rl_driver.c:2394
rlInt32_t(* rlDeviceWaitIrqStatus)(rlComIfHdl_t fd, rlUInt8_t highLow)
Polls Host Interrupt Status.
Definition: mmwavelink.h:1461

Copyright 2021, Texas Instruments Incorporated