rl_driver.h
1 /****************************************************************************************
2  * FileName : rl_driver.h
3  *
4  * Description : This file implements the mmwave radar Host Communication Protocol.
5  *
6  ****************************************************************************************
7  * (C) Copyright 2014, Texas Instruments Incorporated. - TI web address www.ti.com
8  *---------------------------------------------------------------------------------------
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * Neither the name of Texas Instruments Incorporated nor the names of its
21  * contributors may be used to endorse or promote products derived from this
22  * software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 
38 /****************************************************************************************
39  * FILE INCLUSION PROTECTION
40  ****************************************************************************************
41  */
42 #ifndef RL_DRIVER_H
43 #define RL_DRIVER_H
44 
45 /******************************************************************************
46  * INCLUDE FILES
47  ******************************************************************************
48  */
49 #include "rl_datatypes.h"
50 #include "rl_protocol.h"
51 #include "rl_messages.h"
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 /****************************************************************************************
57 * MACRO DEFINITIONS
58 ****************************************************************************************
59 */
60 
61 
62 #define RL_API_CMD_RETRY_COUNT (3U) /* RHCP Retry Count */
63 #define RL_SBC_ERR_SB_SIZE (4U) /* RHCP ERROR SB Size */
64 #define RL_PROTOCOL_ALIGN_SIZE (4U) /* Alignment required for CRC computation,
65  4 - 16/32bit CRC, 8 - 64bit CRC*/
66 #define RL_PROTOCOL_DUMMY_BYTE (0xFFU) /* Dummy Byte used by Protocol*/
67 #define RL_RSP_ERR_MSG_LEN (SYNC_PATTERN_LEN + RHCP_HEADER_LEN + \
68  RL_SBC_ERR_SB_SIZE + RL_CRC_LEN_MAX)
69 
70 /******************************************************************************
71  * GLOBAL VARIABLES/DATA-TYPES DEFINITIONS
72  ******************************************************************************
73  */
74 
78 #define RL_API_DIR_INVALID (0x0U)
79 #define RL_API_DIR_HOST_TO_BSS (0x1U)
80 #define RL_API_DIR_BSS_TO_HOST (0x2U)
81 #define RL_API_DIR_HOST_TO_DSS (0x3U)
82 #define RL_API_DIR_DSS_TO_HOST (0x4U)
83 #define RL_API_DIR_HOST_TO_MSS (0x5U)
84 #define RL_API_DIR_MSS_TO_HOST (0x6U)
85 #define RL_API_DIR_BSS_TO_MSS (0x7U)
86 #define RL_API_DIR_MSS_TO_BSS (0x8U)
87 #define RL_API_DIR_BSS_TO_DSS (0x9U)
88 #define RL_API_DIR_DSS_TO_BSS (0xAU)
89 #define RL_API_DIR_MSS_TO_DSS (0xBU)
90 #define RL_API_DIR_DSS_TO_MSS (0xCU)
91 #define RL_API_DIR_RESRVD (0xFU)
92 
96 #define RL_API_CLASS_CMD (0x0U)
97 #define RL_API_CLASS_RSP (0x1U)
98 #define RL_API_CLASS_NACK (0x2U)
99 #define RL_API_CLASS_ASYNC (0x3U)
100 
101 #define RL_API_CLASS_BYPASS (0x4U)
102 #define RL_API_CLASS_MAX (0x5U)
103 
107 #define RL_HDR_FLAG_NO_RETRY (0x0U)
108 #define RL_HDR_FLAG_RETRY (0x3U)
109 
113 #define RL_HDR_FLAG_ACK (0x0U)
114 #define RL_HDR_FLAG_NO_ACK (0x3U)
115 
119 #define RL_API_RTYP_SET (0x0U)
120 #define RL_API_RTYP_GET (0x1U)
121 
125 #define RL_PROT_VERSION_0 (0x0U)
126 #define RL_PROT_VERSION_MAX (0xFU)
127 
131 #define RL_HDR_FLAG_CRC (0x0U)
132 #define RL_HDR_FLAG_NO_CRC (0x3U)
133 
137 #define RL_HDR_FLAG_CRC_16BIT (0x0U)
138 #define RL_HDR_FLAG_CRC_32BIT (0x1U)
139 #define RL_HDR_FLAG_CRC_64BIT (0x2U)
140 
144 typedef rlUInt16_t rlCrcData_t;
145 
149 #define RL_PAYLOAD_MSG_4BYTE_MULT (0x4U) /* MSG must be multiple of this value */
150 #define RL_PAYLOAD_MSG_8BYTE_MULT (0x8U) /* MSG must be multiple of this value */
151 
155  typedef struct rlPayloadSb
156 {
157  rlUInt16_t sbid;
158  rlUInt16_t len;
159  rlUInt8_t *pSblkData;
161 
162 
166 typedef struct rlFixPayloadSb
167 {
168  rlUInt16_t sbid;
169  rlUInt16_t len;
170  rlUInt8_t sblkData[240];
172 
173 
177 typedef struct rlAsyncEvt
178 {
179  rlRhcpMsg_t evtMsg;
180 }rlAsyncEvt_t;
181 
187 typedef struct rlDriverRespMsg
188 {
189  rlProtHeader_t hdr;
190  rlPayloadSb_t* subblocks;
191  rlUInt8_t isSendToSender;
193 
197 typedef struct rlFunctionParams
198 {
199  rlRhcpMsg_t* cmd;
200  rlRhcpMsg_t* rsp;
201  rlAsyncEvt_t asyncEvt;
202  rlUInt8_t rxMsgClass;
203  rlUInt8_t alignReserved1;
204  rlUInt8_t alignReserved2;
205  rlUInt8_t alignReserved3;
206  rlUInt8_t msgCRC[RL_CRC_LEN_MAX];
208 
212 typedef struct rlComDevInx
213 {
217  rlComIfHdl_t comIfHdl[RL_DEVICE_CONNECTED_MAX];
221  rlUInt8_t rlDevIndex[RL_DEVICE_CONNECTED_MAX];
223 
227 typedef struct loggingFunctions
228 {
229  rlPrintFptr rlPrintAr[RL_DBG_LEVEL_VERBOSE];
230 }rlLogCtx_t;
231 
235 typedef struct rlDriverData
236 {
248  rlUInt8_t deviceMap;
252  volatile rlUInt8_t isCmdRespWaited[RL_DEVICE_CONNECTED_MAX];
256  rlUInt8_t isRespWriteWaited[RL_DEVICE_CONNECTED_MAX];
260  volatile rlUInt8_t rxIrqCnt[RL_DEVICE_CONNECTED_MAX];
264  volatile rlUInt8_t rxDoneCnt[RL_DEVICE_CONNECTED_MAX];
268  rlUInt16_t cmdSeqNum[RL_DEVICE_CONNECTED_MAX];
276  rlOsiMutexHdl_t globalMutex;
280  rlOsiSemHdl_t cmdSem;
284  rlOsiMsgQHdl_t spawnQueue;
293  rlRhcpMsg_t *txMsgPtr;
294  rlRhcpMsg_t *rxMsgPtr;
296 
297 typedef struct rlSyncHeader
298 {
299  rlSyncPattern_t syncPattern;
300  rlProtHeader_t protHdr;
301 }rlSyncHeader_t;
302 
306 typedef union rlReadBuf
307 {
308  rlUInt8_t tempBuf[RHCP_HEADER_LEN + SYNC_PATTERN_LEN];
309  rlSyncHeader_t syncHeader;
310 }rlReadBuf_t;
311 
315 typedef struct rlDriverOpcode
316 {
320  rlUInt8_t dir;
324  rlUInt8_t msgType;
328  rlUInt16_t msgId;
332  rlUInt16_t nsbc;
334 
338 typedef struct rlDriverMsg
339 {
340  rlDriverOpcode_t opcode;
341  rlPayloadSb_t* subblocks;
342  rlUInt16_t remChunks;
344 
345 
364 /******************************************************************************
365  * FUNCTION DECLARATIONS
366  ******************************************************************************
367  */
368 rlReturnVal_t rlDriverInit(rlUInt8_t deviceMap, rlClientCbs_t clientCb);
369 rlReturnVal_t rlDriverOsiInit(void);
370 rlReturnVal_t rlDriverAddDevice(rlUInt8_t deviceMap);
371 rlReturnVal_t rlDriverRemoveDevices(rlUInt8_t deviceMap);
372 rlReturnVal_t rlDriverDeInit(void);
374 rlUInt8_t rlDriverGetPlatformId(void);
375 rlUInt8_t rlDriverGetArDeviceType(void);
376 rlUInt8_t rlDriverGetNoOfConnectedDev(void);
377 rlUInt8_t rlDriverGetCmdDir(rlUInt16_t msgId);
378 rlReturnVal_t rlDriverIsDeviceMapValid(rlUInt8_t deviceMap);
379 rlReturnVal_t rlDriverWaitForResponse(rlUInt8_t devIndex, rlDriverMsg_t* outMsg);
380 rlReturnVal_t rlDriverCmdInvoke(rlUInt8_t deviceMap, rlDriverMsg_t inMsg,
381  rlDriverMsg_t* outMsg);
382 rlReturnVal_t rlDriverSendResponse(rlRhcpMsg_t *outMsg);
383 rlReturnVal_t rlDriverSendMsg(rlUInt8_t devIndex, rlUInt8_t* inMsg, rlUInt16_t inLen);
384 rlReturnVal_t rlDriverConfigureCrc(rlCrcType_t crcType);
385 rlReturnVal_t rlDriverConfigureAckTimeout(rlUInt32_t ackTimeout);
386 
387 rlReturnVal_t rlDriverCalCRC(rlUInt8_t* data,rlUInt16_t dataLen,
388  rlUInt8_t crcType, rlUInt8_t crc[RL_CRC_LEN_MAX]);
389 
390 rlReturnVal_t rlDriverVerifyCRC(rlUInt8_t* data, rlUInt16_t dataLen,
391  rlUInt8_t crcType, rlUInt8_t crc[RL_CRC_LEN_MAX]);
392 void rlDriverShiftDWord(rlUInt8_t buf[]);
393 rlReturnVal_t rlDriverCalChkSum(rlProtHeader_t* hdrData, rlUInt8_t len, rlUInt16_t* checksum);
394 rlReturnVal_t rlDriverValidateHdr(rlProtHeader_t protHdr);
395 rlReturnVal_t rlDriverAsyncEventHandler(rlUInt8_t devIndex, rlUInt16_t nsbc,
396  rlUInt8_t *payload,
397  rlUInt16_t payloadLen);
398 rlUInt8_t rlDeviceIdentifyCmdDir(rlUInt16_t msgId, rlUInt8_t platform);
399 void rlDriverHostIrqHandler(rlUInt8_t deviceIndex, void *pValue);
400 rlUInt8_t rlDriverGetDeviceIndex(rlUInt16_t dataDir);
401 rlReturnVal_t rlDriverMsgReadSpawnCtx(const void *pValue);
402 rlReturnVal_t rlDriverMsgReadCmdCtx(rlUInt8_t devIndex);
403 rlReturnVal_t rlDriverMsgRead(rlDriverData_t* rlDrvData, rlUInt8_t devIndex);
404 rlReturnVal_t rlDriverMsgWrite(rlDriverData_t* rlDrvData, rlComIfHdl_t comIfHdl);
405 rlReturnVal_t rlDriverRxHdrRead(rlUInt8_t hdrBuf[RHCP_HEADER_LEN],
406  rlComIfHdl_t comIfHdl);
407 rlUInt8_t rlDriverPendingRxMsg(void);
408 void rlDriverFillPayload(rlUInt16_t msgId, rlUInt16_t sbcID, rlPayloadSb_t* payloadPtr,
409  rlUInt8_t* data, rlUInt16_t inLen);
410 void rlDriverConstructInMsg(rlUInt16_t msgId, rlDriverMsg_t* inMsg,
411  rlPayloadSb_t* payloadPtr);
412 void rlDriverConstructOutMsg(rlUInt16_t numSblk, rlDriverMsg_t* outMsg,
413  rlPayloadSb_t* payloadPtr);
414 rlReturnVal_t rlDriverExecuteGetApi(rlUInt8_t deviceMap, rlUInt16_t msgId,
415  rlUInt16_t sbcID, rlUInt8_t *msgData, rlUInt16_t inLen);
416 rlReturnVal_t rlDriverExecuteSetApi(rlUInt8_t deviceMap, rlUInt16_t msgId,
417  rlUInt16_t sbcID, rlUInt8_t *msgData, rlUInt16_t inLen);
418 rlReturnVal_t rlDriverRdVerifyAsync(rlReadBuf_t readBuf, rlUInt8_t devIndex,
419  rlUInt16_t rxLengthRecv);
420 rlReturnVal_t rlDriverProcRdMsg(rlUInt8_t devIdx, rlReturnVal_t inVal);
421 rlReturnVal_t rlDriverMsgCmdReply(rlDriverData_t* rlDrvData, rlUInt8_t devIndex);
422 rlReturnVal_t rlDriverRdVerifyCmd(rlReadBuf_t readBuf, rlUInt8_t devIndex,
423  rlUInt16_t rxLengthRecv);
424 rlReturnVal_t rlDriverRdVerifyMsg(rlReadBuf_t readBuf, rlUInt8_t devIndex);
425 rlReturnVal_t rlDriverRdVerifyRsp(rlReadBuf_t readBuf, rlUInt8_t devIndex,
426  rlUInt16_t rxLengthRecv);
427 rlReturnVal_t rlDriverCmdSendRetry(rlUInt8_t deviceMap, rlDriverMsg_t* outMsg);
428 
434 #ifdef __cplusplus
435 }
436 #endif
437 
438 #endif
439 
440 /*
441  * END OF RL_DRIVER_H FILE
442  */
rlReturnVal_t rlDriverMsgReadCmdCtx(rlUInt8_t devIndex)
Wait and handle command response.
Definition: rl_driver.c:892
mmWaveLink client callback structure
Definition: mmwavelink.h:1330
rlUInt8_t dir
Message Direction.
Definition: rl_driver.h:320
mmwave radar Driver Opcode
Definition: rl_driver.h:315
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
rlUInt8_t msgType
Message Class.
Definition: rl_driver.h:324
RHCP Payload Structure.
Definition: rl_driver.h:166
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
rlUInt16_t msgId
Message Id.
Definition: rl_driver.h:328
rlUInt8_t rlDriverGetPlatformId(void)
Returns RL Platform ID (i.e. where mmWaveLink is executing)
Definition: rl_driver.c:2097
rlLogCtx_t logObj
As per debug level callback functions will be assinged.
Definition: rl_driver.h:292
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
The passing message type of Tx task of API module.
Definition: rl_driver.h:187
rlReturnVal_t rlDriverValidateHdr(rlProtHeader_t protHdr)
Validates the header by comparing Checksum.
Definition: rl_driver.c:361
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
RHCP Async Event structure.
Definition: rl_driver.h:177
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
mmwave Logging functions
Definition: rl_driver.h:227
rlFunctionParams_t funcParams
Current API parameters.
Definition: rl_driver.h:240
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
rlReturnVal_t rlDriverDeInit(void)
De Initializes the mmwave radar Driver.
Definition: rl_driver.c:2018
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
mmwave radar Driver Function Params
Definition: rl_driver.h:197
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
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
rlReturnVal_t rlDriverConfigureAckTimeout(rlUInt32_t ackTimeout)
Configures the Acknowledgement timeout in mmwavelink Driver.
Definition: rl_driver.c:2572
rlReturnVal_t rlDriverOsiInit(void)
Initializes the OSI layer abstraction for mmwavelink.
Definition: rl_driver.c:1637
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
rlReturnVal_t rlDriverRemoveDevices(rlUInt8_t deviceMap)
Disconnects the mmwave radar devices.
Definition: rl_driver.c:1973
Communication handle and device-index for deifferent devices connected to Host.
Definition: rl_driver.h:212
rlClientCbs_t clientCtx
Client context.
Definition: rl_driver.h:288
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
rlReturnVal_t rlDriverWaitForResponse(rlUInt8_t devIndex, rlDriverMsg_t *outMsg)
: Wait for Device's response
Definition: rl_driver.c:2177
rlOsiMsgQHdl_t spawnQueue
Driver Spawn queue.
Definition: rl_driver.h:284
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
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
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
rlReturnVal_t rlDriverIsDeviceMapValid(rlUInt8_t deviceMap)
Checks if given deviecMap is valid wrt to global DeviceMap set to mmWaveLink.
Definition: rl_driver.c:2134

Copyright 2018, Texas Instruments Incorporated