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  */
59 
60 /******************************************************************************
61  * INCLUDE FILES
62  ******************************************************************************
63  */
64 #include <stdlib.h>
65 #include <string.h>
66 #include <ti/control/mmwavelink/mmwavelink.h>
67 #include <ti/control/mmwavelink/include/rl_driver.h>
68 #include <ti/control/mmwavelink/include/rl_messages.h>
69 #include <ti/control/mmwavelink/include/rl_controller.h>
70 #include <ti/control/mmwavelink/include/rl_protocol.h>
71 #include <ti/control/mmwavelink/include/rl_trace.h>
72 
73 /****************************************************************************************
74 * MACRO DEFINITIONS
75 ****************************************************************************************
76 */
77 /* Check if Interrupt is pending */
78 #define RL_PENDING_RX_MSG(driverData, index) \
79  (((driverData)->rxIrqCnt[(index)]) != ((driverData)->rxDoneCnt[(index)]))
80 
81 /* mmwave radar Communication Interface Read/Write */
82 #define RL_IF_WRITE(fd,pBuff,len) \
83  rl_driverData.clientCtx.comIfCb.rlComIfWrite((fd),(pBuff),(len))
84 #define RL_IF_READ(fd,pBuff,len) \
85  rl_driverData.clientCtx.comIfCb.rlComIfRead((fd),(pBuff),(len))
86 
87 
88 /* mmwave radar Communication Interface Read/Write Error Check */
89 #define RL_IF_WRITE_CHECK(fd,pBuff,len) \
90  {\
91  if (((rlInt32_t)(len)) != RL_IF_WRITE((fd), (pBuff), (len)))\
92  {\
93  return RL_RET_CODE_RADAR_IF_ERROR;\
94  }\
95  }
96 #define RL_IF_READ_CHECK(fd,pBuff,len) \
97  {\
98  if (((rlInt32_t)(len)) != RL_IF_READ((fd), (pBuff), (len)))\
99  {\
100  return RL_RET_CODE_RADAR_IF_ERROR;\
101  }\
102  }
103 
104 /* MAX Retry of SYNC Match */
105 #define RL_SYNC_SCAN_THRESHOLD (1000U)
106 
107 /* mmWaveLink Header Opcode Class */
108 #define RL_RHCP_HDR_OPCODE_CLASS(ptr) \
109  (rlUInt8_t) (((rlProtHeader_t *)(ptr))->opcode.b2MsgType)
110 
111 /* mmWaveLink Header Payload */
112 #define RL_RHCP_HDR_PL_LENGTH(ptr) (((rlProtHeader_t *)(ptr))->len)
113 
114 #define PATTERN_NOT_MATCHED ((rlInt32_t)0x0)
115 #define SYNC_PATTERN_MATCHED ((rlInt32_t)0x1)
116 #define CNYS_PATTERN_MATCHED ((rlInt32_t)0x2)
117 
118 /* Protocol SYNC Patterns */
119 #define D2H_SYNC_PATTERN_1 (0xDCBAU)
120 #define D2H_SYNC_PATTERN_2 (0xABCDU)
121 #define H2D_SYNC_PATTERN_1 (0x1234U)
122 #define H2D_SYNC_PATTERN_2 (0x4321U)
123 #define H2D_CNYS_PATTERN_1 (0x5678U)
124 #define H2D_CNYS_PATTERN_2 (0x8765U)
125 
126 /******************************************************************************
127  * GLOBAL VARIABLES/DATA-TYPES DEFINITIONS
128  ******************************************************************************
129  */
130 
131 /* mmwave radar Driver global structure */
132 #ifdef ccs
133 #pragma DATA_ALIGN(rl_driverData, 4);
134 #endif
135 static rlDriverData_t rl_driverData = {0};
136 
137 /* mmwave radar Driver Command/Response Buffer */
138 #ifdef ccs
139 #pragma DATA_ALIGN(rl_txMsg, 8);
140 #endif
141 rlRhcpMsg_t rl_txMsg = {0};
142 #ifdef ccs
143 #pragma DATA_ALIGN(rl_rxMsg, 8);
144 #endif
145 rlRhcpMsg_t rl_rxMsg = {0};
146 
147 /******************************************************************************
148  * FUNCTION PROTOTYPES
149  ******************************************************************************
150  */
151 static rlReturnVal_t rlDriverOriginDirCheck(rlUInt8_t deviceRunId, rlUInt16_t dataDir);
152 static rlUInt8_t rlDriverReceiveSync(rlComIfHdl_t comIfHdl, rlUInt8_t syncBuf[],
153  rlInt32_t *syncType);
154 static rlReturnVal_t rlDriverClientCbCheck(rlClientCbs_t clientCb);
155 static rlReturnVal_t rlDriverOsiCbCheck(rlClientCbs_t clientCb);
156 static rlReturnVal_t rlDriverCmdWriter(rlUInt8_t devIndex, rlDriverMsg_t* outMsg);
157 
158 
159 /******************************************************************************
160  * FUNCTION DEFINITIONS
161  ******************************************************************************
162  */
163 
171 /* SourceId : */
172 /* DesignId : */
173 /* Requirements : */
174 void rlDriverShiftDWord(rlUInt8_t buf[])
175 {
176  rlUInt8_t shiftIdx;
177 
178  /* shift each byte in recevied byte array */
179  for (shiftIdx = 0U; shiftIdx < 7U; shiftIdx++)
180  {
181  /* overwritting each data byte with next data byte of array */
182  buf[shiftIdx] = buf[shiftIdx + 1U];
183  }
184 
185  /* set last byte to zero */
186  buf[7U] = 0U;
187 }
188 
202 /* DesignId : */
203 /* Requirements : AUTORADAR_REQ-774 */
204 rlReturnVal_t rlDriverCalCRC(rlUInt8_t* data, rlUInt16_t dataLen,
205  rlUInt8_t crcType, rlUInt8_t crc[RL_CRC_LEN_MAX])
206 {
207  rlReturnVal_t retVal;
208 
209  RL_LOGV_ARG0("rlDriverCalCRC starts...\n");
210 
211  /* check if API is defined by the application during powerOn */
212  if (rl_driverData.clientCtx.crcCb.rlComputeCRC != NULL)
213  {
214  /* compute CRC on given data */
215  retVal = rl_driverData.clientCtx.crcCb.rlComputeCRC(data, dataLen, crcType, &crc[0U]);
216  }
217  else
218  {
219  /* set error code if CRC compute API is not set by Application */
220  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
221  }
222  RL_LOGV_ARG0("rlDriverCalCRC ends...\n");
223 
224  return retVal;
225 }
226 
241 /* DesignId : */
242 /* Requirements : AUTORADAR_REQ-780 */
243 rlReturnVal_t rlDriverVerifyCRC(rlUInt8_t* data, rlUInt16_t dataLen,
244  rlUInt8_t crcType, rlUInt8_t crc[RL_CRC_LEN_MAX])
245 {
246  rlUInt8_t indx;
247  rlUInt8_t crcByte[RL_CRC_LEN_MAX];
248  rlReturnVal_t retVal = RL_RET_CODE_OK;
249 
250  RL_LOGV_ARG0("rlDriverVerifyCRC starts...\n");
251 
252  /* compute CRC on given data */
253  if (RL_RET_CODE_OK != rl_driverData.clientCtx.crcCb.rlComputeCRC(data, dataLen, \
254  crcType, &crcByte[0U]))
255  {
256  /* set error code if CRC callback returns non-zero */
257  retVal += RL_RET_CODE_RADAR_IF_ERROR;
258  }
259  else
260  {
261  /* compare computed and received CRC value */
262  for (indx = 0U; indx < (2U << crcType); indx++)
263  {
264  if (crcByte[indx] != crc[indx])
265  {
266  /* set error code if computed and received CRC value mismatched */
267  retVal += RL_RET_CODE_CRC_FAILED;
268  break;
269  }
270  }
271  }
272  RL_LOGV_ARG0("rlDriverVerifyCRC ends...\n");
273 
274  return retVal;
275 }
276 
289 /* DesignId : */
290 /* Requirements : AUTORADAR_REQ-774, AUTORADAR_REQ-777 */
291 rlReturnVal_t rlDriverCalChkSum(rlProtHeader_t* hdrData, rlUInt8_t len,
292  rlUInt16_t* checksum)
293 {
294  /* TBD - MISRA compliant Checksum code */
295  rlUInt32_t checkSumVal = 0U;
296  rlUInt8_t *localGenHdr = (rlUInt8_t *)hdrData;
297  rlReturnVal_t retVal;
298 
299  RL_LOGV_ARG0("rlDriverCalChkSum starts...\n");
300 
301  /* if received data pointer is not NULL */
302  if (localGenHdr != RL_NULL_PTR)
303  {
304  /* if length is 2 or more bytes */
305  while (len > 1U)
306  {
307  /* AR_CODE_REVIEW MR:R.11.2 <APPROVED> "Pointer conversion
308  * from data array
309  * to calculate Checksum" */
310  /*LDRA_INSPECTED 94 S */
311  /*LDRA_INSPECTED 95 S */
312  checkSumVal += *((rlUInt16_t*) localGenHdr);
313  localGenHdr += 2U;
314 
315  /* If high order bit set, fold */
316  if ((checkSumVal & 0x80000000U) != 0U)
317  {
318  checkSumVal = (checkSumVal & 0xFFFFU) + (checkSumVal >> 16U);
319  }
320  /* decrement length by 2 as checkSum is calculated on each 2 bytes */
321  len -= 2U;
322  }
323  /* Take care of left over byte */
324  if (len > 0U)
325  {
326  checkSumVal += (rlUInt32_t) (*((rlUInt8_t *)localGenHdr));
327  }
328  /* Add all half words to calcuated SUM */
329  while ((checkSumVal >> 16U) != 0U)
330  {
331  checkSumVal = (checkSumVal & 0xFFFFU) + (checkSumVal >> 16U);
332  }
333  RL_LOGV_ARG1("Final checksum 0x%X\n", *checksum);
334 
335  /* Calculate Checksum as compliment of the SUM */
336  *(checksum) = (rlUInt16_t)~checkSumVal;
337  retVal = RL_RET_CODE_OK;
338  }
339  else
340  {
341  retVal = RL_RET_CODE_FATAL_ERROR;
342  }
343 
344  RL_LOGV_ARG0("rlDriverCalChkSum ends...\n");
345 
346  return retVal;
347 }
348 
349 
359 /* DesignId : */
360 /* Requirements : AUTORADAR_REQ-777 */
361 rlReturnVal_t rlDriverValidateHdr(rlProtHeader_t protHdr)
362 {
363  rlReturnVal_t retVal;
364  rlUInt16_t checkSum = 0U;
365 
366  /* Calculate checksum*/
367  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Checksum is getting updated in called function" */
368  /*LDRA_INSPECTED 8 D */
369  if (RL_RET_CODE_OK != rlDriverCalChkSum(&protHdr, ((rlUInt8_t)(RHCP_HEADER_LEN - 2U)),
370  &checkSum))
371  {
372  /* Set error code if checksum callback returns non-zero value */
373  retVal = RL_RET_CODE_RADAR_IF_ERROR;
374  }
375  else
376  {
377  /* Compare calcualted and received checksum*/
378  if (protHdr.chksum != checkSum)
379  {
380  /* Checksum doesn't match, return error*/
381  retVal = RL_RET_CODE_CHKSUM_FAILED;
382  RL_LOGE_ARG0("Checksum validation failed for header\n");
383  }
384  else
385  {
386  /* checksum successfully matched */
387  RL_LOGD_ARG0("Checksum validation is successful\n");
388  retVal= RL_RET_CODE_OK;
389  }
390  }
391 
392  return retVal;
393 }
394 
405 /* DesignId : */
406 /* Requirements : */
407 rlUInt8_t rlDeviceIdentifyCmdDir(rlUInt16_t msgId, rlUInt8_t platform)
408 {
409  rlUInt8_t cmdDir;
410 
411  RL_LOGV_ARG0("rlDeviceIdentifyCmdDir starts...\n");
412 
413  /* if MsgId is for radarSS */
414  if ((RL_RF_RESP_ERROR_MSG < msgId) && (RL_RF_ASYNC_EVENT_MSG > msgId))
415  {
416  /* if mmWaveLink is running on MSS */
417  if (RL_PLATFORM_MSS == platform)
418  {
419  cmdDir = RL_API_DIR_MSS_TO_BSS;
420  }
421  /* if mmWaveLink is running on Host */
422  else if (RL_PLATFORM_HOST == platform)
423  {
424  cmdDir = RL_API_DIR_HOST_TO_BSS;
425  }
426  /* if mmWaveLink is running on DSS */
427  else
428  {
429  cmdDir = RL_API_DIR_DSS_TO_BSS;
430  }
431  RL_LOGV_ARG1("cmdDir for radarSS = %d (1:host2Bss, 10:dss2Bss, 8:mss2bss)\n",\
432  cmdDir);
433  }
434  /* if MsgId is for MSS */
435  else if ((RL_DEV_POWERUP_MSG <= msgId) && (RL_DEV_ASYNC_EVENT_MSG > msgId))
436  {
437  /* if mmWaveLink is running on Host */
438  if (RL_PLATFORM_HOST == platform)
439  {
440  /* MsgId for MSS need not send to MSS itself */
441  cmdDir = RL_API_DIR_HOST_TO_MSS;
442  }
443  else
444  {
445  /* If MSS wants to configure these MsgID to DSS */
446  cmdDir = RL_API_DIR_MSS_TO_DSS;
447  }
448  RL_LOGV_ARG1("cmdDir for MSS = %d (5:host2Mss, 12:dss2Mss)\n", cmdDir);
449  }
450  /* if msgId is for DSS */
451  else if ((RL_DSP_RESERVED0_MSG <= msgId) && (RL_DSP_ASYNC_EVENT_MSG > msgId))
452  {
453  /* MsgId for DSS need not send to DSS itself */
454 
455  /* if mmWaveLink is running on MSS */
456  if (RL_PLATFORM_MSS == platform)
457  {
458  /* set direction MSS_TO_DSS */
459  cmdDir = RL_API_DIR_MSS_TO_DSS;
460  }
461  /* if mmWaveLink is running on Host */
462  else
463  {
464  /* set direction HOST_TO_DSS */
465  cmdDir = RL_API_DIR_HOST_TO_DSS;
466  }
467  RL_LOGV_ARG1("cmdDir for DSS = %d (11:Mss2Dss, 3:hostDss)\n", cmdDir);
468  }
469  else
470  {
471  /* set direction INVALID */
472  cmdDir = RL_API_DIR_INVALID;
473  RL_LOGE_ARG1("rlDeviceIdentifyCmdDir: Invalid cmd, platform: [%d]\n", platform);
474  }
475  RL_LOGV_ARG0("rlDeviceIdentifyCmdDir ends...\n");
476 
477  return cmdDir;
478 }
479 
493 /* DesignId : */
494 /* Requirements : AUTORADAR_REQ-783 */
495 rlReturnVal_t rlDriverAsyncEventHandler(rlUInt8_t devIndex,
496  rlUInt16_t nsbc, rlUInt8_t *payload,
497  rlUInt16_t payloadLen)
498 {
499  rlUInt16_t indx;
500  rlUInt16_t sbLen = 0U;
501  rlUInt16_t sbcId = 0U;
502  rlUInt16_t recSbsLen = 0U;
503  rlReturnVal_t retVal = RL_RET_CODE_OK;
504  rlUInt8_t *payldAddr = payload;
505 
506  RL_LOGV_ARG0("rlDriverAsyncEventHandler starts...\n");
507 
508  /* Lood for all the Events Sub Block and call event handler */
509  for (indx = 0U; indx < nsbc; indx++)
510  {
511  /* check for payload pointer for NULL */
512  if ((payldAddr == RL_NULL_PTR) || (recSbsLen > payloadLen))
513  {
514  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Error value set on top of default value" */
515  /*LDRA_INSPECTED 8 D */
516  retVal = RL_RET_CODE_FATAL_ERROR;
517  break;
518  }
519  /* Read Sub Block Id */
520  rlGetSubBlockId(payldAddr, &sbcId);
521 
522  /* Read Sub Block Len */
523  rlGetSubBlockLen(payldAddr, &sbLen);
524 
525  /* Call Application registered callback to indicate event*/
526  if (RL_NULL_PTR != rl_driverData.clientCtx.eventCb.rlAsyncEvent)
527  {
528  /* Call event handler and pass event payload */
529  /* AR_CODE_REVIEW MR:R.18.1,R.18.4 <APPROVED> "pointer arithmetic required" */
530  /*LDRA_INSPECTED 567 S */
531  /*LDRA_INSPECTED 87 S */
532  rl_driverData.clientCtx.eventCb.rlAsyncEvent(devIndex, sbcId, \
533  ((rlUInt16_t)(sbLen - RL_MIN_SBC_LEN)),\
534  (payldAddr + RL_SBC_PL_INDEX));
535  /* Increase received payload length*/
536  recSbsLen += (sbLen);
537 
538  /* increment payload address */
539  payldAddr += sbLen;
540  }
541  }
542  RL_LOGV_ARG0("rlDriverAsyncEventHandler ends...\n");
543 
544  return retVal;
545 }
546 
558 /* DesignId : */
559 /* Requirements : AUTORADAR_REQ-777 */
560 void rlDriverHostIrqHandler(rlUInt8_t deviceIndex, void *pValue)
561 {
562  rlUInt8_t tempVar;
563  /* get rlDriver global structure pointer */
564  rlDriverData_t* rlDrvData = rlDriverGetHandle();
565 
566  RL_LOGV_ARG0("rlDriverHostIrqHandler starts...\n");
567 
568  /* check for NULL pointer */
569  if (pValue == RL_NULL_PTR)
570  {
571  /* No Argument Passed */
572  RL_LOGD_ARG0("rlDriverHostIrqHandler Input arg is NULL\n");
573  }
574 
575  /* Mask the Interrupt - Required if interrupt is Level triggered*/
576  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData is pointer to a global strcture,
577  can't be NULL" */
578  /*LDRA_INSPECTED 45 D */
579  if ((RL_NULL_PTR != rlDrvData->clientCtx.devCtrlCb.rlDeviceMaskHostIrq)\
580  && ((rlComIfHdl_t)RL_NULL_PTR != rlDrvData->commDevIdx.comIfHdl[deviceIndex]))
581  {
582  /* Mask Host IRQ */
583  rlDrvData->clientCtx.devCtrlCb.rlDeviceMaskHostIrq((rlComIfHdl_t) \
584  rlDrvData->commDevIdx.comIfHdl[deviceIndex]);
585  RL_LOGD_ARG0("rlDriverHostIrqHandler Mask the Interrupt\n");
586  }
587 
588  /* Increment the Irq count*/
589  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "storing incremented value to global structure" */
590  /*LDRA_INSPECTED 105 D */
591  rlDrvData->rxIrqCnt[deviceIndex] = (rlDrvData->rxIrqCnt[deviceIndex] + 1U);
592 
593  /* store deviceIndex in Global */
594  rlDrvData->commDevIdx.rlDevIndex[deviceIndex] = deviceIndex;
595 
596  tempVar = (rlDrvData->isCmdRespWaited[deviceIndex] | \
597  rlDrvData->isRespWriteWaited[deviceIndex]);
598  /* Check if command transaction is in progress*/
599  if (RL_TRUE == tempVar)
600  {
601  /* Release command response wait semaphore to unblock command thread*/
602  (void)rlDrvData->clientCtx.osiCb.sem.rlOsiSemSignal(
603  &rlDrvData->cmdSem);
604  RL_LOGD_ARG0("rlDriverHostIrqHandler Release command response \n");
605  }
606  else
607  {
608  /* No response is expected, Add to the Spawn queue to be hanled
609  * in different context*/
610  (void)rlDrvData->clientCtx.osiCb.queue.rlOsiSpawn(
611  (RL_P_OSI_SPAWN_ENTRY)rlDriverMsgReadSpawnCtx,
612  &rlDrvData->commDevIdx.rlDevIndex[deviceIndex], 0);
613  RL_LOGD_ARG0("rlDriverHostIrqHandler No response is expected \n");
614  }
615 
616  RL_LOGV_ARG0("rlDriverHostIrqHandler ends...\n");
617 
618  return;
619 }
620 
631 rlReturnVal_t rlDriverProcRdMsg(rlUInt8_t devIdx, rlReturnVal_t inVal)
632 {
633  /* get rlDriver global structure pointer */
634  rlDriverData_t* rlDrvData = rlDriverGetHandle();
635  rlReturnVal_t retVal;
636 
637  /* Increment IRQ done IR*/
638  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData is pointer to a global strcture,
639  can't be NULL" */
640  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "storing incremented value to global structure" */
641  /*LDRA_INSPECTED 105 D */
642  /*LDRA_INSPECTED 45 D */
643  rlDrvData->rxDoneCnt[devIdx] = (rlDrvData->rxDoneCnt[devIdx] + 1U);
644 
645  /* Check received message class*/
646  switch (rlDrvData->funcParams.rxMsgClass)
647  {
648  case RL_API_CLASS_ASYNC:
649  /* If CRC check passed then only parse Async Event */
650  if (inVal == RL_RET_CODE_OK)
651  {
652  /* parse received Async Event Message */
653  /*LDRA_INSPECTED 95 S */
654  retVal = rlDriverAsyncEventHandler(devIdx,\
655  rlDrvData->funcParams.asyncEvt.evtMsg.hdr.nsbc,\
656  (rlUInt8_t *)&rlDrvData->funcParams.asyncEvt.evtMsg.payload[0],\
657  (rlUInt16_t)(rlDrvData->funcParams.asyncEvt.evtMsg.hdr.len - \
658  RHCP_HEADER_LEN));
659  }
660  else
661  {
662  retVal = RL_RET_CODE_OK;
663  }
664  break;
665  case RL_API_CLASS_NACK:
666  /* These types are legal in this context. Do nothing */
667  retVal = RL_RET_CODE_OK;
668  break;
669  case RL_API_CLASS_RSP:
670  /* Command response is illegal in this context. */
671  retVal = RL_RET_CODE_OK;
672  break;
673  /* if mmWaveLink is running on MSS/DSS and receives command from other Core/HOST */
674  case RL_API_CLASS_CMD:
675  case RL_API_CLASS_BYPASS:
676  {
677  /* Check if command parser API callback is assigned by the application */
678  if (rl_driverData.clientCtx.cmdParserCb.rlCmdParser != RL_NULL_PTR)
679  {
680  /* invoke callback to parse the received command packet */
681  (void)rl_driverData.clientCtx.cmdParserCb.rlCmdParser(
682  rlDrvData->funcParams.rxMsgClass, inVal);
683  }
684  else
685  {
686  /* do nothing */
687  }
688  retVal = RL_RET_CODE_OK;
689  }
690  break;
691  case RL_API_CLASS_MAX:
692  /* do nothing */
693  retVal = RL_RET_CODE_OK;
694  break;
695  default:
696  /* set error code */
697  retVal = RL_RET_CODE_PROTOCOL_ERROR;
698  RL_LOGE_ARG0("rlDriverProcRdMsg, Rl protocol error\n");
699  break;
700  }
701 
702  return retVal;
703 }
704 
714 /* DesignId : */
715 /* Requirements : AUTORADAR_REQ-782 */
716 rlReturnVal_t rlDriverMsgReadSpawnCtx(const void *pValue)
717 {
718  rlReturnVal_t retVal, msgRdRetVal;
719  rlUInt8_t deviceIndex;
720  rlUInt8_t lclRxIrqCnt, lclRxDoneCnt;
721  /* get rlDriver global structure pointer */
722  rlDriverData_t* rlDrvData = rlDriverGetHandle();
723 
724  RL_LOGV_ARG0("rlDriverMsgReadSpawnCtx starts...\n");
725 
726  /* check for NULL pointer */
727  if (pValue == RL_NULL_PTR)
728  {
729  /* No Argument Passed */
730  deviceIndex = 0U;
731  RL_LOGE_ARG0("rlDriverMsgReadSpawnCtx Input arg is NULL\n");
732  }
733  else
734  {
735  /* argument passed is Device Index */
736  deviceIndex = *(const rlUInt8_t*)pValue;
737  }
738 
739  /* This function pointer is always being checked on powerOn and mmwavelink
740  fails poweron with error return value, in this failure case no API call is allowed */
741 
742  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData is pointer to a global strcture,
743  can't be NULL" */
744  /*LDRA_INSPECTED 45 D */
745  (void)rlDrvData->clientCtx.osiCb.mutex.rlOsiMutexLock
746  (&rlDrvData->globalMutex, (rlOsiTime_t)RL_OSI_WAIT_FOREVER);
747 
748  /* Messages might have been read by CmdResp context. Therefore after getting LockObj,
749  check again where the Pending Rx Msg is still present. */
750  lclRxIrqCnt = rlDrvData->rxIrqCnt[deviceIndex];
751  lclRxDoneCnt = rlDrvData->rxDoneCnt[deviceIndex];
752 
753  /* unlock Mutex if all Received IRQ are handled i.e. DONE */
754  if (lclRxIrqCnt == lclRxDoneCnt)
755  {
756  (void)rlDrvData->clientCtx.osiCb.mutex.rlOsiMutexUnLock(
757  &rlDrvData->globalMutex);
758  RL_LOGD_ARG0("rlDriverMsgReadSpawnCtx, RxIrqCnt is equal to RxDoneCnt\n");
759  retVal = RL_RET_CODE_OK;
760  }
761  else
762  {
763  /* Receive data over communicaton channel*/
764  /* AR_CODE_REVIEW MR:D.4.7,R.17.7 <APPROVED> "variable is used in next function call" */
765  /*LDRA_INSPECTED 91 D */
766  msgRdRetVal = rlDriverMsgRead(rlDrvData, deviceIndex);
767  /* process received message */
768  retVal = rlDriverProcRdMsg(deviceIndex, msgRdRetVal);
769 
770  /* Unlock Global Mutex */
771  (void)rlDrvData->clientCtx.osiCb.mutex.rlOsiMutexUnLock(&rlDrvData->globalMutex);
772  }
773 
774  RL_LOGV_ARG0("rlDriverMsgReadSpawnCtx ends...\n");
775 
776  return retVal;
777 }
778 
791 rlReturnVal_t rlDriverMsgCmdReply(rlDriverData_t* rlDrvData, rlUInt8_t devIndex)
792 {
793  rlReturnVal_t retVal, retStatus;
794  rlUInt8_t tempRxDoneCnt, tempVar;
795 
796  RL_LOGV_ARG0("rlDriverMsgCmdReply starts...\n");
797 
798  /* Receive data over communication channel */
799  retStatus = rlDriverMsgRead(rlDrvData, devIndex);
800 
801  if (RL_RET_CODE_OK != (rlInt32_t)retStatus)
802  {
803  /* update rxDoneCnt */
804  tempRxDoneCnt = rlDrvData->rxDoneCnt[devIndex];
805  rlDrvData->rxDoneCnt[devIndex] = (tempRxDoneCnt + 1U);
806  /* Error in received data, return error */
807  retVal = retStatus;
808  RL_LOGE_ARG0("Error in received data\n");
809  }
810  else
811  {
812  /* Data received successfully */
813  rlDrvData->rxDoneCnt[devIndex]++;
814 
815  /* Check received message class */
816  if (RL_API_CLASS_RSP == rlDrvData->funcParams.rxMsgClass)
817  {
818  /* Command response received, clear the Wait flag to exit loop */
819  tempVar = RL_FALSE;
820  rlDrvData->isCmdRespWaited[devIndex] = tempVar;
821 
822  /* check if received msg-ID doesn't match with CMD msg-ID */
823  if (rl_rxMsg.hdr.opcode.b10MsgId != rl_txMsg.hdr.opcode.b10MsgId)
824  {
825  /* set error code if MsgId of response doesn't match with CMD msg ID */
826  retVal = RL_RET_CODE_MSGID_MISMATCHED;
827  RL_LOGE_ARG0("Msg id is mis-matched\n");
828  }
829  else
830  {
831  /* response MSG ID matched with response MSG ID,set return value to OK */
832  retVal = RL_RET_CODE_OK;
833  }
834 
835  /* In case CmdResp has been read without waiting on cmdSem that */
836  /* Sem object. That to prevent old signal to be processed. */
837  /* Clear the Semaphore */
838  rlDrvData->clientCtx.osiCb.sem.rlOsiSemWait
839  (&(rlDrvData->cmdSem), (rlOsiTime_t)RL_OSI_NO_WAIT);
840  }
841  else if (RL_API_CLASS_ASYNC == rlDrvData->funcParams.rxMsgClass)
842  {
843  /* Async event received when command response is awaited,
844  Handle the event and keep waiting for the response*/
845  /* AR_CODE_REVIEW MR:R.10.3 <APPROVED> "All parameter types are matching to function
846  argument type. LDRA tool issue." */
847  /*LDRA_INSPECTED 458 S */
848  /*LDRA_INSPECTED 95 S */
849  (void)rlDriverAsyncEventHandler(devIndex,
850  rlDrvData->funcParams.asyncEvt.evtMsg.hdr.nsbc,
851  (rlUInt8_t *)&rlDrvData->funcParams.asyncEvt.evtMsg.payload[0],
852  rlDrvData->funcParams.asyncEvt.evtMsg.hdr.len);
853 
854  retVal = RL_RET_CODE_OK;
855 
856  /* If CRC check fails, the Async Event is Ignored */
857  }
858  else if (RL_API_CLASS_NACK == rlDrvData->funcParams.rxMsgClass)
859  {
860  /* If NACK received for the CMD sent, set CMD Response Wait TAG to FALSE */
861  tempVar = RL_FALSE;
862  rlDrvData->isCmdRespWaited[devIndex] = tempVar;
863  /* set error code to CRC Failed */
864  retVal = RL_RET_CODE_CRC_FAILED;
865  RL_LOGE_ARG0("CRC check fails, the Async Event is Ignored\n");
866  }
867  else
868  {
869  /* Invalid Class*/
870  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
871  RL_LOGE_ARG0("Invalid Class\n");
872  }
873  }
874  RL_LOGV_ARG0("rlDriverMsgCmdReply ends...\n");
875 
876  return retVal;
877 }
878 
879 
890 /* DesignId : MMWL_DesignId_102 */
891 /* Requirements : AUTORADAR_REQ-782 */
892 rlReturnVal_t rlDriverMsgReadCmdCtx(rlUInt8_t devIndex)
893 {
894  rlReturnVal_t retVal;
895  rlDriverData_t* rlDrvData = rlDriverGetHandle();
896 
897  RL_LOGV_ARG0("rlDriverMsgReadCmdCtx starts...\n");
898  /* check for NULL pointer */
899  if (RL_NULL_PTR == rlDrvData)
900  {
901  retVal = RL_RET_CODE_FATAL_ERROR;
902  }
903  else
904  {
905  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Return value is being set under different
906  conditions, where it's set with default value first" */
907  /*LDRA_INSPECTED 8 D */
908 
909  retVal = RL_RET_CODE_OK;
910  /* after command response is received and isCmdRespWaited flag is set FALSE, it is
911  necessary to read out all Async messages in Commands context, because slave device
912  could have dispatched some Async messages before receiving the command */
913 
914  /* AR_CODE_REVIEW MR:D.2.1 <APPROVED> "This is function must loop till
915  * command response is received successfully or retry timer expires ,
916  * if any Hw hang then WDT reset recovers from this error" */
917  /*LDRA_INSPECTED 28 D */
918  while ((RL_TRUE == rlDrvData->isCmdRespWaited[devIndex]) && (RL_RET_CODE_OK == retVal))
919  {
920  if (RL_PENDING_RX_MSG(rlDrvData, devIndex))
921  {
922  /* init to illegal value and verify it's overwritten with the
923  * valid one */
924  rlDrvData->funcParams.rxMsgClass = RL_API_CLASS_MAX;
925 
926  /* Receive data over communication channel */
927  retVal += rlDriverMsgCmdReply(rlDrvData, devIndex);
928  }
929  /* AR_CODE_REVIEW MR:D.2.1 <APPROVED> "This is function must loop till
930  * command response is received successfully or retry timer expires,
931  * if any Hw hang then WDT reset recovers from this error" */
932  /*LDRA_INSPECTED 28 D */
933  else
934  {
935  /* cmdSem will be signaled by IRQ */
936  if (RL_RET_CODE_OK != rlDrvData->clientCtx.osiCb.sem.rlOsiSemWait(
937  &(rlDrvData->cmdSem),
938  (rlOsiTime_t)rlDrvData->clientCtx.ackTimeout))
939  {
940  /* setCmd Response Wait Tag to False when timer expires */
941  rlDrvData->isCmdRespWaited[devIndex] = RL_FALSE;
942 
943  RL_LOGE_ARG0("CmdSem should be signaled by IRQ but respTimeout\n");
944  retVal += RL_RET_CODE_RESP_TIMEOUT;
945  break;
946  }
947  }
948  }
949 
950  /* if any Rx Msg is pending to process and ACK Timout error hasn't happend */
951  if (RL_PENDING_RX_MSG(rlDrvData, devIndex) && (retVal != RL_RET_CODE_FATAL_ERROR) \
952  && (rlDrvData->isCmdRespWaited[devIndex] == RL_FALSE))
953  {
954  /* Spawn a thread/task to read pending Rx Msg */
955  if (rlDrvData->clientCtx.osiCb.queue.rlOsiSpawn
956  ((RL_P_OSI_SPAWN_ENTRY)rlDriverMsgReadSpawnCtx, \
957  &rlDrvData->commDevIdx.rlDevIndex[devIndex], 0U) != RL_RET_CODE_OK)
958  {
959  retVal = RL_RET_CODE_RADAR_OSIF_ERROR;
960  }
961  }
962  }
963  RL_LOGV_ARG0("rlDriverMsgReadCmdCtx ends...\n");
964 
965  return retVal;
966 }
967 
981 /* DesignId : */
982 /* Requirements : */
983 static rlReturnVal_t rlDriverOriginDirCheck(rlUInt8_t deviceRunId,
984  rlUInt16_t dataDir)
985 {
986  rlReturnVal_t retVal;
987 
988  RL_LOGV_ARG0("rlDriverOriginDirCheck starts...\n");
989 
990  switch (deviceRunId)
991  {
992  /* if mmWaveLink instance is running on Host */
993  case RL_PLATFORM_HOST:
994  if ((RL_API_DIR_BSS_TO_HOST == dataDir) ||
995  (RL_API_DIR_MSS_TO_HOST == dataDir) ||
996  (RL_API_DIR_DSS_TO_HOST == dataDir))
997  {
998  /* set OK to return value, i.e. requested DataDir is correct
999  as per running instance of mmWaveLink */
1000  retVal = RL_RET_CODE_OK;
1001  }
1002  else
1003  {
1004  /* request DataDir is invalid as per running instance of mmWaveLink */
1005  retVal = RL_RET_CODE_INVALID_INPUT;
1006  }
1007  break;
1008  /* if mmWaveLink instance is running on MSS */
1009  case RL_PLATFORM_MSS:
1010  if ((RL_API_DIR_BSS_TO_MSS == dataDir) ||
1011  (RL_API_DIR_DSS_TO_MSS == dataDir) ||
1012  (RL_API_DIR_HOST_TO_MSS == dataDir))
1013  {
1014  /* set OK to return value, i.e. requested DataDir is correct
1015  as per running instance of mmWaveLink */
1016  retVal = RL_RET_CODE_OK;
1017  }
1018  else
1019  {
1020  /* request DataDir is invalid as per running instance of mmWaveLink */
1021  retVal = RL_RET_CODE_INVALID_INPUT;
1022  }
1023  break;
1024  /* if mmWaveLink instance is running on DSS */
1025  case RL_PLATFORM_DSS:
1026  /* if Data direction is towards DSS */
1027  if ((RL_API_DIR_BSS_TO_DSS == dataDir) ||
1028  (RL_API_DIR_MSS_TO_DSS == dataDir) ||
1029  (RL_API_DIR_HOST_TO_DSS == dataDir))
1030  {
1031  /* set OK to return value, i.e. requested DataDir is correct
1032  as per running instance of mmWaveLink */
1033  retVal = RL_RET_CODE_OK;
1034  }
1035  else
1036  {
1037  /* request DataDir is invalid as per running instance of mmWaveLink */
1038  retVal = RL_RET_CODE_INVALID_INPUT;
1039  }
1040  break;
1041  default:
1042  /* Invalid: set error code */
1043  retVal = RL_RET_CODE_INVALID_INPUT;
1044  RL_LOGE_ARG2("Unknown platform %d, retVal = %d\n", \
1045  dataDir, retVal);
1046  break;
1047  }
1048  RL_LOGV_ARG0("rlDriverOriginDirCheck ends...\n");
1049 
1050  return retVal;
1051 }
1052 
1053 rlReturnVal_t rlDriverRdVerifyMsg(rlReadBuf_t readBuf, rlUInt8_t devIndex)
1054 {
1055  rlUInt16_t rxLengthRecv;
1056  rlReturnVal_t retVal, readRetVal;
1057  rlUInt16_t payloadLen, msgCrcLen, msgCrcType;
1058  rlUInt8_t isCrcPresent;
1059 
1060  /* get Received Message length excluding SYNC */
1061  rxLengthRecv = RL_RHCP_HDR_PL_LENGTH(&(readBuf.syncHeader.protHdr));
1062 
1063  /* check if received msg length is under valid Msg size */
1064  if (rxLengthRecv >= (RL_MAX_SIZE_MSG - SYNC_PATTERN_LEN))
1065  {
1066  retVal = RL_RET_CODE_PROTOCOL_ERROR;
1067  }
1068  else
1069  {
1070  rlRhcpMsg_t *rhcpMsg;
1071 
1072  /* Get Rx Message Class from received buffer header */
1073  /* Process Header Here - Verify each field */
1074  rl_driverData.funcParams.rxMsgClass =
1075  RL_RHCP_HDR_OPCODE_CLASS(&(readBuf.syncHeader.protHdr));
1076 
1077  /* get the Payload Value removing Header length from Rx Msg Length */
1078  payloadLen = rxLengthRecv - (rlUInt16_t)RHCP_HEADER_LEN;
1079 
1080  if (RL_API_CLASS_ASYNC == rl_driverData.funcParams.rxMsgClass)
1081  {
1082  /* Get RHCP message strcture pointer */
1083  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData is pointer to a global
1084  strcture, can't be NULL" */
1085  /*LDRA_INSPECTED 45 D */
1086  rhcpMsg = &rl_driverData.funcParams.asyncEvt.evtMsg;
1087  }
1088  else
1089  {
1090  /* Get RHCP message strcture pointer */
1091  rhcpMsg = &rl_rxMsg;
1092  }
1093 
1094  /* copy header to global strucutre */
1095  rhcpMsg->hdr = readBuf.syncHeader.protHdr;
1096  /* Copy SYNC from Communication Channel*/
1097  rhcpMsg->syncPattern = readBuf.syncHeader.syncPattern;
1098 
1099  /* Check whether CRC is present*/
1100  if (rhcpMsg->hdr.flags.b2Crc != 0U)
1101  {
1102  /* if CRC is not present in Msg the reset crc variables */
1103  isCrcPresent = RL_FALSE;
1104  msgCrcLen = 0U;
1105  msgCrcType = 0U;
1106  }
1107  else
1108  {
1109  isCrcPresent = RL_TRUE;
1110  /* It may be size 2/4/8 based on 16/32/64 bit */
1111  msgCrcType = rhcpMsg->hdr.flags.b2CrcLen;
1112  /* set CRC length in bytes based on CRC Type */
1113  msgCrcLen = (2U << (msgCrcType & 0x3U));
1114  }
1115  /* Calculate payload length from header legnth*/
1116  payloadLen = ((isCrcPresent == RL_TRUE) ? (payloadLen - msgCrcLen) : payloadLen);
1117 
1118  /* This is an Response/AsyncEvent message. Read the rest of it. */
1119  if (payloadLen > 0U)
1120  {
1121  if (RL_IF_READ(rl_driverData.commDevIdx.comIfHdl[devIndex],
1122  &rhcpMsg->payload[0U], payloadLen) != (rlInt32_t)payloadLen)
1123  {
1124  /* If Read from Communication channel failed then set Error code */
1125  readRetVal = RL_RET_CODE_RADAR_IF_ERROR;
1126  }
1127  else
1128  {
1129  readRetVal = RL_RET_CODE_OK;
1130  }
1131  }
1132  else
1133  {
1134  readRetVal = RL_RET_CODE_OK;
1135  }
1136 
1137  /* If CRC is present - Read and verify*/
1138  if ((isCrcPresent == RL_TRUE) && (readRetVal == RL_RET_CODE_OK))
1139  {
1140  /* Read the CRC Bytes */
1141  if (RL_IF_READ(rl_driverData.commDevIdx.comIfHdl[devIndex],
1142  rl_driverData.funcParams.msgCRC,
1143  msgCrcLen) != (rlInt32_t)msgCrcLen)
1144  {
1145  /* Set the error code if read data fails */
1146  retVal = RL_RET_CODE_RADAR_IF_ERROR;
1147  }
1148  else
1149  {
1150  (void)memcpy(&rhcpMsg->payload[payloadLen], &rl_driverData.funcParams.msgCRC[0U], \
1151  msgCrcLen);
1152  /* Check if CRC is enabled from the application and it's type
1153  matched with received MSG CRC type */
1154  if ((rl_driverData.clientCtx.crcType != (rlUInt8_t)RL_CRC_TYPE_NO_CRC) && \
1155  (rl_driverData.clientCtx.crcType == (rlUInt8_t)msgCrcType))
1156  {
1157  /* Validate CRC first as Opcode might be corrupt as well */
1158  /* AR_CODE_REVIEW MR:R.10.3 <APPROVED> "All parameter types are matching to
1159  function argument type. LDRA tool issue." */
1160  /*LDRA_INSPECTED 458 S */
1161  retVal = rlDriverVerifyCRC((rlUInt8_t*)&rhcpMsg->hdr, (rxLengthRecv - \
1162  msgCrcLen), (rlUInt8_t)(msgCrcType), \
1163  rl_driverData.funcParams.msgCRC);
1164  }
1165  else
1166  {
1167  retVal = RL_RET_CODE_OK;
1168  }
1169  }
1170  }
1171  else
1172  {
1173  retVal = RL_RET_CODE_OK;
1174  }
1175  }
1176 
1177  return retVal;
1178 }
1179 
1191 /* DesignId : MMWL_DesignId_026 */
1192 /* Requirements : AUTORADAR_REQ-777, AUTORADAR_REQ-779 */
1193 rlReturnVal_t rlDriverMsgRead(rlDriverData_t* rlDrvData, rlUInt8_t devIndex)
1194 {
1195  rlReturnVal_t retVal, hdrRetVal;
1196  rlReadBuf_t readBuf = {0};
1197  rlUInt16_t payloadLen;
1198 
1199  RL_LOGV_ARG0("rlDriverMsgRead starts...\n");
1200  /* check for NULL pointer */
1201  if (RL_NULL_PTR == rlDrvData)
1202  {
1203  /* set error code */
1204  retVal = RL_RET_CODE_FATAL_ERROR;
1205  }
1206  else
1207  {
1208  rlReturnVal_t hdrType;
1209 
1210  /* Read message Header from given device index */
1211  hdrType = rlDriverRxHdrRead(readBuf.tempBuf,
1212  rlDrvData->commDevIdx.comIfHdl[devIndex]);
1213  RL_LOGV_ARG1("rlDriverRxHdrRead return val = %d\n", hdrType);
1214 
1215  /* if it's not CNYS pattern then calculate checksum before consuming or
1216  * forwarding to other core */
1217  if (SYNC_PATTERN_MATCHED == (rlInt32_t)(hdrType))
1218  {
1219  /* Verify Checksum, return value 0/-7 (RL_RET_CODE_CHKSUM_FAILED) */
1220  hdrRetVal = rlDriverValidateHdr(readBuf.syncHeader.protHdr);
1221 
1222  /* received msg can be command/response/async_event
1223  * and it is destined to the same device where this mmWaveLink ir running
1224  */
1225  if ((RL_RET_CODE_OK == hdrRetVal) && (RL_RET_CODE_OK == \
1226  rlDriverOriginDirCheck(rlDrvData->clientCtx.platform,
1227  readBuf.syncHeader.protHdr.opcode.b4Direction)))
1228  {
1229  retVal = rlDriverRdVerifyMsg(readBuf, devIndex);
1230  }
1231  else if (RL_RET_CODE_OK == hdrRetVal)
1232  {
1233  rlDrvData->funcParams.rxMsgClass = RL_API_CLASS_BYPASS;
1234  /* if rcvd data is not meant for the device where mmWaveLink is running,
1235  * Then pass data to intended destination; Assumption: byPass of
1236  * Data will happening in MSS only
1237  */
1238  rl_rxMsg.syncPattern = readBuf.syncHeader.syncPattern;
1239  rl_rxMsg.hdr = readBuf.syncHeader.protHdr;
1240 
1241  /* this length includes the CRC field also */
1242  payloadLen = readBuf.syncHeader.protHdr.len - (rlUInt16_t)RHCP_HEADER_LEN;
1243 
1244  /* read full data before writing to destination COMM handle */
1245  if (RL_IF_READ(rlDrvData->commDevIdx.comIfHdl[devIndex], \
1246  &rl_rxMsg.payload[0], payloadLen) != (rlInt32_t)payloadLen)
1247  {
1248  /* Set error code if read is failed */
1249  retVal = RL_RET_CODE_RADAR_IF_ERROR;
1250  }
1251  else
1252  {
1253  /* Set as passed if data read returns zero */
1254  retVal = RL_RET_CODE_OK;
1255  }
1256  }
1257  else
1258  {
1259  /* Set header Validate function return value to retVal */
1260  retVal = hdrRetVal;
1261  }
1262 
1263  }
1264  /* In case mmWaveLink instance is running on MSS, it may receive CNYS from Host Over SPI */
1265  else if (CNYS_PATTERN_MATCHED == (rlInt32_t)(hdrType))
1266  {
1267  /* Check callback is assigned by the application */
1268  if (rl_driverData.clientCtx.cmdParserCb.rlPostCnysStep != RL_NULL_PTR)
1269  {
1270  /* invoke function to complete the task required after receiving CNYS */
1271  retVal = rl_driverData.clientCtx.cmdParserCb.rlPostCnysStep(devIndex);
1272  }
1273  else
1274  {
1275  /* Set error code if callback is NULL */
1276  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1277  }
1278  }
1279  else
1280  {
1281  retVal = hdrType;
1282  /* Set Message class to MAX (invalid) */
1283  rlDrvData->funcParams.rxMsgClass = RL_API_CLASS_MAX;
1284  }
1285 
1286  /* Unmask Interrupt call */
1287  if ((RL_NULL_PTR != rlDrvData->clientCtx.devCtrlCb.rlDeviceUnMaskHostIrq) &&\
1288  (retVal != RL_RET_CODE_FATAL_ERROR))
1289  {
1290  /* Un Mask Interrupt */
1292  rlDrvData->commDevIdx.comIfHdl[devIndex]);
1293  RL_LOGD_ARG0("rlDriverMsgRead Unmask Interrupt call\n");
1294  }
1295  }
1296 
1297  RL_LOGV_ARG0("rlDriverMsgRead ends...\n");
1298 
1299  return retVal;
1300 }
1301 
1312 /* DesignId : MMWL_DesignId_025 */
1313 /* Requirements : AUTORADAR_REQ_772, AUTORADAR_REQ-774 */
1314 rlReturnVal_t rlDriverMsgWrite(rlDriverData_t* rlDrvData, rlComIfHdl_t comIfHdl)
1315 {
1316  rlReturnVal_t retVal;
1317 
1318  RL_LOGV_ARG0("rlDriverMsgWrite starts...\n");
1319 
1320  /* check for NULL pointer */
1321  if (((rlComIfHdl_t)RL_NULL != comIfHdl) && (rlDrvData != RL_NULL_PTR))
1322  {
1323  rlUInt16_t checkSum = 0U, msgCrcLen;
1324  rlUInt16_t payloadLen;
1325  rlUInt16_t tempLen;
1326  /* Calculate Checksum */
1327  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Checksum is getting updated in called function" */
1328  /*LDRA_INSPECTED 8 D */
1329  (void)rlDriverCalChkSum(&rl_txMsg.hdr, ((rlUInt8_t)(RHCP_HEADER_LEN - 2U)), &checkSum);
1330  rl_txMsg.hdr.chksum = checkSum;
1331 
1332  /* get Payload length removing Header length from Msg Length */
1333  payloadLen = rl_txMsg.hdr.len - (rlUInt16_t)RHCP_HEADER_LEN;
1334  RL_LOGV_ARG1("API Dir = %d \n", rl_txMsg.hdr.opcode.b4Direction);
1335 
1336  /* check for Data Direction to choose Sync Pattern */
1337  if ((RL_API_DIR_DSS_TO_HOST == rl_txMsg.hdr.opcode.b4Direction) || \
1338  (RL_API_DIR_MSS_TO_HOST == rl_txMsg.hdr.opcode.b4Direction) || \
1339  (RL_API_DIR_DSS_TO_MSS == rl_txMsg.hdr.opcode.b4Direction))
1340  {
1341  /* set device to Host Sync Pattern */
1342  rl_txMsg.syncPattern.sync1 = D2H_SYNC_PATTERN_1;
1343  rl_txMsg.syncPattern.sync2 = D2H_SYNC_PATTERN_2;
1344  }
1345  else
1346  {
1347  /* set Host to device Sync Pattern */
1348  rl_txMsg.syncPattern.sync1 = H2D_SYNC_PATTERN_1;
1349  rl_txMsg.syncPattern.sync2 = H2D_SYNC_PATTERN_2;
1350  }
1351 
1352  /* Check if CRC is enabled, Calculate and update payload length*/
1353  if (rl_txMsg.hdr.flags.b2Crc == RL_HDR_FLAG_CRC)
1354  {
1355  /* It may be size 2/4/8 based on 16/32/64 bit */
1356  msgCrcLen = (2U << (rlDrvData->clientCtx.crcType & 0x3U));
1357  /* compute CRC */
1358  (void)rlDriverCalCRC((rlUInt8_t *)&rl_txMsg.hdr, (
1359  rl_txMsg.hdr.len - msgCrcLen),
1360  (rlUInt8_t)rlDrvData->clientCtx.crcType,
1361  (rlUInt8_t *)rlDrvData->funcParams.msgCRC);
1362  /* copy computed CRC to Tx Msg buffer */
1363  (void)memcpy((rlUInt8_t*)(&rl_txMsg.payload[payloadLen - msgCrcLen]),
1364  (rlUInt8_t*)&(rlDrvData->funcParams.msgCRC[0]), msgCrcLen);
1365  }
1366  tempLen = ((rlUInt16_t)(SYNC_PATTERN_LEN + RHCP_HEADER_LEN) + payloadLen);
1367 
1368  /* write Tx Msg to destination either over Mailbox internal to
1369  mmWave device or to External Host Over SPI */
1370  if (RL_IF_WRITE(comIfHdl, ((rlUInt8_t *)&rl_txMsg), \
1371  tempLen) != (rlInt32_t)tempLen)
1372  {
1373  /* set error code */
1374  retVal = RL_RET_CODE_RADAR_IF_ERROR;
1375  }
1376  else
1377  {
1378  /* set Error code as OK */
1379  retVal = RL_RET_CODE_OK;
1380  }
1381  }
1382  else
1383  {
1384  /* set error code if pointers are NULL */
1385  retVal = RL_RET_CODE_FATAL_ERROR;
1386  }
1387  RL_LOGV_ARG0("rlDriverMsgWrite ends...\n");
1388 
1389  return retVal;
1390 }
1391 
1405 /* DesignId : */
1406 /* Requirements : AUTORADAR_REQ-777 */
1407 static rlUInt8_t rlDriverReceiveSync(rlComIfHdl_t comIfHdl, rlUInt8_t syncBuf[],
1408  rlInt32_t *syncType)
1409 {
1410  rlUInt16_t count = 0;
1411  rlInt32_t retVal;
1412  rlSyncPattern_t recSyncPattern = {0U, 0U};
1413  rlReturnVal_t errVal;
1414 
1415  RL_LOGV_ARG0("rlDriverReceiveSync starts...\n");
1416 
1417  /* check for NULL pointer */
1418  if (syncType != (rlInt32_t*)RL_NULL)
1419  {
1420  /* Read 4 bytes SYNC Pattern) */
1421  if (RL_IF_READ(comIfHdl, &syncBuf[0U], (rlUInt16_t)SYNC_PATTERN_LEN) != \
1422  (rlInt32_t)SYNC_PATTERN_LEN)
1423  {
1424  /* set error code */
1425  errVal = RL_RET_CODE_RADAR_IF_ERROR;
1426  }
1427  else
1428  {
1429  /* if SYNC pattern has been read properly then copy it */
1430  (void)memcpy(&recSyncPattern, &syncBuf[0U], SYNC_PATTERN_LEN);
1431  errVal = RL_RET_CODE_OK;
1432  }
1433  retVal = PATTERN_NOT_MATCHED;
1434 
1435  /* Wait for SYNC_PATTERN from the device (when mmWaveLink is running on Ext Host*/
1436  while (((retVal) == (rlInt32_t)PATTERN_NOT_MATCHED) && (errVal == RL_RET_CODE_OK))
1437  {
1438  /* check if matched with SYNC pattern Host-to-device or device-to-Host */
1439  if (((recSyncPattern.sync1 == H2D_SYNC_PATTERN_1) &&
1440  (recSyncPattern.sync2 == H2D_SYNC_PATTERN_2) ) || \
1441  ((recSyncPattern.sync1 == D2H_SYNC_PATTERN_1) &&
1442  (recSyncPattern.sync2 == D2H_SYNC_PATTERN_2)))
1443  {
1444  /* set to SYNC Matched flag if H2D or D2H SYNC pattern is matching
1445  for big/little endian data */
1446  retVal = SYNC_PATTERN_MATCHED;
1447  }
1448  else
1449  {
1450  /* if mmwavelink running on device and connect to Host over SPI then
1451  it may recieve CNYS to send data */
1452  if ((recSyncPattern.sync1 == H2D_CNYS_PATTERN_1) &&
1453  (recSyncPattern.sync2 == H2D_CNYS_PATTERN_2))
1454  {
1455  /* set to CNYS Matched flag if H2D CNYS pattern is matching
1456  for big/little endian data */
1457  retVal = CNYS_PATTERN_MATCHED;
1458  }
1459  /* check if count is beyond SYNC Scan threshold */
1460  else if (count >= (rlUInt16_t)RL_SYNC_SCAN_THRESHOLD)
1461  {
1462  /* Set error code to terminate this loop */
1463  errVal += RL_RET_CODE_PROTOCOL_ERROR;
1464  }
1465  else
1466  {
1467  /* Read next 4 bytes to Low 4 bytes of buffer */
1468  if (0 == (count % SYNC_PATTERN_LEN))
1469  {
1470  /* Read 4 bytes SYNC Pattern) */
1471  if (RL_IF_READ(comIfHdl, &syncBuf[SYNC_PATTERN_LEN],\
1472  (rlUInt16_t)SYNC_PATTERN_LEN) != \
1473  (rlInt32_t)SYNC_PATTERN_LEN)
1474  {
1475  /* Set error code to terminate this loop */
1476  errVal += RL_RET_CODE_RADAR_IF_ERROR;
1477  break;
1478  }
1479  }
1480  /* Shift Buffer Up for checking if the sync is shifted */
1481  rlDriverShiftDWord(syncBuf);
1482  /* copy data to recv sync pattern to compare further */
1483  (void)memcpy(&recSyncPattern, &syncBuf[0U], SYNC_PATTERN_LEN);
1484  /* increment read counter */
1485  count++;
1486  }
1487  }
1488  }
1489 
1490  if (errVal == RL_RET_CODE_OK)
1491  {
1492  *(syncType) = retVal;
1493  }
1494  else
1495  {
1496  *(syncType) = errVal;
1497  }
1498  }
1499  count %= SYNC_PATTERN_LEN;
1500  RL_LOGV_ARG1("rlDriverReceiveSync, count = %d\n", count);
1501  RL_LOGV_ARG0("rlDriverReceiveSync ends...\n");
1502 
1503  return (rlUInt8_t)count;
1504 }
1505 
1516 /* DesignId : */
1517 /* Requirements : AUTORADAR_REQ-777 */
1518 /*AR_CODE_REVIEW MR:R.2.2 <APPROVED> "errVal is re initialized under different
1519  if else conditions based on what the error is" */
1520 /*LDRA_INSPECTED 8 D */
1521 rlReturnVal_t rlDriverRxHdrRead(rlUInt8_t hdrBuf[RHCP_HEADER_LEN], rlComIfHdl_t comIfHdl)
1522 {
1523  /* syncBuf: it should be 2/4 byte aligned, as in the application where
1524  * it uses DMA to Rd/Wr DMA might have limitation of src/dest address
1525  * alignement
1526  */
1527  rlUInt8_t syncBuf[SYNC_PATTERN_LEN * 2] = {0U};
1528  /* This buffer contains CNYS pattern (4Bytes) and 12Bytes of dummy sequence.
1529  Host writes this buffer in response to Host-IRQ raised by AWR device to indicate
1530  that device can now write response/async event data to its SPI buffer which will
1531  be read by Host.
1532  */
1533  rlUInt16_t cnysBuf[8U] = {H2D_CNYS_PATTERN_1, H2D_CNYS_PATTERN_2,
1534  0xFFFFU, 0xFFFFU, 0xFFFFU, 0xFFFFU, 0xFFFFU, 0xFFFFU};
1535  rlInt32_t syncType = PATTERN_NOT_MATCHED;
1536  rlUInt8_t syncCnt;
1537  rlInt32_t errVal;
1538 
1539  RL_LOGV_ARG0("rlDriverRxHdrRead starts...\n");
1540 
1541  /* check for NULL pointer */
1542  if ((rlComIfHdl_t)RL_NULL == comIfHdl)
1543  {
1544  errVal = RL_RET_CODE_FATAL_ERROR;
1545  syncType += errVal;
1546  }
1547  else
1548  {
1549  /* If mmWaveLink is running on Ext Host */
1550  if (rl_driverData.clientCtx.platform == RL_PLATFORM_HOST)
1551  {
1552  /* Write CNYS pattern to mmWave Radar */
1553  if (RL_IF_WRITE(comIfHdl,
1554  (rlUInt8_t*)&cnysBuf[0U], (rlUInt16_t)(SYNC_PATTERN_LEN+ RHCP_HEADER_LEN)) !=\
1555  (rlInt32_t)(SYNC_PATTERN_LEN + RHCP_HEADER_LEN))
1556  {
1557  /* Set error code if data write function fails to write SYNC pattern */
1558  errVal = RL_RET_CODE_RADAR_IF_ERROR;
1559  }
1560  else
1561  {
1562  errVal = RL_RET_CODE_OK;
1563  }
1564 
1565  RL_LOGV_ARG2("Platform = %d, delay = %d \n",\
1566  rl_driverData.clientCtx.platform, \
1567  rl_driverData.clientCtx.timerCb.rlDelay);
1568  /* Need to wait till host Irq is down */
1569  /* Check if Host Irq Status can be polled, else use fixed delay */
1570  if ((rl_driverData.clientCtx.devCtrlCb.rlDeviceWaitIrqStatus == NULL)||
1571  (rl_driverData.clientCtx.devCtrlCb.rlDeviceWaitIrqStatus(comIfHdl,
1572  0) != RL_RET_CODE_OK))
1573  {
1574  /* Check if Delay callback is present and invoke */
1575  if (rl_driverData.clientCtx.timerCb.rlDelay != RL_NULL_PTR)
1576  {
1577  /* add 1 mSec delay */
1578  (void)rl_driverData.clientCtx.timerCb.rlDelay(1U);
1579  }
1580  }
1581  }
1582  else
1583  {
1584  errVal = RL_RET_CODE_OK;
1585  }
1586 
1587  if (errVal == RL_RET_CODE_OK)
1588  {
1589  /* AR_CODE_REVIEW MR:D.4.7 <APPROVED> "syncCnt is used when pattern is matched to
1590  copy and read data" */
1591  /*LDRA_INSPECTED 91 D */
1592  syncCnt = rlDriverReceiveSync(comIfHdl, &syncBuf[0U], &syncType);
1593  RL_LOGV_ARG1("syncType = %d \n", syncType);
1594 
1595  if ((CNYS_PATTERN_MATCHED == syncType) || (SYNC_PATTERN_MATCHED == syncType))
1596  {
1597  rlUInt16_t tempLen;
1598  /* copying shifted data to hdrBuf */
1599  (void)memcpy(&hdrBuf[0], &syncBuf[0U], (SYNC_PATTERN_LEN + syncCnt));
1600 
1601  tempLen = RHCP_HEADER_LEN - (0x00FFU & syncCnt);
1602  /* Here we've read Sync Pattern. Read the remaining header */
1603  if (RL_IF_READ(comIfHdl, (&hdrBuf[(SYNC_PATTERN_LEN + syncCnt)]), \
1604  tempLen) != (rlInt32_t)tempLen)
1605  {
1606  syncType += RL_RET_CODE_RADAR_IF_ERROR;
1607  }
1608  }
1609  else
1610  {
1611  /* do nothing */
1612  RL_LOGD_ARG0("do nothing ");
1613  }
1614  }
1615  else
1616  {
1617  syncType += errVal;
1618  }
1619 
1620  }
1621 
1622  RL_LOGV_ARG0("rlDriverRxHdrRead ends...\n");
1623 
1624  return syncType;
1625 }
1626 
1635 /* DesignId : MMWL_DesignId_002 */
1636 /* Requirements : AUTORADAR_REQ-784 */
1637 rlReturnVal_t rlDriverOsiInit(void)
1638 {
1639  rlReturnVal_t retVal;
1640  rlInt32_t funcRetVal;
1641 
1642  /* Create Global Mutex Object */
1643  funcRetVal = rl_driverData.clientCtx.osiCb.mutex.rlOsiMutexCreate(
1644  &rl_driverData.globalMutex, "GlobalLockObj");
1645 
1646  /* Create Command Semaphore */
1647  funcRetVal += rl_driverData.clientCtx.osiCb.sem.rlOsiSemCreate(
1648  &rl_driverData.cmdSem, "CmdSem");
1649 
1650  /* check for above function call return value */
1651  if (funcRetVal != RL_RET_CODE_OK)
1652  {
1653  /* set error code */
1654  retVal = RL_RET_CODE_RADAR_OSIF_ERROR;
1655  }
1656  else
1657  {
1658  retVal = RL_RET_CODE_OK;
1659  }
1660 
1661  return retVal;
1662 }
1663 
1664 static rlReturnVal_t rlDriverOsiCbCheck(rlClientCbs_t clientCb)
1665 {
1666  rlReturnVal_t retVal;
1667 
1668  /* Check if application has passed mutex interace functions */
1669  if ((RL_NULL_PTR == clientCb.osiCb.mutex.rlOsiMutexCreate) ||
1670  (RL_NULL_PTR == clientCb.osiCb.mutex.rlOsiMutexLock ) ||
1671  (RL_NULL_PTR == clientCb.osiCb.mutex.rlOsiMutexUnLock) ||
1672  (RL_NULL_PTR == clientCb.osiCb.mutex.rlOsiMutexDelete))
1673  {
1674  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1675  }
1676  /* Check if application has passed semaphore interface functions */
1677  else if ((RL_NULL_PTR == clientCb.osiCb.sem.rlOsiSemCreate) ||
1678  (RL_NULL_PTR == clientCb.osiCb.sem.rlOsiSemWait ) ||
1679  (RL_NULL_PTR == clientCb.osiCb.sem.rlOsiSemSignal) ||
1680  (RL_NULL_PTR == clientCb.osiCb.sem.rlOsiSemDelete))
1681  {
1682  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1683  }
1684  /* Check if application has passed communication interface functions */
1685  else if ((RL_NULL_PTR == (void*)clientCb.comIfCb.rlComIfOpen ) ||
1686  (RL_NULL_PTR == clientCb.comIfCb.rlComIfClose) ||
1687  (RL_NULL_PTR == clientCb.comIfCb.rlComIfRead ) ||
1688  (RL_NULL_PTR == clientCb.comIfCb.rlComIfWrite))
1689  {
1690  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1691  }
1692  else
1693  {
1694  /* if no error then set return value as OK */
1695  retVal = RL_RET_CODE_OK;
1696  }
1697 
1698  return retVal;
1699 }
1700 
1710 static rlReturnVal_t rlDriverClientCbCheck(rlClientCbs_t clientCb)
1711 {
1712  rlReturnVal_t retVal;
1713 
1714  if (RL_RET_CODE_OK != rlDriverOsiCbCheck(clientCb))
1715  {
1716  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1717  }
1718  /* Check if application has passed device interace functions */
1719  else if ((RL_NULL_PTR == clientCb.eventCb.rlAsyncEvent ) ||
1720  (RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceDisable ) ||
1721  (RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceEnable ) ||
1722  (RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceMaskHostIrq ))
1723  {
1724  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1725  }
1726  /* When mmWaveLink instance is running on HOST, check for interface for IRQ and delay */
1727  else if (((clientCb.platform == RL_PLATFORM_HOST) &&
1728  (((RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceWaitIrqStatus) &&
1729  (RL_NULL_PTR == clientCb.timerCb.rlDelay)))) ||
1730  (RL_NULL_PTR == clientCb.osiCb.queue.rlOsiSpawn))
1731  {
1732  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1733  }
1734  /* If CRC is enabled from application then check for CRC compute interface function */
1735  else if ((RL_NULL_PTR == clientCb.devCtrlCb.rlDeviceUnMaskHostIrq) ||
1736  (RL_NULL_PTR == clientCb.devCtrlCb.rlRegisterInterruptHandler) ||
1737  ((RL_CRC_TYPE_NO_CRC != clientCb.crcType) &&
1738  (RL_NULL_PTR == clientCb.crcCb.rlComputeCRC)))
1739  {
1740  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
1741  }
1742  else
1743  {
1744  retVal = RL_RET_CODE_OK;
1745  }
1746 
1747  return retVal;
1748 }
1749 
1761 /* DesignId : MMWL_DesignId_003 */
1762 /* Requirements : AUTORADAR_REQ-707 */
1763 rlReturnVal_t rlDriverInit(rlUInt8_t deviceMap, rlClientCbs_t clientCb)
1764 {
1765  rlReturnVal_t retVal, cbCheck;
1766  rlUInt8_t index = 0U;
1767 
1768  /* check for all interface APIs passed by the Application */
1769  cbCheck = rlDriverClientCbCheck(clientCb);
1770 
1771  if (RL_RET_CODE_OK != cbCheck)
1772  {
1773  retVal = cbCheck;
1774  }
1775  /* Initialize Driver Global Data */
1776  else if (deviceMap <= ((1U << RL_DEVICE_CONNECTED_MAX) - 0x1U))
1777  {
1778  /* Initialize Driver Global Data */
1779  for (; index < RL_DEVICE_CONNECTED_MAX; index++)
1780  {
1781  rl_driverData.isCmdRespWaited[index] = RL_FALSE;
1782  rl_driverData.isRespWriteWaited[index] = RL_FALSE;
1783  rl_driverData.rxDoneCnt[index] = 0U;
1784  rl_driverData.rxIrqCnt[index] = 0U;
1785  }
1786 
1787  /*Copy Client Context Info*/
1788  rl_driverData.clientCtx = clientCb;
1789 
1790  rl_driverData.deviceMap = deviceMap;
1791  /* intialize and stitch all OS interfaces */
1792  retVal = rlDriverOsiInit();
1793 
1794  rl_driverData.txMsgPtr = &rl_txMsg;
1795  rl_driverData.rxMsgPtr = &rl_rxMsg;
1796 #if !(RL_DISABLE_LOGGING)
1797  if (RL_RET_CODE_OK == retVal)
1798  {
1799  /*All callback copied in global strcuture, Init log parameter */
1800  retVal += rlLogInit();
1801  RL_LOGV_ARG0("Logging is enabled \n");
1802  }
1803 #endif
1804  index = 0U;
1805 
1806  do
1807  {
1808  /* If deviceIndex is set in devceMap requested by application */
1809  if (((deviceMap & (1U << index)) != 0U) && (retVal == RL_RET_CODE_OK))
1810  {
1811  /* reset to zero sequence number for that deviceIndex */
1812  rl_driverData.cmdSeqNum[index] = 0U;
1813  /* store the deviceIndex in a global structure */
1814  rl_driverData.commDevIdx.rlDevIndex[index] = index;
1815  /* Open communication interface handle */
1816  rl_driverData.commDevIdx.comIfHdl[index] =
1817  rl_driverData.clientCtx.comIfCb.rlComIfOpen(index, 0U);
1818 
1819  /* check for NULL pointer */
1820  if ((rlComIfHdl_t)RL_NULL_PTR == rl_driverData.commDevIdx.comIfHdl[index])
1821  {
1822  retVal += RL_RET_CODE_RADAR_IF_ERROR;
1823  }
1824  else
1825  {
1826  /* Register Host Interrupt Handler */
1827  if (rl_driverData.clientCtx.devCtrlCb.rlRegisterInterruptHandler(\
1828  index, (RL_P_EVENT_HANDLER)rlDriverHostIrqHandler, \
1829  (void*)RL_NULL) != RL_RET_CODE_OK)
1830  {
1831  retVal +=RL_RET_CODE_RADAR_IF_ERROR;
1832  }
1833  }
1834  /* Get next Device Map based on index */
1835  deviceMap &= ~(1U << index);
1836 
1837  /* check for any error */
1838  if (retVal != RL_RET_CODE_OK)
1839  {
1840  /* If error occured then break from this loop */
1841  break;
1842  }
1843  }
1844  /* increment Device Index */
1845  index++;
1846  }
1847  while ((deviceMap != 0U) && (index < RL_DEVICE_CONNECTED_MAX));
1848  }
1849  else
1850  {
1851  retVal = RL_RET_CODE_INVALID_INPUT;
1852  RL_LOGE_ARG0("Invaid input argument\n");
1853  }
1854 
1855  /* If no error during deviceInit then set the flag to 1 */
1856  if (retVal == RL_RET_CODE_OK)
1857  {
1858  rl_driverData.isDriverInitialized = 1U;
1859  RL_LOGD_ARG0("Driver init flag is set\n");
1860  }
1861  else
1862  {
1863  RL_LOGE_ARG0("rlDriverInit, Init failed\n");
1864  }
1865  return retVal;
1866 }
1867 
1878 /* DesignId : */
1879 /* Requirements : */
1880 rlReturnVal_t rlDriverAddDevice(rlUInt8_t deviceMap)
1881 {
1882  rlReturnVal_t retVal;
1883  rlUInt8_t index = 0U;
1884 
1885  RL_LOGV_ARG0("rlDeviceAddDevices starts\n");
1886 
1887  if ((rl_driverData.isDriverInitialized != (rlUInt8_t)0U) && \
1888  (deviceMap <= ((1U << RL_DEVICE_CONNECTED_MAX) - 0x1U)))
1889  {
1890  /* Add to the global device map */
1891  rl_driverData.deviceMap |= deviceMap;
1892 
1893  do
1894  {
1895  /* If deviceIndex is set in devceMap requested by application */
1896  if ((deviceMap & (1U << index)) != 0U)
1897  {
1898  /* reset to zero sequence number for that deviceIndex */
1899  rl_driverData.cmdSeqNum[index] = 0U;
1900  /* store the deviceIndex in a global structure */
1901  rl_driverData.commDevIdx.rlDevIndex[index] = index;
1902  /* Open communication interface handle */
1903  rl_driverData.commDevIdx.comIfHdl[index] = \
1904  rl_driverData.clientCtx.comIfCb.rlComIfOpen(index, 0U);
1905 
1906  if ((rlComIfHdl_t)RL_NULL_PTR != rl_driverData.commDevIdx.comIfHdl[index])
1907  {
1908  /* register Interrupt handler */
1909  if ((rl_driverData.clientCtx.devCtrlCb.rlRegisterInterruptHandler(\
1910  index, (RL_P_EVENT_HANDLER)rlDriverHostIrqHandler, \
1911  (void*)RL_NULL) != RL_RET_CODE_OK) ||
1912  (rl_driverData.clientCtx.devCtrlCb.rlDeviceEnable(index) < 0))
1913  {
1914  /* set the error code */
1915  retVal = RL_RET_CODE_RADAR_IF_ERROR;
1916  }
1917  else
1918  {
1919  retVal = RL_RET_CODE_OK;
1920  }
1921  }
1922  else
1923  {
1924  retVal =RL_RET_CODE_RADAR_IF_ERROR;
1925  }
1926  deviceMap &= ~(1U << index);
1927  }
1928  else
1929  {
1930  retVal = RL_RET_CODE_OK;
1931  }
1932 
1933  /* break the loop if any error occured during above callbacks */
1934  if (RL_RET_CODE_OK != retVal)
1935  {
1936  break;
1937  }
1938  /* increment device index */
1939  index++;
1940  }
1941  while ((deviceMap != 0U) && (index < RL_DEVICE_CONNECTED_MAX));
1942  }
1943  else
1944  {
1945  if (deviceMap > ((1U << RL_DEVICE_CONNECTED_MAX) - 0x1U))
1946  {
1947  retVal = RL_RET_CODE_INVALID_INPUT;
1948  RL_LOGE_ARG0("Invaid input argument\n");
1949  }
1950  else
1951  {
1952  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
1953  RL_LOGE_ARG0("rlDriverAddDevice, Invalid state \n");
1954  }
1955  }
1956  RL_LOGV_ARG0("rlDeviceAddDevices completes\n");
1957 
1958  return retVal;
1959 }
1960 
1971 /* DesignId : */
1972 /* Requirements : */
1973 rlReturnVal_t rlDriverRemoveDevices(rlUInt8_t deviceMap)
1974 {
1975  rlUInt8_t index;
1976  rlReturnVal_t retVal = RL_RET_CODE_OK;
1977 
1978  RL_LOGV_ARG0("rlDriverRemoveDevices starts...\n");
1979 
1980  /* Clear the device map from driver data */
1981  rl_driverData.deviceMap &= ~deviceMap;
1982 
1983  for (index = 0U; ((deviceMap != 0U) && (index < RL_DEVICE_CONNECTED_MAX));\
1984  index++)
1985  {
1986  if ((deviceMap & (1U << index)) != 0U)
1987  {
1988  /* Close mmwave radar device communication Channel */
1989  if (rl_driverData.commDevIdx.comIfHdl[index] != RL_NULL_PTR)
1990  {
1991  retVal += rl_driverData.clientCtx.comIfCb.rlComIfClose( \
1992  rl_driverData.commDevIdx.comIfHdl[index]);
1993  rl_driverData.commDevIdx.comIfHdl[index] = RL_NULL_PTR;
1994  }
1995 
1996  /* Un Register Interrupt Handler */
1997  (void)rl_driverData.clientCtx.devCtrlCb.rlRegisterInterruptHandler(
1998  index, RL_NULL, RL_NULL);
1999 
2000  deviceMap &= ~(1U << index);
2001  }
2002  }
2003  RL_LOGV_ARG0("rlDriverRemoveDevices completes\n");
2004  return retVal;
2005 }
2006 
2016 /* DesignId : */
2017 /* Requirements : AUTORADAR_REQ-711 */
2018 rlReturnVal_t rlDriverDeInit(void)
2019 {
2020  rlUInt8_t index;
2021  rlUInt8_t deviceMap = rl_driverData.deviceMap;
2022  rlReturnVal_t retVal = RL_RET_CODE_OK;
2023 
2024  RL_LOGV_ARG0("rlDriverDeInit starts...\n");
2025 
2026  for (index = 0U; ((deviceMap != 0U) && (index < RL_DEVICE_CONNECTED_MAX));\
2027  index++)
2028  {
2029  if ((deviceMap & (1U << index)) != 0U)
2030  {
2031  /* Close mmwave radar device communication Channel */
2032  if (rl_driverData.commDevIdx.comIfHdl[index] != RL_NULL_PTR)
2033  {
2034  retVal += rl_driverData.clientCtx.comIfCb.rlComIfClose( \
2035  rl_driverData.commDevIdx.comIfHdl[index]);
2036  rl_driverData.commDevIdx.comIfHdl[index] = RL_NULL_PTR;
2037  }
2038 
2039  /* Un Register Interrupt Handler */
2040  (void)rl_driverData.clientCtx.devCtrlCb.rlRegisterInterruptHandler(
2041  index, RL_NULL, RL_NULL);
2042 
2043  deviceMap &= ~(1U << index);
2044  }
2045  }
2046  /* Destroy Global Mutex */
2047  if (rl_driverData.globalMutex != RL_NULL_PTR)
2048  {
2049  retVal += rl_driverData.clientCtx.osiCb.mutex.rlOsiMutexDelete(
2050  &rl_driverData.globalMutex);
2051  rl_driverData.globalMutex = RL_NULL_PTR;
2052  RL_LOGD_ARG0("Destroy Global Mutex\n");
2053  }
2054 
2055  /* Destroy Command Semaphore */
2056  if (rl_driverData.cmdSem != RL_NULL_PTR)
2057  {
2058  retVal += rl_driverData.clientCtx.osiCb.sem.rlOsiSemDelete(\
2059  &rl_driverData.cmdSem);
2060  rl_driverData.cmdSem = RL_NULL_PTR;
2061  RL_LOGD_ARG0("Destroy Command Semaphore\n");
2062  }
2063 
2064  rl_driverData.deviceMap = 0U;
2065  rl_driverData.isDriverInitialized = 0U;
2066  RL_LOGV_ARG0("rlDriverDeInit ends...\n");
2067 
2068  return retVal;
2069 }
2070 
2079 /* DesignId : */
2080 /* Requirements : */
2082 {
2083  /* return driverData pointer/handle */
2084  return (&rl_driverData);
2085 }
2086 
2095 /* DesignId : */
2096 /* Requirements : */
2097 rlUInt8_t rlDriverGetPlatformId(void)
2098 {
2099  RL_LOGV_ARG0("rlDriverGetPlatformId is called \n");
2100  /* return platform ID */
2101  return (rl_driverData.clientCtx.platform);
2102 }
2103 
2104 
2113 /* DesignId : */
2114 /* Requirements : */
2116 {
2117  RL_LOGV_ARG0("rlDriverGetArDeviceType is called \n");
2118  /* return AWR device Type */
2119  return (rl_driverData.clientCtx.arDevType);
2120 }
2121 
2132 /* DesignId : */
2133 /* Requirements : */
2134 rlReturnVal_t rlDriverIsDeviceMapValid(rlUInt8_t deviceMap)
2135 {
2136  rlUInt8_t storedDevMap;
2137  rlReturnVal_t retVal;
2138 
2139  RL_LOGV_ARG0("rlDriverIsDeviceMapValid starts \n");
2140 
2141  /* get the no. of connected device */
2142  storedDevMap = rl_driverData.deviceMap;
2143 
2144  if ((storedDevMap & deviceMap) != 0U)
2145  {
2146  /* set return value to success */
2147  retVal = 0;
2148  }
2149  else
2150  {
2151  /* set return value to failure */
2152  retVal = -1;
2153  RL_LOGE_ARG0("Device map is In-valid \n");
2154  }
2155  RL_LOGV_ARG0("rlDriverIsDeviceMapValid ends \n");
2156 
2157  return retVal;
2158 }
2159 
2172 /* DesignId : MMWL_DesignId_024 */
2173 /* Requirements : AUTORADAR_REQ-774 */
2174 /*AR_CODE_REVIEW MR:R.2.2 <APPROVED> "payloadLen is re initialized after each pass to the
2175  rlGetSubBlock fucntion as it is passed again to the function" */
2176 /*LDRA_INSPECTED 8 D */
2177 rlReturnVal_t rlDriverWaitForResponse(rlUInt8_t devIndex,
2178  rlDriverMsg_t* outMsg)
2179 {
2180  rlUInt16_t rspChunks;
2181  rlPayloadSb_t errorSB;
2182  rlReturnVal_t retVal, retVal1;
2183  rlUInt16_t indx;
2184  rlUInt8_t payloadLen = 0U;
2185 
2186  RL_LOGV_ARG0("rlDriverWaitForResponse starts... \n");
2187 
2188  do
2189  {
2190  /* Wait for Host Interrupt and Read the Response */
2191  retVal1 = rlDriverMsgReadCmdCtx(devIndex);
2192  if (RL_RET_CODE_OK == retVal1)
2193  {
2194  /* Get number of chunks in the response */
2195  rspChunks = rl_rxMsg.hdr.remChunks;
2196 
2197  /* Check if Number of Sub Block doesn't exceed expected number */
2198  if (outMsg->opcode.nsbc >= rl_rxMsg.hdr.nsbc)
2199  {
2200  outMsg->opcode.nsbc = rl_rxMsg.hdr.nsbc;
2201  /* Loop for number of chunks and copy payload */
2202  for (indx = 0U; indx < (outMsg->opcode.nsbc); indx++)
2203  {
2204  /* Copy Payload to output variable*/
2205  /* AR_CODE_REVIEW MR:R.18.4 <APPROVED> "pointer arithmetic required" */
2206  /*LDRA_INSPECTED 87 S */
2207  (void)rlGetSubBlock(rl_rxMsg.payload + payloadLen,
2208  &(outMsg->subblocks[indx].sbid),
2209  &(outMsg->subblocks[indx].len),
2210  outMsg->subblocks[indx].pSblkData);
2211  payloadLen += (rlUInt8_t)(outMsg->subblocks[indx].len);
2212 
2213  }
2214  }
2215  retVal = retVal1;
2216  }
2217  else if (RL_RET_CODE_MSGID_MISMATCHED == retVal1)
2218  {
2219  /* Number of Sub Block is unexpected. Error Case */
2220  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function.
2221  LDRA Tool Issue" */
2222  /*LDRA_INSPECTED 105 D */
2223  rlErrorResp_t errMsgSbData = {(rlSysNRespType_t)0U, (rlUInt16_t)0U};
2224 
2225  errorSB.pSblkData = (rlUInt8_t* )&errMsgSbData;
2226 
2227  /* Copy Payload to local variable*/
2228  /* AR_CODE_REVIEW MR:R.18.4 <APPROVED> "pointer arithmetic required" */
2229  /*LDRA_INSPECTED 87 S */
2230  (void)rlGetSubBlock(rl_rxMsg.payload + payloadLen,
2231  &(errorSB.sbid), &(errorSB.len),
2232  errorSB.pSblkData);
2233 
2234  /* Return Error to indicate command failure */
2235  retVal = (rlReturnVal_t)(errMsgSbData.errorType);
2236  rspChunks = 0U;
2237 
2238  RL_LOGE_ARG0("msg id mis-match, command failure\n");
2239 
2240  }
2241  else
2242  {
2243  /* Timeout in receiving response*/
2244  rspChunks = 0U;
2245  retVal = retVal1;
2246  RL_LOGE_ARG0("Timeout in receiving response\n");
2247  }
2248  }
2249  while (rspChunks > 0U);
2250 
2251  RL_LOGV_ARG0("rlDriverWaitForResponse ends... \n");
2252 
2253  return retVal;
2254 }
2255 
2256 static rlReturnVal_t rlDriverCmdWriter(rlUInt8_t devIndex, rlDriverMsg_t* outMsg)
2257 {
2258  rlReturnVal_t retVal;
2259  rlUInt8_t retryCount = 0U;
2260  rlDriverData_t *rlDrvData = rlDriverGetHandle();
2261  rlUInt8_t isPayloadValid = RL_FALSE;
2262 
2263  do
2264  {
2265  if (retryCount != 0U)
2266  {
2267  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by
2268  other function" */
2269  /*LDRA_INSPECTED 105 D */
2270  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "rlDrvData Can't be NULL" */
2271  /*LDRA_INSPECTED 45 D */
2272  rlDrvData->funcParams.cmd->hdr.flags.b2RetryFlag = RL_HDR_FLAG_RETRY;
2273  }
2274  retryCount++;
2275 
2276  if ( rlDrvData->clientCtx.ackTimeout != 0U)
2277  {
2278  /* Set flag to true and check for it in Host IRQ handler routine*/
2279  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by
2280  other function" */
2281  /*LDRA_INSPECTED 105 D */
2282  rlDrvData->isCmdRespWaited[devIndex] = RL_TRUE;
2283  }
2284  /* send the command to mmWave Radar device */
2285  retVal = rlDriverMsgWrite(rlDrvData, rlDrvData->commDevIdx.comIfHdl[devIndex]);
2286 
2287  if (RL_RET_CODE_OK == retVal)
2288  {
2289  /* Check if It needs to wait for ACK*/
2290  if (rlDrvData->clientCtx.ackTimeout != 0U)
2291  {
2292  /* wait for respond */
2293  retVal += rlDriverWaitForResponse(devIndex, outMsg);
2294  RL_LOGD_ARG0("rlDriverCmdWriter, wait for respond\n");
2295  }
2296 
2297  /* Response received Successfully */
2298  if ((RL_RET_CODE_OK == retVal) || \
2299  ((RL_RET_CODE_CRC_FAILED != retVal) && \
2300  (RL_RET_CODE_RESP_TIMEOUT != retVal)))
2301  {
2302  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Set to TRUE for valid payload" */
2303  /*LDRA_INSPECTED 8 D */
2304  isPayloadValid = RL_TRUE;
2305  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by
2306  other function" */
2307  /*LDRA_INSPECTED 105 D */
2308  rlDrvData->isCmdRespWaited[devIndex] = RL_FALSE;
2309  /* Increment the Sequence Number */
2310  rlDrvData->cmdSeqNum[devIndex]++;
2311  }
2312 
2313  }
2314  else
2315  {
2316  /* Error in command message write */
2317  if (rlDrvData->clientCtx.ackTimeout != 0U)
2318  {
2319  rlDrvData->isCmdRespWaited[devIndex] = RL_FALSE;
2320  }
2321  RL_LOGE_ARG0("rlDriverCmdWriter, Error in cmd msg write\n");
2322  break;
2323  }
2324  }
2325  while ((retryCount < RL_API_CMD_RETRY_COUNT) && (isPayloadValid == RL_FALSE));
2326 
2327  return retVal;
2328 }
2329 
2341 /* DesignId : MMWL_DesignId_023 */
2342 /* Requirements : AUTORADAR_REQ-772, AUTORADAR_REQ-774, AUTORADAR_REQ-775, AUTORADAR_REQ-778,\
2343  AUTORADAR_REQ-781 */
2344 rlReturnVal_t rlDriverCmdSendRetry(rlUInt8_t deviceMap, rlDriverMsg_t* outMsg)
2345 {
2346  rlReturnVal_t retVal;
2347  rlUInt8_t devIndex = 0U;
2348  rlDriverData_t *rlDrvData = rlDriverGetHandle();
2349 
2350  if ((rlDrvData == RL_NULL) || (rlDrvData->funcParams.cmd == RL_NULL))
2351  {
2352  retVal = RL_RET_CODE_FATAL_ERROR;
2353  }
2354  else
2355  {
2356  retVal = RL_RET_CODE_OK;
2357  }
2358 
2359  /* Send Command to Device connected and wait for response one by one */
2360  /* AR_CODE_REVIEW MR:D.2.1 <APPROVED> "This loop terminates when it sends commands to all
2361  * connected devices or when any of devices returns -ve response" */
2362  /*LDRA_INSPECTED 28 D */
2363  while ((deviceMap != 0U) && (RL_RET_CODE_OK == retVal))
2364  {
2365  if ((deviceMap & (1U << devIndex)) != 0U)
2366  {
2367  /* Fill Command Sequence Number */
2368  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by other function" */
2369  /*LDRA_INSPECTED 105 D */
2370  /*LDRA_INSPECTED 8 D */
2371  rlDrvData->funcParams.cmd->hdr.flags.b4SeqNum =
2372  rlDrvData->cmdSeqNum[devIndex] % 16U;
2373 
2374  /* Write command to slave device */
2375  retVal += rlDriverCmdWriter(devIndex, outMsg);
2376 
2377  deviceMap &= ~(1U << devIndex);
2378  }/* End of If */
2379  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Global variable is used by other function" */
2380  /*LDRA_INSPECTED 105 D */
2381  rlDrvData->isCmdRespWaited[devIndex] = RL_FALSE;
2382  devIndex++;
2383  }/* End for Loop */
2384 
2385  return retVal;
2386 }
2387 
2404 /* DesignId : MMWL_DesignId_023 */
2405 /* Requirements : AUTORADAR_REQ-772, AUTORADAR_REQ-774, AUTORADAR_REQ-776 */
2406 rlReturnVal_t rlDriverCmdInvoke(rlUInt8_t deviceMap, rlDriverMsg_t inMsg,
2407  rlDriverMsg_t* outMsg)
2408 {
2409  rlReturnVal_t retVal;
2410  rlUInt8_t protAlignSize;
2411  rlUInt16_t indx, msgCrcLen;
2412  rlUInt16_t payloadLen = 0U;
2413 
2414  RL_LOGV_ARG0("rlDriverCmdInvoke starts... \n");
2415 
2416  if (rl_driverData.isDriverInitialized != (rlUInt8_t)0U)
2417  {
2418  rlReturnVal_t retVal1 = RL_RET_CODE_OK;
2419  (void)rl_driverData.clientCtx.osiCb.mutex.rlOsiMutexLock
2420  (&(rl_driverData.globalMutex), (rlOsiTime_t)RL_OSI_WAIT_FOREVER);
2421 
2422  /* Fill Command Header */
2423  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Some of variables are re-assigned based
2424  on different conditions."*/
2425  /*LDRA_INSPECTED 8 D */
2426  rl_txMsg.hdr.opcode.b4Direction = inMsg.opcode.dir;
2427  rl_txMsg.hdr.opcode.b2MsgType = inMsg.opcode.msgType;
2428  rl_txMsg.hdr.opcode.b10MsgId = inMsg.opcode.msgId;
2429  rl_txMsg.hdr.remChunks = inMsg.remChunks;
2430  rl_txMsg.hdr.nsbc = inMsg.opcode.nsbc;
2431  rl_txMsg.hdr.flags.b2AckFlag = 0U;
2432  rl_txMsg.hdr.flags.b2Crc = 0U;
2433  rl_txMsg.hdr.flags.b2CrcLen = 0U;
2434  rl_txMsg.hdr.flags.b2RetryFlag = 0U;
2435  rl_txMsg.hdr.flags.b4SeqNum = 0U;
2436  rl_txMsg.hdr.flags.b4Version = 0U;
2437 
2438  /* Fill Payload */
2439  for (indx = 0U; indx < inMsg.opcode.nsbc; indx++)
2440  {
2441  /* append all subblock len, id and data to one global structure */
2442  retVal1 += rlAppendSubBlock(&rl_txMsg.payload[payloadLen],
2443  inMsg.subblocks[indx].sbid,
2444  inMsg.subblocks[indx].len,
2445  inMsg.subblocks[indx].pSblkData);
2446  /* increment payload length as appending each sub-block data in a message */
2447  payloadLen += inMsg.subblocks[indx].len + \
2448  (rlUInt16_t)(RL_SBC_ID_SIZE + RL_SBC_LEN_SIZE);
2449  if (RL_RET_CODE_OK != retVal1)
2450  {
2451  break;
2452  }
2453  }
2454 
2455  /* if above for loop is not terminated due to any error */
2456  if (indx == inMsg.opcode.nsbc)
2457  {
2458  rl_txMsg.hdr.len = RHCP_HEADER_LEN + payloadLen;
2459 
2460  /* Update command and response buffers */
2461  rl_driverData.funcParams.cmd = &rl_txMsg;
2462  rl_driverData.funcParams.rsp = &rl_rxMsg;
2463 
2464  /* Check if ACK is Requested*/
2465  if (rl_driverData.clientCtx.ackTimeout == 0U)
2466  {
2467  /* No ACK Requested */
2468  rl_txMsg.hdr.flags.b2AckFlag = RL_HDR_FLAG_NO_ACK;
2469  }
2470 
2471  /* Check if CRC is required to be sent*/
2472  if (rl_driverData.clientCtx.crcType == RL_CRC_TYPE_NO_CRC)
2473  {
2474  /* CRC Not Included */
2475  rl_txMsg.hdr.flags.b2Crc = RL_HDR_FLAG_NO_CRC;
2476  }
2477 
2478  /* Append Dummy Bytes if CRC is present */
2479  if (rl_driverData.funcParams.cmd->hdr.flags.b2Crc == RL_HDR_FLAG_CRC)
2480  {
2481  rl_txMsg.hdr.flags.b2CrcLen = rl_driverData.clientCtx.crcType;
2482 
2483  /* It may be size 2/4/8 based on 16/32/64 bit */
2484  msgCrcLen = (2U << (rl_driverData.clientCtx.crcType & 0x3U));
2485 
2486  protAlignSize = (rl_driverData.clientCtx.crcType < RL_CRC_TYPE_64BIT_ISO) ? \
2487  RL_PAYLOAD_MSG_4BYTE_MULT : RL_PAYLOAD_MSG_8BYTE_MULT;
2488 
2489  /* Add Padding Byte to payload - This is required before CRC calculation*/
2490  if ((rl_driverData.funcParams.cmd->hdr.len % protAlignSize) != 0U)
2491  {
2492  /* AR_CODE_REVIEW MR:R.18.1,R.18.4 <APPROVED> "pointer arithmetic required" */
2493  /*LDRA_INSPECTED 567 S */
2494  /* AR_CODE_REVIEW MR:R.10.3 <APPROVED> "All parameter types are matching to
2495  function argument type. LDRA tool issue." */
2496  /*LDRA_INSPECTED 458 S */
2497  /*LDRA_INSPECTED 87 S */
2498  (void)rlAppendDummy((rlUInt8_t*)((rlUInt8_t*)rl_driverData.funcParams.cmd + \
2499  rl_driverData.funcParams.cmd->hdr.len + SYNC_PATTERN_LEN), \
2500  (rlUInt8_t)(protAlignSize - \
2501  (rlUInt8_t)(rl_driverData.funcParams.cmd->hdr.len % protAlignSize)));
2502  rl_driverData.funcParams.cmd->hdr.len += (rlUInt16_t)(protAlignSize - \
2503  (rlUInt16_t)(rl_driverData.funcParams.cmd->hdr.len % protAlignSize));
2504  }
2505  rl_driverData.funcParams.cmd->hdr.len += msgCrcLen;
2506  }
2507 
2508  retVal = rlDriverCmdSendRetry(deviceMap, outMsg);
2509  /* Release the Global Mutex */
2510  (void)rl_driverData.clientCtx.osiCb.mutex.rlOsiMutexUnLock(\
2511  &(rl_driverData.globalMutex));
2512  }
2513  else
2514  {
2515  retVal = retVal1;
2516  }
2517  }
2518  else
2519  {
2520  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
2521  RL_LOGE_ARG0("rlDriverCmdInvoke, Invalid input \n");
2522  }
2523 
2524  RL_LOGV_ARG0("rlDriverCmdInvoke ends... \n");
2525 
2526  return retVal;
2527 }
2528 
2538 rlReturnVal_t rlDriverConfigureCrc(rlCrcType_t crcType)
2539 {
2540  rlReturnVal_t retVal;
2541 
2542  RL_LOGV_ARG0("rlDriverConfigureCrc starts... \n");
2543  /* Check if driver is initialized */
2544  if (rl_driverData.isDriverInitialized == 1U)
2545  {
2546  /* Set CRC Type to global structure */
2547  rl_driverData.clientCtx.crcType = crcType;
2548  RL_LOGD_ARG0("rlDriverConfigureCrc is success\n");
2549  retVal = RL_RET_CODE_OK;
2550  }
2551  else
2552  {
2553  /* if driver is not initialized then return and error value */
2554  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
2555  }
2556  RL_LOGV_ARG0("rlDriverConfigureCrc ends... \n");
2557 
2558  return retVal;
2559 }
2560 
2570 /* DesignId : */
2571 /* Requirements : */
2572 rlReturnVal_t rlDriverConfigureAckTimeout(rlUInt32_t ackTimeout)
2573 {
2574  rlReturnVal_t retVal;
2575 
2576  RL_LOGV_ARG0("rlDriverConfigureAckTimeout starts... \n");
2577  /* Check if driver is initialized */
2578  if (rl_driverData.isDriverInitialized == 1U)
2579  {
2580  /* set ACK timeout to global structure */
2581  rl_driverData.clientCtx.ackTimeout = ackTimeout;
2582  RL_LOGD_ARG0("rlDriverConfigureAckTimeout is success\n");
2583  retVal = RL_RET_CODE_OK;
2584  }
2585  else
2586  {
2587  /* if driver is not initialized then return and error value */
2588  retVal = RL_RET_CODE_INVALID_STATE_ERROR;
2589  }
2590  RL_LOGV_ARG0("rlDriverConfigureAckTimeout ends... \n");
2591 
2592  return retVal;
2593 }
2594 
2605 /* DesignId : */
2606 /* Requirements : */
2607 rlPrintFptr rlGetLogFptr(rlUInt8_t dbgLevel)
2608 {
2609  rlPrintFptr retFuncPtr;
2610  if (dbgLevel > 0U)
2611  {
2612  /* If debug level is valid the set debug function pointer */
2613  retFuncPtr = rl_driverData.logObj.rlPrintAr[dbgLevel - (rlUInt8_t)1U];
2614  }
2615  else
2616  {
2617  /* If debug level is valid the set debug function pointer to NULL */
2618  retFuncPtr = RL_NULL_PTR;
2619  }
2620 
2621  return retFuncPtr;
2622 }
2623 
2633 /* DesignId : MMWL_DesignId_031 */
2634 /* Requirements : AUTORADAR_REQ-712 */
2635 rlReturnVal_t rlLogInit(void)
2636 {
2637  rlReturnVal_t retVal;
2638  rlDriverData_t* rlDrvData = &rl_driverData;
2639  rlPrintFptr fPtr;
2640  rlUInt8_t level, idx;
2641  /* store debug level to local variable */
2642  level = rlDrvData->clientCtx.dbgCb.dbgLevel;
2643  /* store Function pointer to local variable */
2644  fPtr = rlDrvData->clientCtx.dbgCb.rlPrint;
2645 
2646  /* check for Function pointer for NON-NULL */
2647  if (fPtr != RL_NULL_PTR)
2648  {
2649  switch (level)
2650  {
2651  case RL_DBG_LEVEL_VERBOSE :
2652  case RL_DBG_LEVEL_DEBUG :
2653  case RL_DBG_LEVEL_INFO :
2654  case RL_DBG_LEVEL_WARNING :
2655  case RL_DBG_LEVEL_ERROR :
2656  for (idx = level; idx > RL_DBG_LEVEL_NONE; idx--)
2657  {
2658  rlDrvData->logObj.rlPrintAr[idx - 1U] = fPtr;
2659  }
2660  break;
2661  case RL_DBG_LEVEL_NONE :
2662  {
2663  (void)fPtr("INFO: MMWAVELINK Logging is disabled\n");
2664  /* reset all function pointers to NULL */
2665  (void)memset(&rlDrvData->logObj.rlPrintAr[0], 0U, sizeof(rlLogCtx_t));
2666  break;
2667  }
2668  default :
2669  {
2670  (void)fPtr("INFO: Invalid MMWAVELINK Logging, hence disbled\n");
2671  /* if dbgLevel is set beyond expected value then assign NONE */
2672  rlDrvData->clientCtx.dbgCb.dbgLevel = RL_DBG_LEVEL_NONE;
2673 
2674  /* reset all function pointers to NULL */
2675  (void)memset(&rlDrvData->logObj.rlPrintAr[0], 0U, sizeof(rlLogCtx_t));
2676  break;
2677  }
2678  }
2679  retVal = RL_RET_CODE_OK;
2680  }
2681  else
2682  {
2683  /* reset all function pointers to NULL */
2684  (void)memset(&rlDrvData->logObj.rlPrintAr[0], 0U, sizeof(rlLogCtx_t));
2685  retVal = RL_RET_CODE_INTERFACE_CB_NULL;
2686  }
2687 
2688  return retVal;
2689 }
2690 
2703 void rlDriverConstructInMsg(rlUInt16_t msgId, rlDriverMsg_t* inMsg, rlPayloadSb_t* payloadPtr)
2704 {
2705  /* check for NULL pointer */
2706  if (inMsg != NULL)
2707  {
2708  rlUInt8_t cmdDir;
2709  /* Set Command Header Opcode */
2710  inMsg->opcode.nsbc = 1U;
2711  inMsg->opcode.msgType = RL_API_CLASS_CMD;
2712  inMsg->opcode.msgId = msgId;
2713  inMsg->remChunks = 0U;
2714  /* get command direction based on requested MsgId */
2715  cmdDir = rlDeviceIdentifyCmdDir(msgId, rlDriverGetPlatformId());
2716  inMsg->opcode.dir = cmdDir;
2717  inMsg->subblocks = payloadPtr;
2718  }
2719  else
2720  {
2721  /* Error: iutMsg is sent as NULL */
2722  RL_LOGV_ARG0("rlDriverConstructInMsg construct InMsg failed!!!\n");
2723  }
2724 }
2725 
2738 void rlDriverConstructOutMsg(rlUInt16_t numSblk, rlDriverMsg_t* outMsg,
2739  rlPayloadSb_t* payloadPtr)
2740 {
2741  /* check for NULL pointer */
2742  if (outMsg != NULL)
2743  {
2744  /* Set num of sub-block to outMsg Opcode field */
2745  outMsg->opcode.nsbc = numSblk;
2746  /* assign payload pointer to subblock ot outMsg */
2747  outMsg->subblocks = payloadPtr;
2748  }
2749  else
2750  {
2751  /* Error: outMsg is sent as NULL */
2752  RL_LOGV_ARG0("rlDriverConstructOutMsg construct OutMsg failed!!!\n");
2753  }
2754 }
2755 
2769 void rlDriverFillPayload(rlUInt16_t msgId, rlUInt16_t sbcID, rlPayloadSb_t* payloadPtr,
2770  rlUInt8_t* data, rlUInt16_t inLen)
2771 {
2772  /* check for NULL pointer */
2773  if (payloadPtr != NULL)
2774  {
2775  /* get Unique Sub-Block ID and asign it to Command Sub Block */
2776  payloadPtr->sbid = (rlUInt16_t)RL_GET_UNIQUE_SBID(msgId, sbcID);
2777 
2778  /* set Command Sub-block length to sizeof command strcuture type */
2779  payloadPtr->len = inLen;
2780  /* set sub-block data pointer to payload structure */
2781  payloadPtr->pSblkData = data;
2782  }
2783  else
2784  {
2785  RL_LOGV_ARG0("rlDriverFillPayload data fill failed!!!\n");
2786  }
2787 }
2788 
2802 rlReturnVal_t rlDriverExecuteGetApi(rlUInt8_t deviceMap, rlUInt16_t msgId,
2803  rlUInt16_t sbcID, rlUInt8_t *msgData, rlUInt16_t inLen)
2804 {
2805  /*LDRA waiver 8 D - DD data flow anomalies found- */
2806  rlReturnVal_t retVal;
2807  /* Initialize Command and Response Sub Blocks */
2808  /* Initialize in-message structure to zero */
2809  rlDriverMsg_t inMsg = {0};
2810  /* Initialize out-message structure to zero */
2811  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function. LDRA Tool Issue" */
2812  /*LDRA_INSPECTED 105 D */
2813  rlDriverMsg_t outMsg = {0};
2814  /* Initialize in-payload sub-block structure to zero */
2815  rlPayloadSb_t inPayloadSb = {0};
2816  /* Initialize out-payload sub-block structure to zero */
2817  rlPayloadSb_t outPayloadSb = {0};
2818 
2819  /* Construct command packet */
2820  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function. LDRA Tool Issue" */
2821  /*LDRA_INSPECTED 8 D */
2822  rlDriverConstructInMsg(msgId, &inMsg, &inPayloadSb);
2823 
2824  /* Fill in-message Payload */
2825  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function. LDRA Tool Issue" */
2826  /*LDRA_INSPECTED 105 D */
2827  rlDriverFillPayload(msgId, sbcID, &inPayloadSb, NULL , 0U);
2828 
2829  /* Construct response packet */
2830  rlDriverConstructOutMsg(1U, &outMsg, &outPayloadSb);
2831 
2832  /* Fill out-message Payload */
2833  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function. LDRA Tool Issue" */
2834  /*LDRA_INSPECTED 105 D */
2835  rlDriverFillPayload(0U, 0U, &outPayloadSb, msgData, inLen);
2836 
2837  /* Send Command to mmWave Radar Device */
2838  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "Can't be NULL" */
2839  /*LDRA_INSPECTED 45 D */
2840  retVal = rlDriverCmdInvoke(deviceMap, inMsg, &outMsg);
2841 
2842  return retVal;
2843 }
2844 
2858 rlReturnVal_t rlDriverExecuteSetApi(rlUInt8_t deviceMap, rlUInt16_t msgId,
2859  rlUInt16_t sbcID, rlUInt8_t *msgData, rlUInt16_t inLen)
2860 {
2861  /*LDRA waiver 8 D - DD data flow anomalies found- */
2862  rlReturnVal_t retVal;
2863  /* Initialize in-message structure to zero */
2864  rlDriverMsg_t inMsg = {0};
2865  /* Initialize out-message structure to zero */
2866  rlDriverMsg_t outMsg = {0};
2867  /* Initialize in-payload sub-block structure to zero */
2868  rlPayloadSb_t inPayloadSb = {0};
2869 
2870  /* Construct command packet */
2871  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are updated in other function.
2872  LDRA Tool Issue" */
2873  /*LDRA_INSPECTED 8 D */
2874  rlDriverConstructInMsg(msgId, &inMsg, &inPayloadSb);
2875 
2876  /* Fill in-message Payload */
2877  /* AR_CODE_REVIEW MR:R.2.2 <APPROVED> "Values are used by called function.
2878  LDRA Tool Issue" */
2879  /*LDRA_INSPECTED 105 D */
2880  rlDriverFillPayload(msgId, sbcID, &inPayloadSb, msgData, inLen);
2881 
2882  /* Send Command to mmWave Radar Device */
2883  /* AR_CODE_REVIEW MR:D.4.1,D.4.14 <APPROVED> "Can't be NULL" */
2884  /*LDRA_INSPECTED 45 D */
2885  retVal = rlDriverCmdInvoke(deviceMap, inMsg, &outMsg);
2886 
2887  return retVal;
2888 }
2889 
2890 /*
2891  * END OF rl_driver.c FILE
2892  */
rlInt32_t(* rlOsiSemWait)(rlOsiSemHdl_t *semHdl, rlOsiTime_t timeout)
Wait for Semaphore.
Definition: mmwavelink.h:1051
rlReturnVal_t rlDriverMsgReadCmdCtx(rlUInt8_t devIndex)
Wait and handle command response.
Definition: rl_driver.c:892
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:1339
mmWaveLink client callback structure
Definition: mmwavelink.h:1330
volatile rlUInt8_t isCmdRespWaited[RL_DEVICE_CONNECTED_MAX]
Driver Command Wait Flag.
Definition: rl_driver.h:252
rlUInt8_t dir
Message Direction.
Definition: rl_driver.h:320
rlInt32_t(* rlDeviceEnable)(rlUInt8_t deviceIndex)
Bring mmWave radar device out of Reset.
Definition: mmwavelink.h:1206
rlReturnVal_t rlDriverMsgCmdReply(rlDriverData_t *rlDrvData, rlUInt8_t devIndex)
Wait and handle command response.
Definition: rl_driver.c:791
rlUInt8_t rlDeviceIdentifyCmdDir(rlUInt16_t msgId, rlUInt8_t platform)
Get the direction of command packet based on MsgID and platform.
Definition: rl_driver.c:407
rlReturnVal_t rlDriverConfigureCrc(rlCrcType_t crcType)
Configures the CRC Type in mmwavelink Driver.
Definition: rl_driver.c:2538
rlInt32_t(* rlOsiSemCreate)(rlOsiSemHdl_t *semHdl, rlInt8_t *name)
Create Semaphore Object.
Definition: mmwavelink.h:1037
rlUInt8_t platform
0x0: mmWaveLink runs on Ext Host, 0x1: mmWaveLink runs on MSS, 0x2: mmWaveLink runs on DSS ...
Definition: mmwavelink.h:1376
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:260
rlUInt8_t msgType
Message Class.
Definition: rl_driver.h:324
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:2738
rlInt32_t(* rlOsiMutexUnLock)(rlOsiMutexHdl_t *mutexHdl)
Unlock Mutex Object.
Definition: mmwavelink.h:1004
rlUInt8_t rlDevIndex[RL_DEVICE_CONNECTED_MAX]
stores device Index
Definition: rl_driver.h:221
rlUInt32_t ackTimeout
ACK wait timeout in Milliseconds, 0 - No ACK Configuration of the timeout should consider interrupt l...
Definition: mmwavelink.h:1370
rlUInt16_t msgId
Message Id.
Definition: rl_driver.h:328
rlUInt16_t cmdSeqNum[RL_DEVICE_CONNECTED_MAX]
Driver command sequnce number.
Definition: rl_driver.h:268
rlOsiMsgQCbs_t queue
OS message queue/Spawn callback functions.
Definition: mmwavelink.h:1120
rlUInt8_t rlDriverGetPlatformId(void)
Returns RL Platform ID (i.e. where mmWaveLink is executing)
Definition: rl_driver.c:2097
volatile rlUInt8_t rxDoneCnt[RL_DEVICE_CONNECTED_MAX]
Driver serviced Host Interrupt count.
Definition: rl_driver.h:264
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
rlInt32_t(* rlComputeCRC)(rlUInt8_t *data, rlUInt32_t dataLen, rlUInt8_t crcType, rlUInt8_t *crc)
Compute CRC on the input message.
Definition: mmwavelink.h:1185
rlLogCtx_t logObj
As per debug level callback functions will be assinged.
Definition: rl_driver.h:292
rlUInt8_t isRespWriteWaited[RL_DEVICE_CONNECTED_MAX]
if writing a data waits for Host IRQ
Definition: rl_driver.h:256
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:204
rlComIfCbs_t comIfCb
Comunication Interface Callback.
Definition: mmwavelink.h:1335
rlPrintFptr rlPrint
Print input message as per the format in the input arguments.
Definition: mmwavelink.h:1320
rlInt32_t(* rlOsiMutexCreate)(rlOsiMutexHdl_t *mutexHdl, rlInt8_t *name)
Create Mutex Object.
Definition: mmwavelink.h:977
rlOsiSemCbs_t sem
Semaphore callback functions.
Definition: mmwavelink.h:1116
rlReturnVal_t rlDriverValidateHdr(rlProtHeader_t protHdr)
Validates the header by comparing Checksum.
Definition: rl_driver.c:361
rlOsiMutexCbs_t mutex
Mutex callback functions.
Definition: mmwavelink.h:1112
rlDbgCb_t dbgCb
Debug Callback, required to receive Debug information.
Definition: mmwavelink.h:1385
rlUInt16_t b4SeqNum
Sequence Number.
Definition: rl_protocol.h:169
rlUInt8_t arDevType
xWR1243 + HOST = 0x0, xWR1443 MSS = 0x1, xWR1642 MSS/DSS = 0x2, xWR1843 MSS/DSS = 0x3...
Definition: mmwavelink.h:1381
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:929
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:2703
mmwave radar Driver Global Structure
Definition: rl_driver.h:235
rlComIfHdl_t comIfHdl[RL_DEVICE_CONNECTED_MAX]
Communication Interface Handles.
Definition: rl_driver.h:217
rlUInt8_t isDriverInitialized
Driver Status.
Definition: rl_driver.h:244
rlReturnVal_t rlDriverMsgRead(rlDriverData_t *rlDrvData, rlUInt8_t devIndex)
Receive and validate protocol header and payload.
Definition: rl_driver.c:1193
rlUInt16_t nsbc
Number of Sub Blocks in Payload.
Definition: rl_driver.h:332
rlInt32_t(* rlComIfClose)(rlComIfHdl_t fd)
Close the Communication interface.
Definition: mmwavelink.h:957
mmwave Logging functions
Definition: rl_driver.h:227
rlUInt16_t b4Direction
Direction.
Definition: rl_protocol.h:104
rlEventCbs_t eventCb
Event Callback, required to receive notification.
Definition: mmwavelink.h:1343
rlComIfHdl_t(* rlComIfOpen)(rlUInt8_t deviceIndex, rlUInt32_t flags)
Open Communication interface.
Definition: mmwavelink.h:914
rlFunctionParams_t funcParams
Current API parameters.
Definition: rl_driver.h:240
rlUInt8_t dbgLevel
User needs to set debug level such as error, warning, debug, verbose.
Definition: mmwavelink.h:1324
rlReturnVal_t rlDriverRxHdrRead(rlUInt8_t hdrBuf[RHCP_HEADER_LEN], rlComIfHdl_t comIfHdl)
Read SYNC and Header from communication channel.
Definition: rl_driver.c:1521
rlUInt8_t rlDriverGetArDeviceType(void)
Returns AR device type which mmWavelink is communicating.
Definition: rl_driver.c:2115
mmwave radar Driver Protocol header read buffer
Definition: rl_driver.h:306
rlInt32_t(* rlRegisterInterruptHandler)(rlUInt8_t deviceIndex, RL_P_EVENT_HANDLER pHandler, void *pValue)
Register Host Interrupt Handler.
Definition: mmwavelink.h:1294
rlReturnVal_t rlDriverDeInit(void)
De Initializes the mmwave radar Driver.
Definition: rl_driver.c:2018
void(* rlDeviceMaskHostIrq)(rlComIfHdl_t fd)
Masks Host Interrupt.
Definition: mmwavelink.h:1232
rlDriverData_t * rlDriverGetHandle(void)
Returns mmwave radar Driver Global Structure.
Definition: rl_driver.c:2081
void rlDriverHostIrqHandler(rlUInt8_t deviceIndex, void *pValue)
Interrupt Service Routine to handle host interrupt from mmwave radar device.
Definition: rl_driver.c:560
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:495
rlReturnVal_t rlDriverCmdSendRetry(rlUInt8_t deviceMap, rlDriverMsg_t *outMsg)
: Send command and wait for response
Definition: rl_driver.c:2344
RHCP Payload Structure.
Definition: rl_driver.h:155
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:2406
RHCP protocol header structure.
Definition: rl_protocol.h:209
mmwave radar Driver Payload
Definition: rl_driver.h:338
rlTimerCbs_t timerCb
Timer Callback, required when ACK is enabled.
Definition: mmwavelink.h:1351
rlCrcCbs_t crcCb
CRC Callback, required when CRC is enabled.
Definition: mmwavelink.h:1360
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:2769
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:2572
rlInt32_t(* rlOsiSpawn)(RL_P_OSI_SPAWN_ENTRY pEntry, const void *pValue, rlUInt32_t flags)
Calls a function in a different context.
Definition: mmwavelink.h:1100
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:1143
rlReturnVal_t rlDriverOsiInit(void)
Initializes the OSI layer abstraction for mmwavelink.
Definition: rl_driver.c:1637
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:243
rlInt32_t(* rlOsiMutexLock)(rlOsiMutexHdl_t *mutexHdl, rlOsiTime_t timeout)
Lock Mutex Object.
Definition: mmwavelink.h:991
rlReturnVal_t rlDriverRemoveDevices(rlUInt8_t deviceMap)
Disconnects the mmwave radar devices.
Definition: rl_driver.c:1973
rlInt32_t(* rlOsiSemSignal)(rlOsiSemHdl_t *semHdl)
Release Semaphore.
Definition: mmwavelink.h:1064
rlInt32_t(* rlOsiSemDelete)(rlOsiSemHdl_t *semHdl)
Destroy Semaphore Object.
Definition: mmwavelink.h:1077
rlInt32_t(* rlComIfWrite)(rlComIfHdl_t fd, rlUInt8_t *pBuff, rlUInt16_t len)
Write Data over Communication interface.
Definition: mmwavelink.h:944
rlInt32_t(* rlDeviceDisable)(rlUInt8_t deviceIndex)
Power off mmWave radar device.
Definition: mmwavelink.h:1220
void(* rlDeviceUnMaskHostIrq)(rlComIfHdl_t fd)
Unmask Host Interrupt.
Definition: mmwavelink.h:1244
rlSysNRespType_t errorType
Definition: rl_protocol.h:74
rlClientCbs_t clientCtx
Client context.
Definition: rl_driver.h:288
rlDeviceCtrlCbs_t devCtrlCb
Device Control Callback.
Definition: mmwavelink.h:1347
rlReturnVal_t rlDriverAddDevice(rlUInt8_t deviceMap)
Adds mmwave radar device.
Definition: rl_driver.c:1880
RHCP message structure.
Definition: rl_protocol.h:225
rlOsiSemHdl_t cmdSem
Driver Command Wait Semaphore.
Definition: rl_driver.h:280
mmWaveLink API Error Sub block structure
Definition: rl_protocol.h:69
rlCrcType_t crcType
CRC Types rlCrcType_t 16/32/64.
Definition: mmwavelink.h:1364
rlReturnVal_t rlDriverWaitForResponse(rlUInt8_t devIndex, rlDriverMsg_t *outMsg)
: Wait for Device&#39;s response
Definition: rl_driver.c:2177
rlReturnVal_t rlDriverMsgWrite(rlDriverData_t *rlDrvData, rlComIfHdl_t comIfHdl)
Write command header and payload data over communication channel.
Definition: rl_driver.c:1314
rlUInt8_t deviceMap
Bitmap of devices connected radarSS/DSS Mailbox in case of 16xx autonomous.
Definition: rl_driver.h:248
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:631
RHCP SYNC Pattern Structure.
Definition: rl_protocol.h:85
rlInt32_t(* rlOsiMutexDelete)(rlOsiMutexHdl_t *mutexHdl)
Destroy Mutex Object.
Definition: mmwavelink.h:1017
rlComDevInx_t commDevIdx
Communication handle and device-index for deifferent devices connected to Host.
Definition: rl_driver.h:272
void rlDriverShiftDWord(rlUInt8_t buf[])
Shifts one byte in the byte array.
Definition: rl_driver.c:174
rlOsiMutexHdl_t globalMutex
Driver Global Lock Mutex.
Definition: rl_driver.h:276
rlCmdParserCbs_t cmdParserCb
Call back for parsing the Command received at MSS from the Host TI Internal Use only.
Definition: mmwavelink.h:1356
rlReturnVal_t rlDriverIsDeviceMapValid(rlUInt8_t deviceMap)
Checks if given deviecMap is valid wrt to global DeviceMap set to mmWaveLink.
Definition: rl_driver.c:2134
rlInt32_t(* rlDeviceWaitIrqStatus)(rlComIfHdl_t fd, rlUInt8_t highLow)
Polls Host Interrupt Status.
Definition: mmwavelink.h:1262

Copyright 2018, Texas Instruments Incorporated